mirror of
https://github.com/dingusdev/dingusppc.git
synced 2024-12-27 00:29:18 +00:00
59fba285b5
Add absolute coordinates for tablets. Absolute coordinates is relative to window so it can't work for multiple displays? Doesn't work for single display without mouse driver modification. Add arbitrary number of buttons. Previously, only one mouse button was supported. Add arbitrary number of bits. Previously, only 7 bits per axis was supported which is good enough for relative movement but not absolute movement.
124 lines
3.2 KiB
C++
124 lines
3.2 KiB
C++
/*
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
|
Copyright (C) 2018-23 divingkatae and maximum
|
|
(theweirdo) spatium
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef EVENT_MANAGER_H
|
|
#define EVENT_MANAGER_H
|
|
|
|
#include <core/coresignal.h>
|
|
|
|
#include <cinttypes>
|
|
|
|
class WindowEvent {
|
|
public:
|
|
WindowEvent() = default;
|
|
~WindowEvent() = default;
|
|
|
|
uint16_t sub_type;
|
|
uint32_t window_id;
|
|
};
|
|
|
|
enum : uint32_t {
|
|
MOUSE_EVENT_MOTION = 1 << 0,
|
|
MOUSE_EVENT_BUTTON = 1 << 1,
|
|
KEYBOARD_EVENT_DOWN = 1 << 0,
|
|
KEYBOARD_EVENT_UP = 1 << 1,
|
|
};
|
|
|
|
class MouseEvent {
|
|
public:
|
|
MouseEvent() = default;
|
|
~MouseEvent() = default;
|
|
|
|
uint32_t flags;
|
|
uint32_t xrel;
|
|
uint32_t yrel;
|
|
uint32_t xabs;
|
|
uint32_t yabs;
|
|
uint8_t buttons_state;
|
|
};
|
|
|
|
class KeyboardEvent {
|
|
public:
|
|
KeyboardEvent() = default;
|
|
~KeyboardEvent() = default;
|
|
|
|
uint32_t flags;
|
|
uint32_t key;
|
|
uint16_t keys_state;
|
|
};
|
|
|
|
class EventManager {
|
|
public:
|
|
static EventManager* get_instance() {
|
|
if (!event_manager) {
|
|
event_manager = new EventManager();
|
|
}
|
|
return event_manager;
|
|
};
|
|
|
|
void poll_events();
|
|
|
|
template <typename T>
|
|
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
|
|
_window_signal.connect_method(inst, func);
|
|
}
|
|
|
|
template <typename T>
|
|
void add_mouse_handler(T *inst, void (T::*func)(const MouseEvent&)) {
|
|
_mouse_signal.connect_method(inst, func);
|
|
}
|
|
|
|
template <typename T>
|
|
void add_keyboard_handler(T* inst, void (T::*func)(const KeyboardEvent&)) {
|
|
_keyboard_signal.connect_method(inst, func);
|
|
}
|
|
|
|
template <typename T>
|
|
void add_post_handler(T *inst, void (T::*func)()) {
|
|
_post_signal.connect_method(inst, func);
|
|
}
|
|
|
|
void disconnect_handlers() {
|
|
_window_signal.disconnect_all();
|
|
_mouse_signal.disconnect_all();
|
|
_keyboard_signal.disconnect_all();
|
|
_post_signal.disconnect_all();
|
|
}
|
|
|
|
private:
|
|
static EventManager* event_manager;
|
|
EventManager() {}; // private constructor to implement a singleton
|
|
|
|
CoreSignal<const WindowEvent&> _window_signal;
|
|
CoreSignal<const MouseEvent&> _mouse_signal;
|
|
CoreSignal<const KeyboardEvent&> _keyboard_signal;
|
|
CoreSignal<> _post_signal;
|
|
|
|
uint64_t events_captured = 0;
|
|
uint64_t unhandled_events = 0;
|
|
uint64_t key_downs = 0;
|
|
uint64_t key_ups = 0;
|
|
uint64_t mouse_motions = 0;
|
|
uint8_t buttons_state = 0;
|
|
};
|
|
|
|
#endif // EVENT_MANAGER_H
|