mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-15 04:32:35 +00:00
Implemented support for dynamic repainting of gui states with GuiState#needs_repaint?
This commit is contained in:
@@ -65,6 +65,8 @@ module CyberarmEngine
|
||||
|
||||
set_border_thickness
|
||||
set_border_color
|
||||
|
||||
root.gui_state.request_repaint
|
||||
end
|
||||
|
||||
def safe_style_fetch(*args)
|
||||
@@ -166,10 +168,10 @@ module CyberarmEngine
|
||||
return if self.is_a?(ToolTip)
|
||||
|
||||
if old_width != width || old_height != height
|
||||
(root&.gui_state || @gui_state).request_recalculate
|
||||
else
|
||||
stylize
|
||||
root.gui_state.request_recalculate
|
||||
end
|
||||
|
||||
stylize
|
||||
end
|
||||
|
||||
def default_events
|
||||
@@ -267,6 +269,10 @@ module CyberarmEngine
|
||||
@enabled
|
||||
end
|
||||
|
||||
def focused?
|
||||
@focus
|
||||
end
|
||||
|
||||
def visible?
|
||||
@visible
|
||||
end
|
||||
@@ -278,18 +284,21 @@ module CyberarmEngine
|
||||
def toggle
|
||||
@visible = !@visible
|
||||
root.gui_state.request_recalculate
|
||||
root.gui_state.request_repaint
|
||||
end
|
||||
|
||||
def show
|
||||
bool = visible?
|
||||
@visible = true
|
||||
root.gui_state.request_recalculate unless bool
|
||||
root.gui_state.request_repaint unless bool
|
||||
end
|
||||
|
||||
def hide
|
||||
bool = visible?
|
||||
@visible = false
|
||||
root.gui_state.request_recalculate if bool
|
||||
root.gui_state.request_repaint if bool
|
||||
end
|
||||
|
||||
def draw
|
||||
@@ -479,6 +488,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def background=(_background)
|
||||
root.gui_state.request_repaint
|
||||
|
||||
@style.background_canvas.background = _background
|
||||
update_background
|
||||
end
|
||||
@@ -497,6 +508,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def background_nine_slice=(_image_path)
|
||||
root.gui_state.request_repaint
|
||||
|
||||
@style.background_nine_slice_canvas.image = _image_path
|
||||
update_background_nine_slice
|
||||
end
|
||||
@@ -521,6 +534,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def background_image=(image_path)
|
||||
root.gui_state.request_repaint
|
||||
|
||||
@style.background_image = image_path.is_a?(Gosu::Image) ? image_path : get_image(image_path)
|
||||
update_background_image
|
||||
end
|
||||
|
||||
@@ -122,6 +122,9 @@ module CyberarmEngine
|
||||
|
||||
layout
|
||||
|
||||
old_width = @width
|
||||
old_height = @height
|
||||
|
||||
if is_root?
|
||||
@width = @style.width = window.width
|
||||
@height = @style.height = window.height
|
||||
@@ -178,6 +181,8 @@ module CyberarmEngine
|
||||
# puts "TOOK: #{Gosu.milliseconds - s}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}"
|
||||
|
||||
update_background
|
||||
|
||||
root.gui_state.request_repaint if @width != old_width || @height != old_height
|
||||
end
|
||||
|
||||
def layout
|
||||
@@ -242,6 +247,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = 0 if @scroll_position.y > 0
|
||||
|
||||
root.gui_state.request_recalculate_for(self)
|
||||
root.gui_state.request_repaint
|
||||
|
||||
return :handled
|
||||
end
|
||||
@@ -257,6 +263,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
|
||||
|
||||
root.gui_state.request_recalculate_for(self)
|
||||
root.gui_state.request_repaint
|
||||
|
||||
return :handled
|
||||
end
|
||||
@@ -278,7 +285,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def value
|
||||
@children.map { |c| c.class }.join(", ")
|
||||
@children.map(&:class).join(", ")
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
||||
@@ -36,6 +36,9 @@ module CyberarmEngine
|
||||
@text.color = @style.color
|
||||
end
|
||||
|
||||
old_width = @width
|
||||
old_height = @height
|
||||
|
||||
@width = 0
|
||||
@height = 0
|
||||
|
||||
@@ -79,6 +82,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
update_background
|
||||
|
||||
root.gui_state.request_repaint if @width != old_width || @height != old_height
|
||||
end
|
||||
|
||||
def handle_text_wrapping(max_width)
|
||||
@@ -159,6 +164,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def value=(value)
|
||||
old_value = @raw_text
|
||||
@raw_text = value.to_s.chomp
|
||||
|
||||
old_width = width
|
||||
@@ -170,6 +176,8 @@ module CyberarmEngine
|
||||
recalculate
|
||||
end
|
||||
|
||||
root.gui_state.request_repaint if old_value != @raw_text
|
||||
|
||||
publish(:changed, self.value)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,6 +27,8 @@ module CyberarmEngine
|
||||
@pending_recalculate_request = false
|
||||
@pending_element_recalculate_requests = []
|
||||
|
||||
@needs_repaint = false
|
||||
|
||||
@menu = nil
|
||||
@min_drag_distance = 0
|
||||
@mouse_pos = Vector.new
|
||||
@@ -66,6 +68,12 @@ module CyberarmEngine
|
||||
|
||||
@root_container.debug_draw
|
||||
end
|
||||
|
||||
@needs_repaint = false
|
||||
end
|
||||
|
||||
def needs_repaint?
|
||||
@needs_repaint
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -253,6 +261,12 @@ module CyberarmEngine
|
||||
@pending_focus_element = element
|
||||
end
|
||||
|
||||
def request_repaint
|
||||
# puts caller[0..4]
|
||||
# puts
|
||||
@needs_repaint = true
|
||||
end
|
||||
|
||||
def show_menu(list_box)
|
||||
@menu = list_box
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user