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.
- checksums.yaml +7 -0
- data/.doc/ext/reflex/application.cpp +54 -39
- data/.doc/ext/reflex/capture_event.cpp +87 -0
- data/.doc/ext/reflex/draw_event.cpp +103 -0
- data/.doc/ext/reflex/event.cpp +73 -0
- data/.doc/ext/reflex/focus_event.cpp +98 -0
- data/.doc/ext/reflex/frame_event.cpp +133 -0
- data/.doc/ext/reflex/image_view.cpp +74 -0
- data/.doc/ext/reflex/key_event.cpp +124 -0
- data/.doc/ext/reflex/native.cpp +45 -6
- data/.doc/ext/reflex/pointer_event.cpp +181 -0
- data/.doc/ext/reflex/reflex.cpp +17 -41
- data/.doc/ext/reflex/scroll_event.cpp +141 -0
- data/.doc/ext/reflex/selector.cpp +135 -0
- data/.doc/ext/reflex/style.cpp +253 -0
- data/.doc/ext/reflex/style_length.cpp +133 -0
- data/.doc/ext/reflex/style_length2.cpp +149 -0
- data/.doc/ext/reflex/style_length4.cpp +192 -0
- data/.doc/ext/reflex/update_event.cpp +77 -0
- data/.doc/ext/reflex/view.cpp +408 -88
- data/.doc/ext/reflex/wheel_event.cpp +146 -0
- data/.doc/ext/reflex/window.cpp +95 -92
- data/Rakefile +6 -5
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +67 -49
- data/ext/reflex/capture_event.cpp +92 -0
- data/ext/reflex/draw_event.cpp +110 -0
- data/ext/reflex/event.cpp +77 -0
- data/ext/reflex/extconf.rb +18 -68
- data/ext/reflex/focus_event.cpp +104 -0
- data/ext/reflex/frame_event.cpp +143 -0
- data/ext/reflex/image_view.cpp +77 -0
- data/ext/reflex/key_event.cpp +133 -0
- data/ext/reflex/native.cpp +45 -6
- data/ext/reflex/pointer_event.cpp +195 -0
- data/ext/reflex/reflex.cpp +21 -47
- data/ext/reflex/scroll_event.cpp +152 -0
- data/ext/reflex/selector.cpp +144 -0
- data/ext/reflex/style.cpp +277 -0
- data/ext/reflex/style_length.cpp +140 -0
- data/ext/reflex/style_length2.cpp +157 -0
- data/ext/reflex/style_length4.cpp +204 -0
- data/ext/reflex/update_event.cpp +81 -0
- data/ext/reflex/view.cpp +469 -114
- data/ext/reflex/wheel_event.cpp +158 -0
- data/ext/reflex/window.cpp +130 -123
- data/include/reflex/application.h +12 -7
- data/include/reflex/defs.h +13 -89
- data/include/reflex/event.h +260 -0
- data/include/reflex/exception.h +17 -11
- data/include/reflex/image_view.h +45 -0
- data/include/reflex/reflex.h +2 -6
- data/include/reflex/ruby/application.h +40 -13
- data/include/reflex/ruby/event.h +72 -0
- data/include/reflex/ruby/image_view.h +25 -0
- data/include/reflex/ruby/selector.h +27 -0
- data/include/reflex/ruby/style.h +27 -0
- data/include/reflex/ruby/style_length.h +37 -0
- data/include/reflex/ruby/view.h +193 -38
- data/include/reflex/ruby/window.h +123 -39
- data/include/reflex/ruby.h +3 -2
- data/include/reflex/selector.h +64 -0
- data/include/reflex/style.h +144 -0
- data/include/reflex/style_length.h +147 -0
- data/include/reflex/view.h +182 -19
- data/include/reflex/window.h +35 -19
- data/include/reflex.h +7 -0
- data/lib/reflex/application.rb +14 -5
- data/lib/reflex/arc_shape.rb +20 -0
- data/lib/reflex/button.rb +75 -0
- data/lib/reflex/capture_event.rb +37 -0
- data/lib/reflex/color.rb +13 -0
- data/lib/reflex/color_space.rb +13 -0
- data/lib/reflex/draw_event.rb +19 -0
- data/lib/reflex/ellipse_shape.rb +20 -0
- data/lib/reflex/ext.rb +1 -1
- data/lib/reflex/flags.rb +18 -0
- data/lib/reflex/focus_event.rb +38 -0
- data/lib/reflex/font.rb +13 -0
- data/lib/reflex/frame_event.rb +42 -0
- data/lib/reflex/helper.rb +87 -30
- data/lib/reflex/image_view.rb +25 -0
- data/lib/reflex/key_event.rb +38 -0
- data/lib/reflex/line_shape.rb +20 -0
- data/lib/reflex/list_view.rb +15 -0
- data/lib/reflex/model.rb +149 -0
- data/lib/reflex/model_owner.rb +57 -0
- data/lib/reflex/model_view.rb +22 -0
- data/lib/reflex/module.rb +11 -7
- data/lib/reflex/pointer_event.rb +85 -0
- data/lib/reflex/rect_shape.rb +20 -0
- data/lib/reflex/reflex.rb +13 -2
- data/lib/reflex/scroll_event.rb +19 -0
- data/lib/reflex/selector.rb +31 -0
- data/lib/reflex/shader.rb +13 -0
- data/lib/reflex/shape.rb +34 -0
- data/lib/reflex/style.rb +55 -0
- data/lib/reflex/style_length.rb +30 -0
- data/lib/reflex/style_length2.rb +34 -0
- data/lib/reflex/style_length4.rb +38 -0
- data/lib/reflex/text_view.rb +55 -0
- data/lib/reflex/update_event.rb +19 -0
- data/lib/reflex/view.rb +38 -4
- data/lib/reflex/wheel_event.rb +19 -0
- data/lib/reflex/window.rb +7 -5
- data/lib/reflex.rb +38 -1
- data/lib/reflexion/include.rb +5 -0
- data/lib/reflexion.rb +100 -0
- data/reflex.gemspec +3 -4
- data/samples/app.rb +13 -0
- data/samples/bats.rb +91 -0
- data/samples/checker.rb +36 -0
- data/{examples/ruby/shapes.rb → samples/fans.rb} +12 -16
- data/samples/fps.rb +46 -0
- data/samples/grid.rb +60 -0
- data/{examples/ruby → samples}/hello.rb +14 -16
- data/samples/image.rb +44 -0
- data/samples/ios/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- data/samples/ios/hello/hello/Images.xcassets/LaunchImage.launchimage/Contents.json +51 -0
- data/samples/ios/hello/hello/en.lproj/InfoPlist.strings +2 -0
- data/samples/ios/hello/hello/hello-Info.plist +47 -0
- data/samples/ios/hello/hello/hello-Prefix.pch +10 -0
- data/samples/ios/hello/hello/main.cpp +79 -0
- data/samples/ios/hello/hello.xcodeproj/project.pbxproj +725 -0
- data/{examples/ruby → samples}/key.rb +11 -14
- data/samples/layout.rb +89 -0
- data/samples/model.rb +86 -0
- data/samples/osx/hello/hello/Images.xcassets/AppIcon.appiconset/Contents.json +58 -0
- data/samples/osx/hello/hello/en.lproj/Credits.rtf +29 -0
- data/samples/osx/hello/hello/en.lproj/InfoPlist.strings +2 -0
- data/samples/osx/hello/hello/hello-Info.plist +32 -0
- data/samples/osx/hello/hello/hello-Prefix.pch +3 -0
- data/samples/osx/hello/hello/main.cpp +79 -0
- data/samples/osx/hello/hello.xcodeproj/project.pbxproj +725 -0
- data/samples/reflexion/hello.rb +24 -0
- data/samples/reflexion/paint.rb +40 -0
- data/samples/reflexion/pulse.rb +34 -0
- data/samples/repl.rb +69 -0
- data/samples/shader.rb +41 -0
- data/samples/shapes.rb +30 -0
- data/{examples/ruby → samples}/text.rb +7 -8
- data/samples/tree.rb +71 -0
- data/samples/views.rb +41 -0
- data/samples/visuals.rb +22 -0
- data/src/event.cpp +225 -0
- data/src/exception.cpp +24 -15
- data/src/image_view.cpp +70 -0
- data/src/ios/app_delegate.h +17 -0
- data/src/ios/app_delegate.mm +120 -0
- data/src/ios/application.mm +116 -0
- data/src/{cocoa/applicationdata.h → ios/application_data.h} +6 -6
- data/src/ios/event.h +26 -0
- data/src/ios/event.mm +31 -0
- data/src/ios/native_window.h +37 -0
- data/src/ios/native_window.mm +220 -0
- data/src/ios/opengl_view.h +13 -0
- data/src/ios/opengl_view.mm +131 -0
- data/src/{cocoa → ios}/reflex.mm +8 -12
- data/src/ios/window.mm +303 -0
- data/src/ios/window_data.h +75 -0
- data/src/osx/app_delegate.h +17 -0
- data/src/{cocoa/cocoaapplication.mm → osx/app_delegate.mm} +90 -48
- data/src/osx/application.mm +132 -0
- data/src/osx/application_data.h +45 -0
- data/src/osx/event.h +42 -0
- data/src/osx/event.mm +112 -0
- data/src/osx/native_window.h +26 -0
- data/src/osx/native_window.mm +322 -0
- data/src/{cocoa/openglview.h → osx/opengl_view.h} +0 -4
- data/src/{cocoa/openglview.mm → osx/opengl_view.mm} +66 -23
- data/src/osx/reflex.mm +50 -0
- data/src/osx/window.mm +308 -0
- data/src/osx/window_data.h +75 -0
- data/src/selector.cpp +121 -0
- data/src/style.cpp +576 -0
- data/src/style_length.cpp +341 -0
- data/src/view.cpp +1228 -129
- data/src/win32/application.cpp +1 -1
- data/src/window.cpp +54 -26
- data/test/helper.rb +8 -4
- data/test/test_capture_event.rb +41 -0
- data/test/test_event.rb +20 -0
- data/test/test_has_frame.rb +45 -0
- data/test/test_model.rb +9 -0
- data/test/test_model_owner.rb +9 -0
- data/test/test_selector.rb +75 -0
- data/test/test_style.rb +70 -0
- data/test/test_style_length.rb +38 -0
- data/test/test_style_length2.rb +50 -0
- data/test/test_style_length4.rb +56 -0
- data/test/test_view.rb +97 -23
- data/test/test_window.rb +54 -46
- metadata +205 -84
- data/.doc/ext/reflex/defs.cpp +0 -8
- data/.doc/ext/reflex/key.cpp +0 -122
- data/.doc/ext/reflex/points.cpp +0 -151
- data/.gitignore +0 -14
- data/ChangeLog +0 -8
- data/examples/hello/.gitignore +0 -2
- data/examples/hello/Rakefile +0 -41
- data/examples/hello/main.cpp +0 -18
- data/examples/ruby/app.rb +0 -13
- data/examples/ruby/checker.rb +0 -41
- data/examples/ruby/fps.rb +0 -49
- data/examples/ruby/grid.rb +0 -65
- data/examples/ruby/views.rb +0 -88
- data/examples/ruby/visuals.rb +0 -27
- data/ext/reflex/defs.cpp +0 -8
- data/ext/reflex/key.cpp +0 -129
- data/ext/reflex/points.cpp +0 -161
- data/include/reflex/ruby/key.h +0 -39
- data/include/reflex/ruby/points.h +0 -39
- data/lib/reflex/visuals/string.rb +0 -53
- data/src/cocoa/application.mm +0 -101
- data/src/cocoa/cocoaapplication.h +0 -21
- data/src/cocoa/cocoawindow.h +0 -46
- data/src/cocoa/cocoawindow.mm +0 -230
- data/src/cocoa/defs.h +0 -34
- data/src/cocoa/defs.mm +0 -87
- data/src/cocoa/window.mm +0 -148
- data/src/cocoa/windowdata.h +0 -56
- data/src/defs.cpp +0 -47
- data/src/helper.h +0 -12
- data/src/reflex.cpp +0 -43
- /data/{README → README.md} +0 -0
data/src/image_view.cpp
ADDED
|
@@ -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
|
|
4
|
-
#define
|
|
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
|
|
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
|
-
|
|
20
|
+
AppDelegate* delegate;
|
|
21
21
|
|
|
22
22
|
String name;
|
|
23
23
|
|
|
24
24
|
Data ()
|
|
25
|
-
:
|
|
25
|
+
: delegate(nil)
|
|
26
26
|
{
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
operator bool () const
|
|
30
30
|
{
|
|
31
|
-
return
|
|
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
|