Class: BTetrisKp::MenuItem
- Inherits:
-
Object
- Object
- BTetrisKp::MenuItem
- Defined in:
- lib/btetris_kp/gui/menuitem.rb
Overview
class representing menu item
Instance Method Summary collapse
-
#clicked ⇒ Object
returns true menu item is clicked (click + mouse_over).
-
#draw ⇒ Object
draws menuitem on window (gosu).
-
#initialize(window, text, id, callback, font, x, y) ⇒ MenuItem
constructor
A new instance of MenuItem.
-
#mouse_over? ⇒ Boolean
returns true if mouse is over menu item.
-
#update ⇒ Object
updates menu item, changes item color depending on mouse_over?.
Constructor Details
#initialize(window, text, id, callback, font, x, y) ⇒ MenuItem
Returns a new instance of MenuItem.
6 7 8 9 10 11 12 13 14 |
# File 'lib/btetris_kp/gui/menuitem.rb', line 6 def initialize(window, text, id, callback, font, x, y) @window = window @text = text @callback = callback @font = font @color = Const::MENU_ITEM_CLR @x = x @y = y + id * (@font.height + Const::FONT_GAP) end |
Instance Method Details
#clicked ⇒ Object
returns true menu item is clicked (click + mouse_over)
35 36 37 |
# File 'lib/btetris_kp/gui/menuitem.rb', line 35 def clicked @callback.call if mouse_over? end |
#draw ⇒ Object
draws menuitem on window (gosu)
40 41 42 |
# File 'lib/btetris_kp/gui/menuitem.rb', line 40 def draw @font.draw(@text, @x, @y, 0, 1, 1, @color) end |
#mouse_over? ⇒ Boolean
returns true if mouse is over menu item
26 27 28 29 30 31 32 |
# File 'lib/btetris_kp/gui/menuitem.rb', line 26 def mouse_over? mx = @window.mouse_x my = @window.mouse_y (mx >= @x && my >= @y) && (mx <= @x + @font.text_width(@text)) && (my <= @y + @font.height) end |
#update ⇒ Object
updates menu item, changes item color depending on mouse_over?
17 18 19 20 21 22 23 |
# File 'lib/btetris_kp/gui/menuitem.rb', line 17 def update if mouse_over? @color = Const::MENU_ITEM_MO_CLR else @color = Const::MENU_ITEM_CLR end end |