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/gamepad.cpp
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
#include "gamepad.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <algorithm>
|
5
|
+
#include "reflex/exception.h"
|
6
|
+
#include "application.h"
|
7
|
+
|
8
|
+
|
9
|
+
namespace Reflex
|
10
|
+
{
|
11
|
+
|
12
|
+
|
13
|
+
Gamepad::Data::~Data ()
|
14
|
+
{
|
15
|
+
}
|
16
|
+
|
17
|
+
void
|
18
|
+
Gamepad::Data::update_prev ()
|
19
|
+
{
|
20
|
+
if (prev) prev->self->state = state;
|
21
|
+
}
|
22
|
+
|
23
|
+
const char*
|
24
|
+
Gamepad::Data::name () const
|
25
|
+
{
|
26
|
+
return "Unknown";
|
27
|
+
}
|
28
|
+
|
29
|
+
bool
|
30
|
+
Gamepad::Data::is_valid () const
|
31
|
+
{
|
32
|
+
return true;
|
33
|
+
}
|
34
|
+
|
35
|
+
bool
|
36
|
+
Gamepad::Data::has_handle (void* handle) const
|
37
|
+
{
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
static Gamepad_CreateFun gamepad_create_fun = NULL;
|
43
|
+
|
44
|
+
void
|
45
|
+
Gamepad_set_create_fun (Gamepad_CreateFun fun)
|
46
|
+
{
|
47
|
+
gamepad_create_fun = fun;
|
48
|
+
}
|
49
|
+
|
50
|
+
Gamepad*
|
51
|
+
Gamepad_create ()
|
52
|
+
{
|
53
|
+
return gamepad_create_fun ? gamepad_create_fun() : new Gamepad();
|
54
|
+
}
|
55
|
+
|
56
|
+
static Gamepad::List gamepads;
|
57
|
+
|
58
|
+
void
|
59
|
+
Gamepad_add (Application* app, Gamepad* gamepad)
|
60
|
+
{
|
61
|
+
if (!gamepad)
|
62
|
+
argument_error(__FILE__, __LINE__);
|
63
|
+
|
64
|
+
gamepads.emplace_back(gamepad);
|
65
|
+
|
66
|
+
Application_call_device_connect(app, gamepad);
|
67
|
+
}
|
68
|
+
|
69
|
+
void
|
70
|
+
Gamepad_remove (Application* app, Gamepad* gamepad)
|
71
|
+
{
|
72
|
+
if (!gamepad) return;
|
73
|
+
|
74
|
+
auto it = std::find(gamepads.begin(), gamepads.end(), gamepad);
|
75
|
+
if (it == gamepads.end()) return;
|
76
|
+
|
77
|
+
Application_call_device_disconnect(app, gamepad);
|
78
|
+
|
79
|
+
gamepads.erase(it);
|
80
|
+
}
|
81
|
+
|
82
|
+
void
|
83
|
+
Gamepad_remove_all (Application* app)
|
84
|
+
{
|
85
|
+
for (auto& gamepad : gamepads)
|
86
|
+
Gamepad_remove(app, gamepad);
|
87
|
+
}
|
88
|
+
|
89
|
+
Gamepad*
|
90
|
+
Gamepad_find (void* handle)
|
91
|
+
{
|
92
|
+
if (!handle)
|
93
|
+
return NULL;
|
94
|
+
|
95
|
+
auto it = std::find_if(
|
96
|
+
gamepads.begin(), gamepads.end(),
|
97
|
+
[&](auto& gamepad) {return gamepad->self->has_handle(handle);});
|
98
|
+
if (it == gamepads.end())
|
99
|
+
return NULL;
|
100
|
+
|
101
|
+
return it->get();
|
102
|
+
}
|
103
|
+
|
104
|
+
float
|
105
|
+
Gamepad_get_button_press_threshold ()
|
106
|
+
{
|
107
|
+
return 0.35;
|
108
|
+
}
|
109
|
+
|
110
|
+
|
111
|
+
Gamepad::Gamepad ()
|
112
|
+
{
|
113
|
+
}
|
114
|
+
|
115
|
+
Gamepad::~Gamepad ()
|
116
|
+
{
|
117
|
+
}
|
118
|
+
|
119
|
+
const char*
|
120
|
+
Gamepad::name () const
|
121
|
+
{
|
122
|
+
return self->name();
|
123
|
+
}
|
124
|
+
|
125
|
+
ulonglong
|
126
|
+
Gamepad::buttons () const
|
127
|
+
{
|
128
|
+
return self->state.buttons;
|
129
|
+
}
|
130
|
+
|
131
|
+
const Point&
|
132
|
+
Gamepad::stick (size_t index) const
|
133
|
+
{
|
134
|
+
if (index >= INDEX_MAX)
|
135
|
+
index_error(__FILE__, __LINE__);
|
136
|
+
|
137
|
+
return self->state.sticks[index];
|
138
|
+
}
|
139
|
+
|
140
|
+
float
|
141
|
+
Gamepad::trigger (size_t index) const
|
142
|
+
{
|
143
|
+
if (index >= INDEX_MAX)
|
144
|
+
index_error(__FILE__, __LINE__);
|
145
|
+
|
146
|
+
return self->state.triggers[index];
|
147
|
+
}
|
148
|
+
|
149
|
+
const Gamepad*
|
150
|
+
Gamepad::prev () const
|
151
|
+
{
|
152
|
+
return self->prev.get();
|
153
|
+
}
|
154
|
+
|
155
|
+
void
|
156
|
+
Gamepad::on_key (KeyEvent* e)
|
157
|
+
{
|
158
|
+
}
|
159
|
+
|
160
|
+
void
|
161
|
+
Gamepad::on_key_down (KeyEvent* e)
|
162
|
+
{
|
163
|
+
}
|
164
|
+
|
165
|
+
void
|
166
|
+
Gamepad::on_key_up (KeyEvent* e)
|
167
|
+
{
|
168
|
+
}
|
169
|
+
|
170
|
+
Gamepad::operator bool () const
|
171
|
+
{
|
172
|
+
return self->is_valid();
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
}// Reflex
|
data/src/gamepad.h
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __REFLEX_SRC_DEVICE_H__
|
4
|
+
#define __REFLEX_SRC_DEVICE_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <memory>
|
8
|
+
#include "reflex/gamepad.h"
|
9
|
+
|
10
|
+
|
11
|
+
namespace Reflex
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
class Application;
|
16
|
+
|
17
|
+
|
18
|
+
struct Gamepad::Data
|
19
|
+
{
|
20
|
+
|
21
|
+
struct State
|
22
|
+
{
|
23
|
+
|
24
|
+
ulonglong buttons = 0;
|
25
|
+
|
26
|
+
Point sticks[2];
|
27
|
+
|
28
|
+
float triggers[2];
|
29
|
+
|
30
|
+
};// State
|
31
|
+
|
32
|
+
State state;
|
33
|
+
|
34
|
+
std::unique_ptr<Gamepad> prev;
|
35
|
+
|
36
|
+
virtual ~Data ();
|
37
|
+
|
38
|
+
virtual void update_prev ();
|
39
|
+
|
40
|
+
virtual const char* name () const;
|
41
|
+
|
42
|
+
virtual bool is_valid () const;
|
43
|
+
|
44
|
+
virtual bool has_handle (void* handle) const;
|
45
|
+
|
46
|
+
};// Gamepad
|
47
|
+
|
48
|
+
|
49
|
+
typedef Gamepad* (*Gamepad_CreateFun) ();
|
50
|
+
|
51
|
+
|
52
|
+
void Gamepad_init (Application* app);
|
53
|
+
|
54
|
+
void Gamepad_fin (Application* app);
|
55
|
+
|
56
|
+
void Gamepad_set_create_fun (Gamepad_CreateFun fun);
|
57
|
+
|
58
|
+
Gamepad* Gamepad_create ();
|
59
|
+
|
60
|
+
void Gamepad_add (Application* app, Gamepad* gamepad);
|
61
|
+
|
62
|
+
void Gamepad_remove (Application* app, Gamepad* gamepad);
|
63
|
+
|
64
|
+
void Gamepad_remove_all (Application* app);
|
65
|
+
|
66
|
+
Gamepad* Gamepad_find (void* handle);
|
67
|
+
|
68
|
+
float Gamepad_get_button_press_threshold ();
|
69
|
+
|
70
|
+
|
71
|
+
}// Reflex
|
72
|
+
|
73
|
+
|
74
|
+
#endif//EOH
|
data/src/ios/app_delegate.mm
CHANGED
@@ -76,7 +76,7 @@
|
|
76
76
|
return YES;
|
77
77
|
|
78
78
|
Reflex::Event e;
|
79
|
-
application
|
79
|
+
Application_call_start(application, &e);
|
80
80
|
started = true;
|
81
81
|
|
82
82
|
return !e.is_blocked();
|
@@ -147,7 +147,7 @@
|
|
147
147
|
if (self->application)
|
148
148
|
{
|
149
149
|
Reflex::Event e;
|
150
|
-
self->application
|
150
|
+
Application_call_quit(self->application, &e);
|
151
151
|
if (e.is_blocked())
|
152
152
|
{
|
153
153
|
Reflex::not_implemented_error(
|
data/src/ios/application.mm
CHANGED
@@ -75,35 +75,10 @@ namespace Reflex
|
|
75
75
|
not_implemented_error(__FILE__, __LINE__);
|
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
|
}
|
102
82
|
|
103
|
-
Application::operator bool () const
|
104
|
-
{
|
105
|
-
return true;
|
106
|
-
}
|
107
|
-
|
108
83
|
|
109
84
|
}// Reflex
|
data/src/ios/event.mm
CHANGED
data/src/ios/gamepad.mm
ADDED
@@ -0,0 +1,313 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#include "../gamepad.h"
|
3
|
+
|
4
|
+
|
5
|
+
#import <GameController/GameController.h>
|
6
|
+
#include "reflex/exception.h"
|
7
|
+
#include "window.h"
|
8
|
+
|
9
|
+
|
10
|
+
namespace Reflex
|
11
|
+
{
|
12
|
+
|
13
|
+
|
14
|
+
struct GameControllerGamepadData : Gamepad::Data
|
15
|
+
{
|
16
|
+
|
17
|
+
typedef Gamepad::Data Super;
|
18
|
+
|
19
|
+
GCController* controller = nil;
|
20
|
+
|
21
|
+
GameControllerGamepadData (GCController* controller)
|
22
|
+
: controller([controller retain])
|
23
|
+
{
|
24
|
+
prev.reset(new Gamepad());
|
25
|
+
}
|
26
|
+
|
27
|
+
~GameControllerGamepadData ()
|
28
|
+
{
|
29
|
+
//clear_event_handlers(controller);
|
30
|
+
[controller release];
|
31
|
+
}
|
32
|
+
|
33
|
+
const char* name () const override
|
34
|
+
{
|
35
|
+
return controller.vendorName.UTF8String;
|
36
|
+
}
|
37
|
+
|
38
|
+
bool is_valid () const override
|
39
|
+
{
|
40
|
+
return Super::is_valid() && controller;
|
41
|
+
}
|
42
|
+
|
43
|
+
bool has_handle (void* handle) const override
|
44
|
+
{
|
45
|
+
return handle == (__bridge void*) controller;
|
46
|
+
}
|
47
|
+
|
48
|
+
};// GameControllerGamepadData
|
49
|
+
|
50
|
+
|
51
|
+
static Gamepad*
|
52
|
+
Gamepad_create (GCController* controller)
|
53
|
+
{
|
54
|
+
Gamepad* g = Gamepad_create();
|
55
|
+
g->self.reset(new GameControllerGamepadData(controller));
|
56
|
+
return g;
|
57
|
+
}
|
58
|
+
|
59
|
+
static void
|
60
|
+
call_gamepad_event (int key_code, bool pressed)
|
61
|
+
{
|
62
|
+
Window* win = Window_get_active();
|
63
|
+
if (!win) return;
|
64
|
+
|
65
|
+
auto action = pressed ? KeyEvent::DOWN : KeyEvent::UP;
|
66
|
+
KeyEvent e(action, NULL, key_code, 0, 0);
|
67
|
+
Window_call_key_event(win, &e);
|
68
|
+
}
|
69
|
+
|
70
|
+
static void
|
71
|
+
call_button_event (
|
72
|
+
Gamepad* gamepad, ulonglong button, int key_code, float value)
|
73
|
+
{
|
74
|
+
Gamepad::Data* self = gamepad->self.get();
|
75
|
+
|
76
|
+
bool pressed = value > Gamepad_get_button_press_threshold();
|
77
|
+
bool current = self->state.buttons & button;
|
78
|
+
if (pressed == current) return;
|
79
|
+
|
80
|
+
self->update_prev();
|
81
|
+
if (pressed)
|
82
|
+
self->state.buttons |= button;
|
83
|
+
else
|
84
|
+
self->state.buttons &= ~button;
|
85
|
+
|
86
|
+
call_gamepad_event(key_code, pressed);
|
87
|
+
}
|
88
|
+
|
89
|
+
static void
|
90
|
+
handle_button_event (
|
91
|
+
Gamepad* gamepad, GCControllerButtonInput* input,
|
92
|
+
ulonglong button, int key_code)
|
93
|
+
{
|
94
|
+
[input setPressedChangedHandler:
|
95
|
+
^(GCControllerButtonInput*, float, BOOL pressed)
|
96
|
+
{
|
97
|
+
call_button_event(gamepad, button, key_code, pressed ? 1 : 0);
|
98
|
+
}];
|
99
|
+
}
|
100
|
+
|
101
|
+
static void
|
102
|
+
handle_stick_dpad_event (
|
103
|
+
Gamepad* gamepad, GCControllerButtonInput* input,
|
104
|
+
ulonglong button, int key_code)
|
105
|
+
{
|
106
|
+
[input setValueChangedHandler:
|
107
|
+
^(GCControllerButtonInput*, float value, BOOL)
|
108
|
+
{
|
109
|
+
call_button_event(gamepad, button, key_code, value);
|
110
|
+
}];
|
111
|
+
}
|
112
|
+
|
113
|
+
static void
|
114
|
+
handle_stick_event (
|
115
|
+
Gamepad* gamepad, GCControllerDirectionPad* input, Gamepad::Index index)
|
116
|
+
{
|
117
|
+
[input setValueChangedHandler:
|
118
|
+
^(GCControllerDirectionPad*, float x, float y)
|
119
|
+
{
|
120
|
+
gamepad->self->update_prev();
|
121
|
+
gamepad->self->state.sticks[index].reset(x, y);
|
122
|
+
}];
|
123
|
+
}
|
124
|
+
|
125
|
+
static void
|
126
|
+
handle_trigger_event (
|
127
|
+
Gamepad* gamepad, GCControllerButtonInput* input, Gamepad::Index index,
|
128
|
+
ulonglong button, int key_code)
|
129
|
+
{
|
130
|
+
[input setPressedChangedHandler:
|
131
|
+
^(GCControllerButtonInput*, float, BOOL pressed)
|
132
|
+
{
|
133
|
+
call_button_event(gamepad, button, key_code, pressed ? 1 : 0);
|
134
|
+
}];
|
135
|
+
|
136
|
+
[input setValueChangedHandler:
|
137
|
+
^(GCControllerButtonInput*, float value, BOOL)
|
138
|
+
{
|
139
|
+
Gamepad::Data* self = gamepad->self.get();
|
140
|
+
|
141
|
+
self->update_prev();
|
142
|
+
self->state.triggers[index] = value;
|
143
|
+
}];
|
144
|
+
}
|
145
|
+
|
146
|
+
static void
|
147
|
+
handle_gamepad_events (Gamepad* gamepad, GCController* controller)
|
148
|
+
{
|
149
|
+
GCExtendedGamepad* g = controller.extendedGamepad;
|
150
|
+
if (!gamepad) return;
|
151
|
+
|
152
|
+
static const Gamepad::Index L = Gamepad::INDEX_LEFT, R = Gamepad::INDEX_RIGHT;
|
153
|
+
|
154
|
+
auto* dpad = g.dpad;
|
155
|
+
handle_button_event(gamepad, dpad.left, Gamepad::LEFT, KEY_GAMEPAD_LEFT);
|
156
|
+
handle_button_event(gamepad, dpad.right, Gamepad::RIGHT, KEY_GAMEPAD_RIGHT);
|
157
|
+
handle_button_event(gamepad, dpad.up, Gamepad::UP, KEY_GAMEPAD_UP);
|
158
|
+
handle_button_event(gamepad, dpad.down, Gamepad::DOWN, KEY_GAMEPAD_DOWN);
|
159
|
+
|
160
|
+
auto* lstick = g.leftThumbstick;
|
161
|
+
handle_stick_event( gamepad, lstick, L);
|
162
|
+
handle_stick_dpad_event(gamepad, lstick.left, Gamepad::LSTICK_LEFT, KEY_GAMEPAD_LSTICK_LEFT);
|
163
|
+
handle_stick_dpad_event(gamepad, lstick.right, Gamepad::LSTICK_RIGHT, KEY_GAMEPAD_LSTICK_RIGHT);
|
164
|
+
handle_stick_dpad_event(gamepad, lstick.up, Gamepad::LSTICK_UP, KEY_GAMEPAD_LSTICK_UP);
|
165
|
+
handle_stick_dpad_event(gamepad, lstick.down, Gamepad::LSTICK_DOWN, KEY_GAMEPAD_LSTICK_DOWN);
|
166
|
+
|
167
|
+
auto* rstick = g.rightThumbstick;
|
168
|
+
handle_stick_event( gamepad, rstick, R);
|
169
|
+
handle_stick_dpad_event(gamepad, rstick.left, Gamepad::RSTICK_LEFT, KEY_GAMEPAD_RSTICK_LEFT);
|
170
|
+
handle_stick_dpad_event(gamepad, rstick.right, Gamepad::RSTICK_RIGHT, KEY_GAMEPAD_RSTICK_RIGHT);
|
171
|
+
handle_stick_dpad_event(gamepad, rstick.up, Gamepad::RSTICK_UP, KEY_GAMEPAD_RSTICK_UP);
|
172
|
+
handle_stick_dpad_event(gamepad, rstick.down, Gamepad::RSTICK_DOWN, KEY_GAMEPAD_RSTICK_DOWN);
|
173
|
+
|
174
|
+
handle_button_event(gamepad, g.buttonA, Gamepad::BUTTON_A, KEY_GAMEPAD_A);
|
175
|
+
handle_button_event(gamepad, g.buttonB, Gamepad::BUTTON_B, KEY_GAMEPAD_B);
|
176
|
+
handle_button_event(gamepad, g.buttonX, Gamepad::BUTTON_X, KEY_GAMEPAD_X);
|
177
|
+
handle_button_event(gamepad, g.buttonY, Gamepad::BUTTON_Y, KEY_GAMEPAD_Y);
|
178
|
+
|
179
|
+
handle_button_event( gamepad, g. leftShoulder, Gamepad::LSHOULDER, KEY_GAMEPAD_LSHOULDER);
|
180
|
+
handle_button_event( gamepad, g.rightShoulder, Gamepad::RSHOULDER, KEY_GAMEPAD_RSHOULDER);
|
181
|
+
handle_trigger_event(gamepad, g. leftTrigger, L, Gamepad::LTRIGGER, KEY_GAMEPAD_LTRIGGER);
|
182
|
+
handle_trigger_event(gamepad, g.rightTrigger, R, Gamepad::RTRIGGER, KEY_GAMEPAD_RTRIGGER);
|
183
|
+
|
184
|
+
if (@available(iOS 12.1, *))
|
185
|
+
{
|
186
|
+
handle_button_event(gamepad, g. leftThumbstickButton, Gamepad::LTHUMB, KEY_GAMEPAD_LTHUMB);
|
187
|
+
handle_button_event(gamepad, g.rightThumbstickButton, Gamepad::RTHUMB, KEY_GAMEPAD_RTHUMB);
|
188
|
+
}
|
189
|
+
|
190
|
+
if (@available(iOS 13.0, *))
|
191
|
+
{
|
192
|
+
handle_button_event(gamepad, g.buttonMenu, Gamepad::MENU, KEY_GAMEPAD_MENU);
|
193
|
+
handle_button_event(gamepad, g.buttonOptions, Gamepad::OPTION, KEY_GAMEPAD_OPTION);
|
194
|
+
}
|
195
|
+
|
196
|
+
if (@available(iOS 14.0, *))
|
197
|
+
handle_button_event(gamepad, g.buttonHome, Gamepad::HOME, KEY_GAMEPAD_HOME);
|
198
|
+
|
199
|
+
//if (@available(macOS 11.0, *))
|
200
|
+
{
|
201
|
+
if ([g isKindOfClass: GCDualShockGamepad.class])
|
202
|
+
{
|
203
|
+
GCDualShockGamepad* dualshock = (GCDualShockGamepad*) g;
|
204
|
+
handle_button_event(
|
205
|
+
gamepad, dualshock.touchpadButton,
|
206
|
+
Gamepad::BUTTON_TOUCH, KEY_GAMEPAD_BUTTON_TOUCH);
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
//if (@available(macOS 11.3, *))
|
211
|
+
{
|
212
|
+
if ([g isKindOfClass: GCDualSenseGamepad.class])
|
213
|
+
{
|
214
|
+
GCDualSenseGamepad* dualsense = (GCDualSenseGamepad*) g;
|
215
|
+
handle_button_event(
|
216
|
+
gamepad, dualsense.touchpadButton,
|
217
|
+
Gamepad::BUTTON_TOUCH, KEY_GAMEPAD_BUTTON_TOUCH);
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
//if (@available(macOS 11.0, *))
|
222
|
+
{
|
223
|
+
if ([g isKindOfClass: GCXboxGamepad.class])
|
224
|
+
{
|
225
|
+
GCXboxGamepad* xbox = (GCXboxGamepad*) g;
|
226
|
+
handle_button_event(
|
227
|
+
gamepad, xbox.paddleButton1, Gamepad::RPADDLE_0, KEY_GAMEPAD_RPADDLE_0);
|
228
|
+
handle_button_event(
|
229
|
+
gamepad, xbox.paddleButton2, Gamepad::LPADDLE_0, KEY_GAMEPAD_LPADDLE_0);
|
230
|
+
handle_button_event(
|
231
|
+
gamepad, xbox.paddleButton3, Gamepad::RPADDLE_1, KEY_GAMEPAD_RPADDLE_1);
|
232
|
+
handle_button_event(
|
233
|
+
gamepad, xbox.paddleButton4, Gamepad::LPADDLE_1, KEY_GAMEPAD_LPADDLE_1);
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
static void
|
239
|
+
add_gamepad (Application* app, GCController* controller)
|
240
|
+
{
|
241
|
+
Gamepad* gamepad = Gamepad_create(controller);
|
242
|
+
handle_gamepad_events(gamepad, controller);
|
243
|
+
|
244
|
+
Gamepad_add(app, gamepad);
|
245
|
+
}
|
246
|
+
|
247
|
+
static void
|
248
|
+
remove_gamepad (Application* app, GCController* controller)
|
249
|
+
{
|
250
|
+
Gamepad* gamepad = Gamepad_find((__bridge void*) controller);
|
251
|
+
if (!gamepad) return;
|
252
|
+
|
253
|
+
Gamepad_remove(app, gamepad);
|
254
|
+
}
|
255
|
+
|
256
|
+
static id connect_observer = nil;
|
257
|
+
|
258
|
+
static id disconnect_observer = nil;
|
259
|
+
|
260
|
+
void
|
261
|
+
init_gamepad (Application* app)
|
262
|
+
{
|
263
|
+
if (connect_observer || disconnect_observer)
|
264
|
+
invalid_state_error(__FILE__, __LINE__);
|
265
|
+
|
266
|
+
connect_observer = [NSNotificationCenter.defaultCenter
|
267
|
+
addObserverForName: GCControllerDidConnectNotification
|
268
|
+
object: nil
|
269
|
+
queue: NSOperationQueue.mainQueue
|
270
|
+
usingBlock: ^(NSNotification* n) {add_gamepad(app, n.object);}];
|
271
|
+
|
272
|
+
disconnect_observer = [NSNotificationCenter.defaultCenter
|
273
|
+
addObserverForName: GCControllerDidDisconnectNotification
|
274
|
+
object: nil
|
275
|
+
queue: NSOperationQueue.mainQueue
|
276
|
+
usingBlock: ^(NSNotification* n) {remove_gamepad(app, n.object);}];
|
277
|
+
|
278
|
+
for (GCController* c in GCController.controllers)
|
279
|
+
add_gamepad(app, c);
|
280
|
+
}
|
281
|
+
|
282
|
+
void
|
283
|
+
fin_gamepad (Application* app)
|
284
|
+
{
|
285
|
+
if (!connect_observer || !disconnect_observer)
|
286
|
+
invalid_state_error(__FILE__, __LINE__);
|
287
|
+
|
288
|
+
[NSNotificationCenter.defaultCenter
|
289
|
+
removeObserver: connect_observer];
|
290
|
+
[NSNotificationCenter.defaultCenter
|
291
|
+
removeObserver: disconnect_observer];
|
292
|
+
|
293
|
+
connect_observer = disconnect_observer = nil;
|
294
|
+
|
295
|
+
Gamepad_remove_all(app);
|
296
|
+
}
|
297
|
+
|
298
|
+
void
|
299
|
+
Gamepad_init (Application* app)
|
300
|
+
{
|
301
|
+
init_gamepad(app);
|
302
|
+
}
|
303
|
+
|
304
|
+
void
|
305
|
+
Gamepad_fin (Application* app)
|
306
|
+
{
|
307
|
+
fin_gamepad(app);
|
308
|
+
|
309
|
+
Gamepad_remove_all(app);
|
310
|
+
}
|
311
|
+
|
312
|
+
|
313
|
+
}// Reflex
|
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
|