reflexion 0.1.35 → 0.1.36
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/view.cpp +17 -0
- data/ChangeLog.md +10 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/ext/reflex/extconf.rb +0 -3
- data/ext/reflex/view.cpp +19 -0
- data/include/reflex/event.h +1 -1
- data/include/reflex/view.h +6 -0
- data/lib/reflex/application.rb +2 -3
- data/lib/reflex/autoinit.rb +0 -3
- data/lib/reflex/bitmap.rb +0 -3
- data/lib/reflex/bounds.rb +0 -3
- data/lib/reflex/button.rb +0 -3
- data/lib/reflex/camera.rb +0 -3
- data/lib/reflex/capture_event.rb +0 -3
- data/lib/reflex/color.rb +0 -3
- data/lib/reflex/color_space.rb +0 -3
- data/lib/reflex/contact_event.rb +0 -3
- data/lib/reflex/draw_event.rb +0 -3
- data/lib/reflex/ellipse_shape.rb +0 -3
- data/lib/reflex/ext.rb +0 -3
- data/lib/reflex/extension.rb +0 -3
- data/lib/reflex/filter.rb +0 -3
- data/lib/reflex/fixture.rb +0 -3
- data/lib/reflex/focus_event.rb +0 -3
- data/lib/reflex/font.rb +0 -3
- data/lib/reflex/frame_event.rb +0 -3
- data/lib/reflex/helper.rb +0 -3
- data/lib/reflex/image.rb +0 -3
- data/lib/reflex/image_view.rb +0 -3
- data/lib/reflex/key_event.rb +0 -3
- data/lib/reflex/line_shape.rb +0 -3
- data/lib/reflex/list_view.rb +0 -3
- data/lib/reflex/matrix.rb +0 -3
- data/lib/reflex/model.rb +0 -3
- data/lib/reflex/model_owner.rb +0 -3
- data/lib/reflex/model_view.rb +0 -3
- data/lib/reflex/painter.rb +0 -3
- data/lib/reflex/point.rb +0 -3
- data/lib/reflex/pointer.rb +0 -3
- data/lib/reflex/pointer_event.rb +0 -3
- data/lib/reflex/polygon.rb +0 -3
- data/lib/reflex/polygon_shape.rb +0 -3
- data/lib/reflex/polyline.rb +0 -3
- data/lib/reflex/rect_shape.rb +0 -3
- data/lib/reflex/reflex.rb +0 -3
- data/lib/reflex/scroll_event.rb +0 -3
- data/lib/reflex/selector.rb +0 -3
- data/lib/reflex/shader.rb +0 -3
- data/lib/reflex/shape.rb +0 -3
- data/lib/reflex/style.rb +0 -3
- data/lib/reflex/style_length.rb +0 -3
- data/lib/reflex/text_view.rb +0 -3
- data/lib/reflex/timer.rb +0 -3
- data/lib/reflex/timer_event.rb +0 -3
- data/lib/reflex/update_event.rb +0 -3
- data/lib/reflex/view.rb +10 -4
- data/lib/reflex/wheel_event.rb +0 -3
- data/lib/reflex/window.rb +2 -3
- data/lib/reflex.rb +0 -3
- data/lib/reflexion/include.rb +0 -3
- data/lib/reflexion.rb +0 -3
- data/reflex.gemspec +5 -5
- data/samples/app.rb +0 -3
- data/samples/bats.rb +0 -3
- data/samples/camera.rb +0 -3
- data/samples/checker.rb +0 -3
- data/samples/fans.rb +0 -3
- data/samples/fps.rb +0 -3
- data/samples/grid.rb +0 -3
- data/samples/hello.rb +0 -3
- data/samples/image.rb +0 -3
- data/samples/key.rb +0 -3
- data/samples/layout.rb +0 -3
- data/samples/model.rb +0 -3
- data/samples/physics.rb +0 -3
- data/samples/reflexion/breakout.rb +0 -3
- data/samples/reflexion/hello.rb +0 -3
- data/samples/reflexion/jump_action.rb +0 -3
- data/samples/reflexion/noise.rb +0 -3
- data/samples/reflexion/paint.rb +0 -3
- data/samples/reflexion/physics.rb +0 -3
- data/samples/reflexion/pulse.rb +0 -3
- data/samples/repl.rb +0 -3
- data/samples/shader.rb +0 -3
- data/samples/shapes.rb +0 -3
- data/samples/text.rb +0 -3
- data/samples/tree.rb +0 -3
- data/samples/views.rb +0 -3
- data/samples/visuals.rb +0 -3
- data/src/body.cpp +14 -0
- data/src/body.h +4 -0
- data/src/event.cpp +27 -28
- data/src/view.cpp +89 -14
- data/src/window.cpp +4 -2
- data/test/helper.rb +0 -3
- data/test/test_application.rb +4 -3
- data/test/test_capture_event.rb +0 -3
- data/test/test_contact_event.rb +0 -3
- data/test/test_draw_event.rb +0 -3
- data/test/test_event.rb +1 -4
- data/test/test_focus_event.rb +0 -3
- data/test/test_frame_event.rb +0 -3
- data/test/test_has_frame.rb +0 -3
- data/test/test_key_event.rb +0 -3
- data/test/test_model.rb +0 -3
- data/test/test_model_owner.rb +0 -3
- data/test/test_pointer.rb +0 -3
- data/test/test_pointer_event.rb +0 -3
- data/test/test_reflex_init.rb +0 -3
- data/test/test_scroll_event.rb +0 -3
- data/test/test_selector.rb +0 -3
- data/test/test_shape.rb +0 -3
- data/test/test_style.rb +0 -3
- data/test/test_style_length.rb +0 -3
- data/test/test_timer_event.rb +0 -3
- data/test/test_update_event.rb +0 -3
- data/test/test_view.rb +37 -3
- data/test/test_wheel_event.rb +0 -3
- data/test/test_window.rb +4 -3
- metadata +10 -10
data/samples/camera.rb
CHANGED
data/samples/checker.rb
CHANGED
data/samples/fans.rb
CHANGED
data/samples/fps.rb
CHANGED
data/samples/grid.rb
CHANGED
data/samples/hello.rb
CHANGED
data/samples/image.rb
CHANGED
data/samples/key.rb
CHANGED
data/samples/layout.rb
CHANGED
data/samples/model.rb
CHANGED
data/samples/physics.rb
CHANGED
data/samples/reflexion/hello.rb
CHANGED
data/samples/reflexion/noise.rb
CHANGED
data/samples/reflexion/paint.rb
CHANGED
data/samples/reflexion/pulse.rb
CHANGED
data/samples/repl.rb
CHANGED
data/samples/shader.rb
CHANGED
data/samples/shapes.rb
CHANGED
data/samples/text.rb
CHANGED
data/samples/tree.rb
CHANGED
data/samples/views.rb
CHANGED
data/samples/visuals.rb
CHANGED
data/src/body.cpp
CHANGED
@@ -126,6 +126,14 @@ namespace Reflex
|
|
126
126
|
self->b2body->ApplyAngularImpulse(impulse, true);
|
127
127
|
}
|
128
128
|
|
129
|
+
void
|
130
|
+
Body::awake ()
|
131
|
+
{
|
132
|
+
validate(this);
|
133
|
+
|
134
|
+
self->b2body->SetAwake(true);
|
135
|
+
}
|
136
|
+
|
129
137
|
float
|
130
138
|
Body::meter2pixel (float meter) const
|
131
139
|
{
|
@@ -141,6 +149,12 @@ namespace Reflex
|
|
141
149
|
to_b2vec2(x, y, self->ppm), Xot::deg2rad(degree));
|
142
150
|
}
|
143
151
|
|
152
|
+
void
|
153
|
+
Body::set_transform (const Point& position, float degree)
|
154
|
+
{
|
155
|
+
set_transform(position.x, position.y, degree);
|
156
|
+
}
|
157
|
+
|
144
158
|
Point
|
145
159
|
Body::position () const
|
146
160
|
{
|
data/src/body.h
CHANGED
@@ -41,10 +41,14 @@ namespace Reflex
|
|
41
41
|
|
42
42
|
void apply_angular_impulse (float impulse);
|
43
43
|
|
44
|
+
void awake ();
|
45
|
+
|
44
46
|
float meter2pixel (float meter = 1) const;
|
45
47
|
|
46
48
|
void set_transform (coord x, coord y, float degree);
|
47
49
|
|
50
|
+
void set_transform (const Point& position, float degree);
|
51
|
+
|
48
52
|
Point position () const;
|
49
53
|
|
50
54
|
float angle () const;
|
data/src/event.cpp
CHANGED
@@ -26,10 +26,10 @@ namespace Reflex
|
|
26
26
|
{
|
27
27
|
}
|
28
28
|
|
29
|
-
void block ()
|
29
|
+
void block (bool parent)
|
30
30
|
{
|
31
31
|
blocked = true;
|
32
|
-
if (parent) parent->block();
|
32
|
+
if (parent && this->parent) this->parent->block(true);
|
33
33
|
}
|
34
34
|
|
35
35
|
};// Event::Data
|
@@ -50,9 +50,9 @@ namespace Reflex
|
|
50
50
|
}
|
51
51
|
|
52
52
|
void
|
53
|
-
Event::block ()
|
53
|
+
Event::block (bool parent)
|
54
54
|
{
|
55
|
-
self->block();
|
55
|
+
self->block(parent);
|
56
56
|
}
|
57
57
|
|
58
58
|
bool
|
@@ -634,29 +634,6 @@ namespace Reflex
|
|
634
634
|
pthis->self->captured = captured;
|
635
635
|
}
|
636
636
|
|
637
|
-
static void
|
638
|
-
filter_and_offset_pointer_positions (PointerEvent* event, const Bounds& frame)
|
639
|
-
{
|
640
|
-
assert(event);
|
641
|
-
|
642
|
-
const Point& offset = frame.position();
|
643
|
-
|
644
|
-
std::vector<Pointer> pointers;
|
645
|
-
for (const auto& pointer : event->self->pointers)
|
646
|
-
{
|
647
|
-
if (!frame.is_include(pointer.position()))
|
648
|
-
continue;
|
649
|
-
|
650
|
-
pointers.emplace_back(pointer);
|
651
|
-
Pointer_update_positions(&pointers.back(), [&](Point* pos)
|
652
|
-
{
|
653
|
-
*pos -= offset;
|
654
|
-
});
|
655
|
-
}
|
656
|
-
|
657
|
-
event->self->pointers = pointers;
|
658
|
-
}
|
659
|
-
|
660
637
|
static void
|
661
638
|
scroll_and_zoom_pointer_positions (
|
662
639
|
PointerEvent* event, const Point& scroll, float zoom)
|
@@ -685,7 +662,26 @@ namespace Reflex
|
|
685
662
|
if (!pthis || !view)
|
686
663
|
argument_error(__FILE__, __LINE__);
|
687
664
|
|
688
|
-
|
665
|
+
const Bounds& frame = view->frame();
|
666
|
+
const Point& offset = frame.position();
|
667
|
+
Bounds bounds = frame.dup().move_to(0, 0);
|
668
|
+
float angle = view->angle();
|
669
|
+
|
670
|
+
std::vector<Pointer> pointers;
|
671
|
+
for (const auto& pointer : pthis->self->pointers)
|
672
|
+
{
|
673
|
+
pointers.emplace_back(pointer);
|
674
|
+
Pointer_update_positions(&pointers.back(), [&](Point* pos)
|
675
|
+
{
|
676
|
+
*pos -= offset;
|
677
|
+
pos->rotate(-angle);
|
678
|
+
});
|
679
|
+
|
680
|
+
if (!bounds.is_include(pointers.back().position()))
|
681
|
+
pointers.pop_back();
|
682
|
+
}
|
683
|
+
pthis->self->pointers = pointers;
|
684
|
+
|
689
685
|
scroll_and_zoom_pointer_positions(pthis, view->scroll(), view->zoom());
|
690
686
|
}
|
691
687
|
|
@@ -695,11 +691,14 @@ namespace Reflex
|
|
695
691
|
if (!pthis || !view)
|
696
692
|
argument_error(__FILE__, __LINE__);
|
697
693
|
|
694
|
+
float angle = view->angle();
|
695
|
+
|
698
696
|
for (auto& pointer : pthis->self->pointers)
|
699
697
|
{
|
700
698
|
Pointer_update_positions(&pointer, [=](Point* pos)
|
701
699
|
{
|
702
700
|
*pos = view->from_window(*pos);
|
701
|
+
pos->rotate(-angle);
|
703
702
|
});
|
704
703
|
}
|
705
704
|
|
data/src/view.cpp
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
#include <assert.h>
|
5
5
|
#include <memory>
|
6
6
|
#include <algorithm>
|
7
|
+
#include <rays/matrix.h>
|
7
8
|
#include "reflex/timer.h"
|
8
9
|
#include "reflex/filter.h"
|
9
10
|
#include "reflex/exception.h"
|
@@ -25,6 +26,8 @@ namespace Reflex
|
|
25
26
|
|
26
27
|
static const char* WALL_NAME = "__WALL__";
|
27
28
|
|
29
|
+
static const Point ZERO = 0;
|
30
|
+
|
28
31
|
|
29
32
|
struct View::Data
|
30
33
|
{
|
@@ -68,6 +71,8 @@ namespace Reflex
|
|
68
71
|
|
69
72
|
uint flags = FLAG_CLIP | FLAG_RESIZE_TO_FIT | REDRAW | UPDATE_LAYOUT | UPDATE_STYLE;
|
70
73
|
|
74
|
+
std::unique_ptr<Point> ppivot;
|
75
|
+
|
71
76
|
std::unique_ptr<Point> pscroll;
|
72
77
|
|
73
78
|
SelectorPtr pselector;
|
@@ -94,6 +99,12 @@ namespace Reflex
|
|
94
99
|
|
95
100
|
std::unique_ptr<ChildList> pchildren;
|
96
101
|
|
102
|
+
Point& pivot ()
|
103
|
+
{
|
104
|
+
if (!ppivot) ppivot.reset(new Point);
|
105
|
+
return *ppivot;
|
106
|
+
}
|
107
|
+
|
97
108
|
Point& scroll ()
|
98
109
|
{
|
99
110
|
if (!pscroll) pscroll.reset(new Point);
|
@@ -195,7 +206,40 @@ namespace Reflex
|
|
195
206
|
{
|
196
207
|
if (!pbody) return;
|
197
208
|
|
198
|
-
|
209
|
+
auto* pivot = ppivot.get();
|
210
|
+
if (pivot && (pivot->x != 0 || pivot->y != 0) && angle != 0)
|
211
|
+
{
|
212
|
+
Matrix m;
|
213
|
+
get_view2body_matrix(&m);
|
214
|
+
pbody->set_transform(m * Point(0), angle);
|
215
|
+
}
|
216
|
+
else
|
217
|
+
pbody->set_transform(frame.x, frame.y, angle);
|
218
|
+
}
|
219
|
+
|
220
|
+
void
|
221
|
+
get_view2body_matrix (Matrix* m)
|
222
|
+
{
|
223
|
+
assert(m && *m == 1 && ppivot && *ppivot != 0);
|
224
|
+
|
225
|
+
Point pivot = *ppivot * frame.size();
|
226
|
+
m->translate(frame.position() + pivot)
|
227
|
+
.rotate(angle)
|
228
|
+
.translate(-pivot);
|
229
|
+
}
|
230
|
+
|
231
|
+
void
|
232
|
+
get_body2view_matrix (Matrix* m)
|
233
|
+
{
|
234
|
+
assert(m && *m == 1 && ppivot && *ppivot != 0 && pbody);
|
235
|
+
|
236
|
+
Point pivot = *ppivot * frame.size();
|
237
|
+
float angle = pbody->angle();
|
238
|
+
m->translate(pbody->position())
|
239
|
+
.rotate(angle)
|
240
|
+
.translate( pivot)
|
241
|
+
.rotate(-angle)
|
242
|
+
.translate(-pivot);
|
199
243
|
}
|
200
244
|
|
201
245
|
void update_body_and_shapes ()
|
@@ -797,12 +841,23 @@ namespace Reflex
|
|
797
841
|
update_view_body (View* view)
|
798
842
|
{
|
799
843
|
assert(view);
|
844
|
+
View::Data* self = view->self.get();
|
800
845
|
|
801
|
-
Body* body =
|
846
|
+
Body* body = self->pbody.get();
|
802
847
|
if (!body) return;
|
803
848
|
|
804
849
|
Bounds frame = view->frame();
|
805
|
-
|
850
|
+
|
851
|
+
auto* pivot = self->ppivot.get();
|
852
|
+
if (pivot && (pivot->x != 0 || pivot->y != 0) && self->angle != 0)
|
853
|
+
{
|
854
|
+
Matrix m;
|
855
|
+
self->get_body2view_matrix(&m);
|
856
|
+
frame.set_position(m * Point(0));
|
857
|
+
}
|
858
|
+
else
|
859
|
+
frame.set_position(body->position());
|
860
|
+
|
806
861
|
update_view_frame(view, frame, view->zoom(), body->angle(), false);
|
807
862
|
}
|
808
863
|
|
@@ -1083,7 +1138,7 @@ namespace Reflex
|
|
1083
1138
|
|
1084
1139
|
if (event->is_blocked()) return;
|
1085
1140
|
|
1086
|
-
View::ChildList* pchildren =
|
1141
|
+
View::ChildList* pchildren = self->pchildren.get();
|
1087
1142
|
if (pchildren)
|
1088
1143
|
{
|
1089
1144
|
for (auto& pchild : *pchildren)
|
@@ -1093,7 +1148,7 @@ namespace Reflex
|
|
1093
1148
|
}
|
1094
1149
|
}
|
1095
1150
|
|
1096
|
-
World* child_world =
|
1151
|
+
World* child_world = self->pchild_world.get();
|
1097
1152
|
if (child_world)
|
1098
1153
|
{
|
1099
1154
|
p->push_state();
|
@@ -1177,7 +1232,7 @@ namespace Reflex
|
|
1177
1232
|
Point pos = bounds.position();
|
1178
1233
|
Bounds clip2 = bounds.dup().move_by(offset) & clip;
|
1179
1234
|
|
1180
|
-
bounds.
|
1235
|
+
bounds.set_position(0, 0, bounds.z);
|
1181
1236
|
if (self->pscroll)
|
1182
1237
|
{
|
1183
1238
|
bounds.move_by(-*self->pscroll);
|
@@ -1188,9 +1243,13 @@ namespace Reflex
|
|
1188
1243
|
p->push_matrix();
|
1189
1244
|
p->translate(pos);
|
1190
1245
|
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1246
|
+
if (self->angle != 0)
|
1247
|
+
{
|
1248
|
+
const Point* pivot = self->ppivot.get();
|
1249
|
+
if (pivot) p->translate( pivot->x * bounds.width, pivot->y * bounds.height);
|
1250
|
+
p->rotate(self->angle);
|
1251
|
+
if (pivot) p->translate(-pivot->x * bounds.width, -pivot->y * bounds.height);
|
1252
|
+
}
|
1194
1253
|
|
1195
1254
|
float zoom = self->zoom;
|
1196
1255
|
if (zoom != 1 && zoom > 0)
|
@@ -1285,6 +1344,9 @@ namespace Reflex
|
|
1285
1344
|
{
|
1286
1345
|
assert(view && event);
|
1287
1346
|
|
1347
|
+
if (view->self->pbody)
|
1348
|
+
view->self->pbody->awake();
|
1349
|
+
|
1288
1350
|
view->on_pointer(event);
|
1289
1351
|
|
1290
1352
|
switch ((*event)[0].action())
|
@@ -2070,7 +2132,23 @@ namespace Reflex
|
|
2070
2132
|
return self->angle;
|
2071
2133
|
}
|
2072
2134
|
|
2073
|
-
|
2135
|
+
void
|
2136
|
+
View::set_pivot (float x, float y, float z)
|
2137
|
+
{
|
2138
|
+
self->pivot().reset(x, y, z);
|
2139
|
+
}
|
2140
|
+
|
2141
|
+
void
|
2142
|
+
View::set_pivot (const Point& pivot)
|
2143
|
+
{
|
2144
|
+
set_pivot(pivot.x, pivot.y, pivot.z);
|
2145
|
+
}
|
2146
|
+
|
2147
|
+
const Point&
|
2148
|
+
View::pivot () const
|
2149
|
+
{
|
2150
|
+
return self->ppivot ? self->pivot() : ZERO;
|
2151
|
+
}
|
2074
2152
|
|
2075
2153
|
void
|
2076
2154
|
View::scroll_to (coord x, coord y, coord z)
|
@@ -2110,10 +2188,7 @@ namespace Reflex
|
|
2110
2188
|
const Point&
|
2111
2189
|
View::scroll () const
|
2112
2190
|
{
|
2113
|
-
|
2114
|
-
return self->scroll();
|
2115
|
-
else
|
2116
|
-
return ZERO_SCROLL;
|
2191
|
+
return self->pscroll ? self->scroll() : ZERO;
|
2117
2192
|
}
|
2118
2193
|
|
2119
2194
|
void
|
data/src/window.cpp
CHANGED
@@ -176,7 +176,7 @@ namespace Reflex
|
|
176
176
|
|
177
177
|
for (auto& [view, targets] : window->self->captures)
|
178
178
|
{
|
179
|
-
if (!is_capturing(view.get(), targets, View::CAPTURE_KEY))
|
179
|
+
if (!view->window() || !is_capturing(view.get(), targets, View::CAPTURE_KEY))
|
180
180
|
continue;
|
181
181
|
|
182
182
|
KeyEvent e = event->dup();
|
@@ -256,7 +256,7 @@ namespace Reflex
|
|
256
256
|
|
257
257
|
for (auto& [view, targets] : window->self->captures)
|
258
258
|
{
|
259
|
-
if (targets.empty()) continue;
|
259
|
+
if (!view->window() || targets.empty()) continue;
|
260
260
|
|
261
261
|
PointerEvent event;
|
262
262
|
PointerEvent_set_captured(&event, true);
|
@@ -300,6 +300,8 @@ namespace Reflex
|
|
300
300
|
|
301
301
|
for (auto& view : views_capturing_all)
|
302
302
|
{
|
303
|
+
if (!view->window()) continue;
|
304
|
+
|
303
305
|
PointerEvent e = event.dup();
|
304
306
|
PointerEvent_update_for_capturing_view(&e, view);
|
305
307
|
View_call_pointer_event(const_cast<View*>(view.get()), &e);
|
data/test/helper.rb
CHANGED
data/test/test_application.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
|
4
1
|
require_relative 'helper'
|
5
2
|
|
6
3
|
|
@@ -14,4 +11,8 @@ class TestApplication < Test::Unit::TestCase
|
|
14
11
|
assert_equal 'AppName', @@app.name
|
15
12
|
end
|
16
13
|
|
14
|
+
def test_inspect()
|
15
|
+
assert_match %r|#<Reflex::Application:0x\w{16}>|, @@app.inspect
|
16
|
+
end
|
17
|
+
|
17
18
|
end# TestApplication
|
data/test/test_capture_event.rb
CHANGED
data/test/test_contact_event.rb
CHANGED
data/test/test_draw_event.rb
CHANGED
data/test/test_event.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
|
4
1
|
require_relative 'helper'
|
5
2
|
|
6
3
|
|
@@ -27,7 +24,7 @@ class TestEvent < Test::Unit::TestCase
|
|
27
24
|
assert_true e.blocked?
|
28
25
|
end
|
29
26
|
|
30
|
-
def
|
27
|
+
def _test_block_propagation()
|
31
28
|
e1 = event
|
32
29
|
e2 = e1.dup
|
33
30
|
e3 = e2.dup
|
data/test/test_focus_event.rb
CHANGED
data/test/test_frame_event.rb
CHANGED
data/test/test_has_frame.rb
CHANGED
data/test/test_key_event.rb
CHANGED
data/test/test_model.rb
CHANGED