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/lib/reflex/bounds.rb CHANGED
@@ -1,133 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- require 'reflex/point'
4
+ require 'rays/bounds'
5
5
 
6
6
 
7
7
  module Reflex
8
8
 
9
9
 
10
- class Bounds
11
-
12
- include Comparable
13
-
14
- attr_accessor :x, :y, :width, :height
15
-
16
- def initialize (*args)
17
- case args.size
18
- when 0 then @x = @y = @width = @height = 0
19
- when 1 then @x = @y = 0; @width = @height = args[0]
20
- when 2 then @x = @y = 0; @width, @height = args
21
- when 4 then @x, @y, @width, @height = args
22
- else raise ArgumentError
23
- end
24
- end
25
-
26
- def right ()
27
- @x + @width - 1
28
- end
29
-
30
- def right= (right)
31
- @width = right + 1 - @x
32
- end
33
-
34
- def bottom ()
35
- @y + @height - 1
36
- end
37
-
38
- def bottom= (bottom)
39
- @height = bottom + 1 - @y
40
- end
41
-
42
- alias w width
43
- alias w= width=
44
-
45
- alias h height
46
- alias h= height=
47
-
48
- alias left x
49
- alias left= x=
50
-
51
- alias top y
52
- alias top= y=
53
-
54
- alias l left
55
- alias l= left=
56
-
57
- alias t top
58
- alias t= top=
59
-
60
- alias r right
61
- alias r= right=
62
-
63
- alias b bottom
64
- alias b= bottom=
65
-
66
- def offset_to! (*args)
67
- @x, @y = case args.size
68
- when 1 then args * 2
69
- when 2 then args
70
- else raise ArgumentError
71
- end
72
- self
73
- end
74
-
75
- def offset_to (*args)
76
- dup.offset_to! *args
77
- end
78
-
79
- def offset_by! (*args)
80
- dx, dy = case args.size
81
- when 1 then args * 2
82
- when 2 then args
83
- else raise ArgumentError
84
- end
85
- @x += dx
86
- @y += dy
87
- self
88
- end
89
-
90
- def offset_by (*args)
91
- dup.offset_by! *args
92
- end
93
-
94
- def inset_by! (*args)
95
- dx, dy = case args.size
96
- when 1 then args * 2
97
- when 2 then args
98
- else raise ArgumentError
99
- end
100
- @x += dx
101
- @y += dy
102
- @width -= dx * 2
103
- @height -= dy * 2
104
- self
105
- end
106
-
107
- def inset_by (*args)
108
- dup.inset_by! *args
109
- end
110
-
111
- def to_a ()
112
- [@x, @y, @width, @height]
113
- end
114
-
115
- def [] (index)
116
- case index
117
- when 0 then Point.new(left, top)
118
- when 1 then Point.new(right, bottom)
119
- else raise IndexError
120
- end
121
- end
122
-
123
- def <=> (o)
124
- ret = @x <=> o.x; return ret if ret != 0
125
- ret = @y <=> o.y; return ret if ret != 0
126
- ret = right <=> o.right; return ret if ret != 0
127
- bottom <=> o.bottom
128
- end
129
-
130
- end# Bounds
10
+ Bounds = Rays::Bounds
131
11
 
132
12
 
133
13
  end# Reflex
data/lib/reflex/ext.rb ADDED
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/native'
5
+ require 'reflex/native'
@@ -1,52 +1,57 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
+ require 'reflex/point'
5
+ require 'reflex/bounds'
6
+
7
+
4
8
  module Reflex
5
9
 
6
10
 
7
- module Hookable
11
+ module HasBounds
8
12
 
9
- def hook (name, &hookblock)
10
- klass = class << self; self; end
11
- original = klass.instance_method(name).bind self
12
- obj = self
13
- klass.__send__ :define_method, name do |*args, &methodblock|
14
- hookblock.call self, original, *args, &methodblock
15
- end
16
- self
13
+ def bounds (*args)
14
+ b = get_bounds
15
+ b.move_to! *args unless args.empty?
16
+ b
17
17
  end
18
18
 
19
- def before (name, &beforeblock)
20
- hook name do |obj, org, *args, &methodblock|
21
- beforeblock.call(obj, *args, &methodblock)
22
- org.call(*args, &methodblock)
19
+ def bounds= (*args)
20
+ case args[0]
21
+ when Bounds
22
+ set_bounds *args[0].to_a
23
+ when Point
24
+ set_bounds *args.map{|p| p.to_a}.flatten
25
+ when Array
26
+ set_bounds *args[0]
27
+ when Integer, Float
28
+ set_bounds *args
23
29
  end
24
30
  end
25
31
 
26
- def after (name, &afterblock)
27
- hook name do |obj, org, *args, &methodblock|
28
- ret = org.call(*args, &methodblock)
29
- afterblock.call(obj, *args, &methodblock)
30
- ret
31
- end
32
+ def move_to (x, y)
33
+ b = self.bounds
34
+ b.x, b.y = x, y
35
+ self.bounds = b
32
36
  end
33
37
 
34
- def on (name, &onblock)
35
- hook name do |obj, org, *args, &methodblock|
36
- onblock.call(obj, *args, &methodblock)
37
- end
38
+ def move_by (dx, dy)
39
+ b = self.bounds
40
+ move_to b.x + dx, b.y + dy
38
41
  end
39
42
 
40
- end# Hookable
41
-
42
-
43
- module Setter
43
+ def resize_to (width, height)
44
+ b = self.bounds
45
+ b.width, b.height = width, height
46
+ self.bounds = b
47
+ end
44
48
 
45
- def set (name, *value)
46
- __send__ name.to_s + '=', *value
49
+ def resize_by (dwidth, dheight)
50
+ b = self.bounds
51
+ resize_to b.width + dwidth, b.height + dheight
47
52
  end
48
53
 
49
- end# Setter
54
+ end# HasBounds
50
55
 
51
56
 
52
- end# Helpers
57
+ end# Reflex
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/image'
5
+
6
+
7
+ module Reflex
8
+
9
+
10
+ Image = Rays::Image
11
+
12
+
13
+ end# Reflex
data/lib/reflex/module.rb CHANGED
@@ -22,8 +22,15 @@ module Reflex
22
22
  File.join root_dir, 'task'
23
23
  end
24
24
 
25
- def load_tasks ()
26
- Dir["#{task_dir}/**/*.rake"].each {|path| load path}
25
+ def load_tasks (*names)
26
+ if names.empty?
27
+ Dir["#{task_dir}/**/*.rake"].each {|path| load path}
28
+ else
29
+ names.each do |name|
30
+ path = "#{task_dir}/#{name}.rake"
31
+ load path if File.exist? path
32
+ end
33
+ end
27
34
  end
28
35
 
29
36
  def version ()
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/painter'
5
+
6
+
7
+ module Reflex
8
+
9
+
10
+ Painter = Rays::Painter
11
+
12
+
13
+ end# Reflex
data/lib/reflex/point.rb CHANGED
@@ -1,69 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- module Reflex
5
-
6
-
7
- class Point
8
-
9
- include Comparable
10
-
11
- attr_accessor :x, :y
12
-
13
- def initialize (*args)
14
- case args.size
15
- when 0 then @x = @y = 0
16
- when 1 then @x = @y = args[0]
17
- when 2 then @x, @y = args
18
- else raise ArgumentError
19
- end
20
- end
4
+ require 'rays/point'
21
5
 
22
- def offset_to! (*args)
23
- case args.size
24
- when 1 then @x = @y = args[0]
25
- when 2 then @x, @y = args
26
- else raise ArgumentError
27
- end
28
- self
29
- end
30
6
 
31
- def offset_to (*args)
32
- dup.offset_to! *args
33
- end
34
-
35
- def offset_by! (*args)
36
- case args.size
37
- when 1 then @x += args[0]; @y += args[0]
38
- when 2 then @x += args[0]; @y += args[1]
39
- else raise ArgumentError
40
- end
41
- self
42
- end
43
-
44
- def offset_by (*args)
45
- dup.offset_by! *args
46
- end
47
-
48
- def to_a ()
49
- [@x, @y]
50
- end
51
-
52
- def [] (index)
53
- case index
54
- when 0 then @x
55
- when 1 then @y
56
- else raise IndexError
57
- end
58
- end
7
+ module Reflex
59
8
 
60
- def <=> (o)
61
- ret = @x <=> o.x
62
- return ret if ret != 0
63
- @y <=> o.y
64
- end
65
9
 
66
- end# Point
10
+ Point = Rays::Point
67
11
 
68
12
 
69
13
  end# Reflex
data/lib/reflex/reflex.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- require 'reflex/native'
4
+ require 'reflex/ext'
5
5
 
6
6
 
7
7
  module Reflex
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/texture'
5
+
6
+
7
+ module Reflex
8
+
9
+
10
+ Texture = Rays::Texture
11
+
12
+
13
+ end# Reflex
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'xot/hookable'
5
+ require 'xot/setter'
6
+ require 'xot/blockutil'
7
+ require 'reflex/ext'
8
+ require 'reflex/helpers'
9
+
10
+
11
+ module Reflex
12
+
13
+
14
+ class View
15
+
16
+ include Xot::Hookable
17
+ include Xot::Setter
18
+ include HasBounds
19
+
20
+ alias add add_child
21
+ alias remove remove_child
22
+ alias find find_child
23
+
24
+ def initialize (opts = {}, &block)
25
+ super()
26
+ set opts
27
+ Xot::BlockUtil.instance_eval_or_block_call self, &block if block
28
+ end
29
+
30
+ end# View
31
+
32
+
33
+ end# Reflex
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'reflex/image'
5
+ require 'reflex/bitmap'
6
+ require 'reflex/view'
7
+
8
+
9
+ module Reflex
10
+
11
+
12
+ module Visuals
13
+
14
+
15
+ class String < View
16
+
17
+ attr_reader :data
18
+
19
+ def data= (data)
20
+ if data != @data
21
+ @data = data
22
+ @image = nil
23
+ end
24
+ @data
25
+ end
26
+
27
+ def draw (painter, bounds)
28
+ return unless @image ||= create_image(painter)
29
+ painter.fill = 0
30
+ painter.image @image
31
+ end
32
+
33
+ private
34
+
35
+ def create_image (painter)
36
+ dat = self.data
37
+ return nil unless dat
38
+ str = dat.to_s
39
+ font = painter.font
40
+ size = font.width(str), font.height * 10
41
+ resize_to *size
42
+ bmp = Bitmap.new *size, :GRAY
43
+ bmp.draw_string str
44
+ Image.new bmp, true
45
+ end
46
+
47
+ end# String
48
+
49
+
50
+ end# Visuals
51
+
52
+
53
+ end# Reflex
data/lib/reflex/window.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- require 'reflex/native'
5
- require 'reflex/bounds'
4
+ require 'forwardable'
5
+ require 'xot/hookable'
6
+ require 'xot/setter'
7
+ require 'xot/blockutil'
8
+ require 'reflex/ext'
9
+ require 'reflex/painter'
6
10
  require 'reflex/helpers'
7
- require 'rays/painter'
8
11
 
9
12
 
10
13
  module Reflex
@@ -12,51 +15,23 @@ module Reflex
12
15
 
13
16
  class Window
14
17
 
15
- include Hookable
16
- include Setter
18
+ include Xot::Hookable
19
+ include Xot::Setter
20
+ include HasBounds
17
21
 
18
- attr_reader :painter
22
+ extend Forwardable
19
23
 
20
- def initialize (opts = {}, &block)
21
- @painter = Rays::Painter.new.canvas 0, 0, 1, 1
22
- opts.each {|key, value| set key.intern, *value}
23
- instance_eval &block if block
24
- end
25
-
26
- def paint ()
27
- @painter.begin
28
- yield @painter if block_given?
29
- @painter.end
30
- end
31
-
32
- def bounds (*args)
33
- b = Bounds.new *get_bounds
34
- b.offset_to! *args unless args.empty?
35
- b
36
- end
37
-
38
- def bounds= (*args)
39
- case args[0]
40
- when Bounds
41
- set_bounds *args[0].to_a
42
- when Point
43
- set_bounds *args.map{|p| p.to_a}.flatten
44
- when Array
45
- set_bounds *args[0]
46
- when Integer, Float
47
- set_bounds *args
48
- end
49
- end
24
+ def_delegators :root,
25
+ :add, :remove, :find
50
26
 
51
- def draw ()
52
- paint
27
+ def initialize (opts = {}, &block)
28
+ super()
29
+ set opts
30
+ Xot::BlockUtil.instance_eval_or_block_call self, &block if block
53
31
  end
54
32
 
55
- alias org_resized resized
56
-
57
- def resized (width, height)
58
- @painter.canvas 0, 0, width, height
59
- org_resized width, height
33
+ def paint (&block)
34
+ painter.begin &block
60
35
  end
61
36
 
62
37
  end# Window
data/lib/reflex.rb CHANGED
@@ -4,8 +4,8 @@
4
4
  require 'reflex/autoinit'
5
5
  require 'reflex/module'
6
6
  require 'reflex/reflex'
7
- require 'reflex/point'
8
- require 'reflex/bounds'
9
7
  require 'reflex/application'
10
8
  require 'reflex/window'
11
- require 'reflex/helpers'
9
+ require 'reflex/view'
10
+
11
+ require 'reflex/visuals/string'
data/reflex.gemspec CHANGED
@@ -1,70 +1,44 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
 
3
3
 
4
- $: << File.join(File.dirname(__FILE__), 'lib')
4
+ $: << File.expand_path('../lib', __FILE__)
5
5
 
6
- require 'rake'
7
6
  require 'reflex/module'
8
7
 
9
8
 
10
- MODULE = Reflex
11
- NAME = MODULE.name.downcase
12
-
13
-
14
- FILES = FileList[*%W[
15
- README
16
- ChangeLog
17
- Rakefile
18
- #{NAME}.gemspec
19
- VERSION
20
- task/**/*.rake
21
- ext/**/*.rb
22
- ext/**/*.h
23
- ext/**/*.cpp
24
- include/**/*.h
25
- lib/**/*.rb
26
- src/**/*.h
27
- src/**/*.cpp
28
- src/**/*.mm
29
- examples/**/README
30
- examples/**/Rakefile
31
- examples/**/*.h
32
- examples/**/*.cpp
33
- examples/**/*.rb
34
- test/**/*.rb
35
- ]]
36
-
37
- RDOCS = FileList[*%W[
38
- README
39
- .doc/ext/**/*.cpp
40
- ]]
9
+ Gem::Specification.new do |s|
10
+ def glob (*patterns)
11
+ patterns.map {|pat| Dir.glob(pat).to_a}.flatten
12
+ end
41
13
 
14
+ mod = Reflex
15
+ name = mod.name.downcase
16
+ rdocs = glob *%w[README .doc/ext/**/*.cpp]
42
17
 
43
- Gem::Specification.new do |s|
44
- s.name = "#{NAME}ion"
18
+ s.name = "#{name}ion"
45
19
  s.summary = 'A Graphical User Interface Tool Kit.'
46
20
  s.description = 'This library helps you to develop interactive graphical user interface.'
47
- s.version = MODULE.version
21
+ s.version = mod.version
48
22
 
49
23
  s.authors = %w[snori]
50
24
  s.email = 'snori@xord.org'
51
- s.homepage = "http://github.com/xord/#{NAME}"
25
+ s.homepage = "http://github.com/xord/#{name}"
52
26
 
53
27
  s.platform = Gem::Platform::RUBY
54
28
  s.required_ruby_version = '>=1.9.0'
55
- s.require_paths << 'ext'
56
29
 
30
+ s.add_runtime_dependency 'bundler'
57
31
  s.add_runtime_dependency 'xot'
58
32
  s.add_runtime_dependency 'rucy'
59
33
  s.add_runtime_dependency 'rays'
60
34
  s.add_development_dependency 'rake'
61
35
  s.add_development_dependency 'gemcutter'
62
36
 
63
- s.files = FILES.to_a
64
- s.test_files = FileList['test/**/test_*.rb'].to_a
65
-
37
+ s.files = `git ls-files`.split $/
38
+ s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
39
+ s.test_files = s.files.grep %r{^(test|spec|features)/}
40
+ s.extra_rdoc_files = rdocs.to_a
66
41
  s.has_rdoc = true
67
- s.extra_rdoc_files = RDOCS.to_a
68
42
 
69
43
  s.extensions << 'Rakefile'
70
44
  end