rubygoo 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,144 +1,152 @@
1
1
  require 'publisher'
2
2
  require 'css_colors'
3
3
  require 'goo_color'
4
- class Widget
5
- extend Publisher
6
- can_fire :clicked
7
- attr_accessor :enabled, :parent, :container,
8
- :x, :y, :w, :h, :app, :x_pad, :y_pad, :focussed,
9
- :focus_priority
10
-
11
- DEFAULT_PARAMS = {
12
- :x => 0,
13
- :y => 0,
14
- :w => 1,
15
- :h => 1,
16
- :x_pad => 2,
17
- :y_pad => 2,
18
- }
19
- def initialize(opts={})
20
- merged_opts = DEFAULT_PARAMS.merge opts
21
- @x = merged_opts[:x]
22
- @y = merged_opts[:y]
23
- @x_pad = merged_opts[:x_pad]
24
- @y_pad = merged_opts[:y_pad]
25
- @w = merged_opts[:w]
26
- @h = merged_opts[:h]
27
- update_rect
28
- end
4
+ require 'rect'
5
+ module Rubygoo
6
+ class Widget
7
+ extend Publisher
8
+ can_fire :clicked
9
+ attr_accessor :enabled, :parent, :container,
10
+ :x, :y, :w, :h, :app, :x_pad, :y_pad, :focussed,
11
+ :focus_priority
12
+
13
+ DEFAULT_PARAMS = {
14
+ :x => 0,
15
+ :y => 0,
16
+ :w => 1,
17
+ :h => 1,
18
+ :x_pad => 2,
19
+ :y_pad => 2,
20
+ }
21
+ def initialize(opts={})
22
+ merged_opts = DEFAULT_PARAMS.merge opts
23
+ @x = merged_opts[:x]
24
+ @y = merged_opts[:y]
25
+ @x_pad = merged_opts[:x_pad]
26
+ @y_pad = merged_opts[:y_pad]
27
+ @w = merged_opts[:w]
28
+ @h = merged_opts[:h]
29
+ update_rect
30
+ end
29
31
 
30
- def update_rect()
31
- @rect = Rect.new [@x,@y,@w+@x_pad,@h+@y_pad]
32
- end
32
+ def update_rect()
33
+ @rect = Rect.new [@x,@y,@w+@x_pad,@h+@y_pad]
34
+ end
33
35
 
34
- # called when the widget is added to a container
35
- def added()
36
- end
36
+ # called when the widget is added to a container
37
+ def added()
38
+ end
37
39
 
38
- # called when the widget is removed from a container
39
- def removed()
40
- end
40
+ # called when the widget is removed from a container
41
+ def removed()
42
+ end
41
43
 
42
- def contains?(pos)
43
- @rect.collide_point? pos[0], pos[1]
44
- end
44
+ def contains?(pos)
45
+ @rect.collide_point? pos[0], pos[1]
46
+ end
45
47
 
46
- def enabled?()
47
- @enabled
48
- end
48
+ def enabled?()
49
+ @enabled
50
+ end
49
51
 
50
- def update(millis)
51
- end
52
+ def update(millis)
53
+ end
52
54
 
53
- # draw ourself on the screen
54
- def draw(screen)
55
- end
55
+ # draw ourself on the screen
56
+ def draw(screen)
57
+ end
56
58
 
57
- # called when there is a mouse click
58
- def mouse_down(event)
59
- end
59
+ # called when there is a mouse click
60
+ def mouse_down(event)
61
+ end
60
62
 
61
- # called when there is a mouse motion
62
- def mouse_motion(event)
63
- end
63
+ # called when there is a mouse motion
64
+ def mouse_motion(event)
65
+ end
64
66
 
65
- # called when there is a mouse release
66
- def mouse_up(event)
67
- end
67
+ # called when there is a mouse release
68
+ def mouse_up(event)
69
+ end
68
70
 
69
- # called when a key press is sent to us
70
- def key_pressed(event)
71
- end
71
+ # called when a key press is sent to us
72
+ def key_pressed(event)
73
+ end
72
74
 
73
- # called when a key release is sent to us
74
- def key_released(event)
75
- end
75
+ # called when a key release is sent to us
76
+ def key_released(event)
77
+ end
76
78
 
77
- # called when the widget receives focus
78
- def on_focus()
79
- end
79
+ # called when the widget receives focus
80
+ def on_focus()
81
+ end
80
82
 
81
- def focus()
82
- @focussed = true
83
- on_focus
84
- end
83
+ def focus()
84
+ @focussed = true
85
+ on_focus
86
+ end
85
87
 
86
- # called when the widget loses focus
87
- def on_unfocus()
88
- end
88
+ # called when the widget loses focus
89
+ def on_unfocus()
90
+ end
89
91
 
90
- def unfocus()
91
- @focussed = false
92
- on_unfocus
93
- end
94
-
95
- def focussed?()
96
- @focussed
97
- end
92
+ def unfocus()
93
+ @focussed = false
94
+ on_unfocus
95
+ end
96
+
97
+ def focussed?()
98
+ @focussed
99
+ end
98
100
 
99
- # gets the property for the class asking for it.
100
- # it will walk up the object hierarchy if needed
101
- def theme_property(prop_key)
102
- prop = nil
103
- parent = self.class
104
- until parent == Object
105
- class_theme = app.theme[parent.to_s]
106
- if class_theme
107
- class_prop = class_theme[prop_key]
108
- if class_prop
109
- prop = class_prop
110
- break
101
+ # gets the property for the class asking for it.
102
+ # it will walk up the object hierarchy if needed
103
+ def theme_property(prop_key)
104
+ prop = nil
105
+ parent = self.class
106
+ until parent == Object
107
+ class_theme = app.theme[parent.to_s]
108
+ if class_theme
109
+ class_prop = class_theme[prop_key]
110
+ if class_prop
111
+ prop = class_prop
112
+ break
113
+ end
111
114
  end
115
+ parent = parent.superclass
116
+ end
117
+ if prop_key.to_s.match /color/i
118
+ get_color prop
119
+ else
120
+ prop
112
121
  end
113
- parent = parent.superclass
114
- end
115
- if prop_key.to_s.match /color/i
116
- get_color prop
117
- else
118
- prop
119
122
  end
120
- end
121
123
 
122
- def get_color(color)
123
- new_color = nil
124
- if color.is_a? Array
125
- if color.size > 3
126
- new_color = color
127
- else
128
- # fill in zeros for all other colors
129
- 3-color.size.times do
130
- color << 0
124
+ def get_color(color)
125
+ new_color = nil
126
+ if color.is_a? Array
127
+ if color.size > 3
128
+ new_color = color
129
+ else
130
+ # fill in zeros for all other colors
131
+ 3-color.size.times do
132
+ color << 0
133
+ end
134
+ # fill in alpha as 255
135
+ color << 255
131
136
  end
132
- # fill in alpha as 255
133
- color << 255
137
+ elsif color.is_a? Symbol
138
+ new_color = CSS_COLORS[color]
139
+ else
140
+ raise "invalid color"
134
141
  end
135
- elsif color.is_a? Symbol
136
- new_color = CSS_COLORS[color]
137
- else
138
- raise "invalid color"
142
+
143
+ GooColor.new *new_color
144
+ end
145
+
146
+ # called each update cycle with the amount of time that has passed. useful
147
+ # for animations, etc
148
+ def update(time)
139
149
  end
140
150
 
141
- GooColor.new *new_color
142
151
  end
143
-
144
152
  end
@@ -3,13 +3,20 @@ $: << './lib'
3
3
  require 'rubygoo'
4
4
 
5
5
  require 'gosu'
6
- require 'rubygame'
7
6
  include Gosu
8
- include Rubygame
7
+ include Rubygoo
9
8
 
10
- class GameWindow < Window
9
+ class RubygooWindow < Window
11
10
  def initialize()
11
+
12
12
  super(640, 480, false)
13
+
14
+ # TODO, how can I do this cleaner?
15
+ %w{a b c d e f g h i j k l m n o p q r s t u v w x y z}.each do |letter|
16
+ eval "::Kb#{letter.upcase} = #{self.char_to_button_id(letter)}"
17
+ end
18
+ # how do I get rid of this?
19
+ require 'gosu_app_adapter'
13
20
  factory = AdapterFactory.new
14
21
  @render_adapter = factory.renderer_for :gosu, self
15
22
  app = create_gui(@render_adapter)
@@ -96,7 +103,7 @@ end
96
103
 
97
104
  if $0 == __FILE__
98
105
 
99
- window = GameWindow.new
106
+ window = RubygooWindow.new
100
107
  window.show
101
108
 
102
109
  end
@@ -3,6 +3,7 @@ $: << './lib'
3
3
  require 'rubygoo'
4
4
  require 'rubygame'
5
5
  include Rubygame
6
+ include Rubygoo
6
7
 
7
8
  def create_gui(renderer)
8
9
  app = App.new :renderer => renderer
@@ -62,6 +63,7 @@ end
62
63
  if $0 == __FILE__
63
64
 
64
65
  screen = Screen.new [600,480]
66
+ screen.show_cursor = false
65
67
 
66
68
  factory = AdapterFactory.new
67
69
  render_adapter = factory.renderer_for :rubygame, screen
@@ -1,20 +1,23 @@
1
1
  ---
2
- App:
2
+ Rubygoo::App:
3
3
  :bg_color: :Black
4
- Widget:
4
+ Rubygoo::Widget:
5
5
  :font: Vera.ttf
6
6
  :font_size: 20
7
7
  :color: :Black
8
8
  :focus_color: :FireBrick
9
9
  :bg_color: :Gray
10
10
  :border_color: :FireBrick
11
- Button:
11
+ Rubygoo::Button:
12
12
  :bg_color: :DimGray
13
- CheckBox:
13
+ Rubygoo::CheckBox:
14
14
  :checked_color: :FireBrick
15
- TextField:
15
+ Rubygoo::TextField:
16
16
  :fg_color: :FireBrick
17
17
  :bg_color: :Gray
18
18
  :bg_select_color: :FireBrick
19
19
  :fg_select_color: :Snow
20
20
  :border_color: :Black
21
+ Rubygoo::MouseCursor:
22
+ :color: :Snow
23
+ :mouse_cursor: cursor.png
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubygoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Anderson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-17 00:00:00 -07:00
12
+ date: 2008-10-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -84,6 +84,8 @@ files:
84
84
  - lib/rubygoo/goo_color.rb
85
85
  - lib/rubygoo/goo_event.rb
86
86
  - lib/rubygoo/label.rb
87
+ - lib/rubygoo/mouse_cursor.rb
88
+ - lib/rubygoo/rect.rb
87
89
  - lib/rubygoo/text_field.rb
88
90
  - lib/rubygoo/widget.rb
89
91
  - samples/gosu_app.rb