Type prefixes (#34)
* update documentation * Fix typo * Added some examples * changed window names * Minor fix * Added mfb_update_events to all platforms. Checked on Windows, X11 and Wayland * simplify CMake * Upgrade to CMake 3.5, simplify script and generalize it Now the users only have to add_directory and link_libraries(minifb) in CMake * Renamed typo scrool by scroll Added some checks Removed some warnings * working Windows, X11 and Wayland * fix issue 32 Co-authored-by: Carlos Aragones <> Co-authored-by: caragones <carlos.aragonesmartinez-external@gemalto.com>
This commit is contained in:
parent
4286f055c6
commit
6b30baa7e4
39
README.md
39
README.md
@ -3,7 +3,7 @@ MiniFB
|
||||
|
||||
MiniFB (Mini FrameBuffer) is a small cross platform library that makes it easy to render (32-bit) pixels in a window. An example is the best way to show how it works:
|
||||
|
||||
struct Window *window = mfb_open_ex("my display", 800, 600, WF_RESIZABLE);
|
||||
struct mfb_window *window = mfb_open_ex("my display", 800, 600, WF_RESIZABLE);
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
@ -22,43 +22,46 @@ MiniFB (Mini FrameBuffer) is a small cross platform library that makes it easy t
|
||||
|
||||
Furthermore, you can add callbacks to the windows:
|
||||
|
||||
void active(struct Window *window, bool isActive) {
|
||||
void active(struct mfb_window *window, bool isActive) {
|
||||
...
|
||||
}
|
||||
|
||||
void resize(struct Window *window, int width, int height) {
|
||||
void resize(struct mfb_window *window, int width, int height) {
|
||||
...
|
||||
// Optionally you can also change the viewport size
|
||||
mfb_set_viewport(window, x, y, width, height);
|
||||
}
|
||||
|
||||
void keyboard(struct Window *window, Key key, KeyMod mod, bool isPressed) {
|
||||
void keyboard(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed) {
|
||||
...
|
||||
// Remember to close the window in some way
|
||||
if(key == KB_KEY_ESCAPE) {
|
||||
mfb_close(window);
|
||||
}
|
||||
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [key_mod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
|
||||
}
|
||||
|
||||
void char_input(struct Window *window, unsigned int charCode) {
|
||||
void char_input(struct mfb_window *window, unsigned int charCode) {
|
||||
...
|
||||
}
|
||||
|
||||
void mouse_btn(struct Window *window, MouseButton button, KeyMod mod, bool isPressed) {
|
||||
void mouse_btn(struct mfb_window *window, mfb_mouse_button button, mfb_key_mod mod, bool isPressed) {
|
||||
...
|
||||
}
|
||||
|
||||
// Use wisely this event. It can be sent too often
|
||||
void mouse_move(struct Window *window, int x, int y) {
|
||||
void mouse_move(struct mfb_window *window, int x, int y) {
|
||||
...
|
||||
}
|
||||
|
||||
// Mouse wheel
|
||||
void mouse_scroll(struct Window *window, KeyMod mod, float deltaX, float deltaY) {
|
||||
void mouse_scroll(struct mfb_window *window, mfb_key_mod mod, float deltaX, float deltaY) {
|
||||
...
|
||||
}
|
||||
|
||||
struct Window *window = mfb_open_ex("my display", 800, 600, WF_RESIZABLE);
|
||||
struct mfb_window *window = mfb_open_ex("my display", 800, 600, WF_RESIZABLE);
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
@ -78,6 +81,24 @@ Additionally you can set data per window and recover it
|
||||
myData = (someCast *) mfb_get_user_data(window);
|
||||
|
||||
|
||||
Finally, you can get information about the events in the window directly:
|
||||
|
||||
bool mfb_is_window_active(struct mfb_window *window);
|
||||
|
||||
unsigned mfb_get_window_width(struct mfb_window *window);
|
||||
unsigned mfb_get_window_height(struct mfb_window *window);
|
||||
|
||||
int mfb_get_mouse_x(struct mfb_window *window); // Last mouse pos X
|
||||
int mfb_get_mouse_y(struct mfb_window *window); // Last mouse pos Y
|
||||
|
||||
float mfb_get_mouse_scroll_x(struct mfb_window *window); // Mouse wheel X as a sum. When you call this function it resets.
|
||||
float mfb_get_mouse_scroll_y(struct mfb_window *window); // Mouse wheel Y as a sum. When you call this function it resets.
|
||||
|
||||
const uint8_t * mfb_get_mouse_button_buffer(struct mfb_window *window); // One byte for every button. Press (1), Release 0. (up to 8 buttons)
|
||||
|
||||
const uint8_t * mfb_get_key_buffer(struct mfb_window *window); // One byte for every key. Press (1), Release 0.
|
||||
|
||||
|
||||
First the code creates window with the mfb_open call that is used to display the data, next it's the applications responsibility to allocate a buffer (which has to be at least the size of the window and in 32-bit) Next when calling mfb_update function the buffer will be copied over to the window and displayed. Currently the mfb_update will return -1 if ESC key is pressed but later on it will support to return a key code for a pressed button. See https://github.com/emoon/minifb/blob/master/tests/noise.c for a complete example
|
||||
|
||||
MiniFB has been tested on Windows, Mac OS X and Linux but may of course have trouble depending on your setup. Currently the code will not do any converting of data if not a proper 32-bit display can be created.
|
||||
|
@ -14,47 +14,47 @@ extern "C" {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Create a window that is used to display the buffer sent into the mfb_update function, returns 0 if fails
|
||||
struct Window * mfb_open(const char *title, unsigned width, unsigned height);
|
||||
struct Window * mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags);
|
||||
struct mfb_window * mfb_open(const char *title, unsigned width, unsigned height);
|
||||
struct mfb_window * mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags);
|
||||
|
||||
// Update the display
|
||||
// Input buffer is assumed to be a 32-bit buffer of the size given in the open call
|
||||
// Will return a negative status if something went wrong or the user want to exit
|
||||
// Also updates the window events
|
||||
UpdateState mfb_update(struct Window *window, void *buffer);
|
||||
mfb_update_state mfb_update(struct mfb_window *window, void *buffer);
|
||||
|
||||
// Only updates the window events
|
||||
UpdateState mfb_update_events(struct Window *window);
|
||||
mfb_update_state mfb_update_events(struct mfb_window *window);
|
||||
|
||||
// Close the window
|
||||
void mfb_close(struct Window *window);
|
||||
void mfb_close(struct mfb_window *window);
|
||||
|
||||
// Set user data
|
||||
void mfb_set_user_data(struct Window *window, void *user_data);
|
||||
void * mfb_get_user_data(struct Window *window);
|
||||
void mfb_set_user_data(struct mfb_window *window, void *user_data);
|
||||
void * mfb_get_user_data(struct mfb_window *window);
|
||||
|
||||
// Set viewport (useful when resize)
|
||||
bool mfb_set_viewport(struct Window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height);
|
||||
bool mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height);
|
||||
|
||||
void mfb_set_active_callback(struct Window *window, mfb_active_func callback);
|
||||
void mfb_set_resize_callback(struct Window *window, mfb_resize_func callback);
|
||||
void mfb_set_keyboard_callback(struct Window *window, mfb_keyboard_func callback);
|
||||
void mfb_set_char_input_callback(struct Window *window, mfb_char_input_func callback);
|
||||
void mfb_set_mouse_button_callback(struct Window *window, mfb_mouse_button_func callback);
|
||||
void mfb_set_mouse_move_callback(struct Window *window, mfb_mouse_move_func callback);
|
||||
void mfb_set_mouse_scroll_callback(struct Window *window, mfb_mouse_scroll_func callback);
|
||||
void mfb_set_active_callback(struct mfb_window *window, mfb_active_func callback);
|
||||
void mfb_set_resize_callback(struct mfb_window *window, mfb_resize_func callback);
|
||||
void mfb_set_keyboard_callback(struct mfb_window *window, mfb_keyboard_func callback);
|
||||
void mfb_set_char_input_callback(struct mfb_window *window, mfb_char_input_func callback);
|
||||
void mfb_set_mouse_button_callback(struct mfb_window *window, mfb_mouse_button_func callback);
|
||||
void mfb_set_mouse_move_callback(struct mfb_window *window, mfb_mouse_move_func callback);
|
||||
void mfb_set_mouse_scroll_callback(struct mfb_window *window, mfb_mouse_scroll_func callback);
|
||||
|
||||
const char * mfb_get_key_name(Key key);
|
||||
const char * mfb_get_key_name(mfb_key key);
|
||||
|
||||
bool mfb_is_window_active(struct Window *window);
|
||||
unsigned mfb_get_window_width(struct Window *window);
|
||||
unsigned mfb_get_window_height(struct Window *window);
|
||||
int mfb_get_mouse_x(struct Window *window); // Last mouse pos X
|
||||
int mfb_get_mouse_y(struct Window *window); // Last mouse pos Y
|
||||
float mfb_get_mouse_scroll_x(struct Window *window); // Mouse wheel X as a sum. When you call this function it resets.
|
||||
float mfb_get_mouse_scroll_y(struct Window *window); // Mouse wheel Y as a sum. When you call this function it resets.
|
||||
const uint8_t * mfb_get_mouse_button_buffer(struct Window *window); // One byte for every button. Press (1), Release 0. (up to 8 buttons)
|
||||
const uint8_t * mfb_get_key_buffer(struct Window *window); // One byte for every key. Press (1), Release 0.
|
||||
bool mfb_is_window_active(struct mfb_window *window);
|
||||
unsigned mfb_get_window_width(struct mfb_window *window);
|
||||
unsigned mfb_get_window_height(struct mfb_window *window);
|
||||
int mfb_get_mouse_x(struct mfb_window *window); // Last mouse pos X
|
||||
int mfb_get_mouse_y(struct mfb_window *window); // Last mouse pos Y
|
||||
float mfb_get_mouse_scroll_x(struct mfb_window *window); // Mouse wheel X as a sum. When you call this function it resets.
|
||||
float mfb_get_mouse_scroll_y(struct mfb_window *window); // Mouse wheel Y as a sum. When you call this function it resets.
|
||||
const uint8_t * mfb_get_mouse_button_buffer(struct mfb_window *window); // One byte for every button. Press (1), Release 0. (up to 8 buttons)
|
||||
const uint8_t * mfb_get_key_buffer(struct mfb_window *window); // One byte for every key. Press (1), Release 0.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -6,131 +6,131 @@
|
||||
#include "MiniFB.h"
|
||||
|
||||
template <class T>
|
||||
void mfb_set_active_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, bool));
|
||||
void mfb_set_active_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, bool));
|
||||
|
||||
template <class T>
|
||||
void mfb_set_resize_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
void mfb_set_resize_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, int, int));
|
||||
|
||||
template <class T>
|
||||
void mfb_set_keyboard_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, Key, KeyMod, bool));
|
||||
void mfb_set_keyboard_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, mfb_key, mfb_key_mod, bool));
|
||||
|
||||
template <class T>
|
||||
void mfb_set_char_input_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, unsigned int));
|
||||
void mfb_set_char_input_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, unsigned int));
|
||||
|
||||
template <class T>
|
||||
void mfb_set_mouse_button_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, MouseButton, KeyMod, bool));
|
||||
void mfb_set_mouse_button_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, mfb_mouse_button, mfb_key_mod, bool));
|
||||
|
||||
template <class T>
|
||||
void mfb_set_mouse_move_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
void mfb_set_mouse_move_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, int, int));
|
||||
|
||||
template <class T>
|
||||
void mfb_set_mouse_scroll_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, KeyMod, float, float));
|
||||
void mfb_set_mouse_scroll_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, mfb_key_mod, float, float));
|
||||
|
||||
//-------------------------------------
|
||||
// To avoid clumsy hands
|
||||
//-------------------------------------
|
||||
class Stub {
|
||||
Stub() : m_window(0x0) {}
|
||||
class mfb_stub {
|
||||
mfb_stub() : m_window(0x0) {}
|
||||
|
||||
template <class T>
|
||||
friend void mfb_set_active_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, bool));
|
||||
friend void mfb_set_active_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, bool));
|
||||
template <class T>
|
||||
friend void mfb_set_resize_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
friend void mfb_set_resize_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, int, int));
|
||||
template <class T>
|
||||
friend void mfb_set_mouse_button_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, MouseButton, KeyMod, bool));
|
||||
friend void mfb_set_mouse_button_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, mfb_mouse_button, mfb_key_mod, bool));
|
||||
template <class T>
|
||||
friend void mfb_set_keyboard_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, Key, KeyMod, bool));
|
||||
friend void mfb_set_keyboard_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, mfb_key, mfb_key_mod, bool));
|
||||
template <class T>
|
||||
friend void mfb_set_char_input_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, unsigned int));
|
||||
friend void mfb_set_char_input_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, unsigned int));
|
||||
template <class T>
|
||||
friend void mfb_set_mouse_button_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, MouseButton, KeyMod, bool));
|
||||
friend void mfb_set_mouse_button_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, mfb_mouse_button, mfb_key_mod, bool));
|
||||
template <class T>
|
||||
friend void mfb_set_mouse_move_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
friend void mfb_set_mouse_move_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, int, int));
|
||||
template <class T>
|
||||
friend void mfb_set_mouse_scroll_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, KeyMod, float, float));
|
||||
friend void mfb_set_mouse_scroll_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, mfb_key_mod, float, float));
|
||||
|
||||
static Stub *GetInstance(struct Window *window);
|
||||
static mfb_stub *GetInstance(struct mfb_window *window);
|
||||
|
||||
static void active_stub(struct Window *window, bool isActive);
|
||||
static void resize_stub(struct Window *window, int width, int height);
|
||||
static void keyboard_stub(struct Window *window, Key key, KeyMod mod, bool isPressed);
|
||||
static void char_input_stub(struct Window *window, unsigned int);
|
||||
static void mouse_btn_stub(struct Window *window, MouseButton button, KeyMod mod, bool isPressed);
|
||||
static void mouse_move_stub(struct Window *window, int x, int y);
|
||||
static void scroll_stub(struct Window *window, KeyMod mod, float deltaX, float deltaY);
|
||||
static void active_stub(struct mfb_window *window, bool isActive);
|
||||
static void resize_stub(struct mfb_window *window, int width, int height);
|
||||
static void keyboard_stub(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed);
|
||||
static void char_input_stub(struct mfb_window *window, unsigned int);
|
||||
static void mouse_btn_stub(struct mfb_window *window, mfb_mouse_button button, mfb_key_mod mod, bool isPressed);
|
||||
static void mouse_move_stub(struct mfb_window *window, int x, int y);
|
||||
static void scroll_stub(struct mfb_window *window, mfb_key_mod mod, float deltaX, float deltaY);
|
||||
|
||||
struct Window *m_window;
|
||||
std::function<void(struct Window *window, bool)> m_active;
|
||||
std::function<void(struct Window *window, int, int)> m_resize;
|
||||
std::function<void(struct Window *window, Key, KeyMod, bool)> m_keyboard;
|
||||
std::function<void(struct Window *window, unsigned int)> m_char_input;
|
||||
std::function<void(struct Window *window, MouseButton, KeyMod, bool)> m_mouse_btn;
|
||||
std::function<void(struct Window *window, int, int)> m_mouse_move;
|
||||
std::function<void(struct Window *window, KeyMod, float, float)> m_scroll;
|
||||
struct mfb_window *m_window;
|
||||
std::function<void(struct mfb_window *window, bool)> m_active;
|
||||
std::function<void(struct mfb_window *window, int, int)> m_resize;
|
||||
std::function<void(struct mfb_window *window, mfb_key, mfb_key_mod, bool)> m_keyboard;
|
||||
std::function<void(struct mfb_window *window, unsigned int)> m_char_input;
|
||||
std::function<void(struct mfb_window *window, mfb_mouse_button, mfb_key_mod, bool)> m_mouse_btn;
|
||||
std::function<void(struct mfb_window *window, int, int)> m_mouse_move;
|
||||
std::function<void(struct mfb_window *window, mfb_key_mod, float, float)> m_scroll;
|
||||
};
|
||||
|
||||
//-------------------------------------
|
||||
template <class T>
|
||||
inline void mfb_set_active_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, bool)) {
|
||||
inline void mfb_set_active_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *window, bool)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_active = std::bind(method, obj, _1, _2);
|
||||
mfb_set_active_callback(window, Stub::active_stub);
|
||||
mfb_set_active_callback(window, mfb_stub::active_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_set_resize_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, int, int)) {
|
||||
inline void mfb_set_resize_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *window, int, int)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_resize = std::bind(method, obj, _1, _2, _3);
|
||||
mfb_set_resize_callback(window, Stub::resize_stub);
|
||||
mfb_set_resize_callback(window, mfb_stub::resize_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_set_keyboard_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, Key, KeyMod, bool)) {
|
||||
inline void mfb_set_keyboard_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *window, mfb_key, mfb_key_mod, bool)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_keyboard = std::bind(method, obj, _1, _2, _3, _4);
|
||||
mfb_set_keyboard_callback(window, Stub::keyboard_stub);
|
||||
mfb_set_keyboard_callback(window, mfb_stub::keyboard_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_set_char_input_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, unsigned int)) {
|
||||
inline void mfb_set_char_input_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *window, unsigned int)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_char_input = std::bind(method, obj, _1, _2);
|
||||
mfb_set_char_input_callback(window, Stub::char_input_stub);
|
||||
mfb_set_char_input_callback(window, mfb_stub::char_input_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_set_mouse_button_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, MouseButton, KeyMod, bool)) {
|
||||
inline void mfb_set_mouse_button_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *window, mfb_mouse_button, mfb_key_mod, bool)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_mouse_btn = std::bind(method, obj, _1, _2, _3, _4);
|
||||
mfb_set_mouse_button_callback(window, Stub::mouse_btn_stub);
|
||||
mfb_set_mouse_button_callback(window, mfb_stub::mouse_btn_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_set_mouse_move_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, int, int)) {
|
||||
inline void mfb_set_mouse_move_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *window, int, int)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_mouse_move = std::bind(method, obj, _1, _2, _3);
|
||||
mfb_set_mouse_move_callback(window, Stub::mouse_move_stub);
|
||||
mfb_set_mouse_move_callback(window, mfb_stub::mouse_move_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_set_mouse_scroll_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, KeyMod, float, float)) {
|
||||
inline void mfb_set_mouse_scroll_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *window, mfb_key_mod, float, float)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_scroll = std::bind(method, obj, _1, _2, _3, _4);
|
||||
mfb_set_mouse_scroll_callback(window, Stub::scroll_stub);
|
||||
mfb_set_mouse_scroll_callback(window, mfb_stub::scroll_stub);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -10,7 +10,7 @@ typedef enum {
|
||||
STATE_INVALID_WINDOW = -2,
|
||||
STATE_INVALID_BUFFER = -3,
|
||||
STATE_INTERNAL_ERROR = -4,
|
||||
} UpdateState;
|
||||
} mfb_update_state;
|
||||
|
||||
typedef enum {
|
||||
MOUSE_BTN_0, // No mouse button
|
||||
@ -21,7 +21,7 @@ typedef enum {
|
||||
MOUSE_BTN_5,
|
||||
MOUSE_BTN_6,
|
||||
MOUSE_BTN_7,
|
||||
} MouseButton;
|
||||
} mfb_mouse_button;
|
||||
#define MOUSE_LEFT MOUSE_BTN_1
|
||||
#define MOUSE_RIGHT MOUSE_BTN_2
|
||||
#define MOUSE_MIDDLE MOUSE_BTN_3
|
||||
@ -150,7 +150,7 @@ typedef enum {
|
||||
KB_KEY_RIGHT_ALT = 346,
|
||||
KB_KEY_RIGHT_SUPER = 347,
|
||||
KB_KEY_MENU = 348
|
||||
} Key;
|
||||
} mfb_key;
|
||||
#define KB_KEY_LAST KB_KEY_MENU
|
||||
|
||||
typedef enum {
|
||||
@ -160,7 +160,7 @@ typedef enum {
|
||||
KB_MOD_SUPER = 0x0008,
|
||||
KB_MOD_CAPS_LOCK = 0x0010,
|
||||
KB_MOD_NUM_LOCK = 0x0020
|
||||
} KeyMod;
|
||||
} mfb_key_mod;
|
||||
|
||||
typedef enum {
|
||||
WF_RESIZABLE = 0x01,
|
||||
@ -168,17 +168,17 @@ typedef enum {
|
||||
WF_FULLSCREEN_DESKTOP = 0x04,
|
||||
WF_BORDERLESS = 0x08,
|
||||
WF_ALWAYS_ON_TOP = 0x10,
|
||||
} WindowFlags;
|
||||
} mfb_window_flags;
|
||||
|
||||
// Opaque pointer
|
||||
struct Window;
|
||||
struct mfb_window;
|
||||
|
||||
// Event callbacks
|
||||
typedef void(*mfb_active_func)(struct Window *window, bool isActive);
|
||||
typedef void(*mfb_resize_func)(struct Window *window, int width, int height);
|
||||
typedef void(*mfb_keyboard_func)(struct Window *window, Key key, KeyMod mod, bool isPressed);
|
||||
typedef void(*mfb_char_input_func)(struct Window *window, unsigned int code);
|
||||
typedef void(*mfb_mouse_button_func)(struct Window *window, MouseButton button, KeyMod mod, bool isPressed);
|
||||
typedef void(*mfb_mouse_move_func)(struct Window *window, int x, int y);
|
||||
typedef void(*mfb_mouse_scroll_func)(struct Window *window, KeyMod mod, float deltaX, float deltaY);
|
||||
typedef void(*mfb_active_func)(struct mfb_window *window, bool isActive);
|
||||
typedef void(*mfb_resize_func)(struct mfb_window *window, int width, int height);
|
||||
typedef void(*mfb_keyboard_func)(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed);
|
||||
typedef void(*mfb_char_input_func)(struct mfb_window *window, unsigned int code);
|
||||
typedef void(*mfb_mouse_button_func)(struct mfb_window *window, mfb_mouse_button button, mfb_key_mod mod, bool isPressed);
|
||||
typedef void(*mfb_mouse_move_func)(struct mfb_window *window, int x, int y);
|
||||
typedef void(*mfb_mouse_scroll_func)(struct mfb_window *window, mfb_key_mod mod, float deltaX, float deltaY);
|
||||
|
||||
|
@ -7,7 +7,8 @@ short int g_keycodes[512] = { 0 };
|
||||
//-------------------------------------
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_set_active_callback(struct Window *window, mfb_active_func callback) {
|
||||
void
|
||||
mfb_set_active_callback(struct mfb_window *window, mfb_active_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->active_func = callback;
|
||||
@ -15,7 +16,8 @@ void mfb_set_active_callback(struct Window *window, mfb_active_func callback) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_set_resize_callback(struct Window *window, mfb_resize_func callback) {
|
||||
void
|
||||
mfb_set_resize_callback(struct mfb_window *window, mfb_resize_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->resize_func = callback;
|
||||
@ -23,7 +25,8 @@ void mfb_set_resize_callback(struct Window *window, mfb_resize_func callback) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_set_keyboard_callback(struct Window *window, mfb_keyboard_func callback) {
|
||||
void
|
||||
mfb_set_keyboard_callback(struct mfb_window *window, mfb_keyboard_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->keyboard_func = callback;
|
||||
@ -31,7 +34,8 @@ void mfb_set_keyboard_callback(struct Window *window, mfb_keyboard_func callback
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_set_char_input_callback(struct Window *window, mfb_char_input_func callback) {
|
||||
void
|
||||
mfb_set_char_input_callback(struct mfb_window *window, mfb_char_input_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->char_input_func = callback;
|
||||
@ -39,7 +43,8 @@ void mfb_set_char_input_callback(struct Window *window, mfb_char_input_func call
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_set_mouse_button_callback(struct Window *window, mfb_mouse_button_func callback) {
|
||||
void
|
||||
mfb_set_mouse_button_callback(struct mfb_window *window, mfb_mouse_button_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->mouse_btn_func = callback;
|
||||
@ -47,7 +52,8 @@ void mfb_set_mouse_button_callback(struct Window *window, mfb_mouse_button_func
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_set_mouse_move_callback(struct Window *window, mfb_mouse_move_func callback) {
|
||||
void
|
||||
mfb_set_mouse_move_callback(struct mfb_window *window, mfb_mouse_move_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->mouse_move_func = callback;
|
||||
@ -55,7 +61,8 @@ void mfb_set_mouse_move_callback(struct Window *window, mfb_mouse_move_func call
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_set_mouse_scroll_callback(struct Window *window, mfb_mouse_scroll_func callback) {
|
||||
void
|
||||
mfb_set_mouse_scroll_callback(struct mfb_window *window, mfb_mouse_scroll_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->mouse_wheel_func = callback;
|
||||
@ -63,7 +70,8 @@ void mfb_set_mouse_scroll_callback(struct Window *window, mfb_mouse_scroll_func
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_set_user_data(struct Window *window, void *user_data) {
|
||||
void
|
||||
mfb_set_user_data(struct mfb_window *window, void *user_data) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->user_data = user_data;
|
||||
@ -71,7 +79,8 @@ void mfb_set_user_data(struct Window *window, void *user_data) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void *mfb_get_user_data(struct Window *window) {
|
||||
void *
|
||||
mfb_get_user_data(struct mfb_window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->user_data;
|
||||
@ -81,7 +90,8 @@ void *mfb_get_user_data(struct Window *window) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_close(struct Window *window) {
|
||||
void
|
||||
mfb_close(struct mfb_window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->close = true;
|
||||
@ -89,7 +99,8 @@ void mfb_close(struct Window *window) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void keyboard_default(struct Window *window, Key key, KeyMod mod, bool isPressed) {
|
||||
void
|
||||
keyboard_default(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed) {
|
||||
kUnused(mod);
|
||||
kUnused(isPressed);
|
||||
if (key == KB_KEY_ESCAPE) {
|
||||
@ -99,7 +110,8 @@ void keyboard_default(struct Window *window, Key key, KeyMod mod, bool isPressed
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
bool mfb_is_window_active(struct Window *window) {
|
||||
bool
|
||||
mfb_is_window_active(struct mfb_window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->is_active;
|
||||
@ -108,7 +120,8 @@ bool mfb_is_window_active(struct Window *window) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
unsigned mfb_get_window_width(struct Window *window) {
|
||||
unsigned
|
||||
mfb_get_window_width(struct mfb_window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->window_width;
|
||||
@ -117,7 +130,8 @@ unsigned mfb_get_window_width(struct Window *window) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
unsigned mfb_get_window_height(struct Window *window) {
|
||||
unsigned
|
||||
mfb_get_window_height(struct mfb_window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->window_height;
|
||||
@ -126,7 +140,8 @@ unsigned mfb_get_window_height(struct Window *window) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
int mfb_get_mouse_x(struct Window *window) {
|
||||
int
|
||||
mfb_get_mouse_x(struct mfb_window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->mouse_pos_x;
|
||||
@ -135,7 +150,8 @@ int mfb_get_mouse_x(struct Window *window) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
int mfb_get_mouse_y(struct Window *window) {
|
||||
int
|
||||
mfb_get_mouse_y(struct mfb_window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->mouse_pos_y;
|
||||
@ -144,7 +160,8 @@ int mfb_get_mouse_y(struct Window *window) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
float mfb_get_mouse_scroll_x(struct Window *window) {
|
||||
float
|
||||
mfb_get_mouse_scroll_x(struct mfb_window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->mouse_wheel_x;
|
||||
@ -153,7 +170,8 @@ float mfb_get_mouse_scroll_x(struct Window *window) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
float mfb_get_mouse_scroll_y(struct Window *window) {
|
||||
float
|
||||
mfb_get_mouse_scroll_y(struct mfb_window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->mouse_wheel_y;
|
||||
@ -162,7 +180,8 @@ float mfb_get_mouse_scroll_y(struct Window *window) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
const uint8_t * mfb_get_mouse_button_buffer(struct Window *window) {
|
||||
const uint8_t *
|
||||
mfb_get_mouse_button_buffer(struct mfb_window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->mouse_button_status;
|
||||
@ -171,7 +190,8 @@ const uint8_t * mfb_get_mouse_button_buffer(struct Window *window) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
const uint8_t * mfb_get_key_buffer(struct Window *window) {
|
||||
const uint8_t *
|
||||
mfb_get_key_buffer(struct mfb_window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->key_status;
|
||||
@ -179,10 +199,9 @@ const uint8_t * mfb_get_key_buffer(struct Window *window) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-------------------------------------
|
||||
const char * mfb_get_key_name(Key key) {
|
||||
const char *
|
||||
mfb_get_key_name(mfb_key key) {
|
||||
|
||||
switch (key)
|
||||
{
|
||||
|
@ -2,53 +2,68 @@
|
||||
#include <MiniFB_enums.h>
|
||||
#include <vector>
|
||||
|
||||
Stub *
|
||||
Stub::GetInstance(struct Window *window) {
|
||||
static std::vector<Stub *> s_instances;
|
||||
//-------------------------------------
|
||||
mfb_stub *
|
||||
mfb_stub::GetInstance(struct mfb_window *window) {
|
||||
static std::vector<mfb_stub *> s_instances;
|
||||
|
||||
for(Stub *instance : s_instances) {
|
||||
for(mfb_stub *instance : s_instances) {
|
||||
if(instance->m_window == window) {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
s_instances.push_back(new Stub);
|
||||
s_instances.push_back(new mfb_stub);
|
||||
s_instances.back()->m_window = window;
|
||||
|
||||
return s_instances.back();
|
||||
}
|
||||
|
||||
void Stub::active_stub(struct Window *window, bool isActive) {
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
//-------------------------------------
|
||||
void
|
||||
mfb_stub::active_stub(struct mfb_window *window, bool isActive) {
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_active(window, isActive);
|
||||
}
|
||||
|
||||
void Stub::resize_stub(struct Window *window, int width, int height) {
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
//-------------------------------------
|
||||
void
|
||||
mfb_stub::resize_stub(struct mfb_window *window, int width, int height) {
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_resize(window, width, height);
|
||||
}
|
||||
|
||||
void Stub::keyboard_stub(struct Window *window, Key key, KeyMod mod, bool isPressed) {
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
//-------------------------------------
|
||||
void
|
||||
mfb_stub::keyboard_stub(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed) {
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_keyboard(window, key, mod, isPressed);
|
||||
}
|
||||
|
||||
void Stub::char_input_stub(struct Window *window, unsigned int code) {
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
//-------------------------------------
|
||||
void
|
||||
mfb_stub::char_input_stub(struct mfb_window *window, unsigned int code) {
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_char_input(window, code);
|
||||
}
|
||||
|
||||
void Stub::mouse_btn_stub(struct Window *window, MouseButton button, KeyMod mod, bool isPressed) {
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
//-------------------------------------
|
||||
void
|
||||
mfb_stub::mouse_btn_stub(struct mfb_window *window, mfb_mouse_button button, mfb_key_mod mod, bool isPressed) {
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_mouse_btn(window, button, mod, isPressed);
|
||||
}
|
||||
|
||||
void Stub::mouse_move_stub(struct Window *window, int x, int y) {
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
//-------------------------------------
|
||||
void
|
||||
mfb_stub::mouse_move_stub(struct mfb_window *window, int x, int y) {
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_mouse_move(window, x, y);
|
||||
}
|
||||
|
||||
void Stub::scroll_stub(struct Window *window, KeyMod mod, float deltaX, float deltaY) {
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
//-------------------------------------
|
||||
void
|
||||
mfb_stub::scroll_stub(struct mfb_window *window, mfb_key_mod mod, float deltaX, float deltaY) {
|
||||
mfb_stub *stub = mfb_stub::GetInstance(window);
|
||||
stub->m_scroll(window, mod, deltaX, deltaY);
|
||||
}
|
||||
|
@ -4,7 +4,8 @@
|
||||
//#define kUseBilinearInterpolation
|
||||
|
||||
#if defined(kUseBilinearInterpolation)
|
||||
static uint32_t interpolate(uint32_t *srcImage, uint32_t x, uint32_t y, uint32_t srcOffsetX, uint32_t srcOffsetY, uint32_t srcWidth, uint32_t srcHeight, uint32_t srcPitch) {
|
||||
static uint32_t
|
||||
interpolate(uint32_t *srcImage, uint32_t x, uint32_t y, uint32_t srcOffsetX, uint32_t srcOffsetY, uint32_t srcWidth, uint32_t srcHeight, uint32_t srcPitch) {
|
||||
uint32_t incX = x + 1 < srcWidth ? 1 : 0;
|
||||
uint32_t incY = y + 1 < srcHeight ? srcPitch : 0;
|
||||
uint8_t *p00 = (uint8_t *) &srcImage[(srcOffsetX >> 16)];
|
||||
@ -38,7 +39,8 @@ static uint32_t interpolate(uint32_t *srcImage, uint32_t x, uint32_t y, uint32_t
|
||||
#endif
|
||||
|
||||
// Only for 32 bits images
|
||||
void stretch_image(uint32_t *srcImage, uint32_t srcX, uint32_t srcY, uint32_t srcWidth, uint32_t srcHeight, uint32_t srcPitch,
|
||||
void
|
||||
stretch_image(uint32_t *srcImage, uint32_t srcX, uint32_t srcY, uint32_t srcWidth, uint32_t srcHeight, uint32_t srcPitch,
|
||||
uint32_t *dstImage, uint32_t dstX, uint32_t dstY, uint32_t dstWidth, uint32_t dstHeight, uint32_t dstPitch) {
|
||||
|
||||
uint32_t x, y;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "MiniFB.h"
|
||||
#include "MiniFB_enums.h"
|
||||
|
||||
#define kCall(func, ...) if(window_data && window_data->func) window_data->func((struct Window *) window_data, __VA_ARGS__);
|
||||
#define kCall(func, ...) if(window_data && window_data->func) window_data->func((struct mfb_window *) window_data, __VA_ARGS__);
|
||||
#define kUnused(var) (void) var;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
@ -12,7 +12,7 @@ extern "C" {
|
||||
|
||||
extern short int g_keycodes[512];
|
||||
void init_keycodes();
|
||||
void keyboard_default(struct Window *window, Key key, KeyMod mod, bool isPressed);
|
||||
void keyboard_default(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
@ -85,7 +85,8 @@ NSString* g_shadersSrc = @
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(USE_METAL_API)
|
||||
static bool create_shaders(SWindowData_OSX *window_data_osx) {
|
||||
static bool
|
||||
create_shaders(SWindowData_OSX *window_data_osx) {
|
||||
// Error
|
||||
NSError* nsError = 0x0;
|
||||
NSError** nsErrorPtr = &nsError;
|
||||
@ -136,14 +137,16 @@ static bool create_shaders(SWindowData_OSX *window_data_osx) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Window *mfb_open(const char *title, unsigned width, unsigned height)
|
||||
struct mfb_window *
|
||||
mfb_open(const char *title, unsigned width, unsigned height)
|
||||
{
|
||||
return mfb_open_ex(title, width, height, 0);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Window *mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
||||
struct mfb_window *
|
||||
mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
||||
{
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@ -254,7 +257,7 @@ struct Window *mfb_open_ex(const char *title, unsigned width, unsigned height, u
|
||||
[NSApp finishLaunching];
|
||||
#endif
|
||||
|
||||
mfb_set_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
mfb_set_keyboard_callback((struct mfb_window *) window_data, keyboard_default);
|
||||
|
||||
#if defined(USE_METAL_API)
|
||||
NSLog(@"Window created using Metal API");
|
||||
@ -264,12 +267,13 @@ struct Window *mfb_open_ex(const char *title, unsigned width, unsigned height, u
|
||||
|
||||
[pool drain];
|
||||
|
||||
return (struct Window *) window_data;
|
||||
return (struct mfb_window *) window_data;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void destroy_window_data(SWindowData *window_data)
|
||||
static void
|
||||
destroy_window_data(SWindowData *window_data)
|
||||
{
|
||||
if(window_data == 0x0)
|
||||
return;
|
||||
@ -293,7 +297,8 @@ static void destroy_window_data(SWindowData *window_data)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void update_events(SWindowData *window_data)
|
||||
static void
|
||||
update_events(SWindowData *window_data)
|
||||
{
|
||||
NSEvent* event;
|
||||
|
||||
@ -312,7 +317,8 @@ static void update_events(SWindowData *window_data)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
UpdateState mfb_update(struct Window *window, void *buffer)
|
||||
mfb_update_state
|
||||
mfb_update(struct mfb_window *window, void *buffer)
|
||||
{
|
||||
if(window == 0x0) {
|
||||
return STATE_INVALID_WINDOW;
|
||||
@ -345,7 +351,8 @@ UpdateState mfb_update(struct Window *window, void *buffer)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
UpdateState mfb_update_events(struct Window *window)
|
||||
mfb_update_state
|
||||
mfb_update_events(struct mfb_window *window)
|
||||
{
|
||||
if(window == 0x0) {
|
||||
return STATE_INVALID_WINDOW;
|
||||
@ -368,7 +375,8 @@ UpdateState mfb_update_events(struct Window *window)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool mfb_set_viewport(struct Window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height)
|
||||
bool
|
||||
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height)
|
||||
{
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
|
||||
@ -410,7 +418,8 @@ bool mfb_set_viewport(struct Window *window, unsigned offset_x, unsigned offset_
|
||||
|
||||
extern short int g_keycodes[512];
|
||||
|
||||
void init_keycodes()
|
||||
void
|
||||
init_keycodes()
|
||||
{
|
||||
// Clear keys
|
||||
for (unsigned int i = 0; i < sizeof(g_keycodes) / sizeof(g_keycodes[0]); ++i)
|
||||
|
@ -136,7 +136,7 @@ keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t
|
||||
|
||||
SWindowData *window_data = (SWindowData *) data;
|
||||
if(key < 512) {
|
||||
Key key_code = (Key) g_keycodes[key];
|
||||
mfb_key key_code = (mfb_key) g_keycodes[key];
|
||||
bool is_pressed = (bool) (state == WL_KEYBOARD_KEY_STATE_PRESSED);
|
||||
switch (key_code)
|
||||
{
|
||||
@ -174,7 +174,7 @@ keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t
|
||||
}
|
||||
|
||||
window_data->key_status[key_code] = is_pressed;
|
||||
kCall(keyboard_func, key_code, (KeyMod)window_data->mod_keys, is_pressed);
|
||||
kCall(keyboard_func, key_code, (mfb_key_mod) window_data->mod_keys, is_pressed);
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,7 +210,8 @@ keyboard_repeat_info(void *data, struct wl_keyboard *keyboard, int32_t rate, int
|
||||
kUnused(delay);
|
||||
}
|
||||
|
||||
static const struct wl_keyboard_listener keyboard_listener = {
|
||||
static const struct
|
||||
wl_keyboard_listener keyboard_listener = {
|
||||
.keymap = keyboard_keymap,
|
||||
.enter = keyboard_enter,
|
||||
.leave = keyboard_leave,
|
||||
@ -319,7 +320,7 @@ pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t
|
||||
|
||||
//printf("Pointer button '%d'(%d)\n", button, state);
|
||||
SWindowData *window_data = (SWindowData *) data;
|
||||
kCall(mouse_btn_func, (MouseButton) (button - BTN_MOUSE + 1), (KeyMod) window_data->mod_keys, state == 1);
|
||||
kCall(mouse_btn_func, (mfb_mouse_button) (button - BTN_MOUSE + 1), (mfb_key_mod) window_data->mod_keys, state == 1);
|
||||
}
|
||||
|
||||
// Scroll and other axis notifications.
|
||||
@ -352,10 +353,10 @@ pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axi
|
||||
//printf("Pointer handle axis: axis: %d (0x%x)\n", axis, value);
|
||||
SWindowData *window_data = (SWindowData *) data;
|
||||
if(axis == 0) {
|
||||
kCall(mouse_wheel_func, (KeyMod) window_data->mod_keys, 0.0f, -(value / 256.0f));
|
||||
kCall(mouse_wheel_func, (mfb_key_mod) window_data->mod_keys, 0.0f, -(value / 256.0f));
|
||||
}
|
||||
else if(axis == 1) {
|
||||
kCall(mouse_wheel_func, (KeyMod) window_data->mod_keys, -(value / 256.0f), 0.0f);
|
||||
kCall(mouse_wheel_func, (mfb_key_mod) window_data->mod_keys, -(value / 256.0f), 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@ -388,7 +389,8 @@ axis_discrete(void *data, struct wl_pointer *pointer, uint32_t axis, int32_t dis
|
||||
kUnused(discrete);
|
||||
}
|
||||
|
||||
static const struct wl_pointer_listener pointer_listener = {
|
||||
static const struct
|
||||
wl_pointer_listener pointer_listener = {
|
||||
.enter = pointer_enter,
|
||||
.leave = pointer_leave,
|
||||
.motion = pointer_motion,
|
||||
@ -439,7 +441,8 @@ seat_name(void *data, struct wl_seat *seat, const char *name) {
|
||||
printf("Seat '%s'n", name);
|
||||
}
|
||||
|
||||
static const struct wl_seat_listener seat_listener = {
|
||||
static const struct
|
||||
wl_seat_listener seat_listener = {
|
||||
.capabilities = seat_capabilities,
|
||||
.name = 0x0,
|
||||
};
|
||||
@ -475,7 +478,8 @@ shm_format(void *data, struct wl_shm *shm, uint32_t format)
|
||||
}
|
||||
}
|
||||
|
||||
static const struct wl_shm_listener shm_listener = {
|
||||
static const struct
|
||||
wl_shm_listener shm_listener = {
|
||||
.format = shm_format
|
||||
};
|
||||
|
||||
@ -515,7 +519,8 @@ registry_global(void *data, struct wl_registry *registry, uint32_t id, char cons
|
||||
}
|
||||
}
|
||||
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
static const struct
|
||||
wl_registry_listener registry_listener = {
|
||||
.global = registry_global,
|
||||
.global_remove = 0x0,
|
||||
};
|
||||
@ -552,14 +557,14 @@ static const struct wl_shell_surface_listener shell_surface_listener = {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Window *
|
||||
struct mfb_window *
|
||||
mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags) {
|
||||
// TODO: Not yet
|
||||
kUnused(flags);
|
||||
return mfb_open(title, width, height);
|
||||
}
|
||||
|
||||
struct Window *
|
||||
struct mfb_window *
|
||||
mfb_open(const char *title, unsigned width, unsigned height)
|
||||
{
|
||||
int fd = -1;
|
||||
@ -662,11 +667,11 @@ mfb_open(const char *title, unsigned width, unsigned height)
|
||||
wl_surface_damage(window_data_way->surface, window_data->dst_offset_x, window_data->dst_offset_y, window_data->dst_width, window_data->dst_height);
|
||||
wl_surface_commit(window_data_way->surface);
|
||||
|
||||
mfb_set_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
mfb_set_keyboard_callback((struct mfb_window *) window_data, keyboard_default);
|
||||
|
||||
printf("Window created using Wayland API\n");
|
||||
|
||||
return (struct Window *) window_data;
|
||||
return (struct mfb_window *) window_data;
|
||||
|
||||
out:
|
||||
close(fd);
|
||||
@ -688,12 +693,13 @@ frame_done(void *data, struct wl_callback *callback, uint32_t cookie)
|
||||
*(uint32_t *)data = 1;
|
||||
}
|
||||
|
||||
static const struct wl_callback_listener frame_listener = {
|
||||
static const struct
|
||||
wl_callback_listener frame_listener = {
|
||||
.done = frame_done,
|
||||
};
|
||||
|
||||
UpdateState
|
||||
mfb_update(struct Window *window, void *buffer)
|
||||
mfb_update_state
|
||||
mfb_update(struct mfb_window *window, void *buffer)
|
||||
{
|
||||
uint32_t done = 0;
|
||||
|
||||
@ -739,8 +745,8 @@ mfb_update(struct Window *window, void *buffer)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
UpdateState
|
||||
mfb_update_events(struct Window *window)
|
||||
mfb_update_state
|
||||
mfb_update_events(struct mfb_window *window)
|
||||
{
|
||||
if(window == 0x0) {
|
||||
return STATE_INVALID_WINDOW;
|
||||
@ -896,7 +902,7 @@ init_keycodes(void)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool
|
||||
mfb_set_viewport(struct Window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
|
||||
|
@ -12,10 +12,11 @@ long s_window_style = WS_POPUP | WS_SYSMENU | WS_CAPTION;
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint32_t translate_mod();
|
||||
Key translate_key(unsigned int wParam, unsigned long lParam);
|
||||
mfb_key translate_key(unsigned int wParam, unsigned long lParam);
|
||||
void destroy_window_data(SWindowData *window_data);
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
LRESULT CALLBACK
|
||||
WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
LRESULT res = 0;
|
||||
|
||||
SWindowData *window_data = (SWindowData *) GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
||||
@ -69,7 +70,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case WM_SYSKEYUP:
|
||||
{
|
||||
if (window_data) {
|
||||
Key key_code = translate_key((unsigned int)wParam, (unsigned long)lParam);
|
||||
mfb_key key_code = translate_key((unsigned int)wParam, (unsigned long)lParam);
|
||||
int is_pressed = !((lParam >> 31) & 1);
|
||||
window_data->mod_keys = translate_mod();
|
||||
|
||||
@ -113,7 +114,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case WM_XBUTTONDBLCLK:
|
||||
{
|
||||
if (window_data) {
|
||||
MouseButton button = MOUSE_BTN_0;
|
||||
mfb_mouse_button button = MOUSE_BTN_0;
|
||||
window_data->mod_keys = translate_mod();
|
||||
int is_pressed = 0;
|
||||
switch(message) {
|
||||
@ -219,7 +220,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Window *mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags) {
|
||||
struct mfb_window *
|
||||
mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags) {
|
||||
RECT rect = { 0 };
|
||||
int x = 0, y = 0;
|
||||
|
||||
@ -357,18 +359,20 @@ struct Window *mfb_open_ex(const char *title, unsigned width, unsigned height, u
|
||||
|
||||
window_data_win->hdc = GetDC(window_data_win->window);
|
||||
|
||||
mfb_set_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
mfb_set_keyboard_callback((struct mfb_window *) window_data, keyboard_default);
|
||||
|
||||
return (struct Window *) window_data;
|
||||
return (struct mfb_window *) window_data;
|
||||
}
|
||||
|
||||
struct Window *mfb_open(const char *title, unsigned width, unsigned height) {
|
||||
struct mfb_window *
|
||||
mfb_open(const char *title, unsigned width, unsigned height) {
|
||||
return mfb_open_ex(title, width, height, 0);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
UpdateState mfb_update(struct Window *window, void *buffer) {
|
||||
mfb_update_state
|
||||
mfb_update(struct mfb_window *window, void *buffer) {
|
||||
MSG msg;
|
||||
|
||||
if (window == 0x0) {
|
||||
@ -401,7 +405,8 @@ UpdateState mfb_update(struct Window *window, void *buffer) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
UpdateState mfb_update_events(struct Window *window) {
|
||||
mfb_update_state
|
||||
mfb_update_events(struct mfb_window *window) {
|
||||
MSG msg;
|
||||
|
||||
if (window == 0x0) {
|
||||
@ -428,7 +433,8 @@ UpdateState mfb_update_events(struct Window *window) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void destroy_window_data(SWindowData *window_data) {
|
||||
void
|
||||
destroy_window_data(SWindowData *window_data) {
|
||||
if (window_data == 0x0)
|
||||
return;
|
||||
|
||||
@ -452,7 +458,8 @@ void destroy_window_data(SWindowData *window_data) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint32_t translate_mod() {
|
||||
uint32_t
|
||||
translate_mod() {
|
||||
uint32_t mods = 0;
|
||||
|
||||
if (GetKeyState(VK_SHIFT) & 0x8000)
|
||||
@ -475,7 +482,8 @@ uint32_t translate_mod() {
|
||||
|
||||
extern short int g_keycodes[512];
|
||||
|
||||
void init_keycodes() {
|
||||
void
|
||||
init_keycodes() {
|
||||
|
||||
// Clear keys
|
||||
for (size_t i = 0; i < sizeof(g_keycodes) / sizeof(g_keycodes[0]); ++i)
|
||||
@ -606,7 +614,8 @@ void init_keycodes() {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Key translate_key(unsigned int wParam, unsigned long lParam) {
|
||||
mfb_key
|
||||
translate_key(unsigned int wParam, unsigned long lParam) {
|
||||
if (wParam == VK_CONTROL) {
|
||||
MSG next;
|
||||
DWORD time;
|
||||
@ -626,12 +635,13 @@ Key translate_key(unsigned int wParam, unsigned long lParam) {
|
||||
if (wParam == VK_PROCESSKEY)
|
||||
return KB_KEY_UNKNOWN;
|
||||
|
||||
return (Key) g_keycodes[HIWORD(lParam) & 0x1FF];
|
||||
return (mfb_key) g_keycodes[HIWORD(lParam) & 0x1FF];
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool mfb_set_viewport(struct Window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||
bool
|
||||
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
|
||||
if (offset_x + width > window_data->window_width) {
|
||||
|
@ -20,7 +20,7 @@ stretch_image(uint32_t *srcImage, uint32_t srcX, uint32_t srcY, uint32_t srcWidt
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Window *
|
||||
struct mfb_window *
|
||||
mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags) {
|
||||
int depth, i, formatCount, convDepth = -1;
|
||||
XPixmapFormatValues* formats;
|
||||
@ -185,14 +185,14 @@ mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
||||
|
||||
window_data_x11->image = XCreateImage(window_data_x11->display, CopyFromParent, depth, ZPixmap, 0, 0x0, width, height, 32, width * 4);
|
||||
|
||||
mfb_set_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
mfb_set_keyboard_callback((struct mfb_window *) window_data, keyboard_default);
|
||||
|
||||
printf("Window created using X11 API\n");
|
||||
|
||||
return (struct Window *) window_data;
|
||||
return (struct mfb_window *) window_data;
|
||||
}
|
||||
|
||||
struct Window *
|
||||
struct mfb_window *
|
||||
mfb_open(const char *title, unsigned width, unsigned height) {
|
||||
return mfb_open_ex(title, width, height, 0);
|
||||
}
|
||||
@ -203,7 +203,8 @@ int translate_key(int scancode);
|
||||
int translate_mod(int state);
|
||||
int translate_mod_ex(int key, int state, int is_pressed);
|
||||
|
||||
static void processEvents(SWindowData *window_data) {
|
||||
static void
|
||||
processEvents(SWindowData *window_data) {
|
||||
XEvent event;
|
||||
SWindowData_X11 *window_data_x11 = (SWindowData_X11 *) window_data->specific;
|
||||
|
||||
@ -214,44 +215,44 @@ static void processEvents(SWindowData *window_data) {
|
||||
case KeyPress:
|
||||
case KeyRelease:
|
||||
{
|
||||
Key key_code = (Key) translate_key(event.xkey.keycode);
|
||||
mfb_key key_code = (mfb_key) translate_key(event.xkey.keycode);
|
||||
int is_pressed = (event.type == KeyPress);
|
||||
window_data->mod_keys = translate_mod_ex(key_code, event.xkey.state, is_pressed);
|
||||
|
||||
window_data->key_status[key_code] = is_pressed;
|
||||
kCall(keyboard_func, key_code, (KeyMod) window_data->mod_keys, is_pressed);
|
||||
kCall(keyboard_func, key_code, (mfb_key_mod) window_data->mod_keys, is_pressed);
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonPress:
|
||||
case ButtonRelease:
|
||||
{
|
||||
MouseButton button = (MouseButton) event.xbutton.button;
|
||||
mfb_mouse_button button = (mfb_mouse_button) event.xbutton.button;
|
||||
int is_pressed = (event.type == ButtonPress);
|
||||
window_data->mod_keys = translate_mod(event.xkey.state);
|
||||
switch (button) {
|
||||
case Button1:
|
||||
case Button2:
|
||||
case Button3:
|
||||
kCall(mouse_btn_func, button, (KeyMod) window_data->mod_keys, is_pressed);
|
||||
kCall(mouse_btn_func, button, (mfb_key_mod) window_data->mod_keys, is_pressed);
|
||||
break;
|
||||
|
||||
case Button4:
|
||||
kCall(mouse_wheel_func, (KeyMod) window_data->mod_keys, 0.0f, 1.0f);
|
||||
kCall(mouse_wheel_func, (mfb_key_mod) window_data->mod_keys, 0.0f, 1.0f);
|
||||
break;
|
||||
case Button5:
|
||||
kCall(mouse_wheel_func, (KeyMod) window_data->mod_keys, 0.0f, -1.0f);
|
||||
kCall(mouse_wheel_func, (mfb_key_mod) window_data->mod_keys, 0.0f, -1.0f);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
kCall(mouse_wheel_func, (KeyMod) window_data->mod_keys, 1.0f, 0.0f);
|
||||
kCall(mouse_wheel_func, (mfb_key_mod) window_data->mod_keys, 1.0f, 0.0f);
|
||||
break;
|
||||
case 7:
|
||||
kCall(mouse_wheel_func, (KeyMod) window_data->mod_keys, -1.0f, 0.0f);
|
||||
kCall(mouse_wheel_func, (mfb_key_mod) window_data->mod_keys, -1.0f, 0.0f);
|
||||
break;
|
||||
|
||||
default:
|
||||
kCall(mouse_btn_func, (MouseButton) (button - 4), (KeyMod) window_data->mod_keys, is_pressed);
|
||||
kCall(mouse_btn_func, (mfb_mouse_button) (button - 4), (mfb_key_mod) window_data->mod_keys, is_pressed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -303,7 +304,8 @@ static void processEvents(SWindowData *window_data) {
|
||||
|
||||
void destroy(SWindowData *window_data);
|
||||
|
||||
UpdateState mfb_update(struct Window *window, void *buffer) {
|
||||
mfb_update_state
|
||||
mfb_update(struct mfb_window *window, void *buffer) {
|
||||
if (window == 0x0) {
|
||||
return STATE_INVALID_WINDOW;
|
||||
}
|
||||
@ -358,7 +360,8 @@ UpdateState mfb_update(struct Window *window, void *buffer) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
UpdateState mfb_update_events(struct Window *window) {
|
||||
mfb_update_state
|
||||
mfb_update_events(struct mfb_window *window) {
|
||||
if (window == 0x0) {
|
||||
return STATE_INVALID_WINDOW;
|
||||
}
|
||||
@ -378,7 +381,8 @@ UpdateState mfb_update_events(struct Window *window) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void destroy(SWindowData *window_data) {
|
||||
void
|
||||
destroy(SWindowData *window_data) {
|
||||
if (window_data != 0x0) {
|
||||
if (window_data->specific != 0x0) {
|
||||
SWindowData_X11 *window_data_x11 = (SWindowData_X11 *) window_data->specific;
|
||||
@ -400,7 +404,8 @@ void destroy(SWindowData *window_data) {
|
||||
|
||||
extern short int g_keycodes[512];
|
||||
|
||||
static int translateKeyCodeB(int keySym) {
|
||||
static int
|
||||
translateKeyCodeB(int keySym) {
|
||||
|
||||
switch (keySym)
|
||||
{
|
||||
@ -563,7 +568,8 @@ static int translateKeyCodeA(int keySym) {
|
||||
return KB_KEY_UNKNOWN;
|
||||
}
|
||||
|
||||
void init_keycodes(SWindowData_X11 *window_data_x11) {
|
||||
void
|
||||
init_keycodes(SWindowData_X11 *window_data_x11) {
|
||||
size_t i;
|
||||
int keySym;
|
||||
|
||||
@ -585,7 +591,8 @@ void init_keycodes(SWindowData_X11 *window_data_x11) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int translate_key(int scancode) {
|
||||
int
|
||||
translate_key(int scancode) {
|
||||
if (scancode < 0 || scancode > 255)
|
||||
return KB_KEY_UNKNOWN;
|
||||
|
||||
@ -594,7 +601,8 @@ int translate_key(int scancode) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int translate_mod(int state) {
|
||||
int
|
||||
translate_mod(int state) {
|
||||
int mod_keys = 0;
|
||||
|
||||
if (state & ShiftMask)
|
||||
@ -615,7 +623,8 @@ int translate_mod(int state) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int translate_mod_ex(int key, int state, int is_pressed) {
|
||||
int
|
||||
translate_mod_ex(int key, int state, int is_pressed) {
|
||||
int mod_keys = 0;
|
||||
|
||||
mod_keys = translate_mod(state);
|
||||
@ -660,7 +669,8 @@ int translate_mod_ex(int key, int state, int is_pressed) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool mfb_set_viewport(struct Window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||
bool
|
||||
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
|
||||
if (offset_x + width > window_data->window_width) {
|
||||
|
@ -11,7 +11,8 @@ static bool g_active = true;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void active(struct Window *window, bool isActive) {
|
||||
void
|
||||
active(struct mfb_window *window, bool isActive) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
@ -20,7 +21,8 @@ void active(struct Window *window, bool isActive) {
|
||||
g_active = isActive;
|
||||
}
|
||||
|
||||
void resize(struct Window *window, int width, int height) {
|
||||
void
|
||||
resize(struct mfb_window *window, int width, int height) {
|
||||
uint32_t x = 0;
|
||||
uint32_t y = 0;
|
||||
const char *window_title = "";
|
||||
@ -40,18 +42,20 @@ void resize(struct Window *window, int width, int height) {
|
||||
mfb_set_viewport(window, x, y, width, height);
|
||||
}
|
||||
|
||||
void keyboard(struct Window *window, Key key, KeyMod mod, bool isPressed) {
|
||||
void
|
||||
keyboard(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [KeyMod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [key_mod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
if(key == KB_KEY_ESCAPE) {
|
||||
mfb_close(window);
|
||||
}
|
||||
}
|
||||
|
||||
void char_input(struct Window *window, unsigned int charCode) {
|
||||
void
|
||||
char_input(struct mfb_window *window, unsigned int charCode) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
@ -59,15 +63,17 @@ void char_input(struct Window *window, unsigned int charCode) {
|
||||
fprintf(stdout, "%s > charCode: %d\n", window_title, charCode);
|
||||
}
|
||||
|
||||
void mouse_btn(struct Window *window, MouseButton button, KeyMod mod, bool isPressed) {
|
||||
void
|
||||
mouse_btn(struct mfb_window *window, mfb_mouse_button button, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [KeyMod: %x]\n", window_title, button, isPressed, mod);
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [key_mod: %x]\n", window_title, button, isPressed, mod);
|
||||
}
|
||||
|
||||
void mouse_move(struct Window *window, int x, int y) {
|
||||
void
|
||||
mouse_move(struct mfb_window *window, int x, int y) {
|
||||
kUnused(window);
|
||||
kUnused(x);
|
||||
kUnused(y);
|
||||
@ -78,21 +84,23 @@ void mouse_move(struct Window *window, int x, int y) {
|
||||
//fprintf(stdout, "%s > mouse_move: %d, %d\n", window_title, x, y);
|
||||
}
|
||||
|
||||
void mouse_scroll(struct Window *window, KeyMod mod, float deltaX, float deltaY) {
|
||||
void
|
||||
mouse_scroll(struct mfb_window *window, mfb_key_mod mod, float deltaX, float deltaY) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [KeyMod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [key_mod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main()
|
||||
int
|
||||
main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct Window *window = mfb_open_ex("Input Events Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
struct mfb_window *window = mfb_open_ex("Input Events Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
@ -109,7 +117,7 @@ int main()
|
||||
for (;;)
|
||||
{
|
||||
int i;
|
||||
UpdateState state;
|
||||
mfb_update_state state;
|
||||
|
||||
if(g_active)
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ static unsigned int g_buffer[WIDTH * HEIGHT];
|
||||
|
||||
class Events {
|
||||
public:
|
||||
void active(struct Window *window, bool isActive) {
|
||||
void active(struct mfb_window *window, bool isActive) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
@ -20,7 +20,7 @@ public:
|
||||
fprintf(stdout, "%s > active: %d\n", window_title, isActive);
|
||||
}
|
||||
|
||||
void resize(struct Window *window, int width, int height) {
|
||||
void resize(struct mfb_window *window, int width, int height) {
|
||||
uint32_t x = 0;
|
||||
uint32_t y = 0;
|
||||
const char *window_title = "";
|
||||
@ -40,18 +40,18 @@ public:
|
||||
mfb_set_viewport(window, x, y, width, height);
|
||||
}
|
||||
|
||||
void keyboard(struct Window *window, Key key, KeyMod mod, bool isPressed) {
|
||||
void keyboard(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [KeyMod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [key_mod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
if(key == KB_KEY_ESCAPE) {
|
||||
mfb_close(window);
|
||||
}
|
||||
}
|
||||
|
||||
void char_input(struct Window *window, unsigned int charCode) {
|
||||
void char_input(struct mfb_window *window, unsigned int charCode) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
@ -59,15 +59,15 @@ public:
|
||||
fprintf(stdout, "%s > charCode: %d\n", window_title, charCode);
|
||||
}
|
||||
|
||||
void mouse_btn(struct Window *window, MouseButton button, KeyMod mod, bool isPressed) {
|
||||
void mouse_btn(struct mfb_window *window, mfb_mouse_button button, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [KeyMod: %x]\n", window_title, button, isPressed, mod);
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [key_mod: %x]\n", window_title, button, isPressed, mod);
|
||||
}
|
||||
|
||||
void mouse_move(struct Window *window, int x, int y) {
|
||||
void mouse_move(struct mfb_window *window, int x, int y) {
|
||||
kUnused(window);
|
||||
kUnused(x);
|
||||
kUnused(y);
|
||||
@ -78,22 +78,23 @@ public:
|
||||
//fprintf(stdout, "%s > mouse_move: %d, %d\n", window_title, x, y);
|
||||
}
|
||||
|
||||
void mouse_scroll(struct Window *window, KeyMod mod, float deltaX, float deltaY) {
|
||||
void mouse_scroll(struct mfb_window *window, mfb_key_mod mod, float deltaX, float deltaY) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [KeyMod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [key_mod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main()
|
||||
int
|
||||
main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct Window *window = mfb_open_ex("Input Events CPP Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
struct mfb_window *window = mfb_open_ex("Input Events CPP Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
@ -112,7 +113,7 @@ int main()
|
||||
for (;;)
|
||||
{
|
||||
int i;
|
||||
UpdateState state;
|
||||
mfb_update_state state;
|
||||
|
||||
for (i = 0; i < WIDTH * HEIGHT; ++i)
|
||||
{
|
||||
|
@ -17,7 +17,8 @@ static unsigned int g_buffer_b[WIDTH_B * HEIGHT_B];
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void active(struct Window *window, bool isActive) {
|
||||
void
|
||||
active(struct mfb_window *window, bool isActive) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
@ -25,7 +26,8 @@ void active(struct Window *window, bool isActive) {
|
||||
fprintf(stdout, "%s > active: %d\n", window_title, isActive);
|
||||
}
|
||||
|
||||
void resize(struct Window *window, int width, int height) {
|
||||
void
|
||||
resize(struct mfb_window *window, int width, int height) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
@ -34,18 +36,20 @@ void resize(struct Window *window, int width, int height) {
|
||||
fprintf(stdout, "%s > resize: %d, %d\n", window_title, width, height);
|
||||
}
|
||||
|
||||
void keyboard(struct Window *window, Key key, KeyMod mod, bool isPressed) {
|
||||
void
|
||||
keyboard(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [KeyMod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
fprintf(stdout, "%s > keyboard: key: %s (pressed: %d) [key_mod: %x]\n", window_title, mfb_get_key_name(key), isPressed, mod);
|
||||
if(key == KB_KEY_ESCAPE) {
|
||||
mfb_close(window);
|
||||
}
|
||||
}
|
||||
|
||||
void char_input(struct Window *window, unsigned int charCode) {
|
||||
void
|
||||
char_input(struct mfb_window *window, unsigned int charCode) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
@ -53,15 +57,17 @@ void char_input(struct Window *window, unsigned int charCode) {
|
||||
fprintf(stdout, "%s > charCode: %d\n", window_title, charCode);
|
||||
}
|
||||
|
||||
void mouse_btn(struct Window *window, MouseButton button, KeyMod mod, bool isPressed) {
|
||||
void
|
||||
mouse_btn(struct mfb_window *window, mfb_mouse_button button, mfb_key_mod mod, bool isPressed) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [KeyMod: %x]\n", window_title, button, isPressed, mod);
|
||||
fprintf(stdout, "%s > mouse_btn: button: %d (pressed: %d) [key_mod: %x]\n", window_title, button, isPressed, mod);
|
||||
}
|
||||
|
||||
void mouse_move(struct Window *window, int x, int y) {
|
||||
void
|
||||
mouse_move(struct mfb_window *window, int x, int y) {
|
||||
kUnused(window);
|
||||
kUnused(x);
|
||||
kUnused(y);
|
||||
@ -72,21 +78,23 @@ void mouse_move(struct Window *window, int x, int y) {
|
||||
//fprintf(stdout, "%s > mouse_move: %d, %d\n", window_title, x, y);
|
||||
}
|
||||
|
||||
void mouse_scroll(struct Window *window, KeyMod mod, float deltaX, float deltaY) {
|
||||
void
|
||||
mouse_scroll(struct mfb_window *window, mfb_key_mod mod, float deltaX, float deltaY) {
|
||||
const char *window_title = "";
|
||||
if(window) {
|
||||
window_title = (const char *) mfb_get_user_data(window);
|
||||
}
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [KeyMod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
fprintf(stdout, "%s > mouse_scroll: x: %f, y: %f [key_mod: %x]\n", window_title, deltaX, deltaY, mod);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main()
|
||||
int
|
||||
main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct Window *window_a = mfb_open_ex("Multiple Windows Test", WIDTH_A, HEIGHT_A, WF_RESIZABLE);
|
||||
struct mfb_window *window_a = mfb_open_ex("Multiple Windows Test", WIDTH_A, HEIGHT_A, WF_RESIZABLE);
|
||||
if (!window_a)
|
||||
return 0;
|
||||
|
||||
@ -101,7 +109,7 @@ int main()
|
||||
mfb_set_user_data(window_a, (void *) "Window A");
|
||||
|
||||
//--
|
||||
struct Window *window_b = mfb_open_ex("Secondary Window", WIDTH_B, HEIGHT_B, WF_RESIZABLE);
|
||||
struct mfb_window *window_b = mfb_open_ex("Secondary Window", WIDTH_B, HEIGHT_B, WF_RESIZABLE);
|
||||
if (!window_b)
|
||||
return 0;
|
||||
|
||||
@ -137,7 +145,8 @@ int main()
|
||||
int i, x, y;
|
||||
float dx, dy, time_x, time_y;
|
||||
int index;
|
||||
UpdateState state_a, state_b;
|
||||
|
||||
mfb_update_state state_a, state_b;
|
||||
|
||||
for (i = 0; i < WIDTH_A * HEIGHT_A; ++i)
|
||||
{
|
||||
|
@ -8,18 +8,19 @@ static unsigned int g_buffer[WIDTH * HEIGHT];
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main()
|
||||
int
|
||||
main()
|
||||
{
|
||||
int noise, carry, seed = 0xbeef;
|
||||
|
||||
struct Window *window = mfb_open_ex("Noise Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
struct mfb_window *window = mfb_open_ex("Noise Test", WIDTH, HEIGHT, WF_RESIZABLE);
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int i;
|
||||
UpdateState state;
|
||||
mfb_update_state state;
|
||||
|
||||
for (i = 0; i < WIDTH * HEIGHT; ++i)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user