Class: Wads::WadsApp
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- Wads::WadsApp
- Defined in:
- lib/wads/app.rb
Overview
The WadsApp class provides a simple starting point to quickly build a native Ruby application using Gosu as an underlying library. It provides all the necessary hooks to get started. All you need to do is supply the parent Wads widget using the set_display(widget) method. See one of the Wads samples for example usage.
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #button_up(id) ⇒ Object
- #draw ⇒ Object
- #get_display ⇒ Object
-
#initialize(width, height, caption, widget) ⇒ WadsApp
constructor
A new instance of WadsApp.
-
#register_hold_down_key(id) ⇒ Object
Register a key (identified by the Gosu id) to check if it is being held down.
-
#set_display(widget) ⇒ Object
This method must be invoked with any Wads::Widget instance.
- #update ⇒ Object
Constructor Details
#initialize(width, height, caption, widget) ⇒ WadsApp
Returns a new instance of WadsApp.
12 13 14 15 16 17 18 19 20 |
# File 'lib/wads/app.rb', line 12 def initialize(width, height, caption, ) super(width, height) self.caption = caption @update_count = 0 WadsConfig.instance.set_window(self) set_display() WadsConfig.instance.set_log_level("info") @registered_hold_down_buttons = [] end |
Instance Method Details
#button_down(id) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/wads/app.rb', line 58 def id close if id == Gosu::KbEscape # Delegate button events to the primary display widget result = @main_widget. id, mouse_x, mouse_y if not result.nil? and result.is_a? WidgetResult if result. close end end end |
#button_up(id) ⇒ Object
69 70 71 |
# File 'lib/wads/app.rb', line 69 def id @main_widget. id, mouse_x, mouse_y end |
#draw ⇒ Object
54 55 56 |
# File 'lib/wads/app.rb', line 54 def draw @main_widget.draw end |
#get_display ⇒ Object
30 31 32 |
# File 'lib/wads/app.rb', line 30 def get_display @main_widget end |
#register_hold_down_key(id) ⇒ Object
Register a key (identified by the Gosu id) to check if it is being held down. If so, the handle_key_held_down callback will be invoked on widgets For example, register_hold_down_key(Gosu::KbLeft)
37 38 39 |
# File 'lib/wads/app.rb', line 37 def register_hold_down_key(id) @registered_hold_down_buttons << id end |
#set_display(widget) ⇒ Object
This method must be invoked with any Wads::Widget instance. It then handles delegating all events and drawing all child widgets.
26 27 28 |
# File 'lib/wads/app.rb', line 26 def set_display() @main_widget = end |
#update ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wads/app.rb', line 41 def update @main_widget.update(@update_count, mouse_x, mouse_y) # Look for keys that are held down and delegate those events @registered_hold_down_buttons.each do |id| if (id) @main_widget.handle_key_held_down id, mouse_x, mouse_y end end @update_count = @update_count + 1 end |