reflexion 0.5.3 → 0.7.0

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.
Files changed (309) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/reflex/application.cpp +56 -7
  3. data/.doc/ext/reflex/capture_event.cpp +1 -1
  4. data/.doc/ext/reflex/chase_constraint.cpp +84 -0
  5. data/.doc/ext/reflex/clipboard.cpp +65 -0
  6. data/.doc/ext/reflex/color_event.cpp +76 -0
  7. data/.doc/ext/reflex/color_picker.cpp +113 -0
  8. data/.doc/ext/reflex/constraint.cpp +135 -0
  9. data/.doc/ext/reflex/contact_event.cpp +1 -1
  10. data/.doc/ext/reflex/control_change_event.cpp +1 -1
  11. data/.doc/ext/reflex/device.cpp +1 -1
  12. data/.doc/ext/reflex/device_event.cpp +1 -1
  13. data/.doc/ext/reflex/draw_event.cpp +1 -1
  14. data/.doc/ext/reflex/ellipse_shape.cpp +1 -1
  15. data/.doc/ext/reflex/event.cpp +1 -1
  16. data/.doc/ext/reflex/file_dialog.cpp +181 -0
  17. data/.doc/ext/reflex/file_event.cpp +103 -0
  18. data/.doc/ext/reflex/filter.cpp +1 -1
  19. data/.doc/ext/reflex/focus_event.cpp +1 -1
  20. data/.doc/ext/reflex/frame_event.cpp +1 -1
  21. data/.doc/ext/reflex/gamepad.cpp +48 -0
  22. data/.doc/ext/reflex/image_view.cpp +1 -1
  23. data/.doc/ext/reflex/key_event.cpp +1 -274
  24. data/.doc/ext/reflex/line_shape.cpp +1 -1
  25. data/.doc/ext/reflex/link_constraint.cpp +178 -0
  26. data/.doc/ext/reflex/menu.cpp +303 -0
  27. data/.doc/ext/reflex/midi.cpp +9 -2
  28. data/.doc/ext/reflex/midi_event.cpp +1 -1
  29. data/.doc/ext/reflex/motion_event.cpp +1 -1
  30. data/.doc/ext/reflex/native.cpp +40 -10
  31. data/.doc/ext/reflex/note_event.cpp +1 -1
  32. data/.doc/ext/reflex/pin.cpp +156 -0
  33. data/.doc/ext/reflex/pointer.cpp +3 -1
  34. data/.doc/ext/reflex/pointer_event.cpp +3 -3
  35. data/.doc/ext/reflex/polygon_shape.cpp +1 -1
  36. data/.doc/ext/reflex/rect_shape.cpp +1 -1
  37. data/.doc/ext/reflex/reflex.cpp +606 -237
  38. data/.doc/ext/reflex/screen.cpp +27 -1
  39. data/.doc/ext/reflex/scroll_event.cpp +1 -1
  40. data/.doc/ext/reflex/selector.cpp +5 -5
  41. data/.doc/ext/reflex/shape.cpp +1 -1
  42. data/.doc/ext/reflex/snap_constraint.cpp +125 -0
  43. data/.doc/ext/reflex/style.cpp +1 -1
  44. data/.doc/ext/reflex/style_length.cpp +4 -3
  45. data/.doc/ext/reflex/text_event.cpp +104 -0
  46. data/.doc/ext/reflex/timer.cpp +1 -1
  47. data/.doc/ext/reflex/timer_event.cpp +1 -1
  48. data/.doc/ext/reflex/update_event.cpp +1 -1
  49. data/.doc/ext/reflex/view.cpp +206 -79
  50. data/.doc/ext/reflex/wheel_constraint.cpp +142 -0
  51. data/.doc/ext/reflex/wheel_event.cpp +1 -1
  52. data/.doc/ext/reflex/window.cpp +282 -31
  53. data/.github/workflows/release-gem.yml +2 -40
  54. data/.github/workflows/tag.yml +5 -28
  55. data/.github/workflows/test.yml +1 -28
  56. data/ChangeLog.md +79 -0
  57. data/Gemfile.lock +13 -8
  58. data/README.md +1 -0
  59. data/Rakefile +13 -2
  60. data/Reflex.podspec +2 -2
  61. data/VERSION +1 -1
  62. data/ext/reflex/application.cpp +62 -7
  63. data/ext/reflex/capture_event.cpp +1 -1
  64. data/ext/reflex/chase_constraint.cpp +89 -0
  65. data/ext/reflex/clipboard.cpp +69 -0
  66. data/ext/reflex/color_event.cpp +80 -0
  67. data/ext/reflex/color_picker.cpp +121 -0
  68. data/ext/reflex/constraint.cpp +146 -0
  69. data/ext/reflex/contact_event.cpp +1 -1
  70. data/ext/reflex/control_change_event.cpp +1 -1
  71. data/ext/reflex/device.cpp +1 -1
  72. data/ext/reflex/device_event.cpp +1 -1
  73. data/ext/reflex/draw_event.cpp +1 -1
  74. data/ext/reflex/ellipse_shape.cpp +1 -1
  75. data/ext/reflex/event.cpp +1 -1
  76. data/ext/reflex/extconf.rb +4 -2
  77. data/ext/reflex/file_dialog.cpp +194 -0
  78. data/ext/reflex/file_event.cpp +108 -0
  79. data/ext/reflex/filter.cpp +1 -1
  80. data/ext/reflex/focus_event.cpp +1 -1
  81. data/ext/reflex/frame_event.cpp +1 -1
  82. data/ext/reflex/gamepad.cpp +50 -0
  83. data/ext/reflex/image_view.cpp +1 -1
  84. data/ext/reflex/key_event.cpp +1 -275
  85. data/ext/reflex/line_shape.cpp +1 -1
  86. data/ext/reflex/link_constraint.cpp +194 -0
  87. data/ext/reflex/menu.cpp +331 -0
  88. data/ext/reflex/midi.cpp +11 -3
  89. data/ext/reflex/midi_event.cpp +1 -1
  90. data/ext/reflex/motion_event.cpp +1 -1
  91. data/ext/reflex/native.cpp +40 -10
  92. data/ext/reflex/note_event.cpp +1 -1
  93. data/ext/reflex/pin.cpp +165 -0
  94. data/ext/reflex/pointer.cpp +3 -1
  95. data/ext/reflex/pointer_event.cpp +3 -3
  96. data/ext/reflex/polygon_shape.cpp +1 -1
  97. data/ext/reflex/rect_shape.cpp +1 -1
  98. data/ext/reflex/reflex.cpp +608 -237
  99. data/ext/reflex/screen.cpp +31 -2
  100. data/ext/reflex/scroll_event.cpp +1 -1
  101. data/ext/reflex/selector.cpp +5 -5
  102. data/ext/reflex/selector.h +10 -10
  103. data/ext/reflex/shape.cpp +1 -1
  104. data/ext/reflex/snap_constraint.cpp +135 -0
  105. data/ext/reflex/style.cpp +1 -1
  106. data/ext/reflex/style_length.cpp +4 -3
  107. data/ext/reflex/text_event.cpp +111 -0
  108. data/ext/reflex/timer.cpp +1 -1
  109. data/ext/reflex/timer_event.cpp +1 -1
  110. data/ext/reflex/update_event.cpp +1 -1
  111. data/ext/reflex/view.cpp +236 -96
  112. data/ext/reflex/wheel_constraint.cpp +154 -0
  113. data/ext/reflex/wheel_event.cpp +1 -1
  114. data/ext/reflex/window.cpp +318 -40
  115. data/include/reflex/application.h +19 -0
  116. data/include/reflex/clipboard.h +53 -0
  117. data/include/reflex/color_picker.h +65 -0
  118. data/include/reflex/constraint.h +275 -0
  119. data/include/reflex/defs.h +204 -195
  120. data/include/reflex/event.h +180 -88
  121. data/include/reflex/file_dialog.h +73 -0
  122. data/include/reflex/gamepad.h +3 -0
  123. data/include/reflex/menu.h +120 -0
  124. data/include/reflex/midi.h +3 -0
  125. data/include/reflex/pin.h +68 -0
  126. data/include/reflex/pointer.h +4 -0
  127. data/include/reflex/reflex.h +2 -0
  128. data/include/reflex/ruby/application.h +6 -1
  129. data/include/reflex/ruby/clipboard.h +23 -0
  130. data/include/reflex/ruby/color_picker.h +89 -0
  131. data/include/reflex/ruby/constraint.h +94 -0
  132. data/include/reflex/ruby/event.h +62 -29
  133. data/include/reflex/ruby/file_dialog.h +89 -0
  134. data/include/reflex/ruby/gamepad.h +46 -0
  135. data/include/reflex/ruby/menu.h +103 -0
  136. data/include/reflex/ruby/pin.h +40 -0
  137. data/include/reflex/ruby/reflex.h +3 -0
  138. data/include/reflex/ruby/view.h +123 -39
  139. data/include/reflex/ruby/window.h +96 -19
  140. data/include/reflex/ruby.h +3 -0
  141. data/include/reflex/screen.h +11 -2
  142. data/include/reflex/view.h +66 -27
  143. data/include/reflex/window.h +57 -12
  144. data/include/reflex.h +8 -0
  145. data/lib/reflex/application.rb +5 -5
  146. data/lib/reflex/autoinit.rb +3 -1
  147. data/lib/reflex/button.rb +3 -3
  148. data/lib/reflex/chase_constraint.rb +15 -0
  149. data/lib/reflex/clipboard.rb +19 -0
  150. data/lib/reflex/color_event.rb +16 -0
  151. data/lib/reflex/color_picker.rb +45 -0
  152. data/lib/reflex/constraint.rb +29 -0
  153. data/lib/reflex/control_change_event.rb +17 -0
  154. data/lib/reflex/extension.rb +1 -1
  155. data/lib/reflex/file_dialog.rb +70 -0
  156. data/lib/reflex/file_event.rb +37 -0
  157. data/lib/reflex/helper.rb +79 -0
  158. data/lib/reflex/key_event.rb +14 -14
  159. data/lib/reflex/link_constraint.rb +31 -0
  160. data/lib/reflex/menu.rb +92 -0
  161. data/lib/reflex/model.rb +19 -19
  162. data/lib/reflex/note_event.rb +1 -1
  163. data/lib/reflex/pin.rb +39 -0
  164. data/lib/reflex/pointer.rb +30 -1
  165. data/lib/reflex/pointer_event.rb +13 -2
  166. data/lib/reflex/reflex.rb +5 -0
  167. data/lib/reflex/shape.rb +14 -14
  168. data/lib/reflex/snap_constraint.rb +28 -0
  169. data/lib/reflex/style.rb +16 -16
  170. data/lib/reflex/text_event.rb +40 -0
  171. data/lib/reflex/timer.rb +3 -3
  172. data/lib/reflex/view.rb +85 -18
  173. data/lib/reflex/wheel_constraint.rb +28 -0
  174. data/lib/reflex/wheel_event.rb +19 -1
  175. data/lib/reflex/window.rb +25 -13
  176. data/lib/reflex.rb +23 -8
  177. data/pod.rake +1 -1
  178. data/reflex.gemspec +4 -4
  179. data/samples/constraint.rb +152 -0
  180. data/samples/ime.rb +100 -0
  181. data/samples/ios/hello/hello.xcodeproj/project.pbxproj +236 -224
  182. data/samples/menu.rb +32 -0
  183. data/samples/model.rb +3 -3
  184. data/samples/test/alert.rb +93 -0
  185. data/samples/test/always_on.rb +76 -0
  186. data/samples/test/app_background.rb +51 -0
  187. data/samples/test/boundary.rb +75 -0
  188. data/samples/test/callback_exception.rb +101 -0
  189. data/samples/test/cancel.rb +53 -0
  190. data/samples/test/color_picker.rb +63 -0
  191. data/samples/test/file_dialog.rb +102 -0
  192. data/samples/window_style.rb +156 -0
  193. data/src/application.cpp +180 -20
  194. data/src/application.h +95 -5
  195. data/src/clipboard.cpp +81 -0
  196. data/src/color_picker.cpp +113 -0
  197. data/src/color_picker.h +36 -0
  198. data/src/constraint.cpp +1662 -0
  199. data/src/constraint.h +64 -0
  200. data/src/event.cpp +416 -252
  201. data/src/event.h +13 -2
  202. data/src/file_dialog.cpp +163 -0
  203. data/src/file_dialog.h +52 -0
  204. data/src/gamepad.cpp +42 -5
  205. data/src/gamepad.h +4 -0
  206. data/src/ios/app_delegate.mm +5 -3
  207. data/src/ios/application.mm +29 -0
  208. data/src/ios/clipboard.mm +44 -0
  209. data/src/ios/color_picker.mm +19 -0
  210. data/src/ios/event.h +6 -2
  211. data/src/ios/event.mm +31 -12
  212. data/src/ios/file_dialog.mm +21 -0
  213. data/src/ios/gamepad.mm +4 -4
  214. data/src/ios/menu.mm +41 -0
  215. data/src/ios/reflex.mm +8 -0
  216. data/src/ios/screen.mm +26 -0
  217. data/src/ios/view_controller.mm +47 -42
  218. data/src/ios/window.mm +44 -9
  219. data/src/menu.cpp +387 -0
  220. data/src/menu.h +81 -0
  221. data/src/midi.cpp +61 -31
  222. data/src/osx/app_delegate.h +4 -0
  223. data/src/osx/app_delegate.mm +168 -139
  224. data/src/osx/application.mm +103 -5
  225. data/src/osx/clipboard.mm +45 -0
  226. data/src/osx/color_picker.mm +112 -0
  227. data/src/osx/event.h +10 -0
  228. data/src/osx/event.mm +114 -30
  229. data/src/osx/file_dialog.mm +168 -0
  230. data/src/osx/gamepad.mm +2 -2
  231. data/src/osx/gamepad_hid.mm +1 -1
  232. data/src/osx/menu.h +25 -0
  233. data/src/osx/menu.mm +516 -0
  234. data/src/osx/native_window.h +16 -2
  235. data/src/osx/native_window.mm +141 -57
  236. data/src/osx/opengl_view.h +2 -1
  237. data/src/osx/opengl_view.mm +229 -37
  238. data/src/osx/reflex.mm +38 -0
  239. data/src/osx/screen.mm +36 -0
  240. data/src/osx/window.mm +117 -24
  241. data/src/pin.cpp +137 -0
  242. data/src/pointer.cpp +36 -16
  243. data/src/pointer.h +10 -0
  244. data/src/rays.h +46 -0
  245. data/src/sdl/application.cpp +73 -8
  246. data/src/sdl/clipboard.cpp +39 -0
  247. data/src/sdl/color_picker.cpp +18 -0
  248. data/src/sdl/event.cpp +44 -6
  249. data/src/sdl/event.h +18 -3
  250. data/src/sdl/file_dialog.cpp +20 -0
  251. data/src/sdl/gamepad.cpp +3 -7
  252. data/src/sdl/menu.cpp +40 -0
  253. data/src/sdl/reflex.cpp +20 -0
  254. data/src/sdl/screen.cpp +36 -0
  255. data/src/sdl/window.cpp +168 -37
  256. data/src/shape.cpp +15 -10
  257. data/src/view.cpp +583 -233
  258. data/src/view.h +22 -4
  259. data/src/vk.h +416 -0
  260. data/src/win32/application.cpp +167 -12
  261. data/src/win32/application.h +20 -0
  262. data/src/win32/clipboard.cpp +210 -0
  263. data/src/win32/color_picker.cpp +82 -0
  264. data/src/win32/event.cpp +123 -11
  265. data/src/win32/event.h +22 -3
  266. data/src/win32/file_dialog.cpp +226 -0
  267. data/src/win32/gamepad.cpp +9 -2
  268. data/src/win32/menu.cpp +490 -0
  269. data/src/win32/menu.h +35 -0
  270. data/src/win32/opengl.cpp +2 -9
  271. data/src/win32/reflex.cpp +44 -3
  272. data/src/win32/screen.cpp +164 -3
  273. data/src/win32/screen.h +8 -0
  274. data/src/win32/tray.cpp +191 -0
  275. data/src/win32/tray.h +22 -0
  276. data/src/win32/vk.cpp +11 -0
  277. data/src/win32/window.cpp +858 -135
  278. data/src/win32/window.h +9 -0
  279. data/src/window.cpp +929 -183
  280. data/src/window.h +77 -33
  281. data/src/world.cpp +86 -15
  282. data/src/world.h +9 -2
  283. data/test/helper.rb +24 -0
  284. data/test/test_application.rb +101 -1
  285. data/test/test_chase_constraint.rb +122 -0
  286. data/test/test_clipboard.rb +54 -0
  287. data/test/test_color_event.rb +36 -0
  288. data/test/test_color_picker.rb +62 -0
  289. data/test/test_constraint.rb +184 -0
  290. data/test/test_event.rb +1 -1
  291. data/test/test_file_dialog.rb +48 -0
  292. data/test/test_file_event.rb +43 -0
  293. data/test/test_has_text_preedit.rb +54 -0
  294. data/test/test_key_event.rb +23 -2
  295. data/test/test_link_constraint.rb +237 -0
  296. data/test/test_menu.rb +237 -0
  297. data/test/test_pin.rb +65 -0
  298. data/test/test_pointer.rb +50 -26
  299. data/test/test_pointer_event.rb +25 -10
  300. data/test/test_reflex.rb +36 -0
  301. data/test/test_screen.rb +24 -2
  302. data/test/test_snap_constraint.rb +140 -0
  303. data/test/test_text_event.rb +54 -0
  304. data/test/test_view.rb +152 -25
  305. data/test/test_wheel_constraint.rb +125 -0
  306. data/test/test_wheel_event.rb +24 -10
  307. data/test/test_window.rb +205 -43
  308. metadata +154 -10
  309. data/.github/workflows/utils.rb +0 -127
data/src/osx/reflex.mm CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  #import <Cocoa/Cocoa.h>
6
6
  #include "reflex/exception.h"
7
+ #include "../vk.h"
7
8
 
8
9
 
9
10
  namespace Reflex
@@ -37,5 +38,42 @@ namespace Reflex
37
38
  global::pool = nil;
38
39
  }
39
40
 
41
+ static void
42
+ activate_app ()
43
+ {
44
+ NSApplication* app = NSApplication.sharedApplication;
45
+ if (app.activationPolicy == NSApplicationActivationPolicyProhibited)
46
+ [app setActivationPolicy: NSApplicationActivationPolicyRegular];
47
+
48
+ [app activateIgnoringOtherApps: YES];
49
+ }
50
+
51
+ void
52
+ alert (const char* message, const char* title)
53
+ {
54
+ if (!message)
55
+ argument_error(__FILE__, __LINE__);
56
+
57
+ activate_app();
58
+
59
+ NSAlert* alert = [[[NSAlert alloc] init] autorelease];
60
+ NSString* text = [NSString stringWithUTF8String: message];
61
+ if (title && *title)
62
+ {
63
+ alert.messageText = [NSString stringWithUTF8String: title];
64
+ alert.informativeText = text;
65
+ }
66
+ else
67
+ alert.messageText = text;
68
+
69
+ // in front of the other apps once runModal shows it, as macOS 14 or
70
+ // later lets no app launched from a terminal take the focus from it
71
+ [alert.window
72
+ performSelector: @selector(orderFrontRegardless)
73
+ withObject: nil afterDelay: 0 inModes: @[NSModalPanelRunLoopMode]];
74
+
75
+ [alert runModal];
76
+ }
77
+
40
78
 
41
79
  }// Reflex
data/src/osx/screen.mm CHANGED
@@ -2,6 +2,7 @@
2
2
  #include "screen.h"
3
3
 
4
4
 
5
+ #import <AppKit/AppKit.h>
5
6
  #include "reflex/exception.h"
6
7
 
7
8
 
@@ -43,6 +44,19 @@ namespace Reflex
43
44
  {
44
45
  }
45
46
 
47
+ String
48
+ Screen::name () const
49
+ {
50
+ if (!*this)
51
+ invalid_state_error(__FILE__, __LINE__);
52
+
53
+ const char* name = NULL;
54
+ if (@available(macOS 10.15, *))
55
+ name = self->screen.localizedName.UTF8String;
56
+
57
+ return name ? name : "";
58
+ }
59
+
46
60
  Bounds
47
61
  Screen::frame () const
48
62
  {
@@ -57,6 +71,15 @@ namespace Reflex
57
71
  f.size.height);
58
72
  }
59
73
 
74
+ float
75
+ Screen::pixel_density () const
76
+ {
77
+ if (!*this)
78
+ invalid_state_error(__FILE__, __LINE__);
79
+
80
+ return self->screen.backingScaleFactor;
81
+ }
82
+
60
83
  Screen::operator bool () const
61
84
  {
62
85
  return self->screen;
@@ -68,5 +91,18 @@ namespace Reflex
68
91
  return !operator bool();
69
92
  }
70
93
 
94
+ Screen::List
95
+ Screen::all ()
96
+ {
97
+ List list;
98
+ for (NSScreen* screen in NSScreen.screens)
99
+ {
100
+ Screen s;
101
+ Screen_initialize(&s, screen);
102
+ list.emplace_back(s);
103
+ }
104
+ return list;
105
+ }
106
+
71
107
 
72
108
  }// Reflex
data/src/osx/window.mm CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  #import <Cocoa/Cocoa.h>
6
6
  #include "reflex/exception.h"
7
+ #include "menu.h"
7
8
  #include "screen.h"
8
9
  #import "native_window.h"
9
10
 
@@ -35,20 +36,18 @@ namespace Reflex
35
36
  NSWindowStyleMask
36
37
  Window_make_style_mask (uint flags, NSWindowStyleMask styleMask)
37
38
  {
38
- if (Xot::has_flag(flags, Window::FLAG_CLOSABLE))
39
- styleMask |= NSWindowStyleMaskClosable;
40
- else
41
- styleMask &= ~NSWindowStyleMaskClosable;
42
-
43
- if (Xot::has_flag(flags, Window::FLAG_MINIMIZABLE))
44
- styleMask |= NSWindowStyleMaskMiniaturizable;
45
- else
46
- styleMask &= ~NSWindowStyleMaskMiniaturizable;
47
-
48
- if (Xot::has_flag(flags, Window::FLAG_RESIZABLE))
49
- styleMask |= NSWindowStyleMaskResizable;
50
- else
51
- styleMask &= ~NSWindowStyleMaskResizable;
39
+ Xot::update_flag(
40
+ &styleMask, NSWindowStyleMaskClosable,
41
+ Xot::has_flag(flags, Window::FLAG_CLOSABLE));
42
+ Xot::update_flag(
43
+ &styleMask, NSWindowStyleMaskMiniaturizable,
44
+ Xot::has_flag(flags, Window::FLAG_MINIMIZABLE));
45
+ Xot::update_flag(
46
+ &styleMask, NSWindowStyleMaskResizable,
47
+ Xot::has_flag(flags, Window::FLAG_RESIZABLE));
48
+ Xot::update_flag(
49
+ &styleMask, NSWindowStyleMaskFullSizeContentView,
50
+ !Xot::has_flag(flags, Window::FLAG_TITLEBAR_BACKGROUND));
52
51
 
53
52
  return styleMask;
54
53
  }
@@ -74,9 +73,12 @@ namespace Reflex
74
73
  Window_default_flags ()
75
74
  {
76
75
  return
77
- Window::FLAG_CLOSABLE |
78
- Window::FLAG_RESIZABLE |
79
- Window::FLAG_MINIMIZABLE;
76
+ Window::FLAG_CLOSABLE |
77
+ Window::FLAG_MINIMIZABLE |
78
+ Window::FLAG_RESIZABLE |
79
+ Window::FLAG_TITLEBAR_BUTTONS |
80
+ Window::FLAG_TITLEBAR_BACKGROUND |
81
+ Window::FLAG_SHADOW;
80
82
  }
81
83
 
82
84
  void
@@ -126,10 +128,12 @@ namespace Reflex
126
128
  void
127
129
  Window_set_frame (Window* window, coord x, coord y, coord w, coord h)
128
130
  {
129
- NSRect f = [NativeWindow frameRectForContentRect: NSMakeRect(x, y, w, h)];
130
- f.origin.y = primary_screen_height() - (f.origin.y + h);
131
+ NativeWindow* native = get_native(window);
131
132
 
132
- [get_native(window) setFrame: f display: NO animate: NO];
133
+ NSRect r = [native frameRectForContentRect: NSMakeRect(x, y, w, h)];
134
+ r.origin.y = primary_screen_height() - (y + h);
135
+
136
+ [native setFrame: r display: NO animate: NO];
133
137
  }
134
138
 
135
139
  Bounds
@@ -137,10 +141,20 @@ namespace Reflex
137
141
  {
138
142
  NativeWindow* native = get_native(&window);
139
143
 
140
- NSRect f = [native contentRectForFrameRect: native.frame];
141
- f.origin.y = primary_screen_height() - (f.origin.y + f.size.height);
144
+ NSRect r = [native contentRectForFrameRect: native.frame];
145
+ r.origin.y = primary_screen_height() - (r.origin.y + r.size.height);
142
146
 
143
- return Bounds(f.origin.x, f.origin.y, f.size.width, f.size.height);
147
+ return Bounds(r.origin.x, r.origin.y, r.size.width, r.size.height);
148
+ }
149
+
150
+ void
151
+ Window_set_menu (Window* window, Menu* menu)
152
+ {
153
+ NativeWindow* native = get_native(window);
154
+ if (!native) return;
155
+
156
+ if (native.isMainWindow)
157
+ Menu_apply_to_main_menu(menu);
144
158
  }
145
159
 
146
160
  Screen
@@ -163,13 +177,47 @@ namespace Reflex
163
177
 
164
178
  NativeWindow* native = get_native(window);
165
179
  NSWindowStyleMask styleMask =
166
- Window_make_style_mask(window->self->flags, native.styleMask);
180
+ Window_make_style_mask(flags, native.styleMask);
167
181
 
168
182
  if (styleMask != native.styleMask)
183
+ {
184
+ NSRect content = [native contentRectForFrameRect: native.frame];
169
185
  native.styleMask = styleMask;
186
+ [native setFrame: [native frameRectForContentRect: content] display: YES];
187
+ }
188
+
189
+ bool buttons = Xot::has_flag(flags, Window::FLAG_TITLEBAR_BUTTONS);
190
+ bool background = Xot::has_flag(flags, Window::FLAG_TITLEBAR_BACKGROUND);
191
+ [native setTitlebarButtonsVisible: buttons];
192
+ [native setTitlebarBackgroundVisible: background];
193
+ [native setTitlebarContainerVisible: buttons || background];
194
+
195
+ NSWindowCollectionBehavior behavior = native.collectionBehavior;
196
+ if (Xot::has_flag(flags, Window::FLAG_UNLISTED))
197
+ {
198
+ behavior &= ~NSWindowCollectionBehaviorManaged;
199
+ behavior |= NSWindowCollectionBehaviorTransient;
200
+ }
201
+ else
202
+ {
203
+ behavior &= ~NSWindowCollectionBehaviorTransient;
204
+ behavior |= NSWindowCollectionBehaviorManaged;
205
+ }
206
+ native.collectionBehavior = behavior;
207
+
208
+ native.hasShadow = Xot::has_flag(flags, Window::FLAG_SHADOW);
209
+
210
+ [native setBackgroundTransparent: Xot::has_flag(flags, Window::FLAG_TRANSPARENT)];
170
211
 
171
212
  if (native.hasFullScreenFlag != Xot::has_flag(flags, Window::FLAG_FULLSCREEN))
172
213
  [native toggleFullScreen: native];
214
+
215
+ if (Xot::has_flag(flags, Window::FLAG_ALWAYS_ON_TOP))
216
+ native.level = NSFloatingWindowLevel;
217
+ else if (Xot::has_flag(flags, Window::FLAG_ALWAYS_ON_BOTTOM))
218
+ native.level = NSNormalWindowLevel - 1;
219
+ else
220
+ native.level = NSNormalWindowLevel;
173
221
  }
174
222
 
175
223
  float
@@ -178,5 +226,50 @@ namespace Reflex
178
226
  return get_native(&window).backingScaleFactor;
179
227
  }
180
228
 
229
+ void
230
+ Window_set_pointer_through (Window* window, bool through)
231
+ {
232
+ get_native(window).ignoresMouseEvents = through ? YES : NO;
233
+ }
234
+
235
+ static bool
236
+ is_covered_by_another_window (NativeWindow* native, NSPoint screen_pos)
237
+ {
238
+ // only a window that takes mouse events counts as covering. when
239
+ // the frontmost window at the point is also the frontmost behind
240
+ // this window, nothing sits between them, so nothing is in front
241
+ // of this window. this holds while the window ignores mouse events
242
+ // too, since the hit test then skips the window itself
243
+
244
+ NSInteger hit = [NSWindow
245
+ windowNumberAtPoint: screen_pos
246
+ belowWindowWithWindowNumber: 0];
247
+ if (hit == 0 || hit == native.windowNumber)
248
+ return false;
249
+
250
+ NSInteger behind = [NSWindow
251
+ windowNumberAtPoint: screen_pos
252
+ belowWindowWithWindowNumber: native.windowNumber];
253
+ return hit != behind;
254
+ }
255
+
256
+ bool
257
+ Window_is_pointer_over_and_uncovered (Point* position, const Window& window)
258
+ {
259
+ NativeWindow* native = get_native(&window);
260
+ NSPoint screen_pos = [NSEvent mouseLocation];
261
+ if (!NSPointInRect(screen_pos, native.frame))
262
+ return false;
263
+ if (is_covered_by_another_window(native, screen_pos))
264
+ return false;
265
+
266
+ NSRect screen_rect = NSMakeRect(screen_pos.x, screen_pos.y, 0, 0);
267
+ NSRect window_rect = [native convertRectFromScreen: screen_rect];
268
+ NSView* view = native.contentView;
269
+ NSPoint view_pos = [view convertPoint: window_rect.origin fromView: nil];
270
+ position->reset(view_pos.x, view.bounds.size.height - view_pos.y);
271
+ return true;
272
+ }
273
+
181
274
 
182
275
  }// Reflex
data/src/pin.cpp ADDED
@@ -0,0 +1,137 @@
1
+ #include "reflex/pin.h"
2
+
3
+
4
+ #include "reflex/exception.h"
5
+ #include "view.h"
6
+ #include "constraint.h"
7
+
8
+
9
+ namespace Reflex
10
+ {
11
+
12
+
13
+ struct Pin::Data
14
+ {
15
+
16
+ Xot::WeakRef<View> view;
17
+
18
+ std::unique_ptr<Point> pposition;
19
+
20
+ };// Pin::Data
21
+
22
+
23
+ template <typename T>
24
+ static T*
25
+ setup_constraint (
26
+ T* constraint,
27
+ View* view0, const Point* position0,
28
+ View* view1, const Point* position1)
29
+ {
30
+ if (!view0)
31
+ invalid_state_error(__FILE__, __LINE__, "the pin has no view");
32
+
33
+ Constraint_set_pins(constraint, view0, position0, view1, position1);
34
+ View_add_constraint(view0, constraint);
35
+ return constraint;
36
+ }
37
+
38
+
39
+ Pin::Pin ()
40
+ {
41
+ }
42
+
43
+ Pin::Pin (coord x, coord y)
44
+ : Pin(NULL, Point(x, y))
45
+ {
46
+ }
47
+
48
+ Pin::Pin (const Point& position)
49
+ : Pin(NULL, position)
50
+ {
51
+ }
52
+
53
+ Pin::Pin (View* view)
54
+ {
55
+ self->view = view;
56
+ }
57
+
58
+ Pin::Pin (View* view, coord x, coord y)
59
+ : Pin(view, Point(x, y))
60
+ {
61
+ }
62
+
63
+ Pin::Pin (View* view, const Point& position)
64
+ {
65
+ self->view = view;
66
+ self->pposition.reset(new Point(position));
67
+ }
68
+
69
+ SnapConstraint*
70
+ Pin::snap (Pin target)
71
+ {
72
+ return setup_constraint(
73
+ Xot::Ref<SnapConstraint>(SnapConstraint_create()).get(),
74
+ view(), position(), target.view(), target.position());
75
+ }
76
+
77
+ LinkConstraint*
78
+ Pin::link (Pin target)
79
+ {
80
+ return setup_constraint(
81
+ Xot::Ref<LinkConstraint>(LinkConstraint_create()).get(),
82
+ view(), position(), target.view(), target.position());
83
+ }
84
+
85
+ WheelConstraint*
86
+ Pin::wheel (Pin target)
87
+ {
88
+ return setup_constraint(
89
+ Xot::Ref<WheelConstraint>(WheelConstraint_create()).get(),
90
+ view(), position(), target.view(), target.position());
91
+ }
92
+
93
+ ChaseConstraint*
94
+ Pin::chase (Pin target)
95
+ {
96
+ if (target.view() && target.view() == view())
97
+ argument_error(__FILE__, __LINE__, "can not chase itself");
98
+
99
+ ChaseConstraint* chase = setup_constraint(
100
+ Xot::Ref<ChaseConstraint>(ChaseConstraint_create()).get(),
101
+ view(), position(), NULL, NULL);
102
+ chase->set_target(target);
103
+ return chase;
104
+ }
105
+
106
+ View*
107
+ Pin::view ()
108
+ {
109
+ return self->view.get();
110
+ }
111
+
112
+ const View*
113
+ Pin::view () const
114
+ {
115
+ return const_cast<Pin*>(this)->view();
116
+ }
117
+
118
+ const Point*
119
+ Pin::position () const
120
+ {
121
+ return self->pposition ? self->pposition.get() : NULL;
122
+ }
123
+
124
+ Pin::operator bool () const
125
+ {
126
+ return true;
127
+ }
128
+
129
+ bool
130
+ Pin::operator ! () const
131
+ {
132
+ return !operator bool();
133
+ }
134
+
135
+
136
+ }// Reflex
137
+
data/src/pointer.cpp CHANGED
@@ -29,13 +29,11 @@ namespace Reflex
29
29
 
30
30
  DRAG = Xot::bit(0, TYPE_LAST),
31
31
 
32
- ENTER = Xot::bit(1, TYPE_LAST),
32
+ FLOATABLE = Xot::bit(1, TYPE_LAST),
33
33
 
34
- EXIT = Xot::bit(2, TYPE_LAST),
34
+ HAS_SYSTEM_ID = Xot::bit(2, TYPE_LAST),
35
35
 
36
- HAS_SYSTEM_ID = Xot::bit(3, TYPE_LAST),
37
-
38
- HAS_PREV_POS = Xot::bit(4, TYPE_LAST),
36
+ HAS_PREV_POS = Xot::bit(3, TYPE_LAST),
39
37
 
40
38
  };// Flag
41
39
 
@@ -56,23 +54,15 @@ namespace Reflex
56
54
  Data (
57
55
  ID id = -1, uint types = TYPE_NONE, Action action = ACTION_NONE,
58
56
  const Point& position = 0, uint modifiers = 0, uint click_count = 0,
59
- bool drag = false, bool enter = false, bool exit = false,
57
+ bool drag = false,
60
58
  double time = 0)
61
59
  : id(id), types(types), action(action),
62
60
  position(position), modifiers(modifiers), click_count(click_count),
63
- flags(make_flags(drag, enter, exit)),
61
+ flags(drag ? DRAG : 0),
64
62
  time(time)
65
63
  {
66
64
  }
67
65
 
68
- uint make_flags (bool drag, bool enter, bool exit)
69
- {
70
- return
71
- (drag ? DRAG : 0) |
72
- (enter ? ENTER : 0) |
73
- (exit ? EXIT : 0);
74
- }
75
-
76
66
  bool is_valid () const
77
67
  {
78
68
  return id >= 0 && types != TYPE_NONE && action != ACTION_NONE;
@@ -96,6 +86,36 @@ namespace Reflex
96
86
  it->self->id = id;
97
87
  }
98
88
 
89
+ void
90
+ Pointer_set_types (Pointer* it, uint types)
91
+ {
92
+ it->self->types = types;
93
+ }
94
+
95
+ void
96
+ Pointer_set_action (Pointer* it, Pointer::Action action)
97
+ {
98
+ it->self->action = action;
99
+ }
100
+
101
+ void
102
+ Pointer_set_time (Pointer* it, double time)
103
+ {
104
+ it->self->time = time;
105
+ }
106
+
107
+ void
108
+ Pointer_set_floatable (Pointer* it, bool floatable)
109
+ {
110
+ Xot::update_flag(&it->self->flags, Pointer::Data::FLOATABLE, floatable);
111
+ }
112
+
113
+ bool
114
+ Pointer_is_floatable (const Pointer& it)
115
+ {
116
+ return Xot::has_flag(it.self->flags, Pointer::Data::FLOATABLE);
117
+ }
118
+
99
119
  void
100
120
  Pointer_add_flag (Pointer* it, uint flag)
101
121
  {
@@ -167,7 +187,7 @@ namespace Reflex
167
187
  double time)
168
188
  : self(new Data(
169
189
  id, types, action,
170
- position, modifiers, click_count, drag, false, false,
190
+ position, modifiers, click_count, drag,
171
191
  time))
172
192
  {
173
193
  }
data/src/pointer.h CHANGED
@@ -16,6 +16,16 @@ namespace Reflex
16
16
 
17
17
  void Pointer_set_id (Pointer* it, Pointer::ID id);
18
18
 
19
+ void Pointer_set_types (Pointer* it, uint types);
20
+
21
+ void Pointer_set_action (Pointer* it, Pointer::Action action);
22
+
23
+ void Pointer_set_time (Pointer* it, double time);
24
+
25
+ void Pointer_set_floatable (Pointer* it, bool floatable);
26
+
27
+ bool Pointer_is_floatable (const Pointer& it);
28
+
19
29
  void Pointer_add_flag (Pointer* it, uint flag);
20
30
 
21
31
  void Pointer_remove_flag (Pointer* it, uint flag);
data/src/rays.h ADDED
@@ -0,0 +1,46 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_SRC_RAYS_H__
4
+ #define __REFLEX_SRC_RAYS_H__
5
+
6
+
7
+ #include <rays/color.h>
8
+ #include <rays/bitmap.h>
9
+ #include <rays/painter.h>
10
+
11
+ #if defined(OSX) && defined(__OBJC__)
12
+ @class NSImage;
13
+ #elif defined(WIN32)
14
+ #include <xot/windows.h>
15
+ #endif
16
+
17
+
18
+ namespace Rays
19
+ {
20
+
21
+
22
+ bool Painter_get_pixel (Color* color, Painter* painter, coord x, coord y);
23
+
24
+
25
+ #if defined(OSX) && defined(__OBJC__)
26
+
27
+ NSImage* Bitmap_get_nsimage (const Bitmap& bitmap);
28
+
29
+ #endif
30
+
31
+
32
+ #ifdef WIN32
33
+
34
+ void Rays_set_pre_init_fun (void (*)());
35
+
36
+ HBITMAP Bitmap_get_hbitmap (const Bitmap& bitmap);
37
+
38
+ const PIXELFORMATDESCRIPTOR* OpenGL_get_pixel_format_descriptor ();
39
+
40
+ #endif
41
+
42
+
43
+ }// Rays
44
+
45
+
46
+ #endif//EOH