reflexion 0.3.5 → 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 +49 -19
- data/.doc/ext/reflex/native.cpp +6 -4
- data/.doc/ext/reflex/reflex.cpp +7 -6
- data/ChangeLog.md +8 -0
- 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/key_event.cpp +49 -19
- data/ext/reflex/native.cpp +6 -4
- data/ext/reflex/reflex.cpp +7 -6
- data/include/reflex/application.h +4 -0
- data/include/reflex/defs.h +58 -21
- 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.h +0 -5
- data/src/ios/event.mm +1 -85
- data/src/ios/gamepad.mm +313 -0
- data/src/ios/reflex.mm +0 -5
- data/src/osx/app_delegate.mm +2 -2
- data/src/osx/application.mm +0 -25
- data/src/osx/event.h +1 -3
- data/src/osx/event.mm +9 -86
- 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/osx/reflex.mm +0 -5
- data/src/win32/application.cpp +5 -26
- data/src/win32/event.cpp +6 -89
- data/src/win32/event.h +3 -1
- data/src/win32/gamepad.cpp +110 -0
- data/src/win32/gamepad.h +20 -0
- data/src/win32/window.cpp +2 -1
- metadata +28 -14
data/src/ios/reflex.mm
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
#include "reflex/exception.h"
|
6
|
-
#include "event.h"
|
7
6
|
|
8
7
|
|
9
8
|
namespace Reflex
|
@@ -25,8 +24,6 @@ namespace Reflex
|
|
25
24
|
reflex_error(__FILE__, __LINE__, "already initialized.");
|
26
25
|
|
27
26
|
global::pool = [[NSAutoreleasePool alloc] init];
|
28
|
-
|
29
|
-
init_game_controllers();
|
30
27
|
}
|
31
28
|
|
32
29
|
void
|
@@ -35,8 +32,6 @@ namespace Reflex
|
|
35
32
|
if (!global::pool)
|
36
33
|
reflex_error(__FILE__, __LINE__, "not initialized.");
|
37
34
|
|
38
|
-
fin_game_controllers();
|
39
|
-
|
40
35
|
[global::pool release];
|
41
36
|
global::pool = nil;
|
42
37
|
}
|
data/src/osx/app_delegate.mm
CHANGED
@@ -69,7 +69,7 @@
|
|
69
69
|
return YES;
|
70
70
|
|
71
71
|
Reflex::Event e;
|
72
|
-
application
|
72
|
+
Application_call_start(application, &e);
|
73
73
|
started = true;
|
74
74
|
|
75
75
|
if (e.is_blocked()) [self quit];
|
@@ -119,7 +119,7 @@
|
|
119
119
|
if (self->application)
|
120
120
|
{
|
121
121
|
Reflex::Event e;
|
122
|
-
self->application
|
122
|
+
Application_call_quit(self->application, &e);
|
123
123
|
if (e.is_blocked()) return NSTerminateCancel;
|
124
124
|
}
|
125
125
|
|
data/src/osx/application.mm
CHANGED
@@ -75,36 +75,11 @@ namespace Reflex
|
|
75
75
|
[NSApp terminate: nil];
|
76
76
|
}
|
77
77
|
|
78
|
-
void
|
79
|
-
Application::on_start (Event* e)
|
80
|
-
{
|
81
|
-
}
|
82
|
-
|
83
|
-
void
|
84
|
-
Application::on_quit (Event* e)
|
85
|
-
{
|
86
|
-
}
|
87
|
-
|
88
|
-
void
|
89
|
-
Application::on_motion (MotionEvent* e)
|
90
|
-
{
|
91
|
-
}
|
92
|
-
|
93
|
-
void
|
94
|
-
Application::on_preference (Event* e)
|
95
|
-
{
|
96
|
-
}
|
97
|
-
|
98
78
|
void
|
99
79
|
Application::on_about (Event* e)
|
100
80
|
{
|
101
81
|
[NSApp orderFrontStandardAboutPanel: nil];
|
102
82
|
}
|
103
83
|
|
104
|
-
Application::operator bool () const
|
105
|
-
{
|
106
|
-
return true;
|
107
|
-
}
|
108
|
-
|
109
84
|
|
110
85
|
}// Reflex
|
data/src/osx/event.h
CHANGED
data/src/osx/event.mm
CHANGED
@@ -5,9 +5,8 @@
|
|
5
5
|
#include <assert.h>
|
6
6
|
#include <Carbon/Carbon.h>
|
7
7
|
#import <Cocoa/Cocoa.h>
|
8
|
-
#
|
8
|
+
#include "reflex/exception.h"
|
9
9
|
#include "reflex/debug.h"
|
10
|
-
#include "window.h"
|
11
10
|
|
12
11
|
|
13
12
|
namespace Reflex
|
@@ -15,7 +14,7 @@ namespace Reflex
|
|
15
14
|
|
16
15
|
|
17
16
|
static uint
|
18
|
-
get_modifiers (const NSEvent* event
|
17
|
+
get_modifiers (const NSEvent* event)
|
19
18
|
{
|
20
19
|
NSUInteger flags = event ? event.modifierFlags : NSEvent.modifierFlags;
|
21
20
|
return
|
@@ -29,6 +28,12 @@ namespace Reflex
|
|
29
28
|
(flags & NSFunctionKeyMask) ? MOD_FUNCTION : 0;
|
30
29
|
}
|
31
30
|
|
31
|
+
uint
|
32
|
+
get_key_modifiers ()
|
33
|
+
{
|
34
|
+
return get_modifiers(nil);
|
35
|
+
}
|
36
|
+
|
32
37
|
static Point
|
33
38
|
get_pointer_position (NSEvent* e, NSView* view)
|
34
39
|
{
|
@@ -164,86 +169,4 @@ namespace Reflex
|
|
164
169
|
}
|
165
170
|
|
166
171
|
|
167
|
-
|
168
|
-
call_gamepad_event (int code, bool pressed)
|
169
|
-
{
|
170
|
-
Window* win = Window_get_active();
|
171
|
-
if (!win) return;
|
172
|
-
|
173
|
-
auto action = pressed ? KeyEvent::DOWN : KeyEvent::UP;
|
174
|
-
KeyEvent e(action, NULL, code, get_modifiers(), 0);
|
175
|
-
Window_call_key_event(win, &e);
|
176
|
-
}
|
177
|
-
|
178
|
-
static void
|
179
|
-
handle_gamepad_event (GCControllerButtonInput* input, int code)
|
180
|
-
{
|
181
|
-
[input setPressedChangedHandler:
|
182
|
-
^(GCControllerButtonInput* button, float value, BOOL pressed) {
|
183
|
-
call_gamepad_event(code, pressed);
|
184
|
-
}];
|
185
|
-
}
|
186
|
-
|
187
|
-
static void
|
188
|
-
handle_gamepad_events (GCController* controller)
|
189
|
-
{
|
190
|
-
GCExtendedGamepad* gamepad = controller.extendedGamepad;
|
191
|
-
if (!gamepad) return;
|
192
|
-
|
193
|
-
handle_gamepad_event(gamepad.dpad.left, KEY_GAMEPAD_LEFT);
|
194
|
-
handle_gamepad_event(gamepad.dpad.right, KEY_GAMEPAD_RIGHT);
|
195
|
-
handle_gamepad_event(gamepad.dpad.up, KEY_GAMEPAD_UP);
|
196
|
-
handle_gamepad_event(gamepad.dpad.down, KEY_GAMEPAD_DOWN);
|
197
|
-
|
198
|
-
handle_gamepad_event(gamepad.buttonA, KEY_GAMEPAD_A);
|
199
|
-
handle_gamepad_event(gamepad.buttonB, KEY_GAMEPAD_B);
|
200
|
-
handle_gamepad_event(gamepad.buttonX, KEY_GAMEPAD_X);
|
201
|
-
handle_gamepad_event(gamepad.buttonY, KEY_GAMEPAD_Y);
|
202
|
-
|
203
|
-
handle_gamepad_event(gamepad. leftShoulder, KEY_GAMEPAD_SHOULDER_LEFT);
|
204
|
-
handle_gamepad_event(gamepad.rightShoulder, KEY_GAMEPAD_SHOULDER_RIGHT);
|
205
|
-
handle_gamepad_event(gamepad. leftTrigger, KEY_GAMEPAD_TRIGGER_LEFT);
|
206
|
-
handle_gamepad_event(gamepad.rightTrigger, KEY_GAMEPAD_TRIGGER_RIGHT);
|
207
|
-
|
208
|
-
if (@available(macOS 10.14.1, *))
|
209
|
-
{
|
210
|
-
handle_gamepad_event(gamepad. leftThumbstickButton, KEY_GAMEPAD_THUMB_LEFT);
|
211
|
-
handle_gamepad_event(gamepad.rightThumbstickButton, KEY_GAMEPAD_THUMB_RIGHT);
|
212
|
-
}
|
213
|
-
|
214
|
-
if (@available(macOS 10.15, *))
|
215
|
-
{
|
216
|
-
handle_gamepad_event(gamepad.buttonMenu, KEY_GAMEPAD_MENU);
|
217
|
-
handle_gamepad_event(gamepad.buttonOptions, KEY_GAMEPAD_OPTION);
|
218
|
-
}
|
219
|
-
|
220
|
-
if (@available(macOS 11.0, *))
|
221
|
-
handle_gamepad_event(gamepad.buttonHome, KEY_GAMEPAD_HOME);
|
222
|
-
}
|
223
|
-
|
224
|
-
static id game_controllers_observer = nil;
|
225
|
-
|
226
|
-
void
|
227
|
-
init_game_controllers ()
|
228
|
-
{
|
229
|
-
for (GCController* c in GCController.controllers)
|
230
|
-
handle_gamepad_events(c);
|
231
|
-
|
232
|
-
game_controllers_observer = [NSNotificationCenter.defaultCenter
|
233
|
-
addObserverForName: GCControllerDidConnectNotification
|
234
|
-
object: nil
|
235
|
-
queue: NSOperationQueue.mainQueue
|
236
|
-
usingBlock: ^(NSNotification* n) {handle_gamepad_events(n.object);}];
|
237
|
-
}
|
238
|
-
|
239
|
-
void
|
240
|
-
fin_game_controllers ()
|
241
|
-
{
|
242
|
-
if (!game_controllers_observer) return;
|
243
|
-
|
244
|
-
[NSNotificationCenter.defaultCenter
|
245
|
-
removeObserver: game_controllers_observer];
|
246
|
-
}
|
247
|
-
|
248
|
-
|
249
|
-
};// Reflex
|
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
|