class Pc::Window

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/pc/interfaces/desktop/window.rb, line 8
def initialize
  super 640, 480, is_fullscreen
  self.caption = 'Game Hall'
  @font = Gosu::Font.new self, Gosu::default_font_name, 20
end

Public Instance Methods

button_down(id) click to toggle source

This method is called whenever a key is pressed down

# File lib/pc/interfaces/desktop/window.rb, line 60
def button_down(id)
  case id
    when Gosu::KbEscape then close
  end
end
button_up(id) click to toggle source

This method is called whenever a key is pressed up

# File lib/pc/interfaces/desktop/window.rb, line 67
def button_up(id)
  case id
  when Gosu::MsLeft
    @buttons.each do |button, index|
      if button[:y1] < mouse_y && mouse_y < button[:y2] && button[:x1] < mouse_x && mouse_x < button[:x2]
        @buttons = nil
        button[:action].call
        break
      end
    end if @buttons
  end
end
draw() click to toggle source

This method is called after every update and whenever the OS wants the window to repaint itself.

# File lib/pc/interfaces/desktop/window.rb, line 54
def draw
  draw_text @alert if @alert
  draw_buttons @buttons if @buttons
end
draw_buttons(buttons) click to toggle source
# File lib/pc/interfaces/desktop/window.rb, line 46
def draw_buttons(buttons)
  buttons.reject{|button| button[:label] == :next}.each do |button|
    draw_rectangle button
    @font.draw button[:label], button[:x1], button[:y1], 2
  end
end
draw_rectangle(button) click to toggle source
# File lib/pc/interfaces/desktop/window.rb, line 39
def draw_rectangle(button)
  c1, c2 = [Gosu::Color.new(0xFF1EB1FA), Gosu::Color.new(0xFF1D4DB5)]
  x1, x2, y1, y2 = [button[:x1], button[:x2], button[:y1], button[:y2]]
  z_index = 0
  draw_quad x1, y1, c1, x2, y1, c1, x1, y2, c2, x2, y2, c2, z_index
end
draw_text(text) click to toggle source
# 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) click to toggle source
# File lib/pc/interfaces/desktop/window.rb, line 14
def set_alert(message)
  @alert = message
end
set_buttons(choices = {}) click to toggle source
# File lib/pc/interfaces/desktop/window.rb, line 18
def set_buttons(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() click to toggle source

This method is called once every update_interval milliseconds while the window is being shown.

# File lib/pc/interfaces/desktop/window.rb, line 25
def update
  @buttons.each do |button, index|
    if button[:timeout] < Time.now && button[:label] == :next
      @buttons = nil
      button[:action].call
      break
    end
  end if @buttons
end

Private Instance Methods

is_fullscreen() click to toggle source
# File lib/pc/interfaces/desktop/window.rb, line 82
def is_fullscreen
  false
end
needs_cursor?() click to toggle source
from Gosu::Window

Whether the system cursor should be shown

# File lib/pc/interfaces/desktop/window.rb, line 87
def needs_cursor?
  true
end