reflexion 0.1.22 → 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/reflex/event.cpp +9 -1
  3. data/.doc/ext/reflex/key_event.cpp +3 -3
  4. data/.doc/ext/reflex/native.cpp +2 -0
  5. data/.doc/ext/reflex/pointer.cpp +158 -0
  6. data/.doc/ext/reflex/pointer_event.cpp +29 -88
  7. data/.doc/ext/reflex/selector.cpp +8 -0
  8. data/.doc/ext/reflex/view.cpp +57 -0
  9. data/.doc/ext/reflex/window.cpp +24 -0
  10. data/VERSION +1 -1
  11. data/ext/reflex/event.cpp +11 -2
  12. data/ext/reflex/key_event.cpp +3 -3
  13. data/ext/reflex/native.cpp +2 -0
  14. data/ext/reflex/pointer.cpp +170 -0
  15. data/ext/reflex/pointer_event.cpp +29 -94
  16. data/ext/reflex/selector.cpp +9 -0
  17. data/ext/reflex/view.cpp +67 -3
  18. data/ext/reflex/window.cpp +30 -3
  19. data/include/reflex/defs.h +0 -18
  20. data/include/reflex/event.h +26 -27
  21. data/include/reflex/pointer.h +107 -0
  22. data/include/reflex/ruby/pointer.h +41 -0
  23. data/include/reflex/ruby/view.h +9 -0
  24. data/include/reflex/ruby/window.h +9 -0
  25. data/include/reflex/selector.h +1 -1
  26. data/include/reflex/view.h +6 -4
  27. data/include/reflex/window.h +10 -8
  28. data/lib/reflex/key_event.rb +1 -1
  29. data/lib/reflex/pointer.rb +107 -0
  30. data/lib/reflex/pointer_event.rb +16 -54
  31. data/lib/reflex.rb +1 -0
  32. data/reflex.gemspec +5 -5
  33. data/src/event.cpp +189 -37
  34. data/src/event.h +32 -0
  35. data/src/ios/event.h +15 -3
  36. data/src/ios/event.mm +126 -11
  37. data/src/ios/view_controller.mm +49 -21
  38. data/src/osx/event.h +6 -3
  39. data/src/osx/event.mm +40 -22
  40. data/src/osx/native_window.mm +79 -16
  41. data/src/pointer.cpp +203 -0
  42. data/src/pointer.h +26 -0
  43. data/src/selector.cpp +1 -1
  44. data/src/view.cpp +83 -72
  45. data/src/view.h +0 -4
  46. data/src/window.cpp +321 -97
  47. data/src/window.h +22 -3
  48. data/test/test_event.rb +16 -2
  49. data/test/test_pointer.rb +149 -0
  50. data/test/test_pointer_event.rb +70 -104
  51. data/test/test_selector.rb +7 -0
  52. data/test/test_view.rb +38 -11
  53. data/test/test_window.rb +27 -25
  54. metadata +46 -35
@@ -0,0 +1,107 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_POINTER_H__
4
+ #define __REFLEX_POINTER_H__
5
+
6
+
7
+ #include <xot/pimpl.h>
8
+ #include <xot/util.h>
9
+ #include <rays/point.h>
10
+ #include <reflex/defs.h>
11
+
12
+
13
+ namespace Reflex
14
+ {
15
+
16
+
17
+ class Pointer
18
+ {
19
+
20
+ typedef Pointer This;
21
+
22
+ public:
23
+
24
+ typedef int ID;
25
+
26
+ enum Type
27
+ {
28
+
29
+ TYPE_NONE = 0,
30
+
31
+ MOUSE = Xot::bit(0),
32
+
33
+ MOUSE_LEFT = Xot::bit(1),
34
+
35
+ MOUSE_RIGHT = Xot::bit(2),
36
+
37
+ MOUSE_MIDDLE = Xot::bit(3),
38
+
39
+ TOUCH = Xot::bit(4),
40
+
41
+ PEN = Xot::bit(5),
42
+
43
+ };// Type
44
+
45
+ enum Action
46
+ {
47
+
48
+ ACTION_NONE = 0,
49
+
50
+ DOWN,
51
+
52
+ UP,
53
+
54
+ MOVE,
55
+
56
+ CANCEL,
57
+
58
+ STAY
59
+
60
+ };// Action
61
+
62
+ Pointer ();
63
+
64
+ Pointer (
65
+ ID id, uint type, Action action,
66
+ const Point& position, uint modifiers, uint click_count, bool drag,
67
+ double time);
68
+
69
+ Pointer (const This& obj);
70
+
71
+ Pointer& operator = (const This& obj);
72
+
73
+ ~Pointer ();
74
+
75
+ ID id () const;
76
+
77
+ uint type () const;
78
+
79
+ Action action () const;
80
+
81
+ const Point& position () const;
82
+
83
+ uint modifiers () const;
84
+
85
+ uint click_count () const;
86
+
87
+ bool is_drag () const;
88
+
89
+ double time () const;
90
+
91
+ const Pointer* prev () const;
92
+
93
+ operator bool () const;
94
+
95
+ bool operator ! () const;
96
+
97
+ struct Data;
98
+
99
+ Xot::PImpl<Data> self;
100
+
101
+ };// Pointer
102
+
103
+
104
+ }// Reflex
105
+
106
+
107
+ #endif//EOH
@@ -0,0 +1,41 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_RUBY_POINTER_H__
4
+ #define __REFLEX_RUBY_POINTER_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rucy/extension.h>
10
+ #include <reflex/pointer.h>
11
+
12
+
13
+ namespace Reflex
14
+ {
15
+
16
+
17
+ Rucy::Class pointer_class ();
18
+ // class Reflex::Pointer
19
+
20
+
21
+ }// Reflex
22
+
23
+
24
+ RUCY_DECLARE_VALUE_FROM_TO(Reflex::Pointer)
25
+
26
+
27
+ namespace Rucy
28
+ {
29
+
30
+
31
+ template <> inline Class
32
+ get_ruby_class<Reflex::Pointer> ()
33
+ {
34
+ return Reflex::pointer_class();
35
+ }
36
+
37
+
38
+ }// Rucy
39
+
40
+
41
+ #endif//EOH
@@ -201,6 +201,15 @@ namespace Reflex
201
201
  Super::on_pointer_move(e);
202
202
  }
203
203
 
204
+ virtual void on_pointer_cancel (PointerEvent* e)
205
+ {
206
+ RUCY_SYM(on_pointer_cancel);
207
+ if (this->is_overridable())
208
+ this->value.call(on_pointer_cancel, Rucy::value(e));
209
+ else
210
+ Super::on_pointer_cancel(e);
211
+ }
212
+
204
213
  virtual void on_wheel (WheelEvent* e)
205
214
  {
206
215
  RUCY_SYM(on_wheel);
@@ -153,6 +153,15 @@ namespace Reflex
153
153
  Super::on_pointer_move(e);
154
154
  }
155
155
 
156
+ virtual void on_pointer_cancel (PointerEvent* e)
157
+ {
158
+ RUCY_SYM(on_pointer_cancel);
159
+ if (this->is_overridable())
160
+ this->value.call(on_pointer_cancel, Rucy::value(e));
161
+ else
162
+ Super::on_pointer_cancel(e);
163
+ }
164
+
156
165
  virtual void on_wheel (WheelEvent* e)
157
166
  {
158
167
  RUCY_SYM(on_wheel);
@@ -55,7 +55,7 @@ namespace Reflex
55
55
 
56
56
  const_iterator end () const;
57
57
 
58
- bool is_empty () const;
58
+ bool empty () const;
59
59
 
60
60
  friend bool operator == (const This& lhs, const This& rhs);
61
61
 
@@ -364,13 +364,15 @@ namespace Reflex
364
364
 
365
365
  virtual void on_key_up (KeyEvent* e);
366
366
 
367
- virtual void on_pointer (PointerEvent* e);
367
+ virtual void on_pointer (PointerEvent* e);
368
368
 
369
- virtual void on_pointer_down (PointerEvent* e);
369
+ virtual void on_pointer_down (PointerEvent* e);
370
370
 
371
- virtual void on_pointer_up (PointerEvent* e);
371
+ virtual void on_pointer_up (PointerEvent* e);
372
372
 
373
- virtual void on_pointer_move (PointerEvent* e);
373
+ virtual void on_pointer_move (PointerEvent* e);
374
+
375
+ virtual void on_pointer_cancel (PointerEvent* e);
374
376
 
375
377
  virtual void on_wheel (WheelEvent* e);
376
378
 
@@ -39,6 +39,10 @@ namespace Reflex
39
39
 
40
40
  virtual void redraw ();
41
41
 
42
+ virtual Point from_screen (const Point& point) const;
43
+
44
+ virtual Point to_screen (const Point& point) const;
45
+
42
46
  virtual void set_title (const char* title);
43
47
 
44
48
  virtual const char* title () const;
@@ -67,10 +71,6 @@ namespace Reflex
67
71
 
68
72
  virtual const Painter* painter () const;
69
73
 
70
- virtual Point from_screen (const Point& point) const;
71
-
72
- virtual Point to_screen (const Point& point) const;
73
-
74
74
  virtual void on_show (Event* e);
75
75
 
76
76
  virtual void on_hide (Event* e);
@@ -91,13 +91,15 @@ namespace Reflex
91
91
 
92
92
  virtual void on_key_up (KeyEvent* e);
93
93
 
94
- virtual void on_pointer (PointerEvent* e);
94
+ virtual void on_pointer (PointerEvent* e);
95
+
96
+ virtual void on_pointer_down (PointerEvent* e);
95
97
 
96
- virtual void on_pointer_down (PointerEvent* e);
98
+ virtual void on_pointer_up (PointerEvent* e);
97
99
 
98
- virtual void on_pointer_up (PointerEvent* e);
100
+ virtual void on_pointer_move (PointerEvent* e);
99
101
 
100
- virtual void on_pointer_move (PointerEvent* e);
102
+ virtual void on_pointer_cancel (PointerEvent* e);
101
103
 
102
104
  virtual void on_wheel (WheelEvent* e);
103
105
 
@@ -31,7 +31,7 @@ module Reflex
31
31
  end
32
32
 
33
33
  def inspect()
34
- "#<Reflex::KeyEvent type:#{type} chars:'#{chars}' code:#{code} mod:#{modifiers} repeat:#{repeat} capture?:#{capture?}>"
34
+ "#<Reflex::KeyEvent type:#{type} chars:'#{chars}' code:#{code} mod:#{modifiers} repeat:#{repeat} captured?:#{captured?}>"
35
35
  end
36
36
 
37
37
  end# KeyEvent
@@ -0,0 +1,107 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'xot/bit_flag_accessor'
5
+ require 'xot/const_symbol_accessor'
6
+ require 'reflex/ext'
7
+
8
+
9
+ module Reflex
10
+
11
+
12
+ class Pointer
13
+
14
+ include Comparable
15
+
16
+ alias type get_type
17
+ alias action get_action
18
+
19
+ bit_flag_reader :type, **{
20
+ none: TYPE_NONE,
21
+ mouse: MOUSE,
22
+ mouse_left: MOUSE_LEFT,
23
+ mouse_right: MOUSE_RIGHT,
24
+ mouse_middle: MOUSE_MIDDLE,
25
+ touch: TOUCH,
26
+ pen: PEN
27
+ }
28
+
29
+ const_symbol_reader :action, **{
30
+ none: ACTION_NONE,
31
+ down: DOWN,
32
+ up: UP,
33
+ move: MOVE,
34
+ cancel: CANCEL,
35
+ stay: STAY
36
+ }
37
+
38
+ def mouse?()
39
+ (get_type & MOUSE) != 0
40
+ end
41
+
42
+ def mouse_left?()
43
+ (get_type & MOUSE_LEFT) != 0
44
+ end
45
+
46
+ def mouse_right?()
47
+ (get_type & MOUSE_RIGHT) != 0
48
+ end
49
+
50
+ def mouse_middle?()
51
+ (get_type & MOUSE_MIDDLE) != 0
52
+ end
53
+
54
+ alias left? mouse_left?
55
+ alias right? mouse_right?
56
+ alias middle? mouse_middle?
57
+
58
+ def touch?()
59
+ (get_type & TOUCH) != 0
60
+ end
61
+
62
+ def pen?()
63
+ (get_type & PEN) != 0
64
+ end
65
+
66
+ def down?()
67
+ get_action == DOWN
68
+ end
69
+
70
+ def up?()
71
+ get_action == UP
72
+ end
73
+
74
+ def move?()
75
+ get_action == MOVE
76
+ end
77
+
78
+ def cancel?()
79
+ get_action == CANCEL
80
+ end
81
+
82
+ def stay?()
83
+ get_action == STAY
84
+ end
85
+
86
+ alias pos position
87
+
88
+ def x()
89
+ position.x
90
+ end
91
+
92
+ def y()
93
+ position.y
94
+ end
95
+
96
+ def <=>(o)
97
+ inspect <=> o.inspect
98
+ end
99
+
100
+ def inspect()
101
+ "#<Reflex::Pointer id:#{id} #{type} #{action} (#{x.round 2}, #{y.round 2}) mod:#{modifiers} click:#{click_count} drag:#{drag?} time:#{time.round 2}>"
102
+ end
103
+
104
+ end# Pointer
105
+
106
+
107
+ end# Reflex
@@ -1,8 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- require 'xot/bit_flag_accessor'
5
- require 'xot/const_symbol_accessor'
4
+ require 'forwardable'
6
5
  require 'reflex/ext'
7
6
 
8
7
 
@@ -11,65 +10,28 @@ module Reflex
11
10
 
12
11
  class PointerEvent < Event
13
12
 
14
- alias pos position
13
+ extend Forwardable
15
14
 
16
- alias get_type type
17
- alias get_pointer_type pointer_type
15
+ def_delegators :first,
16
+ :id,
17
+ :type, :mouse?, :touch?, :pen?,
18
+ :mouse_left?, :left?, :mouse_right?, :right?, :mouse_middle?, :middle?,
19
+ :action, :down?, :up?, :move?, :cancel?, :stay?,
20
+ :position, :pos, :x, :y, :modifiers, :click_count, :drag?,
21
+ :time, :prev
18
22
 
19
- const_symbol_reader :type, **{
20
- none: TYPE_NONE,
21
- down: TYPE_DOWN,
22
- up: TYPE_UP,
23
- move: TYPE_MOVE
24
- }
25
-
26
- bit_flag_reader :pointer_type, **{
27
- none: POINTER_NONE,
28
- mouse_left: POINTER_MOUSE_LEFT,
29
- mouse_right: POINTER_MOUSE_RIGHT,
30
- mouse_middle: POINTER_MOUSE_MIDDLE,
31
- touch: POINTER_TOUCH,
32
- pen: POINTER_PEN
33
- }
34
-
35
- def down?()
36
- get_type == TYPE_DOWN
23
+ def pointers()
24
+ to_enum :each
37
25
  end
38
26
 
39
- def up?()
40
- get_type == TYPE_UP
41
- end
42
-
43
- def move?()
44
- get_type == TYPE_MOVE
45
- end
46
-
47
- def left?()
48
- (get_pointer_type & POINTER_MOUSE_LEFT) != 0
49
- end
50
-
51
- def right?()
52
- (get_pointer_type & POINTER_MOUSE_RIGHT) != 0
53
- end
54
-
55
- def middle?()
56
- (get_pointer_type & POINTER_MOUSE_MIDDLE) != 0
57
- end
58
-
59
- def touch?()
60
- (get_pointer_type & POINTER_TOUCH) != 0
61
- end
62
-
63
- def pen?()
64
- (get_pointer_type & POINTER_PEN) != 0
27
+ def inspect()
28
+ "#<Reflex::PointerEvent id:#{id} #{type} #{action} (#{x.round 2}, #{y.round 2}) mod:#{modifiers} click:#{click_count} drag:#{drag?} time:#{time.round 2}>"
65
29
  end
66
30
 
67
- def positions()
68
- size.times.map {|i| position i}
69
- end
31
+ private
70
32
 
71
- def inspect()
72
- "#<Reflex::PointerEvent type:#{type}/#{pointer_type} x:#{x} y:#{y} size:#{size} mod:#{modifiers} count:#{count} drag:#{drag?}>"
33
+ def first()
34
+ self[0]
73
35
  end
74
36
 
75
37
  end# PointerEvent
data/lib/reflex.rb CHANGED
@@ -33,6 +33,7 @@ require 'reflex/frame_event'
33
33
  require 'reflex/scroll_event'
34
34
  require 'reflex/focus_event'
35
35
  require 'reflex/key_event'
36
+ require 'reflex/pointer'
36
37
  require 'reflex/pointer_event'
37
38
  require 'reflex/wheel_event'
38
39
  require 'reflex/capture_event'
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 = '~> 2'
29
+ s.required_ruby_version = '>= 2.6.0'
30
30
 
31
- s.add_runtime_dependency 'xot', '~> 0.1.22'
32
- s.add_runtime_dependency 'rucy', '~> 0.1.22'
33
- s.add_runtime_dependency 'beeps', '~> 0.1.22'
34
- s.add_runtime_dependency 'rays', '~> 0.1.22'
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}