Class: Cura::Application
- Inherits:
-
Object
- Object
- Cura::Application
- Includes:
- Cura::Attributes::HasAttributes, Cura::Attributes::HasEvents, Cura::Attributes::HasInitialize, Cura::Attributes::HasWindows
- Defined in:
- lib/cura/application.rb
Overview
An application.
Instance Attribute Summary collapse
-
#cursor ⇒ Cursor
readonly
Get the text cursor.
-
#dispatcher ⇒ Event::Dispatcher
readonly
Get the event dispatcher.
-
#pencil ⇒ Pencil
readonly
Get the pencil used for drawing.
Attributes included from Cura::Attributes::HasEvents
Attributes included from Cura::Attributes::HasWindows
Class Method Summary collapse
Instance Method Summary collapse
-
#adapter ⇒ Adapter
Get the adapter used for running this application.
-
#adapter=(adapter) ⇒ Adapter
Set the adapter used for running this application.
-
#add_window(window) ⇒ Window
Add a window to this application.
-
#dispatch_event(event, options = {}) ⇒ Event::Base
Dispatch an event.
-
#draw ⇒ Application
Draw all windows.
-
#focus(component) ⇒ Component::Base
Set focus to a component.
-
#focused ⇒ Component::Base
Get the currently focused component.
-
#initialize(attributes = {}) ⇒ Application
constructor
A new instance of Application.
-
#inspect ⇒ String
Instance inspection.
-
#run ⇒ Application
Run this application.
-
#running? ⇒ Boolean
Check if this application is running.
-
#stop ⇒ Application
Stop the application after the current run cycle.
-
#stop! ⇒ Application
Stop the application immediently.
-
#update ⇒ Application
Update all windows.
Methods included from Cura::Attributes::HasEvents
Methods included from Cura::Attributes::HasWindows
#delete_window, #delete_window_at, #delete_windows
Methods included from Cura::Attributes::HasAttributes
Constructor Details
#initialize(attributes = {}) ⇒ Application
Returns a new instance of Application.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cura/application.rb', line 48 def initialize(attributes={}) super # setup_adapter @running = false @cursor = Cursor.new(application: self) @pencil = Pencil.new setup_adapter setup_dispatcher end |
Instance Attribute Details
#cursor ⇒ Cursor (readonly)
Get the text cursor.
78 79 80 |
# File 'lib/cura/application.rb', line 78 def cursor @cursor end |
#dispatcher ⇒ Event::Dispatcher (readonly)
Get the event dispatcher.
88 89 90 |
# File 'lib/cura/application.rb', line 88 def dispatcher @dispatcher end |
#pencil ⇒ Pencil (readonly)
Get the pencil used for drawing.
83 84 85 |
# File 'lib/cura/application.rb', line 83 def pencil @pencil end |
Class Method Details
.run(attributes = {}) ⇒ Object
38 39 40 |
# File 'lib/cura/application.rb', line 38 def run(attributes={}) new(attributes).run end |
Instance Method Details
#adapter ⇒ Adapter
Get the adapter used for running this application.
|
# File 'lib/cura/application.rb', line 61
|
#adapter=(adapter) ⇒ Adapter
Set the adapter used for running this application. This cannot be set after #run is used.
73 |
# File 'lib/cura/application.rb', line 73 attribute(:adapter) { |adapter| validate_adapter(adapter) } |
#add_window(window) ⇒ Window
Add a window to this application.
165 166 167 168 169 170 171 |
# File 'lib/cura/application.rb', line 165 def add_window(window) super window.application = self window end |
#dispatch_event(event, options = {}) ⇒ Event::Base
Dispatch an event.
157 158 159 |
# File 'lib/cura/application.rb', line 157 def dispatch_event(event, ={}) @dispatcher.dispatch_event(event, ) end |
#draw ⇒ Application
Draw all windows.
186 187 188 189 190 |
# File 'lib/cura/application.rb', line 186 def draw draw_windows self end |
#focus(component) ⇒ Component::Base
Set focus to a component.
There can only be one component focused at a time within an application, if any. All dispatched events are sent to the currently focused component, or the application if no component is focused.
141 142 143 144 145 146 147 148 149 |
# File 'lib/cura/application.rb', line 141 def focus(component) raise TypeError, "component must be nil or be a Cura::Component::Base" unless component.nil? || component.is_a?(Cura::Component::Base) dispatch_event(:unfocus) @dispatcher.target = component dispatch_event(:focus) component end |
#focused ⇒ Component::Base
Get the currently focused component.
130 131 132 |
# File 'lib/cura/application.rb', line 130 def focused @dispatcher.target end |
#inspect ⇒ String
Instance inspection.
195 196 197 |
# File 'lib/cura/application.rb', line 195 def inspect "#<#{self.class}>" end |
#run ⇒ Application
Run this application.
93 94 95 96 97 98 99 |
# File 'lib/cura/application.rb', line 93 def run run_event_loop self ensure @adapter.cleanup end |
#running? ⇒ Boolean
Check if this application is running.
123 124 125 |
# File 'lib/cura/application.rb', line 123 def running? @running end |
#stop ⇒ Application
Stop the application after the current run cycle.
104 105 106 107 108 |
# File 'lib/cura/application.rb', line 104 def stop @running = false self end |
#stop! ⇒ Application
Stop the application immediently.
113 114 115 116 117 118 |
# File 'lib/cura/application.rb', line 113 def stop! stop @adapter.cleanup self end |
#update ⇒ Application
Update all windows.
176 177 178 179 180 181 |
# File 'lib/cura/application.rb', line 176 def update update_windows cursor.update self end |