mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 21:22:33 +00:00
Compare commits
10 Commits
63a51d9d2f
...
v0.20.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 24bd769a32 | |||
| 2be5733bc1 | |||
| c8734ae98b | |||
| c35d587419 | |||
| 153871e7f3 | |||
| cf91d4a083 | |||
| 35ad687d4c | |||
| 54802e1254 | |||
| 6cf4cd73dd | |||
| 5e5f8ba7ea |
@@ -4,7 +4,7 @@ module CyberarmEngine
|
||||
include Event
|
||||
include Common
|
||||
|
||||
attr_accessor :x, :y, :z, :enabled, :tip
|
||||
attr_accessor :x, :y, :z, :tip, :element_visible
|
||||
attr_reader :parent, :options, :style, :event_handler, :background_canvas, :border_canvas
|
||||
|
||||
def initialize(options = {}, block = nil)
|
||||
@@ -13,9 +13,9 @@ module CyberarmEngine
|
||||
@options = options
|
||||
@block = block
|
||||
|
||||
@focus = @options[:focus].nil? ? false : @options[:focus]
|
||||
@enabled = @options[:enabled].nil? ? true : @options[:enabled]
|
||||
@visible = @options[:visible].nil? ? true : @options[:visible]
|
||||
@focus = !@options.key?(:focus) ? false : @options[:focus]
|
||||
@enabled = !@options.key?(:enabled) ? true : @options[:enabled]
|
||||
@visible = !@options.key?(:visible) ? true : @options[:visible]
|
||||
@tip = @options[:tip] || ""
|
||||
|
||||
@debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color]
|
||||
@@ -24,6 +24,7 @@ module CyberarmEngine
|
||||
|
||||
@root ||= nil
|
||||
@gui_state ||= nil
|
||||
@element_visible = true
|
||||
|
||||
@x = @style.x
|
||||
@y = @style.y
|
||||
@@ -51,6 +52,9 @@ module CyberarmEngine
|
||||
def stylize
|
||||
set_static_position
|
||||
|
||||
set_color
|
||||
set_font
|
||||
|
||||
set_padding
|
||||
set_margin
|
||||
|
||||
@@ -70,6 +74,15 @@ module CyberarmEngine
|
||||
@y = @style.y if @style.y != 0
|
||||
end
|
||||
|
||||
def set_color
|
||||
@style.color = safe_style_fetch(:color)
|
||||
@text&.color = @style.color
|
||||
end
|
||||
|
||||
def set_font
|
||||
@text&.swap_font(safe_style_fetch(:text_size), safe_style_fetch(:font))
|
||||
end
|
||||
|
||||
def set_background
|
||||
@style.background = safe_style_fetch(:background)
|
||||
|
||||
@@ -138,14 +151,8 @@ module CyberarmEngine
|
||||
old_width = width
|
||||
old_height = height
|
||||
|
||||
_style = @style.send(event)
|
||||
@style_event = event
|
||||
|
||||
if @text.is_a?(CyberarmEngine::Text)
|
||||
@text.color = _style&.dig(:color) || @style.default[:color]
|
||||
@text.swap_font(_style&.dig(:text_size) || @style.default[:text_size], _style&.dig(:font) || @style.default[:font])
|
||||
end
|
||||
|
||||
return if self.is_a?(ToolTip)
|
||||
|
||||
if old_width != width || old_height != height
|
||||
@@ -238,6 +245,14 @@ module CyberarmEngine
|
||||
:handled
|
||||
end
|
||||
|
||||
def enabled=(boolean)
|
||||
@enabled = boolean
|
||||
|
||||
recalculate
|
||||
|
||||
@enabled
|
||||
end
|
||||
|
||||
def enabled?
|
||||
@enabled
|
||||
end
|
||||
@@ -246,6 +261,10 @@ module CyberarmEngine
|
||||
@visible
|
||||
end
|
||||
|
||||
def element_visible?
|
||||
@element_visible
|
||||
end
|
||||
|
||||
def toggle
|
||||
@visible = !@visible
|
||||
root.gui_state.request_recalculate
|
||||
@@ -265,14 +284,13 @@ module CyberarmEngine
|
||||
|
||||
def draw
|
||||
return unless visible?
|
||||
return unless element_visible?
|
||||
|
||||
@style.background_canvas.draw
|
||||
@style.background_nine_slice_canvas.draw
|
||||
@style.border_canvas.draw
|
||||
|
||||
Gosu.clip_to(@x, @y, width, height) do
|
||||
render
|
||||
end
|
||||
render
|
||||
end
|
||||
|
||||
def debug_draw
|
||||
|
||||
@@ -86,9 +86,12 @@ module CyberarmEngine
|
||||
|
||||
old_width = width
|
||||
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)
|
||||
end
|
||||
|
||||
@@ -45,7 +45,7 @@ module CyberarmEngine
|
||||
root.gui_state.request_recalculate
|
||||
end
|
||||
|
||||
def apend(&block)
|
||||
def append(&block)
|
||||
old_container = $__current_container__
|
||||
|
||||
$__current_container__ = self
|
||||
@@ -57,7 +57,12 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
@@ -103,6 +108,8 @@ module CyberarmEngine
|
||||
|
||||
stylize
|
||||
|
||||
# s = Gosu.milliseconds
|
||||
|
||||
layout
|
||||
|
||||
if is_root?
|
||||
@@ -129,8 +136,13 @@ module CyberarmEngine
|
||||
child.reposition # TODO: Implement top,bottom,left,center, and right positioning
|
||||
|
||||
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
|
||||
|
||||
# puts "TOOK: #{Gosu.milliseconds - s}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}"
|
||||
|
||||
update_background
|
||||
end
|
||||
|
||||
@@ -194,9 +206,8 @@ module CyberarmEngine
|
||||
if @scroll_position.y < 0
|
||||
@scroll_position.y += @scroll_speed
|
||||
@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
|
||||
end
|
||||
@@ -210,9 +221,8 @@ module CyberarmEngine
|
||||
if @scroll_position.y.abs < max_scroll_height
|
||||
@scroll_position.y -= @scroll_speed
|
||||
@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
|
||||
end
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
module CyberarmEngine
|
||||
class Element
|
||||
class Progress < Element
|
||||
attr_reader :type
|
||||
|
||||
def initialize(options = {}, block = nil)
|
||||
super(options, block)
|
||||
|
||||
@animation_speed = options[:animation_speed] || 3_000
|
||||
@marquee_width = options[:marquee_width] || 0.25
|
||||
@marquee_offset = 0
|
||||
@marquee_animation_time = Gosu.milliseconds
|
||||
@type = options[:type] || :linear
|
||||
@fraction_background = Background.new(background: @style.fraction_background)
|
||||
self.value = options[:fraction] || 0.0
|
||||
end
|
||||
@@ -24,15 +31,45 @@ module CyberarmEngine
|
||||
def update_background
|
||||
super
|
||||
|
||||
@fraction_background.x = @style.border_thickness_left + @style.padding_left + @x
|
||||
@fraction_background.x = (@style.border_thickness_left + @style.padding_left + @x) + @marquee_offset
|
||||
@fraction_background.y = @style.border_thickness_top + @style.padding_top + @y
|
||||
@fraction_background.z = @z
|
||||
@fraction_background.width = @width * @fraction
|
||||
@fraction_background.width = @width * (@type == :marquee ? @marquee_width : @fraction)
|
||||
@fraction_background.height = @height
|
||||
|
||||
@fraction_background.background = @style.fraction_background
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
return unless @type == :marquee
|
||||
|
||||
marquee_width = @width * @marquee_width
|
||||
range = @width + marquee_width
|
||||
|
||||
@marquee_offset = (@width * (Gosu.milliseconds - @marquee_animation_time) / @animation_speed) - marquee_width
|
||||
@marquee_animation_time = Gosu.milliseconds if @marquee_offset > range
|
||||
|
||||
update_background
|
||||
end
|
||||
|
||||
def type=(type)
|
||||
@type = type
|
||||
|
||||
case type
|
||||
when :linear
|
||||
@marquee_offset = 0
|
||||
when :marquee
|
||||
@marquee_offset = 0
|
||||
@marquee_animation_time = Gosu.milliseconds
|
||||
else
|
||||
raise ArgumentError, "Only types :linear and :marquee are supported"
|
||||
end
|
||||
|
||||
update_background
|
||||
end
|
||||
|
||||
def value
|
||||
@fraction
|
||||
end
|
||||
|
||||
@@ -142,9 +142,12 @@ module CyberarmEngine
|
||||
|
||||
old_width = width
|
||||
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)
|
||||
end
|
||||
|
||||
@@ -75,10 +75,10 @@ module CyberarmEngine
|
||||
@root_container.recalculate
|
||||
|
||||
@pending_recalculate_request = false
|
||||
@pending_element_recalculate_requests.clear # GUI has already been recalculated
|
||||
end
|
||||
|
||||
@pending_element_recalculate_requests.each(&:recalculate)
|
||||
@pending_element_recalculate_requests.clear
|
||||
|
||||
if @pending_focus_request
|
||||
@pending_focus_request = false
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module CyberarmEngine
|
||||
NAME = "InDev".freeze
|
||||
VERSION = "0.19.1".freeze
|
||||
VERSION = "0.20.0".freeze
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user