Class: Shoes::InternalApp
- Inherits:
-
Object
- Object
- Shoes::InternalApp
- Extended by:
- Forwardable
- Includes:
- Common::Clickable, Common::SafelyEvaluate, Common::Style
- Defined in:
- shoes-core/lib/shoes/internal_app.rb
Overview
This is the representation of the app that is used internally by Shoes objects. It is NOT the app object that a user interacts with in a Shoes.app block. The user facing App object is…the App object.
The InternalApp object is responsible for maintaining the state of the App and providing the bulk of the functionality, leaving the App a relatively blank slate for users to bend to their will.
Constant Summary collapse
- DEFAULT_OPTIONS =
{ width: 600, height: 500, title: "Shoes 4", resizable: true, border: true }.freeze
Constants included from Common::Style
Common::Style::DEFAULT_STYLES, Common::Style::STYLE_GROUPS
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#app_title ⇒ Object
Returns the value of attribute app_title.
-
#blk ⇒ Object
Returns the value of attribute blk.
-
#current_slot ⇒ Object
Returns the value of attribute current_slot.
-
#dimensions ⇒ Object
readonly
Returns the value of attribute dimensions.
-
#element_styles ⇒ Object
readonly
Returns the value of attribute element_styles.
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#gui ⇒ Object
readonly
Returns the value of attribute gui.
- #height ⇒ Object
-
#location ⇒ Object
Returns the value of attribute location.
-
#mouse_button ⇒ Object
Returns the value of attribute mouse_button.
-
#mouse_hover_controls ⇒ Object
Returns the value of attribute mouse_hover_controls.
-
#mouse_motion ⇒ Object
readonly
Returns the value of attribute mouse_motion.
-
#mouse_pos ⇒ Object
Returns the value of attribute mouse_pos.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#remove_styles ⇒ Object
readonly
Returns the value of attribute remove_styles.
-
#resizable ⇒ Object
Returns the value of attribute resizable.
-
#resize_callbacks ⇒ Object
readonly
Returns the value of attribute resize_callbacks.
-
#start_as_fullscreen ⇒ Object
(also: #start_as_fullscreen?)
Returns the value of attribute start_as_fullscreen.
-
#start_block ⇒ Object
Returns the value of attribute start_block.
-
#top_slot ⇒ Object
readonly
Returns the value of attribute top_slot.
- #width ⇒ Object
Attributes included from Common::Clickable
Class Method Summary collapse
Instance Method Summary collapse
- #add_child(_child) ⇒ Object
- #add_mouse_hover_control(element) ⇒ Object
- #add_resize_callback(blk) ⇒ Object
- #clear(&blk) ⇒ Object
- #click ⇒ Object
- #contents ⇒ Object
- #default_styles ⇒ Object
- #download(url, opts, &block) ⇒ Object
- #ensure_backend_loaded ⇒ Object
- #execute_block(blk) ⇒ Object
- #font(path = Shoes::DEFAULT_TEXTBLOCK_FONT) ⇒ Object
-
#hidden? ⇒ Boolean
Necessary for click/mouse positioning checks.
- #in_bounds?(_x, _y) ⇒ Boolean
-
#initialize(app, opts, &blk) ⇒ InternalApp
constructor
A new instance of InternalApp.
- #inspect_details ⇒ Object
- #open_gui ⇒ Object
- #release ⇒ Object
- #remove_mouse_hover_control(element) ⇒ Object
- #setup_gui ⇒ Object
- #started? ⇒ Boolean
- #textcursor(line_height) ⇒ Object
- #trigger_resize_callbacks ⇒ Object
- #wait_until_closed ⇒ Object
Methods included from Common::SafelyEvaluate
Methods included from Common::Style
#applicable_app_styles, #create_style_hash, included, #style, #style_init
Methods included from Common::Clickable
#pass_coordinates?, #register_click
Constructor Details
#initialize(app, opts, &blk) ⇒ InternalApp
Returns a new instance of InternalApp.
27 28 29 30 31 32 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 27 def initialize(app, opts, &blk) @app = app @blk = blk (opts) set_initial_attributes end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
55 56 57 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 55 def app @app end |
#app_title ⇒ Object
Returns the value of attribute app_title.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def app_title @app_title end |
#blk ⇒ Object
Returns the value of attribute blk.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def blk @blk end |
#current_slot ⇒ Object
Returns the value of attribute current_slot.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def current_slot @current_slot end |
#dimensions ⇒ Object (readonly)
Returns the value of attribute dimensions.
55 56 57 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 55 def dimensions @dimensions end |
#element_styles ⇒ Object (readonly)
Returns the value of attribute element_styles.
55 56 57 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 55 def element_styles @element_styles end |
#elements ⇒ Object
Returns the value of attribute elements.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def elements @elements end |
#gui ⇒ Object (readonly)
Returns the value of attribute gui.
55 56 57 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 55 def gui @gui end |
#height ⇒ Object
78 79 80 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 78 def height started? ? gui.height : @dimensions.height end |
#location ⇒ Object
Returns the value of attribute location.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def location @location end |
#mouse_button ⇒ Object
Returns the value of attribute mouse_button.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def @mouse_button end |
#mouse_hover_controls ⇒ Object
Returns the value of attribute mouse_hover_controls.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def mouse_hover_controls @mouse_hover_controls end |
#mouse_motion ⇒ Object (readonly)
Returns the value of attribute mouse_motion.
55 56 57 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 55 def mouse_motion @mouse_motion end |
#mouse_pos ⇒ Object
Returns the value of attribute mouse_pos.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def mouse_pos @mouse_pos end |
#opts ⇒ Object
Returns the value of attribute opts.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def opts @opts end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
55 56 57 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 55 def owner @owner end |
#remove_styles ⇒ Object (readonly)
Returns the value of attribute remove_styles.
55 56 57 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 55 def remove_styles @remove_styles end |
#resizable ⇒ Object
Returns the value of attribute resizable.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def resizable @resizable end |
#resize_callbacks ⇒ Object (readonly)
Returns the value of attribute resize_callbacks.
55 56 57 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 55 def resize_callbacks @resize_callbacks end |
#start_as_fullscreen ⇒ Object Also known as: start_as_fullscreen?
Returns the value of attribute start_as_fullscreen.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def start_as_fullscreen @start_as_fullscreen end |
#start_block ⇒ Object
Returns the value of attribute start_block.
60 61 62 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 60 def start_block @start_block end |
#top_slot ⇒ Object (readonly)
Returns the value of attribute top_slot.
55 56 57 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 55 def top_slot @top_slot end |
#width ⇒ Object
74 75 76 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 74 def width started? ? gui.width : @dimensions.width end |
Class Method Details
.add_global_keypress(key, &blk) ⇒ Object
173 174 175 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 173 def self.add_global_keypress(key, &blk) global_keypresses[key] = blk end |
.global_keypresses ⇒ Object
169 170 171 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 169 def self.global_keypresses @global_keypresses ||= {} end |
Instance Method Details
#add_child(_child) ⇒ Object
90 91 92 93 94 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 90 def add_child(_child) # No-op. The top_slot needs this method, but we already hold an explicit # reference to the top_slot, so we don't need to add it as a child. Other # elements should be added as children of the top_slot. end |
#add_mouse_hover_control(element) ⇒ Object
128 129 130 131 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 128 def add_mouse_hover_control(element) return if mouse_hover_controls.include?(element) mouse_hover_controls << element end |
#add_resize_callback(blk) ⇒ Object
153 154 155 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 153 def add_resize_callback(blk) @resize_callbacks << blk end |
#clear(&blk) ⇒ Object
66 67 68 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 66 def clear(&blk) current_slot.clear(&blk) end |
#click ⇒ Object
118 119 120 121 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 118 def click super @app end |
#contents ⇒ Object
70 71 72 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 70 def contents top_slot.contents end |
#default_styles ⇒ Object
96 97 98 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 96 def default_styles Common::Style::DEFAULT_STYLES.clone end |
#download(url, opts, &block) ⇒ Object
141 142 143 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 141 def download(url, opts, &block) app.download url, opts, &block end |
#ensure_backend_loaded ⇒ Object
48 49 50 51 52 53 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 48 def ensure_backend_loaded return if defined?(Shoes.configuration.backend::App) backend_const = Shoes.load_backend(Shoes.configuration.backend_name) backend_const.initialize_backend end |
#execute_block(blk) ⇒ Object
149 150 151 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 149 def execute_block(blk) app.instance_eval(&blk) end |
#font(path = Shoes::DEFAULT_TEXTBLOCK_FONT) ⇒ Object
82 83 84 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 82 def font(path = Shoes::DEFAULT_TEXTBLOCK_FONT) app.font path end |
#hidden? ⇒ Boolean
Necessary for click/mouse positioning checks
114 115 116 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 114 def hidden? false end |
#in_bounds?(_x, _y) ⇒ Boolean
100 101 102 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 100 def in_bounds?(_x, _y) true end |
#inspect_details ⇒ Object
165 166 167 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 165 def inspect_details "\"#{@app_title}\" #{@dimensions.inspect}" end |
#open_gui ⇒ Object
137 138 139 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 137 def open_gui gui.open end |
#release ⇒ Object
123 124 125 126 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 123 def release super @app end |
#remove_mouse_hover_control(element) ⇒ Object
133 134 135 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 133 def remove_mouse_hover_control(element) mouse_hover_controls.delete(element) end |
#setup_gui ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 34 def setup_gui ensure_backend_loaded @gui = Shoes.configuration.backend::App.new self self.current_slot = create_top_slot execution_blk = create_execution_block(blk) eval_block execution_blk eval_block start_block if start_block setup_global_keypresses register_console_keypress end |
#started? ⇒ Boolean
86 87 88 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 86 def started? gui&.started? end |
#textcursor(line_height) ⇒ Object
145 146 147 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 145 def textcursor(line_height) app.line(0, 0, 0, line_height, hidden: true) end |
#trigger_resize_callbacks ⇒ Object
157 158 159 160 161 162 163 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 157 def trigger_resize_callbacks @resize_callbacks.each do |callback| safely_evaluate do callback.call end end end |
#wait_until_closed ⇒ Object
177 178 179 180 |
# File 'shoes-core/lib/shoes/internal_app.rb', line 177 def wait_until_closed return unless gui gui.wait_until_closed end |