Class: R2D::Adapters::Gosu::GosuWindow

Inherits:
Gosu::Window
  • Object
show all
Defined in:
lib/r2d/adapters/gosu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ GosuWindow

Returns a new instance of GosuWindow.



88
89
90
91
92
93
94
95
# 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

Instance Attribute Details

#windowObject

Returns the value of attribute window.



86
87
88
# File 'lib/r2d/adapters/gosu.rb', line 86

def window
  @window
end

Instance Method Details

#button_down(id) ⇒ Object



101
102
103
104
105
106
107
# 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

#drawObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# 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?Boolean

Gosu Methods

Returns:

  • (Boolean)


99
# File 'lib/r2d/adapters/gosu.rb', line 99

def needs_cursor?; @cursor end

#updateObject



109
110
111
112
113
114
115
116
117
# 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