Class: RuGUI::BaseMainController
- Inherits:
-
BaseController
- Object
- BaseObject
- BaseController
- RuGUI::BaseMainController
- Defined in:
- lib/rugui/base_controller.rb,
lib/rugui/framework_adapters/Rubygame.rb
Overview
A base class for main controllers.
Provides a method for running the application as well as a method to quit.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#screen ⇒ Object
Returns the value of attribute screen.
Attributes inherited from BaseController
#controllers, #main_models, #models, #parent_controller, #views
Class Method Summary collapse
- .framerate(frames_per_second = nil) ⇒ Object
- .ignored_events(*args) ⇒ Object
- .quit_hooks(quit_hooks = nil) ⇒ Object
- .screen_depth(depth = nil) ⇒ Object
- .screen_flags(flags = nil) ⇒ Object
- .screen_height(height = nil) ⇒ Object
- .screen_title(title = nil) ⇒ Object
- .screen_width(width = nil) ⇒ Object
Instance Method Summary collapse
- #clock ⇒ Object
- #event_queue ⇒ Object
-
#framework_adapter ⇒ Object
Returns the framework_adapter for this class.
-
#initialize ⇒ BaseMainController
constructor
A new instance of BaseMainController.
-
#quit ⇒ Object
Exits from the application.
-
#refresh ⇒ Object
Refreshes the GUI application, running just one event loop.
-
#run ⇒ Object
Runs the application.
- #step ⇒ Object
- #tick ⇒ Object
Methods inherited from BaseController
controllers, #main_controller, main_models, models, #post_registration, #register_controller, #register_main_model, #register_model, #register_view, views
Methods included from InitializeHooks
included, #initialize_with_hooks, update_initialize_method
Methods included from EntityRegistrationSupport
Methods included from SignalSupport
#autoconnect_declared_signals, included
Methods included from LogSupport
Methods included from PropertyObserver
included, #named_observable_property_updated, #property_updated
Methods included from FrameworkAdapters::FrameworkAdapterSupport
#framework_adapter_for, included, #load_framework_adapter
Methods inherited from BaseObject
Constructor Details
#initialize ⇒ BaseMainController
Returns a new instance of BaseMainController.
73 74 75 76 77 78 79 80 81 82 |
# 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 |
Instance Attribute Details
#screen ⇒ Object
Returns the value of attribute screen.
71 72 73 |
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 71 def screen @screen end |
Class Method Details
.framerate(frames_per_second = nil) ⇒ Object
111 112 113 |
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 111 def framerate(frames_per_second=nil) @framerate ||= frames_per_second || 30 end |
.ignored_events(*args) ⇒ Object
105 106 107 108 109 |
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 105 def ignored_events(*args) @ignored_events ||= [] @ignored_events += args unless args.empty? @ignored_events end |
.quit_hooks(quit_hooks = nil) ⇒ Object
135 136 137 |
# 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) ⇒ Object
123 124 125 |
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 123 def screen_depth(depth=nil) @screen_depth ||= depth || 0 end |
.screen_flags(flags = nil) ⇒ Object
127 128 129 |
# 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) ⇒ Object
119 120 121 |
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 119 def screen_height(height=nil) @screen_height ||= height || 480 end |
.screen_title(title = nil) ⇒ Object
131 132 133 |
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 131 def screen_title(title=nil) @screen_title ||= title || "RuGUI Game!" end |
.screen_width(width = nil) ⇒ Object
115 116 117 |
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 115 def screen_width(width=nil) @screen_width ||= width || 640 end |
Instance Method Details
#clock ⇒ Object
96 97 98 |
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 96 def clock @clock ||= Rubygame::Clock.new end |
#event_queue ⇒ Object
100 101 102 |
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 100 def event_queue @event_queue ||= Rubygame::EventQueue.new end |
#framework_adapter ⇒ Object
Returns the framework_adapter for this class.
222 223 224 |
# File 'lib/rugui/base_controller.rb', line 222 def framework_adapter framework_adapter_for('BaseMainController') end |
#quit ⇒ Object
Exits from the application.
247 248 249 250 251 |
# 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 ⇒ Object
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.
240 241 242 |
# File 'lib/rugui/base_controller.rb', line 240 def refresh self.framework_adapter.refresh end |
#run ⇒ Object
Runs the application.
229 230 231 232 |
# 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 ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 84 def step clear_screen tick handle_events update screen.update end |
#tick ⇒ Object
92 93 94 |
# File 'lib/rugui/framework_adapters/Rubygame.rb', line 92 def tick event_queue << clock.tick end |