mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-17 05:22:35 +00:00
Compare commits
7 Commits
54802e1254
...
v0.20.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 24bd769a32 | |||
| 2be5733bc1 | |||
| c8734ae98b | |||
| c35d587419 | |||
| 153871e7f3 | |||
| cf91d4a083 | |||
| 35ad687d4c |
@@ -4,7 +4,7 @@ module CyberarmEngine
|
|||||||
include Event
|
include Event
|
||||||
include Common
|
include Common
|
||||||
|
|
||||||
attr_accessor :x, :y, :z, :tip
|
attr_accessor :x, :y, :z, :tip, :element_visible
|
||||||
attr_reader :parent, :options, :style, :event_handler, :background_canvas, :border_canvas
|
attr_reader :parent, :options, :style, :event_handler, :background_canvas, :border_canvas
|
||||||
|
|
||||||
def initialize(options = {}, block = nil)
|
def initialize(options = {}, block = nil)
|
||||||
@@ -13,9 +13,9 @@ module CyberarmEngine
|
|||||||
@options = options
|
@options = options
|
||||||
@block = block
|
@block = block
|
||||||
|
|
||||||
@focus = @options[:focus].nil? ? false : @options[:focus]
|
@focus = !@options.key?(:focus) ? false : @options[:focus]
|
||||||
@enabled = @options[:enabled].nil? ? true : @options[:enabled]
|
@enabled = !@options.key?(:enabled) ? true : @options[:enabled]
|
||||||
@visible = @options[:visible].nil? ? true : @options[:visible]
|
@visible = !@options.key?(:visible) ? true : @options[:visible]
|
||||||
@tip = @options[:tip] || ""
|
@tip = @options[:tip] || ""
|
||||||
|
|
||||||
@debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color]
|
@debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color]
|
||||||
@@ -24,6 +24,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
@root ||= nil
|
@root ||= nil
|
||||||
@gui_state ||= nil
|
@gui_state ||= nil
|
||||||
|
@element_visible = true
|
||||||
|
|
||||||
@x = @style.x
|
@x = @style.x
|
||||||
@y = @style.y
|
@y = @style.y
|
||||||
@@ -260,6 +261,10 @@ module CyberarmEngine
|
|||||||
@visible
|
@visible
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def element_visible?
|
||||||
|
@element_visible
|
||||||
|
end
|
||||||
|
|
||||||
def toggle
|
def toggle
|
||||||
@visible = !@visible
|
@visible = !@visible
|
||||||
root.gui_state.request_recalculate
|
root.gui_state.request_recalculate
|
||||||
@@ -279,14 +284,13 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def draw
|
def draw
|
||||||
return unless visible?
|
return unless visible?
|
||||||
|
return unless element_visible?
|
||||||
|
|
||||||
@style.background_canvas.draw
|
@style.background_canvas.draw
|
||||||
@style.background_nine_slice_canvas.draw
|
@style.background_nine_slice_canvas.draw
|
||||||
@style.border_canvas.draw
|
@style.border_canvas.draw
|
||||||
|
|
||||||
Gosu.clip_to(@x, @y, width, height) do
|
render
|
||||||
render
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def debug_draw
|
def debug_draw
|
||||||
|
|||||||
@@ -86,9 +86,12 @@ module CyberarmEngine
|
|||||||
|
|
||||||
old_width = width
|
old_width = width
|
||||||
old_height = height
|
old_height = height
|
||||||
recalculate
|
|
||||||
|
|
||||||
root.gui_state.request_recalculate if old_width != width || old_height != height
|
if old_width != width || old_height != height
|
||||||
|
root.gui_state.request_recalculate
|
||||||
|
else
|
||||||
|
recalculate
|
||||||
|
end
|
||||||
|
|
||||||
publish(:changed, self.value)
|
publish(:changed, self.value)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ module CyberarmEngine
|
|||||||
root.gui_state.request_recalculate
|
root.gui_state.request_recalculate
|
||||||
end
|
end
|
||||||
|
|
||||||
def apend(&block)
|
def append(&block)
|
||||||
old_container = $__current_container__
|
old_container = $__current_container__
|
||||||
|
|
||||||
$__current_container__ = self
|
$__current_container__ = self
|
||||||
@@ -57,7 +57,12 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render
|
def render
|
||||||
Gosu.clip_to(@x, @y, width, height) do
|
Gosu.clip_to(
|
||||||
|
@x + @style.border_thickness_left + @style.padding_left,
|
||||||
|
@y + @style.border_thickness_top + @style.padding_top,
|
||||||
|
content_width + 1,
|
||||||
|
content_height + 1
|
||||||
|
) do
|
||||||
@children.each(&:draw)
|
@children.each(&:draw)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -103,6 +108,8 @@ module CyberarmEngine
|
|||||||
|
|
||||||
stylize
|
stylize
|
||||||
|
|
||||||
|
# s = Gosu.milliseconds
|
||||||
|
|
||||||
layout
|
layout
|
||||||
|
|
||||||
if is_root?
|
if is_root?
|
||||||
@@ -129,8 +136,13 @@ module CyberarmEngine
|
|||||||
child.reposition # TODO: Implement top,bottom,left,center, and right positioning
|
child.reposition # TODO: Implement top,bottom,left,center, and right positioning
|
||||||
|
|
||||||
Stats.increment(:gui_recalculations_last_frame, 1)
|
Stats.increment(:gui_recalculations_last_frame, 1)
|
||||||
|
|
||||||
|
child.element_visible = child.x >= @x - child.width && child.x <= @x + width &&
|
||||||
|
child.y >= @y - child.height && child.y <= @y + height
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# puts "TOOK: #{Gosu.milliseconds - s}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}"
|
||||||
|
|
||||||
update_background
|
update_background
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -194,9 +206,8 @@ module CyberarmEngine
|
|||||||
if @scroll_position.y < 0
|
if @scroll_position.y < 0
|
||||||
@scroll_position.y += @scroll_speed
|
@scroll_position.y += @scroll_speed
|
||||||
@scroll_position.y = 0 if @scroll_position.y > 0
|
@scroll_position.y = 0 if @scroll_position.y > 0
|
||||||
# recalculate
|
|
||||||
root.gui_state.request_recalculate_for(self)
|
|
||||||
|
|
||||||
|
root.gui_state.request_recalculate_for(self)
|
||||||
|
|
||||||
return :handled
|
return :handled
|
||||||
end
|
end
|
||||||
@@ -210,9 +221,8 @@ module CyberarmEngine
|
|||||||
if @scroll_position.y.abs < max_scroll_height
|
if @scroll_position.y.abs < max_scroll_height
|
||||||
@scroll_position.y -= @scroll_speed
|
@scroll_position.y -= @scroll_speed
|
||||||
@scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
|
@scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
|
||||||
# recalculate
|
|
||||||
root.gui_state.request_recalculate_for(self)
|
|
||||||
|
|
||||||
|
root.gui_state.request_recalculate_for(self)
|
||||||
|
|
||||||
return :handled
|
return :handled
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -142,9 +142,12 @@ module CyberarmEngine
|
|||||||
|
|
||||||
old_width = width
|
old_width = width
|
||||||
old_height = height
|
old_height = height
|
||||||
recalculate
|
|
||||||
|
|
||||||
root.gui_state.request_recalculate if old_width != width || old_height != height
|
if old_width != width || old_height != height
|
||||||
|
root.gui_state.request_recalculate
|
||||||
|
else
|
||||||
|
recalculate
|
||||||
|
end
|
||||||
|
|
||||||
publish(:changed, self.value)
|
publish(:changed, self.value)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -75,10 +75,10 @@ module CyberarmEngine
|
|||||||
@root_container.recalculate
|
@root_container.recalculate
|
||||||
|
|
||||||
@pending_recalculate_request = false
|
@pending_recalculate_request = false
|
||||||
@pending_element_recalculate_requests.clear # GUI has already been recalculated
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@pending_element_recalculate_requests.each(&:recalculate)
|
@pending_element_recalculate_requests.each(&:recalculate)
|
||||||
|
@pending_element_recalculate_requests.clear
|
||||||
|
|
||||||
if @pending_focus_request
|
if @pending_focus_request
|
||||||
@pending_focus_request = false
|
@pending_focus_request = false
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
NAME = "InDev".freeze
|
NAME = "InDev".freeze
|
||||||
VERSION = "0.19.1".freeze
|
VERSION = "0.20.0".freeze
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user