reflexion 0.3.5 → 0.3.7
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/midi.cpp +82 -0
- data/.doc/ext/reflex/native.cpp +10 -4
- data/.doc/ext/reflex/note_event.cpp +121 -0
- data/.doc/ext/reflex/reflex.cpp +30 -8
- data/.doc/ext/reflex/view.cpp +11 -16
- data/.doc/ext/reflex/window.cpp +24 -0
- data/ChangeLog.md +16 -0
- data/Rakefile +7 -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/midi.cpp +87 -0
- data/ext/reflex/native.cpp +10 -4
- data/ext/reflex/note_event.cpp +130 -0
- data/ext/reflex/reflex.cpp +31 -8
- data/ext/reflex/view.cpp +11 -16
- data/ext/reflex/window.cpp +27 -0
- 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 +64 -2
- data/include/reflex/gamepad.h +175 -0
- data/include/reflex/midi.h +53 -0
- data/include/reflex/reflex.h +2 -0
- data/include/reflex/ruby/application.h +18 -0
- data/include/reflex/ruby/device.h +40 -0
- data/include/reflex/ruby/event.h +22 -0
- data/include/reflex/ruby/midi.h +84 -0
- data/include/reflex/ruby/window.h +27 -0
- data/include/reflex/view.h +9 -1
- data/include/reflex/window.h +6 -0
- data/lib/reflex/note_event.rb +34 -0
- data/lib/reflex/view.rb +2 -1
- data/lib/reflex.rb +9 -8
- data/reflex.gemspec +3 -3
- data/src/application.cpp +70 -0
- data/src/application.h +9 -0
- data/src/device.cpp +24 -0
- data/src/event.cpp +133 -7
- data/src/event.h +5 -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 +11 -87
- data/src/ios/gamepad.mm +314 -0
- data/src/ios/reflex.mm +0 -5
- data/src/midi.cpp +379 -0
- data/src/midi.h +32 -0
- data/src/osx/app_delegate.mm +2 -2
- data/src/osx/application.mm +0 -25
- data/src/osx/event.h +0 -5
- 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/queue.h +71 -0
- data/src/reflex.cpp +18 -0
- data/src/timer.cpp +3 -10
- data/src/view.cpp +39 -0
- data/src/view.h +2 -0
- data/src/win32/application.cpp +5 -26
- data/src/win32/event.cpp +6 -89
- data/src/win32/event.h +1 -1
- data/src/win32/gamepad.cpp +110 -0
- data/src/win32/gamepad.h +20 -0
- data/src/win32/window.cpp +2 -1
- data/src/window.cpp +61 -10
- data/src/window.h +2 -0
- data/test/test_capture_event.rb +20 -16
- data/test/test_key_event.rb +8 -1
- data/test/test_note_event.rb +43 -0
- data/test/test_view.rb +24 -12
- metadata +43 -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::List gamepads;
|
43
|
+
|
44
|
+
void
|
45
|
+
Gamepad_add (Application* app, Gamepad* gamepad)
|
46
|
+
{
|
47
|
+
if (!gamepad)
|
48
|
+
argument_error(__FILE__, __LINE__);
|
49
|
+
|
50
|
+
gamepads.emplace_back(gamepad);
|
51
|
+
|
52
|
+
Application_call_device_connect(app, gamepad);
|
53
|
+
}
|
54
|
+
|
55
|
+
void
|
56
|
+
Gamepad_remove (Application* app, Gamepad* gamepad)
|
57
|
+
{
|
58
|
+
if (!gamepad) return;
|
59
|
+
|
60
|
+
auto it = std::find(gamepads.begin(), gamepads.end(), gamepad);
|
61
|
+
if (it == gamepads.end()) return;
|
62
|
+
|
63
|
+
Application_call_device_disconnect(app, gamepad);
|
64
|
+
|
65
|
+
gamepads.erase(it);
|
66
|
+
}
|
67
|
+
|
68
|
+
void
|
69
|
+
Gamepad_remove_all (Application* app)
|
70
|
+
{
|
71
|
+
for (auto& gamepad : gamepads)
|
72
|
+
Gamepad_remove(app, gamepad);
|
73
|
+
}
|
74
|
+
|
75
|
+
Gamepad*
|
76
|
+
Gamepad_find (void* handle)
|
77
|
+
{
|
78
|
+
if (!handle)
|
79
|
+
return NULL;
|
80
|
+
|
81
|
+
auto it = std::find_if(
|
82
|
+
gamepads.begin(), gamepads.end(),
|
83
|
+
[&](auto& gamepad) {return gamepad->self->has_handle(handle);});
|
84
|
+
if (it == gamepads.end())
|
85
|
+
return NULL;
|
86
|
+
|
87
|
+
return it->get();
|
88
|
+
}
|
89
|
+
|
90
|
+
float
|
91
|
+
Gamepad_get_button_press_threshold ()
|
92
|
+
{
|
93
|
+
return 0.35;
|
94
|
+
}
|
95
|
+
|
96
|
+
static Gamepad_CreateFun gamepad_create_fun = NULL;
|
97
|
+
|
98
|
+
void
|
99
|
+
Gamepad_set_create_fun (Gamepad_CreateFun fun)
|
100
|
+
{
|
101
|
+
gamepad_create_fun = fun;
|
102
|
+
}
|
103
|
+
|
104
|
+
Gamepad*
|
105
|
+
Gamepad_create ()
|
106
|
+
{
|
107
|
+
return gamepad_create_fun ? gamepad_create_fun() : new Gamepad();
|
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_GAMEPAD_H__
|
4
|
+
#define __REFLEX_SRC_GAMEPAD_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
|
+
void Gamepad_init (Application* app);
|
50
|
+
|
51
|
+
void Gamepad_fin (Application* app);
|
52
|
+
|
53
|
+
void Gamepad_add (Application* app, Gamepad* gamepad);
|
54
|
+
|
55
|
+
void Gamepad_remove (Application* app, Gamepad* gamepad);
|
56
|
+
|
57
|
+
void Gamepad_remove_all (Application* app);
|
58
|
+
|
59
|
+
Gamepad* Gamepad_find (void* handle);
|
60
|
+
|
61
|
+
float Gamepad_get_button_press_threshold ();
|
62
|
+
|
63
|
+
|
64
|
+
typedef Gamepad* (*Gamepad_CreateFun) ();
|
65
|
+
|
66
|
+
void Gamepad_set_create_fun (Gamepad_CreateFun fun);
|
67
|
+
|
68
|
+
Gamepad* Gamepad_create ();
|
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.h
CHANGED
data/src/ios/event.mm
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
#include <assert.h>
|
6
|
-
#include <algorithm>
|
7
|
-
#import <GameController/GameController.h>
|
8
6
|
#include "window.h"
|
9
7
|
|
10
8
|
|
@@ -56,10 +54,11 @@ namespace Reflex
|
|
56
54
|
static uint
|
57
55
|
get_modifiers (const UIEvent* event)
|
58
56
|
{
|
59
|
-
|
57
|
+
if (!event) return 0;
|
60
58
|
|
61
59
|
NSInteger flags = 0;
|
62
|
-
if (@available(iOS 13.4, *))
|
60
|
+
if (@available(iOS 13.4, *))
|
61
|
+
flags = event.modifierFlags;
|
63
62
|
|
64
63
|
return
|
65
64
|
(flags & UIKeyModifierAlphaShift) ? MOD_CAPS : 0 |
|
@@ -70,6 +69,13 @@ namespace Reflex
|
|
70
69
|
(flags & UIKeyModifierNumericPad) ? MOD_NUMPAD : 0;
|
71
70
|
}
|
72
71
|
|
72
|
+
uint
|
73
|
+
KeyEvent_get_modifiers ()
|
74
|
+
{
|
75
|
+
return get_modifiers(nil);
|
76
|
+
}
|
77
|
+
|
78
|
+
|
73
79
|
NativePointerEvent::NativePointerEvent (
|
74
80
|
NSSet* touches, UIEvent* event, UIView* view)
|
75
81
|
{
|
@@ -99,86 +105,4 @@ namespace Reflex
|
|
99
105
|
}
|
100
106
|
|
101
107
|
|
102
|
-
|
103
|
-
call_gamepad_event (int code, bool pressed)
|
104
|
-
{
|
105
|
-
Window* win = Window_get_active();
|
106
|
-
if (!win) return;
|
107
|
-
|
108
|
-
auto action = pressed ? KeyEvent::DOWN : KeyEvent::UP;
|
109
|
-
KeyEvent e(action, NULL, code, 0, 0);
|
110
|
-
Window_call_key_event(win, &e);
|
111
|
-
}
|
112
|
-
|
113
|
-
static void
|
114
|
-
handle_gamepad_event (GCControllerButtonInput* input, int code)
|
115
|
-
{
|
116
|
-
[input setPressedChangedHandler:
|
117
|
-
^(GCControllerButtonInput* button, float value, BOOL pressed) {
|
118
|
-
call_gamepad_event(code, pressed);
|
119
|
-
}];
|
120
|
-
}
|
121
|
-
|
122
|
-
static void
|
123
|
-
handle_gamepad_events (GCController* controller)
|
124
|
-
{
|
125
|
-
GCExtendedGamepad* gamepad = controller.extendedGamepad;
|
126
|
-
if (!gamepad) return;
|
127
|
-
|
128
|
-
handle_gamepad_event(gamepad.dpad.left, KEY_GAMEPAD_LEFT);
|
129
|
-
handle_gamepad_event(gamepad.dpad.right, KEY_GAMEPAD_RIGHT);
|
130
|
-
handle_gamepad_event(gamepad.dpad.up, KEY_GAMEPAD_UP);
|
131
|
-
handle_gamepad_event(gamepad.dpad.down, KEY_GAMEPAD_DOWN);
|
132
|
-
|
133
|
-
handle_gamepad_event(gamepad.buttonA, KEY_GAMEPAD_A);
|
134
|
-
handle_gamepad_event(gamepad.buttonB, KEY_GAMEPAD_B);
|
135
|
-
handle_gamepad_event(gamepad.buttonX, KEY_GAMEPAD_X);
|
136
|
-
handle_gamepad_event(gamepad.buttonY, KEY_GAMEPAD_Y);
|
137
|
-
|
138
|
-
handle_gamepad_event(gamepad. leftShoulder, KEY_GAMEPAD_SHOULDER_LEFT);
|
139
|
-
handle_gamepad_event(gamepad.rightShoulder, KEY_GAMEPAD_SHOULDER_RIGHT);
|
140
|
-
handle_gamepad_event(gamepad. leftTrigger, KEY_GAMEPAD_TRIGGER_LEFT);
|
141
|
-
handle_gamepad_event(gamepad.rightTrigger, KEY_GAMEPAD_TRIGGER_RIGHT);
|
142
|
-
|
143
|
-
if (@available(iOS 12.1, *))
|
144
|
-
{
|
145
|
-
handle_gamepad_event(gamepad. leftThumbstickButton, KEY_GAMEPAD_THUMB_LEFT);
|
146
|
-
handle_gamepad_event(gamepad.rightThumbstickButton, KEY_GAMEPAD_THUMB_RIGHT);
|
147
|
-
}
|
148
|
-
|
149
|
-
if (@available(iOS 13.0, *))
|
150
|
-
{
|
151
|
-
handle_gamepad_event(gamepad.buttonMenu, KEY_GAMEPAD_MENU);
|
152
|
-
handle_gamepad_event(gamepad.buttonOptions, KEY_GAMEPAD_OPTION);
|
153
|
-
}
|
154
|
-
|
155
|
-
if (@available(iOS 14.0, *))
|
156
|
-
handle_gamepad_event(gamepad.buttonHome, KEY_GAMEPAD_HOME);
|
157
|
-
}
|
158
|
-
|
159
|
-
static id game_controllers_observer = nil;
|
160
|
-
|
161
|
-
void
|
162
|
-
init_game_controllers ()
|
163
|
-
{
|
164
|
-
for (GCController* c in GCController.controllers)
|
165
|
-
handle_gamepad_events(c);
|
166
|
-
|
167
|
-
game_controllers_observer = [NSNotificationCenter.defaultCenter
|
168
|
-
addObserverForName: GCControllerDidConnectNotification
|
169
|
-
object: nil
|
170
|
-
queue: NSOperationQueue.mainQueue
|
171
|
-
usingBlock: ^(NSNotification* n) {handle_gamepad_events(n.object);}];
|
172
|
-
}
|
173
|
-
|
174
|
-
void
|
175
|
-
fin_game_controllers ()
|
176
|
-
{
|
177
|
-
if (!game_controllers_observer) return;
|
178
|
-
|
179
|
-
[NSNotificationCenter.defaultCenter
|
180
|
-
removeObserver: game_controllers_observer];
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
};// Reflex
|
108
|
+
}// Reflex
|