reflexion 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.doc/ext/reflex/application.cpp +16 -0
- data/.doc/ext/reflex/device.cpp +46 -3
- data/.doc/ext/reflex/device_event.cpp +62 -0
- data/.doc/ext/reflex/key_event.cpp +50 -0
- data/.doc/ext/reflex/native.cpp +6 -4
- data/.doc/ext/reflex/reflex.cpp +24 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +12 -0
- data/CONTRIBUTING.md +7 -0
- data/ChangeLog.md +20 -0
- data/README.md +46 -2
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +18 -0
- data/ext/reflex/device.cpp +48 -3
- data/ext/reflex/device_event.cpp +65 -0
- data/ext/reflex/extconf.rb +3 -3
- data/ext/reflex/key_event.cpp +50 -0
- data/ext/reflex/native.cpp +6 -4
- data/ext/reflex/reflex.cpp +24 -0
- data/include/reflex/application.h +4 -0
- data/include/reflex/defs.h +60 -0
- data/include/reflex/device.h +22 -0
- data/include/reflex/event.h +25 -0
- data/include/reflex/gamepad.h +175 -0
- data/include/reflex/ruby/application.h +18 -0
- data/include/reflex/ruby/device.h +40 -0
- data/include/reflex/ruby/event.h +11 -0
- data/reflex.gemspec +3 -3
- data/src/application.cpp +67 -0
- data/src/application.h +9 -0
- data/src/device.cpp +24 -0
- data/src/event.cpp +38 -0
- data/src/gamepad.cpp +176 -0
- data/src/gamepad.h +74 -0
- data/src/ios/app_delegate.mm +2 -2
- data/src/ios/application.mm +0 -25
- data/src/ios/event.mm +2 -3
- data/src/ios/gamepad.mm +313 -0
- data/src/osx/app_delegate.mm +2 -2
- data/src/osx/application.mm +0 -25
- data/src/osx/event.h +3 -0
- data/src/osx/event.mm +11 -3
- data/src/osx/gamepad.mm +40 -0
- data/src/osx/gamepad_gc.mm +299 -0
- data/src/osx/gamepad_hid.mm +567 -0
- data/src/view.cpp +52 -18
- data/src/win32/application.cpp +5 -26
- data/src/win32/event.cpp +8 -7
- data/src/win32/event.h +5 -0
- data/src/win32/gamepad.cpp +110 -0
- data/src/win32/gamepad.h +20 -0
- data/src/win32/window.cpp +9 -1
- data/src/window.cpp +15 -0
- data/src/window.h +9 -0
- metadata +30 -14
data/src/osx/event.mm
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
#include <assert.h>
|
|
6
6
|
#include <Carbon/Carbon.h>
|
|
7
7
|
#import <Cocoa/Cocoa.h>
|
|
8
|
+
#include "reflex/exception.h"
|
|
9
|
+
#include "reflex/debug.h"
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
namespace Reflex
|
|
@@ -12,9 +14,9 @@ namespace Reflex
|
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
static uint
|
|
15
|
-
get_modifiers (const NSEvent*
|
|
17
|
+
get_modifiers (const NSEvent* event)
|
|
16
18
|
{
|
|
17
|
-
NSUInteger flags =
|
|
19
|
+
NSUInteger flags = event ? event.modifierFlags : NSEvent.modifierFlags;
|
|
18
20
|
return
|
|
19
21
|
(flags & NSAlphaShiftKeyMask) ? MOD_CAPS : 0 |
|
|
20
22
|
(flags & NSShiftKeyMask) ? MOD_SHIFT : 0 |
|
|
@@ -26,6 +28,12 @@ namespace Reflex
|
|
|
26
28
|
(flags & NSFunctionKeyMask) ? MOD_FUNCTION : 0;
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
uint
|
|
32
|
+
get_key_modifiers ()
|
|
33
|
+
{
|
|
34
|
+
return get_modifiers(nil);
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
static Point
|
|
30
38
|
get_pointer_position (NSEvent* e, NSView* view)
|
|
31
39
|
{
|
|
@@ -161,4 +169,4 @@ namespace Reflex
|
|
|
161
169
|
}
|
|
162
170
|
|
|
163
171
|
|
|
164
|
-
}
|
|
172
|
+
}// Reflex
|
data/src/osx/gamepad.mm
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// -*- objc -*-
|
|
2
|
+
#include "../gamepad.h"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
#include "reflex/exception.h"
|
|
6
|
+
#include "../gamepad.h"
|
|
7
|
+
#include "application.h"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
namespace Reflex
|
|
11
|
+
{
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
void init_gc_gamepads (Application* app);
|
|
15
|
+
|
|
16
|
+
void fin_gc_gamepads (Application* app);
|
|
17
|
+
|
|
18
|
+
void init_hid_gamepads (Application* app);
|
|
19
|
+
|
|
20
|
+
void fin_hid_gamepads (Application* app);
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
void
|
|
24
|
+
Gamepad_init (Application* app)
|
|
25
|
+
{
|
|
26
|
+
init_gc_gamepads(app);
|
|
27
|
+
init_hid_gamepads(app);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void
|
|
31
|
+
Gamepad_fin (Application* app)
|
|
32
|
+
{
|
|
33
|
+
fin_gc_gamepads(app);
|
|
34
|
+
fin_hid_gamepads(app);
|
|
35
|
+
|
|
36
|
+
Gamepad_remove_all(app);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
}// Reflex
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
// -*- objc -*-
|
|
2
|
+
#include "../gamepad.h"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
#import <GameController/GameController.h>
|
|
6
|
+
#include "reflex/exception.h"
|
|
7
|
+
#include "reflex/debug.h"
|
|
8
|
+
#include "event.h"
|
|
9
|
+
#include "window.h"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
namespace Reflex
|
|
13
|
+
{
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
struct GameControllerGamepadData : Gamepad::Data
|
|
17
|
+
{
|
|
18
|
+
|
|
19
|
+
typedef Gamepad::Data Super;
|
|
20
|
+
|
|
21
|
+
GCController* controller = nil;
|
|
22
|
+
|
|
23
|
+
GameControllerGamepadData (GCController* controller)
|
|
24
|
+
: controller([controller retain])
|
|
25
|
+
{
|
|
26
|
+
prev.reset(new Gamepad());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
~GameControllerGamepadData ()
|
|
30
|
+
{
|
|
31
|
+
//clear_event_handlers(controller);
|
|
32
|
+
[controller release];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const char* name () const override
|
|
36
|
+
{
|
|
37
|
+
return controller.vendorName.UTF8String;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
bool is_valid () const override
|
|
41
|
+
{
|
|
42
|
+
return Super::is_valid() && controller;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
bool has_handle (void* handle) const override
|
|
46
|
+
{
|
|
47
|
+
return handle == controller;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
};// GameControllerGamepadData
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
static Gamepad*
|
|
54
|
+
Gamepad_create (GCController* controller)
|
|
55
|
+
{
|
|
56
|
+
Gamepad* g = Gamepad_create();
|
|
57
|
+
g->self.reset(new GameControllerGamepadData(controller));
|
|
58
|
+
return g;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static void
|
|
62
|
+
call_gamepad_event (int key_code, bool pressed)
|
|
63
|
+
{
|
|
64
|
+
Window* win = Window_get_active();
|
|
65
|
+
if (!win) return;
|
|
66
|
+
|
|
67
|
+
auto action = pressed ? KeyEvent::DOWN : KeyEvent::UP;
|
|
68
|
+
KeyEvent e(action, NULL, key_code, get_key_modifiers(), 0);
|
|
69
|
+
Window_call_key_event(win, &e);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static void
|
|
73
|
+
call_button_event (
|
|
74
|
+
Gamepad* gamepad, ulonglong button, int key_code, float value)
|
|
75
|
+
{
|
|
76
|
+
Gamepad::Data* self = gamepad->self.get();
|
|
77
|
+
|
|
78
|
+
bool pressed = value > Gamepad_get_button_press_threshold();
|
|
79
|
+
bool current = self->state.buttons & button;
|
|
80
|
+
if (pressed == current) return;
|
|
81
|
+
|
|
82
|
+
self->update_prev();
|
|
83
|
+
if (pressed)
|
|
84
|
+
self->state.buttons |= button;
|
|
85
|
+
else
|
|
86
|
+
self->state.buttons &= ~button;
|
|
87
|
+
|
|
88
|
+
call_gamepad_event(key_code, pressed);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static void
|
|
92
|
+
handle_button_event (
|
|
93
|
+
Gamepad* gamepad, GCControllerButtonInput* input,
|
|
94
|
+
ulonglong button, int key_code)
|
|
95
|
+
{
|
|
96
|
+
[input setPressedChangedHandler:
|
|
97
|
+
^(GCControllerButtonInput*, float, BOOL pressed)
|
|
98
|
+
{
|
|
99
|
+
call_button_event(gamepad, button, key_code, pressed ? 1 : 0);
|
|
100
|
+
}];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static void
|
|
104
|
+
handle_stick_dpad_event (
|
|
105
|
+
Gamepad* gamepad, GCControllerButtonInput* input,
|
|
106
|
+
ulonglong button, int key_code)
|
|
107
|
+
{
|
|
108
|
+
[input setValueChangedHandler:
|
|
109
|
+
^(GCControllerButtonInput*, float value, BOOL)
|
|
110
|
+
{
|
|
111
|
+
call_button_event(gamepad, button, key_code, value);
|
|
112
|
+
}];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static void
|
|
116
|
+
handle_stick_event (
|
|
117
|
+
Gamepad* gamepad, GCControllerDirectionPad* input, Gamepad::Index index)
|
|
118
|
+
{
|
|
119
|
+
[input setValueChangedHandler:
|
|
120
|
+
^(GCControllerDirectionPad*, float x, float y)
|
|
121
|
+
{
|
|
122
|
+
gamepad->self->update_prev();
|
|
123
|
+
gamepad->self->state.sticks[index].reset(x, y);
|
|
124
|
+
}];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static void
|
|
128
|
+
handle_trigger_event (
|
|
129
|
+
Gamepad* gamepad, GCControllerButtonInput* input, Gamepad::Index index,
|
|
130
|
+
ulonglong button, int key_code)
|
|
131
|
+
{
|
|
132
|
+
[input setPressedChangedHandler:
|
|
133
|
+
^(GCControllerButtonInput*, float, BOOL pressed)
|
|
134
|
+
{
|
|
135
|
+
call_button_event(gamepad, button, key_code, pressed ? 1 : 0);
|
|
136
|
+
}];
|
|
137
|
+
|
|
138
|
+
[input setValueChangedHandler:
|
|
139
|
+
^(GCControllerButtonInput*, float value, BOOL)
|
|
140
|
+
{
|
|
141
|
+
Gamepad::Data* self = gamepad->self.get();
|
|
142
|
+
|
|
143
|
+
self->update_prev();
|
|
144
|
+
self->state.triggers[index] = value;
|
|
145
|
+
}];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static void
|
|
149
|
+
handle_gamepad_events (Gamepad* gamepad, GCController* controller)
|
|
150
|
+
{
|
|
151
|
+
GCExtendedGamepad* g = controller.extendedGamepad;
|
|
152
|
+
if (!gamepad) return;
|
|
153
|
+
|
|
154
|
+
static const Gamepad::Index L = Gamepad::INDEX_LEFT, R = Gamepad::INDEX_RIGHT;
|
|
155
|
+
|
|
156
|
+
auto* dpad = g.dpad;
|
|
157
|
+
handle_button_event(gamepad, dpad.left, Gamepad::LEFT, KEY_GAMEPAD_LEFT);
|
|
158
|
+
handle_button_event(gamepad, dpad.right, Gamepad::RIGHT, KEY_GAMEPAD_RIGHT);
|
|
159
|
+
handle_button_event(gamepad, dpad.up, Gamepad::UP, KEY_GAMEPAD_UP);
|
|
160
|
+
handle_button_event(gamepad, dpad.down, Gamepad::DOWN, KEY_GAMEPAD_DOWN);
|
|
161
|
+
|
|
162
|
+
auto* lstick = g.leftThumbstick;
|
|
163
|
+
handle_stick_event( gamepad, lstick, L);
|
|
164
|
+
handle_stick_dpad_event(gamepad, lstick.left, Gamepad::LSTICK_LEFT, KEY_GAMEPAD_LSTICK_LEFT);
|
|
165
|
+
handle_stick_dpad_event(gamepad, lstick.right, Gamepad::LSTICK_RIGHT, KEY_GAMEPAD_LSTICK_RIGHT);
|
|
166
|
+
handle_stick_dpad_event(gamepad, lstick.up, Gamepad::LSTICK_UP, KEY_GAMEPAD_LSTICK_UP);
|
|
167
|
+
handle_stick_dpad_event(gamepad, lstick.down, Gamepad::LSTICK_DOWN, KEY_GAMEPAD_LSTICK_DOWN);
|
|
168
|
+
|
|
169
|
+
auto* rstick = g.rightThumbstick;
|
|
170
|
+
handle_stick_event( gamepad, rstick, R);
|
|
171
|
+
handle_stick_dpad_event(gamepad, rstick.left, Gamepad::RSTICK_LEFT, KEY_GAMEPAD_RSTICK_LEFT);
|
|
172
|
+
handle_stick_dpad_event(gamepad, rstick.right, Gamepad::RSTICK_RIGHT, KEY_GAMEPAD_RSTICK_RIGHT);
|
|
173
|
+
handle_stick_dpad_event(gamepad, rstick.up, Gamepad::RSTICK_UP, KEY_GAMEPAD_RSTICK_UP);
|
|
174
|
+
handle_stick_dpad_event(gamepad, rstick.down, Gamepad::RSTICK_DOWN, KEY_GAMEPAD_RSTICK_DOWN);
|
|
175
|
+
|
|
176
|
+
handle_button_event(gamepad, g.buttonA, Gamepad::BUTTON_A, KEY_GAMEPAD_A);
|
|
177
|
+
handle_button_event(gamepad, g.buttonB, Gamepad::BUTTON_B, KEY_GAMEPAD_B);
|
|
178
|
+
handle_button_event(gamepad, g.buttonX, Gamepad::BUTTON_X, KEY_GAMEPAD_X);
|
|
179
|
+
handle_button_event(gamepad, g.buttonY, Gamepad::BUTTON_Y, KEY_GAMEPAD_Y);
|
|
180
|
+
|
|
181
|
+
handle_button_event( gamepad, g. leftShoulder, Gamepad::LSHOULDER, KEY_GAMEPAD_LSHOULDER);
|
|
182
|
+
handle_button_event( gamepad, g.rightShoulder, Gamepad::RSHOULDER, KEY_GAMEPAD_RSHOULDER);
|
|
183
|
+
handle_trigger_event(gamepad, g. leftTrigger, L, Gamepad::LTRIGGER, KEY_GAMEPAD_LTRIGGER);
|
|
184
|
+
handle_trigger_event(gamepad, g.rightTrigger, R, Gamepad::RTRIGGER, KEY_GAMEPAD_RTRIGGER);
|
|
185
|
+
|
|
186
|
+
if (@available(macOS 10.14.1, *))
|
|
187
|
+
{
|
|
188
|
+
handle_button_event(gamepad, g. leftThumbstickButton, Gamepad::LTHUMB, KEY_GAMEPAD_LTHUMB);
|
|
189
|
+
handle_button_event(gamepad, g.rightThumbstickButton, Gamepad::RTHUMB, KEY_GAMEPAD_RTHUMB);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (@available(macOS 10.15, *))
|
|
193
|
+
{
|
|
194
|
+
handle_button_event(gamepad, g.buttonMenu, Gamepad::MENU, KEY_GAMEPAD_MENU);
|
|
195
|
+
handle_button_event(gamepad, g.buttonOptions, Gamepad::OPTION, KEY_GAMEPAD_OPTION);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (@available(macOS 11.0, *))
|
|
199
|
+
handle_button_event(gamepad, g.buttonHome, Gamepad::HOME, KEY_GAMEPAD_HOME);
|
|
200
|
+
|
|
201
|
+
if (@available(macOS 11.0, *))
|
|
202
|
+
{
|
|
203
|
+
if ([g isKindOfClass: GCDualShockGamepad.class])
|
|
204
|
+
{
|
|
205
|
+
GCDualShockGamepad* dualshock = (GCDualShockGamepad*) g;
|
|
206
|
+
handle_button_event(
|
|
207
|
+
gamepad, dualshock.touchpadButton,
|
|
208
|
+
Gamepad::BUTTON_TOUCH, KEY_GAMEPAD_BUTTON_TOUCH);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (@available(macOS 11.3, *))
|
|
213
|
+
{
|
|
214
|
+
if ([g isKindOfClass: GCDualSenseGamepad.class])
|
|
215
|
+
{
|
|
216
|
+
GCDualSenseGamepad* dualsense = (GCDualSenseGamepad*) g;
|
|
217
|
+
handle_button_event(
|
|
218
|
+
gamepad, dualsense.touchpadButton,
|
|
219
|
+
Gamepad::BUTTON_TOUCH, KEY_GAMEPAD_BUTTON_TOUCH);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (@available(macOS 11.0, *))
|
|
224
|
+
{
|
|
225
|
+
if ([g isKindOfClass: GCXboxGamepad.class])
|
|
226
|
+
{
|
|
227
|
+
GCXboxGamepad* xbox = (GCXboxGamepad*) g;
|
|
228
|
+
handle_button_event(
|
|
229
|
+
gamepad, xbox.paddleButton1, Gamepad::RPADDLE_0, KEY_GAMEPAD_RPADDLE_0);
|
|
230
|
+
handle_button_event(
|
|
231
|
+
gamepad, xbox.paddleButton2, Gamepad::LPADDLE_0, KEY_GAMEPAD_LPADDLE_0);
|
|
232
|
+
handle_button_event(
|
|
233
|
+
gamepad, xbox.paddleButton3, Gamepad::RPADDLE_1, KEY_GAMEPAD_RPADDLE_1);
|
|
234
|
+
handle_button_event(
|
|
235
|
+
gamepad, xbox.paddleButton4, Gamepad::LPADDLE_1, KEY_GAMEPAD_LPADDLE_1);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
static void
|
|
241
|
+
add_gamepad (Application* app, GCController* controller)
|
|
242
|
+
{
|
|
243
|
+
Gamepad* gamepad = Gamepad_create(controller);
|
|
244
|
+
handle_gamepad_events(gamepad, controller);
|
|
245
|
+
|
|
246
|
+
Gamepad_add(app, gamepad);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
static void
|
|
250
|
+
remove_gamepad (Application* app, GCController* controller)
|
|
251
|
+
{
|
|
252
|
+
Gamepad* gamepad = Gamepad_find(controller);
|
|
253
|
+
if (!gamepad) return;
|
|
254
|
+
|
|
255
|
+
Gamepad_remove(app, gamepad);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
static id connect_observer = nil;
|
|
259
|
+
|
|
260
|
+
static id disconnect_observer = nil;
|
|
261
|
+
|
|
262
|
+
void
|
|
263
|
+
init_gc_gamepads (Application* app)
|
|
264
|
+
{
|
|
265
|
+
if (connect_observer || disconnect_observer)
|
|
266
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
267
|
+
|
|
268
|
+
connect_observer = [NSNotificationCenter.defaultCenter
|
|
269
|
+
addObserverForName: GCControllerDidConnectNotification
|
|
270
|
+
object: nil
|
|
271
|
+
queue: NSOperationQueue.mainQueue
|
|
272
|
+
usingBlock: ^(NSNotification* n) {add_gamepad(app, n.object);}];
|
|
273
|
+
|
|
274
|
+
disconnect_observer = [NSNotificationCenter.defaultCenter
|
|
275
|
+
addObserverForName: GCControllerDidDisconnectNotification
|
|
276
|
+
object: nil
|
|
277
|
+
queue: NSOperationQueue.mainQueue
|
|
278
|
+
usingBlock: ^(NSNotification* n) {remove_gamepad(app, n.object);}];
|
|
279
|
+
|
|
280
|
+
for (GCController* c in GCController.controllers)
|
|
281
|
+
add_gamepad(app, c);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
void
|
|
285
|
+
fin_gc_gamepads (Application* app)
|
|
286
|
+
{
|
|
287
|
+
if (!connect_observer || !disconnect_observer)
|
|
288
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
289
|
+
|
|
290
|
+
[NSNotificationCenter.defaultCenter
|
|
291
|
+
removeObserver: connect_observer];
|
|
292
|
+
[NSNotificationCenter.defaultCenter
|
|
293
|
+
removeObserver: disconnect_observer];
|
|
294
|
+
|
|
295
|
+
connect_observer = disconnect_observer = nil;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
}// Reflex
|