mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 05:02:34 +00:00
Added GuiState#request_recalculation to enable requesting a gui recalc on next update, GUI state will request a recalculation if the window size changes
This commit is contained in:
@@ -3,10 +3,11 @@ module CyberarmEngine
|
||||
include Common
|
||||
|
||||
attr_accessor :stroke_color, :fill_color
|
||||
attr_reader :children
|
||||
attr_reader :children, :gui_state
|
||||
attr_reader :scroll_x, :scroll_y
|
||||
|
||||
def initialize(options = {}, block = nil)
|
||||
@gui_state = options.delete(:gui_state)
|
||||
super
|
||||
|
||||
@scroll_x, @scroll_y = 0, 0
|
||||
|
||||
@@ -119,17 +119,17 @@ module CyberarmEngine
|
||||
|
||||
def toggle
|
||||
@visible = !@visible
|
||||
root.recalculate
|
||||
root.gui_state.request_recalculate
|
||||
end
|
||||
|
||||
def show
|
||||
@visible = true
|
||||
root.recalculate
|
||||
root.gui_state.request_recalculate
|
||||
end
|
||||
|
||||
def hide
|
||||
@visible = false
|
||||
root.recalculate
|
||||
root.gui_state.request_recalculate
|
||||
end
|
||||
|
||||
def draw
|
||||
|
||||
@@ -10,15 +10,18 @@ module CyberarmEngine
|
||||
|
||||
@down_keys = {}
|
||||
|
||||
@root_container = Stack.new
|
||||
@root_container = Stack.new(gui_state: self)
|
||||
@game_objects << @root_container
|
||||
@containers = [@root_container]
|
||||
|
||||
@active_width = window.width
|
||||
@active_height = window.height
|
||||
|
||||
@focus = nil
|
||||
@mouse_over = nil
|
||||
@mouse_down_on = {}
|
||||
@mouse_down_position = {}
|
||||
|
||||
@pending_recalculate_request = false
|
||||
|
||||
setup
|
||||
end
|
||||
@@ -35,6 +38,11 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def update
|
||||
if @pending_recalculate_request
|
||||
@root_container.recalculate
|
||||
@pending_recalculate_request = false
|
||||
end
|
||||
|
||||
super
|
||||
|
||||
new_mouse_over = @root_container.hit_element?(window.mouse_x, window.mouse_y)
|
||||
@@ -49,6 +57,11 @@ module CyberarmEngine
|
||||
redirect_holding_mouse_button(:left) if @mouse_over && Gosu.button_down?(Gosu::MsLeft)
|
||||
redirect_holding_mouse_button(:middle) if @mouse_over && Gosu.button_down?(Gosu::MsMiddle)
|
||||
redirect_holding_mouse_button(:right) if @mouse_over && Gosu.button_down?(Gosu::MsRight)
|
||||
|
||||
request_recalculate if @active_width != window.width || @active_height != window.height
|
||||
|
||||
@active_width = window.width
|
||||
@active_height = window.height
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
@@ -115,5 +128,10 @@ module CyberarmEngine
|
||||
def redirect_mouse_wheel(button)
|
||||
@mouse_over.publish(:"mouse_wheel_#{button}", window.mouse_x, window.mouse_y) if @mouse_over
|
||||
end
|
||||
|
||||
# Schedule a full GUI recalculation on next update
|
||||
def request_recalculate
|
||||
@pending_recalculate_request = true
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -37,7 +37,7 @@ module CyberarmEngine
|
||||
old_width, old_height = width, height
|
||||
recalculate
|
||||
|
||||
root.recalculate if old_width != width || old_height != height
|
||||
root.gui_state.request_recalculate if old_width != width || old_height != height
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user