reflexion 0.1.1

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 (74) hide show
  1. data/ChangeLog +8 -0
  2. data/README +4 -0
  3. data/Rakefile +70 -0
  4. data/VERSION +1 -0
  5. data/examples/hello/Rakefile +41 -0
  6. data/examples/hello/main.cpp +18 -0
  7. data/examples/ruby/app.rb +13 -0
  8. data/examples/ruby/checker.rb +41 -0
  9. data/examples/ruby/fps.rb +49 -0
  10. data/examples/ruby/hello.rb +38 -0
  11. data/examples/ruby/key.rb +44 -0
  12. data/examples/ruby/shapes.rb +124 -0
  13. data/examples/ruby/text.rb +35 -0
  14. data/ext/reflex/application.cpp +151 -0
  15. data/ext/reflex/extconf.rb +57 -0
  16. data/ext/reflex/key.cpp +128 -0
  17. data/ext/reflex/native.cpp +22 -0
  18. data/ext/reflex/points.cpp +160 -0
  19. data/ext/reflex/reflex.cpp +83 -0
  20. data/ext/reflex/reflex.h +39 -0
  21. data/ext/reflex/window.cpp +357 -0
  22. data/include/reflex/application.h +50 -0
  23. data/include/reflex/defs.h +258 -0
  24. data/include/reflex/helpers.h +32 -0
  25. data/include/reflex/reflex.h +26 -0
  26. data/include/reflex/ruby/application.h +39 -0
  27. data/include/reflex/ruby/key.h +39 -0
  28. data/include/reflex/ruby/points.h +39 -0
  29. data/include/reflex/ruby/reflex.h +21 -0
  30. data/include/reflex/ruby/window.h +39 -0
  31. data/include/reflex/ruby.h +14 -0
  32. data/include/reflex/window.h +79 -0
  33. data/include/reflex.h +13 -0
  34. data/lib/reflex/application.rb +25 -0
  35. data/lib/reflex/autoinit.rb +11 -0
  36. data/lib/reflex/bounds.rb +133 -0
  37. data/lib/reflex/helpers.rb +52 -0
  38. data/lib/reflex/module.rb +30 -0
  39. data/lib/reflex/point.rb +69 -0
  40. data/lib/reflex/reflex.rb +21 -0
  41. data/lib/reflex/window.rb +65 -0
  42. data/lib/reflex.rb +11 -0
  43. data/reflex.gemspec +57 -0
  44. data/src/cocoa/application.mm +90 -0
  45. data/src/cocoa/applicationdata.h +51 -0
  46. data/src/cocoa/cocoaapplication.h +19 -0
  47. data/src/cocoa/cocoaapplication.mm +180 -0
  48. data/src/cocoa/cocoawindow.h +44 -0
  49. data/src/cocoa/cocoawindow.mm +171 -0
  50. data/src/cocoa/defs.h +34 -0
  51. data/src/cocoa/defs.mm +84 -0
  52. data/src/cocoa/openglview.h +17 -0
  53. data/src/cocoa/openglview.mm +186 -0
  54. data/src/cocoa/reflex.mm +68 -0
  55. data/src/cocoa/window.mm +118 -0
  56. data/src/cocoa/windowdata.h +51 -0
  57. data/src/defs.cpp +47 -0
  58. data/src/win32/defs.cpp +150 -0
  59. data/src/win32/opengl.cpp +95 -0
  60. data/src/win32/opengl.h +50 -0
  61. data/src/win32/reflex.cpp +65 -0
  62. data/src/win32/window.cpp +480 -0
  63. data/src/window.cpp +60 -0
  64. data/support.rb +56 -0
  65. data/task/ext.rake +42 -0
  66. data/task/gem.rake +33 -0
  67. data/task/git.rake +22 -0
  68. data/task/lib.rake +54 -0
  69. data/test/helpers.rb +15 -0
  70. data/test/test_bounds.rb +163 -0
  71. data/test/test_point.rb +81 -0
  72. data/test/test_reflex.rb +17 -0
  73. data/test/test_window.rb +39 -0
  74. metadata +173 -0
data/reflex.gemspec ADDED
@@ -0,0 +1,57 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ $: << File.join(File.dirname(__FILE__), 'lib')
3
+ require 'rake'
4
+ require 'reflex/module'
5
+
6
+
7
+ FILES = FileList[*%w[
8
+ ChangeLog
9
+ README
10
+ Rakefile
11
+ support.rb
12
+ reflex.gemspec
13
+ VERSION
14
+ task/**/*.rake
15
+ ext/**/*.rb
16
+ ext/**/*.h
17
+ ext/**/*.cpp
18
+ include/**/*.h
19
+ lib/**/*.rb
20
+ src/**/*.h
21
+ src/**/*.cpp
22
+ src/**/*.mm
23
+ examples/**/README
24
+ examples/**/Rakefile
25
+ examples/**/*.h
26
+ examples/**/*.cpp
27
+ examples/**/*.rb
28
+ test/**/*.rb
29
+ ]]
30
+
31
+ Gem::Specification.new do |s|
32
+ s.name = 'reflexion'
33
+ s.summary = 'A Graphical User Interface Tool Kit.'
34
+ s.description = 'This library helps you to develop interactive graphical user interface.'
35
+ s.version = Reflex.version
36
+
37
+ s.authors = %w[snori]
38
+ s.email = 'snori@xord.org'
39
+ s.homepage = 'http://github.com/xord/reflex'
40
+
41
+ s.platform = Gem::Platform::RUBY
42
+ s.required_ruby_version = '>=1.9.0'
43
+ s.require_paths << 'ext'
44
+
45
+ s.add_runtime_dependency 'rucy'
46
+ s.add_runtime_dependency 'rays'
47
+ s.add_development_dependency 'rake'
48
+ s.add_development_dependency 'gemcutter'
49
+
50
+ s.files = FILES.to_a
51
+ s.test_files = FileList['test/**/test_*.rb'].to_a
52
+
53
+ s.has_rdoc = true
54
+ s.extra_rdoc_files = ['README']
55
+
56
+ s.extensions << 'Rakefile'
57
+ end
@@ -0,0 +1,90 @@
1
+ // -*- objc -*-
2
+ #include "reflex/application.h"
3
+
4
+
5
+ #import <Cocoa/Cocoa.h>
6
+ #include "applicationdata.h"
7
+ #import "cocoaapplication.h"
8
+
9
+
10
+ namespace Reflex
11
+ {
12
+
13
+
14
+ Application::Application ()
15
+ {
16
+ self->this_ = this;
17
+ self->self_ = NSApp ? [NSApp retain] : nil;
18
+ if (self->self_)
19
+ [self->self_ setApplicationData: self];
20
+ }
21
+
22
+ Application::~Application ()
23
+ {
24
+ if (self->self_)
25
+ {
26
+ [self->self_ release];
27
+ self->self_ = nil;
28
+ }
29
+ self->this_ = NULL;
30
+ }
31
+
32
+ bool
33
+ Application::run ()
34
+ {
35
+ if (!*this) return false;
36
+ [self->self_ run];
37
+ return true;
38
+ }
39
+
40
+ bool
41
+ Application::quit ()
42
+ {
43
+ if (!*this) return false;
44
+ [self->self_ terminate: nil];
45
+ return true;
46
+ }
47
+
48
+ bool
49
+ Application::preference ()
50
+ {
51
+ return *this;
52
+ }
53
+
54
+ bool
55
+ Application::about ()
56
+ {
57
+ if (!*this) return false;
58
+ [self->self_ orderFrontStandardAboutPanel: nil];
59
+ return true;
60
+ }
61
+
62
+ bool
63
+ Application::get_name (String* name) const
64
+ {
65
+ if (!*this || !name) return false;
66
+ *name = self->name;
67
+ return true;
68
+ }
69
+
70
+ bool
71
+ Application::set_name (const char* name)
72
+ {
73
+ if (!*this || !name) return false;
74
+ self->name = name;
75
+ return true;
76
+ }
77
+
78
+ Application::operator bool () const
79
+ {
80
+ return self && *self;
81
+ }
82
+
83
+ bool
84
+ Application::operator ! () const
85
+ {
86
+ return !operator bool();
87
+ }
88
+
89
+
90
+ }// Reflex
@@ -0,0 +1,51 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_COCOA_APPLICATIONDATA_H__
4
+ #define __REFLEX_COCOA_APPLICATIONDATA_H__
5
+
6
+
7
+ #include <boost/shared_ptr.hpp>
8
+ #include <reflex/application.h>
9
+
10
+
11
+ @class CocoaApplication;
12
+
13
+
14
+ namespace Reflex
15
+ {
16
+
17
+
18
+ struct Application::Data
19
+ {
20
+
21
+ Application* this_;
22
+
23
+ CocoaApplication* self_;
24
+
25
+ String name;
26
+
27
+ Data ()
28
+ : this_(NULL), self_(nil)
29
+ {
30
+ }
31
+
32
+ operator bool () const
33
+ {
34
+ return this_ && self_;
35
+ }
36
+
37
+ bool operator ! () const
38
+ {
39
+ return !operator bool();
40
+ }
41
+
42
+ };// Application::Data
43
+
44
+
45
+ typedef boost::shared_ptr<Reflex::Application::Data> ApplicationData;
46
+
47
+
48
+ }// Reflex
49
+
50
+
51
+ #endif//EOH
@@ -0,0 +1,19 @@
1
+ // -*- objc -*-
2
+ #import <AppKit/NSApplication.h>
3
+ #include "applicationdata.h"
4
+
5
+
6
+ @interface CocoaApplication : NSApplication <NSApplicationDelegate>
7
+
8
+ {
9
+ @private
10
+ Reflex::ApplicationData data;
11
+ }
12
+
13
+ - (void) about;
14
+
15
+ - (void) quit;
16
+
17
+ - (BOOL) setApplicationData: (Reflex::ApplicationData) data;
18
+
19
+ @end// CocoaApplication
@@ -0,0 +1,180 @@
1
+ // -*- objc -*-
2
+ #import "cocoaapplication.h"
3
+
4
+
5
+ #import <Cocoa/Cocoa.h>
6
+ #include <reflex/reflex.h>
7
+
8
+
9
+ @implementation CocoaApplication
10
+
11
+ - (id) init
12
+ {
13
+ self = [super init];
14
+ if (!self) return nil;
15
+
16
+ [self setDelegate: self];
17
+ [self setActivationPolicy: NSApplicationActivationPolicyRegular];
18
+ [self activateIgnoringOtherApps: YES];
19
+
20
+ return self;
21
+ }
22
+
23
+ - (BOOL) setApplicationData: (Reflex::ApplicationData) data_
24
+ {
25
+ if (data || !data_) return NO;
26
+ data = data_;
27
+ return YES;
28
+ }
29
+
30
+ - (void) quit
31
+ {
32
+ if (data && *data)
33
+ data->this_->quit();
34
+ else
35
+ Reflex::quit();
36
+ }
37
+
38
+ - (void) about
39
+ {
40
+ if (data && *data)
41
+ data->this_->about();
42
+ else
43
+ [self orderFrontStandardAboutPanel: nil];
44
+ }
45
+
46
+ - (BOOL) setupApplicationMenu: (NSMenu*) parent
47
+ {
48
+ if (!parent) return NO;
49
+
50
+ NSMenu* menu = [[[NSMenu alloc]
51
+ initWithTitle: @"Application"]
52
+ autorelease];
53
+ if ([self respondsToSelector: @selector(setAppleMenu:)])
54
+ [self performSelector: @selector(setAppleMenu:) withObject: menu];
55
+
56
+ NSString* name = !data->name.empty() ?
57
+ [NSString stringWithUTF8String: data->name.c_str()] : @"";
58
+ if ([name length] > 0)
59
+ name = [@" " stringByAppendingString: name];
60
+
61
+ NSMenu* submenu = nil;
62
+ NSMenuItem* item = nil;
63
+
64
+ [menu
65
+ addItemWithTitle: [@"About" stringByAppendingString: name]
66
+ action: @selector(about)
67
+ keyEquivalent: @""];
68
+
69
+ [menu addItem: [NSMenuItem separatorItem]];
70
+
71
+ [menu
72
+ addItemWithTitle: @"Preferences"
73
+ action: @selector(preference:)
74
+ keyEquivalent: @","];
75
+
76
+ [menu addItem: [NSMenuItem separatorItem]];
77
+
78
+ item = [menu
79
+ addItemWithTitle: @"Services"
80
+ action: nil
81
+ keyEquivalent: @""];
82
+ submenu = [[[NSMenu alloc] initWithTitle: @"Services"] autorelease];
83
+ [item setSubmenu: submenu];
84
+ [self setServicesMenu: submenu];
85
+
86
+ [menu addItem: [NSMenuItem separatorItem]];
87
+
88
+ [menu
89
+ addItemWithTitle: [@"Hide" stringByAppendingString: name]
90
+ action: @selector(hide:)
91
+ keyEquivalent: @"h"];
92
+
93
+ item = [menu
94
+ addItemWithTitle: @"Hide Others"
95
+ action: @selector(hideOtherApplications:)
96
+ keyEquivalent: @"h"];
97
+ [item setKeyEquivalentModifierMask: NSAlternateKeyMask | NSCommandKeyMask];
98
+
99
+ [menu
100
+ addItemWithTitle: @"ShowAll"
101
+ action: @selector(unhideAllApplications:)
102
+ keyEquivalent: @""];
103
+
104
+ [menu addItem: [NSMenuItem separatorItem]];
105
+
106
+ [menu
107
+ addItemWithTitle: [@"Quit" stringByAppendingString: name]
108
+ action: @selector(quit)
109
+ keyEquivalent: @"q"];
110
+
111
+ item =
112
+ [parent addItemWithTitle: @"Application" action: nil keyEquivalent: @""];
113
+ [parent setSubmenu: menu forItem: item];
114
+
115
+ return YES;
116
+ }
117
+
118
+ - (BOOL) setupWindowMenu: (NSMenu*) parent
119
+ {
120
+ if (!parent) return NO;
121
+
122
+ NSMenu* menu = [[[NSMenu alloc]
123
+ initWithTitle: @"Window"]
124
+ autorelease];
125
+
126
+ [menu
127
+ addItemWithTitle: @"Minimize"
128
+ action: @selector(performMiniaturize:)
129
+ keyEquivalent: @"m"];
130
+
131
+ [menu
132
+ addItemWithTitle: @"Zoom"
133
+ action: @selector(performZoom:)
134
+ keyEquivalent: @""];
135
+
136
+ [menu addItem: [NSMenuItem separatorItem]];
137
+
138
+ [menu
139
+ addItemWithTitle: @"Bring All to Front"
140
+ action: @selector(arrangeInFront:)
141
+ keyEquivalent: @""];
142
+
143
+ NSMenuItem* item =
144
+ [parent addItemWithTitle: @"Window" action: nil keyEquivalent: @""];
145
+ [parent setSubmenu: menu forItem: item];
146
+
147
+ [self setWindowsMenu: menu];
148
+
149
+ return YES;
150
+ }
151
+
152
+ - (BOOL) setupMenu
153
+ {
154
+ if ([self mainMenu]) return NO;
155
+
156
+ NSMenu* menu = [[[NSMenu alloc] initWithTitle: @"MainMenu"] autorelease];
157
+
158
+ if (
159
+ ![self setupApplicationMenu: menu] ||
160
+ ![self setupWindowMenu: menu])
161
+ {
162
+ return NO;
163
+ }
164
+
165
+ [self setMainMenu: menu];
166
+
167
+ return YES;
168
+ }
169
+
170
+ - (BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication*) app
171
+ {
172
+ return YES;
173
+ }
174
+
175
+ - (void) applicationDidFinishLaunching: (NSNotification*) notification
176
+ {
177
+ [self setupMenu];
178
+ }
179
+
180
+ @end// CocoaApplication
@@ -0,0 +1,44 @@
1
+ // -*- objc -*-
2
+ #import <AppKit/NSWindow.h>
3
+ #include "windowdata.h"
4
+
5
+
6
+ @class OpenGLView;
7
+
8
+
9
+ @interface CocoaWindow : NSWindow <NSWindowDelegate>
10
+
11
+ {
12
+ @private
13
+ Reflex::WindowData data;
14
+ OpenGLView* view;
15
+ NSTimer* timer;
16
+ }
17
+
18
+ - (id) initWithWindowData: (Reflex::WindowData) data;
19
+
20
+ - (void) setupContentView;
21
+
22
+ - (void) startTimer: (int) fps;
23
+
24
+ - (void) stopTimer;
25
+
26
+ - (void) update: (NSTimer*) t;
27
+
28
+ - (void) draw;
29
+
30
+ - (void) redraw;
31
+
32
+ - (void) keyDown: (NSEvent*) event;
33
+
34
+ - (void) keyUp: (NSEvent*) event;
35
+
36
+ - (void) mouseDown: (NSEvent*) event;
37
+
38
+ - (void) mouseUp: (NSEvent*) event;
39
+
40
+ - (void) mouseMoved: (NSEvent*) event;
41
+
42
+ - (void) mouseDragged: (NSEvent*) event;
43
+
44
+ @end// CocoaWindow
@@ -0,0 +1,171 @@
1
+ // -*- objc -*-
2
+ #import "cocoawindow.h"
3
+
4
+
5
+ #import <Cocoa/Cocoa.h>
6
+ #import "openglview.h"
7
+
8
+ #include <reflex/window.h>
9
+ #include "defs.h"
10
+
11
+
12
+ @implementation CocoaWindow
13
+
14
+ - (id) initWithWindowData: (Reflex::WindowData) data_
15
+ {
16
+ NSRect frame = NSMakeRect(0, 0, 0, 0);
17
+
18
+ self = [super
19
+ initWithContentRect: NSMakeRect(0, 0, 0, 0)
20
+ styleMask:
21
+ NSTitledWindowMask |
22
+ NSClosableWindowMask |
23
+ NSMiniaturizableWindowMask |
24
+ NSResizableWindowMask |
25
+ 0//NSTexturedBackgroundWindowMask
26
+ backing: NSBackingStoreBuffered
27
+ defer: NO];
28
+ if (!self) return nil;
29
+
30
+ data = data_;
31
+ view = nil;
32
+ timer = nil;
33
+
34
+ [self setDelegate: self];
35
+ //[self setReleasedWhenClosed: NO];
36
+
37
+ [self setupContentView];
38
+ [self startTimer: 60];
39
+
40
+ return self;
41
+ }
42
+
43
+ - (void) dealloc
44
+ {
45
+ [self stopTimer];
46
+ [view release];
47
+
48
+ [super dealloc];
49
+ }
50
+
51
+ - (void) setupContentView
52
+ {
53
+ NSRect rect = [self contentRectForFrameRect: [self frame]];
54
+ rect.origin.x = rect.origin.y = 0;
55
+ view = [[OpenGLView alloc] initWithFrame: rect];
56
+ [self setContentView: view];
57
+ }
58
+
59
+ - (void) startTimer: (int) fps
60
+ {
61
+ [self stopTimer];
62
+
63
+ if (fps <= 0) return;
64
+
65
+ timer = [[NSTimer
66
+ timerWithTimeInterval: 1.f / (float) fps
67
+ target: self
68
+ selector: @selector(update:)
69
+ userInfo: nil
70
+ repeats: YES] retain];
71
+ if (!timer) return;
72
+
73
+ [[NSRunLoop currentRunLoop]
74
+ addTimer: timer forMode: NSDefaultRunLoopMode];
75
+ [[NSRunLoop currentRunLoop]
76
+ addTimer: timer forMode: NSEventTrackingRunLoopMode];
77
+ }
78
+
79
+ - (void) stopTimer
80
+ {
81
+ if (timer)
82
+ {
83
+ if ([timer isValid]) [timer invalidate];
84
+ [timer release];
85
+ timer = nil;
86
+ }
87
+ }
88
+
89
+ - (void) update: (NSTimer*) t
90
+ {
91
+ if (!data || !*data) return;
92
+ data->this_->update();
93
+ }
94
+
95
+ - (void) draw
96
+ {
97
+ if (!data || !*data) return;
98
+ data->this_->draw();
99
+ }
100
+
101
+ - (void) redraw
102
+ {
103
+ [self display];
104
+ }
105
+
106
+ - (BOOL) windowShouldClose: (id) sender
107
+ {
108
+ if (!data || !*data) return YES;
109
+ data->this_->close();
110
+ return NO;
111
+ }
112
+
113
+ - (void) windowWillClose: (NSNotification*) notification
114
+ {
115
+ [self stopTimer];
116
+ data.reset();
117
+ }
118
+
119
+ - (void) windowDidMove: (NSNotification*) notification
120
+ {
121
+ if (!data || !*data) return;
122
+ Reflex::coord x = 0, y = 0;
123
+ data->this_->get_bounds(&x, &y);
124
+ data->this_->moved(x, y);
125
+ }
126
+
127
+ - (void) windowDidResize: (NSNotification*) notification
128
+ {
129
+ if (!data || !*data) return;
130
+ Reflex::coord w = 0, h = 0;
131
+ data->this_->get_bounds(NULL, NULL, &w, &h);
132
+ data->this_->resized(w, h);
133
+ }
134
+
135
+ - (void) keyDown: (NSEvent*) event
136
+ {
137
+ if (!data || !*data) return;
138
+ data->this_->key_down(Reflex::CocoaKey(event));
139
+ }
140
+
141
+ - (void) keyUp: (NSEvent*) event
142
+ {
143
+ if (!data || !*data) return;
144
+ data->this_->key_up(Reflex::CocoaKey(event));
145
+ }
146
+
147
+ - (void) mouseDown: (NSEvent*) event
148
+ {
149
+ if (!data || !*data) return;
150
+ data->this_->points_down(Reflex::CocoaPoints(event, view));
151
+ }
152
+
153
+ - (void) mouseUp: (NSEvent*) event
154
+ {
155
+ if (!data || !*data) return;
156
+ data->this_->points_up(Reflex::CocoaPoints(event, view));
157
+ }
158
+
159
+ - (void) mouseMoved: (NSEvent*) event
160
+ {
161
+ if (!data || !*data) return;
162
+ data->this_->points_moved(Reflex::CocoaPoints(event, view));
163
+ }
164
+
165
+ - (void) mouseDragged: (NSEvent*) event
166
+ {
167
+ if (!data || !*data) return;
168
+ data->this_->points_moved(Reflex::CocoaPoints(event, view));
169
+ }
170
+
171
+ @end// CocoaWindow
data/src/cocoa/defs.h ADDED
@@ -0,0 +1,34 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_COCOA_DEFS_H__
4
+ #define __REFLEX_COCOA_DEFS_H__
5
+
6
+
7
+ #import <AppKit/NSEvent.h>
8
+ #include <reflex/defs.h>
9
+
10
+
11
+ namespace Reflex
12
+ {
13
+
14
+
15
+ struct CocoaKey : public Key
16
+ {
17
+
18
+ CocoaKey (NSEvent* event);
19
+
20
+ };// CocoaKey
21
+
22
+
23
+ struct CocoaPoints : public Points
24
+ {
25
+
26
+ CocoaPoints (NSEvent* event, NSView* view);
27
+
28
+ };// CocoaPoints
29
+
30
+
31
+ }// Reflex
32
+
33
+
34
+ #endif//EOH