Class: Example

Inherits:
Object
  • Object
show all
Defined in:
lib/gosu-examples/example.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, *options)
  @width, @height = width, height
end

Instance Attribute Details

#captionObject

Returns the value of attribute caption.



2
3
4
# File 'lib/gosu-examples/example.rb', line 2

def caption
  @caption
end

#heightObject (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

Parameters:

  • value

    the value to set the attribute parent_window to.



4
5
6
# File 'lib/gosu-examples/example.rb', line 4

def parent_window=(value)
  @parent_window = value
end

#widthObject (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_fileObject



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

.examplesObject



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_exampleObject



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.expand_path(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_fileObject



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 button_down(id)
end

#button_up(id) ⇒ Object



19
20
# File 'lib/gosu-examples/example.rb', line 19

def button_up(id)
end

#closeObject



22
23
24
# File 'lib/gosu-examples/example.rb', line 22

def close
  # no-op, examples cannot close the containing window.
end

#drawObject



10
11
# File 'lib/gosu-examples/example.rb', line 10

def draw
end

#mouse_xObject



26
27
28
# File 'lib/gosu-examples/example.rb', line 26

def mouse_x
  @parent_window && @parent_window.mouse_x
end

#mouse_yObject



30
31
32
# File 'lib/gosu-examples/example.rb', line 30

def mouse_y
  @parent_window && @parent_window.mouse_y
end

#text_inputObject



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

#updateObject



13
14
# File 'lib/gosu-examples/example.rb', line 13

def update
end