reflexion 0.1.19 → 0.1.23
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/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/src/osx/native_window.mm
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
|
5
5
|
#include <assert.h>
|
6
6
|
#import <Cocoa/Cocoa.h>
|
7
|
-
#include "rays/bounds.h"
|
8
7
|
#include "reflex/exception.h"
|
9
8
|
#include "../view.h"
|
9
|
+
#include "../pointer.h"
|
10
10
|
#include "event.h"
|
11
11
|
#include "window.h"
|
12
12
|
#import "opengl_view.h"
|
@@ -20,12 +20,30 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
20
20
|
0;//NSTexturedBackgroundWindowMask
|
21
21
|
|
22
22
|
|
23
|
+
static int
|
24
|
+
count_mouse_buttons (const Reflex::PointerEvent& e)
|
25
|
+
{
|
26
|
+
uint nbuttons = 0;
|
27
|
+
PointerEvent_each_pointer(&e, [&](const auto& pointer) {
|
28
|
+
uint t = pointer.type();
|
29
|
+
nbuttons +=
|
30
|
+
(t & Reflex::Pointer::MOUSE_LEFT ? 1 : 0) +
|
31
|
+
(t & Reflex::Pointer::MOUSE_RIGHT ? 1 : 0) +
|
32
|
+
(t & Reflex::Pointer::MOUSE_MIDDLE ? 1 : 0);
|
33
|
+
});
|
34
|
+
return nbuttons;
|
35
|
+
}
|
36
|
+
|
23
37
|
@implementation NativeWindow
|
24
38
|
|
25
39
|
{
|
26
40
|
Reflex::Window *pwindow, *ptr_for_rebind;
|
27
41
|
OpenGLView* view;
|
28
42
|
NSTimer* timer;
|
43
|
+
int update_count;
|
44
|
+
int clicking_count;
|
45
|
+
Reflex::Pointer::ID pointer_id;
|
46
|
+
Reflex::Pointer prevPointer;
|
29
47
|
}
|
30
48
|
|
31
49
|
- (id) init
|
@@ -37,9 +55,13 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
37
55
|
defer: NO];
|
38
56
|
if (!self) return nil;
|
39
57
|
|
40
|
-
pwindow
|
41
|
-
|
42
|
-
|
58
|
+
pwindow =
|
59
|
+
ptr_for_rebind = NULL;
|
60
|
+
view = nil;
|
61
|
+
timer = nil;
|
62
|
+
update_count = 0;
|
63
|
+
clicking_count = 0;
|
64
|
+
pointer_id = 0;
|
43
65
|
|
44
66
|
[self setDelegate: self];
|
45
67
|
[self setupContentView];
|
@@ -152,6 +174,8 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
152
174
|
Reflex::Window* win = self.window;
|
153
175
|
if (!win) return;
|
154
176
|
|
177
|
+
++update_count;
|
178
|
+
|
155
179
|
double now = Xot::time();
|
156
180
|
Reflex::UpdateEvent e(now, now - win->self->prev_time_update);
|
157
181
|
win->self->prev_time_update = now;
|
@@ -172,6 +196,9 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
172
196
|
Reflex::Window* win = self.window;
|
173
197
|
if (!win) return;
|
174
198
|
|
199
|
+
if (update_count == 0)
|
200
|
+
[self update];
|
201
|
+
|
175
202
|
double now = Xot::time();
|
176
203
|
double dt = now - win->self->prev_time_draw;
|
177
204
|
double fps = 1. / dt;
|
@@ -250,7 +277,7 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
250
277
|
b.move_to(0, 0);
|
251
278
|
|
252
279
|
if (win->painter())
|
253
|
-
win->painter()->canvas(b,
|
280
|
+
win->painter()->canvas(b, win->painter()->pixel_density());
|
254
281
|
|
255
282
|
if (win->root())
|
256
283
|
View_set_frame(win->root(), b);
|
@@ -266,7 +293,7 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
266
293
|
if (!win) return;
|
267
294
|
|
268
295
|
Reflex::NativeKeyEvent e(event, Reflex::KeyEvent::DOWN);
|
269
|
-
win
|
296
|
+
Window_call_key_event(win, &e);
|
270
297
|
}
|
271
298
|
|
272
299
|
- (void) keyUp: (NSEvent*) event
|
@@ -275,12 +302,16 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
275
302
|
if (!win) return;
|
276
303
|
|
277
304
|
Reflex::NativeKeyEvent e(event, Reflex::KeyEvent::UP);
|
278
|
-
win
|
305
|
+
Window_call_key_event(win, &e);
|
279
306
|
}
|
280
307
|
|
281
308
|
- (void) flagsChanged: (NSEvent*) event
|
282
309
|
{
|
283
|
-
|
310
|
+
Reflex::Window* win = self.window;
|
311
|
+
if (!win) return;
|
312
|
+
|
313
|
+
Reflex::NativeFlagKeyEvent e(event);
|
314
|
+
Window_call_key_event(win, &e);
|
284
315
|
}
|
285
316
|
|
286
317
|
- (void) mouseDown: (NSEvent*) event
|
@@ -288,8 +319,22 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
288
319
|
Reflex::Window* win = self.window;
|
289
320
|
if (!win) return;
|
290
321
|
|
291
|
-
|
292
|
-
|
322
|
+
if (clicking_count == 0) ++pointer_id;
|
323
|
+
|
324
|
+
Reflex::NativePointerEvent e(event, view, pointer_id, Reflex::Pointer::DOWN);
|
325
|
+
|
326
|
+
if (e[0].position().y < 0)
|
327
|
+
{
|
328
|
+
// ignore mouseDown event since the mouseUp event to the window title bar
|
329
|
+
// will not come and will break clicking_count.
|
330
|
+
return;
|
331
|
+
}
|
332
|
+
|
333
|
+
[self attachAndUpdatePrevPointer: &e];
|
334
|
+
|
335
|
+
clicking_count += count_mouse_buttons(e);
|
336
|
+
|
337
|
+
Window_call_pointer_event(win, &e);
|
293
338
|
}
|
294
339
|
|
295
340
|
- (void) mouseUp: (NSEvent*) event
|
@@ -297,8 +342,16 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
297
342
|
Reflex::Window* win = self.window;
|
298
343
|
if (!win) return;
|
299
344
|
|
300
|
-
Reflex::NativePointerEvent e(event, view, Reflex::
|
301
|
-
|
345
|
+
Reflex::NativePointerEvent e(event, view, pointer_id, Reflex::Pointer::UP);
|
346
|
+
[self attachAndUpdatePrevPointer: &e];
|
347
|
+
|
348
|
+
clicking_count -= count_mouse_buttons(e);
|
349
|
+
if (clicking_count == 0)
|
350
|
+
++pointer_id;
|
351
|
+
else if (clicking_count < 0)
|
352
|
+
Reflex::invalid_state_error(__FILE__, __LINE__);
|
353
|
+
|
354
|
+
Window_call_pointer_event(win, &e);
|
302
355
|
}
|
303
356
|
|
304
357
|
- (void) mouseDragged: (NSEvent*) event
|
@@ -306,8 +359,10 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
306
359
|
Reflex::Window* win = self.window;
|
307
360
|
if (!win) return;
|
308
361
|
|
309
|
-
Reflex::NativePointerEvent e(event, view, Reflex::
|
310
|
-
|
362
|
+
Reflex::NativePointerEvent e(event, view, pointer_id, Reflex::Pointer::MOVE);
|
363
|
+
[self attachAndUpdatePrevPointer: &e];
|
364
|
+
|
365
|
+
Window_call_pointer_event(win, &e);
|
311
366
|
}
|
312
367
|
|
313
368
|
- (void) mouseMoved: (NSEvent*) event
|
@@ -315,8 +370,20 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
315
370
|
Reflex::Window* win = self.window;
|
316
371
|
if (!win) return;
|
317
372
|
|
318
|
-
Reflex::NativePointerEvent e(event, view, Reflex::
|
319
|
-
|
373
|
+
Reflex::NativePointerEvent e(event, view, pointer_id, Reflex::Pointer::MOVE);
|
374
|
+
[self attachAndUpdatePrevPointer: &e];
|
375
|
+
|
376
|
+
Window_call_pointer_event(win, &e);
|
377
|
+
}
|
378
|
+
|
379
|
+
- (void) attachAndUpdatePrevPointer: (Reflex::PointerEvent*) e
|
380
|
+
{
|
381
|
+
assert(e->size() == 1);
|
382
|
+
|
383
|
+
Reflex::Pointer& pointer = Reflex::PointerEvent_pointer_at(e, 0);
|
384
|
+
if (prevPointer)
|
385
|
+
Reflex::Pointer_set_prev(&pointer, &prevPointer);
|
386
|
+
prevPointer = pointer;
|
320
387
|
}
|
321
388
|
|
322
389
|
- (void) scrollWheel: (NSEvent*) event
|
@@ -325,7 +392,7 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
325
392
|
if (!win) return;
|
326
393
|
|
327
394
|
Reflex::NativeWheelEvent e(event, view);
|
328
|
-
win
|
395
|
+
Window_call_wheel_event(win, &e);
|
329
396
|
}
|
330
397
|
|
331
398
|
+ (NSRect) frameRectForContentRect: (NSRect) contentRect
|
data/src/osx/window.mm
CHANGED
@@ -112,6 +112,28 @@ namespace Reflex
|
|
112
112
|
rect.size.height);
|
113
113
|
}
|
114
114
|
|
115
|
+
void
|
116
|
+
Window_set_resizable (Window* window, bool state)
|
117
|
+
{
|
118
|
+
NativeWindow* native = get_native(window);
|
119
|
+
if (state)
|
120
|
+
native.styleMask |= NSResizableWindowMask;
|
121
|
+
else
|
122
|
+
native.styleMask &= ~NSResizableWindowMask;
|
123
|
+
}
|
124
|
+
|
125
|
+
bool
|
126
|
+
Window_is_resizable (const Window& window)
|
127
|
+
{
|
128
|
+
return get_native(&window).styleMask & NSResizableWindowMask;
|
129
|
+
}
|
130
|
+
|
131
|
+
float
|
132
|
+
Window_get_pixel_density (const Window& window)
|
133
|
+
{
|
134
|
+
return get_native(&window).backingScaleFactor;
|
135
|
+
}
|
136
|
+
|
115
137
|
|
116
138
|
WindowData::WindowData ()
|
117
139
|
{
|
data/src/pointer.cpp
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
#include "pointer.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <xot/time.h>
|
5
|
+
#include "reflex/exception.h"
|
6
|
+
|
7
|
+
|
8
|
+
namespace Reflex
|
9
|
+
{
|
10
|
+
|
11
|
+
|
12
|
+
class PrevPointerPtr : public Xot::PImpl<Pointer>
|
13
|
+
{
|
14
|
+
|
15
|
+
typedef Xot::PImpl<Pointer> Super;
|
16
|
+
|
17
|
+
public:
|
18
|
+
|
19
|
+
PrevPointerPtr () : Super(NULL) {}
|
20
|
+
|
21
|
+
};// PrevPointerPtr
|
22
|
+
|
23
|
+
|
24
|
+
struct Pointer::Data
|
25
|
+
{
|
26
|
+
|
27
|
+
enum Flag
|
28
|
+
{
|
29
|
+
|
30
|
+
DRAG = Xot::bit(0),
|
31
|
+
|
32
|
+
ENTER = Xot::bit(1),
|
33
|
+
|
34
|
+
EXIT = Xot::bit(2),
|
35
|
+
|
36
|
+
};// Flag
|
37
|
+
|
38
|
+
ID id;
|
39
|
+
|
40
|
+
uint type;
|
41
|
+
|
42
|
+
Action action;
|
43
|
+
|
44
|
+
Point position;
|
45
|
+
|
46
|
+
uint modifiers, click_count, flags;
|
47
|
+
|
48
|
+
double time;
|
49
|
+
|
50
|
+
PrevPointerPtr prev;
|
51
|
+
|
52
|
+
Data (
|
53
|
+
ID id = -1, uint type = TYPE_NONE, Action action = ACTION_NONE,
|
54
|
+
const Point& position = 0, uint modifiers = 0, uint click_count = 0,
|
55
|
+
bool drag = false, bool enter = false, bool exit = false,
|
56
|
+
double time = 0)
|
57
|
+
: id(id), type(type), action(action),
|
58
|
+
position(position), modifiers(modifiers), click_count(click_count),
|
59
|
+
flags(make_flags(drag, enter, exit)),
|
60
|
+
time(time)
|
61
|
+
{
|
62
|
+
}
|
63
|
+
|
64
|
+
uint make_flags (bool drag, bool enter, bool exit)
|
65
|
+
{
|
66
|
+
return
|
67
|
+
(drag ? DRAG : 0) |
|
68
|
+
(enter ? ENTER : 0) |
|
69
|
+
(exit ? EXIT : 0);
|
70
|
+
}
|
71
|
+
|
72
|
+
};// Pointer::Data
|
73
|
+
|
74
|
+
|
75
|
+
void
|
76
|
+
Pointer_update_positions (Pointer* pthis, std::function<void(Point*)> fun)
|
77
|
+
{
|
78
|
+
assert(pthis);
|
79
|
+
|
80
|
+
auto& self = pthis->self;
|
81
|
+
fun(&self->position);
|
82
|
+
if (self->prev)
|
83
|
+
fun(&self->prev->self->position);
|
84
|
+
}
|
85
|
+
|
86
|
+
void
|
87
|
+
Pointer_set_id (Pointer* pthis, Pointer::ID id)
|
88
|
+
{
|
89
|
+
pthis->self->id = id;
|
90
|
+
}
|
91
|
+
|
92
|
+
void
|
93
|
+
Pointer_set_prev (Pointer* pthis, const Pointer* prev)
|
94
|
+
{
|
95
|
+
if (prev)
|
96
|
+
pthis->self->prev.reset(new Pointer(*prev));
|
97
|
+
else
|
98
|
+
pthis->self->prev.reset();
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
Pointer::Pointer ()
|
103
|
+
{
|
104
|
+
}
|
105
|
+
|
106
|
+
Pointer::Pointer (
|
107
|
+
ID id, uint type, Action action,
|
108
|
+
const Point& position, uint modifiers, uint click_count, bool drag,
|
109
|
+
double time)
|
110
|
+
: self(new Data(
|
111
|
+
id, type, action,
|
112
|
+
position, modifiers, click_count, drag, false, false,
|
113
|
+
time))
|
114
|
+
{
|
115
|
+
}
|
116
|
+
|
117
|
+
Pointer::Pointer (const This& obj)
|
118
|
+
: self(new Data(*obj.self))
|
119
|
+
{
|
120
|
+
}
|
121
|
+
|
122
|
+
Pointer&
|
123
|
+
Pointer::operator = (const This& obj)
|
124
|
+
{
|
125
|
+
if (&obj == this) return *this;
|
126
|
+
|
127
|
+
*self = *obj.self;
|
128
|
+
return *this;
|
129
|
+
}
|
130
|
+
|
131
|
+
Pointer::~Pointer ()
|
132
|
+
{
|
133
|
+
}
|
134
|
+
|
135
|
+
Pointer::ID
|
136
|
+
Pointer::id () const
|
137
|
+
{
|
138
|
+
return self->id;
|
139
|
+
}
|
140
|
+
|
141
|
+
uint
|
142
|
+
Pointer::type () const
|
143
|
+
{
|
144
|
+
return self->type;
|
145
|
+
}
|
146
|
+
|
147
|
+
Pointer::Action
|
148
|
+
Pointer::action () const
|
149
|
+
{
|
150
|
+
return self->action;
|
151
|
+
}
|
152
|
+
|
153
|
+
const Point&
|
154
|
+
Pointer::position () const
|
155
|
+
{
|
156
|
+
return self->position;
|
157
|
+
}
|
158
|
+
|
159
|
+
uint
|
160
|
+
Pointer::modifiers () const
|
161
|
+
{
|
162
|
+
return self->modifiers;
|
163
|
+
}
|
164
|
+
|
165
|
+
uint
|
166
|
+
Pointer::click_count () const
|
167
|
+
{
|
168
|
+
return self->click_count;
|
169
|
+
}
|
170
|
+
|
171
|
+
bool
|
172
|
+
Pointer::is_drag () const
|
173
|
+
{
|
174
|
+
return self->flags & Data::DRAG;
|
175
|
+
}
|
176
|
+
|
177
|
+
double
|
178
|
+
Pointer::time () const
|
179
|
+
{
|
180
|
+
return self->time;
|
181
|
+
}
|
182
|
+
|
183
|
+
const Pointer*
|
184
|
+
Pointer::prev () const
|
185
|
+
{
|
186
|
+
return self->prev.get();
|
187
|
+
}
|
188
|
+
|
189
|
+
Pointer::operator bool () const
|
190
|
+
{
|
191
|
+
return
|
192
|
+
self->type != TYPE_NONE &&
|
193
|
+
ACTION_NONE < self->action && self->action <= STAY;
|
194
|
+
}
|
195
|
+
|
196
|
+
bool
|
197
|
+
Pointer::operator ! () const
|
198
|
+
{
|
199
|
+
return !operator bool();
|
200
|
+
}
|
201
|
+
|
202
|
+
|
203
|
+
}// Reflex
|
data/src/pointer.h
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __REFLEX_SRC_POINTER_H__
|
4
|
+
#define __REFLEX_SRC_POINTER_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <functional>
|
8
|
+
#include <reflex/pointer.h>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Reflex
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
void Pointer_update_positions (
|
16
|
+
Pointer* pthis, std::function<void(Point*)> fun);
|
17
|
+
|
18
|
+
void Pointer_set_id (Pointer* pthis, Pointer::ID id);
|
19
|
+
|
20
|
+
void Pointer_set_prev (Pointer* pthis, const Pointer* prev);
|
21
|
+
|
22
|
+
|
23
|
+
}// Reflex
|
24
|
+
|
25
|
+
|
26
|
+
#endif//EOH
|