class RuGUI::BaseMainController
A base class for main controllers.
Provides a method for running the application as well as a method to quit.
Attributes
screen[RW]
Public Class Methods
framerate(frames_per_second=nil)
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 111 def framerate(frames_per_second=nil) @framerate ||= frames_per_second || 30 end
ignored_events(*args)
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 105 def ignored_events(*args) @ignored_events ||= [] @ignored_events += args unless args.empty? @ignored_events end
new()
click to toggle source
Calls superclass method
RuGUI::BaseController::new
# File lib/rugui/framework_adapters/Rubygame.rb, line 73 def initialize super setup_clock setup_event_queue setup_screen setup_quit_events setup_autoload_resources setup_main_view_screen end
quit_hooks(quit_hooks=nil)
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 135 def quit_hooks(quit_hooks=nil) @quit_hooks ||= quit_hooks || [:escape, :q, Rubygame::Events::QuitRequested] end
screen_depth(depth=nil)
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 123 def screen_depth(depth=nil) @screen_depth ||= depth || 0 end
screen_flags(flags=nil)
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 127 def screen_flags(flags=nil) @screen_flags ||= flags || [Rubygame::HWSURFACE, Rubygame::DOUBLEBUF] end
screen_height(height=nil)
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 119 def screen_height(height=nil) @screen_height ||= height || 480 end
screen_title(title=nil)
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 131 def screen_title(title=nil) @screen_title ||= title || "RuGUI Game!" end
screen_width(width=nil)
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 115 def screen_width(width=nil) @screen_width ||= width || 640 end
Public Instance Methods
clock()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 96 def clock @clock ||= Rubygame::Clock.new end
event_queue()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 100 def event_queue @event_queue ||= Rubygame::EventQueue.new end
framework_adapter()
click to toggle source
Returns the framework_adapter
for this class.
# File lib/rugui/base_controller.rb, line 222 def framework_adapter framework_adapter_for('BaseMainController') end
quit()
click to toggle source
Exits from the application.
# File lib/rugui/base_controller.rb, line 247 def quit logger.info "Exiting the application through #{self.class.name}." self.framework_adapter.quit logger.info "Application finished." end
refresh()
click to toggle source
Refreshes the GUI application, running just one event loop.
This method is mostly useful when writing tests. It shouldn’t be used in normal applications.
# File lib/rugui/base_controller.rb, line 240 def refresh self.framework_adapter.refresh end
run()
click to toggle source
Runs the application.
# File lib/rugui/base_controller.rb, line 229 def run logger.info "Starting the application through #{self.class.name}." self.framework_adapter.run end
step()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 84 def step clear_screen tick handle_events update screen.update end
tick()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 92 def tick event_queue << clock.tick end
Protected Instance Methods
clear_screen()
click to toggle source
Your MainController
can overwrite this and implement different clear screen logic.
# File lib/rugui/framework_adapters/Rubygame.rb, line 142 def clear_screen screen.fill :black end
update()
click to toggle source
Your MainController
should overwrite this and implement update logic.
# File lib/rugui/framework_adapters/Rubygame.rb, line 147 def update end
Private Instance Methods
handle_events()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 186 def handle_events event_queue.each do |event| handle event end end
images_dir()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 192 def images_dir RuGUI.root.join('app', 'resources', 'images') end
music_dir()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 200 def music_dir RuGUI.root.join('app', 'resources', 'music') end
setup_autoload_resources()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 180 def setup_autoload_resources Rubygame::Surface.autoload_dirs << images_dir if File.exist?(images_dir) Rubygame::Sound.autoload_dirs << sound_dir if File.exist?(sound_dir) Rubygame::Music.autoload_dirs << music_dir if File.exist?(music_dir) end
setup_clock()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 151 def setup_clock clock.target_framerate = self.class.framerate clock.calibrate clock.enable_tick_events end
setup_event_queue()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 157 def setup_event_queue event_queue.enable_new_style_events event_queue.ignore = self.class.ignored_events end
setup_main_view_screen()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 176 def setup_main_view_screen main_view.screen = screen if respond_to?(:main_view) && main_view.respond_to?(:screen=) end
setup_quit_events()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 171 def setup_quit_events hooks = self.class.quit_hooks.inject({}) { |accumulator, hook| accumulator.merge(hook => :quit) } make_magic_hooks hooks end
setup_screen()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 162 def setup_screen self.screen = Rubygame::Screen.new( [self.class.screen_width, self.class.screen_height], self.class.screen_depth, self.class.screen_flags) self.screen.title = self.class.screen_title end
sound_dir()
click to toggle source
# File lib/rugui/framework_adapters/Rubygame.rb, line 196 def sound_dir RuGUI.root.join('app', 'resources', 'sfx') end