2019-06-08 18:11:02 +00:00
|
|
|
#include <MiniFB_cpp.h>
|
|
|
|
#include <MiniFB_enums.h>
|
2019-06-08 18:34:05 +00:00
|
|
|
#include <vector>
|
2019-06-08 18:11:02 +00:00
|
|
|
|
2019-06-08 18:34:05 +00:00
|
|
|
Stub *
|
|
|
|
Stub::GetInstance(struct Window *window) {
|
|
|
|
static std::vector<Stub *> s_instances;
|
2019-06-08 18:11:02 +00:00
|
|
|
|
2019-06-08 18:34:05 +00:00
|
|
|
for(Stub *instance : s_instances) {
|
|
|
|
if(instance->m_window == window) {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s_instances.push_back(new Stub);
|
|
|
|
s_instances.back()->m_window = window;
|
|
|
|
|
|
|
|
return s_instances.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Stub::active_stub(struct Window *window, bool isActive) {
|
|
|
|
Stub *stub = Stub::GetInstance(window);
|
|
|
|
stub->m_active(window, isActive);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 18:34:05 +00:00
|
|
|
void Stub::resize_stub(struct Window *window, int width, int height) {
|
|
|
|
Stub *stub = Stub::GetInstance(window);
|
|
|
|
stub->m_resize(window, width, height);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 18:34:05 +00:00
|
|
|
void Stub::keyboard_stub(struct Window *window, Key key, KeyMod mod, bool isPressed) {
|
|
|
|
Stub *stub = Stub::GetInstance(window);
|
|
|
|
stub->m_keyboard(window, key, mod, isPressed);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 18:34:05 +00:00
|
|
|
void Stub::char_input_stub(struct Window *window, unsigned int code) {
|
|
|
|
Stub *stub = Stub::GetInstance(window);
|
|
|
|
stub->m_char_input(window, code);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 18:34:05 +00:00
|
|
|
void Stub::mouse_btn_stub(struct Window *window, MouseButton button, KeyMod mod, bool isPressed) {
|
|
|
|
Stub *stub = Stub::GetInstance(window);
|
|
|
|
stub->m_mouse_btn(window, button, mod, isPressed);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 18:34:05 +00:00
|
|
|
void Stub::mouse_move_stub(struct Window *window, int x, int y) {
|
|
|
|
Stub *stub = Stub::GetInstance(window);
|
|
|
|
stub->m_mouse_move(window, x, y);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 18:34:05 +00:00
|
|
|
void Stub::scroll_stub(struct Window *window, KeyMod mod, float deltaX, float deltaY) {
|
|
|
|
Stub *stub = Stub::GetInstance(window);
|
|
|
|
stub->m_scroll(window, mod, deltaX, deltaY);
|
2019-06-08 18:11:02 +00:00
|
|
|
}
|