Compare commits

6 Commits

18 changed files with 247 additions and 117 deletions

View File

@@ -1,10 +1,11 @@
module CyberarmEngine module CyberarmEngine
class BackgroundImage class BackgroundImage
include CyberarmEngine::Common include CyberarmEngine::Common
attr_accessor :x, :y, :z, :width, :height, :mode, :color attr_accessor :x, :y, :z, :mode
attr_reader :image attr_reader :image, :width, :height, :color
def initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :fill, color: Gosu::Color::WHITE) def initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :fill, color: Gosu::Color::WHITE)
@image_path = image_path
@image = get_image(image_path) if image_path @image = get_image(image_path) if image_path
@x = x @x = x
@@ -16,12 +17,31 @@ module CyberarmEngine
@mode = mode @mode = mode
@color = color @color = color
@cached_tiling = nil
end end
def image=(image_path) def image=(image_path)
@cached_tiling = nil if image_path != @image_path
@image_path = image_path
@image = image_path ? get_image(image_path) : image_path @image = image_path ? get_image(image_path) : image_path
end end
def width=(n)
@cached_tiling = nil if @width != n
@width = n
end
def height=(n)
@cached_tiling = nil if @height != n
@height = n
end
def color=(c)
@cached_tiling = nil if @color != c
@color = c
end
def width_scale def width_scale
(@width.to_f / @image.width).abs (@width.to_f / @image.width).abs
end end
@@ -33,7 +53,9 @@ module CyberarmEngine
def draw def draw
return unless @image return unless @image
send(:"draw_#{mode}") Gosu.clip_to(@x, @y, @width, @height) do
send(:"draw_#{mode}")
end
end end
def draw_stretch def draw_stretch
@@ -41,15 +63,31 @@ module CyberarmEngine
end end
def draw_tiled def draw_tiled
raise NotImplementedError @cached_tiling ||= Gosu.record(@width, @height) do
height_scale.ceil.times do |y|
width_scale.ceil.times do |x|
@image.draw(x * @image.width, y * @image.height, @z, 1, 1, @color)
end
end
end
@cached_tiling.draw(@x, @y, @z)
end end
def draw_fill def draw_fill
if @width * width_scale > height * height_scale if @width * width_scale > height * height_scale
@image.draw(@x, @y, @z, width_scale, width_scale, @color) draw_fill_width
else else
@image.draw(@x, @y, @z, height_scale, height_scale, @color) draw_fill_height
end end
end end
def draw_fill_width
@image.draw(@x, @y, @z, width_scale, width_scale, @color)
end
def draw_fill_height
@image.draw(@x, @y, @z, height_scale, height_scale, @color)
end
end end
end end

View File

@@ -95,7 +95,7 @@ module CyberarmEngine
end end
def window def window
$window CyberarmEngine::Window.instance
end end
def control_down? def control_down?

View File

@@ -7,7 +7,7 @@ module CyberarmEngine
attr_reader :alpha attr_reader :alpha
def initialize(options = {}) def initialize(options = {})
$window.current_state.add_game_object(self) if options[:auto_manage] || options[:auto_manage].nil? window.current_state.add_game_object(self) if options[:auto_manage] || options[:auto_manage].nil?
@options = options @options = options
@image = options[:image] ? image(options[:image]) : nil @image = options[:image] ? image(options[:image]) : nil
@@ -55,9 +55,9 @@ module CyberarmEngine
if $debug if $debug
show_debug_heading show_debug_heading
$window.draw_circle(@position.x, @position.y, radius, 9999, @debug_color) Gosu.draw_circle(@position.x, @position.y, radius, 9999, @debug_color)
if @debug_text.text != "" if @debug_text.text != ""
$window.draw_rect(@debug_text.x - 10, (@debug_text.y - 10), @debug_text.width + 20, @debug_text.height + 20, Gosu.draw_rect(@debug_text.x - 10, (@debug_text.y - 10), @debug_text.width + 20, @debug_text.height + 20,
Gosu::Color.rgba(0, 0, 0, 200), 9999) Gosu::Color.rgba(0, 0, 0, 200), 9999)
@debug_text.draw @debug_text.draw
end end
@@ -102,13 +102,13 @@ module CyberarmEngine
end end
def _x_visible def _x_visible
x.between?(($window.width / 2) - @world_center_point.x, ($window.width / 2) + @world_center_point.x) || x.between?((window.width / 2) - @world_center_point.x, (window.width / 2) + @world_center_point.x) ||
x.between?((@world_center_point.x - $window.width / 2), ($window.width / 2) + @world_center_point.x) x.between?((@world_center_point.x - window.width / 2), (window.width / 2) + @world_center_point.x)
end end
def _y_visible def _y_visible
y.between?(($window.height / 2) - @world_center_point.y, ($window.height / 2) + @world_center_point.y) || y.between?((window.height / 2) - @world_center_point.y, (window.height / 2) + @world_center_point.y) ||
y.between?(@world_center_point.y - ($window.height / 2), ($window.height / 2) + @world_center_point.y) y.between?(@world_center_point.y - (window.height / 2), (window.height / 2) + @world_center_point.y)
end end
def heading(ahead_by = 100, _object = nil, angle_only = false) def heading(ahead_by = 100, _object = nil, angle_only = false)
@@ -153,10 +153,6 @@ module CyberarmEngine
@color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, int) @color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, int)
end end
def draw_rect(x, y, width, height, color, z = 0)
$window.draw_rect(x, y, width, height, color, z)
end
def button_up(id) def button_up(id)
end end
@@ -190,12 +186,12 @@ module CyberarmEngine
# Duplication... so DRY. # Duplication... so DRY.
def each_circle_collision(object, _resolve_with = :width, &block) def each_circle_collision(object, _resolve_with = :width, &block)
if object.class != Class && object.instance_of?(object.class) if object.class != Class && object.instance_of?(object.class)
$window.current_state.game_objects.select { |i| i.instance_of?(object.class) }.each do |o| window.current_state.game_objects.select { |i| i.instance_of?(object.class) }.each do |o|
distance = Gosu.distance(x, y, object.x, object.y) distance = Gosu.distance(x, y, object.x, object.y)
block.call(o, object) if distance <= radius + object.radius && block block.call(o, object) if distance <= radius + object.radius && block
end end
else else
list = $window.current_state.game_objects.select { |i| i.instance_of?(object) } list = window.current_state.game_objects.select { |i| i.instance_of?(object) }
list.each do |o| list.each do |o|
next if self == o next if self == o
@@ -206,9 +202,9 @@ module CyberarmEngine
end end
def destroy def destroy
if $window.current_state if window.current_state
$window.current_state.game_objects.each do |o| window.current_state.game_objects.each do |o|
$window.current_state.game_objects.delete(o) if o.is_a?(self.class) && o == self window.current_state.game_objects.delete(o) if o.is_a?(self.class) && o == self
end end
end end
end end
@@ -220,13 +216,13 @@ module CyberarmEngine
def self.each_circle_collision(object, _resolve_with = :width, &block) def self.each_circle_collision(object, _resolve_with = :width, &block)
if object.class != Class && object.instance_of?(object.class) if object.class != Class && object.instance_of?(object.class)
$window.current_state.game_objects.select { |i| i.instance_of?(self) }.each do |o| window.current_state.game_objects.select { |i| i.instance_of?(self) }.each do |o|
distance = Gosu.distance(o.x, o.y, object.x, object.y) distance = Gosu.distance(o.x, o.y, object.x, object.y)
block.call(o, object) if distance <= o.radius + object.radius && block block.call(o, object) if distance <= o.radius + object.radius && block
end end
else else
lista = $window.current_state.game_objects.select { |i| i.instance_of?(self) } lista = window.current_state.game_objects.select { |i| i.instance_of?(self) }
listb = $window.current_state.game_objects.select { |i| i.instance_of?(object) } listb = window.current_state.game_objects.select { |i| i.instance_of?(object) }
lista.product(listb).each do |o, o2| lista.product(listb).each do |o, o2|
next if o == o2 next if o == o2
@@ -238,9 +234,9 @@ module CyberarmEngine
def self.destroy_all def self.destroy_all
INSTANCES.clear INSTANCES.clear
if $window.current_state if window.current_state
$window.current_state.game_objects.each do |o| window.current_state.game_objects.each do |o|
$window.current_state.game_objects.delete(o) if o.is_a?(self.class) window.current_state.game_objects.delete(o) if o.is_a?(self.class)
end end
end end
end end

View File

@@ -9,7 +9,7 @@ module CyberarmEngine
@options = options @options = options
@game_objects = [] @game_objects = []
@global_pause = false @global_pause = false
$window.text_input = nil unless options[:preserve_text_input] window.text_input = nil unless options[:preserve_text_input]
@down_keys = {} @down_keys = {}
end end
@@ -30,48 +30,23 @@ module CyberarmEngine
@game_objects.each(&:update) @game_objects.each(&:update)
end end
def draw_bounding_box(box) def needs_redraw?
x = box.x true
y = box.y
max_x = box.max_x
max_y = box.max_y
color = Gosu::Color.rgba(255, 127, 64, 240)
# pipe = 4
# Gosu.draw_rect(x-width, y-height, x+(width*2), y+(height*2), color, Float::INFINITY)
# puts "BB render: #{x}:#{y} w:#{x.abs+width} h:#{y.abs+height}"
# Gosu.draw_rect(x, y, x.abs+width, y.abs+height, color, Float::INFINITY)
# TOP LEFT to BOTTOM LEFT
$window.draw_line(
x, y, color,
x, max_y, color,
Float::INFINITY
)
# BOTTOM LEFT to BOTTOM RIGHT
$window.draw_line(
x, max_y, color,
max_x, max_y, color,
Float::INFINITY
)
# BOTTOM RIGHT to TOP RIGHT
$window.draw_line(
max_x, max_y, color,
max_x, y, color,
Float::INFINITY
)
# TOP RIGHT to TOP LEFT
$window.draw_line(
max_x, y, color,
x, y, color,
Float::INFINITY
)
end end
def destroy def drop(filename)
@options.clear end
@game_objects.clear
def gamepad_connected(index)
end
def gamepad_disconnected(index)
end
def gain_focus
end
def lose_focus
end end
def button_down(id) def button_down(id)
@@ -90,6 +65,54 @@ module CyberarmEngine
end end
end end
def close
window.close!
end
def draw_bounding_box(box)
x = box.x
y = box.y
max_x = box.max_x
max_y = box.max_y
color = Gosu::Color.rgba(255, 127, 64, 240)
# pipe = 4
# Gosu.draw_rect(x-width, y-height, x+(width*2), y+(height*2), color, Float::INFINITY)
# puts "BB render: #{x}:#{y} w:#{x.abs+width} h:#{y.abs+height}"
# Gosu.draw_rect(x, y, x.abs+width, y.abs+height, color, Float::INFINITY)
# TOP LEFT to BOTTOM LEFT
Gosu.draw_line(
x, y, color,
x, max_y, color,
Float::INFINITY
)
# BOTTOM LEFT to BOTTOM RIGHT
Gosu.draw_line(
x, max_y, color,
max_x, max_y, color,
Float::INFINITY
)
# BOTTOM RIGHT to TOP RIGHT
Gosu.draw_line(
max_x, max_y, color,
max_x, y, color,
Float::INFINITY
)
# TOP RIGHT to TOP LEFT
Gosu.draw_line(
max_x, y, color,
x, y, color,
Float::INFINITY
)
end
def destroy
@options.clear
@game_objects.clear
end
def add_game_object(object) def add_game_object(object)
@game_objects << object @game_objects << object
end end

View File

@@ -4,7 +4,7 @@ module CyberarmEngine
def initialize def initialize
@bounding_box_renderer = BoundingBoxRenderer.new @bounding_box_renderer = BoundingBoxRenderer.new
@opengl_renderer = OpenGLRenderer.new(width: $window.width, height: $window.height) @opengl_renderer = OpenGLRenderer.new(width: CyberarmEngine::Window.instance.width, height: CyberarmEngine::Window.instance.height)
end end
def draw(camera, lights, entities) def draw(camera, lights, entities)

View File

@@ -43,9 +43,9 @@ module CyberarmEngine
when :left when :left
@x = 0 + BUTTON_PADDING @x = 0 + BUTTON_PADDING
when :center when :center
@x = ($window.width / 2) - (@textobject.text_width(@text) / 2) @x = (CyberarmEngine::Window.instance.width / 2) - (@textobject.text_width(@text) / 2)
when :right when :right
@x = $window.width - BUTTON_PADDING - @textobject.text_width(@text) @x = CyberarmEngine::Window.instance.width - BUTTON_PADDING - @textobject.text_width(@text)
end end
end end
end end

View File

@@ -116,7 +116,7 @@ module CyberarmEngine
end end
private def element_parent private def element_parent
$__current_container__ CyberarmEngine::Element::Container.current_container
end end
private def container(klass, options = {}, &block) private def container(klass, options = {}, &block)
@@ -126,12 +126,12 @@ module CyberarmEngine
_container = klass.new(options, block) _container = klass.new(options, block)
old_parent = element_parent old_parent = element_parent
$__current_container__ = _container CyberarmEngine::Element::Container.current_container = _container
_container.build _container.build
_container.parent.add(_container) _container.parent.add(_container)
$__current_container__ = old_parent CyberarmEngine::Element::Container.current_container = old_parent
_container _container
end end

View File

@@ -441,7 +441,7 @@ module CyberarmEngine
raise "dimension must be either :width or :height" unless %i[width height].include?(dimension) raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)
new_size = if size.is_a?(Numeric) && size.between?(0.0, 1.0) new_size = if size.is_a?(Numeric) && size.between?(0.0, 1.0)
(@parent.send(:"content_#{dimension}") * size).round - send(:"noncontent_#{dimension}").round (@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
else else
size size
end end
@@ -450,11 +450,15 @@ module CyberarmEngine
fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f # include self since we're dividing fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f # include self since we're dividing
if dimension == :width && @parent.is_a?(Flow) if dimension == :width && @parent.is_a?(Flow)
space_available_width = ((@parent.content_width - (@parent.children.reject { |c| c.style.fill }).map(&:outer_width).sum) / fill_siblings).round space_available_width = ((@parent.content_width - (@parent.children.reject { |c| c.style.fill }).map(&:outer_width).sum) / fill_siblings)
space_available_width = space_available_width.nan? ? 0 : space_available_width.floor # The parent element might not have its dimensions, yet.
return space_available_width - noncontent_width return space_available_width - noncontent_width
elsif dimension == :height && @parent.is_a?(Stack) elsif dimension == :height && @parent.is_a?(Stack)
space_available_height = ((@parent.content_height - (@parent.children.reject { |c| c.style.fill }).map(&:outer_height).sum) / fill_siblings).round space_available_height = ((@parent.content_height - (@parent.children.reject { |c| c.style.fill }).map(&:outer_height).sum) / fill_siblings)
space_available_height = space_available_height.nan? ? 0 : space_available_height.floor # The parent element might not have its dimensions, yet.
return space_available_height - noncontent_height return space_available_height - noncontent_height
end end
@@ -509,8 +513,6 @@ module CyberarmEngine
end end
def background_image=(image_path) def background_image=(image_path)
pp @style.background_image_canvas.image
@style.background_image = image_path.is_a?(Gosu::Image) ? image_path : get_image(image_path) @style.background_image = image_path.is_a?(Gosu::Image) ? image_path : get_image(image_path)
update_background_image update_background_image
end end

View File

@@ -64,8 +64,8 @@ module CyberarmEngine
@scale_y = 1 @scale_y = 1
end end
@width = _width || @image.width.round * @scale_x @width = _width || @image.width.floor * @scale_x
@height = _height || @image.height.round * @scale_y @height = _height || @image.height.floor * @scale_y
update_background update_background
else else

View File

@@ -6,6 +6,16 @@ module CyberarmEngine
attr_accessor :stroke_color, :fill_color attr_accessor :stroke_color, :fill_color
attr_reader :children, :gui_state, :scroll_position attr_reader :children, :gui_state, :scroll_position
def self.current_container
@@current_container
end
def self.current_container=(container)
raise ArgumentError, "Expected container to an an instance of CyberarmEngine::Element::Container, got #{container.class}" unless container.is_a?(CyberarmEngine::Element::Container)
@@current_container = container
end
def initialize(options = {}, block = nil) def initialize(options = {}, block = nil)
@gui_state = options.delete(:gui_state) @gui_state = options.delete(:gui_state)
super super
@@ -35,23 +45,23 @@ module CyberarmEngine
def clear(&block) def clear(&block)
@children.clear @children.clear
old_container = $__current_container__ old_container = CyberarmEngine::Element::Container.current_container
$__current_container__ = self CyberarmEngine::Element::Container.current_container = self
block.call(self) if block block.call(self) if block
$__current_container__ = old_container CyberarmEngine::Element::Container.current_container = old_container
root.gui_state.request_recalculate root.gui_state.request_recalculate
end end
def append(&block) def append(&block)
old_container = $__current_container__ old_container = CyberarmEngine::Element::Container.current_container
$__current_container__ = self CyberarmEngine::Element::Container.current_container = self
block.call(self) if block block.call(self) if block
$__current_container__ = old_container CyberarmEngine::Element::Container.current_container = old_container
root.gui_state.request_recalculate root.gui_state.request_recalculate
end end
@@ -122,8 +132,8 @@ module CyberarmEngine
_width = dimensional_size(@style.width, :width) _width = dimensional_size(@style.width, :width)
_height = dimensional_size(@style.height, :height) _height = dimensional_size(@style.height, :height)
@width = _width || (@children.map { |c| c.x + c.outer_width }.max || 0).round @width = _width || (@children.map { |c| c.x + c.outer_width }.max || 0).floor
@height = _height || (@children.map { |c| c.y + c.outer_height }.max || 0).round @height = _height || (@children.map { |c| c.y + c.outer_height }.max || 0).floor
end end
# Move child to parent after positioning # Move child to parent after positioning

View File

@@ -98,7 +98,7 @@ module CyberarmEngine
end end
def row_at(y) def row_at(y)
((y - @text.y) / @text.textobject.height).round ((y - @text.y) / @text.textobject.height).floor
end end
def column_at(x, y) def column_at(x, y)

View File

@@ -45,8 +45,8 @@ module CyberarmEngine
@scale_y = 1 @scale_y = 1
end end
@width = _width || @image.width.round * @scale_x @width = _width || @image.width.floor * @scale_x
@height = _height || @image.height.round * @scale_y @height = _height || @image.height.floor * @scale_y
update_background update_background
end end

View File

@@ -17,6 +17,8 @@ module CyberarmEngine
@menu.define_singleton_method(:recalculate_menu) do @menu.define_singleton_method(:recalculate_menu) do
@x = @__list_box.x @x = @__list_box.x
@y = @__list_box.y + @__list_box.height @y = @__list_box.y + @__list_box.height
@y = @__list_box.y - height if @y + height > window.height
end end
@menu.instance_variable_set(:"@__list_box", self) @menu.instance_variable_set(:"@__list_box", self)
@@ -29,6 +31,13 @@ module CyberarmEngine
self.choose = @choose self.choose = @choose
end end
def render
super
w = @text.textobject.text_width("")
@text.textobject.draw_text("", @x + content_width - w, @y + @style.padding_top, @z, 1, 1, @text.color)
end
def choose=(item) def choose=(item)
valid = @items.detect { |i| i == item } valid = @items.detect { |i| i == item }
raise "Invalid value '#{item}' for choose, valid options were: #{@items.map { |i| "#{i.inspect}" }.join(", ")}" unless valid raise "Invalid value '#{item}' for choose, valid options were: #{@items.map { |i| "#{i.inspect}" }.join(", ")}" unless valid

View File

@@ -43,8 +43,8 @@ module CyberarmEngine
handle_text_wrapping(_width) handle_text_wrapping(_width)
@width = _width || @text.width.round @width = _width || @text.width.floor
@height = _height || @text.height.round @height = _height || @text.height.floor
@text.y = @style.border_thickness_top + @style.padding_top + @y @text.y = @style.border_thickness_top + @style.padding_top + @y
@text.z = @z + 3 @text.z = @z + 3

View File

@@ -12,7 +12,7 @@ module CyberarmEngine
@root_container = Element::Stack.new(gui_state: self) @root_container = Element::Stack.new(gui_state: self)
@game_objects << @root_container @game_objects << @root_container
$__current_container__ = @root_container CyberarmEngine::Element::Container.current_container = @root_container
@active_width = window.width @active_width = window.width
@active_height = window.height @active_height = window.height
@@ -90,6 +90,8 @@ module CyberarmEngine
@menu&.update @menu&.update
super super
return unless window.has_focus?
new_mouse_over = @menu.hit_element?(window.mouse_x, window.mouse_y) if @menu new_mouse_over = @menu.hit_element?(window.mouse_x, window.mouse_y) if @menu
new_mouse_over ||= @root_container.hit_element?(window.mouse_x, window.mouse_y) new_mouse_over ||= @root_container.hit_element?(window.mouse_x, window.mouse_y)
@@ -135,10 +137,6 @@ module CyberarmEngine
@active_height = window.height @active_height = window.height
end end
def tool_tip_delay
250 # ms
end
def button_down(id) def button_down(id)
super super
@@ -175,6 +173,10 @@ module CyberarmEngine
@focus.button_up(id) if @focus.respond_to?(:button_up) @focus.button_up(id) if @focus.respond_to?(:button_up)
end end
def tool_tip_delay
@tip.style.delay || 250 # ms
end
def redirect_mouse_button(button) def redirect_mouse_button(button)
hide_menu unless @menu && (@menu == @mouse_over) || (@mouse_over&.parent == @menu) hide_menu unless @menu && (@menu == @mouse_over) || (@mouse_over&.parent == @menu)

View File

@@ -154,6 +154,7 @@ module CyberarmEngine
}, },
ToolTip: { # < TextBlock ToolTip: { # < TextBlock
delay: 100, # ms
color: Gosu::Color::WHITE, color: Gosu::Color::WHITE,
padding_top: 4, padding_top: 4,
padding_bottom: 4, padding_bottom: 4,

View File

@@ -1,4 +1,4 @@
module CyberarmEngine module CyberarmEngine
NAME = "InDev".freeze NAME = "InDev".freeze
VERSION = "0.20.0".freeze VERSION = "0.21.0".freeze
end end

View File

@@ -8,21 +8,33 @@ module CyberarmEngine
attr_accessor :show_cursor attr_accessor :show_cursor
attr_writer :exit_on_opengl_error attr_writer :exit_on_opengl_error
attr_reader :last_frame_time attr_reader :last_frame_time, :states
def self.now def self.now
Gosu.milliseconds Gosu.milliseconds
end end
def self.dt def self.dt
$window.last_frame_time / 1000.0 instance.last_frame_time / 1000.0
end
def self.instance=(window)
raise ArgumentError, "Expected window to be a subclass of CyberarmEngine::Window, got: #{window.class}" unless window.is_a?(CyberarmEngine::Window)
@@instance = window
end
def self.instance
@@instance
end end
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false) def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)
@show_cursor = false @show_cursor = false
@has_focus = false
super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable, borderless: borderless) super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable, borderless: borderless)
$window = self Window.instance = self
@last_frame_time = Gosu.milliseconds - 1 @last_frame_time = Gosu.milliseconds - 1
@current_frame_time = Gosu.milliseconds @current_frame_time = Gosu.milliseconds
self.caption = "CyberarmEngine #{CyberarmEngine::VERSION} #{Gosu.language}" self.caption = "CyberarmEngine #{CyberarmEngine::VERSION} #{Gosu.language}"
@@ -34,13 +46,14 @@ module CyberarmEngine
end end
def draw def draw
current_state.draw if current_state current_state&.draw
end end
def update def update
Stats.clear Stats.clear
current_state.update if current_state current_state&.update
@last_frame_time = Gosu.milliseconds - @current_frame_time @last_frame_time = Gosu.milliseconds - @current_frame_time
@current_frame_time = Gosu.milliseconds @current_frame_time = Gosu.milliseconds
end end
@@ -49,6 +62,48 @@ module CyberarmEngine
@show_cursor @show_cursor
end end
def needs_redraw?
current_state ? current_state.needs_redraw? : true
end
def drop(filename)
current_state&.drop(filename)
end
def gamepad_connected(index)
current_state&.gamepad_connected(index)
end
def gamepad_disconnected(index)
current_state&.gamepad_disconnected(index)
end
def gain_focus
@has_focus = true
current_state&.gain_focus
end
def lose_focus
@has_focus = false
current_state&.lose_focus
end
def button_down(id)
super
current_state&.button_down(id)
end
def button_up(id)
super
current_state&.button_up(id)
end
def close
current_state ? current_state.close : super
end
def dt def dt
@last_frame_time / 1000.0 @last_frame_time / 1000.0
end end
@@ -61,16 +116,6 @@ module CyberarmEngine
@exit_on_opengl_error @exit_on_opengl_error
end end
def button_down(id)
super
current_state.button_down(id) if current_state
end
def button_up(id)
super
current_state.button_up(id) if current_state
end
def push_state(klass, options = {}) def push_state(klass, options = {})
options = { setup: true }.merge(options) options = { setup: true }.merge(options)
@@ -108,6 +153,10 @@ module CyberarmEngine
@states.shift @states.shift
end end
def has_focus?
@has_focus
end
# Sourced from https://gist.github.com/ippa/662583 # Sourced from https://gist.github.com/ippa/662583
def draw_circle(cx, cy, r, z = 9999, color = Gosu::Color::GREEN, step = 10) def draw_circle(cx, cy, r, z = 9999, color = Gosu::Color::GREEN, step = 10)
0.step(360, step) do |a1| 0.step(360, step) do |a1|