reflexion 0.1.37 → 0.1.38
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/view.cpp +47 -5
- data/ChangeLog.md +5 -0
- data/VERSION +1 -1
- data/ext/reflex/view.cpp +48 -6
- data/lib/reflex/view.rb +0 -8
- data/lib/reflex/window.rb +34 -20
- data/src/event.cpp +4 -36
- data/src/view.cpp +78 -18
- data/test/test_view.rb +94 -11
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5cd000da9cadc8587ea27cf2ef0d55c617aedd61e00e0fa84f0575215d81060f
|
|
4
|
+
data.tar.gz: 66a9040b3b5d9233afe96b8869c981449403ddff9dd62a9a590d37f99ff14530
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e2d19b6fd82f8f0d81bb6a774d6a829bf84a92e61cb5c5305c9815d76b39118a22f513f7b776f3fd039d65c41a1bf8b3dafc4a094db64adb7cbc42e7dd517503
|
|
7
|
+
data.tar.gz: 51c91ee902178f44c5b1f100d511179e47bc023f46411255ac4e72da03db07b0db3346e9283ff0ba2e0651d0fc9348fb93d7cf6bc761e29f311d1d3cf29d3bc8
|
data/.doc/ext/reflex/view.cpp
CHANGED
|
@@ -405,10 +405,32 @@ VALUE get_angle(VALUE self)
|
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
static
|
|
408
|
-
VALUE set_pivot(VALUE self
|
|
408
|
+
VALUE set_pivot(VALUE self)
|
|
409
409
|
{
|
|
410
410
|
CHECK;
|
|
411
|
-
|
|
411
|
+
|
|
412
|
+
if (argv[0].is_kind_of(Rays::point_class()))
|
|
413
|
+
{
|
|
414
|
+
check_arg_count(__FILE__, __LINE__, "View#pivot=(Point)", argc, 1);
|
|
415
|
+
|
|
416
|
+
THIS->set_pivot(to<Rays::Point&>(argv[0]));
|
|
417
|
+
}
|
|
418
|
+
else
|
|
419
|
+
{
|
|
420
|
+
if (argv[0].is_array())
|
|
421
|
+
{
|
|
422
|
+
argc = argv[0].size();
|
|
423
|
+
argv = &argv[0][0];
|
|
424
|
+
}
|
|
425
|
+
check_arg_count(__FILE__, __LINE__, "View#pivot=(Numeric, ...)", argc, 2, 3);
|
|
426
|
+
|
|
427
|
+
const Rays::Point& p = THIS->pivot();
|
|
428
|
+
float x = to<float>(argv[0]);
|
|
429
|
+
float y = to<float>(argv[1]);
|
|
430
|
+
float z = (argc >= 3 && argv[2]) ? to<float>(argv[2]) : p.z;
|
|
431
|
+
THIS->set_pivot(x, y, z);
|
|
432
|
+
}
|
|
433
|
+
|
|
412
434
|
return value(THIS->pivot());
|
|
413
435
|
}
|
|
414
436
|
|
|
@@ -423,12 +445,22 @@ static
|
|
|
423
445
|
VALUE scroll_to(VALUE self)
|
|
424
446
|
{
|
|
425
447
|
CHECK;
|
|
426
|
-
check_arg_count(__FILE__, __LINE__, "View#scroll_to", argc, 1, 2, 3);
|
|
427
448
|
|
|
428
449
|
if (argv[0].is_kind_of(Rays::point_class()))
|
|
450
|
+
{
|
|
451
|
+
check_arg_count(__FILE__, __LINE__, "View#scroll_to(Point)", argc, 1);
|
|
452
|
+
|
|
429
453
|
THIS->scroll_to(to<Rays::Point&>(argv[0]));
|
|
454
|
+
}
|
|
430
455
|
else
|
|
431
456
|
{
|
|
457
|
+
if (argv[0].is_array())
|
|
458
|
+
{
|
|
459
|
+
argc = argv[0].size();
|
|
460
|
+
argv = &argv[0][0];
|
|
461
|
+
}
|
|
462
|
+
check_arg_count(__FILE__, __LINE__, "View#scroll_to(Numeric, ...)", argc, 2, 3);
|
|
463
|
+
|
|
432
464
|
const Rays::Point& p = THIS->scroll();
|
|
433
465
|
coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
|
|
434
466
|
coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
|
|
@@ -443,12 +475,22 @@ static
|
|
|
443
475
|
VALUE scroll_by(VALUE self)
|
|
444
476
|
{
|
|
445
477
|
CHECK;
|
|
446
|
-
check_arg_count(__FILE__, __LINE__, "View#scroll_by", argc, 1, 2, 3);
|
|
447
478
|
|
|
448
479
|
if (argv[0].is_kind_of(Rays::point_class()))
|
|
480
|
+
{
|
|
481
|
+
check_arg_count(__FILE__, __LINE__, "View#scroll_by", argc, 1);
|
|
482
|
+
|
|
449
483
|
THIS->scroll_by(to<Rays::Point&>(argv[0]));
|
|
484
|
+
}
|
|
450
485
|
else
|
|
451
486
|
{
|
|
487
|
+
if (argv[0].is_array())
|
|
488
|
+
{
|
|
489
|
+
argc = argv[0].size();
|
|
490
|
+
argv = &argv[0][0];
|
|
491
|
+
}
|
|
492
|
+
check_arg_count(__FILE__, __LINE__, "View#scroll_by(Numeric, ...)", argc, 2, 3);
|
|
493
|
+
|
|
452
494
|
coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
|
|
453
495
|
coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
|
|
454
496
|
coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
|
|
@@ -1075,7 +1117,7 @@ Init_reflex_view ()
|
|
|
1075
1117
|
rb_define_method(cView, "fit_to_content", RUBY_METHOD_FUNC(fit_to_content), 0);
|
|
1076
1118
|
rb_define_method(cView, "angle=", RUBY_METHOD_FUNC(set_angle), 1);
|
|
1077
1119
|
rb_define_method(cView, "angle", RUBY_METHOD_FUNC(get_angle), 0);
|
|
1078
|
-
cView
|
|
1120
|
+
rb_define_method(cView, "pivot=", RUBY_METHOD_FUNC(set_pivot), -1);
|
|
1079
1121
|
rb_define_method(cView, "pivot", RUBY_METHOD_FUNC(get_pivot), 0);
|
|
1080
1122
|
rb_define_method(cView, "scroll_to", RUBY_METHOD_FUNC(scroll_to), -1);
|
|
1081
1123
|
rb_define_method(cView, "scroll_by", RUBY_METHOD_FUNC(scroll_by), -1);
|
data/ChangeLog.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# reflex ChangeLog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## [v0.1.38] - 2023-05-13
|
|
5
|
+
|
|
6
|
+
- View: Reimplemented from_parent(), to_parent(), from_window(), to_window(), from_screen(), and to_screen() to account for rotation, zoom, and scrolling during coordinate transformation
|
|
7
|
+
|
|
8
|
+
|
|
4
9
|
## [v0.1.37] - 2023-05-11
|
|
5
10
|
|
|
6
11
|
- Update dependencies
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.38
|
data/ext/reflex/view.cpp
CHANGED
|
@@ -446,10 +446,32 @@ RUCY_DEF0(get_angle)
|
|
|
446
446
|
RUCY_END
|
|
447
447
|
|
|
448
448
|
static
|
|
449
|
-
|
|
449
|
+
RUCY_DEFN(set_pivot)
|
|
450
450
|
{
|
|
451
451
|
CHECK;
|
|
452
|
-
|
|
452
|
+
|
|
453
|
+
if (argv[0].is_kind_of(Rays::point_class()))
|
|
454
|
+
{
|
|
455
|
+
check_arg_count(__FILE__, __LINE__, "View#pivot=(Point)", argc, 1);
|
|
456
|
+
|
|
457
|
+
THIS->set_pivot(to<Rays::Point&>(argv[0]));
|
|
458
|
+
}
|
|
459
|
+
else
|
|
460
|
+
{
|
|
461
|
+
if (argv[0].is_array())
|
|
462
|
+
{
|
|
463
|
+
argc = argv[0].size();
|
|
464
|
+
argv = &argv[0][0];
|
|
465
|
+
}
|
|
466
|
+
check_arg_count(__FILE__, __LINE__, "View#pivot=(Numeric, ...)", argc, 2, 3);
|
|
467
|
+
|
|
468
|
+
const Rays::Point& p = THIS->pivot();
|
|
469
|
+
float x = to<float>(argv[0]);
|
|
470
|
+
float y = to<float>(argv[1]);
|
|
471
|
+
float z = (argc >= 3 && argv[2]) ? to<float>(argv[2]) : p.z;
|
|
472
|
+
THIS->set_pivot(x, y, z);
|
|
473
|
+
}
|
|
474
|
+
|
|
453
475
|
return value(THIS->pivot());
|
|
454
476
|
}
|
|
455
477
|
RUCY_END
|
|
@@ -466,12 +488,22 @@ static
|
|
|
466
488
|
RUCY_DEFN(scroll_to)
|
|
467
489
|
{
|
|
468
490
|
CHECK;
|
|
469
|
-
check_arg_count(__FILE__, __LINE__, "View#scroll_to", argc, 1, 2, 3);
|
|
470
491
|
|
|
471
492
|
if (argv[0].is_kind_of(Rays::point_class()))
|
|
493
|
+
{
|
|
494
|
+
check_arg_count(__FILE__, __LINE__, "View#scroll_to(Point)", argc, 1);
|
|
495
|
+
|
|
472
496
|
THIS->scroll_to(to<Rays::Point&>(argv[0]));
|
|
497
|
+
}
|
|
473
498
|
else
|
|
474
499
|
{
|
|
500
|
+
if (argv[0].is_array())
|
|
501
|
+
{
|
|
502
|
+
argc = argv[0].size();
|
|
503
|
+
argv = &argv[0][0];
|
|
504
|
+
}
|
|
505
|
+
check_arg_count(__FILE__, __LINE__, "View#scroll_to(Numeric, ...)", argc, 2, 3);
|
|
506
|
+
|
|
475
507
|
const Rays::Point& p = THIS->scroll();
|
|
476
508
|
coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : p.x;
|
|
477
509
|
coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : p.y;
|
|
@@ -487,12 +519,22 @@ static
|
|
|
487
519
|
RUCY_DEFN(scroll_by)
|
|
488
520
|
{
|
|
489
521
|
CHECK;
|
|
490
|
-
check_arg_count(__FILE__, __LINE__, "View#scroll_by", argc, 1, 2, 3);
|
|
491
522
|
|
|
492
523
|
if (argv[0].is_kind_of(Rays::point_class()))
|
|
524
|
+
{
|
|
525
|
+
check_arg_count(__FILE__, __LINE__, "View#scroll_by", argc, 1);
|
|
526
|
+
|
|
493
527
|
THIS->scroll_by(to<Rays::Point&>(argv[0]));
|
|
528
|
+
}
|
|
494
529
|
else
|
|
495
530
|
{
|
|
531
|
+
if (argv[0].is_array())
|
|
532
|
+
{
|
|
533
|
+
argc = argv[0].size();
|
|
534
|
+
argv = &argv[0][0];
|
|
535
|
+
}
|
|
536
|
+
check_arg_count(__FILE__, __LINE__, "View#scroll_by(Numeric, ...)", argc, 2, 3);
|
|
537
|
+
|
|
496
538
|
coord x = (argc >= 1 && argv[0]) ? to<coord>(argv[0]) : 0;
|
|
497
539
|
coord y = (argc >= 2 && argv[1]) ? to<coord>(argv[1]) : 0;
|
|
498
540
|
coord z = (argc >= 3 && argv[2]) ? to<coord>(argv[2]) : 0;
|
|
@@ -1193,8 +1235,8 @@ Init_reflex_view ()
|
|
|
1193
1235
|
cView.define_method("fit_to_content", fit_to_content);
|
|
1194
1236
|
cView.define_method("angle=", set_angle);
|
|
1195
1237
|
cView.define_method("angle", get_angle);
|
|
1196
|
-
cView.
|
|
1197
|
-
cView.define_method(
|
|
1238
|
+
cView.define_method("pivot=", set_pivot);
|
|
1239
|
+
cView.define_method("pivot", get_pivot);
|
|
1198
1240
|
cView.define_method("scroll_to", scroll_to);
|
|
1199
1241
|
cView.define_method("scroll_by", scroll_by);
|
|
1200
1242
|
cView.define_method("scroll", get_scroll);
|
data/lib/reflex/view.rb
CHANGED
|
@@ -97,14 +97,6 @@ module Reflex
|
|
|
97
97
|
to_enum :each_shape
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
-
def pivot=(arg)
|
|
101
|
-
case arg
|
|
102
|
-
when Point then set_pivot! arg.x, arg.y, arg.z
|
|
103
|
-
when Array then set_pivot! arg[0], arg[1], arg[2] || 0
|
|
104
|
-
else raise ArgumentError
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
100
|
def capturing?(*args)
|
|
109
101
|
cap = capture
|
|
110
102
|
args.all? {|type| cap.include? type}
|
data/lib/reflex/window.rb
CHANGED
|
@@ -20,28 +20,42 @@ module Reflex
|
|
|
20
20
|
extend Forwardable
|
|
21
21
|
|
|
22
22
|
def_delegators :root,
|
|
23
|
+
:add_child, :add,
|
|
24
|
+
:remove_child, :remove,
|
|
25
|
+
:children, :find_children, :find_child, :find,
|
|
26
|
+
:scroll_to, :scroll_by, :scroll,
|
|
27
|
+
:style, :styles,
|
|
23
28
|
:timeout, :delay, :interval,
|
|
24
|
-
:add_child, :add,
|
|
25
|
-
:remove_child, :remove,
|
|
26
|
-
:children, :find_child, :find, :find_children,
|
|
27
|
-
:style, :styles, :scroll_to, :scroll_by, :scroll,
|
|
28
29
|
:meter2pixel, :meter, :wall,
|
|
29
|
-
:zoom=,
|
|
30
|
-
:clip=,
|
|
31
|
-
:cache=,
|
|
32
|
-
:
|
|
33
|
-
:
|
|
34
|
-
:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
:
|
|
38
|
-
:
|
|
39
|
-
:
|
|
40
|
-
:
|
|
41
|
-
:
|
|
42
|
-
:
|
|
43
|
-
:
|
|
44
|
-
:
|
|
30
|
+
:zoom=, :zoom,
|
|
31
|
+
:clip=, :clip, :clip?,
|
|
32
|
+
:cache=, :cache, :cache?,
|
|
33
|
+
:gravity=, :gravity,
|
|
34
|
+
:time_scale=, :time_scale,
|
|
35
|
+
:debug=, :debug, :debug?
|
|
36
|
+
|
|
37
|
+
def_delegators :style,
|
|
38
|
+
:flow=, :flow,
|
|
39
|
+
:foreground_fill=, :foreground_fill,
|
|
40
|
+
:foreground_stroke=, :foreground_stroke,
|
|
41
|
+
:foreground_stroke_width=, :foreground_stroke_width,
|
|
42
|
+
:background_fill=, :background_fill,
|
|
43
|
+
:background_stroke=, :background_stroke,
|
|
44
|
+
:background_stroke_width=, :background_stroke_width,
|
|
45
|
+
:foreground=, :foreground,
|
|
46
|
+
:background=, :background,
|
|
47
|
+
:fore_fill=, :fore_fill,
|
|
48
|
+
:fore_stroke=, :fore_stroke,
|
|
49
|
+
:fore_stroke_width=, :fore_stroke_width,
|
|
50
|
+
:back_fill=, :back_fill,
|
|
51
|
+
:back_stroke=, :back_stroke,
|
|
52
|
+
:back_stroke_width=, :back_stroke_width,
|
|
53
|
+
:fore=, :fore,
|
|
54
|
+
:back=, :back,
|
|
55
|
+
:fill=, :fill,
|
|
56
|
+
:stroke=, :stroke,
|
|
57
|
+
:stroke_width=, :stroke_width,
|
|
58
|
+
:image=, :image
|
|
45
59
|
|
|
46
60
|
def_delegators :wall,
|
|
47
61
|
:friction=, :friction,
|
data/src/event.cpp
CHANGED
|
@@ -634,38 +634,14 @@ namespace Reflex
|
|
|
634
634
|
pthis->self->captured = captured;
|
|
635
635
|
}
|
|
636
636
|
|
|
637
|
-
static void
|
|
638
|
-
scroll_and_zoom_pointer_positions (
|
|
639
|
-
PointerEvent* event, const Point& scroll, float zoom)
|
|
640
|
-
{
|
|
641
|
-
assert(event);
|
|
642
|
-
|
|
643
|
-
if (zoom == 0)
|
|
644
|
-
argument_error(__FILE__, __LINE__);
|
|
645
|
-
|
|
646
|
-
if (scroll == 0 && zoom == 1)
|
|
647
|
-
return;
|
|
648
|
-
|
|
649
|
-
for (auto& pointer : event->self->pointers)
|
|
650
|
-
{
|
|
651
|
-
Pointer_update_positions(&pointer, [=](Point* pos)
|
|
652
|
-
{
|
|
653
|
-
*pos -= scroll;
|
|
654
|
-
*pos /= zoom;
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
|
|
659
637
|
void
|
|
660
|
-
PointerEvent_update_for_child_view (PointerEvent* pthis, const View*
|
|
638
|
+
PointerEvent_update_for_child_view (PointerEvent* pthis, const View* child)
|
|
661
639
|
{
|
|
662
|
-
if (!pthis || !
|
|
640
|
+
if (!pthis || !child)
|
|
663
641
|
argument_error(__FILE__, __LINE__);
|
|
664
642
|
|
|
665
|
-
const Bounds& frame =
|
|
666
|
-
const Point& offset = frame.position();
|
|
643
|
+
const Bounds& frame = child->frame();
|
|
667
644
|
Bounds bounds = frame.dup().move_to(0, 0);
|
|
668
|
-
float angle = view->angle();
|
|
669
645
|
|
|
670
646
|
std::vector<Pointer> pointers;
|
|
671
647
|
for (const auto& pointer : pthis->self->pointers)
|
|
@@ -673,16 +649,13 @@ namespace Reflex
|
|
|
673
649
|
pointers.emplace_back(pointer);
|
|
674
650
|
Pointer_update_positions(&pointers.back(), [&](Point* pos)
|
|
675
651
|
{
|
|
676
|
-
*pos
|
|
677
|
-
pos->rotate(-angle);
|
|
652
|
+
*pos = child->from_parent(*pos);
|
|
678
653
|
});
|
|
679
654
|
|
|
680
655
|
if (!bounds.is_include(pointers.back().position()))
|
|
681
656
|
pointers.pop_back();
|
|
682
657
|
}
|
|
683
658
|
pthis->self->pointers = pointers;
|
|
684
|
-
|
|
685
|
-
scroll_and_zoom_pointer_positions(pthis, view->scroll(), view->zoom());
|
|
686
659
|
}
|
|
687
660
|
|
|
688
661
|
void
|
|
@@ -691,18 +664,13 @@ namespace Reflex
|
|
|
691
664
|
if (!pthis || !view)
|
|
692
665
|
argument_error(__FILE__, __LINE__);
|
|
693
666
|
|
|
694
|
-
float angle = view->angle();
|
|
695
|
-
|
|
696
667
|
for (auto& pointer : pthis->self->pointers)
|
|
697
668
|
{
|
|
698
669
|
Pointer_update_positions(&pointer, [=](Point* pos)
|
|
699
670
|
{
|
|
700
671
|
*pos = view->from_window(*pos);
|
|
701
|
-
pos->rotate(-angle);
|
|
702
672
|
});
|
|
703
673
|
}
|
|
704
|
-
|
|
705
|
-
scroll_and_zoom_pointer_positions(pthis, view->scroll(), view->zoom());
|
|
706
674
|
}
|
|
707
675
|
|
|
708
676
|
|
data/src/view.cpp
CHANGED
|
@@ -105,12 +105,22 @@ namespace Reflex
|
|
|
105
105
|
return *ppivot;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
bool has_pivot () const
|
|
109
|
+
{
|
|
110
|
+
return ppivot && *ppivot != ZERO;
|
|
111
|
+
}
|
|
112
|
+
|
|
108
113
|
Point& scroll ()
|
|
109
114
|
{
|
|
110
115
|
if (!pscroll) pscroll.reset(new Point);
|
|
111
116
|
return *pscroll;
|
|
112
117
|
}
|
|
113
118
|
|
|
119
|
+
bool has_scroll () const
|
|
120
|
+
{
|
|
121
|
+
return pscroll && *pscroll != ZERO;
|
|
122
|
+
}
|
|
123
|
+
|
|
114
124
|
Selector& selector ()
|
|
115
125
|
{
|
|
116
126
|
if (!pselector) pselector.reset(new Selector);
|
|
@@ -1246,9 +1256,9 @@ namespace Reflex
|
|
|
1246
1256
|
if (self->angle != 0)
|
|
1247
1257
|
{
|
|
1248
1258
|
const Point* pivot = self->ppivot.get();
|
|
1249
|
-
if (pivot) p->translate( pivot->x * bounds.
|
|
1259
|
+
if (pivot) p->translate( pivot->x * bounds.w, pivot->y * bounds.h);
|
|
1250
1260
|
p->rotate(self->angle);
|
|
1251
|
-
if (pivot) p->translate(-pivot->x * bounds.
|
|
1261
|
+
if (pivot) p->translate(-pivot->x * bounds.w, -pivot->y * bounds.h);
|
|
1252
1262
|
}
|
|
1253
1263
|
|
|
1254
1264
|
float zoom = self->zoom;
|
|
@@ -1571,22 +1581,76 @@ namespace Reflex
|
|
|
1571
1581
|
redraw();
|
|
1572
1582
|
}
|
|
1573
1583
|
|
|
1584
|
+
static void
|
|
1585
|
+
get_from_parent_matrix (Matrix* m, const View* view)
|
|
1586
|
+
{
|
|
1587
|
+
assert(m && view);
|
|
1588
|
+
View::Data* self = view->self.get();
|
|
1589
|
+
|
|
1590
|
+
const auto& frame = self->frame;
|
|
1591
|
+
const auto* scroll = self->has_scroll() ? self->pscroll.get() : NULL;
|
|
1592
|
+
auto angle = self->angle;
|
|
1593
|
+
auto zoom = self->zoom;
|
|
1594
|
+
|
|
1595
|
+
if (zoom != 1 && zoom > 0) m->scale(1 / zoom, 1 / zoom);
|
|
1596
|
+
if (angle != 0)
|
|
1597
|
+
{
|
|
1598
|
+
const auto* pivot = self->has_pivot() ? self->ppivot.get() : NULL;
|
|
1599
|
+
if (pivot) m->translate( pivot->x * frame.w, pivot->y * frame.h);
|
|
1600
|
+
m->rotate(-angle);
|
|
1601
|
+
if (pivot) m->translate(-pivot->x * frame.w, -pivot->y * frame.h);
|
|
1602
|
+
}
|
|
1603
|
+
m->translate(-frame.position());
|
|
1604
|
+
if (scroll) m->translate(-*scroll);
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
static void
|
|
1608
|
+
get_to_parent_matrix (Matrix* m, const View* view)
|
|
1609
|
+
{
|
|
1610
|
+
assert(m && view);
|
|
1611
|
+
View::Data* self = view->self.get();
|
|
1612
|
+
|
|
1613
|
+
const auto& frame = self->frame;
|
|
1614
|
+
const auto* scroll = self->has_scroll() ? self->pscroll.get() : NULL;
|
|
1615
|
+
auto angle = self->angle;
|
|
1616
|
+
auto zoom = self->zoom;
|
|
1617
|
+
|
|
1618
|
+
if (scroll) m->translate(*scroll);
|
|
1619
|
+
m->translate(frame.position());
|
|
1620
|
+
if (angle != 0)
|
|
1621
|
+
{
|
|
1622
|
+
const auto* pivot = self->has_pivot() ? self->ppivot.get() : NULL;
|
|
1623
|
+
if (pivot) m->translate( pivot->x * frame.w, pivot->y * frame.h);
|
|
1624
|
+
m->rotate(angle);
|
|
1625
|
+
if (pivot) m->translate(-pivot->x * frame.w, -pivot->y * frame.h);
|
|
1626
|
+
}
|
|
1627
|
+
if (zoom != 1 && zoom > 0) m->scale(zoom, zoom);
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1574
1630
|
Point
|
|
1575
1631
|
View::from_parent (const Point& point) const
|
|
1576
1632
|
{
|
|
1577
|
-
if (!
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1633
|
+
if (self->zoom == 1 && self->angle == 0 && !self->has_scroll())
|
|
1634
|
+
return point - self->frame.position();
|
|
1635
|
+
else
|
|
1636
|
+
{
|
|
1637
|
+
Matrix m(1);
|
|
1638
|
+
get_from_parent_matrix(&m, this);
|
|
1639
|
+
return m * point;
|
|
1640
|
+
}
|
|
1581
1641
|
}
|
|
1582
1642
|
|
|
1583
1643
|
Point
|
|
1584
1644
|
View::to_parent (const Point& point) const
|
|
1585
1645
|
{
|
|
1586
|
-
if (!
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1646
|
+
if (self->zoom == 1 && self->angle == 0 && !self->has_scroll())
|
|
1647
|
+
return point + self->frame.position();
|
|
1648
|
+
else
|
|
1649
|
+
{
|
|
1650
|
+
Matrix m(1);
|
|
1651
|
+
get_to_parent_matrix(&m, this);
|
|
1652
|
+
return m * point;
|
|
1653
|
+
}
|
|
1590
1654
|
}
|
|
1591
1655
|
|
|
1592
1656
|
Point
|
|
@@ -1595,10 +1659,8 @@ namespace Reflex
|
|
|
1595
1659
|
if (!window())
|
|
1596
1660
|
invalid_state_error(__FILE__, __LINE__);
|
|
1597
1661
|
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
p -= v->frame().position();
|
|
1601
|
-
return p;
|
|
1662
|
+
const auto* parent = self->parent;
|
|
1663
|
+
return from_parent(parent ? parent->from_window(point) : point);
|
|
1602
1664
|
}
|
|
1603
1665
|
|
|
1604
1666
|
Point
|
|
@@ -1607,10 +1669,8 @@ namespace Reflex
|
|
|
1607
1669
|
if (!window())
|
|
1608
1670
|
invalid_state_error(__FILE__, __LINE__);
|
|
1609
1671
|
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
p += v->frame().position();
|
|
1613
|
-
return p;
|
|
1672
|
+
const auto* parent = self->parent;
|
|
1673
|
+
return parent ? parent->to_window(to_parent(point)) : to_parent(point);
|
|
1614
1674
|
}
|
|
1615
1675
|
|
|
1616
1676
|
Point
|
data/test/test_view.rb
CHANGED
|
@@ -50,8 +50,8 @@ class TestView < Test::Unit::TestCase
|
|
|
50
50
|
v1 = view x: 10, y: 20
|
|
51
51
|
v2 = view x: 1, y: 2
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
assert_nothing_raised {v2.from_parent 0}
|
|
54
|
+
assert_nothing_raised {v2. to_parent 0}
|
|
55
55
|
assert_raise(Rucy::NativeError) {v2.from_window 0}
|
|
56
56
|
assert_raise(Rucy::NativeError) {v2. to_window 0}
|
|
57
57
|
assert_raise(Rucy::NativeError) {v2.from_screen 0}
|
|
@@ -68,6 +68,22 @@ class TestView < Test::Unit::TestCase
|
|
|
68
68
|
assert_equal [611, 722], v2. to_screen(500).to_a
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
def test_complex_coord_conversion()
|
|
72
|
+
w = window(x: 100, y: 200, size: 500, zoom: 2) {scroll_to 100, 200}
|
|
73
|
+
v1 = view( x: 10, y: 20, size: 50, zoom: 3, angle: 90, pivot: [0.1, 0.2]) {scroll_to 10, 20}
|
|
74
|
+
v2 = view( x: 1, y: 2, size: 5, zoom: 4, angle: 180, pivot: [0.3, 0.4]) {scroll_to 1, 2}
|
|
75
|
+
|
|
76
|
+
w .add v1
|
|
77
|
+
v1.add v2
|
|
78
|
+
|
|
79
|
+
assert_each_in_epsilon [1, 1.75], v2.from_parent(1) .to_a
|
|
80
|
+
assert_each_in_epsilon [1, 4], v2. to_parent(1) .to_a
|
|
81
|
+
assert_each_in_epsilon [4.583, -0.5], v2.from_window(10) .to_a
|
|
82
|
+
assert_each_in_epsilon [262, -120], v2. to_window(10) .to_a
|
|
83
|
+
assert_each_in_epsilon [-99.1666, -196.75], v2.from_screen(100).to_a
|
|
84
|
+
assert_each_in_epsilon [2522, -2080], v2. to_screen(100).to_a
|
|
85
|
+
end
|
|
86
|
+
|
|
71
87
|
def test_add_child()
|
|
72
88
|
assert_raise(ArgumentError) {view.add_child}
|
|
73
89
|
assert_raise(TypeError) {view.add_child nil}
|
|
@@ -261,19 +277,86 @@ class TestView < Test::Unit::TestCase
|
|
|
261
277
|
|
|
262
278
|
def test_pivot()
|
|
263
279
|
v = view
|
|
264
|
-
|
|
280
|
+
assert_each_in_epsilon [0, 0, 0], v.pivot.to_a(3)
|
|
281
|
+
|
|
282
|
+
v.pivot = point 0.1, 0.2
|
|
283
|
+
assert_each_in_epsilon [0.1, 0.2, 0], v.pivot.to_a(3)
|
|
284
|
+
|
|
285
|
+
v.pivot = point 0.3, 0.4, 0.5
|
|
286
|
+
assert_each_in_epsilon [0.3, 0.4, 0.5], v.pivot.to_a(3)
|
|
287
|
+
|
|
288
|
+
v.pivot = [0.6, 0.7]
|
|
289
|
+
assert_each_in_epsilon [0.6, 0.7, 0.5], v.pivot.to_a(3)
|
|
290
|
+
|
|
291
|
+
v.pivot = [0.8, 0.9, 1.0]
|
|
292
|
+
assert_each_in_epsilon [0.8, 0.9, 1.0], v.pivot.to_a(3)
|
|
293
|
+
|
|
294
|
+
v.pivot 1.1, 1.2
|
|
295
|
+
assert_each_in_epsilon [1.1, 1.2, 1.0], v.pivot.to_a(3)
|
|
296
|
+
|
|
297
|
+
v.pivot 1.3, 1.4, 1.5
|
|
298
|
+
assert_each_in_epsilon [1.3, 1.4, 1.5], v.pivot.to_a(3)
|
|
299
|
+
|
|
300
|
+
v.pivot( -1.6, -1.7, -1.8)
|
|
301
|
+
assert_each_in_epsilon [-1.6, -1.7, -1.8], v.pivot.to_a(3)
|
|
302
|
+
|
|
303
|
+
assert_raise(ArgumentError) {v.pivot 2.0}
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
def test_scroll_to()
|
|
307
|
+
v = view
|
|
308
|
+
assert_each_in_epsilon [0, 0, 0], v.scroll.to_a(3)
|
|
309
|
+
|
|
310
|
+
v.scroll_to point(1, 2)
|
|
311
|
+
assert_each_in_epsilon [1, 2, 0], v.scroll.to_a(3)
|
|
312
|
+
|
|
313
|
+
v.scroll_to point(3, 4, 5)
|
|
314
|
+
assert_each_in_epsilon [3, 4, 5], v.scroll.to_a(3)
|
|
315
|
+
|
|
316
|
+
v.scroll_to [6, 7]
|
|
317
|
+
assert_each_in_epsilon [6, 7, 5], v.scroll.to_a(3)
|
|
318
|
+
|
|
319
|
+
v.scroll_to [8, 9, 10]
|
|
320
|
+
assert_each_in_epsilon [8, 9, 10], v.scroll.to_a(3)
|
|
321
|
+
|
|
322
|
+
v.scroll_to 11, 12
|
|
323
|
+
assert_each_in_epsilon [11, 12, 10], v.scroll.to_a(3)
|
|
324
|
+
|
|
325
|
+
v.scroll_to 13, 14, 15
|
|
326
|
+
assert_each_in_epsilon [13, 14, 15], v.scroll.to_a(3)
|
|
327
|
+
|
|
328
|
+
v.scroll_to( -16, -17, -18)
|
|
329
|
+
assert_each_in_epsilon [-16, -17, -18], v.scroll.to_a(3)
|
|
330
|
+
|
|
331
|
+
assert_raise(ArgumentError) {v.scroll_to 100}
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
def test_scroll_by()
|
|
335
|
+
v = view
|
|
336
|
+
assert_each_in_epsilon [0, 0, 0], v.scroll.to_a(3)
|
|
337
|
+
|
|
338
|
+
v.scroll_by point(1, 2)
|
|
339
|
+
assert_each_in_epsilon [1, 2, 0], v.scroll.to_a(3)
|
|
340
|
+
|
|
341
|
+
v.scroll_by point(3, 4, 5)
|
|
342
|
+
assert_each_in_epsilon [4, 6, 5], v.scroll.to_a(3)
|
|
343
|
+
|
|
344
|
+
v.scroll_by [6, 7]
|
|
345
|
+
assert_each_in_epsilon [10, 13, 5], v.scroll.to_a(3)
|
|
346
|
+
|
|
347
|
+
v.scroll_by [8, 9, 10]
|
|
348
|
+
assert_each_in_epsilon [18, 22, 15], v.scroll.to_a(3)
|
|
265
349
|
|
|
266
|
-
v.
|
|
267
|
-
|
|
350
|
+
v.scroll_by 11, 12
|
|
351
|
+
assert_each_in_epsilon [29, 34, 15], v.scroll.to_a(3)
|
|
268
352
|
|
|
269
|
-
v.
|
|
270
|
-
|
|
353
|
+
v.scroll_by 13, 14, 15
|
|
354
|
+
assert_each_in_epsilon [42, 48, 30], v.scroll.to_a(3)
|
|
271
355
|
|
|
272
|
-
v.
|
|
273
|
-
|
|
356
|
+
v.scroll_by( -16, -17, -18)
|
|
357
|
+
assert_each_in_epsilon [ 26, 31, 12], v.scroll.to_a(3)
|
|
274
358
|
|
|
275
|
-
v.
|
|
276
|
-
assert_equal point(0.9, 1.0), v.pivot
|
|
359
|
+
assert_raise(ArgumentError) {v.scroll_by 100}
|
|
277
360
|
end
|
|
278
361
|
|
|
279
362
|
def test_parent()
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: reflexion
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.38
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- xordog
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-05-
|
|
11
|
+
date: 2023-05-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: xot
|