Class: R2D::Window
- Inherits:
-
Object
- Object
- R2D::Window
- Defined in:
- lib/r2d/window.rb
Instance Attribute Summary collapse
-
#bg ⇒ Object
Returns the value of attribute bg.
-
#cursor ⇒ Object
Returns the value of attribute cursor.
-
#fs ⇒ Object
Returns the value of attribute fs.
-
#h ⇒ Object
Returns the value of attribute h.
-
#keys_down ⇒ Object
readonly
Returns the value of attribute keys_down.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#on_keys ⇒ Object
readonly
Returns the value of attribute on_keys.
-
#title ⇒ Object
Returns the value of attribute title.
-
#update_proc ⇒ Object
readonly
Returns the value of attribute update_proc.
-
#w ⇒ Object
Returns the value of attribute w.
Class Method Summary collapse
Instance Method Summary collapse
- #add(o) ⇒ Object
- #add_key_down(key, proc) ⇒ Object
- #add_on_key(key, proc) ⇒ Object
- #clear ⇒ Object
-
#initialize(options = {}) ⇒ Window
constructor
A new instance of Window.
- #key_down?(key) ⇒ Boolean
- #mouse_x ⇒ Object
- #mouse_y ⇒ Object
- #on_key(key, block) ⇒ Object
- #remove(o) ⇒ Object
- #show ⇒ Object
- #update(block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Window
Returns a new instance of Window.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/r2d/window.rb', line 9 def initialize( = {}) = .merge({w: 640, h: 480, title: "R2D", bg: nil, cursor: true, fs: false}) @w, @h, @title, @bg, @cursor, @fs, = [:w], [:h], [:title], [:bg], [:cursor], [:fs] @objects = [] @on_keys = {} @keys_down = {} @update_proc = Proc.new {} Adapters.create(self, :gosu) @@current = self end |
Instance Attribute Details
#bg ⇒ Object
Returns the value of attribute bg.
6 7 8 |
# File 'lib/r2d/window.rb', line 6 def bg @bg end |
#cursor ⇒ Object
Returns the value of attribute cursor.
6 7 8 |
# File 'lib/r2d/window.rb', line 6 def cursor @cursor end |
#fs ⇒ Object
Returns the value of attribute fs.
6 7 8 |
# File 'lib/r2d/window.rb', line 6 def fs @fs end |
#h ⇒ Object
Returns the value of attribute h.
6 7 8 |
# File 'lib/r2d/window.rb', line 6 def h @h end |
#keys_down ⇒ Object (readonly)
Returns the value of attribute keys_down.
7 8 9 |
# File 'lib/r2d/window.rb', line 7 def keys_down @keys_down end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
7 8 9 |
# File 'lib/r2d/window.rb', line 7 def objects @objects end |
#on_keys ⇒ Object (readonly)
Returns the value of attribute on_keys.
7 8 9 |
# File 'lib/r2d/window.rb', line 7 def on_keys @on_keys end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/r2d/window.rb', line 6 def title @title end |
#update_proc ⇒ Object (readonly)
Returns the value of attribute update_proc.
7 8 9 |
# File 'lib/r2d/window.rb', line 7 def update_proc @update_proc end |
#w ⇒ Object
Returns the value of attribute w.
6 7 8 |
# File 'lib/r2d/window.rb', line 6 def w @w end |
Class Method Details
.add(o) ⇒ Object
24 25 26 |
# File 'lib/r2d/window.rb', line 24 def self.add(o) @@current.add(o) end |
.remove(o) ⇒ Object
28 29 30 |
# File 'lib/r2d/window.rb', line 28 def self.remove(o) @@current.remove(o) end |
Instance Method Details
#add(o) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/r2d/window.rb', line 32 def add(o) if !@objects.include?(o) @objects.push(o) true else false end end |
#add_key_down(key, proc) ⇒ Object
64 65 66 67 |
# File 'lib/r2d/window.rb', line 64 def add_key_down(key, proc) @keys_down[Adapters.key_lookup(key)] = proc true end |
#add_on_key(key, proc) ⇒ Object
54 55 56 57 |
# File 'lib/r2d/window.rb', line 54 def add_on_key(key, proc) @on_keys[Adapters.key_lookup(key)] = proc true end |
#clear ⇒ Object
50 51 52 |
# File 'lib/r2d/window.rb', line 50 def clear @objects.clear end |
#key_down?(key) ⇒ Boolean
59 60 61 62 |
# File 'lib/r2d/window.rb', line 59 def key_down?(key) (Adapters.key_lookup(key)) true end |
#on_key(key, block) ⇒ Object
74 75 76 77 |
# File 'lib/r2d/window.rb', line 74 def on_key(key, block) add_on_key(key, block) true end |
#remove(o) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/r2d/window.rb', line 41 def remove(o) if i = @objects.index(o) @objects.slice!(i) true else false end end |
#update(block) ⇒ Object
69 70 71 72 |
# File 'lib/r2d/window.rb', line 69 def update(block) @update_proc = block true end |