Direct mode (#23)
* update documentation * Fix typo * Added some examples * changed window names * Minor fix * renamed callback setters (added _set_) Direct / Poll Mode for asking events: 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_scrool_x(struct Window *window); // Mouse wheel X as a sum. When you call this function it resets. float mfb_get_mouse_scrool_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. const uint8_t * mfb_get_key_buffer(struct Window *window); // One byte for every key. Press (1), Release 0. * Minor fixes * Fixes related to mouse poll * Minor fix on Win64
This commit is contained in:
parent
25a440f822
commit
cdaa54f5d6
14
README.md
14
README.md
@ -62,13 +62,13 @@ Furthermore, you can add callbacks to the windows:
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
mfb_active_callback(window, active);
|
||||
mfb_resize_callback(window, resize);
|
||||
mfb_keyboard_callback(window, keyboard);
|
||||
mfb_char_input_callback(window, char_input);
|
||||
mfb_mouse_button_callback(window, mouse_btn);
|
||||
mfb_mouse_move_callback(window, mouse_move);
|
||||
mfb_mouse_scroll_callback(window, mouse_scroll);
|
||||
mfb_set_active_callback(window, active);
|
||||
mfb_set_resize_callback(window, resize);
|
||||
mfb_set_keyboard_callback(window, keyboard);
|
||||
mfb_set_char_input_callback(window, char_input);
|
||||
mfb_set_mouse_button_callback(window, mouse_btn);
|
||||
mfb_set_mouse_move_callback(window, mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window, mouse_scroll);
|
||||
|
||||
|
||||
Additionally you can set data per window and recover it
|
||||
|
@ -9,13 +9,13 @@ extern "C" {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define MFB_RGB(r, g, b) (((unsigned int) r) << 16) | (((unsigned int) g) << 8) | (b)
|
||||
#define MFB_RGB(r, g, b) (((uint32_t) r) << 16) | (((uint32_t) g) << 8) | ((uint32_t) b)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 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, int width, int height);
|
||||
struct Window *mfb_open_ex(const char *title, int width, int height, int flags);
|
||||
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);
|
||||
|
||||
// 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.
|
||||
@ -31,16 +31,26 @@ void *mfb_get_user_data(struct Window *window);
|
||||
// Set viewport (useful when resize)
|
||||
bool mfb_set_viewport(struct Window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height);
|
||||
|
||||
void mfb_active_callback(struct Window *window, mfb_active_func callback);
|
||||
void mfb_resize_callback(struct Window *window, mfb_resize_func callback);
|
||||
void mfb_keyboard_callback(struct Window *window, mfb_keyboard_func callback);
|
||||
void mfb_char_input_callback(struct Window *window, mfb_char_input_func callback);
|
||||
void mfb_mouse_button_callback(struct Window *window, mfb_mouse_btn_func callback);
|
||||
void mfb_mouse_move_callback(struct Window *window, mfb_mouse_move_func callback);
|
||||
void mfb_mouse_scroll_callback(struct Window *window, mfb_mouse_scroll_func callback);
|
||||
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);
|
||||
|
||||
const char * mfb_get_key_name(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_scrool_x(struct Window *window); // Mouse wheel X as a sum. When you call this function it resets.
|
||||
float mfb_get_mouse_scrool_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.
|
||||
const uint8_t * mfb_get_key_buffer(struct Window *window); // One byte for every key. Press (1), Release 0.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -6,46 +6,48 @@
|
||||
#include "MiniFB.h"
|
||||
|
||||
template <class T>
|
||||
void mfb_active_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, bool));
|
||||
void mfb_set_active_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, bool));
|
||||
|
||||
template <class T>
|
||||
void mfb_resize_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
void mfb_set_resize_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
|
||||
template <class T>
|
||||
void mfb_keyboard_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, Key, KeyMod, bool));
|
||||
void mfb_set_keyboard_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, Key, KeyMod, bool));
|
||||
|
||||
template <class T>
|
||||
void mfb_char_input_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, unsigned int));
|
||||
void mfb_set_char_input_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, unsigned int));
|
||||
|
||||
template <class T>
|
||||
void mfb_mouse_button_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, MouseButton, KeyMod, bool));
|
||||
void mfb_set_mouse_button_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, MouseButton, KeyMod, bool));
|
||||
|
||||
template <class T>
|
||||
void mfb_mouse_move_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
void mfb_set_mouse_move_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
|
||||
template <class T>
|
||||
void mfb_mouse_scroll_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, KeyMod, float, float));
|
||||
void mfb_set_mouse_scroll_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, KeyMod, float, float));
|
||||
|
||||
//-------------------------------------
|
||||
// To avoid clumsy hands
|
||||
//-------------------------------------
|
||||
class Stub {
|
||||
Stub() : m_window(0x0) {}
|
||||
|
||||
template <class T>
|
||||
friend void mfb_active_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, bool));
|
||||
friend void mfb_set_active_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, bool));
|
||||
template <class T>
|
||||
friend void mfb_resize_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
friend void mfb_set_resize_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
template <class T>
|
||||
friend void mfb_mouse_button_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, MouseButton, KeyMod, bool));
|
||||
friend void mfb_set_mouse_button_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, MouseButton, KeyMod, bool));
|
||||
template <class T>
|
||||
friend void mfb_keyboard_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, Key, KeyMod, bool));
|
||||
friend void mfb_set_keyboard_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, Key, KeyMod, bool));
|
||||
template <class T>
|
||||
friend void mfb_char_input_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, unsigned int));
|
||||
friend void mfb_set_char_input_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, unsigned int));
|
||||
template <class T>
|
||||
friend void mfb_mouse_button_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, MouseButton, KeyMod, bool));
|
||||
friend void mfb_set_mouse_button_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, MouseButton, KeyMod, bool));
|
||||
template <class T>
|
||||
friend void mfb_mouse_move_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
friend void mfb_set_mouse_move_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, int, int));
|
||||
template <class T>
|
||||
friend void mfb_mouse_scroll_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, KeyMod, float, float));
|
||||
friend void mfb_set_mouse_scroll_callback(struct Window *window, T *obj, void (T::*method)(struct Window *, KeyMod, float, float));
|
||||
|
||||
static Stub *GetInstance(struct Window *window);
|
||||
|
||||
@ -69,66 +71,66 @@ class Stub {
|
||||
|
||||
//-------------------------------------
|
||||
template <class T>
|
||||
inline void mfb_active_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, bool)) {
|
||||
inline void mfb_set_active_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, bool)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
stub->m_active = std::bind(method, obj, _1, _2);
|
||||
mfb_active_callback(window, Stub::active_stub);
|
||||
mfb_set_active_callback(window, Stub::active_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_resize_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, int, int)) {
|
||||
inline void mfb_set_resize_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, int, int)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
stub->m_resize = std::bind(method, obj, _1, _2, _3);
|
||||
mfb_resize_callback(window, Stub::resize_stub);
|
||||
mfb_set_resize_callback(window, Stub::resize_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_keyboard_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, Key, KeyMod, bool)) {
|
||||
inline void mfb_set_keyboard_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, Key, KeyMod, bool)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
stub->m_keyboard = std::bind(method, obj, _1, _2, _3, _4);
|
||||
mfb_keyboard_callback(window, Stub::keyboard_stub);
|
||||
mfb_set_keyboard_callback(window, Stub::keyboard_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_char_input_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, unsigned int)) {
|
||||
inline void mfb_set_char_input_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, unsigned int)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
stub->m_char_input = std::bind(method, obj, _1, _2);
|
||||
mfb_char_input_callback(window, Stub::char_input_stub);
|
||||
mfb_set_char_input_callback(window, Stub::char_input_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_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 Window *window, T *obj, void (T::*method)(struct Window *window, MouseButton, KeyMod, bool)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
stub->m_mouse_btn = std::bind(method, obj, _1, _2, _3, _4);
|
||||
mfb_mouse_button_callback(window, Stub::mouse_btn_stub);
|
||||
mfb_set_mouse_button_callback(window, Stub::mouse_btn_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_mouse_move_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, int, int)) {
|
||||
inline void mfb_set_mouse_move_callback(struct Window *window, T *obj, void (T::*method)(struct Window *window, int, int)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
stub->m_mouse_move = std::bind(method, obj, _1, _2, _3);
|
||||
mfb_mouse_move_callback(window, Stub::mouse_move_stub);
|
||||
mfb_set_mouse_move_callback(window, Stub::mouse_move_stub);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void mfb_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 Window *window, T *obj, void (T::*method)(struct Window *window, KeyMod, float, float)) {
|
||||
using namespace std::placeholders;
|
||||
|
||||
Stub *stub = Stub::GetInstance(window);
|
||||
stub->m_scroll = std::bind(method, obj, _1, _2, _3, _4);
|
||||
mfb_mouse_scroll_callback(window, Stub::scroll_stub);
|
||||
mfb_set_mouse_scroll_callback(window, Stub::scroll_stub);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// Enums
|
||||
@ -20,12 +21,10 @@ typedef enum {
|
||||
MOUSE_BTN_5,
|
||||
MOUSE_BTN_6,
|
||||
MOUSE_BTN_7,
|
||||
MOUSE_BTN_8
|
||||
} MouseButton;
|
||||
#define MOUSE_LAST MOUSE_BTN_8
|
||||
#define MOUSE_LEFT MOUSE_BTN_0
|
||||
#define MOUSE_RIGHT MOUSE_BTN_1
|
||||
#define MOUSE_MIDDLE MOUSE_BTN_2
|
||||
#define MOUSE_LEFT MOUSE_BTN_1
|
||||
#define MOUSE_RIGHT MOUSE_BTN_2
|
||||
#define MOUSE_MIDDLE MOUSE_BTN_3
|
||||
|
||||
typedef enum {
|
||||
KB_KEY_UNKNOWN = -1,
|
||||
@ -179,7 +178,7 @@ 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_btn_func)(struct Window *window, MouseButton button, KeyMod mod, bool isPressed);
|
||||
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);
|
||||
|
||||
|
@ -3,7 +3,11 @@
|
||||
#include <MiniFB_internal.h>
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_active_callback(struct Window *window, mfb_active_func callback) {
|
||||
short int g_keycodes[512] = { 0 };
|
||||
//-------------------------------------
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_set_active_callback(struct Window *window, mfb_active_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->active_func = callback;
|
||||
@ -11,7 +15,7 @@ void mfb_active_callback(struct Window *window, mfb_active_func callback) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_resize_callback(struct Window *window, mfb_resize_func callback) {
|
||||
void mfb_set_resize_callback(struct Window *window, mfb_resize_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->resize_func = callback;
|
||||
@ -19,7 +23,7 @@ void mfb_resize_callback(struct Window *window, mfb_resize_func callback) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_keyboard_callback(struct Window *window, mfb_keyboard_func callback) {
|
||||
void mfb_set_keyboard_callback(struct Window *window, mfb_keyboard_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->keyboard_func = callback;
|
||||
@ -27,7 +31,7 @@ void mfb_keyboard_callback(struct Window *window, mfb_keyboard_func callback) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_char_input_callback(struct Window *window, mfb_char_input_func callback) {
|
||||
void mfb_set_char_input_callback(struct Window *window, mfb_char_input_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->char_input_func = callback;
|
||||
@ -35,7 +39,7 @@ void mfb_char_input_callback(struct Window *window, mfb_char_input_func callback
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_mouse_button_callback(struct Window *window, mfb_mouse_btn_func callback) {
|
||||
void mfb_set_mouse_button_callback(struct Window *window, mfb_mouse_button_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->mouse_btn_func = callback;
|
||||
@ -43,7 +47,7 @@ void mfb_mouse_button_callback(struct Window *window, mfb_mouse_btn_func callbac
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_mouse_move_callback(struct Window *window, mfb_mouse_move_func callback) {
|
||||
void mfb_set_mouse_move_callback(struct Window *window, mfb_mouse_move_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->mouse_move_func = callback;
|
||||
@ -51,7 +55,7 @@ void mfb_mouse_move_callback(struct Window *window, mfb_mouse_move_func callback
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_mouse_scroll_callback(struct Window *window, mfb_mouse_scroll_func callback) {
|
||||
void mfb_set_mouse_scroll_callback(struct Window *window, mfb_mouse_scroll_func callback) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->mouse_wheel_func = callback;
|
||||
@ -77,8 +81,7 @@ void *mfb_get_user_data(struct Window *window) {
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void mfb_close(struct Window *window)
|
||||
{
|
||||
void mfb_close(struct Window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
window_data->close = true;
|
||||
@ -95,6 +98,88 @@ void keyboard_default(struct Window *window, Key key, KeyMod mod, bool isPressed
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
bool mfb_is_window_active(struct Window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->is_active;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
unsigned mfb_get_window_width(struct Window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->window_width;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
unsigned mfb_get_window_height(struct Window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->window_height;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
int mfb_get_mouse_x(struct Window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->mouse_pos_x;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
int mfb_get_mouse_y(struct Window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->mouse_pos_y;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
float mfb_get_mouse_scrool_x(struct Window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->mouse_wheel_x;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
float mfb_get_mouse_scrool_y(struct Window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->mouse_wheel_y;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
const uint8_t * mfb_get_mouse_button_buffer(struct Window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->mouse_button_status;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
const uint8_t * mfb_get_key_buffer(struct Window *window) {
|
||||
if(window != 0x0) {
|
||||
SWindowData *window_data = (SWindowData *) window;
|
||||
return window_data->key_status;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-------------------------------------
|
||||
const char * mfb_get_key_name(Key key) {
|
||||
|
@ -10,7 +10,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
short int keycodes[512];
|
||||
extern short int g_keycodes[512];
|
||||
void init_keycodes();
|
||||
void keyboard_default(struct Window *window, Key key, KeyMod mod, bool isPressed);
|
||||
|
||||
|
@ -12,7 +12,7 @@ typedef struct {
|
||||
mfb_resize_func resize_func;
|
||||
mfb_keyboard_func keyboard_func;
|
||||
mfb_char_input_func char_input_func;
|
||||
mfb_mouse_btn_func mouse_btn_func;
|
||||
mfb_mouse_button_func mouse_btn_func;
|
||||
mfb_mouse_move_func mouse_move_func;
|
||||
mfb_mouse_scroll_func mouse_wheel_func;
|
||||
|
||||
@ -30,4 +30,13 @@ typedef struct {
|
||||
uint32_t buffer_stride;
|
||||
uint32_t mod_keys;
|
||||
bool close;
|
||||
|
||||
bool is_active;
|
||||
int32_t mouse_pos_x;
|
||||
int32_t mouse_pos_y;
|
||||
float mouse_wheel_x;
|
||||
float mouse_wheel_y;
|
||||
uint8_t mouse_button_status[8];
|
||||
uint8_t key_status[512];
|
||||
|
||||
} SWindowData;
|
||||
|
@ -136,14 +136,14 @@ static bool create_shaders(SWindowData_OSX *window_data_osx) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Window *mfb_open(const char *title, int width, int height)
|
||||
struct 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, int width, int height, int flags)
|
||||
struct Window *mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
||||
{
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@ -254,7 +254,7 @@ struct Window *mfb_open_ex(const char *title, int width, int height, int flags)
|
||||
[NSApp finishLaunching];
|
||||
#endif
|
||||
|
||||
mfb_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
mfb_set_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
|
||||
#if defined(USE_METAL_API)
|
||||
NSLog(@"Window created using Metal API");
|
||||
@ -385,126 +385,126 @@ bool mfb_set_viewport(struct Window *window, unsigned offset_x, unsigned offset_
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern short int keycodes[512];
|
||||
extern short int g_keycodes[512];
|
||||
|
||||
void init_keycodes()
|
||||
{
|
||||
// Clear keys
|
||||
for (unsigned int i = 0; i < sizeof(keycodes) / sizeof(keycodes[0]); ++i)
|
||||
keycodes[i] = 0;
|
||||
for (unsigned int i = 0; i < sizeof(g_keycodes) / sizeof(g_keycodes[0]); ++i)
|
||||
g_keycodes[i] = 0;
|
||||
|
||||
keycodes[0x1D] = KB_KEY_0;
|
||||
keycodes[0x12] = KB_KEY_1;
|
||||
keycodes[0x13] = KB_KEY_2;
|
||||
keycodes[0x14] = KB_KEY_3;
|
||||
keycodes[0x15] = KB_KEY_4;
|
||||
keycodes[0x17] = KB_KEY_5;
|
||||
keycodes[0x16] = KB_KEY_6;
|
||||
keycodes[0x1A] = KB_KEY_7;
|
||||
keycodes[0x1C] = KB_KEY_8;
|
||||
keycodes[0x19] = KB_KEY_9;
|
||||
keycodes[0x00] = KB_KEY_A;
|
||||
keycodes[0x0B] = KB_KEY_B;
|
||||
keycodes[0x08] = KB_KEY_C;
|
||||
keycodes[0x02] = KB_KEY_D;
|
||||
keycodes[0x0E] = KB_KEY_E;
|
||||
keycodes[0x03] = KB_KEY_F;
|
||||
keycodes[0x05] = KB_KEY_G;
|
||||
keycodes[0x04] = KB_KEY_H;
|
||||
keycodes[0x22] = KB_KEY_I;
|
||||
keycodes[0x26] = KB_KEY_J;
|
||||
keycodes[0x28] = KB_KEY_K;
|
||||
keycodes[0x25] = KB_KEY_L;
|
||||
keycodes[0x2E] = KB_KEY_M;
|
||||
keycodes[0x2D] = KB_KEY_N;
|
||||
keycodes[0x1F] = KB_KEY_O;
|
||||
keycodes[0x23] = KB_KEY_P;
|
||||
keycodes[0x0C] = KB_KEY_Q;
|
||||
keycodes[0x0F] = KB_KEY_R;
|
||||
keycodes[0x01] = KB_KEY_S;
|
||||
keycodes[0x11] = KB_KEY_T;
|
||||
keycodes[0x20] = KB_KEY_U;
|
||||
keycodes[0x09] = KB_KEY_V;
|
||||
keycodes[0x0D] = KB_KEY_W;
|
||||
keycodes[0x07] = KB_KEY_X;
|
||||
keycodes[0x10] = KB_KEY_Y;
|
||||
keycodes[0x06] = KB_KEY_Z;
|
||||
g_keycodes[0x1D] = KB_KEY_0;
|
||||
g_keycodes[0x12] = KB_KEY_1;
|
||||
g_keycodes[0x13] = KB_KEY_2;
|
||||
g_keycodes[0x14] = KB_KEY_3;
|
||||
g_keycodes[0x15] = KB_KEY_4;
|
||||
g_keycodes[0x17] = KB_KEY_5;
|
||||
g_keycodes[0x16] = KB_KEY_6;
|
||||
g_keycodes[0x1A] = KB_KEY_7;
|
||||
g_keycodes[0x1C] = KB_KEY_8;
|
||||
g_keycodes[0x19] = KB_KEY_9;
|
||||
g_keycodes[0x00] = KB_KEY_A;
|
||||
g_keycodes[0x0B] = KB_KEY_B;
|
||||
g_keycodes[0x08] = KB_KEY_C;
|
||||
g_keycodes[0x02] = KB_KEY_D;
|
||||
g_keycodes[0x0E] = KB_KEY_E;
|
||||
g_keycodes[0x03] = KB_KEY_F;
|
||||
g_keycodes[0x05] = KB_KEY_G;
|
||||
g_keycodes[0x04] = KB_KEY_H;
|
||||
g_keycodes[0x22] = KB_KEY_I;
|
||||
g_keycodes[0x26] = KB_KEY_J;
|
||||
g_keycodes[0x28] = KB_KEY_K;
|
||||
g_keycodes[0x25] = KB_KEY_L;
|
||||
g_keycodes[0x2E] = KB_KEY_M;
|
||||
g_keycodes[0x2D] = KB_KEY_N;
|
||||
g_keycodes[0x1F] = KB_KEY_O;
|
||||
g_keycodes[0x23] = KB_KEY_P;
|
||||
g_keycodes[0x0C] = KB_KEY_Q;
|
||||
g_keycodes[0x0F] = KB_KEY_R;
|
||||
g_keycodes[0x01] = KB_KEY_S;
|
||||
g_keycodes[0x11] = KB_KEY_T;
|
||||
g_keycodes[0x20] = KB_KEY_U;
|
||||
g_keycodes[0x09] = KB_KEY_V;
|
||||
g_keycodes[0x0D] = KB_KEY_W;
|
||||
g_keycodes[0x07] = KB_KEY_X;
|
||||
g_keycodes[0x10] = KB_KEY_Y;
|
||||
g_keycodes[0x06] = KB_KEY_Z;
|
||||
|
||||
keycodes[0x27] = KB_KEY_APOSTROPHE;
|
||||
keycodes[0x2A] = KB_KEY_BACKSLASH;
|
||||
keycodes[0x2B] = KB_KEY_COMMA;
|
||||
keycodes[0x18] = KB_KEY_EQUAL;
|
||||
keycodes[0x32] = KB_KEY_GRAVE_ACCENT;
|
||||
keycodes[0x21] = KB_KEY_LEFT_BRACKET;
|
||||
keycodes[0x1B] = KB_KEY_MINUS;
|
||||
keycodes[0x2F] = KB_KEY_PERIOD;
|
||||
keycodes[0x1E] = KB_KEY_RIGHT_BRACKET;
|
||||
keycodes[0x29] = KB_KEY_SEMICOLON;
|
||||
keycodes[0x2C] = KB_KEY_SLASH;
|
||||
keycodes[0x0A] = KB_KEY_WORLD_1;
|
||||
g_keycodes[0x27] = KB_KEY_APOSTROPHE;
|
||||
g_keycodes[0x2A] = KB_KEY_BACKSLASH;
|
||||
g_keycodes[0x2B] = KB_KEY_COMMA;
|
||||
g_keycodes[0x18] = KB_KEY_EQUAL;
|
||||
g_keycodes[0x32] = KB_KEY_GRAVE_ACCENT;
|
||||
g_keycodes[0x21] = KB_KEY_LEFT_BRACKET;
|
||||
g_keycodes[0x1B] = KB_KEY_MINUS;
|
||||
g_keycodes[0x2F] = KB_KEY_PERIOD;
|
||||
g_keycodes[0x1E] = KB_KEY_RIGHT_BRACKET;
|
||||
g_keycodes[0x29] = KB_KEY_SEMICOLON;
|
||||
g_keycodes[0x2C] = KB_KEY_SLASH;
|
||||
g_keycodes[0x0A] = KB_KEY_WORLD_1;
|
||||
|
||||
keycodes[0x33] = KB_KEY_BACKSPACE;
|
||||
keycodes[0x39] = KB_KEY_CAPS_LOCK;
|
||||
keycodes[0x75] = KB_KEY_DELETE;
|
||||
keycodes[0x7D] = KB_KEY_DOWN;
|
||||
keycodes[0x77] = KB_KEY_END;
|
||||
keycodes[0x24] = KB_KEY_ENTER;
|
||||
keycodes[0x35] = KB_KEY_ESCAPE;
|
||||
keycodes[0x7A] = KB_KEY_F1;
|
||||
keycodes[0x78] = KB_KEY_F2;
|
||||
keycodes[0x63] = KB_KEY_F3;
|
||||
keycodes[0x76] = KB_KEY_F4;
|
||||
keycodes[0x60] = KB_KEY_F5;
|
||||
keycodes[0x61] = KB_KEY_F6;
|
||||
keycodes[0x62] = KB_KEY_F7;
|
||||
keycodes[0x64] = KB_KEY_F8;
|
||||
keycodes[0x65] = KB_KEY_F9;
|
||||
keycodes[0x6D] = KB_KEY_F10;
|
||||
keycodes[0x67] = KB_KEY_F11;
|
||||
keycodes[0x6F] = KB_KEY_F12;
|
||||
keycodes[0x69] = KB_KEY_F13;
|
||||
keycodes[0x6B] = KB_KEY_F14;
|
||||
keycodes[0x71] = KB_KEY_F15;
|
||||
keycodes[0x6A] = KB_KEY_F16;
|
||||
keycodes[0x40] = KB_KEY_F17;
|
||||
keycodes[0x4F] = KB_KEY_F18;
|
||||
keycodes[0x50] = KB_KEY_F19;
|
||||
keycodes[0x5A] = KB_KEY_F20;
|
||||
keycodes[0x73] = KB_KEY_HOME;
|
||||
keycodes[0x72] = KB_KEY_INSERT;
|
||||
keycodes[0x7B] = KB_KEY_LEFT;
|
||||
keycodes[0x3A] = KB_KEY_LEFT_ALT;
|
||||
keycodes[0x3B] = KB_KEY_LEFT_CONTROL;
|
||||
keycodes[0x38] = KB_KEY_LEFT_SHIFT;
|
||||
keycodes[0x37] = KB_KEY_LEFT_SUPER;
|
||||
keycodes[0x6E] = KB_KEY_MENU;
|
||||
keycodes[0x47] = KB_KEY_NUM_LOCK;
|
||||
keycodes[0x79] = KB_KEY_PAGE_DOWN;
|
||||
keycodes[0x74] = KB_KEY_PAGE_UP;
|
||||
keycodes[0x7C] = KB_KEY_RIGHT;
|
||||
keycodes[0x3D] = KB_KEY_RIGHT_ALT;
|
||||
keycodes[0x3E] = KB_KEY_RIGHT_CONTROL;
|
||||
keycodes[0x3C] = KB_KEY_RIGHT_SHIFT;
|
||||
keycodes[0x36] = KB_KEY_RIGHT_SUPER;
|
||||
keycodes[0x31] = KB_KEY_SPACE;
|
||||
keycodes[0x30] = KB_KEY_TAB;
|
||||
keycodes[0x7E] = KB_KEY_UP;
|
||||
g_keycodes[0x33] = KB_KEY_BACKSPACE;
|
||||
g_keycodes[0x39] = KB_KEY_CAPS_LOCK;
|
||||
g_keycodes[0x75] = KB_KEY_DELETE;
|
||||
g_keycodes[0x7D] = KB_KEY_DOWN;
|
||||
g_keycodes[0x77] = KB_KEY_END;
|
||||
g_keycodes[0x24] = KB_KEY_ENTER;
|
||||
g_keycodes[0x35] = KB_KEY_ESCAPE;
|
||||
g_keycodes[0x7A] = KB_KEY_F1;
|
||||
g_keycodes[0x78] = KB_KEY_F2;
|
||||
g_keycodes[0x63] = KB_KEY_F3;
|
||||
g_keycodes[0x76] = KB_KEY_F4;
|
||||
g_keycodes[0x60] = KB_KEY_F5;
|
||||
g_keycodes[0x61] = KB_KEY_F6;
|
||||
g_keycodes[0x62] = KB_KEY_F7;
|
||||
g_keycodes[0x64] = KB_KEY_F8;
|
||||
g_keycodes[0x65] = KB_KEY_F9;
|
||||
g_keycodes[0x6D] = KB_KEY_F10;
|
||||
g_keycodes[0x67] = KB_KEY_F11;
|
||||
g_keycodes[0x6F] = KB_KEY_F12;
|
||||
g_keycodes[0x69] = KB_KEY_F13;
|
||||
g_keycodes[0x6B] = KB_KEY_F14;
|
||||
g_keycodes[0x71] = KB_KEY_F15;
|
||||
g_keycodes[0x6A] = KB_KEY_F16;
|
||||
g_keycodes[0x40] = KB_KEY_F17;
|
||||
g_keycodes[0x4F] = KB_KEY_F18;
|
||||
g_keycodes[0x50] = KB_KEY_F19;
|
||||
g_keycodes[0x5A] = KB_KEY_F20;
|
||||
g_keycodes[0x73] = KB_KEY_HOME;
|
||||
g_keycodes[0x72] = KB_KEY_INSERT;
|
||||
g_keycodes[0x7B] = KB_KEY_LEFT;
|
||||
g_keycodes[0x3A] = KB_KEY_LEFT_ALT;
|
||||
g_keycodes[0x3B] = KB_KEY_LEFT_CONTROL;
|
||||
g_keycodes[0x38] = KB_KEY_LEFT_SHIFT;
|
||||
g_keycodes[0x37] = KB_KEY_LEFT_SUPER;
|
||||
g_keycodes[0x6E] = KB_KEY_MENU;
|
||||
g_keycodes[0x47] = KB_KEY_NUM_LOCK;
|
||||
g_keycodes[0x79] = KB_KEY_PAGE_DOWN;
|
||||
g_keycodes[0x74] = KB_KEY_PAGE_UP;
|
||||
g_keycodes[0x7C] = KB_KEY_RIGHT;
|
||||
g_keycodes[0x3D] = KB_KEY_RIGHT_ALT;
|
||||
g_keycodes[0x3E] = KB_KEY_RIGHT_CONTROL;
|
||||
g_keycodes[0x3C] = KB_KEY_RIGHT_SHIFT;
|
||||
g_keycodes[0x36] = KB_KEY_RIGHT_SUPER;
|
||||
g_keycodes[0x31] = KB_KEY_SPACE;
|
||||
g_keycodes[0x30] = KB_KEY_TAB;
|
||||
g_keycodes[0x7E] = KB_KEY_UP;
|
||||
|
||||
keycodes[0x52] = KB_KEY_KP_0;
|
||||
keycodes[0x53] = KB_KEY_KP_1;
|
||||
keycodes[0x54] = KB_KEY_KP_2;
|
||||
keycodes[0x55] = KB_KEY_KP_3;
|
||||
keycodes[0x56] = KB_KEY_KP_4;
|
||||
keycodes[0x57] = KB_KEY_KP_5;
|
||||
keycodes[0x58] = KB_KEY_KP_6;
|
||||
keycodes[0x59] = KB_KEY_KP_7;
|
||||
keycodes[0x5B] = KB_KEY_KP_8;
|
||||
keycodes[0x5C] = KB_KEY_KP_9;
|
||||
keycodes[0x45] = KB_KEY_KP_ADD;
|
||||
keycodes[0x41] = KB_KEY_KP_DECIMAL;
|
||||
keycodes[0x4B] = KB_KEY_KP_DIVIDE;
|
||||
keycodes[0x4C] = KB_KEY_KP_ENTER;
|
||||
keycodes[0x51] = KB_KEY_KP_EQUAL;
|
||||
keycodes[0x43] = KB_KEY_KP_MULTIPLY;
|
||||
keycodes[0x4E] = KB_KEY_KP_SUBTRACT;
|
||||
g_keycodes[0x52] = KB_KEY_KP_0;
|
||||
g_keycodes[0x53] = KB_KEY_KP_1;
|
||||
g_keycodes[0x54] = KB_KEY_KP_2;
|
||||
g_keycodes[0x55] = KB_KEY_KP_3;
|
||||
g_keycodes[0x56] = KB_KEY_KP_4;
|
||||
g_keycodes[0x57] = KB_KEY_KP_5;
|
||||
g_keycodes[0x58] = KB_KEY_KP_6;
|
||||
g_keycodes[0x59] = KB_KEY_KP_7;
|
||||
g_keycodes[0x5B] = KB_KEY_KP_8;
|
||||
g_keycodes[0x5C] = KB_KEY_KP_9;
|
||||
g_keycodes[0x45] = KB_KEY_KP_ADD;
|
||||
g_keycodes[0x41] = KB_KEY_KP_DECIMAL;
|
||||
g_keycodes[0x4B] = KB_KEY_KP_DIVIDE;
|
||||
g_keycodes[0x4C] = KB_KEY_KP_ENTER;
|
||||
g_keycodes[0x51] = KB_KEY_KP_EQUAL;
|
||||
g_keycodes[0x43] = KB_KEY_KP_MULTIPLY;
|
||||
g_keycodes[0x4E] = KB_KEY_KP_SUBTRACT;
|
||||
}
|
||||
|
@ -4,8 +4,6 @@
|
||||
#include <MiniFB_internal.h>
|
||||
#include <MiniFB_enums.h>
|
||||
|
||||
extern short int g_keycodes[512];
|
||||
|
||||
@implementation OSXWindow
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -99,26 +97,32 @@ extern short int g_keycodes[512];
|
||||
}
|
||||
|
||||
if(mod_keys != window_data->mod_keys) {
|
||||
short int keyCode = keycodes[[event keyCode] & 0x1ff];
|
||||
if(keyCode != KB_KEY_UNKNOWN) {
|
||||
short int key_code = g_keycodes[[event keyCode] & 0x1ff];
|
||||
if(key_code != KB_KEY_UNKNOWN) {
|
||||
mod_keys_aux = mod_keys ^ window_data->mod_keys;
|
||||
if(mod_keys_aux & KB_MOD_CAPS_LOCK) {
|
||||
kCall(keyboard_func, keyCode, mod_keys, (mod_keys & KB_MOD_CAPS_LOCK) != 0);
|
||||
window_data->key_status[key_code] = (mod_keys & KB_MOD_CAPS_LOCK) != 0;
|
||||
kCall(keyboard_func, key_code, mod_keys, window_data->key_status[key_code]);
|
||||
}
|
||||
if(mod_keys_aux & KB_MOD_SHIFT) {
|
||||
kCall(keyboard_func, keyCode, mod_keys, (mod_keys & KB_MOD_SHIFT) != 0);
|
||||
window_data->key_status[key_code] = (mod_keys & KB_MOD_SHIFT) != 0;
|
||||
kCall(keyboard_func, key_code, mod_keys, window_data->key_status[key_code]);
|
||||
}
|
||||
if(mod_keys_aux & KB_MOD_CONTROL) {
|
||||
kCall(keyboard_func, keyCode, mod_keys, (mod_keys & KB_MOD_CONTROL) != 0);
|
||||
window_data->key_status[key_code] = (mod_keys & KB_MOD_CONTROL) != 0;
|
||||
kCall(keyboard_func, key_code, mod_keys, window_data->key_status[key_code]);
|
||||
}
|
||||
if(mod_keys_aux & KB_MOD_ALT) {
|
||||
kCall(keyboard_func, keyCode, mod_keys, (mod_keys & KB_MOD_ALT) != 0);
|
||||
window_data->key_status[key_code] = (mod_keys & KB_MOD_ALT) != 0;
|
||||
kCall(keyboard_func, key_code, mod_keys, window_data->key_status[key_code]);
|
||||
}
|
||||
if(mod_keys_aux & KB_MOD_SUPER) {
|
||||
kCall(keyboard_func, keyCode, mod_keys, (mod_keys & KB_MOD_SUPER) != 0);
|
||||
window_data->key_status[key_code] = (mod_keys & KB_MOD_SUPER) != 0;
|
||||
kCall(keyboard_func, key_code, mod_keys, window_data->key_status[key_code]);
|
||||
}
|
||||
if(mod_keys_aux & KB_MOD_NUM_LOCK) {
|
||||
kCall(keyboard_func, keyCode, mod_keys, (mod_keys & KB_MOD_NUM_LOCK) != 0);
|
||||
window_data->key_status[key_code] = (mod_keys & KB_MOD_NUM_LOCK) != 0;
|
||||
kCall(keyboard_func, key_code, mod_keys, window_data->key_status[key_code]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -131,16 +135,18 @@ extern short int g_keycodes[512];
|
||||
|
||||
- (void)keyDown:(NSEvent *)event
|
||||
{
|
||||
short int keyCode = keycodes[[event keyCode] & 0x1ff];
|
||||
kCall(keyboard_func, keyCode, window_data->mod_keys, true);
|
||||
short int key_code = g_keycodes[[event keyCode] & 0x1ff];
|
||||
window_data->key_status[key_code] = true;
|
||||
kCall(keyboard_func, key_code, window_data->mod_keys, true);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
- (void)keyUp:(NSEvent *)event
|
||||
{
|
||||
short int keyCode = keycodes[[event keyCode] & 0x1ff];
|
||||
kCall(keyboard_func, keyCode, window_data->mod_keys, false);
|
||||
short int key_code = g_keycodes[[event keyCode] & 0x1ff];
|
||||
window_data->key_status[key_code] = false;
|
||||
kCall(keyboard_func, key_code, window_data->mod_keys, false);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -174,9 +180,8 @@ extern short int g_keycodes[512];
|
||||
{
|
||||
kUnused(notification);
|
||||
|
||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
||||
if(window_data_osx->active == true) {
|
||||
window_data_osx->active = false;
|
||||
if(window_data->is_active == true) {
|
||||
window_data->is_active = false;
|
||||
kCall(active_func, false);
|
||||
}
|
||||
}
|
||||
@ -227,12 +232,14 @@ extern short int g_keycodes[512];
|
||||
- (void)windowDidBecomeKey:(NSNotification *)notification
|
||||
{
|
||||
kUnused(notification);
|
||||
window_data->is_active = true;
|
||||
kCall(active_func, true);
|
||||
}
|
||||
|
||||
- (void)windowDidResignKey:(NSNotification *)notification
|
||||
{
|
||||
kUnused(notification);
|
||||
window_data->is_active = false;
|
||||
kCall(active_func, false);
|
||||
}
|
||||
|
||||
|
@ -262,6 +262,8 @@ extern Vertex gVertices[4];
|
||||
{
|
||||
NSPoint point = [event locationInWindow];
|
||||
//NSPoint localPoint = [self convertPoint:point fromView:nil];
|
||||
window_data->mouse_pos_x = point.x;
|
||||
window_data->mouse_pos_y = point.y;
|
||||
kCall(mouse_move_func, point.x, point.y);
|
||||
}
|
||||
|
||||
|
@ -17,5 +17,4 @@ typedef struct {
|
||||
id<MTLRenderPipelineState> pipeline_state;
|
||||
} metal;
|
||||
#endif
|
||||
bool active;
|
||||
} SWindowData_OSX;
|
||||
|
@ -102,6 +102,7 @@ keyboard_enter(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct
|
||||
kUnused(keys);
|
||||
|
||||
SWindowData *window_data = (SWindowData *) data;
|
||||
window_data->is_active = true;
|
||||
kCall(active_func, true);
|
||||
}
|
||||
|
||||
@ -116,6 +117,7 @@ keyboard_leave(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct
|
||||
kUnused(surface);
|
||||
|
||||
SWindowData *window_data = (SWindowData *) data;
|
||||
window_data->is_active = false;
|
||||
kCall(active_func, false);
|
||||
}
|
||||
|
||||
@ -134,9 +136,9 @@ keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t
|
||||
|
||||
SWindowData *window_data = (SWindowData *) data;
|
||||
if(key < 512) {
|
||||
Key kb_key = (Key) keycodes[key];
|
||||
Key key_code = (Key) g_keycodes[key];
|
||||
bool is_pressed = (bool) (state == WL_KEYBOARD_KEY_STATE_PRESSED);
|
||||
switch (kb_key)
|
||||
switch (key_code)
|
||||
{
|
||||
case KB_KEY_LEFT_SHIFT:
|
||||
case KB_KEY_RIGHT_SHIFT:
|
||||
@ -171,7 +173,8 @@ keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t
|
||||
break;
|
||||
}
|
||||
|
||||
kCall(keyboard_func, kb_key, (KeyMod)window_data->mod_keys, is_pressed);
|
||||
window_data->key_status[key_code] = is_pressed;
|
||||
kCall(keyboard_func, key_code, (KeyMod)window_data->mod_keys, is_pressed);
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,7 +287,9 @@ pointer_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t
|
||||
|
||||
//printf("Pointer moved at %f %f\n", sx / 256.0f, sy / 256.0f);
|
||||
SWindowData *window_data = (SWindowData *) data;
|
||||
kCall(mouse_move_func, sx >> 24, sy >> 24);
|
||||
window_data->mouse_pos_x = sx >> 24;
|
||||
window_data->mouse_pos_y = sy >> 24;
|
||||
kCall(mouse_move_func, window_data->mouse_pos_x, window_data->mouse_pos_y);
|
||||
}
|
||||
|
||||
// Mouse button click and release notifications.
|
||||
@ -314,7 +319,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, button - BTN_MOUSE + 1, window_data->mod_keys, state == 1);
|
||||
kCall(mouse_btn_func, (MouseButton) (button - BTN_MOUSE + 1), (KeyMod) window_data->mod_keys, state == 1);
|
||||
}
|
||||
|
||||
// Scroll and other axis notifications.
|
||||
@ -347,10 +352,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, window_data->mod_keys, 0.0f, -(value / 256.0f));
|
||||
kCall(mouse_wheel_func, (KeyMod) window_data->mod_keys, 0.0f, -(value / 256.0f));
|
||||
}
|
||||
else if(axis == 1) {
|
||||
kCall(mouse_wheel_func, window_data->mod_keys, -(value / 256.0f), 0.0f);
|
||||
kCall(mouse_wheel_func, (KeyMod) window_data->mod_keys, -(value / 256.0f), 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@ -548,21 +553,21 @@ static const struct wl_shell_surface_listener shell_surface_listener = {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Window *
|
||||
mfb_open_ex(const char *title, int width, int height, int flags) {
|
||||
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 *
|
||||
mfb_open(const char *title, int width, int height)
|
||||
mfb_open(const char *title, unsigned width, unsigned height)
|
||||
{
|
||||
int fd = -1;
|
||||
|
||||
SWindowData *window_data = malloc(sizeof(SWindowData));
|
||||
SWindowData *window_data = (SWindowData *) malloc(sizeof(SWindowData));
|
||||
memset(window_data, 0, sizeof(SWindowData));
|
||||
|
||||
SWindowData_Way *window_data_way = malloc(sizeof(SWindowData_Way));
|
||||
SWindowData_Way *window_data_way = (SWindowData_Way *) malloc(sizeof(SWindowData_Way));
|
||||
memset(window_data_way, 0, sizeof(SWindowData_Way));
|
||||
window_data->specific = window_data_way;
|
||||
|
||||
@ -643,11 +648,11 @@ mfb_open(const char *title, int width, int height)
|
||||
wl_shell_surface_set_toplevel(window_data_way->shell_surface);
|
||||
}
|
||||
|
||||
wl_surface_attach(window_data_way->surface, window_data->draw_buffer, window_data->dst_offset_x, window_data->dst_offset_y);
|
||||
wl_surface_attach(window_data_way->surface, (struct wl_buffer *) window_data->draw_buffer, window_data->dst_offset_x, window_data->dst_offset_y);
|
||||
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_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
mfb_set_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
|
||||
printf("Window created using Wayland API\n");
|
||||
|
||||
@ -703,7 +708,7 @@ mfb_update(struct Window *window, void *buffer)
|
||||
// update shm buffer
|
||||
memcpy(window_data_way->shm_ptr, buffer, window_data->buffer_stride * window_data->buffer_height);
|
||||
|
||||
wl_surface_attach(window_data_way->surface, window_data->draw_buffer, window_data->dst_offset_x, window_data->dst_offset_y);
|
||||
wl_surface_attach(window_data_way->surface, (struct wl_buffer *) window_data->draw_buffer, window_data->dst_offset_x, window_data->dst_offset_y);
|
||||
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);
|
||||
struct wl_callback *frame_callback = wl_surface_frame(window_data_way->surface);
|
||||
if (!frame_callback) {
|
||||
@ -725,132 +730,132 @@ mfb_update(struct Window *window, void *buffer)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern short int keycodes[512];
|
||||
extern short int g_keycodes[512];
|
||||
|
||||
void
|
||||
init_keycodes(void)
|
||||
{
|
||||
// Clear keys
|
||||
for (size_t i = 0; i < sizeof(keycodes) / sizeof(keycodes[0]); ++i)
|
||||
keycodes[i] = 0;
|
||||
for (size_t i = 0; i < sizeof(g_keycodes) / sizeof(g_keycodes[0]); ++i)
|
||||
g_keycodes[i] = 0;
|
||||
|
||||
keycodes[KEY_GRAVE] = KB_KEY_GRAVE_ACCENT;
|
||||
keycodes[KEY_1] = KB_KEY_1;
|
||||
keycodes[KEY_2] = KB_KEY_2;
|
||||
keycodes[KEY_3] = KB_KEY_3;
|
||||
keycodes[KEY_4] = KB_KEY_4;
|
||||
keycodes[KEY_5] = KB_KEY_5;
|
||||
keycodes[KEY_6] = KB_KEY_6;
|
||||
keycodes[KEY_7] = KB_KEY_7;
|
||||
keycodes[KEY_8] = KB_KEY_8;
|
||||
keycodes[KEY_9] = KB_KEY_9;
|
||||
keycodes[KEY_0] = KB_KEY_0;
|
||||
keycodes[KEY_SPACE] = KB_KEY_SPACE;
|
||||
keycodes[KEY_MINUS] = KB_KEY_MINUS;
|
||||
keycodes[KEY_EQUAL] = KB_KEY_EQUAL;
|
||||
keycodes[KEY_Q] = KB_KEY_Q;
|
||||
keycodes[KEY_W] = KB_KEY_W;
|
||||
keycodes[KEY_E] = KB_KEY_E;
|
||||
keycodes[KEY_R] = KB_KEY_R;
|
||||
keycodes[KEY_T] = KB_KEY_T;
|
||||
keycodes[KEY_Y] = KB_KEY_Y;
|
||||
keycodes[KEY_U] = KB_KEY_U;
|
||||
keycodes[KEY_I] = KB_KEY_I;
|
||||
keycodes[KEY_O] = KB_KEY_O;
|
||||
keycodes[KEY_P] = KB_KEY_P;
|
||||
keycodes[KEY_LEFTBRACE] = KB_KEY_LEFT_BRACKET;
|
||||
keycodes[KEY_RIGHTBRACE] = KB_KEY_RIGHT_BRACKET;
|
||||
keycodes[KEY_A] = KB_KEY_A;
|
||||
keycodes[KEY_S] = KB_KEY_S;
|
||||
keycodes[KEY_D] = KB_KEY_D;
|
||||
keycodes[KEY_F] = KB_KEY_F;
|
||||
keycodes[KEY_G] = KB_KEY_G;
|
||||
keycodes[KEY_H] = KB_KEY_H;
|
||||
keycodes[KEY_J] = KB_KEY_J;
|
||||
keycodes[KEY_K] = KB_KEY_K;
|
||||
keycodes[KEY_L] = KB_KEY_L;
|
||||
keycodes[KEY_SEMICOLON] = KB_KEY_SEMICOLON;
|
||||
keycodes[KEY_APOSTROPHE] = KB_KEY_APOSTROPHE;
|
||||
keycodes[KEY_Z] = KB_KEY_Z;
|
||||
keycodes[KEY_X] = KB_KEY_X;
|
||||
keycodes[KEY_C] = KB_KEY_C;
|
||||
keycodes[KEY_V] = KB_KEY_V;
|
||||
keycodes[KEY_B] = KB_KEY_B;
|
||||
keycodes[KEY_N] = KB_KEY_N;
|
||||
keycodes[KEY_M] = KB_KEY_M;
|
||||
keycodes[KEY_COMMA] = KB_KEY_COMMA;
|
||||
keycodes[KEY_DOT] = KB_KEY_PERIOD;
|
||||
keycodes[KEY_SLASH] = KB_KEY_SLASH;
|
||||
keycodes[KEY_BACKSLASH] = KB_KEY_BACKSLASH;
|
||||
keycodes[KEY_ESC] = KB_KEY_ESCAPE;
|
||||
keycodes[KEY_TAB] = KB_KEY_TAB;
|
||||
keycodes[KEY_LEFTSHIFT] = KB_KEY_LEFT_SHIFT;
|
||||
keycodes[KEY_RIGHTSHIFT] = KB_KEY_RIGHT_SHIFT;
|
||||
keycodes[KEY_LEFTCTRL] = KB_KEY_LEFT_CONTROL;
|
||||
keycodes[KEY_RIGHTCTRL] = KB_KEY_RIGHT_CONTROL;
|
||||
keycodes[KEY_LEFTALT] = KB_KEY_LEFT_ALT;
|
||||
keycodes[KEY_RIGHTALT] = KB_KEY_RIGHT_ALT;
|
||||
keycodes[KEY_LEFTMETA] = KB_KEY_LEFT_SUPER;
|
||||
keycodes[KEY_RIGHTMETA] = KB_KEY_RIGHT_SUPER;
|
||||
keycodes[KEY_MENU] = KB_KEY_MENU;
|
||||
keycodes[KEY_NUMLOCK] = KB_KEY_NUM_LOCK;
|
||||
keycodes[KEY_CAPSLOCK] = KB_KEY_CAPS_LOCK;
|
||||
keycodes[KEY_PRINT] = KB_KEY_PRINT_SCREEN;
|
||||
keycodes[KEY_SCROLLLOCK] = KB_KEY_SCROLL_LOCK;
|
||||
keycodes[KEY_PAUSE] = KB_KEY_PAUSE;
|
||||
keycodes[KEY_DELETE] = KB_KEY_DELETE;
|
||||
keycodes[KEY_BACKSPACE] = KB_KEY_BACKSPACE;
|
||||
keycodes[KEY_ENTER] = KB_KEY_ENTER;
|
||||
keycodes[KEY_HOME] = KB_KEY_HOME;
|
||||
keycodes[KEY_END] = KB_KEY_END;
|
||||
keycodes[KEY_PAGEUP] = KB_KEY_PAGE_UP;
|
||||
keycodes[KEY_PAGEDOWN] = KB_KEY_PAGE_DOWN;
|
||||
keycodes[KEY_INSERT] = KB_KEY_INSERT;
|
||||
keycodes[KEY_LEFT] = KB_KEY_LEFT;
|
||||
keycodes[KEY_RIGHT] = KB_KEY_RIGHT;
|
||||
keycodes[KEY_DOWN] = KB_KEY_DOWN;
|
||||
keycodes[KEY_UP] = KB_KEY_UP;
|
||||
keycodes[KEY_F1] = KB_KEY_F1;
|
||||
keycodes[KEY_F2] = KB_KEY_F2;
|
||||
keycodes[KEY_F3] = KB_KEY_F3;
|
||||
keycodes[KEY_F4] = KB_KEY_F4;
|
||||
keycodes[KEY_F5] = KB_KEY_F5;
|
||||
keycodes[KEY_F6] = KB_KEY_F6;
|
||||
keycodes[KEY_F7] = KB_KEY_F7;
|
||||
keycodes[KEY_F8] = KB_KEY_F8;
|
||||
keycodes[KEY_F9] = KB_KEY_F9;
|
||||
keycodes[KEY_F10] = KB_KEY_F10;
|
||||
keycodes[KEY_F11] = KB_KEY_F11;
|
||||
keycodes[KEY_F12] = KB_KEY_F12;
|
||||
keycodes[KEY_F13] = KB_KEY_F13;
|
||||
keycodes[KEY_F14] = KB_KEY_F14;
|
||||
keycodes[KEY_F15] = KB_KEY_F15;
|
||||
keycodes[KEY_F16] = KB_KEY_F16;
|
||||
keycodes[KEY_F17] = KB_KEY_F17;
|
||||
keycodes[KEY_F18] = KB_KEY_F18;
|
||||
keycodes[KEY_F19] = KB_KEY_F19;
|
||||
keycodes[KEY_F20] = KB_KEY_F20;
|
||||
keycodes[KEY_F21] = KB_KEY_F21;
|
||||
keycodes[KEY_F22] = KB_KEY_F22;
|
||||
keycodes[KEY_F23] = KB_KEY_F23;
|
||||
keycodes[KEY_F24] = KB_KEY_F24;
|
||||
keycodes[KEY_KPSLASH] = KB_KEY_KP_DIVIDE;
|
||||
keycodes[KEY_KPDOT] = KB_KEY_KP_MULTIPLY;
|
||||
keycodes[KEY_KPMINUS] = KB_KEY_KP_SUBTRACT;
|
||||
keycodes[KEY_KPPLUS] = KB_KEY_KP_ADD;
|
||||
keycodes[KEY_KP0] = KB_KEY_KP_0;
|
||||
keycodes[KEY_KP1] = KB_KEY_KP_1;
|
||||
keycodes[KEY_KP2] = KB_KEY_KP_2;
|
||||
keycodes[KEY_KP3] = KB_KEY_KP_3;
|
||||
keycodes[KEY_KP4] = KB_KEY_KP_4;
|
||||
keycodes[KEY_KP5] = KB_KEY_KP_5;
|
||||
keycodes[KEY_KP6] = KB_KEY_KP_6;
|
||||
keycodes[KEY_KP7] = KB_KEY_KP_7;
|
||||
keycodes[KEY_KP8] = KB_KEY_KP_8;
|
||||
keycodes[KEY_KP9] = KB_KEY_KP_9;
|
||||
keycodes[KEY_KPCOMMA] = KB_KEY_KP_DECIMAL;
|
||||
keycodes[KEY_KPEQUAL] = KB_KEY_KP_EQUAL;
|
||||
keycodes[KEY_KPENTER] = KB_KEY_KP_ENTER;
|
||||
g_keycodes[KEY_GRAVE] = KB_KEY_GRAVE_ACCENT;
|
||||
g_keycodes[KEY_1] = KB_KEY_1;
|
||||
g_keycodes[KEY_2] = KB_KEY_2;
|
||||
g_keycodes[KEY_3] = KB_KEY_3;
|
||||
g_keycodes[KEY_4] = KB_KEY_4;
|
||||
g_keycodes[KEY_5] = KB_KEY_5;
|
||||
g_keycodes[KEY_6] = KB_KEY_6;
|
||||
g_keycodes[KEY_7] = KB_KEY_7;
|
||||
g_keycodes[KEY_8] = KB_KEY_8;
|
||||
g_keycodes[KEY_9] = KB_KEY_9;
|
||||
g_keycodes[KEY_0] = KB_KEY_0;
|
||||
g_keycodes[KEY_SPACE] = KB_KEY_SPACE;
|
||||
g_keycodes[KEY_MINUS] = KB_KEY_MINUS;
|
||||
g_keycodes[KEY_EQUAL] = KB_KEY_EQUAL;
|
||||
g_keycodes[KEY_Q] = KB_KEY_Q;
|
||||
g_keycodes[KEY_W] = KB_KEY_W;
|
||||
g_keycodes[KEY_E] = KB_KEY_E;
|
||||
g_keycodes[KEY_R] = KB_KEY_R;
|
||||
g_keycodes[KEY_T] = KB_KEY_T;
|
||||
g_keycodes[KEY_Y] = KB_KEY_Y;
|
||||
g_keycodes[KEY_U] = KB_KEY_U;
|
||||
g_keycodes[KEY_I] = KB_KEY_I;
|
||||
g_keycodes[KEY_O] = KB_KEY_O;
|
||||
g_keycodes[KEY_P] = KB_KEY_P;
|
||||
g_keycodes[KEY_LEFTBRACE] = KB_KEY_LEFT_BRACKET;
|
||||
g_keycodes[KEY_RIGHTBRACE] = KB_KEY_RIGHT_BRACKET;
|
||||
g_keycodes[KEY_A] = KB_KEY_A;
|
||||
g_keycodes[KEY_S] = KB_KEY_S;
|
||||
g_keycodes[KEY_D] = KB_KEY_D;
|
||||
g_keycodes[KEY_F] = KB_KEY_F;
|
||||
g_keycodes[KEY_G] = KB_KEY_G;
|
||||
g_keycodes[KEY_H] = KB_KEY_H;
|
||||
g_keycodes[KEY_J] = KB_KEY_J;
|
||||
g_keycodes[KEY_K] = KB_KEY_K;
|
||||
g_keycodes[KEY_L] = KB_KEY_L;
|
||||
g_keycodes[KEY_SEMICOLON] = KB_KEY_SEMICOLON;
|
||||
g_keycodes[KEY_APOSTROPHE] = KB_KEY_APOSTROPHE;
|
||||
g_keycodes[KEY_Z] = KB_KEY_Z;
|
||||
g_keycodes[KEY_X] = KB_KEY_X;
|
||||
g_keycodes[KEY_C] = KB_KEY_C;
|
||||
g_keycodes[KEY_V] = KB_KEY_V;
|
||||
g_keycodes[KEY_B] = KB_KEY_B;
|
||||
g_keycodes[KEY_N] = KB_KEY_N;
|
||||
g_keycodes[KEY_M] = KB_KEY_M;
|
||||
g_keycodes[KEY_COMMA] = KB_KEY_COMMA;
|
||||
g_keycodes[KEY_DOT] = KB_KEY_PERIOD;
|
||||
g_keycodes[KEY_SLASH] = KB_KEY_SLASH;
|
||||
g_keycodes[KEY_BACKSLASH] = KB_KEY_BACKSLASH;
|
||||
g_keycodes[KEY_ESC] = KB_KEY_ESCAPE;
|
||||
g_keycodes[KEY_TAB] = KB_KEY_TAB;
|
||||
g_keycodes[KEY_LEFTSHIFT] = KB_KEY_LEFT_SHIFT;
|
||||
g_keycodes[KEY_RIGHTSHIFT] = KB_KEY_RIGHT_SHIFT;
|
||||
g_keycodes[KEY_LEFTCTRL] = KB_KEY_LEFT_CONTROL;
|
||||
g_keycodes[KEY_RIGHTCTRL] = KB_KEY_RIGHT_CONTROL;
|
||||
g_keycodes[KEY_LEFTALT] = KB_KEY_LEFT_ALT;
|
||||
g_keycodes[KEY_RIGHTALT] = KB_KEY_RIGHT_ALT;
|
||||
g_keycodes[KEY_LEFTMETA] = KB_KEY_LEFT_SUPER;
|
||||
g_keycodes[KEY_RIGHTMETA] = KB_KEY_RIGHT_SUPER;
|
||||
g_keycodes[KEY_MENU] = KB_KEY_MENU;
|
||||
g_keycodes[KEY_NUMLOCK] = KB_KEY_NUM_LOCK;
|
||||
g_keycodes[KEY_CAPSLOCK] = KB_KEY_CAPS_LOCK;
|
||||
g_keycodes[KEY_PRINT] = KB_KEY_PRINT_SCREEN;
|
||||
g_keycodes[KEY_SCROLLLOCK] = KB_KEY_SCROLL_LOCK;
|
||||
g_keycodes[KEY_PAUSE] = KB_KEY_PAUSE;
|
||||
g_keycodes[KEY_DELETE] = KB_KEY_DELETE;
|
||||
g_keycodes[KEY_BACKSPACE] = KB_KEY_BACKSPACE;
|
||||
g_keycodes[KEY_ENTER] = KB_KEY_ENTER;
|
||||
g_keycodes[KEY_HOME] = KB_KEY_HOME;
|
||||
g_keycodes[KEY_END] = KB_KEY_END;
|
||||
g_keycodes[KEY_PAGEUP] = KB_KEY_PAGE_UP;
|
||||
g_keycodes[KEY_PAGEDOWN] = KB_KEY_PAGE_DOWN;
|
||||
g_keycodes[KEY_INSERT] = KB_KEY_INSERT;
|
||||
g_keycodes[KEY_LEFT] = KB_KEY_LEFT;
|
||||
g_keycodes[KEY_RIGHT] = KB_KEY_RIGHT;
|
||||
g_keycodes[KEY_DOWN] = KB_KEY_DOWN;
|
||||
g_keycodes[KEY_UP] = KB_KEY_UP;
|
||||
g_keycodes[KEY_F1] = KB_KEY_F1;
|
||||
g_keycodes[KEY_F2] = KB_KEY_F2;
|
||||
g_keycodes[KEY_F3] = KB_KEY_F3;
|
||||
g_keycodes[KEY_F4] = KB_KEY_F4;
|
||||
g_keycodes[KEY_F5] = KB_KEY_F5;
|
||||
g_keycodes[KEY_F6] = KB_KEY_F6;
|
||||
g_keycodes[KEY_F7] = KB_KEY_F7;
|
||||
g_keycodes[KEY_F8] = KB_KEY_F8;
|
||||
g_keycodes[KEY_F9] = KB_KEY_F9;
|
||||
g_keycodes[KEY_F10] = KB_KEY_F10;
|
||||
g_keycodes[KEY_F11] = KB_KEY_F11;
|
||||
g_keycodes[KEY_F12] = KB_KEY_F12;
|
||||
g_keycodes[KEY_F13] = KB_KEY_F13;
|
||||
g_keycodes[KEY_F14] = KB_KEY_F14;
|
||||
g_keycodes[KEY_F15] = KB_KEY_F15;
|
||||
g_keycodes[KEY_F16] = KB_KEY_F16;
|
||||
g_keycodes[KEY_F17] = KB_KEY_F17;
|
||||
g_keycodes[KEY_F18] = KB_KEY_F18;
|
||||
g_keycodes[KEY_F19] = KB_KEY_F19;
|
||||
g_keycodes[KEY_F20] = KB_KEY_F20;
|
||||
g_keycodes[KEY_F21] = KB_KEY_F21;
|
||||
g_keycodes[KEY_F22] = KB_KEY_F22;
|
||||
g_keycodes[KEY_F23] = KB_KEY_F23;
|
||||
g_keycodes[KEY_F24] = KB_KEY_F24;
|
||||
g_keycodes[KEY_KPSLASH] = KB_KEY_KP_DIVIDE;
|
||||
g_keycodes[KEY_KPDOT] = KB_KEY_KP_MULTIPLY;
|
||||
g_keycodes[KEY_KPMINUS] = KB_KEY_KP_SUBTRACT;
|
||||
g_keycodes[KEY_KPPLUS] = KB_KEY_KP_ADD;
|
||||
g_keycodes[KEY_KP0] = KB_KEY_KP_0;
|
||||
g_keycodes[KEY_KP1] = KB_KEY_KP_1;
|
||||
g_keycodes[KEY_KP2] = KB_KEY_KP_2;
|
||||
g_keycodes[KEY_KP3] = KB_KEY_KP_3;
|
||||
g_keycodes[KEY_KP4] = KB_KEY_KP_4;
|
||||
g_keycodes[KEY_KP5] = KB_KEY_KP_5;
|
||||
g_keycodes[KEY_KP6] = KB_KEY_KP_6;
|
||||
g_keycodes[KEY_KP7] = KB_KEY_KP_7;
|
||||
g_keycodes[KEY_KP8] = KB_KEY_KP_8;
|
||||
g_keycodes[KEY_KP9] = KB_KEY_KP_9;
|
||||
g_keycodes[KEY_KPCOMMA] = KB_KEY_KP_DECIMAL;
|
||||
g_keycodes[KEY_KPEQUAL] = KB_KEY_KP_EQUAL;
|
||||
g_keycodes[KEY_KPENTER] = KB_KEY_KP_ENTER;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -19,7 +19,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
LRESULT res = 0;
|
||||
|
||||
SWindowData *window_data = (SWindowData *) GetWindowLongPtr(hWnd, GWL_USERDATA);
|
||||
SWindowData *window_data = (SWindowData *) GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
||||
SWindowData_Win *window_data_win = 0x0;
|
||||
if(window_data != 0x0) {
|
||||
window_data_win = (SWindowData_Win *) window_data->specific;
|
||||
@ -70,14 +70,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case WM_SYSKEYUP:
|
||||
{
|
||||
if(window_data) {
|
||||
Key kb_key = translate_key((unsigned int)wParam, (unsigned long)lParam);
|
||||
Key key_code = translate_key((unsigned int)wParam, (unsigned long)lParam);
|
||||
int is_pressed = !((lParam >> 31) & 1);
|
||||
window_data->mod_keys = translate_mod();
|
||||
|
||||
if (kb_key == KB_KEY_UNKNOWN)
|
||||
if (key_code == KB_KEY_UNKNOWN)
|
||||
return FALSE;
|
||||
|
||||
kCall(keyboard_func, kb_key, window_data->mod_keys, is_pressed);
|
||||
window_data->key_status[key_code] = is_pressed;
|
||||
kCall(keyboard_func, key_code, window_data->mod_keys, is_pressed);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -169,7 +170,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
tme.hwndTrack = hWnd;
|
||||
TrackMouseEvent(&tme);
|
||||
}
|
||||
kCall(mouse_move_func, ((int)(short)LOWORD(lParam)), ((int)(short)HIWORD(lParam)));
|
||||
window_data->mouse_pos_x = (int)(short) LOWORD(lParam);
|
||||
window_data->mouse_pos_y = (int)(short) HIWORD(lParam);
|
||||
kCall(mouse_move_func, window_data->mouse_pos_x, window_data->mouse_pos_y);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -194,12 +197,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
case WM_SETFOCUS:
|
||||
if(window_data) {
|
||||
window_data->is_active = true;
|
||||
kCall(active_func, true);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_KILLFOCUS:
|
||||
if(window_data) {
|
||||
window_data->is_active = false;
|
||||
kCall(active_func, false);
|
||||
}
|
||||
break;
|
||||
@ -215,7 +220,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Window *mfb_open_ex(const char *title, int width, int height, int flags) {
|
||||
struct Window *mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags) {
|
||||
RECT rect = { 0 };
|
||||
int x, y;
|
||||
|
||||
@ -241,7 +246,7 @@ struct Window *mfb_open_ex(const char *title, int width, int height, int flags)
|
||||
rect.bottom = GetSystemMetrics(SM_CYSCREEN);
|
||||
s_window_style = WS_POPUP & ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
|
||||
|
||||
DEVMODE settings;
|
||||
DEVMODE settings = { 0 };
|
||||
EnumDisplaySettings(0, 0, &settings);
|
||||
settings.dmPelsWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||
settings.dmPelsHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||
@ -275,7 +280,7 @@ struct Window *mfb_open_ex(const char *title, int width, int height, int flags)
|
||||
rect.right += rect.left;
|
||||
rect.left = 0;
|
||||
}
|
||||
if (rect.bottom > height) {
|
||||
if (rect.bottom > (LONG) height) {
|
||||
height -= (rect.bottom - height);
|
||||
rect.bottom += (rect.bottom - height);
|
||||
rect.top = 0;
|
||||
@ -342,12 +347,12 @@ struct Window *mfb_open_ex(const char *title, int width, int height, int flags)
|
||||
|
||||
window_data_win->hdc = GetDC(window_data_win->window);
|
||||
|
||||
mfb_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
mfb_set_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
|
||||
return (struct Window *) window_data;
|
||||
}
|
||||
|
||||
struct Window *mfb_open(const char *title, int width, int height) {
|
||||
struct Window *mfb_open(const char *title, unsigned width, unsigned height) {
|
||||
return mfb_open_ex(title, width, height, 0);
|
||||
}
|
||||
|
||||
@ -432,135 +437,135 @@ uint32_t translate_mod() {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern short int keycodes[512];
|
||||
extern short int g_keycodes[512];
|
||||
|
||||
void init_keycodes() {
|
||||
|
||||
// Clear keys
|
||||
for (size_t i = 0; i < sizeof(keycodes) / sizeof(keycodes[0]); ++i)
|
||||
keycodes[i] = 0;
|
||||
for (size_t i = 0; i < sizeof(g_keycodes) / sizeof(g_keycodes[0]); ++i)
|
||||
g_keycodes[i] = 0;
|
||||
|
||||
keycodes[0x00B] = KB_KEY_0;
|
||||
keycodes[0x002] = KB_KEY_1;
|
||||
keycodes[0x003] = KB_KEY_2;
|
||||
keycodes[0x004] = KB_KEY_3;
|
||||
keycodes[0x005] = KB_KEY_4;
|
||||
keycodes[0x006] = KB_KEY_5;
|
||||
keycodes[0x007] = KB_KEY_6;
|
||||
keycodes[0x008] = KB_KEY_7;
|
||||
keycodes[0x009] = KB_KEY_8;
|
||||
keycodes[0x00A] = KB_KEY_9;
|
||||
keycodes[0x01E] = KB_KEY_A;
|
||||
keycodes[0x030] = KB_KEY_B;
|
||||
keycodes[0x02E] = KB_KEY_C;
|
||||
keycodes[0x020] = KB_KEY_D;
|
||||
keycodes[0x012] = KB_KEY_E;
|
||||
keycodes[0x021] = KB_KEY_F;
|
||||
keycodes[0x022] = KB_KEY_G;
|
||||
keycodes[0x023] = KB_KEY_H;
|
||||
keycodes[0x017] = KB_KEY_I;
|
||||
keycodes[0x024] = KB_KEY_J;
|
||||
keycodes[0x025] = KB_KEY_K;
|
||||
keycodes[0x026] = KB_KEY_L;
|
||||
keycodes[0x032] = KB_KEY_M;
|
||||
keycodes[0x031] = KB_KEY_N;
|
||||
keycodes[0x018] = KB_KEY_O;
|
||||
keycodes[0x019] = KB_KEY_P;
|
||||
keycodes[0x010] = KB_KEY_Q;
|
||||
keycodes[0x013] = KB_KEY_R;
|
||||
keycodes[0x01F] = KB_KEY_S;
|
||||
keycodes[0x014] = KB_KEY_T;
|
||||
keycodes[0x016] = KB_KEY_U;
|
||||
keycodes[0x02F] = KB_KEY_V;
|
||||
keycodes[0x011] = KB_KEY_W;
|
||||
keycodes[0x02D] = KB_KEY_X;
|
||||
keycodes[0x015] = KB_KEY_Y;
|
||||
keycodes[0x02C] = KB_KEY_Z;
|
||||
g_keycodes[0x00B] = KB_KEY_0;
|
||||
g_keycodes[0x002] = KB_KEY_1;
|
||||
g_keycodes[0x003] = KB_KEY_2;
|
||||
g_keycodes[0x004] = KB_KEY_3;
|
||||
g_keycodes[0x005] = KB_KEY_4;
|
||||
g_keycodes[0x006] = KB_KEY_5;
|
||||
g_keycodes[0x007] = KB_KEY_6;
|
||||
g_keycodes[0x008] = KB_KEY_7;
|
||||
g_keycodes[0x009] = KB_KEY_8;
|
||||
g_keycodes[0x00A] = KB_KEY_9;
|
||||
g_keycodes[0x01E] = KB_KEY_A;
|
||||
g_keycodes[0x030] = KB_KEY_B;
|
||||
g_keycodes[0x02E] = KB_KEY_C;
|
||||
g_keycodes[0x020] = KB_KEY_D;
|
||||
g_keycodes[0x012] = KB_KEY_E;
|
||||
g_keycodes[0x021] = KB_KEY_F;
|
||||
g_keycodes[0x022] = KB_KEY_G;
|
||||
g_keycodes[0x023] = KB_KEY_H;
|
||||
g_keycodes[0x017] = KB_KEY_I;
|
||||
g_keycodes[0x024] = KB_KEY_J;
|
||||
g_keycodes[0x025] = KB_KEY_K;
|
||||
g_keycodes[0x026] = KB_KEY_L;
|
||||
g_keycodes[0x032] = KB_KEY_M;
|
||||
g_keycodes[0x031] = KB_KEY_N;
|
||||
g_keycodes[0x018] = KB_KEY_O;
|
||||
g_keycodes[0x019] = KB_KEY_P;
|
||||
g_keycodes[0x010] = KB_KEY_Q;
|
||||
g_keycodes[0x013] = KB_KEY_R;
|
||||
g_keycodes[0x01F] = KB_KEY_S;
|
||||
g_keycodes[0x014] = KB_KEY_T;
|
||||
g_keycodes[0x016] = KB_KEY_U;
|
||||
g_keycodes[0x02F] = KB_KEY_V;
|
||||
g_keycodes[0x011] = KB_KEY_W;
|
||||
g_keycodes[0x02D] = KB_KEY_X;
|
||||
g_keycodes[0x015] = KB_KEY_Y;
|
||||
g_keycodes[0x02C] = KB_KEY_Z;
|
||||
|
||||
keycodes[0x028] = KB_KEY_APOSTROPHE;
|
||||
keycodes[0x02B] = KB_KEY_BACKSLASH;
|
||||
keycodes[0x033] = KB_KEY_COMMA;
|
||||
keycodes[0x00D] = KB_KEY_EQUAL;
|
||||
keycodes[0x029] = KB_KEY_GRAVE_ACCENT;
|
||||
keycodes[0x01A] = KB_KEY_LEFT_BRACKET;
|
||||
keycodes[0x00C] = KB_KEY_MINUS;
|
||||
keycodes[0x034] = KB_KEY_PERIOD;
|
||||
keycodes[0x01B] = KB_KEY_RIGHT_BRACKET;
|
||||
keycodes[0x027] = KB_KEY_SEMICOLON;
|
||||
keycodes[0x035] = KB_KEY_SLASH;
|
||||
keycodes[0x056] = KB_KEY_WORLD_2;
|
||||
g_keycodes[0x028] = KB_KEY_APOSTROPHE;
|
||||
g_keycodes[0x02B] = KB_KEY_BACKSLASH;
|
||||
g_keycodes[0x033] = KB_KEY_COMMA;
|
||||
g_keycodes[0x00D] = KB_KEY_EQUAL;
|
||||
g_keycodes[0x029] = KB_KEY_GRAVE_ACCENT;
|
||||
g_keycodes[0x01A] = KB_KEY_LEFT_BRACKET;
|
||||
g_keycodes[0x00C] = KB_KEY_MINUS;
|
||||
g_keycodes[0x034] = KB_KEY_PERIOD;
|
||||
g_keycodes[0x01B] = KB_KEY_RIGHT_BRACKET;
|
||||
g_keycodes[0x027] = KB_KEY_SEMICOLON;
|
||||
g_keycodes[0x035] = KB_KEY_SLASH;
|
||||
g_keycodes[0x056] = KB_KEY_WORLD_2;
|
||||
|
||||
keycodes[0x00E] = KB_KEY_BACKSPACE;
|
||||
keycodes[0x153] = KB_KEY_DELETE;
|
||||
keycodes[0x14F] = KB_KEY_END;
|
||||
keycodes[0x01C] = KB_KEY_ENTER;
|
||||
keycodes[0x001] = KB_KEY_ESCAPE;
|
||||
keycodes[0x147] = KB_KEY_HOME;
|
||||
keycodes[0x152] = KB_KEY_INSERT;
|
||||
keycodes[0x15D] = KB_KEY_MENU;
|
||||
keycodes[0x151] = KB_KEY_PAGE_DOWN;
|
||||
keycodes[0x149] = KB_KEY_PAGE_UP;
|
||||
keycodes[0x045] = KB_KEY_PAUSE;
|
||||
keycodes[0x146] = KB_KEY_PAUSE;
|
||||
keycodes[0x039] = KB_KEY_SPACE;
|
||||
keycodes[0x00F] = KB_KEY_TAB;
|
||||
keycodes[0x03A] = KB_KEY_CAPS_LOCK;
|
||||
keycodes[0x145] = KB_KEY_NUM_LOCK;
|
||||
keycodes[0x046] = KB_KEY_SCROLL_LOCK;
|
||||
keycodes[0x03B] = KB_KEY_F1;
|
||||
keycodes[0x03C] = KB_KEY_F2;
|
||||
keycodes[0x03D] = KB_KEY_F3;
|
||||
keycodes[0x03E] = KB_KEY_F4;
|
||||
keycodes[0x03F] = KB_KEY_F5;
|
||||
keycodes[0x040] = KB_KEY_F6;
|
||||
keycodes[0x041] = KB_KEY_F7;
|
||||
keycodes[0x042] = KB_KEY_F8;
|
||||
keycodes[0x043] = KB_KEY_F9;
|
||||
keycodes[0x044] = KB_KEY_F10;
|
||||
keycodes[0x057] = KB_KEY_F11;
|
||||
keycodes[0x058] = KB_KEY_F12;
|
||||
keycodes[0x064] = KB_KEY_F13;
|
||||
keycodes[0x065] = KB_KEY_F14;
|
||||
keycodes[0x066] = KB_KEY_F15;
|
||||
keycodes[0x067] = KB_KEY_F16;
|
||||
keycodes[0x068] = KB_KEY_F17;
|
||||
keycodes[0x069] = KB_KEY_F18;
|
||||
keycodes[0x06A] = KB_KEY_F19;
|
||||
keycodes[0x06B] = KB_KEY_F20;
|
||||
keycodes[0x06C] = KB_KEY_F21;
|
||||
keycodes[0x06D] = KB_KEY_F22;
|
||||
keycodes[0x06E] = KB_KEY_F23;
|
||||
keycodes[0x076] = KB_KEY_F24;
|
||||
keycodes[0x038] = KB_KEY_LEFT_ALT;
|
||||
keycodes[0x01D] = KB_KEY_LEFT_CONTROL;
|
||||
keycodes[0x02A] = KB_KEY_LEFT_SHIFT;
|
||||
keycodes[0x15B] = KB_KEY_LEFT_SUPER;
|
||||
keycodes[0x137] = KB_KEY_PRINT_SCREEN;
|
||||
keycodes[0x138] = KB_KEY_RIGHT_ALT;
|
||||
keycodes[0x11D] = KB_KEY_RIGHT_CONTROL;
|
||||
keycodes[0x036] = KB_KEY_RIGHT_SHIFT;
|
||||
keycodes[0x15C] = KB_KEY_RIGHT_SUPER;
|
||||
keycodes[0x150] = KB_KEY_DOWN;
|
||||
keycodes[0x14B] = KB_KEY_LEFT;
|
||||
keycodes[0x14D] = KB_KEY_RIGHT;
|
||||
keycodes[0x148] = KB_KEY_UP;
|
||||
g_keycodes[0x00E] = KB_KEY_BACKSPACE;
|
||||
g_keycodes[0x153] = KB_KEY_DELETE;
|
||||
g_keycodes[0x14F] = KB_KEY_END;
|
||||
g_keycodes[0x01C] = KB_KEY_ENTER;
|
||||
g_keycodes[0x001] = KB_KEY_ESCAPE;
|
||||
g_keycodes[0x147] = KB_KEY_HOME;
|
||||
g_keycodes[0x152] = KB_KEY_INSERT;
|
||||
g_keycodes[0x15D] = KB_KEY_MENU;
|
||||
g_keycodes[0x151] = KB_KEY_PAGE_DOWN;
|
||||
g_keycodes[0x149] = KB_KEY_PAGE_UP;
|
||||
g_keycodes[0x045] = KB_KEY_PAUSE;
|
||||
g_keycodes[0x146] = KB_KEY_PAUSE;
|
||||
g_keycodes[0x039] = KB_KEY_SPACE;
|
||||
g_keycodes[0x00F] = KB_KEY_TAB;
|
||||
g_keycodes[0x03A] = KB_KEY_CAPS_LOCK;
|
||||
g_keycodes[0x145] = KB_KEY_NUM_LOCK;
|
||||
g_keycodes[0x046] = KB_KEY_SCROLL_LOCK;
|
||||
g_keycodes[0x03B] = KB_KEY_F1;
|
||||
g_keycodes[0x03C] = KB_KEY_F2;
|
||||
g_keycodes[0x03D] = KB_KEY_F3;
|
||||
g_keycodes[0x03E] = KB_KEY_F4;
|
||||
g_keycodes[0x03F] = KB_KEY_F5;
|
||||
g_keycodes[0x040] = KB_KEY_F6;
|
||||
g_keycodes[0x041] = KB_KEY_F7;
|
||||
g_keycodes[0x042] = KB_KEY_F8;
|
||||
g_keycodes[0x043] = KB_KEY_F9;
|
||||
g_keycodes[0x044] = KB_KEY_F10;
|
||||
g_keycodes[0x057] = KB_KEY_F11;
|
||||
g_keycodes[0x058] = KB_KEY_F12;
|
||||
g_keycodes[0x064] = KB_KEY_F13;
|
||||
g_keycodes[0x065] = KB_KEY_F14;
|
||||
g_keycodes[0x066] = KB_KEY_F15;
|
||||
g_keycodes[0x067] = KB_KEY_F16;
|
||||
g_keycodes[0x068] = KB_KEY_F17;
|
||||
g_keycodes[0x069] = KB_KEY_F18;
|
||||
g_keycodes[0x06A] = KB_KEY_F19;
|
||||
g_keycodes[0x06B] = KB_KEY_F20;
|
||||
g_keycodes[0x06C] = KB_KEY_F21;
|
||||
g_keycodes[0x06D] = KB_KEY_F22;
|
||||
g_keycodes[0x06E] = KB_KEY_F23;
|
||||
g_keycodes[0x076] = KB_KEY_F24;
|
||||
g_keycodes[0x038] = KB_KEY_LEFT_ALT;
|
||||
g_keycodes[0x01D] = KB_KEY_LEFT_CONTROL;
|
||||
g_keycodes[0x02A] = KB_KEY_LEFT_SHIFT;
|
||||
g_keycodes[0x15B] = KB_KEY_LEFT_SUPER;
|
||||
g_keycodes[0x137] = KB_KEY_PRINT_SCREEN;
|
||||
g_keycodes[0x138] = KB_KEY_RIGHT_ALT;
|
||||
g_keycodes[0x11D] = KB_KEY_RIGHT_CONTROL;
|
||||
g_keycodes[0x036] = KB_KEY_RIGHT_SHIFT;
|
||||
g_keycodes[0x15C] = KB_KEY_RIGHT_SUPER;
|
||||
g_keycodes[0x150] = KB_KEY_DOWN;
|
||||
g_keycodes[0x14B] = KB_KEY_LEFT;
|
||||
g_keycodes[0x14D] = KB_KEY_RIGHT;
|
||||
g_keycodes[0x148] = KB_KEY_UP;
|
||||
|
||||
keycodes[0x052] = KB_KEY_KP_0;
|
||||
keycodes[0x04F] = KB_KEY_KP_1;
|
||||
keycodes[0x050] = KB_KEY_KP_2;
|
||||
keycodes[0x051] = KB_KEY_KP_3;
|
||||
keycodes[0x04B] = KB_KEY_KP_4;
|
||||
keycodes[0x04C] = KB_KEY_KP_5;
|
||||
keycodes[0x04D] = KB_KEY_KP_6;
|
||||
keycodes[0x047] = KB_KEY_KP_7;
|
||||
keycodes[0x048] = KB_KEY_KP_8;
|
||||
keycodes[0x049] = KB_KEY_KP_9;
|
||||
keycodes[0x04E] = KB_KEY_KP_ADD;
|
||||
keycodes[0x053] = KB_KEY_KP_DECIMAL;
|
||||
keycodes[0x135] = KB_KEY_KP_DIVIDE;
|
||||
keycodes[0x11C] = KB_KEY_KP_ENTER;
|
||||
keycodes[0x037] = KB_KEY_KP_MULTIPLY;
|
||||
keycodes[0x04A] = KB_KEY_KP_SUBTRACT;
|
||||
g_keycodes[0x052] = KB_KEY_KP_0;
|
||||
g_keycodes[0x04F] = KB_KEY_KP_1;
|
||||
g_keycodes[0x050] = KB_KEY_KP_2;
|
||||
g_keycodes[0x051] = KB_KEY_KP_3;
|
||||
g_keycodes[0x04B] = KB_KEY_KP_4;
|
||||
g_keycodes[0x04C] = KB_KEY_KP_5;
|
||||
g_keycodes[0x04D] = KB_KEY_KP_6;
|
||||
g_keycodes[0x047] = KB_KEY_KP_7;
|
||||
g_keycodes[0x048] = KB_KEY_KP_8;
|
||||
g_keycodes[0x049] = KB_KEY_KP_9;
|
||||
g_keycodes[0x04E] = KB_KEY_KP_ADD;
|
||||
g_keycodes[0x053] = KB_KEY_KP_DECIMAL;
|
||||
g_keycodes[0x135] = KB_KEY_KP_DIVIDE;
|
||||
g_keycodes[0x11C] = KB_KEY_KP_ENTER;
|
||||
g_keycodes[0x037] = KB_KEY_KP_MULTIPLY;
|
||||
g_keycodes[0x04A] = KB_KEY_KP_SUBTRACT;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -585,7 +590,7 @@ Key translate_key(unsigned int wParam, unsigned long lParam) {
|
||||
if (wParam == VK_PROCESSKEY)
|
||||
return KB_KEY_UNKNOWN;
|
||||
|
||||
return (Key) keycodes[HIWORD(lParam) & 0x1FF];
|
||||
return (Key) g_keycodes[HIWORD(lParam) & 0x1FF];
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -21,7 +21,7 @@ stretch_image(uint32_t *srcImage, uint32_t srcX, uint32_t srcY, uint32_t srcWidt
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Window *
|
||||
mfb_open_ex(const char *title, int width, int height, int flags) {
|
||||
mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags) {
|
||||
int depth, i, formatCount, convDepth = -1;
|
||||
XPixmapFormatValues* formats;
|
||||
XSetWindowAttributes windowAttributes;
|
||||
@ -175,7 +175,7 @@ mfb_open_ex(const char *title, int width, int height, int flags) {
|
||||
|
||||
window_data_x11->image = XCreateImage(window_data_x11->display, CopyFromParent, depth, ZPixmap, 0, 0x0, width, height, 32, width * 4);
|
||||
|
||||
mfb_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
mfb_set_keyboard_callback((struct Window *) window_data, keyboard_default);
|
||||
|
||||
printf("Window created using X11 API\n");
|
||||
|
||||
@ -183,7 +183,7 @@ mfb_open_ex(const char *title, int width, int height, int flags) {
|
||||
}
|
||||
|
||||
struct Window *
|
||||
mfb_open(const char *title, int width, int height)
|
||||
mfb_open(const char *title, unsigned width, unsigned height)
|
||||
{
|
||||
return mfb_open_ex(title, width, height, 0);
|
||||
}
|
||||
@ -206,11 +206,12 @@ static void processEvents(SWindowData *window_data)
|
||||
case KeyPress:
|
||||
case KeyRelease:
|
||||
{
|
||||
Key kb_key = (Key) translate_key(event.xkey.keycode);
|
||||
Key key_code = (Key) translate_key(event.xkey.keycode);
|
||||
int is_pressed = (event.type == KeyPress);
|
||||
window_data->mod_keys = translate_mod_ex(kb_key, event.xkey.state, is_pressed);
|
||||
window_data->mod_keys = translate_mod_ex(key_code, event.xkey.state, is_pressed);
|
||||
|
||||
kCall(keyboard_func, kb_key, (KeyMod) window_data->mod_keys, is_pressed);
|
||||
window_data->key_status[key_code] = is_pressed;
|
||||
kCall(keyboard_func, key_code, (KeyMod) window_data->mod_keys, is_pressed);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -249,6 +250,8 @@ static void processEvents(SWindowData *window_data)
|
||||
break;
|
||||
|
||||
case MotionNotify:
|
||||
window_data->mouse_pos_x = event.xmotion.x;
|
||||
window_data->mouse_pos_y = event.xmotion.y;
|
||||
kCall(mouse_move_func, event.xmotion.x, event.xmotion.y);
|
||||
break;
|
||||
|
||||
@ -271,10 +274,12 @@ static void processEvents(SWindowData *window_data)
|
||||
break;
|
||||
|
||||
case FocusIn:
|
||||
window_data->is_active = true;
|
||||
kCall(active_func, true);
|
||||
break;
|
||||
|
||||
case FocusOut:
|
||||
window_data->is_active = false;
|
||||
kCall(active_func, false);
|
||||
break;
|
||||
|
||||
@ -364,7 +369,7 @@ void destroy(SWindowData *window_data)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern short int keycodes[512];
|
||||
extern short int g_keycodes[512];
|
||||
|
||||
static int translateKeyCodeB(int keySym) {
|
||||
|
||||
@ -534,17 +539,17 @@ void init_keycodes(SWindowData_X11 *window_data_x11) {
|
||||
int keySym;
|
||||
|
||||
// Clear keys
|
||||
for (i = 0; i < sizeof(keycodes) / sizeof(keycodes[0]); ++i)
|
||||
keycodes[i] = KB_KEY_UNKNOWN;
|
||||
for (i = 0; i < sizeof(g_keycodes) / sizeof(g_keycodes[0]); ++i)
|
||||
g_keycodes[i] = KB_KEY_UNKNOWN;
|
||||
|
||||
// Valid key code range is [8,255], according to the Xlib manual
|
||||
for(int i=8; i<=255; ++i) {
|
||||
// Try secondary keysym, for numeric keypad keys
|
||||
keySym = XkbKeycodeToKeysym(window_data_x11->display, i, 0, 1);
|
||||
keycodes[i] = translateKeyCodeB(keySym);
|
||||
if(keycodes[i] == KB_KEY_UNKNOWN) {
|
||||
g_keycodes[i] = translateKeyCodeB(keySym);
|
||||
if(g_keycodes[i] == KB_KEY_UNKNOWN) {
|
||||
keySym = XkbKeycodeToKeysym(window_data_x11->display, i, 0, 0);
|
||||
keycodes[i] = translateKeyCodeA(keySym);
|
||||
g_keycodes[i] = translateKeyCodeA(keySym);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -555,7 +560,7 @@ int translate_key(int scancode) {
|
||||
if (scancode < 0 || scancode > 255)
|
||||
return KB_KEY_UNKNOWN;
|
||||
|
||||
return keycodes[scancode];
|
||||
return g_keycodes[scancode];
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -94,13 +94,13 @@ int main()
|
||||
if (!window)
|
||||
return 0;
|
||||
|
||||
mfb_active_callback(window, active);
|
||||
mfb_resize_callback(window, resize);
|
||||
mfb_keyboard_callback(window, keyboard);
|
||||
mfb_char_input_callback(window, char_input);
|
||||
mfb_mouse_button_callback(window, mouse_btn);
|
||||
mfb_mouse_move_callback(window, mouse_move);
|
||||
mfb_mouse_scroll_callback(window, mouse_scroll);
|
||||
mfb_set_active_callback(window, active);
|
||||
mfb_set_resize_callback(window, resize);
|
||||
mfb_set_keyboard_callback(window, keyboard);
|
||||
mfb_set_char_input_callback(window, char_input);
|
||||
mfb_set_mouse_button_callback(window, mouse_btn);
|
||||
mfb_set_mouse_move_callback(window, mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window, mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window, (void *) "Input Events Test");
|
||||
|
||||
|
@ -99,13 +99,13 @@ int main()
|
||||
|
||||
Events e;
|
||||
|
||||
mfb_active_callback(window, &e, &Events::active);
|
||||
mfb_resize_callback(window, &e, &Events::resize);
|
||||
mfb_keyboard_callback(window, &e, &Events::keyboard);
|
||||
mfb_char_input_callback(window, &e, &Events::char_input);
|
||||
mfb_mouse_button_callback(window, &e, &Events::mouse_btn);
|
||||
mfb_mouse_move_callback(window, &e, &Events::mouse_move);
|
||||
mfb_mouse_scroll_callback(window, &e, &Events::mouse_scroll);
|
||||
mfb_set_active_callback(window, &e, &Events::active);
|
||||
mfb_set_resize_callback(window, &e, &Events::resize);
|
||||
mfb_set_keyboard_callback(window, &e, &Events::keyboard);
|
||||
mfb_set_char_input_callback(window, &e, &Events::char_input);
|
||||
mfb_set_mouse_button_callback(window, &e, &Events::mouse_btn);
|
||||
mfb_set_mouse_move_callback(window, &e, &Events::mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window, &e, &Events::mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window, (void *) "Input Events CPP Test");
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
#include <MiniFB.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#define kPI 3.14159265358979323846f
|
||||
#define kUnused(var) (void) var;
|
||||
|
||||
#define WIDTH_A 800
|
||||
@ -88,13 +90,13 @@ int main()
|
||||
if (!window_a)
|
||||
return 0;
|
||||
|
||||
mfb_active_callback(window_a, active);
|
||||
mfb_resize_callback(window_a, resize);
|
||||
mfb_keyboard_callback(window_a, keyboard);
|
||||
mfb_char_input_callback(window_a, char_input);
|
||||
mfb_mouse_button_callback(window_a, mouse_btn);
|
||||
mfb_mouse_move_callback(window_a, mouse_move);
|
||||
mfb_mouse_scroll_callback(window_a, mouse_scroll);
|
||||
mfb_set_active_callback(window_a, active);
|
||||
mfb_set_resize_callback(window_a, resize);
|
||||
mfb_set_keyboard_callback(window_a, keyboard);
|
||||
mfb_set_char_input_callback(window_a, char_input);
|
||||
mfb_set_mouse_button_callback(window_a, mouse_btn);
|
||||
mfb_set_mouse_move_callback(window_a, mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window_a, mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window_a, (void *) "Window A");
|
||||
|
||||
@ -103,13 +105,13 @@ int main()
|
||||
if (!window_b)
|
||||
return 0;
|
||||
|
||||
mfb_active_callback(window_b, active);
|
||||
mfb_resize_callback(window_b, resize);
|
||||
mfb_keyboard_callback(window_b, keyboard);
|
||||
mfb_char_input_callback(window_b, char_input);
|
||||
mfb_mouse_button_callback(window_b, mouse_btn);
|
||||
mfb_mouse_move_callback(window_b, mouse_move);
|
||||
mfb_mouse_scroll_callback(window_b, mouse_scroll);
|
||||
mfb_set_active_callback(window_b, active);
|
||||
mfb_set_resize_callback(window_b, resize);
|
||||
mfb_set_keyboard_callback(window_b, keyboard);
|
||||
mfb_set_char_input_callback(window_b, char_input);
|
||||
mfb_set_mouse_button_callback(window_b, mouse_btn);
|
||||
mfb_set_mouse_move_callback(window_b, mouse_move);
|
||||
mfb_set_mouse_scroll_callback(window_b, mouse_scroll);
|
||||
|
||||
mfb_set_user_data(window_b, (void *) "Window B");
|
||||
|
||||
@ -117,7 +119,7 @@ int main()
|
||||
uint32_t pallete[512];
|
||||
float inc = 90.0f / 64.0f;
|
||||
for(uint32_t c=0; c<64; ++c) {
|
||||
int32_t col = (255.0f * sinf(c * inc * M_PI / 180.0f)) + 0.5f;
|
||||
int32_t col = (int32_t) ((255.0f * sinf(c * inc * kPI / 180.0f)) + 0.5f);
|
||||
pallete[64*0 + c] = MFB_RGB(col, 0, 0);
|
||||
pallete[64*1 + c] = MFB_RGB(255, col, 0);
|
||||
pallete[64*2 + c] = MFB_RGB(255-col, 255, 0);
|
||||
@ -151,13 +153,13 @@ int main()
|
||||
}
|
||||
|
||||
//--
|
||||
time_x = sinf(time * M_PI / 180.0f);
|
||||
time_y = cosf(time * M_PI / 180.0f);
|
||||
time_x = sinf(time * kPI / 180.0f);
|
||||
time_y = cosf(time * kPI / 180.0f);
|
||||
i = 0;
|
||||
for(y=0; y<HEIGHT_B; ++y) {
|
||||
dy = cosf((y * time_y) * M_PI / 180.0f); // [-1, 1]
|
||||
dy = cosf((y * time_y) * kPI / 180.0f); // [-1, 1]
|
||||
for(x=0; x<WIDTH_B; ++x) {
|
||||
dx = sinf((x * time_x) * M_PI / 180.0f); // [-1, 1]
|
||||
dx = sinf((x * time_x) * kPI / 180.0f); // [-1, 1]
|
||||
|
||||
index = (int) ((2.0f + dx + dy) * 0.25f * 511.0f); // [0, 511]
|
||||
g_buffer_b[i++] = pallete[index];
|
||||
|
Loading…
Reference in New Issue
Block a user