class R2D::Adapters::Gosu::GosuWindow

Attributes

window[RW]

Public Class Methods

new(window) click to toggle source
Calls superclass method
# File lib/r2d/adapters/gosu.rb, line 88
def initialize(window)
  # super 800, 600, false
  super window.w, window.h, window.fs
  
  self.caption = window.title
  @cursor = window.cursor
  @window = window
end

Public Instance Methods

button_down(id) click to toggle source
# File lib/r2d/adapters/gosu.rb, line 101
def button_down(id)
  if id == ::Gosu::KbEscape
    close
  elsif @window.on_keys.has_key? id
    @window.on_keys[id].call
  end
end
draw() click to toggle source
# File lib/r2d/adapters/gosu.rb, line 119
def draw
  @window.objects.each do |o|
    case o
    when Line
      draw_quad(
        o.qx1, o.qy1, o.c1.adapter,
        o.qx2, o.qy2, o.c2.adapter,
        o.qx3, o.qy3, o.c3.adapter,
        o.qx4, o.qy4, o.c4.adapter
      )
    when Triangle
      draw_triangle(
        o.x1, o.y1, o.c1.adapter,
        o.x2, o.y2, o.c2.adapter,
        o.x3, o.y3, o.c3.adapter
      )
    when Quad
      draw_quad(
        o.x1, o.y1, o.c1.adapter,
        o.x2, o.y2, o.c2.adapter,
        o.x3, o.y3, o.c3.adapter,
        o.x4, o.y4, o.c4.adapter
      )
    when Image
      # .draw(x, y, z, factor_x=1, factor_y=1, color=0xffffffff, mode=:default)
      o.adapter.draw(o.x, o.y, 0, o.f_x, o.f_y)
    when Text
      # .draw(text, x, y, z, factor_x=1, factor_y=1, color=0xffffffff, mode=:default)
      o.adapter.draw(o.content, o.x, o.y, 0, 1, 1, o.c.adapter)
    else
      raise Error, "Cannot draw type '#{o.class}'"
    end
  end
end
needs_cursor?() click to toggle source

Gosu Methods

# File lib/r2d/adapters/gosu.rb, line 99
def needs_cursor?; @cursor end
update() click to toggle source
# File lib/r2d/adapters/gosu.rb, line 109
def update
  @window.update_proc.call
  
  @window.keys_down.each_key do |id|
    if button_down? id
      @window.keys_down[id].call
    end
  end
end