reflexion 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +8 -0
- data/README +4 -0
- data/Rakefile +70 -0
- data/VERSION +1 -0
- data/examples/hello/Rakefile +41 -0
- data/examples/hello/main.cpp +18 -0
- data/examples/ruby/app.rb +13 -0
- data/examples/ruby/checker.rb +41 -0
- data/examples/ruby/fps.rb +49 -0
- data/examples/ruby/hello.rb +38 -0
- data/examples/ruby/key.rb +44 -0
- data/examples/ruby/shapes.rb +124 -0
- data/examples/ruby/text.rb +35 -0
- data/ext/reflex/application.cpp +151 -0
- data/ext/reflex/extconf.rb +57 -0
- data/ext/reflex/key.cpp +128 -0
- data/ext/reflex/native.cpp +22 -0
- data/ext/reflex/points.cpp +160 -0
- data/ext/reflex/reflex.cpp +83 -0
- data/ext/reflex/reflex.h +39 -0
- data/ext/reflex/window.cpp +357 -0
- data/include/reflex/application.h +50 -0
- data/include/reflex/defs.h +258 -0
- data/include/reflex/helpers.h +32 -0
- data/include/reflex/reflex.h +26 -0
- data/include/reflex/ruby/application.h +39 -0
- data/include/reflex/ruby/key.h +39 -0
- data/include/reflex/ruby/points.h +39 -0
- data/include/reflex/ruby/reflex.h +21 -0
- data/include/reflex/ruby/window.h +39 -0
- data/include/reflex/ruby.h +14 -0
- data/include/reflex/window.h +79 -0
- data/include/reflex.h +13 -0
- data/lib/reflex/application.rb +25 -0
- data/lib/reflex/autoinit.rb +11 -0
- data/lib/reflex/bounds.rb +133 -0
- data/lib/reflex/helpers.rb +52 -0
- data/lib/reflex/module.rb +30 -0
- data/lib/reflex/point.rb +69 -0
- data/lib/reflex/reflex.rb +21 -0
- data/lib/reflex/window.rb +65 -0
- data/lib/reflex.rb +11 -0
- data/reflex.gemspec +57 -0
- data/src/cocoa/application.mm +90 -0
- data/src/cocoa/applicationdata.h +51 -0
- data/src/cocoa/cocoaapplication.h +19 -0
- data/src/cocoa/cocoaapplication.mm +180 -0
- data/src/cocoa/cocoawindow.h +44 -0
- data/src/cocoa/cocoawindow.mm +171 -0
- data/src/cocoa/defs.h +34 -0
- data/src/cocoa/defs.mm +84 -0
- data/src/cocoa/openglview.h +17 -0
- data/src/cocoa/openglview.mm +186 -0
- data/src/cocoa/reflex.mm +68 -0
- data/src/cocoa/window.mm +118 -0
- data/src/cocoa/windowdata.h +51 -0
- data/src/defs.cpp +47 -0
- data/src/win32/defs.cpp +150 -0
- data/src/win32/opengl.cpp +95 -0
- data/src/win32/opengl.h +50 -0
- data/src/win32/reflex.cpp +65 -0
- data/src/win32/window.cpp +480 -0
- data/src/window.cpp +60 -0
- data/support.rb +56 -0
- data/task/ext.rake +42 -0
- data/task/gem.rake +33 -0
- data/task/git.rake +22 -0
- data/task/lib.rake +54 -0
- data/test/helpers.rb +15 -0
- data/test/test_bounds.rb +163 -0
- data/test/test_point.rb +81 -0
- data/test/test_reflex.rb +17 -0
- data/test/test_window.rb +39 -0
- metadata +173 -0
data/ChangeLog
ADDED
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
$: << File.expand_path(File.dirname __FILE__)
|
3
|
+
%w[../rucy/lib ../rays/lib ../reflex/lib].each do |path|
|
4
|
+
$: << File.expand_path(File.join File.dirname(__FILE__), *path.split('/'))
|
5
|
+
end
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rbconfig'
|
8
|
+
require 'support'
|
9
|
+
require 'rays/module'
|
10
|
+
require 'reflex/module'
|
11
|
+
|
12
|
+
|
13
|
+
NAME = 'reflex'
|
14
|
+
|
15
|
+
SRCDIR = 'src'
|
16
|
+
INCDIR = 'include'
|
17
|
+
LIBDIR = 'lib'
|
18
|
+
EXTDIR = 'ext'
|
19
|
+
TASKDIR = 'task'
|
20
|
+
|
21
|
+
EXTEXT = RbConfig::CONFIG['DLEXT'] || 'so'
|
22
|
+
|
23
|
+
DEFS = %w[]
|
24
|
+
DEFS << 'WIN32' if win32?
|
25
|
+
DEFS << 'COCOA' if cocoa?
|
26
|
+
|
27
|
+
incroot = RbConfig::CONFIG['rubyhdrdir']
|
28
|
+
INCDIRS = Reflex.include_dirs + Rays.include_dirs + [
|
29
|
+
incroot,
|
30
|
+
"#{incroot}/#{RUBY_PLATFORM}",
|
31
|
+
'/opt/local/include',
|
32
|
+
'/opt/include'
|
33
|
+
]
|
34
|
+
|
35
|
+
RUBY = ENV['RUBY'] || 'ruby'
|
36
|
+
GEM = ENV['GEM'] || 'gem'
|
37
|
+
GIT = ENV['GIT'] || 'git'
|
38
|
+
MAKE = ENV['MAKE'] || 'make'
|
39
|
+
CC = RbConfig::CONFIG['CC'] || ENV['CC'] || 'g++'
|
40
|
+
CFLAGS = '-Wall -O' + DEFS.map{|s| " -D#{s}"}.join
|
41
|
+
AR = ENV['AR'] || 'ar'
|
42
|
+
ARFLAGS = 'crs'
|
43
|
+
|
44
|
+
|
45
|
+
task :default => :build
|
46
|
+
|
47
|
+
task :build => :ext
|
48
|
+
|
49
|
+
task :rebuild => [:clean, :build]
|
50
|
+
|
51
|
+
task :lib => 'lib:build'
|
52
|
+
|
53
|
+
task :ext => 'ext:build'
|
54
|
+
|
55
|
+
task :gem => 'gem:build'
|
56
|
+
|
57
|
+
task :install => 'gem:install'
|
58
|
+
|
59
|
+
task :uninstall => 'gem:uninstall'
|
60
|
+
|
61
|
+
task :clean => ['lib:clean', 'ext:clean', 'gem:clean']
|
62
|
+
|
63
|
+
task :test => :ext do
|
64
|
+
Dir['test/**/test_*.rb'].each do |rb|
|
65
|
+
sh %( ruby #{rb} )
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
Dir["#{TASKDIR}/**/*.rake"].each {|path| load path}
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
%w[../../../rucy/lib ../../../rays/lib ../../lib].each do |path|
|
3
|
+
$: << File.expand_path(File.join File.dirname(__FILE__), *path.split('/'))
|
4
|
+
end
|
5
|
+
require 'rubygems'
|
6
|
+
require 'reflex/reflex'
|
7
|
+
|
8
|
+
|
9
|
+
OUT = 'hello'
|
10
|
+
SRCS = Dir.glob('*.cpp')
|
11
|
+
|
12
|
+
REFLEX = Reflex.name.downcase
|
13
|
+
LIBREFLEX = File.join(Reflex.library_dirs[0], "lib#{REFLEX}.a")
|
14
|
+
|
15
|
+
INCDIRS = %w[/opt/local/include /opt/include] + Reflex.include_dirs
|
16
|
+
LIBDIRS = %w[] + Reflex.library_dirs
|
17
|
+
|
18
|
+
LIBS = %w[stdc++ objc] + [REFLEX]
|
19
|
+
FRAMEWORKS = %w[Cocoa]
|
20
|
+
|
21
|
+
CFLAGS = INCDIRS.map{|s| "-I#{s}"}.join(' ')
|
22
|
+
LDFLAGS = (
|
23
|
+
LIBDIRS.map {|s| "-L#{s}"} +
|
24
|
+
LIBS.map {|s| "-l#{s}"} +
|
25
|
+
FRAMEWORKS.map {|s| "-framework #{s}"}
|
26
|
+
).join(' ')
|
27
|
+
|
28
|
+
|
29
|
+
task :default => :run
|
30
|
+
|
31
|
+
task :run => OUT do
|
32
|
+
sh %( ./#{OUT} )
|
33
|
+
end
|
34
|
+
|
35
|
+
file OUT => [LIBREFLEX] + SRCS do
|
36
|
+
sh %( gcc -o #{OUT} #{CFLAGS} #{LDFLAGS} #{SRCS.join ' '} )
|
37
|
+
end
|
38
|
+
|
39
|
+
task LIBREFLEX do
|
40
|
+
sh %( cd #{Reflex.root_dir} && rake )
|
41
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#include <reflex.h>
|
2
|
+
|
3
|
+
|
4
|
+
using namespace Reflex;
|
5
|
+
|
6
|
+
|
7
|
+
int
|
8
|
+
main (int argc, char** argv)
|
9
|
+
{
|
10
|
+
init();
|
11
|
+
Window win;
|
12
|
+
win.set_title("Reflex Test Window");
|
13
|
+
win.set_bounds(100, 100, 600, 500);
|
14
|
+
win.show();
|
15
|
+
run();
|
16
|
+
fin();
|
17
|
+
return EXIT_SUCCESS;
|
18
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
%w[rays reflex].product(%w[ext lib]).each do |paths|
|
5
|
+
$: << File.expand_path(
|
6
|
+
File.join File.dirname(__FILE__), "..", "..", "..", *paths)
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'reflex'
|
10
|
+
|
11
|
+
|
12
|
+
Reflex::Window.new(:bounds => [100, 100, 500, 500]).show
|
13
|
+
Reflex.run "AppName"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
%w[rays reflex].product(%w[ext lib]).each do |paths|
|
5
|
+
$: << File.expand_path(
|
6
|
+
File.join File.dirname(__FILE__), "..", "..", "..", *paths)
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'reflex'
|
11
|
+
|
12
|
+
|
13
|
+
class CheckerWindow < Reflex::Window
|
14
|
+
|
15
|
+
def initialize ()
|
16
|
+
super
|
17
|
+
set :title, "Hello Reflex!"
|
18
|
+
set :bounds, 100, 100, 320, 240
|
19
|
+
painter.font = Rays::Font.new nil, 32
|
20
|
+
painter.clear = 1
|
21
|
+
end
|
22
|
+
|
23
|
+
def draw ()
|
24
|
+
count = 16
|
25
|
+
size = 10
|
26
|
+
paint do |p|
|
27
|
+
count.times do |x|
|
28
|
+
count.times do |y|
|
29
|
+
next if (x + y) % 2 == 0
|
30
|
+
p.fill = x.to_f / count, y.to_f / count, 1
|
31
|
+
p.rect x * size, y * size, size - 1, size - 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end# CheckerWindow
|
38
|
+
|
39
|
+
|
40
|
+
CheckerWindow.new.show
|
41
|
+
Reflex.run
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
%w[rays reflex].product(%w[ext lib]).each do |paths|
|
5
|
+
$: << File.expand_path(
|
6
|
+
File.join File.dirname(__FILE__), "..", "..", "..", *paths)
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'reflex'
|
10
|
+
|
11
|
+
|
12
|
+
x = 0
|
13
|
+
y = 0
|
14
|
+
font = Rays::Font.new("Osaka", 32)
|
15
|
+
prev = Time.now
|
16
|
+
fps = 0
|
17
|
+
|
18
|
+
w = Reflex::Window.
|
19
|
+
new(:title => "Reflex on Ruby", :bounds => [100, 100, 600, 400]).
|
20
|
+
before(:close) {|o| o.hide; sleep 1; o.show; sleep 1}.
|
21
|
+
on(:moved) {|o, x, y| p [x, y]}.
|
22
|
+
on(:resized) {|o, w, h| p [w, h]}.
|
23
|
+
on(:update) {|o| o.redraw}.
|
24
|
+
on(:draw) do |o|
|
25
|
+
b = o.bounds 0
|
26
|
+
o.paint do |p|
|
27
|
+
p.fill = 1, 0.5, 0.5, 0.05
|
28
|
+
#p.stroke = 0.5, 0.5, 1
|
29
|
+
100.times do
|
30
|
+
n = rand * Math::PI * 2
|
31
|
+
xx = x + Math.sin(n) * 50
|
32
|
+
yy = y + Math.cos(n) * 50
|
33
|
+
p.rect xx, yy, 50, 50
|
34
|
+
end
|
35
|
+
p.fill = 1
|
36
|
+
p.text "hello Rays/Reflex!", x, y + 32, font
|
37
|
+
x = (x + 1) % 100
|
38
|
+
y = (y + 1) % 100
|
39
|
+
|
40
|
+
now = Time.now
|
41
|
+
fps = 1 / (now - prev) if x % 10 == 0
|
42
|
+
p.fill = 1, 1, 1, 1
|
43
|
+
p.text "#{fps.to_i} FPS", 0, b.bottom - font.height, font
|
44
|
+
prev = now
|
45
|
+
end
|
46
|
+
end.
|
47
|
+
show
|
48
|
+
|
49
|
+
Reflex.run
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
%w[rays reflex].product(%w[ext lib]).each do |paths|
|
5
|
+
$: << File.expand_path(
|
6
|
+
File.join File.dirname(__FILE__), "..", "..", "..", *paths)
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'reflex'
|
11
|
+
|
12
|
+
|
13
|
+
class HelloWindow < Reflex::Window
|
14
|
+
|
15
|
+
def initialize ()
|
16
|
+
super
|
17
|
+
set :title, "Hello Reflex!"
|
18
|
+
set :bounds, 100, 100, 320, 240
|
19
|
+
painter.font = Rays::Font.new nil, 32
|
20
|
+
end
|
21
|
+
|
22
|
+
def draw ()
|
23
|
+
paint do |p|
|
24
|
+
p.fill = 1
|
25
|
+
p.text "hello world!", 100, 100
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def update ()
|
30
|
+
#painter.clear = rand, rand, rand
|
31
|
+
redraw
|
32
|
+
end
|
33
|
+
|
34
|
+
end# HelloWindow
|
35
|
+
|
36
|
+
|
37
|
+
HelloWindow.new.show
|
38
|
+
Reflex.run
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
%w[rays reflex].product(%w[ext lib]).each do |paths|
|
5
|
+
$: << File.expand_path(
|
6
|
+
File.join File.dirname(__FILE__), "..", "..", "..", *paths)
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'reflex'
|
11
|
+
|
12
|
+
|
13
|
+
$text = $pos = ''
|
14
|
+
|
15
|
+
|
16
|
+
w = Reflex::Window.new
|
17
|
+
w.title = "Reflex Input Sample"
|
18
|
+
w.bounds = 100, 100, 800, 300
|
19
|
+
w.painter.font = Rays::Font.new nil, 32
|
20
|
+
|
21
|
+
w.on :draw do
|
22
|
+
w.paint do |p|
|
23
|
+
p.fill = 1
|
24
|
+
p.text $text, 100, 100
|
25
|
+
p.text $pos, 100, 150
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
w.on :key_down do |obj, key|
|
30
|
+
w.close if key.code == 53
|
31
|
+
$text += key.chars
|
32
|
+
$text = $text[-10..-1] if $text.size > 10
|
33
|
+
p [key.chars, key.code, key.repeat, key.modifiers]
|
34
|
+
w.redraw
|
35
|
+
end
|
36
|
+
|
37
|
+
w.on :points_moved do |obj, points|
|
38
|
+
$pos = "#{points.x}, #{points.y}"
|
39
|
+
p [points.type, points.x, points.y, points.size, points.modifiers, points.count, points.drag]
|
40
|
+
w.redraw
|
41
|
+
end
|
42
|
+
|
43
|
+
w.show
|
44
|
+
Reflex.run
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
%w[rays reflex].product(%w[ext lib]).each do |paths|
|
5
|
+
$: << File.expand_path(
|
6
|
+
File.join File.dirname(__FILE__), "..", "..", "..", *paths)
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'reflex'
|
11
|
+
|
12
|
+
|
13
|
+
module DisplayFPS
|
14
|
+
|
15
|
+
def fps ()
|
16
|
+
@fps ||= 0
|
17
|
+
@fps_count ||= 0
|
18
|
+
now = Time.now
|
19
|
+
@fps = 1.0 / (now - @fps_prev) if
|
20
|
+
@fps_prev && @fps_prev < now && (@fps_count += 1) % 32 == 1
|
21
|
+
@fps_prev = now
|
22
|
+
@fps.to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
def draw_fps (p, x = 0, y = 0)
|
26
|
+
fill = p.fill
|
27
|
+
=begin
|
28
|
+
p.fill = 1
|
29
|
+
(-1..1).each do |xx|
|
30
|
+
(-1..1).each do |yy|
|
31
|
+
p.text fps, x + xx, y + yy, @fps_font
|
32
|
+
end
|
33
|
+
end
|
34
|
+
=end
|
35
|
+
p.fill = 0
|
36
|
+
p.text "#{fps} FPS", x, y, @fps_font ||= Rays::Font.new(nil, 20)
|
37
|
+
p.fill = fill
|
38
|
+
end
|
39
|
+
|
40
|
+
end# DisplayFPS
|
41
|
+
|
42
|
+
|
43
|
+
class Ring
|
44
|
+
|
45
|
+
def initialize (x, y, width, height, colors, rotation = 1)
|
46
|
+
@x, @y, @width, @height, @colors, @rot, @angle, @min =
|
47
|
+
x, y, width, height, colors, rotation, 0, 0
|
48
|
+
end
|
49
|
+
|
50
|
+
def draw (p)
|
51
|
+
w = 45
|
52
|
+
p.fill = *@colors[0]
|
53
|
+
fin p, 0, w
|
54
|
+
fin p, 180, w
|
55
|
+
p.fill = *@colors[1]
|
56
|
+
fin p, 90, w
|
57
|
+
fin p, 270, w
|
58
|
+
end
|
59
|
+
|
60
|
+
def update ()
|
61
|
+
@angle = (@angle + @rot) % 360
|
62
|
+
end
|
63
|
+
|
64
|
+
def fin (p, angle, width)
|
65
|
+
angle += @angle
|
66
|
+
p.arc @x, @y, @width, @height, angle, angle + width, @min
|
67
|
+
end
|
68
|
+
|
69
|
+
end# Ring
|
70
|
+
|
71
|
+
|
72
|
+
class ShapesWindow < Reflex::Window
|
73
|
+
|
74
|
+
include Enumerable
|
75
|
+
include DisplayFPS
|
76
|
+
|
77
|
+
def initialize ()
|
78
|
+
super
|
79
|
+
set :title, "Shapes Sample"
|
80
|
+
set :bounds, 100, 400, 640, 240
|
81
|
+
painter.clear = 1
|
82
|
+
@rings = []
|
83
|
+
setup
|
84
|
+
end
|
85
|
+
|
86
|
+
def setup ()
|
87
|
+
c = [0.9, 0.5, 0.5], [0.5, 0.5, 0.9]
|
88
|
+
w = 100
|
89
|
+
h = 100
|
90
|
+
rot = 0
|
91
|
+
(0..5).each do |y|
|
92
|
+
(0..10).each do |x|
|
93
|
+
@rings << Ring.new(x * w, y * h, w, h, c, rot += 0.1)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def draw ()
|
99
|
+
paint do |p|
|
100
|
+
each {|o| o.draw p}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def update ()
|
105
|
+
each {|o| o.update}
|
106
|
+
redraw
|
107
|
+
@count ||= 0
|
108
|
+
fps_ = fps
|
109
|
+
#puts "#{fps_} FPS, GC count: #{GC.stat[:count]}" if (@count += 1) % 100 == 0
|
110
|
+
end
|
111
|
+
|
112
|
+
def key_down (key)
|
113
|
+
close if key.code == 53 || key.chars =~ /q/i
|
114
|
+
end
|
115
|
+
|
116
|
+
def each ()
|
117
|
+
@rings.each {|o| yield o}
|
118
|
+
end
|
119
|
+
|
120
|
+
end# ShapesWindow
|
121
|
+
|
122
|
+
|
123
|
+
ShapesWindow.new.show
|
124
|
+
Reflex.run "Shapes"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
%w[rays reflex].product(%w[ext lib]).each do |paths|
|
5
|
+
$: << File.expand_path(
|
6
|
+
File.join File.dirname(__FILE__), "..", "..", "..", *paths)
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'reflex'
|
10
|
+
|
11
|
+
|
12
|
+
lines = File.readlines(__FILE__)
|
13
|
+
|
14
|
+
|
15
|
+
win = Reflex::Window.
|
16
|
+
new do
|
17
|
+
set :title, "Rays/Reflex Text Test"
|
18
|
+
set :bounds, 100, 100, 600, 400
|
19
|
+
paint do |p|
|
20
|
+
p.clear = 1
|
21
|
+
p.font = Rays::Font.new 'Courier', 12
|
22
|
+
end
|
23
|
+
end.
|
24
|
+
# on(:update) {|o| o.redraw}.
|
25
|
+
on(:draw) do |o|
|
26
|
+
o.paint do |p|
|
27
|
+
p.fill = 0 #rand, rand, rand, 1
|
28
|
+
lines.each.with_index do |line, i|
|
29
|
+
p.text line.chomp, 0, p.font.height * i
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end.
|
33
|
+
show
|
34
|
+
|
35
|
+
Reflex.run
|
@@ -0,0 +1,151 @@
|
|
1
|
+
#include "reflex/ruby/application.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <rucy.h>
|
5
|
+
#include "reflex.h"
|
6
|
+
|
7
|
+
|
8
|
+
using namespace Rucy;
|
9
|
+
|
10
|
+
|
11
|
+
namespace Reflex
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
Class
|
16
|
+
application_class ()
|
17
|
+
{
|
18
|
+
static Class c = reflex_module().define_class("Application");
|
19
|
+
return c;
|
20
|
+
}
|
21
|
+
|
22
|
+
|
23
|
+
}// Reflex
|
24
|
+
|
25
|
+
|
26
|
+
namespace Rucy
|
27
|
+
{
|
28
|
+
|
29
|
+
|
30
|
+
Value
|
31
|
+
value (const Reflex::Application& application)
|
32
|
+
{
|
33
|
+
return new_type<Reflex::Application>(
|
34
|
+
Reflex::application_class(), new Reflex::Application(application));
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
}// Rucy
|
39
|
+
|
40
|
+
|
41
|
+
class RubyApplication : public Reflex::Application
|
42
|
+
{
|
43
|
+
|
44
|
+
public:
|
45
|
+
|
46
|
+
typedef Reflex::Application Super;
|
47
|
+
|
48
|
+
Value self;
|
49
|
+
|
50
|
+
void mark ()
|
51
|
+
{
|
52
|
+
self.mark();
|
53
|
+
}
|
54
|
+
|
55
|
+
virtual bool run ()
|
56
|
+
{
|
57
|
+
SYM(run);
|
58
|
+
return self.call(run);
|
59
|
+
}
|
60
|
+
|
61
|
+
virtual bool quit ()
|
62
|
+
{
|
63
|
+
SYM(quit);
|
64
|
+
return self.call(quit);
|
65
|
+
}
|
66
|
+
|
67
|
+
virtual bool about ()
|
68
|
+
{
|
69
|
+
SYM(about);
|
70
|
+
return self.call(about);
|
71
|
+
}
|
72
|
+
|
73
|
+
};// RubyApplication
|
74
|
+
|
75
|
+
|
76
|
+
#define this ((RubyApplication*) to<Reflex::Application*>(self))
|
77
|
+
|
78
|
+
#define CHECK CHECK_OBJECT(self, RubyApplication, Reflex::application_class())
|
79
|
+
|
80
|
+
|
81
|
+
static
|
82
|
+
RUBY_DEF_ALLOC(alloc, klass)
|
83
|
+
{
|
84
|
+
RubyApplication* app = new RubyApplication;
|
85
|
+
return app->self = new_type<RubyApplication>(klass, app, mark_type<RubyApplication>);
|
86
|
+
}
|
87
|
+
RUBY_END
|
88
|
+
|
89
|
+
static
|
90
|
+
RUBY_DEF0(run)
|
91
|
+
{
|
92
|
+
CHECK;
|
93
|
+
if (!this->Super::run())
|
94
|
+
system_error("failed to run application.");
|
95
|
+
return self;
|
96
|
+
}
|
97
|
+
RUBY_END
|
98
|
+
|
99
|
+
static
|
100
|
+
RUBY_DEF0(quit)
|
101
|
+
{
|
102
|
+
CHECK;
|
103
|
+
if (!this->Super::quit())
|
104
|
+
system_error("failed to quit application.");
|
105
|
+
return self;
|
106
|
+
}
|
107
|
+
RUBY_END
|
108
|
+
|
109
|
+
static
|
110
|
+
RUBY_DEF0(about)
|
111
|
+
{
|
112
|
+
CHECK;
|
113
|
+
if (!this->Super::about())
|
114
|
+
system_error("failed to show about application.");
|
115
|
+
return self;
|
116
|
+
}
|
117
|
+
RUBY_END
|
118
|
+
|
119
|
+
static
|
120
|
+
RUBY_DEF0(get_name)
|
121
|
+
{
|
122
|
+
CHECK;
|
123
|
+
String s;
|
124
|
+
if (!this->get_name(&s))
|
125
|
+
system_error("failed to get name of application.");
|
126
|
+
return Value(s.c_str());
|
127
|
+
}
|
128
|
+
RUBY_END
|
129
|
+
|
130
|
+
static
|
131
|
+
RUBY_DEF1(set_name, name)
|
132
|
+
{
|
133
|
+
CHECK;
|
134
|
+
if (!this->set_name(name.c_str()))
|
135
|
+
system_error("failed to set name of application.");
|
136
|
+
return name;
|
137
|
+
}
|
138
|
+
RUBY_END
|
139
|
+
|
140
|
+
|
141
|
+
void
|
142
|
+
Init_application ()
|
143
|
+
{
|
144
|
+
Reflex::application_class()
|
145
|
+
.define_alloc_func(alloc)
|
146
|
+
.define_method("run", run)
|
147
|
+
.define_method("quit", quit)
|
148
|
+
.define_method("about", about)
|
149
|
+
.define_method("name", get_name)
|
150
|
+
.define_method("name=", set_name);
|
151
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
%w[../../../rucy/lib ../../lib].each do |path|
|
3
|
+
$: << File.expand_path(File.join File.dirname(__FILE__), *path.split('/'))
|
4
|
+
end
|
5
|
+
require 'rubygems'
|
6
|
+
require 'mkmf'
|
7
|
+
require 'rucy/module'
|
8
|
+
require 'reflex/module'
|
9
|
+
|
10
|
+
|
11
|
+
DEBUG = ENV['DEBUG'] || false
|
12
|
+
|
13
|
+
DEFS = []
|
14
|
+
INCDIRS = %w[/opt/local/include /opt/include] +
|
15
|
+
Rucy.include_dirs + Reflex.include_dirs
|
16
|
+
LIBDIRS = %w[] +
|
17
|
+
Rucy.library_dirs + Reflex.library_dirs
|
18
|
+
|
19
|
+
HEADERS = %w[
|
20
|
+
boost/shared_ptr.hpp
|
21
|
+
ruby.h
|
22
|
+
rucy.h
|
23
|
+
reflex.h
|
24
|
+
]
|
25
|
+
LIBS = %w[stdc++ rucy reflex]
|
26
|
+
FRAMEWORKS = %w[]
|
27
|
+
|
28
|
+
|
29
|
+
DEFS << '_DEBUG' if DEBUG
|
30
|
+
|
31
|
+
case RUBY_PLATFORM
|
32
|
+
when /mswin|ming|cygwin/
|
33
|
+
DEFS << 'WINDOWS' << 'WIN32' << $~[0].upcase
|
34
|
+
LIBS.unshift 'gdi32', 'opengl32'
|
35
|
+
when /darwin/
|
36
|
+
DEFS << 'COCOA'
|
37
|
+
FRAMEWORKS << 'Cocoa'# << 'OpenGL'
|
38
|
+
end
|
39
|
+
|
40
|
+
$CPPFLAGS << DEFS.map {|s| " -D#{s}"}.join
|
41
|
+
$CPPFLAGS << INCDIRS.map {|s| " -I#{s}"}.join
|
42
|
+
$LDFLAGS << LIBDIRS.map {|s| " -L#{s}"}.join
|
43
|
+
$LDFLAGS << FRAMEWORKS.map {|s| " -framework #{s}"}.join
|
44
|
+
$LOCAL_LIBS << ' -lrucy'
|
45
|
+
|
46
|
+
dir_config 'boost'
|
47
|
+
dir_config 'rucy', Rucy.root_dir
|
48
|
+
dir_config 'reflex', Reflex.root_dir
|
49
|
+
|
50
|
+
|
51
|
+
Config::CONFIG.each {|key, val| val.gsub!(/gcc/, 'g++')}
|
52
|
+
|
53
|
+
exit 1 unless HEADERS.all? {|s| have_header(s)}
|
54
|
+
exit 1 unless LIBS.all? {|s| have_library(s)}
|
55
|
+
|
56
|
+
|
57
|
+
create_makefile 'reflex/native'
|