reflexion 0.1.21 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/reflex/contact_event.cpp +6 -6
  3. data/.doc/ext/reflex/focus_event.cpp +6 -6
  4. data/.doc/ext/reflex/key_event.cpp +210 -12
  5. data/.doc/ext/reflex/pointer_event.cpp +21 -21
  6. data/VERSION +1 -1
  7. data/ext/reflex/contact_event.cpp +6 -6
  8. data/ext/reflex/focus_event.cpp +6 -6
  9. data/ext/reflex/key_event.cpp +211 -12
  10. data/ext/reflex/pointer_event.cpp +21 -21
  11. data/include/reflex/defs.h +143 -91
  12. data/lib/reflex/application.rb +3 -3
  13. data/lib/reflex/autoinit.rb +1 -1
  14. data/lib/reflex/button.rb +7 -7
  15. data/lib/reflex/capture_event.rb +7 -7
  16. data/lib/reflex/contact_event.rb +4 -4
  17. data/lib/reflex/draw_event.rb +2 -2
  18. data/lib/reflex/ellipse_shape.rb +2 -2
  19. data/lib/reflex/focus_event.rb +4 -4
  20. data/lib/reflex/frame_event.rb +5 -5
  21. data/lib/reflex/helper.rb +20 -20
  22. data/lib/reflex/image_view.rb +2 -2
  23. data/lib/reflex/key_event.rb +5 -5
  24. data/lib/reflex/model.rb +22 -22
  25. data/lib/reflex/model_owner.rb +7 -7
  26. data/lib/reflex/model_view.rb +1 -1
  27. data/lib/reflex/module.rb +5 -5
  28. data/lib/reflex/pointer_event.rb +12 -12
  29. data/lib/reflex/polygon_shape.rb +2 -2
  30. data/lib/reflex/reflex.rb +3 -3
  31. data/lib/reflex/scroll_event.rb +1 -1
  32. data/lib/reflex/selector.rb +4 -4
  33. data/lib/reflex/shape.rb +13 -13
  34. data/lib/reflex/style.rb +11 -11
  35. data/lib/reflex/style_length.rb +1 -1
  36. data/lib/reflex/text_view.rb +2 -2
  37. data/lib/reflex/timer.rb +2 -2
  38. data/lib/reflex/timer_event.rb +1 -1
  39. data/lib/reflex/update_event.rb +1 -1
  40. data/lib/reflex/view.rb +32 -32
  41. data/lib/reflex/wheel_event.rb +3 -3
  42. data/lib/reflex/window.rb +5 -5
  43. data/lib/reflexion.rb +17 -17
  44. data/reflex.gemspec +4 -4
  45. data/samples/reflexion/noise.rb +1 -1
  46. data/samples/tree.rb +1 -1
  47. data/src/ios/window.mm +1 -1
  48. data/src/osx/event.h +8 -0
  49. data/src/osx/event.mm +173 -1
  50. data/src/osx/native_window.mm +5 -1
  51. data/src/view.cpp +38 -10
  52. data/src/window.cpp +1 -1
  53. data/test/helper.rb +3 -3
  54. data/test/test_application.rb +1 -1
  55. data/test/test_capture_event.rb +6 -6
  56. data/test/test_event.rb +2 -2
  57. data/test/test_has_frame.rb +11 -11
  58. data/test/test_pointer_event.rb +13 -13
  59. data/test/test_reflex.rb +1 -1
  60. data/test/test_selector.rb +8 -8
  61. data/test/test_shape.rb +8 -8
  62. data/test/test_style.rb +13 -13
  63. data/test/test_style_length.rb +5 -5
  64. data/test/test_view.rb +30 -30
  65. data/test/test_window.rb +10 -10
  66. metadata +10 -10
data/lib/reflexion.rb CHANGED
@@ -18,7 +18,7 @@ module Reflexion
18
18
  }
19
19
 
20
20
 
21
- def call_event (event, *args, &block)
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 (e)
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 (*args, &block)
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 (e)
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 (e)
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 (e)
59
+ def on_key(e)
60
60
  super
61
61
  call_event e, e, &$key
62
62
  end
63
63
 
64
- def on_pointer (e)
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 (&block)
82
+ def setup(&block)
83
83
  $setup = block
84
84
  end
85
85
 
86
- def update (&block)
86
+ def update(&block)
87
87
  $update = block
88
88
  end
89
89
 
90
- def draw (&block)
90
+ def draw(&block)
91
91
  $draw = block
92
92
  end
93
93
 
94
- def key (&block)
94
+ def key(&block)
95
95
  $key = block
96
96
  end
97
97
 
98
- def pointer (&block)
98
+ def pointer(&block)
99
99
  $pointer = block
100
100
  end
101
101
 
102
- def motion (&block)
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
@@ -28,10 +28,10 @@ Gem::Specification.new do |s|
28
28
  s.platform = Gem::Platform::RUBY
29
29
  s.required_ruby_version = '~> 2'
30
30
 
31
- s.add_runtime_dependency 'xot', '~> 0.1.21'
32
- s.add_runtime_dependency 'rucy', '~> 0.1.21'
33
- s.add_runtime_dependency 'beeps', '~> 0.1.21'
34
- s.add_runtime_dependency 'rays', '~> 0.1.21'
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'
35
35
 
36
36
  s.files = `git ls-files`.split $/
37
37
  s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
@@ -12,7 +12,7 @@ y = 0
12
12
 
13
13
  draw do
14
14
  stroke :white
15
- lines *(0..200).map {|x|
15
+ line *(0..200).map {|x|
16
16
  xx = x * 5
17
17
  yy = 200 + Rays.perlin(x / 10.0, y / 100.0) * 100
18
18
  [xx, yy]
data/samples/tree.rb CHANGED
@@ -48,7 +48,7 @@ class W < Reflex::Window
48
48
  end
49
49
 
50
50
  def on_pointer_move (e)
51
- $scroll = [-e.x.floor, -e.y.floor]
51
+ $scroll = [e.x.floor, e.y.floor]
52
52
  end
53
53
 
54
54
  end# W
data/src/ios/window.mm CHANGED
@@ -133,7 +133,7 @@ namespace Reflex
133
133
  void
134
134
  Window_set_resizable (Window* window, bool state)
135
135
  {
136
- not_implemented_error(__FILE__, __LINE__);
136
+ //not_implemented_error(__FILE__, __LINE__);
137
137
  }
138
138
 
139
139
  bool
data/src/osx/event.h CHANGED
@@ -20,6 +20,14 @@ namespace Reflex
20
20
  };// NativeKeyEvent
21
21
 
22
22
 
23
+ struct NativeFlagKeyEvent : public KeyEvent
24
+ {
25
+
26
+ NativeFlagKeyEvent (NSEvent* event);
27
+
28
+ };// NativeFlagKeyEvent
29
+
30
+
23
31
  struct NativePointerEvent : public PointerEvent
24
32
  {
25
33
 
data/src/osx/event.mm CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
 
5
5
  #include <assert.h>
6
+ #include <Carbon/Carbon.h>
6
7
  #import <Cocoa/Cocoa.h>
7
8
 
8
9
 
@@ -17,6 +18,168 @@ namespace Reflex
17
18
  return [chars UTF8String];
18
19
  }
19
20
 
21
+ static KeyCode
22
+ get_code (UInt16 code)
23
+ {
24
+ switch (code)
25
+ {
26
+ case kVK_ANSI_A: return KEY_A;
27
+ case kVK_ANSI_S: return KEY_S;
28
+ case kVK_ANSI_D: return KEY_D;
29
+ case kVK_ANSI_F: return KEY_F;
30
+ case kVK_ANSI_H: return KEY_H;
31
+ case kVK_ANSI_G: return KEY_G;
32
+ case kVK_ANSI_Z: return KEY_Z;
33
+ case kVK_ANSI_X: return KEY_X;
34
+ case kVK_ANSI_C: return KEY_C;
35
+ case kVK_ANSI_V: return KEY_V;
36
+ case kVK_ANSI_B: return KEY_B;
37
+ case kVK_ANSI_Q: return KEY_Q;
38
+ case kVK_ANSI_W: return KEY_W;
39
+ case kVK_ANSI_E: return KEY_E;
40
+ case kVK_ANSI_R: return KEY_R;
41
+ case kVK_ANSI_Y: return KEY_Y;
42
+ case kVK_ANSI_T: return KEY_T;
43
+ case kVK_ANSI_1: return KEY_1;
44
+ case kVK_ANSI_2: return KEY_2;
45
+ case kVK_ANSI_3: return KEY_3;
46
+ case kVK_ANSI_4: return KEY_4;
47
+ case kVK_ANSI_6: return KEY_6;
48
+ case kVK_ANSI_5: return KEY_5;
49
+ case kVK_ANSI_Equal: return KEY_EQUAL;
50
+ case kVK_ANSI_9: return KEY_9;
51
+ case kVK_ANSI_7: return KEY_7;
52
+ case kVK_ANSI_Minus: return KEY_MINUS;
53
+ case kVK_ANSI_8: return KEY_8;
54
+ case kVK_ANSI_0: return KEY_0;
55
+ case kVK_ANSI_RightBracket: return KEY_RBRACKET;
56
+ case kVK_ANSI_O: return KEY_O;
57
+ case kVK_ANSI_U: return KEY_U;
58
+ case kVK_ANSI_LeftBracket: return KEY_LBRACKET;
59
+ case kVK_ANSI_I: return KEY_I;
60
+ case kVK_ANSI_P: return KEY_P;
61
+ case kVK_ANSI_L: return KEY_L;
62
+ case kVK_ANSI_J: return KEY_J;
63
+ case kVK_ANSI_Quote: return KEY_QUOTE;
64
+ case kVK_ANSI_K: return KEY_K;
65
+ case kVK_ANSI_Semicolon: return KEY_SEMICOLON;
66
+ case kVK_ANSI_Backslash: return KEY_BACKSLASH;
67
+ case kVK_ANSI_Comma: return KEY_COMMA;
68
+ case kVK_ANSI_Slash: return KEY_SLASH;
69
+ case kVK_ANSI_N: return KEY_N;
70
+ case kVK_ANSI_M: return KEY_M;
71
+ case kVK_ANSI_Period: return KEY_PERIOD;
72
+ case kVK_ANSI_Grave: return KEY_GRAVE;
73
+ case kVK_ANSI_KeypadDecimal: return KEY_NUM_DECIMAL;
74
+ case kVK_ANSI_KeypadMultiply: return KEY_NUM_MULTIPLY;
75
+ case kVK_ANSI_KeypadPlus: return KEY_NUM_PLUS;
76
+ case kVK_ANSI_KeypadClear: return KEY_NUM_CLEAR;
77
+ case kVK_ANSI_KeypadDivide: return KEY_NUM_DIVIDE;
78
+ case kVK_ANSI_KeypadEnter: return KEY_ENTER;
79
+ case kVK_ANSI_KeypadMinus: return KEY_NUM_MINUS;
80
+ case kVK_ANSI_KeypadEquals: return KEY_NUM_EQUAL;
81
+ case kVK_ANSI_Keypad0: return KEY_NUM_0;
82
+ case kVK_ANSI_Keypad1: return KEY_NUM_1;
83
+ case kVK_ANSI_Keypad2: return KEY_NUM_2;
84
+ case kVK_ANSI_Keypad3: return KEY_NUM_3;
85
+ case kVK_ANSI_Keypad4: return KEY_NUM_4;
86
+ case kVK_ANSI_Keypad5: return KEY_NUM_5;
87
+ case kVK_ANSI_Keypad6: return KEY_NUM_6;
88
+ case kVK_ANSI_Keypad7: return KEY_NUM_7;
89
+ case kVK_ANSI_Keypad8: return KEY_NUM_8;
90
+ case kVK_ANSI_Keypad9: return KEY_NUM_9;
91
+
92
+ case kVK_Return: return KEY_RETURN;
93
+ case kVK_Tab: return KEY_TAB;
94
+ case kVK_Space: return KEY_SPACE;
95
+ case kVK_Delete: return KEY_BACKSPACE;
96
+ case kVK_Escape: return KEY_ESCAPE;
97
+ case kVK_Command: return KEY_LCOMMAND;
98
+ case kVK_Shift: return KEY_LSHIFT;
99
+ case kVK_CapsLock: return KEY_CAPSLOCK;
100
+ case kVK_Option: return KEY_LOPTION;
101
+ case kVK_Control: return KEY_LCONTROL;
102
+ case kVK_RightCommand: return KEY_RCOMMAND;
103
+ case kVK_RightShift: return KEY_RSHIFT;
104
+ case kVK_RightOption: return KEY_ROPTION;
105
+ case kVK_RightControl: return KEY_RCONTROL;
106
+ case kVK_Function: return KEY_FUNCTION;
107
+ case kVK_F17: return KEY_F17;
108
+ case kVK_VolumeUp: return KEY_VOLUME_UP;
109
+ case kVK_VolumeDown: return KEY_VOLUME_DOWN;
110
+ case kVK_Mute: return KEY_MUTE;
111
+ case kVK_F18: return KEY_F18;
112
+ case kVK_F19: return KEY_F19;
113
+ case kVK_F20: return KEY_F20;
114
+ case kVK_F5: return KEY_F5;
115
+ case kVK_F6: return KEY_F6;
116
+ case kVK_F7: return KEY_F7;
117
+ case kVK_F3: return KEY_F3;
118
+ case kVK_F8: return KEY_F8;
119
+ case kVK_F9: return KEY_F9;
120
+ case kVK_F11: return KEY_F11;
121
+ case kVK_F13: return KEY_F13;
122
+ case kVK_F16: return KEY_F16;
123
+ case kVK_F14: return KEY_F14;
124
+ case kVK_F10: return KEY_F10;
125
+ case kVK_F12: return KEY_F12;
126
+ case kVK_F15: return KEY_F15;
127
+ case kVK_Help: return KEY_HELP;
128
+ case kVK_Home: return KEY_HOME;
129
+ case kVK_PageUp: return KEY_PAGEUP;
130
+ case kVK_ForwardDelete: return KEY_DELETE;
131
+ case kVK_F4: return KEY_F4;
132
+ case kVK_End: return KEY_END;
133
+ case kVK_F2: return KEY_F2;
134
+ case kVK_PageDown: return KEY_PAGEDOWN;
135
+ case kVK_F1: return KEY_F1;
136
+ case kVK_LeftArrow: return KEY_LEFT;
137
+ case kVK_RightArrow: return KEY_RIGHT;
138
+ case kVK_DownArrow: return KEY_DOWN;
139
+ case kVK_UpArrow: return KEY_UP;
140
+
141
+ case kVK_ISO_Section: return KEY_SECTION;
142
+
143
+ case kVK_JIS_Yen: return KEY_YEN;
144
+ case kVK_JIS_Underscore: return KEY_UNDERSCORE;
145
+ case kVK_JIS_KeypadComma: return KEY_NUM_COMMA;
146
+ case kVK_JIS_Eisu: return KEY_IME_EISU;
147
+ case kVK_JIS_Kana: return KEY_IME_KANA;
148
+ }
149
+
150
+ return KEY_NONE;
151
+ }
152
+
153
+ static uint
154
+ get_modifier_flag_mask (const NSEvent* e)
155
+ {
156
+ switch ([e keyCode])
157
+ {
158
+ case kVK_Shift:
159
+ case kVK_RightShift: return NSShiftKeyMask;
160
+ case kVK_Control:
161
+ case kVK_RightControl: return NSControlKeyMask;
162
+ case kVK_Option:
163
+ case kVK_RightOption: return NSAlternateKeyMask;
164
+ case kVK_Command:
165
+ case kVK_RightCommand: return NSCommandKeyMask;
166
+ case kVK_CapsLock: return NSAlphaShiftKeyMask;
167
+ case kVK_Function: return NSFunctionKeyMask;
168
+ }
169
+ return 0;
170
+ }
171
+
172
+ static KeyEvent::Type
173
+ get_flag_key_event_type(const NSEvent* e)
174
+ {
175
+ uint mask = get_modifier_flag_mask(e);
176
+ if (mask == 0) return Reflex::KeyEvent::NONE;
177
+
178
+ return [e modifierFlags] & mask
179
+ ? Reflex::KeyEvent::DOWN
180
+ : Reflex::KeyEvent::UP;
181
+ }
182
+
20
183
  static uint
21
184
  get_current_pointer_type ()
22
185
  {
@@ -81,7 +244,16 @@ namespace Reflex
81
244
 
82
245
  NativeKeyEvent::NativeKeyEvent (NSEvent* e, Type type)
83
246
  : KeyEvent(
84
- type, get_chars(e), [e keyCode], get_modifiers(e), [e isARepeat] ? 1 : 0)
247
+ type, get_chars(e), get_code([e keyCode]), get_modifiers(e),
248
+ [e isARepeat] ? 1 : 0)
249
+ {
250
+ }
251
+
252
+
253
+ NativeFlagKeyEvent::NativeFlagKeyEvent (NSEvent* e)
254
+ : KeyEvent(
255
+ get_flag_key_event_type(e), "", get_code([e keyCode]), get_modifiers(e),
256
+ 0)
85
257
  {
86
258
  }
87
259
 
@@ -280,7 +280,11 @@ static const NSUInteger WINDOW_STYLE_MASK =
280
280
 
281
281
  - (void) flagsChanged: (NSEvent*) event
282
282
  {
283
- // TODO: implement later.
283
+ Reflex::Window* win = self.window;
284
+ if (!win) return;
285
+
286
+ Reflex::NativeFlagKeyEvent e(event);
287
+ win->on_key(&e);
284
288
  }
285
289
 
286
290
  - (void) mouseDown: (NSEvent*) event
data/src/view.cpp CHANGED
@@ -1279,6 +1279,24 @@ namespace Reflex
1279
1279
  }
1280
1280
  }
1281
1281
 
1282
+ static void
1283
+ scroll_and_zoom_positions (PointerEvent* e, const Point* scroll, float zoom)
1284
+ {
1285
+ static const Point ZERO = 0;
1286
+
1287
+ assert(zoom != 0);
1288
+
1289
+ if (!scroll) scroll = &ZERO;
1290
+ if (*scroll == 0 && zoom == 1)
1291
+ return;
1292
+
1293
+ for (size_t i = 0; i < e->size; ++i)
1294
+ {
1295
+ e->position(i) -= *scroll;
1296
+ e->position(i) /= zoom;
1297
+ }
1298
+ }
1299
+
1282
1300
  void
1283
1301
  View_call_pointer_event (View* view, const PointerEvent& event)
1284
1302
  {
@@ -1288,14 +1306,14 @@ namespace Reflex
1288
1306
  bool capturing = view->capture() & View::CAPTURE_POINTER;
1289
1307
  if (capturing != event.capture) return;
1290
1308
 
1291
- const Bounds& frame = view->frame();
1292
-
1293
1309
  PointerEvent e = event;
1294
- filter_pointer_event(&e, event, frame);
1310
+ filter_pointer_event(&e, event, view->frame());
1295
1311
 
1296
1312
  if (!capturing && e.size == 0)
1297
1313
  return;
1298
1314
 
1315
+ scroll_and_zoom_positions(&e, view->self->pscroll.get(), view->zoom());
1316
+
1299
1317
  view->on_pointer(&e);
1300
1318
 
1301
1319
  switch (e.type)
@@ -1989,18 +2007,23 @@ namespace Reflex
1989
2007
  void
1990
2008
  View::scroll_to (coord x, coord y, coord z)
1991
2009
  {
1992
- Point old = self->scroll();
1993
- self->scroll().reset(x, y, z);
1994
- ScrollEvent e(x, y, z, x - old.x, y - old.y, z - old.z);
1995
- on_scroll(&e);
1996
-
1997
- redraw();
2010
+ scroll_to(Point(x, y, z));
1998
2011
  }
1999
2012
 
2000
2013
  void
2001
2014
  View::scroll_to (const Point& scroll)
2002
2015
  {
2003
- scroll_to(scroll.x, scroll.y, scroll.z);
2016
+ if (scroll == this->scroll()) return;
2017
+
2018
+ Point old = self->scroll();
2019
+ self->scroll() = scroll;
2020
+
2021
+ ScrollEvent e(
2022
+ scroll.x, scroll.y, scroll.z,
2023
+ scroll.x - old.x, scroll.y - old.y, scroll.z - old.z);
2024
+ on_scroll(&e);
2025
+
2026
+ redraw();
2004
2027
  }
2005
2028
 
2006
2029
  void
@@ -2028,6 +2051,11 @@ namespace Reflex
2028
2051
  void
2029
2052
  View::set_zoom (float zoom)
2030
2053
  {
2054
+ if (zoom == self->zoom) return;
2055
+
2056
+ if (zoom == 0)
2057
+ argument_error(__FILE__, __LINE__);
2058
+
2031
2059
  self->zoom = zoom;
2032
2060
  redraw();
2033
2061
  }