Class: AuthorEngine::Window
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- AuthorEngine::Window
- Defined in:
- lib/author_engine/window.rb
Instance Attribute Summary collapse
-
#base_size ⇒ Object
readonly
Returns the value of attribute base_size.
-
#container ⇒ Object
Returns the value of attribute container.
-
#scale_x ⇒ Object
readonly
Returns the value of attribute scale_x.
-
#scale_y ⇒ Object
readonly
Returns the value of attribute scale_y.
-
#show_cursor ⇒ Object
Returns the value of attribute show_cursor.
-
#sprite_size ⇒ Object
readonly
Returns the value of attribute sprite_size.
-
#square_scale ⇒ Object
readonly
Returns the value of attribute square_scale.
Class Method Summary collapse
Instance Method Summary collapse
- #alt_button_down? ⇒ Boolean
- #button_down(id) ⇒ Object
- #button_up(id) ⇒ Object
- #calculate_scale ⇒ Object
- #close ⇒ Object
- #control_button_down? ⇒ Boolean
- #darken(color, amount = 25) ⇒ Object
- #draw ⇒ Object
-
#initialize ⇒ Window
constructor
A new instance of Window.
- #lighten(color, amount = 25) ⇒ Object
- #save_and_exit ⇒ Object
- #setup ⇒ Object
- #shift_button_down? ⇒ Boolean
- #update ⇒ Object
Constructor Details
#initialize ⇒ Window
Returns a new instance of Window.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/author_engine/window.rb', line 15 def initialize super(512, 512, fullscreen: false) super(512, 512, fullscreen: true) if ARGV.join.include?("--fullscreen") # super(1280, 800, fullscreen: false) super(Gosu.screen_width, Gosu.screen_height, fullscreen: true) if ARGV.join.include?("--native") Window.instance = self @container = nil @show_cursor = true @scale_x = 1.0 @scale_y = 1.0 @square_scale = 1.0 @base_size = SIZE @sprite_size = 16 @close_counter = 0 @cursor = AuthorEngine::Image.new("assets/ui/cursor.png", retro: true) calculate_scale setup end |
Instance Attribute Details
#base_size ⇒ Object (readonly)
Returns the value of attribute base_size.
14 15 16 |
# File 'lib/author_engine/window.rb', line 14 def base_size @base_size end |
#container ⇒ Object
Returns the value of attribute container.
14 15 16 |
# File 'lib/author_engine/window.rb', line 14 def container @container end |
#scale_x ⇒ Object (readonly)
Returns the value of attribute scale_x.
14 15 16 |
# File 'lib/author_engine/window.rb', line 14 def scale_x @scale_x end |
#scale_y ⇒ Object (readonly)
Returns the value of attribute scale_y.
14 15 16 |
# File 'lib/author_engine/window.rb', line 14 def scale_y @scale_y end |
#show_cursor ⇒ Object
Returns the value of attribute show_cursor.
13 14 15 |
# File 'lib/author_engine/window.rb', line 13 def show_cursor @show_cursor end |
#sprite_size ⇒ Object (readonly)
Returns the value of attribute sprite_size.
14 15 16 |
# File 'lib/author_engine/window.rb', line 14 def sprite_size @sprite_size end |
#square_scale ⇒ Object (readonly)
Returns the value of attribute square_scale.
14 15 16 |
# File 'lib/author_engine/window.rb', line 14 def square_scale @square_scale end |
Class Method Details
.instance ⇒ Object
3 4 5 |
# File 'lib/author_engine/window.rb', line 3 def self.instance @instance end |
.instance=(_instance) ⇒ Object
7 8 9 |
# File 'lib/author_engine/window.rb', line 7 def self.instance=(_instance) @instance = _instance end |
Instance Method Details
#alt_button_down? ⇒ Boolean
88 89 90 |
# File 'lib/author_engine/window.rb', line 88 def (Gosu.(Gosu::KbLeftAlt) || Gosu.(Gosu::KbRightAlt)) end |
#button_down(id) ⇒ Object
112 113 114 115 116 |
# File 'lib/author_engine/window.rb', line 112 def (id) super @container.(id) end |
#button_up(id) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/author_engine/window.rb', line 118 def (id) super if id == Gosu::KbEscape @close_counter += 1 save_and_exit if @close_counter == 2 else @close_counter = 0 end @container.(id) end |
#calculate_scale ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/author_engine/window.rb', line 50 def calculate_scale warn "Display is to small! (was #{self.width}x#{self.height} minimum is 128x128)" if self.width < 128 || self.height < 128 @scale_x = (self.width / VIEW_WIDTH) @scale_y = (self.height / VIEW_HEIGHT) @square_scale = @scale_y end |
#close ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/author_engine/window.rb', line 104 def close if @container @container.close else super end end |
#control_button_down? ⇒ Boolean
84 85 86 |
# File 'lib/author_engine/window.rb', line 84 def (Gosu.(Gosu::KbLeftControl) || Gosu.(Gosu::KbRightControl)) end |
#darken(color, amount = 25) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/author_engine/window.rb', line 76 def darken(color, amount = 25) if defined?(color.alpha) return Gosu::Color.rgba(color.red-amount, color.green-amount, color.blue-amount, color.alpha) else return Gosu::Color.rgb(color.red-amount, color.green-amount, color.blue-amount) end end |
#draw ⇒ Object
59 60 61 62 |
# File 'lib/author_engine/window.rb', line 59 def draw @container.draw @cursor.draw(mouse_x, mouse_y, Float::INFINITY, @square_scale, @square_scale) if @show_cursor end |
#lighten(color, amount = 25) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/author_engine/window.rb', line 68 def lighten(color, amount = 25) if defined?(color.alpha) return Gosu::Color.rgba(color.red+amount, color.green+amount, color.blue+amount, color.alpha) else return Gosu::Color.rgb(color.red+amount, color.green+amount, color.blue+amount) end end |
#save_and_exit ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/author_engine/window.rb', line 96 def save_and_exit if @container.is_a?(Editor) @container.savefile.save end close! end |
#setup ⇒ Object
39 40 41 |
# File 'lib/author_engine/window.rb', line 39 def setup self.container=(Loader.new) end |
#shift_button_down? ⇒ Boolean
92 93 94 |
# File 'lib/author_engine/window.rb', line 92 def (Gosu.(Gosu::KbLeftShift) || Gosu.(Gosu::KbRightShift)) end |
#update ⇒ Object
64 65 66 |
# File 'lib/author_engine/window.rb', line 64 def update @container.update end |