reflexion 0.1.6 → 0.1.7

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 (225) hide show
  1. checksums.yaml +7 -0
  2. data/.doc/ext/reflex/application.cpp +54 -39
  3. data/.doc/ext/reflex/capture_event.cpp +87 -0
  4. data/.doc/ext/reflex/draw_event.cpp +103 -0
  5. data/.doc/ext/reflex/event.cpp +73 -0
  6. data/.doc/ext/reflex/focus_event.cpp +98 -0
  7. data/.doc/ext/reflex/frame_event.cpp +133 -0
  8. data/.doc/ext/reflex/image_view.cpp +74 -0
  9. data/.doc/ext/reflex/key_event.cpp +124 -0
  10. data/.doc/ext/reflex/native.cpp +45 -6
  11. data/.doc/ext/reflex/pointer_event.cpp +181 -0
  12. data/.doc/ext/reflex/reflex.cpp +17 -41
  13. data/.doc/ext/reflex/scroll_event.cpp +141 -0
  14. data/.doc/ext/reflex/selector.cpp +135 -0
  15. data/.doc/ext/reflex/style.cpp +253 -0
  16. data/.doc/ext/reflex/style_length.cpp +133 -0
  17. data/.doc/ext/reflex/style_length2.cpp +149 -0
  18. data/.doc/ext/reflex/style_length4.cpp +192 -0
  19. data/.doc/ext/reflex/update_event.cpp +77 -0
  20. data/.doc/ext/reflex/view.cpp +408 -88
  21. data/.doc/ext/reflex/wheel_event.cpp +146 -0
  22. data/.doc/ext/reflex/window.cpp +95 -92
  23. data/Rakefile +6 -5
  24. data/VERSION +1 -1
  25. data/ext/reflex/application.cpp +67 -49
  26. data/ext/reflex/capture_event.cpp +92 -0
  27. data/ext/reflex/draw_event.cpp +110 -0
  28. data/ext/reflex/event.cpp +77 -0
  29. data/ext/reflex/extconf.rb +18 -68
  30. data/ext/reflex/focus_event.cpp +104 -0
  31. data/ext/reflex/frame_event.cpp +143 -0
  32. data/ext/reflex/image_view.cpp +77 -0
  33. data/ext/reflex/key_event.cpp +133 -0
  34. data/ext/reflex/native.cpp +45 -6
  35. data/ext/reflex/pointer_event.cpp +195 -0
  36. data/ext/reflex/reflex.cpp +21 -47
  37. data/ext/reflex/scroll_event.cpp +152 -0
  38. data/ext/reflex/selector.cpp +144 -0
  39. data/ext/reflex/style.cpp +277 -0
  40. data/ext/reflex/style_length.cpp +140 -0
  41. data/ext/reflex/style_length2.cpp +157 -0
  42. data/ext/reflex/style_length4.cpp +204 -0
  43. data/ext/reflex/update_event.cpp +81 -0
  44. data/ext/reflex/view.cpp +469 -114
  45. data/ext/reflex/wheel_event.cpp +158 -0
  46. data/ext/reflex/window.cpp +130 -123
  47. data/include/reflex/application.h +12 -7
  48. data/include/reflex/defs.h +13 -89
  49. data/include/reflex/event.h +260 -0
  50. data/include/reflex/exception.h +17 -11
  51. data/include/reflex/image_view.h +45 -0
  52. data/include/reflex/reflex.h +2 -6
  53. data/include/reflex/ruby/application.h +40 -13
  54. data/include/reflex/ruby/event.h +72 -0
  55. data/include/reflex/ruby/image_view.h +25 -0
  56. data/include/reflex/ruby/selector.h +27 -0
  57. data/include/reflex/ruby/style.h +27 -0
  58. data/include/reflex/ruby/style_length.h +37 -0
  59. data/include/reflex/ruby/view.h +193 -38
  60. data/include/reflex/ruby/window.h +123 -39
  61. data/include/reflex/ruby.h +3 -2
  62. data/include/reflex/selector.h +64 -0
  63. data/include/reflex/style.h +144 -0
  64. data/include/reflex/style_length.h +147 -0
  65. data/include/reflex/view.h +182 -19
  66. data/include/reflex/window.h +35 -19
  67. data/include/reflex.h +7 -0
  68. data/lib/reflex/application.rb +14 -5
  69. data/lib/reflex/arc_shape.rb +20 -0
  70. data/lib/reflex/button.rb +75 -0
  71. data/lib/reflex/capture_event.rb +37 -0
  72. data/lib/reflex/color.rb +13 -0
  73. data/lib/reflex/color_space.rb +13 -0
  74. data/lib/reflex/draw_event.rb +19 -0
  75. data/lib/reflex/ellipse_shape.rb +20 -0
  76. data/lib/reflex/ext.rb +1 -1
  77. data/lib/reflex/flags.rb +18 -0
  78. data/lib/reflex/focus_event.rb +38 -0
  79. data/lib/reflex/font.rb +13 -0
  80. data/lib/reflex/frame_event.rb +42 -0
  81. data/lib/reflex/helper.rb +87 -30
  82. data/lib/reflex/image_view.rb +25 -0
  83. data/lib/reflex/key_event.rb +38 -0
  84. data/lib/reflex/line_shape.rb +20 -0
  85. data/lib/reflex/list_view.rb +15 -0
  86. data/lib/reflex/model.rb +149 -0
  87. data/lib/reflex/model_owner.rb +57 -0
  88. data/lib/reflex/model_view.rb +22 -0
  89. data/lib/reflex/module.rb +11 -7
  90. data/lib/reflex/pointer_event.rb +85 -0
  91. data/lib/reflex/rect_shape.rb +20 -0
  92. data/lib/reflex/reflex.rb +13 -2
  93. data/lib/reflex/scroll_event.rb +19 -0
  94. data/lib/reflex/selector.rb +31 -0
  95. data/lib/reflex/shader.rb +13 -0
  96. data/lib/reflex/shape.rb +34 -0
  97. data/lib/reflex/style.rb +55 -0
  98. data/lib/reflex/style_length.rb +30 -0
  99. data/lib/reflex/style_length2.rb +34 -0
  100. data/lib/reflex/style_length4.rb +38 -0
  101. data/lib/reflex/text_view.rb +55 -0
  102. data/lib/reflex/update_event.rb +19 -0
  103. data/lib/reflex/view.rb +38 -4
  104. data/lib/reflex/wheel_event.rb +19 -0
  105. data/lib/reflex/window.rb +7 -5
  106. data/lib/reflex.rb +38 -1
  107. data/lib/reflexion/include.rb +5 -0
  108. data/lib/reflexion.rb +100 -0
  109. data/reflex.gemspec +3 -4
  110. data/samples/app.rb +13 -0
  111. data/samples/bats.rb +91 -0
  112. data/samples/checker.rb +36 -0
  113. data/{examples/ruby/shapes.rb → samples/fans.rb} +12 -16
  114. data/samples/fps.rb +46 -0
  115. data/samples/grid.rb +60 -0
  116. data/{examples/ruby → samples}/hello.rb +14 -16
  117. data/samples/image.rb +44 -0
  118. data/samples/ios/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  119. data/samples/ios/hello/hello/Images.xcassets/LaunchImage.launchimage/Contents.json +51 -0
  120. data/samples/ios/hello/hello/en.lproj/InfoPlist.strings +2 -0
  121. data/samples/ios/hello/hello/hello-Info.plist +47 -0
  122. data/samples/ios/hello/hello/hello-Prefix.pch +10 -0
  123. data/samples/ios/hello/hello/main.cpp +79 -0
  124. data/samples/ios/hello/hello.xcodeproj/project.pbxproj +725 -0
  125. data/{examples/ruby → samples}/key.rb +11 -14
  126. data/samples/layout.rb +89 -0
  127. data/samples/model.rb +86 -0
  128. data/samples/osx/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +58 -0
  129. data/samples/osx/hello/hello/en.lproj/Credits.rtf +29 -0
  130. data/samples/osx/hello/hello/en.lproj/InfoPlist.strings +2 -0
  131. data/samples/osx/hello/hello/hello-Info.plist +32 -0
  132. data/samples/osx/hello/hello/hello-Prefix.pch +3 -0
  133. data/samples/osx/hello/hello/main.cpp +79 -0
  134. data/samples/osx/hello/hello.xcodeproj/project.pbxproj +725 -0
  135. data/samples/reflexion/hello.rb +24 -0
  136. data/samples/reflexion/paint.rb +40 -0
  137. data/samples/reflexion/pulse.rb +34 -0
  138. data/samples/repl.rb +69 -0
  139. data/samples/shader.rb +41 -0
  140. data/samples/shapes.rb +30 -0
  141. data/{examples/ruby → samples}/text.rb +7 -8
  142. data/samples/tree.rb +71 -0
  143. data/samples/views.rb +41 -0
  144. data/samples/visuals.rb +22 -0
  145. data/src/event.cpp +225 -0
  146. data/src/exception.cpp +24 -15
  147. data/src/image_view.cpp +70 -0
  148. data/src/ios/app_delegate.h +17 -0
  149. data/src/ios/app_delegate.mm +120 -0
  150. data/src/ios/application.mm +116 -0
  151. data/src/{cocoa/applicationdata.h → ios/application_data.h} +6 -6
  152. data/src/ios/event.h +26 -0
  153. data/src/ios/event.mm +31 -0
  154. data/src/ios/native_window.h +37 -0
  155. data/src/ios/native_window.mm +220 -0
  156. data/src/ios/opengl_view.h +13 -0
  157. data/src/ios/opengl_view.mm +131 -0
  158. data/src/{cocoa → ios}/reflex.mm +8 -12
  159. data/src/ios/window.mm +303 -0
  160. data/src/ios/window_data.h +75 -0
  161. data/src/osx/app_delegate.h +17 -0
  162. data/src/{cocoa/cocoaapplication.mm → osx/app_delegate.mm} +90 -48
  163. data/src/osx/application.mm +132 -0
  164. data/src/osx/application_data.h +45 -0
  165. data/src/osx/event.h +42 -0
  166. data/src/osx/event.mm +112 -0
  167. data/src/osx/native_window.h +26 -0
  168. data/src/osx/native_window.mm +322 -0
  169. data/src/{cocoa/openglview.h → osx/opengl_view.h} +0 -4
  170. data/src/{cocoa/openglview.mm → osx/opengl_view.mm} +66 -23
  171. data/src/osx/reflex.mm +50 -0
  172. data/src/osx/window.mm +308 -0
  173. data/src/osx/window_data.h +75 -0
  174. data/src/selector.cpp +121 -0
  175. data/src/style.cpp +576 -0
  176. data/src/style_length.cpp +341 -0
  177. data/src/view.cpp +1228 -129
  178. data/src/win32/application.cpp +1 -1
  179. data/src/window.cpp +54 -26
  180. data/test/helper.rb +8 -4
  181. data/test/test_capture_event.rb +41 -0
  182. data/test/test_event.rb +20 -0
  183. data/test/test_has_frame.rb +45 -0
  184. data/test/test_model.rb +9 -0
  185. data/test/test_model_owner.rb +9 -0
  186. data/test/test_selector.rb +75 -0
  187. data/test/test_style.rb +70 -0
  188. data/test/test_style_length.rb +38 -0
  189. data/test/test_style_length2.rb +50 -0
  190. data/test/test_style_length4.rb +56 -0
  191. data/test/test_view.rb +97 -23
  192. data/test/test_window.rb +54 -46
  193. metadata +205 -84
  194. data/.doc/ext/reflex/defs.cpp +0 -8
  195. data/.doc/ext/reflex/key.cpp +0 -122
  196. data/.doc/ext/reflex/points.cpp +0 -151
  197. data/.gitignore +0 -14
  198. data/ChangeLog +0 -8
  199. data/examples/hello/.gitignore +0 -2
  200. data/examples/hello/Rakefile +0 -41
  201. data/examples/hello/main.cpp +0 -18
  202. data/examples/ruby/app.rb +0 -13
  203. data/examples/ruby/checker.rb +0 -41
  204. data/examples/ruby/fps.rb +0 -49
  205. data/examples/ruby/grid.rb +0 -65
  206. data/examples/ruby/views.rb +0 -88
  207. data/examples/ruby/visuals.rb +0 -27
  208. data/ext/reflex/defs.cpp +0 -8
  209. data/ext/reflex/key.cpp +0 -129
  210. data/ext/reflex/points.cpp +0 -161
  211. data/include/reflex/ruby/key.h +0 -39
  212. data/include/reflex/ruby/points.h +0 -39
  213. data/lib/reflex/visuals/string.rb +0 -53
  214. data/src/cocoa/application.mm +0 -101
  215. data/src/cocoa/cocoaapplication.h +0 -21
  216. data/src/cocoa/cocoawindow.h +0 -46
  217. data/src/cocoa/cocoawindow.mm +0 -230
  218. data/src/cocoa/defs.h +0 -34
  219. data/src/cocoa/defs.mm +0 -87
  220. data/src/cocoa/window.mm +0 -148
  221. data/src/cocoa/windowdata.h +0 -56
  222. data/src/defs.cpp +0 -47
  223. data/src/helper.h +0 -12
  224. data/src/reflex.cpp +0 -43
  225. /data/{README → README.md} +0 -0
@@ -0,0 +1,70 @@
1
+ #include "reflex/image_view.h"
2
+
3
+
4
+ #include <assert.h>
5
+ #include "reflex/exception.h"
6
+
7
+
8
+ namespace Reflex
9
+ {
10
+
11
+
12
+ struct ImageView::Data
13
+ {
14
+
15
+ Image image;
16
+
17
+ };// ImageView::Data
18
+
19
+
20
+ ImageView::ImageView (const char* name)
21
+ : Super(name)
22
+ {
23
+ }
24
+
25
+ ImageView::~ImageView ()
26
+ {
27
+ }
28
+
29
+ void
30
+ ImageView::set_image (Image image)
31
+ {
32
+ self->image = image;
33
+ redraw();
34
+ }
35
+
36
+ Image
37
+ ImageView::get_image () const
38
+ {
39
+ return self->image;
40
+ }
41
+
42
+ Rays::Point
43
+ ImageView::content_size () const
44
+ {
45
+ if (self->image)
46
+ return Point(self->image.width(), self->image.height());
47
+ else
48
+ return Super::content_size();
49
+ }
50
+
51
+ void
52
+ ImageView::on_draw (DrawEvent* e)
53
+ {
54
+ if (!self->image) return;
55
+
56
+ assert(e && e->painter);
57
+ Painter* p = e->painter;
58
+
59
+ Color f = p->fill(), s = p->stroke();
60
+ p->set_fill(1);
61
+ p->no_stroke();
62
+
63
+ p->image(self->image);
64
+
65
+ p->set_fill(f);
66
+ p->set_stroke(s);
67
+ }
68
+
69
+
70
+ }// Reflex
@@ -0,0 +1,17 @@
1
+ // -*- objc -*-
2
+ #import <UIKit/UIApplication.h>
3
+ #include <reflex/application.h>
4
+
5
+
6
+ @interface AppDelegate : UIResponder <UIApplicationDelegate>
7
+
8
+ {
9
+ @private
10
+ Reflex::Application::Ref* pref;
11
+ }
12
+
13
+ - (void) bind: (Reflex::Application*) instance;
14
+
15
+ - (void) unbind: (Reflex::Application*) instance;
16
+
17
+ @end// AppDelegate
@@ -0,0 +1,120 @@
1
+ // -*- objc -*-
2
+ #import "app_delegate.h"
3
+
4
+
5
+ #include <assert.h>
6
+ #include "reflex/event.h"
7
+ #include "reflex/exception.h"
8
+ #include "application_data.h"
9
+
10
+
11
+ #define REF (*pref)
12
+
13
+
14
+ @implementation AppDelegate
15
+
16
+ - (id) init
17
+ {
18
+ self = [super init];
19
+ if (!self) return nil;
20
+
21
+ pref = new Reflex::Application::Ref;
22
+
23
+ return self;
24
+ }
25
+
26
+ - (void) dealloc
27
+ {
28
+ assert(pref && !REF);
29
+
30
+ delete pref;
31
+
32
+ [super dealloc];
33
+ }
34
+
35
+ - (void) bind: (Reflex::Application*) instance
36
+ {
37
+ assert(pref);
38
+
39
+ if (instance && instance->self->delegate)
40
+ Reflex::argument_error(__FILE__, __LINE__);
41
+
42
+ if (REF)
43
+ Reflex::invalid_state_error(__FILE__, __LINE__);
44
+
45
+ REF = instance;
46
+ if (REF) REF->self->delegate = [self retain];
47
+ }
48
+
49
+ - (void) unbind: (Reflex::Application*) instance
50
+ {
51
+ assert(pref);
52
+
53
+ if (!REF) return;
54
+
55
+ if (instance && instance != REF.get())
56
+ Reflex::invalid_state_error(__FILE__, __LINE__);
57
+
58
+ if (REF->self->delegate) [REF->self->delegate release];
59
+ REF->self->delegate = nil;
60
+ REF.reset();
61
+ }
62
+
63
+ - (BOOL) application: (UIApplication*) application
64
+ didFinishLaunchingWithOptions: (NSDictionary*) options
65
+ {
66
+ if (!Reflex::app())
67
+ {
68
+ Reflex::invalid_state_error(
69
+ __FILE__, __LINE__,
70
+ "no Application instance on application:didFinishLaunchingWithOptions:");
71
+ }
72
+
73
+ [self bind: Reflex::app()];
74
+
75
+ if (REF)
76
+ {
77
+ Reflex::Event e;
78
+ REF->on_start(&e);
79
+ if (e.is_blocked())
80
+ {
81
+ return NO;
82
+ }
83
+ }
84
+
85
+ return YES;
86
+ }
87
+
88
+ - (void) applicationWillResignActive: (UIApplication*) application
89
+ {
90
+ }
91
+
92
+ - (void) applicationDidEnterBackground: (UIApplication*) application
93
+ {
94
+ }
95
+
96
+ - (void) applicationWillEnterForeground: (UIApplication*) application
97
+ {
98
+ }
99
+
100
+ - (void) applicationDidBecomeActive: (UIApplication*) application
101
+ {
102
+ }
103
+
104
+ - (void) applicationWillTerminate: (UIApplication*) application
105
+ {
106
+ if (REF)
107
+ {
108
+ Reflex::Event e;
109
+ REF->on_quit(&e);
110
+ if (e.is_blocked())
111
+ {
112
+ Reflex::not_implemented_error(
113
+ __FILE__, __LINE__, "blocking to quit is not supported.");
114
+ }
115
+ }
116
+
117
+ [self unbind: NULL];
118
+ }
119
+
120
+ @end// AppDelegate
@@ -0,0 +1,116 @@
1
+ // -*- objc -*-
2
+ #include "reflex/application.h"
3
+
4
+
5
+ #include <assert.h>
6
+ #include <crt_externs.h>
7
+ #include "reflex/exception.h"
8
+ #include "application_data.h"
9
+ #import "app_delegate.h"
10
+
11
+
12
+ namespace Reflex
13
+ {
14
+
15
+
16
+ bool initialized ();
17
+
18
+
19
+ static Application* instance = NULL;
20
+
21
+
22
+ Application*
23
+ app ()
24
+ {
25
+ return instance;
26
+ }
27
+
28
+
29
+ Application::Application ()
30
+ {
31
+ if (!initialized())
32
+ reflex_error(__FILE__, __LINE__, "not initialized.");
33
+
34
+ if (instance)
35
+ reflex_error(__FILE__, __LINE__, "multiple application instances.");
36
+
37
+ instance = this;
38
+ }
39
+
40
+ Application::~Application ()
41
+ {
42
+ instance = NULL;
43
+ }
44
+
45
+ void
46
+ Application::start ()
47
+ {
48
+ UIApplicationMain(
49
+ *_NSGetArgc(), *_NSGetArgv(), nil, NSStringFromClass([AppDelegate class]));
50
+ }
51
+
52
+ void
53
+ Application::quit ()
54
+ {
55
+ if (!*this)
56
+ invalid_state_error(__FILE__, __LINE__);
57
+
58
+ not_implemented_error(__FILE__, __LINE__);
59
+ }
60
+
61
+ void
62
+ Application::set_name (const char* name)
63
+ {
64
+ if (!name)
65
+ argument_error(__FILE__, __LINE__);
66
+
67
+ self->name = name;
68
+ }
69
+
70
+ const char*
71
+ Application::name () const
72
+ {
73
+ return self->name.c_str();
74
+ }
75
+
76
+ void
77
+ Application::on_start (Event* e)
78
+ {
79
+ if (!*this)
80
+ invalid_state_error(__FILE__, __LINE__);
81
+ }
82
+
83
+ void
84
+ Application::on_quit (Event* e)
85
+ {
86
+ if (!*this)
87
+ invalid_state_error(__FILE__, __LINE__);
88
+ }
89
+
90
+ void
91
+ Application::on_preference (Event* e)
92
+ {
93
+ if (!*this)
94
+ invalid_state_error(__FILE__, __LINE__);
95
+ }
96
+
97
+ void
98
+ Application::on_about (Event* e)
99
+ {
100
+ if (!*this)
101
+ invalid_state_error(__FILE__, __LINE__);
102
+ }
103
+
104
+ Application::operator bool () const
105
+ {
106
+ return self && *self;
107
+ }
108
+
109
+ bool
110
+ Application::operator ! () const
111
+ {
112
+ return !operator bool();
113
+ }
114
+
115
+
116
+ }// Reflex
@@ -1,13 +1,13 @@
1
1
  // -*- c++ -*-
2
2
  #pragma once
3
- #ifndef __REFLEX_COCOA_APPLICATIONDATA_H__
4
- #define __REFLEX_COCOA_APPLICATIONDATA_H__
3
+ #ifndef __REFLEX_IOS_APPLICATION_DATA_H__
4
+ #define __REFLEX_IOS_APPLICATION_DATA_H__
5
5
 
6
6
 
7
7
  #include <reflex/application.h>
8
8
 
9
9
 
10
- @class CocoaApplication;
10
+ @class AppDelegate;
11
11
 
12
12
 
13
13
  namespace Reflex
@@ -17,18 +17,18 @@ namespace Reflex
17
17
  struct Application::Data
18
18
  {
19
19
 
20
- CocoaApplication* cocoa;
20
+ AppDelegate* delegate;
21
21
 
22
22
  String name;
23
23
 
24
24
  Data ()
25
- : cocoa(nil)
25
+ : delegate(nil)
26
26
  {
27
27
  }
28
28
 
29
29
  operator bool () const
30
30
  {
31
- return cocoa;
31
+ return delegate;
32
32
  }
33
33
 
34
34
  bool operator ! () const
data/src/ios/event.h ADDED
@@ -0,0 +1,26 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_IOS_EVENT_H__
4
+ #define __REFLEX_IOS_EVENT_H__
5
+
6
+
7
+ #import <UIKit/UIEvent.h>
8
+ #include <reflex/event.h>
9
+
10
+
11
+ namespace Reflex
12
+ {
13
+
14
+
15
+ struct NativePointerEvent : public PointerEvent
16
+ {
17
+
18
+ NativePointerEvent (NSSet* touches, UIEvent* event, UIView* view, Type type);
19
+
20
+ };// NativePointerEvent
21
+
22
+
23
+ }// Reflex
24
+
25
+
26
+ #endif//EOH
data/src/ios/event.mm ADDED
@@ -0,0 +1,31 @@
1
+ // -*- c++ -*-
2
+ #include "event.h"
3
+
4
+
5
+ #include <assert.h>
6
+
7
+
8
+ namespace Reflex
9
+ {
10
+
11
+
12
+ static CGPoint
13
+ correct_point (UIView* view, UITouch* touch)
14
+ {
15
+ assert(view && touch);
16
+ CGPoint p = [touch locationInView: view];
17
+ p.y = [view bounds].size.height - p.y;
18
+ return p;
19
+ }
20
+
21
+
22
+ NativePointerEvent::NativePointerEvent (NSSet* touches, UIEvent* e, UIView* view, Type type)
23
+ : PointerEvent(type, POINTER_TOUCH, (coord) 0, (coord) 0)
24
+ {
25
+ CGPoint p = correct_point(view, [touches anyObject]);
26
+ x = p.x;
27
+ y = p.y;
28
+ }
29
+
30
+
31
+ };// Reflex
@@ -0,0 +1,37 @@
1
+ // -*- objc -*-
2
+ #import <UIKit/UIWindow.h>
3
+ #include <reflex/window.h>
4
+
5
+
6
+ @class OpenGLViewController;
7
+
8
+
9
+ @interface NativeWindow : UIWindow
10
+
11
+ {
12
+ @private
13
+ Reflex::Window::Ref* pref;
14
+ OpenGLViewController* view_controller;
15
+ }
16
+
17
+ - (void) bind: (Reflex::Window*) instance;
18
+
19
+ - (void) unbind: (Reflex::Window*) instance;
20
+
21
+ - (void) draw;
22
+
23
+ - (void) keyDown: (UIEvent*) event;
24
+
25
+ - (void) keyUp: (UIEvent*) event;
26
+
27
+ - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
28
+
29
+ - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
30
+
31
+ - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
32
+
33
+ - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
34
+
35
+ + (CGRect) frameRectForContentRect: (CGRect) contentRect;
36
+
37
+ @end// NativeWindow
@@ -0,0 +1,220 @@
1
+ // -*- objc -*-
2
+ #import "native_window.h"
3
+
4
+
5
+ #include <assert.h>
6
+ #include <rays/bounds.h>
7
+ #include "reflex/window.h"
8
+ #include "reflex/exception.h"
9
+ #include "event.h"
10
+ #include "window_data.h"
11
+ #import "opengl_view.h"
12
+
13
+
14
+ #define REF (*pref)
15
+
16
+
17
+ static CGRect device_frame ()
18
+ {
19
+ return [[UIScreen mainScreen] applicationFrame];
20
+ }
21
+
22
+
23
+ @implementation NativeWindow
24
+
25
+ - (id) init
26
+ {
27
+ self = [super initWithFrame: device_frame()];
28
+ if (!self) return nil;
29
+
30
+ pref = new Reflex::Window::Ref;
31
+ view_controller = [[OpenGLViewController alloc] initWithNibName: nil bundle: nil];
32
+
33
+ self.rootViewController = view_controller;
34
+
35
+ return self;
36
+ }
37
+
38
+ - (void) dealloc
39
+ {
40
+ assert(pref);
41
+
42
+ self.rootViewController = nil;
43
+ if (view_controller) [view_controller release];
44
+
45
+ [self unbind: NULL];
46
+ delete pref;
47
+
48
+ [super dealloc];
49
+ }
50
+
51
+ - (void) bind: (Reflex::Window*) instance
52
+ {
53
+ assert(pref);
54
+
55
+ if (instance && instance->self->native)
56
+ Reflex::argument_error(__FILE__, __LINE__);
57
+
58
+ if (REF)
59
+ Reflex::invalid_state_error(__FILE__, __LINE__);
60
+
61
+ REF = instance;
62
+ if (REF) REF->self->native = [self retain];
63
+ }
64
+
65
+ - (void) unbind: (Reflex::Window*) instance
66
+ {
67
+ assert(pref);
68
+
69
+ if (!REF) return;
70
+
71
+ if (instance && instance != REF.get())
72
+ Reflex::invalid_state_error(__FILE__, __LINE__);
73
+
74
+ if (REF->self->native) [REF->self->native release];
75
+ REF->self->native = nil;
76
+ REF.reset();
77
+ }
78
+
79
+ - (void) update
80
+ {
81
+ assert(pref);
82
+
83
+ if (!REF) return;
84
+
85
+ double now = Xot::time();
86
+ Reflex::UpdateEvent e(now - REF->self->prev_time_update);
87
+ REF->self->prev_time_update = now;
88
+
89
+ REF->on_update(&e);
90
+ }
91
+
92
+ - (void) draw
93
+ {
94
+ assert(pref);
95
+
96
+ if (!REF || !REF->self->redraw) return;
97
+
98
+ REF->self->redraw = false;
99
+
100
+ double now = Xot::time();
101
+ double dt = now - REF->self->prev_time_draw;
102
+ double fps = 1. / dt;
103
+
104
+ fps = REF->self->prev_fps * 0.9 + fps * 0.1;// LPF
105
+ REF->self->prev_time_draw = now;
106
+ REF->self->prev_fps = fps;
107
+
108
+ Reflex::DrawEvent e(dt, fps);
109
+
110
+ e.painter = REF->painter();
111
+ if (!e.painter)
112
+ Xot::invalid_state_error(__FILE__, __LINE__);
113
+
114
+ Rays::Bounds b = REF->frame();
115
+ e.bounds.reset(0, 0, b.width, b.height);
116
+
117
+ e.painter->begin();
118
+ REF->on_draw(&e);
119
+ e.painter->end();
120
+ }
121
+
122
+ - (void) frameChanged
123
+ {
124
+ assert(pref);
125
+
126
+ if (!REF) return;
127
+
128
+ Rays::Bounds b = REF->frame();
129
+ Rays::Point dpos = b.position() - REF->self->prev_position;
130
+ Rays::Point dsize = b.size() - REF->self->prev_size;
131
+ REF->self->prev_position = b.position();
132
+ REF->self->prev_size = b.size();
133
+
134
+ if (dpos != 0 || dsize != 0)
135
+ {
136
+ Reflex::FrameEvent e(b, dpos.x, dpos.y, dsize.x, dsize.y);
137
+ if (dpos != 0) REF->on_move(&e);
138
+ if (dsize != 0)
139
+ {
140
+ Rays::Bounds b = REF->frame();
141
+ b.move_to(0, 0);
142
+ if (REF->painter()) REF->painter()->canvas(b);
143
+ if (REF->root()) REF->root()->set_frame(b);
144
+ REF->on_resize(&e);
145
+ }
146
+ }
147
+ }
148
+
149
+ - (void) becomeKeyWindow
150
+ {
151
+ [super becomeKeyWindow];
152
+ [self frameChanged];
153
+ }
154
+
155
+ - (void) keyDown: (UIEvent*) event
156
+ {
157
+ assert(pref);
158
+
159
+ if (!REF) return;
160
+
161
+ //Reflex::NativeKeyEvent e(event, Reflex::KeyEvent::DOWN);
162
+ //REF->on_key(&e);
163
+ }
164
+
165
+ - (void) keyUp: (UIEvent*) event
166
+ {
167
+ assert(pref);
168
+
169
+ if (!REF) return;
170
+
171
+ //Reflex::NativeKeyEvent e(event, Reflex::KeyEvent::UP);
172
+ //REF->on_key(&e);
173
+ }
174
+
175
+ - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
176
+ {
177
+ assert(pref);
178
+
179
+ if (!REF) return;
180
+
181
+ Reflex::NativePointerEvent e(touches, event, view_controller.view, Reflex::PointerEvent::DOWN);
182
+ REF->on_pointer(&e);
183
+ }
184
+
185
+ - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
186
+ {
187
+ assert(pref);
188
+
189
+ if (!REF) return;
190
+
191
+ Reflex::NativePointerEvent e(touches, event, view_controller.view, Reflex::PointerEvent::UP);
192
+ REF->on_pointer(&e);
193
+ }
194
+
195
+ - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
196
+ {
197
+ assert(pref);
198
+
199
+ if (!REF) return;
200
+
201
+ Reflex::NativePointerEvent e(touches, event, view_controller.view, Reflex::PointerEvent::UP);
202
+ REF->on_pointer(&e);
203
+ }
204
+
205
+ - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
206
+ {
207
+ assert(pref);
208
+
209
+ if (!REF) return;
210
+
211
+ Reflex::NativePointerEvent e(touches, event, view_controller.view, Reflex::PointerEvent::MOVE);
212
+ REF->on_pointer(&e);
213
+ }
214
+
215
+ + (CGRect) frameRectForContentRect: (CGRect) contentRect
216
+ {
217
+ return device_frame();
218
+ }
219
+
220
+ @end// NativeWindow
@@ -0,0 +1,13 @@
1
+ // -*- objc -*-
2
+ #import <UIKit/UIKit.h>
3
+ #import <GLKit/GLKit.h>
4
+
5
+
6
+ @interface OpenGLViewController : GLKViewController
7
+
8
+ {
9
+ @private
10
+ EAGLContext* context;
11
+ }
12
+
13
+ @end// OpenGLViewController