reflexion 0.1.19 → 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/contact_event.cpp +6 -6
- data/.doc/ext/reflex/event.cpp +9 -1
- data/.doc/ext/reflex/focus_event.cpp +6 -6
- data/.doc/ext/reflex/key_event.cpp +211 -13
- data/.doc/ext/reflex/native.cpp +2 -0
- data/.doc/ext/reflex/pointer.cpp +158 -0
- data/.doc/ext/reflex/pointer_event.cpp +31 -90
- data/.doc/ext/reflex/selector.cpp +8 -0
- data/.doc/ext/reflex/view.cpp +57 -0
- data/.doc/ext/reflex/window.cpp +41 -0
- data/VERSION +1 -1
- data/ext/reflex/contact_event.cpp +6 -6
- data/ext/reflex/event.cpp +11 -2
- data/ext/reflex/focus_event.cpp +6 -6
- data/ext/reflex/key_event.cpp +212 -13
- data/ext/reflex/native.cpp +2 -0
- data/ext/reflex/pointer.cpp +170 -0
- data/ext/reflex/pointer_event.cpp +30 -95
- data/ext/reflex/selector.cpp +9 -0
- data/ext/reflex/view.cpp +67 -3
- data/ext/reflex/window.cpp +49 -3
- data/include/reflex/defs.h +140 -106
- 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 +14 -8
- data/lib/reflex/application.rb +3 -3
- data/lib/reflex/autoinit.rb +1 -1
- data/lib/reflex/button.rb +7 -7
- data/lib/reflex/capture_event.rb +7 -7
- data/lib/reflex/contact_event.rb +4 -4
- data/lib/reflex/draw_event.rb +2 -2
- data/lib/reflex/ellipse_shape.rb +2 -2
- data/lib/reflex/focus_event.rb +4 -4
- data/lib/reflex/frame_event.rb +5 -5
- data/lib/reflex/helper.rb +20 -20
- data/lib/reflex/image_view.rb +2 -2
- data/lib/reflex/key_event.rb +6 -6
- data/lib/reflex/model.rb +22 -22
- data/lib/reflex/model_owner.rb +7 -7
- data/lib/reflex/model_view.rb +1 -1
- data/lib/reflex/module.rb +5 -5
- data/lib/reflex/pointer.rb +107 -0
- data/lib/reflex/pointer_event.rb +16 -54
- data/lib/reflex/polygon_shape.rb +2 -2
- data/lib/reflex/reflex.rb +3 -3
- data/lib/reflex/scroll_event.rb +1 -1
- data/lib/reflex/selector.rb +4 -4
- data/lib/reflex/shape.rb +13 -13
- data/lib/reflex/style.rb +11 -11
- data/lib/reflex/style_length.rb +1 -1
- data/lib/reflex/text_view.rb +2 -2
- data/lib/reflex/timer.rb +2 -2
- data/lib/reflex/timer_event.rb +1 -1
- data/lib/reflex/update_event.rb +1 -1
- data/lib/reflex/view.rb +32 -32
- data/lib/reflex/wheel_event.rb +3 -3
- data/lib/reflex/window.rb +7 -6
- data/lib/reflex.rb +1 -0
- data/lib/reflexion.rb +17 -17
- data/reflex.gemspec +5 -5
- data/samples/reflexion/noise.rb +1 -1
- data/samples/tree.rb +1 -1
- 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 +50 -22
- data/src/ios/window.mm +18 -0
- data/src/osx/event.h +14 -3
- data/src/osx/event.mm +213 -23
- data/src/osx/native_window.mm +84 -17
- data/src/osx/window.mm +22 -0
- data/src/pointer.cpp +203 -0
- data/src/pointer.h +26 -0
- data/src/selector.cpp +1 -1
- data/src/view.cpp +103 -64
- data/src/view.h +0 -4
- data/src/window.cpp +334 -98
- data/src/window.h +28 -3
- data/test/helper.rb +3 -3
- data/test/test_application.rb +1 -1
- data/test/test_capture_event.rb +6 -6
- data/test/test_event.rb +18 -4
- data/test/test_has_frame.rb +11 -11
- data/test/test_pointer.rb +149 -0
- data/test/test_pointer_event.rb +70 -104
- data/test/test_reflex.rb +1 -1
- data/test/test_selector.rb +15 -8
- data/test/test_shape.rb +8 -8
- data/test/test_style.rb +13 -13
- data/test/test_style_length.rb +5 -5
- data/test/test_view.rb +57 -30
- data/test/test_window.rb +45 -26
- metadata +46 -35
data/lib/reflexion.rb
CHANGED
@@ -18,7 +18,7 @@ module Reflexion
|
|
18
18
|
}
|
19
19
|
|
20
20
|
|
21
|
-
def call_event
|
21
|
+
def call_event(event, *args, &block)
|
22
22
|
$event = event
|
23
23
|
Xot::BlockUtil.instance_eval_or_block_call *args, &block if block
|
24
24
|
$event = nil
|
@@ -27,7 +27,7 @@ module Reflexion
|
|
27
27
|
|
28
28
|
class App < Application
|
29
29
|
|
30
|
-
def on_motion
|
30
|
+
def on_motion(e)
|
31
31
|
super
|
32
32
|
call_event e, e, &$motion
|
33
33
|
end
|
@@ -39,29 +39,29 @@ module Reflexion
|
|
39
39
|
|
40
40
|
attr_reader :event
|
41
41
|
|
42
|
-
def initialize
|
42
|
+
def initialize(*args, &block)
|
43
43
|
super
|
44
44
|
$window = self
|
45
45
|
call_event nil, self, &$setup
|
46
46
|
end
|
47
47
|
|
48
|
-
def on_update
|
48
|
+
def on_update(e)
|
49
49
|
super
|
50
50
|
redraw
|
51
51
|
call_event e, e, &$update
|
52
52
|
end
|
53
53
|
|
54
|
-
def on_draw
|
54
|
+
def on_draw(e)
|
55
55
|
super
|
56
56
|
call_event e, e.painter, &$draw
|
57
57
|
end
|
58
58
|
|
59
|
-
def on_key
|
59
|
+
def on_key(e)
|
60
60
|
super
|
61
61
|
call_event e, e, &$key
|
62
62
|
end
|
63
63
|
|
64
|
-
def on_pointer
|
64
|
+
def on_pointer(e)
|
65
65
|
super
|
66
66
|
call_event e, e, &$pointer
|
67
67
|
end
|
@@ -71,43 +71,43 @@ module Reflexion
|
|
71
71
|
|
72
72
|
module_function
|
73
73
|
|
74
|
-
def window
|
74
|
+
def window()
|
75
75
|
$window ||= MainWindow.new DEFAULTS
|
76
76
|
end
|
77
77
|
|
78
|
-
def event
|
78
|
+
def event()
|
79
79
|
$event
|
80
80
|
end
|
81
81
|
|
82
|
-
def setup
|
82
|
+
def setup(&block)
|
83
83
|
$setup = block
|
84
84
|
end
|
85
85
|
|
86
|
-
def update
|
86
|
+
def update(&block)
|
87
87
|
$update = block
|
88
88
|
end
|
89
89
|
|
90
|
-
def draw
|
90
|
+
def draw(&block)
|
91
91
|
$draw = block
|
92
92
|
end
|
93
93
|
|
94
|
-
def key
|
94
|
+
def key(&block)
|
95
95
|
$key = block
|
96
96
|
end
|
97
97
|
|
98
|
-
def pointer
|
98
|
+
def pointer(&block)
|
99
99
|
$pointer = block
|
100
100
|
end
|
101
101
|
|
102
|
-
def motion
|
102
|
+
def motion(&block)
|
103
103
|
$motion = block
|
104
104
|
end
|
105
105
|
|
106
|
-
def start
|
106
|
+
def start()
|
107
107
|
App.new {window.show}.start
|
108
108
|
end
|
109
109
|
|
110
|
-
def quit
|
110
|
+
def quit()
|
111
111
|
window.close
|
112
112
|
end
|
113
113
|
|
data/reflex.gemspec
CHANGED
@@ -26,12 +26,12 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.homepage = "https://github.com/xord/reflex"
|
27
27
|
|
28
28
|
s.platform = Gem::Platform::RUBY
|
29
|
-
s.required_ruby_version = '
|
29
|
+
s.required_ruby_version = '>= 2.6.0'
|
30
30
|
|
31
|
-
s.add_runtime_dependency 'xot', '~> 0.1.
|
32
|
-
s.add_runtime_dependency 'rucy', '~> 0.1.
|
33
|
-
s.add_runtime_dependency 'beeps', '~> 0.1.
|
34
|
-
s.add_runtime_dependency 'rays', '~> 0.1.
|
31
|
+
s.add_runtime_dependency 'xot', '~> 0.1.23'
|
32
|
+
s.add_runtime_dependency 'rucy', '~> 0.1.23'
|
33
|
+
s.add_runtime_dependency 'beeps', '~> 0.1.23'
|
34
|
+
s.add_runtime_dependency 'rays', '~> 0.1.23'
|
35
35
|
|
36
36
|
s.files = `git ls-files`.split $/
|
37
37
|
s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
|
data/samples/reflexion/noise.rb
CHANGED
data/samples/tree.rb
CHANGED
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
|
|