Class: Rubygoo::Widget
- Inherits:
-
Object
- Object
- Rubygoo::Widget
- Extended by:
- Publisher
- Defined in:
- lib/rubygoo/widget.rb
Constant Summary collapse
- DEFAULT_PARAMS =
{ :x => 0, :y => 0, :w => 1, :h => 1, :x_pad => 2, :y_pad => 2, :relative => false, :enabled => true, :visible => true, }
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#container ⇒ Object
Returns the value of attribute container.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#focus_priority ⇒ Object
Returns the value of attribute focus_priority.
-
#focussed ⇒ Object
Returns the value of attribute focussed.
-
#h ⇒ Object
Returns the value of attribute h.
-
#mouse_over ⇒ Object
Returns the value of attribute mouse_over.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#relative ⇒ Object
Returns the value of attribute relative.
-
#visible ⇒ Object
Returns the value of attribute visible.
-
#w ⇒ Object
Returns the value of attribute w.
-
#x ⇒ Object
Returns the value of attribute x.
-
#x_pad ⇒ Object
Returns the value of attribute x_pad.
-
#y ⇒ Object
Returns the value of attribute y.
-
#y_pad ⇒ Object
Returns the value of attribute y_pad.
Instance Method Summary collapse
-
#_draw(screen) ⇒ Object
:nodoc:.
-
#_focus ⇒ Object
:nodoc:.
-
#_key_pressed(event) ⇒ Object
:nodoc:.
-
#_key_released(event) ⇒ Object
:nodoc:.
-
#_mouse_down(event) ⇒ Object
:nodoc:.
-
#_mouse_drag(event) ⇒ Object
:nodoc:.
-
#_mouse_dragging(event) ⇒ Object
:nodoc:.
-
#_mouse_motion(event) ⇒ Object
:nodoc:.
-
#_mouse_up(event) ⇒ Object
:nodoc:.
-
#_unfocus ⇒ Object
:nodoc:.
-
#_update(time) ⇒ Object
:nodoc:.
-
#added ⇒ Object
called when the widget is added to a container.
- #contains?(x, y) ⇒ Boolean
-
#disable ⇒ Object
called when the widget is disabled.
-
#draw(screen) ⇒ Object
draw ourself on the screen.
-
#enable ⇒ Object
called when the widget is enabled.
- #enabled? ⇒ Boolean
-
#focus ⇒ Object
called when the widget receives focus.
- #focussed? ⇒ Boolean
-
#get_color(color) ⇒ Object
converts theme property to a GooColor.
-
#hide ⇒ Object
called when the widget is hidden.
-
#initialize(opts = {}) ⇒ Widget
constructor
A new instance of Widget.
-
#key_pressed(event) ⇒ Object
called when a key press is sent to us.
-
#key_released(event) ⇒ Object
called when a key release is sent to us.
- #modal? ⇒ Boolean
-
#mouse_down(event) ⇒ Object
called when there is a mouse click.
-
#mouse_drag(event) ⇒ Object
called when there is a mouse release at the end of a drag.
-
#mouse_dragging(event) ⇒ Object
called when there is a mouse motion and a button pressed.
-
#mouse_enter(event) ⇒ Object
called when the mouse first enters a widget.
-
#mouse_exit(event) ⇒ Object
called when the mouse exits a widget.
-
#mouse_motion(event) ⇒ Object
called when there is a mouse motion and no button pressed.
- #mouse_over? ⇒ Boolean
-
#mouse_up(event) ⇒ Object
called when there is a mouse release w/o drag.
-
#removed ⇒ Object
called when the widget is removed from a container.
-
#show ⇒ Object
called when the widget is shown.
-
#tab_to? ⇒ Boolean
does this widget want tabbed focus? Widget do usually.
-
#theme_property(prop_key) ⇒ Object
gets the property for the class asking for it.
-
#unfocus ⇒ Object
called when the widget loses focus.
-
#update(time) ⇒ Object
called each update cycle with the amount of time that has passed.
- #update_rect ⇒ Object
- #visible? ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ Widget
Returns a new instance of Widget.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubygoo/widget.rb', line 28 def initialize(opts={}) merged_opts = DEFAULT_PARAMS.merge opts @x = merged_opts[:x] @y = merged_opts[:y] @x_pad = merged_opts[:x_pad] @y_pad = merged_opts[:y_pad] @w = merged_opts[:w] @h = merged_opts[:h] @relative = merged_opts[:relative] @enabled = merged_opts[:enabled] @visible = merged_opts[:visible] @opts = merged_opts update_rect end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def app @app end |
#container ⇒ Object
Returns the value of attribute container.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def container @container end |
#enabled ⇒ Object
Returns the value of attribute enabled.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def enabled @enabled end |
#focus_priority ⇒ Object
Returns the value of attribute focus_priority.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def focus_priority @focus_priority end |
#focussed ⇒ Object
Returns the value of attribute focussed.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def focussed @focussed end |
#h ⇒ Object
Returns the value of attribute h.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def h @h end |
#mouse_over ⇒ Object
Returns the value of attribute mouse_over.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def mouse_over @mouse_over end |
#opts ⇒ Object
Returns the value of attribute opts.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def opts @opts end |
#parent ⇒ Object
Returns the value of attribute parent.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def parent @parent end |
#relative ⇒ Object
Returns the value of attribute relative.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def relative @relative end |
#visible ⇒ Object
Returns the value of attribute visible.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def visible @visible end |
#w ⇒ Object
Returns the value of attribute w.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def w @w end |
#x ⇒ Object
Returns the value of attribute x.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def x @x end |
#x_pad ⇒ Object
Returns the value of attribute x_pad.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def x_pad @x_pad end |
#y ⇒ Object
Returns the value of attribute y.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def y @y end |
#y_pad ⇒ Object
Returns the value of attribute y_pad.
13 14 15 |
# File 'lib/rubygoo/widget.rb', line 13 def y_pad @y_pad end |
Instance Method Details
#_draw(screen) ⇒ Object
:nodoc:
256 257 258 |
# File 'lib/rubygoo/widget.rb', line 256 def _draw(screen) #:nodoc: draw screen end |
#_focus ⇒ Object
:nodoc:
214 215 216 217 218 |
# File 'lib/rubygoo/widget.rb', line 214 def _focus() #:nodoc: fire :focus @focussed = true focus end |
#_key_pressed(event) ⇒ Object
:nodoc:
246 247 248 249 |
# File 'lib/rubygoo/widget.rb', line 246 def _key_pressed(event) #:nodoc: fire :key_pressed, event key_pressed event end |
#_key_released(event) ⇒ Object
:nodoc:
251 252 253 254 |
# File 'lib/rubygoo/widget.rb', line 251 def _key_released(event) #:nodoc: fire :key_released, event key_released event end |
#_mouse_down(event) ⇒ Object
:nodoc:
241 242 243 244 |
# File 'lib/rubygoo/widget.rb', line 241 def _mouse_down(event) #:nodoc: fire :mouse_down, event mouse_down event end |
#_mouse_drag(event) ⇒ Object
:nodoc:
231 232 233 234 |
# File 'lib/rubygoo/widget.rb', line 231 def _mouse_drag(event) #:nodoc: fire :mouse_drag, event mouse_drag event end |
#_mouse_dragging(event) ⇒ Object
:nodoc:
226 227 228 229 |
# File 'lib/rubygoo/widget.rb', line 226 def _mouse_dragging(event) #:nodoc: fire :mouse_dragging, event mouse_dragging event end |
#_mouse_motion(event) ⇒ Object
:nodoc:
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rubygoo/widget.rb', line 57 def _mouse_motion(event) #:nodoc: if contains?(event.data[:x],event.data[:y]) unless @mouse_over @mouse_over = true fire :mouse_enter, event mouse_enter event end else if @mouse_over @mouse_over = false fire :mouse_exit, event mouse_exit event end end fire :mouse_motion, event mouse_motion event end |
#_mouse_up(event) ⇒ Object
:nodoc:
236 237 238 239 |
# File 'lib/rubygoo/widget.rb', line 236 def _mouse_up(event) #:nodoc: fire :mouse_up, event mouse_up event end |
#_unfocus ⇒ Object
:nodoc:
220 221 222 223 224 |
# File 'lib/rubygoo/widget.rb', line 220 def _unfocus() #:nodoc: fire :unfocus @focussed = false unfocus end |
#_update(time) ⇒ Object
:nodoc:
210 211 212 |
# File 'lib/rubygoo/widget.rb', line 210 def _update(time) #:nodoc: update time end |
#added ⇒ Object
called when the widget is added to a container
274 275 |
# File 'lib/rubygoo/widget.rb', line 274 def added() end |
#contains?(x, y) ⇒ Boolean
49 50 51 |
# File 'lib/rubygoo/widget.rb', line 49 def contains?(x, y) @rect.collide_point? x, y end |
#disable ⇒ Object
called when the widget is disabled
173 174 175 176 177 178 |
# File 'lib/rubygoo/widget.rb', line 173 def disable() if enabled? fire :disable @enabled = false end end |
#draw(screen) ⇒ Object
draw ourself on the screen
323 324 |
# File 'lib/rubygoo/widget.rb', line 323 def draw(screen) end |
#enable ⇒ Object
called when the widget is enabled
181 182 183 184 185 186 |
# File 'lib/rubygoo/widget.rb', line 181 def enable() unless enabled? fire :enable @enabled = true end end |
#enabled? ⇒ Boolean
168 169 170 |
# File 'lib/rubygoo/widget.rb', line 168 def enabled?() @enabled end |
#focus ⇒ Object
called when the widget receives focus
327 328 |
# File 'lib/rubygoo/widget.rb', line 327 def focus() end |
#focussed? ⇒ Boolean
75 76 77 |
# File 'lib/rubygoo/widget.rb', line 75 def focussed?() @focussed end |
#get_color(color) ⇒ Object
converts theme property to a GooColor
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/rubygoo/widget.rb', line 104 def get_color(color) new_color = nil if color.is_a? Array if color.size > 3 new_color = color else # fill in zeros for all other colors (3 - color.size).times do color << 0 end # fill in alpha as 255 color << 255 end elsif color.is_a? Symbol new_color = COLORS[color] else raise "invalid color" end GooColor.new *new_color end |
#hide ⇒ Object
called when the widget is hidden
193 194 195 196 197 198 199 |
# File 'lib/rubygoo/widget.rb', line 193 def hide() if visible? fire :hide @visible = false disable end end |
#key_pressed(event) ⇒ Object
called when a key press is sent to us
315 316 |
# File 'lib/rubygoo/widget.rb', line 315 def key_pressed(event) end |
#key_released(event) ⇒ Object
called when a key release is sent to us
319 320 |
# File 'lib/rubygoo/widget.rb', line 319 def key_released(event) end |
#modal? ⇒ Boolean
269 270 271 |
# File 'lib/rubygoo/widget.rb', line 269 def modal?() false end |
#mouse_down(event) ⇒ Object
called when there is a mouse click
295 296 |
# File 'lib/rubygoo/widget.rb', line 295 def mouse_down(event) end |
#mouse_drag(event) ⇒ Object
called when there is a mouse release at the end of a drag
299 300 |
# File 'lib/rubygoo/widget.rb', line 299 def mouse_drag(event) end |
#mouse_dragging(event) ⇒ Object
called when there is a mouse motion and a button pressed
287 288 |
# File 'lib/rubygoo/widget.rb', line 287 def mouse_dragging(event) end |
#mouse_enter(event) ⇒ Object
called when the mouse first enters a widget
303 304 |
# File 'lib/rubygoo/widget.rb', line 303 def mouse_enter(event) end |
#mouse_exit(event) ⇒ Object
called when the mouse exits a widget
307 308 |
# File 'lib/rubygoo/widget.rb', line 307 def mouse_exit(event) end |
#mouse_motion(event) ⇒ Object
called when there is a mouse motion and no button pressed
311 312 |
# File 'lib/rubygoo/widget.rb', line 311 def mouse_motion(event) end |
#mouse_over? ⇒ Boolean
53 54 55 |
# File 'lib/rubygoo/widget.rb', line 53 def mouse_over?() @mouse_over end |
#mouse_up(event) ⇒ Object
called when there is a mouse release w/o drag
291 292 |
# File 'lib/rubygoo/widget.rb', line 291 def mouse_up(event) end |
#removed ⇒ Object
called when the widget is removed from a container
278 279 |
# File 'lib/rubygoo/widget.rb', line 278 def removed() end |
#show ⇒ Object
called when the widget is shown
202 203 204 205 206 207 208 |
# File 'lib/rubygoo/widget.rb', line 202 def show() unless visible? fire :show @visible = true enable end end |
#tab_to? ⇒ Boolean
does this widget want tabbed focus? Widget do usually
265 266 267 |
# File 'lib/rubygoo/widget.rb', line 265 def tab_to?() true end |
#theme_property(prop_key) ⇒ Object
gets the property for the class asking for it. it will walk up the object hierarchy if needed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rubygoo/widget.rb', line 81 def theme_property(prop_key) prop = nil parent = self.class until parent == Object class_theme = app.theme[parent.to_s] if class_theme class_prop = class_theme[prop_key] if class_prop return nil if class_prop == :none prop = class_prop break end end parent = parent.superclass end if prop_key.to_s.match(/color/i) and prop get_color prop else prop end end |
#unfocus ⇒ Object
called when the widget loses focus
331 332 |
# File 'lib/rubygoo/widget.rb', line 331 def unfocus() end |
#update(time) ⇒ Object
called each update cycle with the amount of time that has passed. useful for animations, etc
283 284 |
# File 'lib/rubygoo/widget.rb', line 283 def update(time) end |
#update_rect ⇒ Object
45 46 47 |
# File 'lib/rubygoo/widget.rb', line 45 def update_rect() @rect = Rect.new [@x,@y,@w,@h] end |
#visible? ⇒ Boolean
188 189 190 |
# File 'lib/rubygoo/widget.rb', line 188 def visible?() @visible end |