class AuthorEngine::Window

Constants

SIZE

Attributes

base_size[R]
container[R]
scale_x[R]
scale_y[R]
show_cursor[RW]
sprite_size[R]
square_scale[R]

Public Class Methods

instance() click to toggle source
# File lib/author_engine/window.rb, line 3
def self.instance
  @instance
end
instance=(_instance) click to toggle source
# File lib/author_engine/window.rb, line 7
def self.instance=(_instance)
  @instance = _instance
end
new() click to toggle source
Calls superclass method
# 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

Public Instance Methods

alt_button_down?() click to toggle source
# File lib/author_engine/window.rb, line 88
def alt_button_down?
  (Gosu.button_down?(Gosu::KbLeftAlt) || Gosu.button_down?(Gosu::KbRightAlt))
end
button_down(id) click to toggle source
Calls superclass method
# File lib/author_engine/window.rb, line 112
def button_down(id)
  super

  @container.button_down(id)
end
button_up(id) click to toggle source
Calls superclass method
# File lib/author_engine/window.rb, line 118
def button_up(id)
  super

  if id == Gosu::KbEscape
    @close_counter += 1
    save_and_exit if @close_counter == 2
  else
    @close_counter = 0
  end

  @container.button_up(id)
end
calculate_scale() click to toggle source
# 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() click to toggle source
Calls superclass method
# File lib/author_engine/window.rb, line 104
def close
  if @container
    @container.close
  else
    super
  end
end
container=(container) click to toggle source
# File lib/author_engine/window.rb, line 43
def container=(container)
  if container.is_a?(Container)
    @container = container
    @container.setup
  end
end
control_button_down?() click to toggle source
# File lib/author_engine/window.rb, line 84
def control_button_down?
  (Gosu.button_down?(Gosu::KbLeftControl) || Gosu.button_down?(Gosu::KbRightControl))
end
darken(color, amount = 25) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/author_engine/window.rb, line 96
def save_and_exit
  if @container.is_a?(Editor)
    @container.savefile.save
  end

  close!
end
setup() click to toggle source
# File lib/author_engine/window.rb, line 39
def setup
  self.container=(Loader.new)
end
shift_button_down?() click to toggle source
# File lib/author_engine/window.rb, line 92
def shift_button_down?
  (Gosu.button_down?(Gosu::KbLeftShift) || Gosu.button_down?(Gosu::KbRightShift))
end
update() click to toggle source
# File lib/author_engine/window.rb, line 64
def update
  @container.update
end