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