reflexion 0.1.3 → 0.1.4

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 (88) hide show
  1. data/.doc/ext/reflex/application.cpp +35 -76
  2. data/.doc/ext/reflex/defs.cpp +8 -0
  3. data/.doc/ext/reflex/key.cpp +38 -43
  4. data/.doc/ext/reflex/native.cpp +6 -4
  5. data/.doc/ext/reflex/points.cpp +47 -52
  6. data/.doc/ext/reflex/reflex.cpp +12 -13
  7. data/.doc/ext/reflex/view.cpp +242 -0
  8. data/.doc/ext/reflex/window.cpp +87 -178
  9. data/.gitignore +14 -0
  10. data/Rakefile +6 -31
  11. data/VERSION +1 -1
  12. data/examples/hello/.gitignore +2 -0
  13. data/examples/ruby/app.rb +2 -2
  14. data/examples/ruby/checker.rb +3 -3
  15. data/examples/ruby/fps.rb +14 -14
  16. data/examples/ruby/grid.rb +65 -0
  17. data/examples/ruby/hello.rb +19 -7
  18. data/examples/ruby/key.rb +4 -4
  19. data/examples/ruby/shapes.rb +6 -6
  20. data/examples/ruby/text.rb +20 -17
  21. data/examples/ruby/views.rb +88 -0
  22. data/examples/ruby/visuals.rb +27 -0
  23. data/ext/reflex/application.cpp +36 -76
  24. data/ext/reflex/defs.cpp +8 -0
  25. data/ext/reflex/defs.h +1 -18
  26. data/ext/reflex/extconf.rb +16 -8
  27. data/ext/reflex/key.cpp +39 -43
  28. data/ext/reflex/native.cpp +6 -4
  29. data/ext/reflex/points.cpp +48 -52
  30. data/ext/reflex/reflex.cpp +12 -13
  31. data/ext/reflex/view.cpp +260 -0
  32. data/ext/reflex/window.cpp +89 -178
  33. data/include/reflex/application.h +14 -7
  34. data/include/reflex/defs.h +8 -6
  35. data/include/reflex/exception.h +1 -1
  36. data/include/reflex/ruby/application.h +31 -10
  37. data/include/reflex/ruby/key.h +3 -3
  38. data/include/reflex/ruby/points.h +3 -3
  39. data/include/reflex/ruby/view.h +106 -0
  40. data/include/reflex/ruby/window.h +83 -12
  41. data/include/reflex/ruby.h +3 -2
  42. data/include/reflex/view.h +103 -0
  43. data/include/reflex/window.h +43 -18
  44. data/include/reflex.h +2 -1
  45. data/lib/reflex/application.rb +8 -7
  46. data/lib/reflex/autoinit.rb +1 -1
  47. data/lib/reflex/bitmap.rb +13 -0
  48. data/lib/reflex/bounds.rb +2 -122
  49. data/lib/reflex/ext.rb +5 -0
  50. data/lib/reflex/helpers.rb +36 -31
  51. data/lib/reflex/image.rb +13 -0
  52. data/lib/reflex/module.rb +9 -2
  53. data/lib/reflex/painter.rb +13 -0
  54. data/lib/reflex/point.rb +3 -59
  55. data/lib/reflex/reflex.rb +1 -1
  56. data/lib/reflex/texture.rb +13 -0
  57. data/lib/reflex/view.rb +33 -0
  58. data/lib/reflex/visuals/string.rb +53 -0
  59. data/lib/reflex/window.rb +18 -43
  60. data/lib/reflex.rb +3 -3
  61. data/reflex.gemspec +16 -42
  62. data/src/cocoa/application.mm +17 -23
  63. data/src/cocoa/applicationdata.h +3 -9
  64. data/src/cocoa/cocoaapplication.h +6 -4
  65. data/src/cocoa/cocoaapplication.mm +61 -19
  66. data/src/cocoa/cocoawindow.h +7 -5
  67. data/src/cocoa/cocoawindow.mm +109 -50
  68. data/src/cocoa/defs.mm +5 -2
  69. data/src/cocoa/window.mm +71 -41
  70. data/src/cocoa/windowdata.h +14 -9
  71. data/src/defs.cpp +1 -1
  72. data/src/exception.cpp +3 -18
  73. data/src/helpers.h +12 -0
  74. data/src/reflex.cpp +11 -5
  75. data/src/view.cpp +326 -0
  76. data/src/win32/application.cpp +7 -8
  77. data/src/win32/defs.h +1 -1
  78. data/src/win32/window.cpp +137 -41
  79. data/src/window.cpp +38 -1
  80. data/test/helpers.rb +2 -5
  81. data/test/test_application.rb +17 -0
  82. data/test/test_reflex.rb +4 -2
  83. data/test/test_view.rb +74 -0
  84. data/test/test_window.rb +33 -2
  85. metadata +157 -97
  86. data/include/reflex/helpers.h +0 -32
  87. data/test/test_bounds.rb +0 -163
  88. data/test/test_point.rb +0 -81
data/Rakefile CHANGED
@@ -1,12 +1,8 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[. ../xot ../rucy ../rays].map {|s| "#{s}/lib"}.each do |path|
5
- $: << File.expand_path(File.join File.dirname(__FILE__), *path.split('/'))
6
- end
7
-
8
- require 'rubygems'
9
- require 'xot/rake/helpers'
4
+ require 'bundler/setup'
5
+ require 'xot/rake'
10
6
  require 'xot/module'
11
7
  require 'rucy/module'
12
8
  require 'rays/module'
@@ -15,36 +11,15 @@ require 'reflex/module'
15
11
  include Xot::Rake
16
12
 
17
13
 
18
- MODULE = Reflex
19
- GEMNAME = 'reflexion'
20
- INCDIRS = [Reflex, Rays, Rucy].map {|m| m.include_dirs}.flatten
14
+ MODULE = Reflex
15
+ GEMNAME = 'reflexion'
16
+ INCDIRS = [Reflex, Rays, Rucy, Xot].map {|m| m.include_dirs}.flatten
17
+ TESTS_ALONE = ['test/test_reflex.rb']
21
18
 
22
19
 
23
20
  task :default => :build
24
21
 
25
22
  task :build => :ext
26
23
 
27
- task :rebuild => [:clean, :build]
28
-
29
- task :lib => 'lib:build'
30
-
31
- task :ext => 'ext:build'
32
-
33
- task :doc => 'ext:doc'
34
-
35
- task :gem => 'gem:build'
36
-
37
- task :install => 'gem:install'
38
-
39
- task :uninstall => 'gem:uninstall'
40
-
41
- task :clean => ['lib:clean', 'ext:clean', 'gem:clean']
42
-
43
- task :test => :ext do
44
- Dir['test/**/test_*.rb'].each do |rb|
45
- sh %( ruby #{rb} )
46
- end
47
- end
48
-
49
24
 
50
25
  [Xot, Rucy, Rays, Reflex].each {|m| m.load_tasks}
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -0,0 +1,2 @@
1
+ hello
2
+ hello.exe
data/examples/ruby/app.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[rays reflex].product(%w[ext lib]).each do |paths|
4
+ %w[xot rays reflex].product(%w[ext lib]).each do |paths|
5
5
  $: << File.expand_path(
6
- File.join File.dirname(__FILE__), "..", "..", "..", *paths)
6
+ File.join File.dirname(__FILE__), *%w[.. .. ..], *paths)
7
7
  end
8
8
 
9
9
  require 'reflex'
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[rays reflex].product(%w[ext lib]).each do |paths|
4
+ %w[xot rays reflex].product(%w[ext lib]).each do |paths|
5
5
  $: << File.expand_path(
6
- File.join File.dirname(__FILE__), "..", "..", "..", *paths)
6
+ File.join File.dirname(__FILE__), *%w[.. .. ..], *paths)
7
7
  end
8
8
 
9
9
  require 'rubygems'
@@ -17,7 +17,7 @@ class CheckerWindow < Reflex::Window
17
17
  set :title, "Hello Reflex!"
18
18
  set :bounds, 100, 100, 320, 240
19
19
  painter.font = Rays::Font.new nil, 32
20
- painter.clear = 1
20
+ painter.background = 1
21
21
  end
22
22
 
23
23
  def draw ()
data/examples/ruby/fps.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[rays reflex].product(%w[ext lib]).each do |paths|
4
+ %w[xot rays reflex].product(%w[ext lib]).each do |paths|
5
5
  $: << File.expand_path(
6
- File.join File.dirname(__FILE__), "..", "..", "..", *paths)
6
+ File.join File.dirname(__FILE__), *%w[.. .. ..], *paths)
7
7
  end
8
8
 
9
9
  require 'reflex'
@@ -11,19 +11,19 @@ require 'reflex'
11
11
 
12
12
  x = 0
13
13
  y = 0
14
- font = Rays::Font.new("Osaka", 32)
14
+ font = Rays::Font.new "Osaka", 32
15
15
  prev = Time.now
16
16
  fps = 0
17
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|
18
+ w = Reflex::Window
19
+ .new(:title => "Reflex on Ruby", :bounds => [100, 100, 600, 400])
20
+ .before(:close) {w.hide; sleep 1; w.show; sleep 1}
21
+ .on(:moved) {|x, y| p [x, y]}
22
+ .on(:resized) {|w, h| p [w, h]}
23
+ .on(:update) {w.redraw}
24
+ .on(:draw) do
25
+ b = w.bounds 0
26
+ w.paint do |p|
27
27
  p.fill = 1, 0.5, 0.5, 0.05
28
28
  #p.stroke = 0.5, 0.5, 1
29
29
  100.times do
@@ -43,7 +43,7 @@ w = Reflex::Window.
43
43
  p.text "#{fps.to_i} FPS", 0, b.bottom - font.height, font
44
44
  prev = now
45
45
  end
46
- end.
47
- show
46
+ end
48
47
 
48
+ w.show
49
49
  Reflex.run
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ %w[xot rays reflex].product(%w[ext lib]).each do |paths|
5
+ $: << File.expand_path(
6
+ File.join File.dirname(__FILE__), *%w[.. .. ..], *paths)
7
+ end
8
+
9
+ require 'rubygems'
10
+ require 'reflex'
11
+
12
+
13
+ Reflex::Window.new do
14
+ set title: "Grid Test", bounds: [100, 100, 50, 50]
15
+ painter.background 0
16
+
17
+ on :draw do
18
+ paint do |p|
19
+ p.push_matrix
20
+ p.push_attrs
21
+
22
+ w, h = bounds.size.to_a
23
+
24
+ p.fill 1, 0, 0
25
+
26
+ p.rect 1, 1, 5, 5
27
+
28
+ p.stroke 0.3, 0.4
29
+ (0..bounds.width) .step(2).each {|x| p.line x, 0, x, h}
30
+ (0..bounds.height).step(2).each {|y| p.line 0, y, w, y}
31
+ p.stroke 0.5, 0.4
32
+ (0..bounds.width) .step(10).each {|x| p.line x, 0, x, h}
33
+ (0..bounds.height).step(10).each {|y| p.line 0, y, w, y}
34
+
35
+ p.translate 3, 10, 0
36
+ p.fill nil
37
+ p.stroke 1
38
+
39
+ p.line 0, 0, 5, 0
40
+
41
+ p.translate 0, 10, 0
42
+
43
+ p.rect 0, 0, 5, 5
44
+
45
+ p.translate 0, 10, 0
46
+ p.fill 0.5, 0.5, 1
47
+ p.stroke nil
48
+
49
+ p.rect 0, 0, 5, 5
50
+
51
+ p.translate 0, 10, 0
52
+ p.fill 0.5, 0.5, 1
53
+ p.stroke 0.5, 1, 0.5
54
+
55
+ p.rect 0, 0, 5, 5
56
+
57
+ p.pop_attrs
58
+ p.pop_matrix
59
+ end
60
+ end
61
+
62
+ show
63
+ end
64
+
65
+ Reflex.run
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[rays reflex].product(%w[ext lib]).each do |paths|
4
+ %w[xot rays reflex].product(%w[ext lib]).each do |paths|
5
5
  $: << File.expand_path(
6
- File.join File.dirname(__FILE__), "..", "..", "..", *paths)
6
+ File.join File.dirname(__FILE__), *%w[.. .. ..], *paths)
7
7
  end
8
8
 
9
9
  require 'rubygems'
@@ -16,21 +16,33 @@ class HelloWindow < Reflex::Window
16
16
  super
17
17
  set :title, "Hello Reflex!"
18
18
  set :bounds, 100, 100, 320, 240
19
- painter.font = Rays::Font.new nil, 32
19
+ p = painter
20
+ p.font Rays::Font.new "Menlo", 32
21
+ p.background 0
22
+ p.fill 1
20
23
  end
21
24
 
22
25
  def draw ()
23
26
  paint do |p|
24
- p.fill = 1
25
- p.text "hello world!", 100, 100
27
+ draw_grid p
28
+ p.text "hello world!", 5, 5
26
29
  end
27
30
  end
28
31
 
29
- def update ()
30
- #painter.clear = rand, rand, rand
32
+ def update_ (dt)
33
+ painter.background = rand, rand, rand
31
34
  redraw
32
35
  end
33
36
 
37
+ def draw_grid (p)
38
+ p.push do
39
+ w, h = bounds.size.to_a
40
+ p.stroke 0.5, 0.4
41
+ (0..w).step(5).each {|x| p.line x, 0, x, h}
42
+ (0..h).step(5).each {|y| p.line 0, y, w, y}
43
+ end
44
+ end
45
+
34
46
  end# HelloWindow
35
47
 
36
48
 
data/examples/ruby/key.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[rays reflex].product(%w[ext lib]).each do |paths|
4
+ %w[xot rays reflex].product(%w[ext lib]).each do |paths|
5
5
  $: << File.expand_path(
6
- File.join File.dirname(__FILE__), "..", "..", "..", *paths)
6
+ File.join File.dirname(__FILE__), *%w[.. .. ..], *paths)
7
7
  end
8
8
 
9
9
  require 'rubygems'
@@ -26,7 +26,7 @@ w.on :draw do
26
26
  end
27
27
  end
28
28
 
29
- w.on :key_down do |obj, key|
29
+ w.on :key_down do |key|
30
30
  w.close if key.code == 53
31
31
  $text += key.chars
32
32
  $text = $text[-10..-1] if $text.size > 10
@@ -34,7 +34,7 @@ w.on :key_down do |obj, key|
34
34
  w.redraw
35
35
  end
36
36
 
37
- w.on :points_moved do |obj, points|
37
+ w.on :points_moved do |points|
38
38
  $pos = "#{points.x}, #{points.y}"
39
39
  p [points.type, points.x, points.y, points.size, points.modifiers, points.count, points.drag]
40
40
  w.redraw
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[rays reflex].product(%w[ext lib]).each do |paths|
4
+ %w[xot rays reflex].product(%w[ext lib]).each do |paths|
5
5
  $: << File.expand_path(
6
- File.join File.dirname(__FILE__), "..", "..", "..", *paths)
6
+ File.join File.dirname(__FILE__), *%w[.. .. ..], *paths)
7
7
  end
8
8
 
9
9
  require 'rubygems'
@@ -57,7 +57,7 @@ class Ring
57
57
  fin p, 270, w
58
58
  end
59
59
 
60
- def update ()
60
+ def update (dt)
61
61
  @angle = (@angle + @rot) % 360
62
62
  end
63
63
 
@@ -78,7 +78,7 @@ class ShapesWindow < Reflex::Window
78
78
  super
79
79
  set :title, "Shapes Sample"
80
80
  set :bounds, 100, 400, 640, 240
81
- painter.clear = 1
81
+ painter.background = 1
82
82
  @rings = []
83
83
  setup
84
84
  end
@@ -101,8 +101,8 @@ class ShapesWindow < Reflex::Window
101
101
  end
102
102
  end
103
103
 
104
- def update ()
105
- each {|o| o.update}
104
+ def update (dt)
105
+ each {|o| o.update dt}
106
106
  redraw
107
107
  @count ||= 0
108
108
  fps_ = fps
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- %w[rays reflex].product(%w[ext lib]).each do |paths|
4
+ %w[xot rays reflex].product(%w[ext lib]).each do |paths|
5
5
  $: << File.expand_path(
6
- File.join File.dirname(__FILE__), "..", "..", "..", *paths)
6
+ File.join File.dirname(__FILE__), *%w[.. .. ..], *paths)
7
7
  end
8
8
 
9
9
  require 'reflex'
@@ -12,24 +12,27 @@ require 'reflex'
12
12
  lines = File.readlines(__FILE__)
13
13
 
14
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
15
+ Reflex::Window.new do
16
+ set title: "Rays/Reflex Text Test", bounds: [100, 100, 600, 400]
17
+ painter.background 0.1
18
+ painter.font Rays::Font.new 'Menlo', 12
19
+ on :draw do
20
+ paint do
21
+ linenum = "%5d "
22
+ linenum_width = font.width(linenum % 0).ceil
23
+ line_height = (font.height * 1.0).ceil
24
+
25
+ fill 0.3
26
+ rect 0, 0, linenum_width, 10000
27
+
28
+ fill 1 #rand, rand, rand, 1
28
29
  lines.each.with_index do |line, i|
29
- p.text line.chomp, 0, p.font.height * i
30
+ text "#{linenum % i} #{line.chomp}"
31
+ translate 0, line_height
30
32
  end
31
33
  end
32
- end.
34
+ end
33
35
  show
36
+ end
34
37
 
35
38
  Reflex.run
@@ -0,0 +1,88 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ %w[xot rays reflex].product(%w[ext lib]).each do |paths|
5
+ $: << File.expand_path(
6
+ File.join File.dirname(__FILE__), *%w[.. .. ..], *paths)
7
+ end
8
+
9
+ require 'rubygems'
10
+ require 'reflex'
11
+
12
+
13
+ def View (&block)
14
+ Reflex::View.new &block
15
+ end
16
+
17
+
18
+ Reflex::Window.new do
19
+ set :title, "Views Sample"
20
+ set :bounds, 100, 100, 300, 300
21
+ @count = 0
22
+
23
+ def count ()
24
+ @count
25
+ end
26
+
27
+ def spawn (x, y)
28
+ @count += 1
29
+ add View {
30
+ c = [rand, rand, rand]
31
+ size = 16
32
+ set :bounds, x - size, y - size, size * 2, size * 2
33
+ @angle = 0
34
+ @speed = (rand * 2 - 1) * 30
35
+
36
+ on :update do
37
+ move_by rand(5) - 2, rand(5) - 2
38
+ @angle += @speed
39
+ @angle %= 360
40
+ redraw
41
+ end
42
+
43
+ on :draw do |p, b|
44
+ p.fill *c
45
+ #p.rect *b.to_a
46
+ p.arc *b.to_a, @angle, @angle + 90
47
+ p.arc *b.to_a, @angle + 180, @angle + 270
48
+ end
49
+ }
50
+ end
51
+
52
+ on :key_down do |key|
53
+ p [key.chars, key.code, key.repeat, key.modifiers]
54
+ close if key.code == 53
55
+ end
56
+
57
+ on :points_down do |ps|
58
+ spawn ps.x, ps.y
59
+ @spawning = true
60
+ end
61
+
62
+ on :points_up do |ps|
63
+ @spawning = false
64
+ end
65
+
66
+ on :points_moved do |ps|
67
+ spawn ps.x, ps.y if @spawning
68
+ end
69
+
70
+ add View {
71
+ on :draw do |p, b|
72
+ set :bounds, window.bounds.move_to(0)
73
+ p.fill 1
74
+ p.text "count: #{window.count}", 10, 10
75
+ end
76
+ }
77
+
78
+ root.on :draw do |p, b|
79
+ p.fill 1
80
+ p.text "draw on root view.", 10, 30
81
+ end
82
+
83
+ #100.times {spawn *bounds.move_to(0).center.to_a}
84
+ show
85
+ end
86
+
87
+
88
+ Reflex.run "Views"
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ %w[xot rays reflex].product(%w[ext lib]).each do |paths|
5
+ $: << File.expand_path(
6
+ File.join File.dirname(__FILE__), *%w[.. .. ..], *paths)
7
+ end
8
+
9
+ require 'rubygems'
10
+ require 'reflex'
11
+
12
+
13
+ Reflex::Application.new :name => 'Visuals' do |app|
14
+ Reflex::Window.new :title => app.name do |win|
15
+ win.bounds = 100, 100, 600, 500
16
+ win.painter.background = 0.8
17
+ 10.times do |i|
18
+ Reflex::Visuals::String.new :name => 'hello' do |v|
19
+ v.data = 'HELLO WORLD!'
20
+ v.move_to *([i * 5] * 2)
21
+ win.add v
22
+ end
23
+ end
24
+ win.show
25
+ end
26
+ app.run
27
+ end
@@ -8,12 +8,13 @@
8
8
  using namespace Rucy;
9
9
 
10
10
 
11
+ static Class cApplication;
12
+
13
+
11
14
  namespace Reflex
12
15
  {
13
16
 
14
17
 
15
- static Class cApplication;
16
-
17
18
  Class
18
19
  application_class ()
19
20
  {
@@ -24,66 +25,20 @@ namespace Reflex
24
25
  }// Reflex
25
26
 
26
27
 
27
- namespace Rucy
28
- {
29
-
30
-
31
- Value
32
- value (const Reflex::Application& application)
33
- {
34
- return new_type<Reflex::Application>(
35
- Reflex::application_class(), new Reflex::Application(application));
36
- }
37
-
38
-
39
- }// Rucy
40
-
41
-
42
- class RubyApplication : public Reflex::Application
43
- {
44
-
45
- public:
46
-
47
- typedef Reflex::Application Super;
48
-
49
- Value self;
50
-
51
- void mark ()
52
- {
53
- self.mark();
54
- }
55
-
56
- virtual bool run ()
57
- {
58
- SYM(run);
59
- return self.call(run);
60
- }
28
+ typedef Reflex::RubyApplication<Reflex::Application> RubyApplication;
61
29
 
62
- virtual bool quit ()
63
- {
64
- SYM(quit);
65
- return self.call(quit);
66
- }
67
30
 
68
- virtual bool about ()
69
- {
70
- SYM(about);
71
- return self.call(about);
72
- }
31
+ #define THIS to<Reflex::Application*>(self)
73
32
 
74
- };// RubyApplication
33
+ #define CHECK RUCY_CHECK_OBJECT(self, Reflex::Application, cApplication)
75
34
 
76
-
77
- #define this ((RubyApplication*) to<Reflex::Application*>(self))
78
-
79
- #define CHECK CHECK_OBJECT(self, RubyApplication, Reflex::application_class())
35
+ #define CALL(fun) RUCY_WRAPPER_CALL(RubyApplication, THIS, fun)
80
36
 
81
37
 
82
38
  static
83
39
  RUBY_DEF_ALLOC(alloc, klass)
84
40
  {
85
- RubyApplication* app = new RubyApplication;
86
- return app->self = new_type<RubyApplication>(klass, app, mark_type<RubyApplication>);
41
+ return value(new RubyApplication, klass);
87
42
  }
88
43
  RUBY_END
89
44
 
@@ -91,7 +46,7 @@ static
91
46
  RUBY_DEF0(run)
92
47
  {
93
48
  CHECK;
94
- if (!this->Super::run())
49
+ if (!CALL(run()))
95
50
  system_error("failed to run application.");
96
51
  return self;
97
52
  }
@@ -101,7 +56,7 @@ static
101
56
  RUBY_DEF0(quit)
102
57
  {
103
58
  CHECK;
104
- if (!this->Super::quit())
59
+ if (!CALL(quit()))
105
60
  system_error("failed to quit application.");
106
61
  return self;
107
62
  }
@@ -111,30 +66,36 @@ static
111
66
  RUBY_DEF0(about)
112
67
  {
113
68
  CHECK;
114
- if (!this->Super::about())
69
+ if (!CALL(about()))
115
70
  system_error("failed to show about application.");
116
71
  return self;
117
72
  }
118
73
  RUBY_END
119
74
 
120
75
  static
121
- RUBY_DEF0(get_name)
76
+ RUBY_DEF1(set_name, name)
122
77
  {
123
78
  CHECK;
124
- String s;
125
- if (!this->get_name(&s))
126
- system_error("failed to get name of application.");
127
- return Value(s.c_str());
79
+ if (!THIS->set_name(name.c_str()))
80
+ system_error("failed to set name of application.");
81
+ return name;
128
82
  }
129
83
  RUBY_END
130
84
 
131
85
  static
132
- RUBY_DEF1(set_name, name)
86
+ RUBY_DEF0(get_name)
133
87
  {
134
88
  CHECK;
135
- if (!this->set_name(name.c_str()))
136
- system_error("failed to set name of application.");
137
- return name;
89
+ const char* s = THIS->name();
90
+ if (!s) system_error("failed to get name of application.");
91
+ return value(s);
92
+ }
93
+ RUBY_END
94
+
95
+ static
96
+ RUBY_DEF0(instance)
97
+ {
98
+ return value(Reflex::app());
138
99
  }
139
100
  RUBY_END
140
101
 
@@ -142,15 +103,14 @@ RUBY_END
142
103
  void
143
104
  Init_application ()
144
105
  {
145
- Module m = define_module("Reflex");
146
-
147
- Class c = m.define_class("Application");
148
- Reflex::cApplication = c;
149
-
150
- c.define_alloc_func(alloc);
151
- c.define_method("run", run);
152
- c.define_method("quit", quit);
153
- c.define_method("about", about);
154
- c.define_method("name", get_name);
155
- c.define_method("name=", set_name);
106
+ Module mReflex = define_module("Reflex");
107
+
108
+ cApplication = mReflex.define_class("Application");
109
+ cApplication.define_alloc_func(alloc);
110
+ cApplication.define_method("run", run);
111
+ cApplication.define_method("quit", quit);
112
+ cApplication.define_method("about", about);
113
+ cApplication.define_method("name=", set_name);
114
+ cApplication.define_method("name", get_name);
115
+ cApplication.define_singleton_method("instance", instance);
156
116
  }
@@ -0,0 +1,8 @@
1
+ #include "defs.h"
2
+
3
+
4
+ #include <rucy/value.h>
5
+ #include <reflex/defs.h>
6
+
7
+
8
+ using namespace Rucy;