Class: Rubygoo::Button
Constant Summary
Constants inherited from Widget
Instance Attribute Summary
Attributes inherited from Widget
#app, #container, #enabled, #focus_priority, #focussed, #h, #mouse_over, #opts, #parent, #relative, #visible, #w, #x, #x_pad, #y, #y_pad
Instance Method Summary collapse
- #added ⇒ Object
- #draw(adapter) ⇒ Object
-
#initialize(text, opts = {}) ⇒ Button
constructor
A new instance of Button.
-
#key_pressed(event) ⇒ Object
called when a key press is sent to us.
-
#mouse_drag(event) ⇒ Object
called when there is a mouse click at the end of a drag.
-
#mouse_up(event) ⇒ Object
called when there is a mouse click.
Methods inherited from Widget
#_draw, #_focus, #_key_pressed, #_key_released, #_mouse_down, #_mouse_drag, #_mouse_dragging, #_mouse_motion, #_mouse_up, #_unfocus, #_update, #contains?, #disable, #enable, #enabled?, #focus, #focussed?, #get_color, #hide, #key_released, #modal?, #mouse_down, #mouse_dragging, #mouse_enter, #mouse_exit, #mouse_motion, #mouse_over?, #removed, #show, #tab_to?, #theme_property, #unfocus, #update, #update_rect, #visible?
Constructor Details
#initialize(text, opts = {}) ⇒ Button
Returns a new instance of Button.
4 5 6 7 8 9 10 |
# File 'lib/rubygoo/button.rb', line 4 def initialize(text, opts={}) super opts @icon = opts[:icon] @text = text end |
Instance Method Details
#added ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubygoo/button.rb', line 12 def added() font = theme_property :font @font_size = @opts[:font_size] @font_size ||= theme_property :font_size @color = theme_property :color @bg_color = theme_property :bg_color @border_color = theme_property :border_color @focus_color = theme_property :focus_color @hover_color = theme_property :hover_color @disabled_color = theme_property :disabled_color @font_file = File.join(@app.theme_dir,font) @rendered_text ||= @app.renderer.render_text @text, @font_file, @font_size, @color @w = @rendered_text.width+2*@x_pad @h = @rendered_text.height+2*@y_pad @x = @x - @x_pad @y = @y - @y_pad update_rect end |
#draw(adapter) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rubygoo/button.rb', line 52 def draw(adapter) x1 = @rect[0] y1 = @rect[1] x2 = @rect[2] + x1 y2 = @rect[3] + y1 if @focussed adapter.fill x1, y1, x2, y2, @focus_color elsif @bg_color adapter.fill x1, y1, x2, y2, @bg_color end if @border_color adapter.draw_box x1, y1, x2, y2, @border_color end if mouse_over? and @hover_color adapter.fill x1, y1, x2, y2, @hover_color end if @disabled_color and !enabled? adapter.fill x1, y1, x2, y2, @disabled_color end if @icon # TODO center icon ix = x1#+((x2-x1)[email protected]) iy = y1#+((y2-y1)[email protected]) adapter.draw_image @icon, ix+@x_pad,iy+@y_pad end adapter.draw_image @rendered_text, @x+@x_pad, @y+@y_pad, @color end |
#key_pressed(event) ⇒ Object
called when a key press is sent to us
45 46 47 48 49 50 |
# File 'lib/rubygoo/button.rb', line 45 def key_pressed(event) case event.data[:key] when K_SPACE fire :pressed, event end end |
#mouse_drag(event) ⇒ Object
called when there is a mouse click at the end of a drag
40 41 42 |
# File 'lib/rubygoo/button.rb', line 40 def mouse_drag(event) fire :pressed, event end |
#mouse_up(event) ⇒ Object
called when there is a mouse click
35 36 37 |
# File 'lib/rubygoo/button.rb', line 35 def mouse_up(event) fire :pressed, event end |