ruby/input: Add macOS mouse support

While keyboard and joypad input had already been present for some time,
mouse input for macOS remained unimplemented in ruby.

Until now, that is.
This commit is contained in:
Sintendo
2021-10-30 09:36:36 +02:00
committed by Screwtapello
parent 6df1807068
commit 74f6ffe89b
2 changed files with 91 additions and 4 deletions

View File

@@ -1,9 +1,10 @@
#include "keyboard/quartz.cpp"
#include "mouse/quartz.cpp"
#include "joypad/iokit.cpp"
struct InputQuartz : InputDriver {
InputQuartz& self = *this;
InputQuartz(Input& super) : InputDriver(super), keyboard(super), joypad(super) {}
InputQuartz(Input& super) : InputDriver(super), keyboard(super), mouse(super), joypad(super) {}
~InputQuartz() { terminate(); }
auto create() -> bool override {
@@ -13,13 +14,14 @@ struct InputQuartz : InputDriver {
auto driver() -> string override { return "Quartz"; }
auto ready() -> bool override { return isReady; }
auto acquired() -> bool override { return false; }
auto acquire() -> bool override { return false; }
auto release() -> bool override { return false; }
auto acquired() -> bool override { return mouse.acquired(); }
auto acquire() -> bool override { return mouse.acquire(); }
auto release() -> bool override { return mouse.release(); }
auto poll() -> vector<shared_pointer<HID::Device>> override {
vector<shared_pointer<HID::Device>> devices;
keyboard.poll(devices);
mouse.poll(devices);
joypad.poll(devices);
return devices;
}
@@ -32,6 +34,7 @@ private:
auto initialize() -> bool {
terminate();
if(!keyboard.initialize()) return false;
if(!mouse.initialize()) return false;
if(!joypad.initialize()) return false;
return isReady = true;
}
@@ -39,10 +42,12 @@ private:
auto terminate() -> void {
isReady = false;
keyboard.terminate();
mouse.terminate();
joypad.terminate();
}
bool isReady = false;
InputKeyboardQuartz keyboard;
InputMouseQuartz mouse;
InputJoypadIOKit joypad;
};