Class: Wads::WadsApp

Inherits:
Gosu::Window
  • Object
show all
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

Constructor Details

#initialize(width, height, caption, widget) ⇒ WadsApp

Returns a new instance of WadsApp.



12
13
14
15
16
17
18
19
# File 'lib/wads/app.rb', line 12

def initialize(width, height, caption, widget)
    super(width, height)
    self.caption = caption
    @update_count = 0
    WadsConfig.instance.set_window(self)
    set_display(widget) 
    WadsConfig.instance.set_log_level("info")
end

Instance Method Details

#button_down(id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/wads/app.rb', line 42

def button_down id
    close if id == Gosu::KbEscape
    # Delegate button events to the primary display widget
    result = @main_widget.button_down id, mouse_x, mouse_y
    if not result.nil? and result.is_a? WidgetResult
        if result.close_widget
            close
        end
    end
end

#button_up(id) ⇒ Object



53
54
55
# File 'lib/wads/app.rb', line 53

def button_up id
    @main_widget.button_up id, mouse_x, mouse_y
end

#drawObject



38
39
40
# File 'lib/wads/app.rb', line 38

def draw
    @main_widget.draw
end

#get_displayObject



29
30
31
# File 'lib/wads/app.rb', line 29

def get_display
    @main_widget
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.



25
26
27
# File 'lib/wads/app.rb', line 25

def set_display(widget) 
    @main_widget = widget 
end

#updateObject



33
34
35
36
# File 'lib/wads/app.rb', line 33

def update
    @main_widget.update(@update_count, mouse_x, mouse_y)
    @update_count = @update_count + 1
end