Sha256: d7958f64578be5b9aa1d28d3b3d87c96eceba6dcdb9ba8a3241d62906fe587cd
Contents?: true
Size: 1.82 KB
Versions: 1
Compression:
Stored size: 1.82 KB
Contents
class Example attr_accessor :caption attr_reader :width, :height attr_writer :parent_window def initialize(width, height, *options) @width, @height = width, height end def draw end def update end def button_down(id) end def button_up(id) end def close # no-op, examples cannot close the containing window. end def mouse_x @parent_window && @parent_window.mouse_x end def mouse_y @parent_window && @parent_window.mouse_y end def text_input @parent_window && @parent_window.text_input end def text_input=(text_input) @parent_window && @parent_window.text_input = text_input end def self.current_source_file @current_source_file end def self.current_source_file=(current_source_file) @current_source_file = current_source_file end def self.inherited(subclass) @@examples ||= {} @@examples[subclass] = self.current_source_file end def self.examples @@examples.keys end def self.source_file @@examples[self] end def self.initial_example @@examples.keys.find { |cls| cls.name.end_with? "::Welcome" } end 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 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gosu-examples-1.0.7 | lib/gosu-examples/example.rb |