Class: Example
- Inherits:
-
Object
- Object
- Example
- Defined in:
- lib/gosu-examples/example.rb
Instance Attribute Summary collapse
-
#caption ⇒ Object
Returns the value of attribute caption.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#parent_window ⇒ Object
writeonly
Sets the attribute parent_window.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
- .current_source_file ⇒ Object
- .current_source_file=(current_source_file) ⇒ Object
- .examples ⇒ Object
- .inherited(subclass) ⇒ Object
- .initial_example ⇒ Object
- .load_examples(pattern) ⇒ Object
- .source_file ⇒ Object
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #button_up(id) ⇒ Object
- #close ⇒ Object
- #draw ⇒ Object
-
#initialize(width, height, *options) ⇒ Example
constructor
A new instance of Example.
- #mouse_x ⇒ Object
- #mouse_y ⇒ Object
- #text_input ⇒ Object
- #text_input=(text_input) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(width, height, *options) ⇒ Example
Returns a new instance of Example.
6 7 8 |
# File 'lib/gosu-examples/example.rb', line 6 def initialize(width, height, *) @width, @height = width, height end |
Instance Attribute Details
#caption ⇒ Object
Returns the value of attribute caption.
2 3 4 |
# File 'lib/gosu-examples/example.rb', line 2 def caption @caption end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
3 4 5 |
# File 'lib/gosu-examples/example.rb', line 3 def height @height end |
#parent_window=(value) ⇒ Object (writeonly)
Sets the attribute parent_window
4 5 6 |
# File 'lib/gosu-examples/example.rb', line 4 def parent_window=(value) @parent_window = value end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
3 4 5 |
# File 'lib/gosu-examples/example.rb', line 3 def width @width end |
Class Method Details
.current_source_file ⇒ Object
42 43 44 |
# File 'lib/gosu-examples/example.rb', line 42 def self.current_source_file @current_source_file end |
.current_source_file=(current_source_file) ⇒ Object
46 47 48 |
# File 'lib/gosu-examples/example.rb', line 46 def self.current_source_file=(current_source_file) @current_source_file = current_source_file end |
.examples ⇒ Object
55 56 57 |
# File 'lib/gosu-examples/example.rb', line 55 def self.examples @@examples.keys end |
.inherited(subclass) ⇒ Object
50 51 52 53 |
# File 'lib/gosu-examples/example.rb', line 50 def self.inherited(subclass) @@examples ||= {} @@examples[subclass] = self.current_source_file end |
.initial_example ⇒ Object
63 64 65 |
# File 'lib/gosu-examples/example.rb', line 63 def self.initial_example @@examples.keys.find { |cls| cls.name.end_with? "::Welcome" } end |
.load_examples(pattern) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gosu-examples/example.rb', line 67 def self.load_examples(pattern) Dir.glob(pattern) do |file| begin # Remember which file we are loading. Example.current_source_file = File.(file) # Load the example in a sandbox module (second parameter to load()). This way, examples can # define classes and constants with the same names, and they will not collide. # # load() does not let us refer to the anonymous module it creates, but we can enumerate all # loaded examples using Example.examples thanks to the "inherited" callback above. load file, true rescue Exception => e puts "*** Cannot load #{file}:" puts e puts end end end |
.source_file ⇒ Object
59 60 61 |
# File 'lib/gosu-examples/example.rb', line 59 def self.source_file @@examples[self] end |
Instance Method Details
#button_down(id) ⇒ Object
16 17 |
# File 'lib/gosu-examples/example.rb', line 16 def (id) end |
#button_up(id) ⇒ Object
19 20 |
# File 'lib/gosu-examples/example.rb', line 19 def (id) end |
#close ⇒ Object
22 23 24 |
# File 'lib/gosu-examples/example.rb', line 22 def close # no-op, examples cannot close the containing window. end |
#draw ⇒ Object
10 11 |
# File 'lib/gosu-examples/example.rb', line 10 def draw end |
#mouse_x ⇒ Object
26 27 28 |
# File 'lib/gosu-examples/example.rb', line 26 def mouse_x @parent_window && @parent_window.mouse_x end |
#mouse_y ⇒ Object
30 31 32 |
# File 'lib/gosu-examples/example.rb', line 30 def mouse_y @parent_window && @parent_window.mouse_y end |
#text_input ⇒ Object
34 35 36 |
# File 'lib/gosu-examples/example.rb', line 34 def text_input @parent_window && @parent_window.text_input end |
#text_input=(text_input) ⇒ Object
38 39 40 |
# File 'lib/gosu-examples/example.rb', line 38 def text_input=(text_input) @parent_window && @parent_window.text_input = text_input end |
#update ⇒ Object
13 14 |
# File 'lib/gosu-examples/example.rb', line 13 def update end |