Class: Pc::Window
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- Pc::Window
- Includes:
- Singleton
- Defined in:
- lib/pc/interfaces/desktop/window.rb
Instance Method Summary collapse
-
#button_down(id) ⇒ Object
This method is called whenever a key is pressed down.
-
#button_up(id) ⇒ Object
This method is called whenever a key is pressed up.
-
#draw ⇒ Object
This method is called after every update and whenever the OS wants the window to repaint itself.
- #draw_buttons(buttons) ⇒ Object
- #draw_rectangle(button) ⇒ Object
- #draw_text(text) ⇒ Object
-
#initialize ⇒ Window
constructor
A new instance of Window.
- #set_alert(message) ⇒ Object
- #set_buttons(choices = {}) ⇒ Object
-
#update ⇒ Object
This method is called once every #update_interval milliseconds while the window is being shown.
Constructor Details
#initialize ⇒ Window
Returns a new instance of Window.
8 9 10 11 12 |
# File 'lib/pc/interfaces/desktop/window.rb', line 8 def initialize super 640, 480, is_fullscreen self. = 'Game Hall' @font = Gosu::Font.new self, Gosu::default_font_name, 20 end |
Instance Method Details
#button_down(id) ⇒ Object
This method is called whenever a key is pressed down
60 61 62 63 64 |
# File 'lib/pc/interfaces/desktop/window.rb', line 60 def (id) case id when Gosu::KbEscape then close end end |
#button_up(id) ⇒ Object
This method is called whenever a key is pressed up
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/pc/interfaces/desktop/window.rb', line 67 def (id) case id when Gosu::MsLeft @buttons.each do |, index| if [:y1] < mouse_y && mouse_y < [:y2] && [:x1] < mouse_x && mouse_x < [:x2] @buttons = nil [:action].call break end end if @buttons end end |
#draw ⇒ Object
This method is called after every update and whenever the OS wants the window to repaint itself.
54 55 56 57 |
# File 'lib/pc/interfaces/desktop/window.rb', line 54 def draw draw_text @alert if @alert @buttons if @buttons end |
#draw_buttons(buttons) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/pc/interfaces/desktop/window.rb', line 46 def () .reject{|| [:label] == :next}.each do || draw_rectangle @font.draw [:label], [:x1], [:y1], 2 end end |
#draw_rectangle(button) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/pc/interfaces/desktop/window.rb', line 39 def draw_rectangle() c1, c2 = [Gosu::Color.new(0xFF1EB1FA), Gosu::Color.new(0xFF1D4DB5)] x1, x2, y1, y2 = [[:x1], [:x2], [:y1], [:y2]] z_index = 0 draw_quad x1, y1, c1, x2, y1, c1, x1, y2, c2, x2, y2, c2, z_index end |
#draw_text(text) ⇒ Object
35 36 37 |
# File 'lib/pc/interfaces/desktop/window.rb', line 35 def draw_text(text) @font.draw @alert, 200, 450, 2 # TO DO: center the text end |
#set_alert(message) ⇒ Object
14 15 16 |
# File 'lib/pc/interfaces/desktop/window.rb', line 14 def set_alert() @alert = end |
#set_buttons(choices = {}) ⇒ Object
18 19 20 21 22 |
# File 'lib/pc/interfaces/desktop/window.rb', line 18 def (choices = {}) @buttons = choices.map.with_index do |(key, value), index| {timeout: Time.now + 1.2, label: key, action: value, x1: 100, x2: 200, y1: 30+index*30, y2: 50+index*30} end end |
#update ⇒ Object
This method is called once every #update_interval milliseconds while the window is being shown.
25 26 27 28 29 30 31 32 33 |
# File 'lib/pc/interfaces/desktop/window.rb', line 25 def update @buttons.each do |, index| if [:timeout] < Time.now && [:label] == :next @buttons = nil [:action].call break end end if @buttons end |