2019-06-08 18:11:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include "MiniFB.h"
|
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
void mfb_set_active_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, bool));
|
2019-06-08 18:11:02 +00:00
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
void mfb_set_resize_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, int, int));
|
2019-06-08 18:11:02 +00:00
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
void mfb_set_keyboard_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, mfb_key, mfb_key_mod, bool));
|
2019-06-08 18:11:02 +00:00
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
void mfb_set_char_input_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, unsigned int));
|
2019-06-08 18:11:02 +00:00
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
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));
|
2019-06-08 18:11:02 +00:00
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
void mfb_set_mouse_move_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, int, int));
|
2019-06-08 18:11:02 +00:00
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
void mfb_set_mouse_scroll_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, mfb_key_mod, float, float));
|
2019-06-08 18:11:02 +00:00
|
|
|
|
|
|
|
//-------------------------------------
|
|
|
|
// To avoid clumsy hands
|
|
|
|
//-------------------------------------
|
2020-03-06 06:06:54 +00:00
|
|
|
class mfb_stub {
|
|
|
|
mfb_stub() : m_window(0x0) {}
|
2019-11-14 15:18:42 +00:00
|
|
|
|
2019-06-08 18:11:02 +00:00
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
friend void mfb_set_active_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, bool));
|
2019-06-08 18:11:02 +00:00
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
friend void mfb_set_resize_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, int, int));
|
2019-06-08 18:11:02 +00:00
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
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));
|
2019-06-08 18:11:02 +00:00
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
friend void mfb_set_keyboard_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, mfb_key, mfb_key_mod, bool));
|
2019-06-08 18:11:02 +00:00
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
friend void mfb_set_char_input_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, unsigned int));
|
2019-06-08 18:11:02 +00:00
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
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));
|
2019-06-08 18:11:02 +00:00
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
friend void mfb_set_mouse_move_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *, int, int));
|
2019-06-08 18:11:02 +00:00
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
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 mfb_stub *GetInstance(struct mfb_window *window);
|
|
|
|
|
|
|
|
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 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;
|
2019-06-08 18:11:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//-------------------------------------
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
inline void mfb_set_active_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *window, bool)) {
|
2019-06-08 18:11:02 +00:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_stub *stub = mfb_stub::GetInstance(window);
|
2019-06-08 18:34:05 +00:00
|
|
|
stub->m_active = std::bind(method, obj, _1, _2);
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_set_active_callback(window, mfb_stub::active_stub);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
inline void mfb_set_resize_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *window, int, int)) {
|
2019-06-08 18:11:02 +00:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_stub *stub = mfb_stub::GetInstance(window);
|
2019-06-08 18:34:05 +00:00
|
|
|
stub->m_resize = std::bind(method, obj, _1, _2, _3);
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_set_resize_callback(window, mfb_stub::resize_stub);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
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)) {
|
2019-06-08 18:11:02 +00:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_stub *stub = mfb_stub::GetInstance(window);
|
2019-06-08 18:34:05 +00:00
|
|
|
stub->m_keyboard = std::bind(method, obj, _1, _2, _3, _4);
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_set_keyboard_callback(window, mfb_stub::keyboard_stub);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
inline void mfb_set_char_input_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *window, unsigned int)) {
|
2019-06-08 18:11:02 +00:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_stub *stub = mfb_stub::GetInstance(window);
|
2019-06-08 18:34:05 +00:00
|
|
|
stub->m_char_input = std::bind(method, obj, _1, _2);
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_set_char_input_callback(window, mfb_stub::char_input_stub);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
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)) {
|
2019-06-08 18:11:02 +00:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_stub *stub = mfb_stub::GetInstance(window);
|
2019-06-08 18:34:05 +00:00
|
|
|
stub->m_mouse_btn = std::bind(method, obj, _1, _2, _3, _4);
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_set_mouse_button_callback(window, mfb_stub::mouse_btn_stub);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
inline void mfb_set_mouse_move_callback(struct mfb_window *window, T *obj, void (T::*method)(struct mfb_window *window, int, int)) {
|
2019-06-08 18:11:02 +00:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_stub *stub = mfb_stub::GetInstance(window);
|
2019-06-08 18:34:05 +00:00
|
|
|
stub->m_mouse_move = std::bind(method, obj, _1, _2, _3);
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_set_mouse_move_callback(window, mfb_stub::mouse_move_stub);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2020-03-06 06:06:54 +00:00
|
|
|
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)) {
|
2019-06-08 18:11:02 +00:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_stub *stub = mfb_stub::GetInstance(window);
|
2019-06-08 18:34:05 +00:00
|
|
|
stub->m_scroll = std::bind(method, obj, _1, _2, _3, _4);
|
2020-03-06 06:06:54 +00:00
|
|
|
mfb_set_mouse_scroll_callback(window, mfb_stub::scroll_stub);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|