reflexion 0.1.22 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.doc/ext/reflex/event.cpp +9 -1
- data/.doc/ext/reflex/key_event.cpp +3 -3
- data/.doc/ext/reflex/native.cpp +2 -0
- data/.doc/ext/reflex/pointer.cpp +158 -0
- data/.doc/ext/reflex/pointer_event.cpp +29 -88
- data/.doc/ext/reflex/selector.cpp +8 -0
- data/.doc/ext/reflex/view.cpp +57 -0
- data/.doc/ext/reflex/window.cpp +24 -0
- data/VERSION +1 -1
- data/ext/reflex/event.cpp +11 -2
- data/ext/reflex/key_event.cpp +3 -3
- data/ext/reflex/native.cpp +2 -0
- data/ext/reflex/pointer.cpp +170 -0
- data/ext/reflex/pointer_event.cpp +29 -94
- data/ext/reflex/selector.cpp +9 -0
- data/ext/reflex/view.cpp +67 -3
- data/ext/reflex/window.cpp +30 -3
- data/include/reflex/defs.h +0 -18
- data/include/reflex/event.h +26 -27
- data/include/reflex/pointer.h +107 -0
- data/include/reflex/ruby/pointer.h +41 -0
- data/include/reflex/ruby/view.h +9 -0
- data/include/reflex/ruby/window.h +9 -0
- data/include/reflex/selector.h +1 -1
- data/include/reflex/view.h +6 -4
- data/include/reflex/window.h +10 -8
- data/lib/reflex/key_event.rb +1 -1
- data/lib/reflex/pointer.rb +107 -0
- data/lib/reflex/pointer_event.rb +16 -54
- data/lib/reflex.rb +1 -0
- data/reflex.gemspec +5 -5
- data/src/event.cpp +189 -37
- data/src/event.h +32 -0
- data/src/ios/event.h +15 -3
- data/src/ios/event.mm +126 -11
- data/src/ios/view_controller.mm +49 -21
- data/src/osx/event.h +6 -3
- data/src/osx/event.mm +40 -22
- data/src/osx/native_window.mm +79 -16
- data/src/pointer.cpp +203 -0
- data/src/pointer.h +26 -0
- data/src/selector.cpp +1 -1
- data/src/view.cpp +83 -72
- data/src/view.h +0 -4
- data/src/window.cpp +321 -97
- data/src/window.h +22 -3
- data/test/test_event.rb +16 -2
- data/test/test_pointer.rb +149 -0
- data/test/test_pointer_event.rb +70 -104
- data/test/test_selector.rb +7 -0
- data/test/test_view.rb +38 -11
- data/test/test_window.rb +27 -25
- metadata +46 -35
data/src/event.cpp
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
#include "
|
1
|
+
#include "event.h"
|
2
2
|
|
3
3
|
|
4
4
|
#include "reflex/timer.h"
|
5
5
|
#include "reflex/shape.h"
|
6
6
|
#include "reflex/exception.h"
|
7
|
+
#include "view.h"
|
8
|
+
#include "pointer.h"
|
7
9
|
|
8
10
|
|
9
11
|
namespace Reflex
|
@@ -11,7 +13,7 @@ namespace Reflex
|
|
11
13
|
|
12
14
|
|
13
15
|
Event::Event ()
|
14
|
-
: blocked(false)
|
16
|
+
: blocked(false), time_(Xot::time())
|
15
17
|
{
|
16
18
|
}
|
17
19
|
|
@@ -27,6 +29,12 @@ namespace Reflex
|
|
27
29
|
return blocked;
|
28
30
|
}
|
29
31
|
|
32
|
+
double
|
33
|
+
Event::time () const
|
34
|
+
{
|
35
|
+
return time_;
|
36
|
+
}
|
37
|
+
|
30
38
|
|
31
39
|
UpdateEvent::UpdateEvent (double now, float dt)
|
32
40
|
: now(now), dt(dt)
|
@@ -123,76 +131,220 @@ namespace Reflex
|
|
123
131
|
|
124
132
|
|
125
133
|
KeyEvent::KeyEvent ()
|
126
|
-
: type(NONE), code(KEY_NONE), modifiers(MOD_NONE), repeat(0),
|
134
|
+
: type(NONE), code(KEY_NONE), modifiers(MOD_NONE), repeat(0), captured(false)
|
127
135
|
{
|
128
136
|
}
|
129
137
|
|
130
138
|
KeyEvent::KeyEvent (
|
131
139
|
Type type, const char* chars, int code, uint modifiers, int repeat)
|
132
140
|
: type(type), chars(chars ? chars : ""), code(code), modifiers(modifiers),
|
133
|
-
repeat(repeat),
|
141
|
+
repeat(repeat), captured(false)
|
134
142
|
{
|
135
143
|
}
|
136
144
|
|
137
145
|
|
138
|
-
PointerEvent::
|
139
|
-
|
140
|
-
|
141
|
-
|
146
|
+
struct PointerEvent::Data
|
147
|
+
{
|
148
|
+
|
149
|
+
std::vector<Pointer> pointers;
|
150
|
+
|
151
|
+
bool captured;
|
152
|
+
|
153
|
+
Data (bool captured = false)
|
154
|
+
: captured(captured)
|
155
|
+
{
|
156
|
+
}
|
157
|
+
|
158
|
+
};// PointerEvent::Data
|
159
|
+
|
160
|
+
|
161
|
+
void
|
162
|
+
PointerEvent_add_pointer (PointerEvent* pthis, const Pointer& pointer)
|
142
163
|
{
|
164
|
+
if (!pthis)
|
165
|
+
argument_error(__FILE__, __LINE__);
|
166
|
+
|
167
|
+
pthis->self->pointers.emplace_back(pointer);
|
143
168
|
}
|
144
169
|
|
145
|
-
|
146
|
-
|
147
|
-
: type(type), pointer_type(pointer_type),
|
148
|
-
size(1), modifiers(modifiers), count(count), drag(drag), capture(false),
|
149
|
-
x(x), y(y), z(0)
|
170
|
+
void
|
171
|
+
PointerEvent_erase_pointer (PointerEvent* pthis, Pointer::ID id)
|
150
172
|
{
|
173
|
+
if (!pthis)
|
174
|
+
argument_error(__FILE__, __LINE__);
|
175
|
+
|
176
|
+
auto& pointers = pthis->self->pointers;
|
177
|
+
auto it = std::find_if(
|
178
|
+
pointers.begin(), pointers.end(),
|
179
|
+
[=](const auto& pointer)
|
180
|
+
{
|
181
|
+
return pointer.id() == id;
|
182
|
+
});
|
183
|
+
|
184
|
+
if (it == pointers.end()) return;
|
185
|
+
|
186
|
+
pointers.erase(it);
|
151
187
|
}
|
152
188
|
|
153
|
-
|
154
|
-
|
155
|
-
uint modifiers, uint count, bool drag)
|
156
|
-
: type(type), pointer_type(pointer_type),
|
157
|
-
size(size), modifiers(modifiers), count(count), drag(drag), capture(false)
|
189
|
+
Pointer&
|
190
|
+
PointerEvent_pointer_at (PointerEvent* pthis, size_t index)
|
158
191
|
{
|
159
|
-
if (!
|
192
|
+
if (!pthis)
|
160
193
|
argument_error(__FILE__, __LINE__);
|
161
194
|
|
162
|
-
|
195
|
+
auto& pointers = pthis->self->pointers;
|
196
|
+
if (index >= pointers.size())
|
197
|
+
index_error(__FILE__, __LINE__);
|
163
198
|
|
164
|
-
|
199
|
+
return pointers[index];
|
200
|
+
}
|
201
|
+
|
202
|
+
void
|
203
|
+
PointerEvent_each_pointer (
|
204
|
+
const PointerEvent* pthis, std::function<void(const Pointer&)> fun)
|
205
|
+
{
|
206
|
+
if (!pthis)
|
207
|
+
argument_error(__FILE__, __LINE__);
|
208
|
+
|
209
|
+
for (const auto& pointer : pthis->self->pointers)
|
210
|
+
fun(pointer);
|
211
|
+
}
|
212
|
+
|
213
|
+
static void
|
214
|
+
filter_and_offset_pointer_positions (PointerEvent* event, const Bounds& frame)
|
215
|
+
{
|
216
|
+
assert(event);
|
217
|
+
|
218
|
+
const Point& offset = frame.position();
|
219
|
+
|
220
|
+
std::vector<Pointer> pointers;
|
221
|
+
for (const auto& pointer : event->self->pointers)
|
165
222
|
{
|
166
|
-
|
167
|
-
|
223
|
+
if (!frame.is_include(pointer.position()))
|
224
|
+
continue;
|
225
|
+
|
226
|
+
pointers.emplace_back(pointer);
|
227
|
+
Pointer_update_positions(&pointers.back(), [&](Point* pos)
|
228
|
+
{
|
229
|
+
*pos -= offset;
|
230
|
+
});
|
168
231
|
}
|
232
|
+
|
233
|
+
event->self->pointers = pointers;
|
169
234
|
}
|
170
235
|
|
171
|
-
|
172
|
-
|
236
|
+
static void
|
237
|
+
scroll_and_zoom_pointer_positions (
|
238
|
+
PointerEvent* event, const Point& scroll, float zoom)
|
173
239
|
{
|
174
|
-
|
175
|
-
|
240
|
+
assert(event);
|
241
|
+
|
242
|
+
if (zoom == 0)
|
243
|
+
argument_error(__FILE__, __LINE__);
|
244
|
+
|
245
|
+
if (scroll == 0 && zoom == 1)
|
246
|
+
return;
|
176
247
|
|
177
|
-
|
248
|
+
for (auto& pointer : event->self->pointers)
|
249
|
+
{
|
250
|
+
Pointer_update_positions(&pointer, [=](Point* pos)
|
251
|
+
{
|
252
|
+
*pos -= scroll;
|
253
|
+
*pos /= zoom;
|
254
|
+
});
|
255
|
+
}
|
178
256
|
}
|
179
257
|
|
180
|
-
|
181
|
-
|
258
|
+
void
|
259
|
+
PointerEvent_update_for_child_view (PointerEvent* pthis, const View* view)
|
182
260
|
{
|
183
|
-
|
261
|
+
if (!pthis || !view)
|
262
|
+
argument_error(__FILE__, __LINE__);
|
263
|
+
|
264
|
+
filter_and_offset_pointer_positions(pthis, view->frame());
|
265
|
+
scroll_and_zoom_pointer_positions(pthis, view->scroll(), view->zoom());
|
184
266
|
}
|
185
267
|
|
186
|
-
|
187
|
-
PointerEvent
|
268
|
+
void
|
269
|
+
PointerEvent_update_for_capturing_view (PointerEvent* pthis, const View* view)
|
188
270
|
{
|
189
|
-
|
271
|
+
if (!pthis || !view)
|
272
|
+
argument_error(__FILE__, __LINE__);
|
273
|
+
|
274
|
+
for (auto& pointer : pthis->self->pointers)
|
275
|
+
{
|
276
|
+
Pointer_update_positions(&pointer, [=](Point* pos)
|
277
|
+
{
|
278
|
+
*pos = view->from_window(*pos);
|
279
|
+
});
|
280
|
+
}
|
281
|
+
|
282
|
+
scroll_and_zoom_pointer_positions(pthis, view->scroll(), view->zoom());
|
190
283
|
}
|
191
284
|
|
192
|
-
|
193
|
-
PointerEvent::
|
285
|
+
|
286
|
+
PointerEvent::PointerEvent (bool captured)
|
287
|
+
: self(new Data(captured))
|
288
|
+
{
|
289
|
+
}
|
290
|
+
|
291
|
+
PointerEvent::PointerEvent (const Pointer& pointer, bool captured)
|
292
|
+
: self(new Data(captured))
|
293
|
+
{
|
294
|
+
self->pointers.emplace_back(pointer);
|
295
|
+
}
|
296
|
+
|
297
|
+
PointerEvent::PointerEvent (const Pointer* pointers, size_t size, bool captured)
|
298
|
+
: self(new Data(captured))
|
299
|
+
{
|
300
|
+
for (size_t i = 0; i < size; ++i)
|
301
|
+
self->pointers.emplace_back(pointers[i]);
|
302
|
+
}
|
303
|
+
|
304
|
+
PointerEvent::PointerEvent (const This& obj)
|
305
|
+
: self(new Data(*obj.self))
|
306
|
+
{
|
307
|
+
}
|
308
|
+
|
309
|
+
PointerEvent&
|
310
|
+
PointerEvent::operator = (const This& obj)
|
311
|
+
{
|
312
|
+
if (&obj == this) return *this;
|
313
|
+
|
314
|
+
Event::operator=(obj);
|
315
|
+
*self = *obj.self;
|
316
|
+
return *this;
|
317
|
+
}
|
318
|
+
|
319
|
+
PointerEvent::~PointerEvent ()
|
194
320
|
{
|
195
|
-
|
321
|
+
}
|
322
|
+
|
323
|
+
size_t
|
324
|
+
PointerEvent::size () const
|
325
|
+
{
|
326
|
+
return self->pointers.size();
|
327
|
+
}
|
328
|
+
|
329
|
+
bool
|
330
|
+
PointerEvent::empty () const
|
331
|
+
{
|
332
|
+
return size() == 0;
|
333
|
+
}
|
334
|
+
|
335
|
+
bool
|
336
|
+
PointerEvent::is_captured () const
|
337
|
+
{
|
338
|
+
return self->captured;
|
339
|
+
}
|
340
|
+
|
341
|
+
const Pointer&
|
342
|
+
PointerEvent::operator [] (size_t index) const
|
343
|
+
{
|
344
|
+
if (index >= self->pointers.size())
|
345
|
+
index_error(__FILE__, __LINE__);
|
346
|
+
|
347
|
+
return self->pointers[index];
|
196
348
|
}
|
197
349
|
|
198
350
|
|
data/src/event.h
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __REFLEX_SRC_EVENT_H__
|
4
|
+
#define __REFLEX_SRC_EVENT_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <functional>
|
8
|
+
#include <reflex/event.h>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Reflex
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
void PointerEvent_add_pointer (PointerEvent* pthis, const Pointer& pointer);
|
16
|
+
|
17
|
+
void PointerEvent_erase_pointer (PointerEvent* pthis, Pointer::ID id);
|
18
|
+
|
19
|
+
Pointer& PointerEvent_pointer_at (PointerEvent* pthis, size_t index);
|
20
|
+
|
21
|
+
void PointerEvent_each_pointer (
|
22
|
+
const PointerEvent* pthis, std::function<void(const Pointer&)> fun);
|
23
|
+
|
24
|
+
void PointerEvent_update_for_child_view (PointerEvent* pthis, const View* view);
|
25
|
+
|
26
|
+
void PointerEvent_update_for_capturing_view (PointerEvent* pthis, const View* view);
|
27
|
+
|
28
|
+
|
29
|
+
}// Reflex
|
30
|
+
|
31
|
+
|
32
|
+
#endif//EOH
|
data/src/ios/event.h
CHANGED
@@ -4,18 +4,30 @@
|
|
4
4
|
#define __REFLEX_SRC_IOS_EVENT_H__
|
5
5
|
|
6
6
|
|
7
|
+
#include <list>
|
7
8
|
#import <UIKit/UIEvent.h>
|
8
|
-
#include
|
9
|
+
#include "../event.h"
|
9
10
|
|
10
11
|
|
11
12
|
namespace Reflex
|
12
13
|
{
|
13
14
|
|
14
15
|
|
15
|
-
|
16
|
+
typedef std::list<Pointer> PrevPointerList;
|
17
|
+
|
18
|
+
|
19
|
+
class NativePointerEvent : public PointerEvent
|
16
20
|
{
|
17
21
|
|
18
|
-
|
22
|
+
public:
|
23
|
+
|
24
|
+
NativePointerEvent (
|
25
|
+
NSSet* touches, UIEvent* event, UIView* view,
|
26
|
+
Pointer::ID* pointer_id);
|
27
|
+
|
28
|
+
NativePointerEvent (
|
29
|
+
NSSet* touches, UIEvent* event, UIView* view,
|
30
|
+
PrevPointerList* prev_pointers);
|
19
31
|
|
20
32
|
};// NativePointerEvent
|
21
33
|
|
data/src/ios/event.mm
CHANGED
@@ -3,30 +3,145 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
#include <assert.h>
|
6
|
+
#include <algorithm>
|
7
|
+
#include "../pointer.h"
|
6
8
|
|
7
9
|
|
8
10
|
namespace Reflex
|
9
11
|
{
|
10
12
|
|
11
13
|
|
12
|
-
static
|
13
|
-
|
14
|
+
static uint
|
15
|
+
get_type (UITouch* touch)
|
14
16
|
{
|
15
|
-
assert(
|
16
|
-
|
17
|
+
assert(touch);
|
18
|
+
|
19
|
+
NSInteger type = 0;
|
20
|
+
if (@available(iOS 9.0, *)) type = touch.type;
|
21
|
+
|
22
|
+
switch (type)
|
23
|
+
{
|
24
|
+
case UITouchTypeDirect: return Pointer::TOUCH;
|
25
|
+
case UITouchTypePencil: return Pointer::PEN;
|
26
|
+
default: return Pointer::TYPE_NONE;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
static Pointer::Action
|
31
|
+
get_action (UITouch* touch)
|
32
|
+
{
|
33
|
+
assert(touch);
|
34
|
+
|
35
|
+
switch (touch.phase)
|
36
|
+
{
|
37
|
+
case UITouchPhaseBegan: return Pointer::DOWN;
|
38
|
+
case UITouchPhaseEnded: return Pointer::UP;
|
39
|
+
case UITouchPhaseMoved: return Pointer::MOVE;
|
40
|
+
case UITouchPhaseStationary: return Pointer::STAY;
|
41
|
+
case UITouchPhaseCancelled: return Pointer::CANCEL;
|
42
|
+
//case UITouchPhaseRegionEntered: return Pointer::MOVE;
|
43
|
+
//case UITouchPhaseRegionExited: return Pointer::MOVE;
|
44
|
+
//case UITouchPhaseRegionMoved: return Pointer::MOVE;
|
45
|
+
default: return Pointer::ACTION_NONE;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
static Point
|
50
|
+
to_point (const CGPoint& point)
|
51
|
+
{
|
52
|
+
return Point(point.x, point.y);
|
53
|
+
}
|
54
|
+
|
55
|
+
static uint
|
56
|
+
get_modifiers (const UIEvent* event)
|
57
|
+
{
|
58
|
+
assert(event);
|
59
|
+
|
60
|
+
NSInteger flags = 0;
|
61
|
+
if (@available(iOS 13.4, *)) flags = event.modifierFlags;
|
62
|
+
|
63
|
+
return
|
64
|
+
(flags & UIKeyModifierAlphaShift) ? MOD_CAPS : 0 |
|
65
|
+
(flags & UIKeyModifierShift) ? MOD_SHIFT : 0 |
|
66
|
+
(flags & UIKeyModifierControl) ? MOD_CONTROL : 0 |
|
67
|
+
(flags & UIKeyModifierAlternate) ? MOD_ALT : 0 |
|
68
|
+
(flags & UIKeyModifierCommand) ? MOD_COMMAND : 0 |
|
69
|
+
(flags & UIKeyModifierNumericPad) ? MOD_NUMPAD : 0;
|
70
|
+
}
|
71
|
+
|
72
|
+
static void
|
73
|
+
attach_prev_pointer (
|
74
|
+
Pointer* pointer, PrevPointerList* prev_pointers, const Point& prev_position)
|
75
|
+
{
|
76
|
+
assert(pointer && prev_pointers);
|
77
|
+
|
78
|
+
auto it = std::find_if(
|
79
|
+
prev_pointers->begin(), prev_pointers->end(),
|
80
|
+
[&](const Reflex::Pointer& p) {return p.position() == prev_position;});
|
81
|
+
|
82
|
+
if (it != prev_pointers->end())
|
83
|
+
{
|
84
|
+
Reflex::Pointer_set_prev(pointer, &*it);
|
85
|
+
prev_pointers->erase(it);
|
86
|
+
}
|
87
|
+
else if (prev_pointers->size() == 1)
|
88
|
+
{
|
89
|
+
Reflex::Pointer_set_prev(pointer, &prev_pointers->front());
|
90
|
+
prev_pointers->clear();
|
91
|
+
}
|
92
|
+
else
|
93
|
+
Reflex::Pointer_set_prev(pointer, NULL);
|
94
|
+
|
95
|
+
if (pointer->prev())
|
96
|
+
Reflex::Pointer_set_id(pointer, pointer->prev()->id());
|
17
97
|
}
|
18
98
|
|
99
|
+
static Pointer
|
100
|
+
create_pointer (
|
101
|
+
UITouch* touch, UIEvent* event, UIView* view, double time,
|
102
|
+
Pointer::ID pointer_id, PrevPointerList* prev_pointers)
|
103
|
+
{
|
104
|
+
Reflex::Pointer::Action action = get_action(touch);
|
105
|
+
Reflex::Pointer pointer(
|
106
|
+
pointer_id,
|
107
|
+
get_type(touch),
|
108
|
+
action,
|
109
|
+
to_point([touch locationInView: view]),
|
110
|
+
get_modifiers(event),
|
111
|
+
(uint) touch.tapCount,
|
112
|
+
action == Pointer::MOVE,
|
113
|
+
time);
|
114
|
+
|
115
|
+
if (prev_pointers)
|
116
|
+
{
|
117
|
+
attach_prev_pointer(
|
118
|
+
&pointer, prev_pointers,
|
119
|
+
to_point([touch previousLocationInView: view]));
|
120
|
+
}
|
121
|
+
|
122
|
+
return pointer;
|
123
|
+
}
|
124
|
+
|
125
|
+
NativePointerEvent::NativePointerEvent (
|
126
|
+
NSSet* touches, UIEvent* event, UIView* view,
|
127
|
+
Pointer::ID* pointer_id)
|
128
|
+
{
|
129
|
+
for (UITouch* touch in touches)
|
130
|
+
{
|
131
|
+
PointerEvent_add_pointer(
|
132
|
+
this, create_pointer(touch, event, view, time(), ++*pointer_id, NULL));
|
133
|
+
}
|
134
|
+
}
|
19
135
|
|
20
136
|
NativePointerEvent::NativePointerEvent (
|
21
|
-
NSSet* touches, UIEvent*
|
22
|
-
|
137
|
+
NSSet* touches, UIEvent* event, UIView* view,
|
138
|
+
PrevPointerList* prev_pointers)
|
23
139
|
{
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
140
|
+
for (UITouch* touch in touches)
|
141
|
+
{
|
142
|
+
PointerEvent_add_pointer(
|
143
|
+
this, create_pointer(touch, event, view, time(), 0, prev_pointers));
|
28
144
|
}
|
29
|
-
size = index;
|
30
145
|
}
|
31
146
|
|
32
147
|
|
data/src/ios/view_controller.mm
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
#include <rays/opengl.h>
|
6
|
-
#include <rays/exception.h>
|
7
6
|
#include "reflex/exception.h"
|
8
7
|
#include "../view.h"
|
8
|
+
#include "../pointer.h"
|
9
9
|
#include "event.h"
|
10
10
|
#include "window.h"
|
11
11
|
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
static ReflexViewController*
|
17
|
-
|
17
|
+
create_reflex_view_controller ()
|
18
18
|
{
|
19
19
|
return [[ReflexViewController alloc] init];
|
20
20
|
}
|
@@ -52,7 +52,7 @@ get_top_view_controller (UIViewController* vc)
|
|
52
52
|
}
|
53
53
|
|
54
54
|
static void
|
55
|
-
|
55
|
+
show_reflex_view_controller (
|
56
56
|
UIViewController* root_vc, ReflexViewController* reflex_vc)
|
57
57
|
{
|
58
58
|
UIViewController* top = get_top_view_controller(root_vc);
|
@@ -90,13 +90,13 @@ ReflexViewController_set_show_fun (ReflexViewController_ShowFun fun)
|
|
90
90
|
ReflexViewController_CreateFun
|
91
91
|
ReflexViewController_get_create_fun ()
|
92
92
|
{
|
93
|
-
return global::create_fun ? global::create_fun :
|
93
|
+
return global::create_fun ? global::create_fun : create_reflex_view_controller;
|
94
94
|
}
|
95
95
|
|
96
96
|
ReflexViewController_ShowFun
|
97
97
|
ReflexViewController_get_show_fun ()
|
98
98
|
{
|
99
|
-
return global::show_fun ? global::show_fun :
|
99
|
+
return global::show_fun ? global::show_fun : show_reflex_view_controller;
|
100
100
|
}
|
101
101
|
|
102
102
|
|
@@ -131,6 +131,10 @@ ReflexViewController_get_show_fun ()
|
|
131
131
|
|
132
132
|
{
|
133
133
|
Reflex::Window *pwindow, *ptr_for_rebind;
|
134
|
+
int update_count;
|
135
|
+
int touching_count;
|
136
|
+
Reflex::Pointer::ID pointer_id;
|
137
|
+
Reflex::PrevPointerList prev_pointers;
|
134
138
|
}
|
135
139
|
|
136
140
|
- (id) init
|
@@ -138,7 +142,11 @@ ReflexViewController_get_show_fun ()
|
|
138
142
|
self = [super init];
|
139
143
|
if (!self) return nil;
|
140
144
|
|
141
|
-
pwindow
|
145
|
+
pwindow =
|
146
|
+
ptr_for_rebind = NULL;
|
147
|
+
update_count = 0;
|
148
|
+
touching_count = 0;
|
149
|
+
pointer_id = 0;
|
142
150
|
|
143
151
|
return self;
|
144
152
|
}
|
@@ -312,6 +320,8 @@ ReflexViewController_get_show_fun ()
|
|
312
320
|
Reflex::Window* win = self.window;
|
313
321
|
if (!win) return;
|
314
322
|
|
323
|
+
++update_count;
|
324
|
+
|
315
325
|
double now = Xot::time();
|
316
326
|
Reflex::UpdateEvent e(now, now - win->self->prev_time_update);
|
317
327
|
win->self->prev_time_update = now;
|
@@ -332,6 +342,9 @@ ReflexViewController_get_show_fun ()
|
|
332
342
|
Reflex::Window* win = self.window;
|
333
343
|
if (!win) return;
|
334
344
|
|
345
|
+
if (update_count == 0)
|
346
|
+
[self update];
|
347
|
+
|
335
348
|
EAGLContext* context = self.reflexView.context;
|
336
349
|
if (!context) return;
|
337
350
|
|
@@ -386,9 +399,12 @@ ReflexViewController_get_show_fun ()
|
|
386
399
|
Reflex::Window* win = self.window;
|
387
400
|
if (!win) return;
|
388
401
|
|
389
|
-
Reflex::NativePointerEvent e(
|
390
|
-
|
391
|
-
|
402
|
+
Reflex::NativePointerEvent e(touches, event, self.reflexView, &pointer_id);
|
403
|
+
[self addToPrevPointers: e];
|
404
|
+
|
405
|
+
touching_count += e.size();
|
406
|
+
|
407
|
+
Window_call_pointer_event(win, &e);
|
392
408
|
}
|
393
409
|
|
394
410
|
- (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
|
@@ -396,19 +412,20 @@ ReflexViewController_get_show_fun ()
|
|
396
412
|
Reflex::Window* win = self.window;
|
397
413
|
if (!win) return;
|
398
414
|
|
399
|
-
Reflex::NativePointerEvent e(
|
400
|
-
|
401
|
-
|
415
|
+
Reflex::NativePointerEvent e(touches, event, self.reflexView, &prev_pointers);
|
416
|
+
|
417
|
+
touching_count -= e.size();
|
418
|
+
if (touching_count == 0)
|
419
|
+
prev_pointers.clear();
|
420
|
+
else if (touching_count < 0)
|
421
|
+
Reflex::invalid_state_error(__FILE__, __LINE__);
|
422
|
+
|
423
|
+
Window_call_pointer_event(win, &e);
|
402
424
|
}
|
403
425
|
|
404
426
|
- (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
|
405
427
|
{
|
406
|
-
|
407
|
-
if (!win) return;
|
408
|
-
|
409
|
-
Reflex::NativePointerEvent e(
|
410
|
-
touches, event, self.reflexView, Reflex::PointerEvent::UP);
|
411
|
-
win->on_pointer(&e);
|
428
|
+
[self touchesEnded: touches withEvent: event];
|
412
429
|
}
|
413
430
|
|
414
431
|
- (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
|
@@ -416,9 +433,20 @@ ReflexViewController_get_show_fun ()
|
|
416
433
|
Reflex::Window* win = self.window;
|
417
434
|
if (!win) return;
|
418
435
|
|
419
|
-
Reflex::NativePointerEvent e(
|
420
|
-
|
421
|
-
|
436
|
+
Reflex::NativePointerEvent e(touches, event, self.reflexView, &prev_pointers);
|
437
|
+
[self addToPrevPointers: e];
|
438
|
+
|
439
|
+
Window_call_pointer_event(win, &e);
|
440
|
+
}
|
441
|
+
|
442
|
+
- (void) addToPrevPointers: (const Reflex::PointerEvent&) event
|
443
|
+
{
|
444
|
+
size_t size = event.size();
|
445
|
+
for (size_t i = 0; i < size; ++i)
|
446
|
+
{
|
447
|
+
prev_pointers.emplace_back(event[i]);
|
448
|
+
Reflex::Pointer_set_prev(&prev_pointers.back(), NULL);
|
449
|
+
}
|
422
450
|
}
|
423
451
|
|
424
452
|
@end// ReflexViewController
|
data/src/osx/event.h
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
|
7
7
|
#import <AppKit/NSEvent.h>
|
8
|
-
#include
|
8
|
+
#include "../event.h"
|
9
9
|
|
10
10
|
|
11
11
|
namespace Reflex
|
@@ -28,10 +28,13 @@ namespace Reflex
|
|
28
28
|
};// NativeFlagKeyEvent
|
29
29
|
|
30
30
|
|
31
|
-
|
31
|
+
class NativePointerEvent : public PointerEvent
|
32
32
|
{
|
33
33
|
|
34
|
-
|
34
|
+
public:
|
35
|
+
|
36
|
+
NativePointerEvent (
|
37
|
+
NSEvent* event, NSView* view, Pointer::ID id, Pointer::Action action);
|
35
38
|
|
36
39
|
};// NativePointerEvent
|
37
40
|
|