mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-05-06 07:58:15 +00:00
Compare commits
6 Commits
512d8a5c0f
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e7c6f8a19 | |||
| cd5bd51a02 | |||
| adf517f374 | |||
| 1c868522b7 | |||
| a79b9cc20e | |||
| c229329542 |
@@ -10,6 +10,7 @@ require "json"
|
||||
require_relative "cyberarm_engine/version"
|
||||
require_relative "cyberarm_engine/stats"
|
||||
require_relative "cyberarm_engine/result"
|
||||
require_relative "cyberarm_engine/event_bus"
|
||||
|
||||
require_relative "cyberarm_engine/common"
|
||||
|
||||
@@ -58,6 +59,7 @@ require_relative "cyberarm_engine/ui/elements/image"
|
||||
require_relative "cyberarm_engine/ui/elements/container"
|
||||
require_relative "cyberarm_engine/ui/elements/flow"
|
||||
require_relative "cyberarm_engine/ui/elements/stack"
|
||||
require_relative "cyberarm_engine/ui/elements/widget"
|
||||
require_relative "cyberarm_engine/ui/elements/check_box"
|
||||
require_relative "cyberarm_engine/ui/elements/radio"
|
||||
require_relative "cyberarm_engine/ui/elements/progress"
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
module CyberarmEngine
|
||||
class BackgroundNineSlice
|
||||
include CyberarmEngine::Common
|
||||
|
||||
CACHE = {}
|
||||
|
||||
attr_accessor :x, :y, :z, :width, :height, :mode, :color
|
||||
attr_reader :image, :left, :top, :right, :bottom
|
||||
|
||||
|
||||
39
lib/cyberarm_engine/event_bus.rb
Normal file
39
lib/cyberarm_engine/event_bus.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
module CyberarmEngine
|
||||
class EventBus
|
||||
Subscriber = Data.define(:event, :listener, :method, :callback)
|
||||
@subscribers = []
|
||||
|
||||
def self.subscribe(event, listener = nil, method = nil, &block)
|
||||
raise "Subscriber cannot have both a method AND a callback block" if method && block_given?
|
||||
|
||||
subscriber = Subscriber.new(event, listener, method, block)
|
||||
@subscribers << subscriber
|
||||
|
||||
subscriber
|
||||
end
|
||||
|
||||
def self.unsubscribe(event, listener_or_subscriber)
|
||||
@subscribers.delete_if { |s| s.event == event && (s == listener_or_subscriber || s.listener == listener_or_subscriber) }
|
||||
end
|
||||
|
||||
def self.unsubscribe!(event)
|
||||
@subscribers.delete_if { |s| s.event == event }
|
||||
end
|
||||
|
||||
def self.announce(event, *payload)
|
||||
subscribers = @subscribers.select { |s| s.event == event }
|
||||
|
||||
subscribers.each do |subscriber|
|
||||
subscriber&.listener&.send(subscriber.method, *payload) if subscriber&.method
|
||||
subscriber.callback&.call(*payload)
|
||||
rescue StandardError => e
|
||||
# TODO
|
||||
warn "Failed to deliver event (#{event}) to listener (#{subscriber.inspect}): #{e}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.publish(*args)
|
||||
announce(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -9,7 +9,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def okay?
|
||||
!@error
|
||||
!error?
|
||||
end
|
||||
|
||||
def error?
|
||||
@@ -17,4 +17,3 @@ module CyberarmEngine
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ module CyberarmEngine
|
||||
@color = Gosu::Color::WHITE
|
||||
end
|
||||
@mode = options[:mode] || :default
|
||||
@alignment = options[:alignment] || nil
|
||||
@alignment = options[:alignment] || :left
|
||||
|
||||
@border = options[:border]
|
||||
@border = true if options[:border].nil?
|
||||
@@ -39,17 +39,6 @@ module CyberarmEngine
|
||||
@static = options[:static] || (options[:static].nil? || options[:static] == false ? false : true)
|
||||
|
||||
@textobject = check_cache(@size, @font)
|
||||
|
||||
if @alignment
|
||||
case @alignment
|
||||
when :left
|
||||
@x = 0 + BUTTON_PADDING
|
||||
when :center
|
||||
@x = (CyberarmEngine::Window.instance.width / 2) - (@textobject.text_width(@text) / 2)
|
||||
when :right
|
||||
@x = CyberarmEngine::Window.instance.width - BUTTON_PADDING - @textobject.text_width(@text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_cache(size, font_name)
|
||||
@@ -113,6 +102,38 @@ module CyberarmEngine
|
||||
invalidate_cache! if old_color != color
|
||||
end
|
||||
|
||||
def alignment=(value)
|
||||
invalidate_cache! if @alignment != value
|
||||
@alignment = value
|
||||
end
|
||||
|
||||
def shadow=(value)
|
||||
invalidate_cache! if @shadow != value
|
||||
@shadow = value
|
||||
end
|
||||
|
||||
def shadow_color=(color)
|
||||
old_color = @shadow_color
|
||||
|
||||
if color
|
||||
@shadow_color = color.is_a?(Gosu::Color) ? color : Gosu::Color.new(color)
|
||||
else
|
||||
raise "color cannot be nil"
|
||||
end
|
||||
|
||||
invalidate_cache! if old_color != color
|
||||
end
|
||||
|
||||
def shadow_alpha=(value)
|
||||
invalidate_cache! if @shadow_alpha != value
|
||||
@shadow_alpha = value
|
||||
end
|
||||
|
||||
def shadow_size=(value)
|
||||
invalidate_cache! if @shadow_size != value
|
||||
@shadow_size = value
|
||||
end
|
||||
|
||||
def border=(boolean)
|
||||
invalidate_cache! if @border != boolean
|
||||
@border = boolean
|
||||
@@ -129,8 +150,15 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def border_color=(n)
|
||||
invalidate_cache! if @border_color != n
|
||||
@border_color = n
|
||||
old_color = @border_color
|
||||
|
||||
if color
|
||||
@border_color = color.is_a?(Gosu::Color) ? color : Gosu::Color.new(color)
|
||||
else
|
||||
raise "color cannot be nil"
|
||||
end
|
||||
|
||||
invalidate_cache! if old_color != color
|
||||
end
|
||||
|
||||
def width(text = @text)
|
||||
@@ -194,9 +222,9 @@ module CyberarmEngine
|
||||
end
|
||||
end
|
||||
|
||||
@cached_text_shadow_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font) if @shadow
|
||||
@cached_text_shadow_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font, align: @alignment) if @shadow
|
||||
|
||||
@gosu_cached_text_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font)
|
||||
@gosu_cached_text_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font, align: @alignment)
|
||||
|
||||
@cached_text_border_image.draw(@x, @y, @z, @factor_x, @factor_y, @border_color, @mode) if @border
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ module CyberarmEngine
|
||||
container(CyberarmEngine::Element::Stack, options, &block)
|
||||
end
|
||||
|
||||
def widget(options = {}, &block)
|
||||
container(CyberarmEngine::Element::Widget, options, &block)
|
||||
end
|
||||
|
||||
def menu(options = {}, &block)
|
||||
container(CyberarmEngine::Element::Menu, options, &block)
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ module CyberarmEngine
|
||||
@visible = !@options.key?(:visible) ? true : @options[:visible]
|
||||
@tip = @options[:tip] || ""
|
||||
|
||||
@debug = @options[:debug] || false
|
||||
@debug = @options[:debug] || CyberarmEngine.const_defined?("GUI_DEBUG") && CyberarmEngine::GUI_DEBUG || false
|
||||
@debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color]
|
||||
|
||||
@style = Style.new(options)
|
||||
@@ -44,7 +44,7 @@ module CyberarmEngine
|
||||
@background_image_canvas = nil # BackgroundImage.new
|
||||
@border_canvas = nil # BorderCanvas.new(element: self)
|
||||
|
||||
@style_event = :default
|
||||
@style_event = enabled? ? :default : :disabled
|
||||
|
||||
stylize
|
||||
|
||||
@@ -53,7 +53,15 @@ module CyberarmEngine
|
||||
root.gui_state.request_focus(self) if @options[:autofocus]
|
||||
end
|
||||
|
||||
def resolution_scaled(n)
|
||||
return n unless @style.design_width
|
||||
|
||||
((@style.design_width / Gosu.screen_width(window).to_f) * n).floor
|
||||
end
|
||||
|
||||
def stylize
|
||||
@style_event = :disabled unless enabled?
|
||||
|
||||
set_static_position
|
||||
|
||||
set_color
|
||||
@@ -73,11 +81,11 @@ module CyberarmEngine
|
||||
when :border_color_bottom, :border_color_left, :border_color_right, :border_color_top
|
||||
safe_style_fetch(key, :border_color)
|
||||
when :border_thickness_bottom, :border_thickness_left, :border_thickness_right, :border_thickness_top
|
||||
safe_style_fetch(key, :border_thickness)
|
||||
visible? ? safe_style_fetch(key, :border_thickness) : 0
|
||||
when :margin_bottom, :margin_left, :margin_right, :margin_top
|
||||
safe_style_fetch(key, :margin)
|
||||
visible? ? safe_style_fetch(key, :margin) : 0
|
||||
when :padding_bottom, :padding_left, :padding_right, :padding_top
|
||||
safe_style_fetch(key, :padding)
|
||||
visible? ? safe_style_fetch(key, :padding) : 0
|
||||
else
|
||||
safe_style_fetch(key)
|
||||
end
|
||||
@@ -108,7 +116,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def set_font
|
||||
@text&.swap_font(safe_style_fetch(:text_size), safe_style_fetch(:font))
|
||||
@text&.swap_font(resolution_scaled(safe_style_fetch(:text_size)), safe_style_fetch(:font))
|
||||
end
|
||||
|
||||
def set_background
|
||||
@@ -214,7 +222,7 @@ module CyberarmEngine
|
||||
|
||||
if !@enabled
|
||||
update_styles(:disabled)
|
||||
elsif @focus
|
||||
elsif @focus && !@style.active.empty?
|
||||
update_styles(:active)
|
||||
else
|
||||
update_styles(:hover)
|
||||
@@ -229,7 +237,7 @@ module CyberarmEngine
|
||||
unless @enabled
|
||||
update_styles(:disabled)
|
||||
else
|
||||
update_styles(:active)
|
||||
update_styles(:active) unless @style.active.empty?
|
||||
end
|
||||
|
||||
window.current_state.focus = self
|
||||
@@ -275,6 +283,7 @@ module CyberarmEngine
|
||||
root.gui_state.request_repaint if @enabled != boolean
|
||||
|
||||
@enabled = boolean
|
||||
@style_event = :default if boolean && @style_event == :disabled
|
||||
|
||||
recalculate
|
||||
|
||||
|
||||
@@ -35,13 +35,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def layout
|
||||
unless @enabled
|
||||
@background_canvas.background = @style.disabled.background
|
||||
@text.color = @style.disabled.color
|
||||
else
|
||||
@background_canvas.background = styled(:background)
|
||||
@text.color = styled(:color)
|
||||
end
|
||||
|
||||
if @image
|
||||
@width = 0
|
||||
@@ -78,6 +73,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def value=(value)
|
||||
old_value = self.value
|
||||
|
||||
if value.is_a?(Gosu::Image)
|
||||
@image = value
|
||||
else
|
||||
@@ -93,7 +90,9 @@ module CyberarmEngine
|
||||
recalculate
|
||||
end
|
||||
|
||||
publish(:changed, self.value)
|
||||
publish(:changed, self.value) if value != old_value
|
||||
|
||||
self.value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,8 +46,12 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def value=(bool)
|
||||
old_value = this.value
|
||||
|
||||
@toggle_button.value = bool
|
||||
publish(:changed, @toggle_button.value)
|
||||
publish(:changed, bool) if bool != old_value
|
||||
|
||||
bool
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -106,9 +106,12 @@ module CyberarmEngine
|
||||
@children.each(&:update)
|
||||
end
|
||||
|
||||
def hit_element?(x, y)
|
||||
# return nil if element was not hit, or array of hit elements if hit, includes self.
|
||||
def hit_element?(x, y, elements = [])
|
||||
return unless hit?(x, y)
|
||||
|
||||
elements << self
|
||||
|
||||
# Offset child hit point by scroll position/offset
|
||||
child_x = x - @scroll_position.x
|
||||
child_y = y - @scroll_position.y
|
||||
@@ -118,15 +121,18 @@ module CyberarmEngine
|
||||
|
||||
case child
|
||||
when Container
|
||||
if (element = child.hit_element?(child_x, child_y))
|
||||
return element
|
||||
if (child.hit_element?(child_x, child_y, elements))
|
||||
return elements
|
||||
end
|
||||
else
|
||||
return child if child.hit?(child_x, child_y)
|
||||
if child.hit?(child_x, child_y)
|
||||
elements << child
|
||||
return elements
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self if hit?(x, y)
|
||||
elements
|
||||
end
|
||||
|
||||
def update_child_element_visibity(child)
|
||||
|
||||
@@ -45,19 +45,23 @@ module CyberarmEngine
|
||||
|
||||
def draw_selection
|
||||
selection_width = caret_position - selection_start_position
|
||||
selection_start_line = calculate_line(@text_input.caret_pos)
|
||||
selection_end_line = calculate_line(@text_input.selection_start)
|
||||
|
||||
Gosu.draw_rect(selection_start_position, @text.y, selection_width, @text.textobject.height,
|
||||
# pp [selection_width, selection_start_line, selection_end_line]
|
||||
|
||||
Gosu.draw_rect(selection_start_position, @text.y + selection_start_line * @text.textobject.height, selection_width, @text.textobject.height,
|
||||
default(:selection_color), @z)
|
||||
end
|
||||
|
||||
def text_input_position_for(_method)
|
||||
line = @text_input.text[0...@text_input.caret_pos].lines.last
|
||||
def text_input_position_for(method)
|
||||
line = @text_input.text[0...@text_input.send(method)].lines.last
|
||||
_x = @text.x + @offset_x
|
||||
|
||||
if @type == :password
|
||||
_x + @text.width(default(:password_character) * line.length)
|
||||
_x + @text.width(default(:password_character) * line.length) - @style.border_thickness_left
|
||||
else
|
||||
_x + @text.width(line)
|
||||
_x + @text.width(line) - @style.border_thickness_left
|
||||
end
|
||||
end
|
||||
|
||||
@@ -66,9 +70,12 @@ module CyberarmEngine
|
||||
@text_input.selection_start = @text_input.caret_pos = int
|
||||
end
|
||||
|
||||
def calculate_line(caret_pos = @text_input.caret_pos)
|
||||
sub_text = @text_input.text[0...caret_pos].lines.size - 1
|
||||
end
|
||||
|
||||
def calculate_active_line
|
||||
sub_text = @text_input.text[0...@text_input.caret_pos]
|
||||
@active_line = sub_text.lines.size - 1
|
||||
@active_line = calculate_line(@text_input.caret_pos)
|
||||
end
|
||||
|
||||
def caret_stay_left_of_last_newline
|
||||
@@ -92,7 +99,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
active_line = row_at(mouse_y - y_scroll_offset)
|
||||
right_offset = column_at(mouse_x, mouse_y)
|
||||
right_offset = column_at(mouse_x, mouse_y - y_scroll_offset)
|
||||
|
||||
buffer = @text_input.text.lines[0..active_line].join if active_line != 0
|
||||
buffer = @text_input.text.lines.first if active_line == 0
|
||||
@@ -176,6 +183,8 @@ module CyberarmEngine
|
||||
pos = text.length
|
||||
end
|
||||
|
||||
pp [direction, pos, @active_line]
|
||||
|
||||
set_position(pos)
|
||||
end
|
||||
|
||||
|
||||
@@ -291,6 +291,8 @@ module CyberarmEngine
|
||||
|
||||
def value=(string)
|
||||
@text_input.text = string
|
||||
|
||||
string
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,12 +56,18 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def value=(path_or_image, retro: false, tileable: false)
|
||||
old_value = self.value
|
||||
|
||||
@path = path_or_image if path_or_image.is_a?(String)
|
||||
|
||||
@image = Gosu::Image.new(path_or_image, retro: retro, tileable: tileable) if @path
|
||||
@image = path_or_image unless @path
|
||||
|
||||
recalculate
|
||||
|
||||
publish(:changed, @image) if old_value != self.value
|
||||
|
||||
self.value
|
||||
end
|
||||
|
||||
def path
|
||||
|
||||
@@ -83,9 +83,11 @@ module CyberarmEngine
|
||||
@fraction = decimal.clamp(0.0, 1.0)
|
||||
update_background
|
||||
|
||||
root.gui_state.request_repaint if @fraction != old_value
|
||||
|
||||
if @fraction != old_value
|
||||
root.gui_state.request_repaint
|
||||
publish(:changed, @fraction)
|
||||
end
|
||||
|
||||
@fraction
|
||||
end
|
||||
end
|
||||
|
||||
@@ -94,13 +94,17 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def value=(n)
|
||||
old_value = this.value
|
||||
|
||||
@value = n
|
||||
position_handle
|
||||
@handle.recalculate
|
||||
|
||||
root.gui_state.request_repaint
|
||||
|
||||
publish(:changed, @value)
|
||||
publish(:changed, @value) if old_value != n
|
||||
|
||||
n
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,6 +8,7 @@ module CyberarmEngine
|
||||
text, font: @options[:font], z: @z, color: @options[:color],
|
||||
size: @options[:text_size], shadow: @options[:text_shadow],
|
||||
static: @options[:text_static],
|
||||
alignment: @options[:text_align],
|
||||
shadow_size: @options[:text_shadow_size],
|
||||
shadow_color: @options[:text_shadow_color],
|
||||
border: @options[:text_border],
|
||||
@@ -41,11 +42,18 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def layout
|
||||
unless @enabled
|
||||
@text.color = @style.disabled.color
|
||||
else
|
||||
@text.color = styled(:color)
|
||||
end
|
||||
@text.alignment = styled(:text_align)
|
||||
|
||||
@text.shadow = styled(:text_shadow)
|
||||
@text.shadow_color = styled(:text_shadow_color)
|
||||
@text.shadow_alpha = styled(:text_shadow_alpha)
|
||||
@text.shadow_size = styled(:text_shadow_size)
|
||||
|
||||
@text.border = styled(:text_border)
|
||||
@text.border_color = styled(:text_border_color)
|
||||
@text.border_alpha = styled(:text_border_alpha)
|
||||
@text.border_size = styled(:text_border_size)
|
||||
|
||||
@width = 0
|
||||
@height = 0
|
||||
@@ -186,9 +194,12 @@ module CyberarmEngine
|
||||
recalculate
|
||||
end
|
||||
|
||||
root.gui_state.request_repaint if old_value != @raw_text
|
||||
if old_value != @raw_text
|
||||
root.gui_state.request_repaint
|
||||
publish(:changed, @raw_text)
|
||||
end
|
||||
|
||||
publish(:changed, self.value)
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
@@ -214,6 +225,9 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
class ToolTip < TextBlock
|
||||
def needs_repaint?
|
||||
@needs_repaint || !value.to_s.empty?
|
||||
end
|
||||
end
|
||||
|
||||
class Link < TextBlock
|
||||
|
||||
@@ -50,6 +50,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def value=(boolean)
|
||||
old_value = self.value
|
||||
|
||||
@value = boolean
|
||||
|
||||
if boolean
|
||||
@@ -60,7 +62,9 @@ module CyberarmEngine
|
||||
|
||||
recalculate
|
||||
|
||||
publish(:changed, @value)
|
||||
publish(:changed, @value) if old_value != boolean
|
||||
|
||||
boolean
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
36
lib/cyberarm_engine/ui/elements/widget.rb
Normal file
36
lib/cyberarm_engine/ui/elements/widget.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
module CyberarmEngine
|
||||
class Element
|
||||
# Special container that has a layout like a Flow
|
||||
# and makes all its children mirror its styling (i.e. hover, active, disabled...)
|
||||
class Widget < Flow
|
||||
def update_styles(style = :default)
|
||||
super
|
||||
|
||||
@children.each do |child|
|
||||
recursive_styles(style, self)
|
||||
end
|
||||
end
|
||||
|
||||
# Make child elements mirror the widgets styling
|
||||
# disabled elements will not have their styling overridden
|
||||
def recursive_styles(style, container)
|
||||
container.children.each do |child|
|
||||
child.update_styles(style)
|
||||
|
||||
recursive_styles(style, child) if child.is_a?(Container)
|
||||
end
|
||||
end
|
||||
|
||||
# Enable child elements to display their tooltips
|
||||
# but fall back to the Widget if no hit element has a tip
|
||||
def tip
|
||||
elements = hit_element?(window.mouse_x, window.mouse_y)
|
||||
|
||||
return @tip unless elements
|
||||
|
||||
elements.delete(self) # prevent infinite recursive loop (Widget#tip)
|
||||
elements.reverse.find { |e| !e.tip.empty? }&.tip || @tip
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -13,7 +13,7 @@ module CyberarmEngine
|
||||
def publish(event, *args)
|
||||
raise ArgumentError, "#{self.class} does not handle #{event.inspect}" unless @event_handler.include?(event)
|
||||
|
||||
return unless enabled?
|
||||
return if !enabled? && event != :changed
|
||||
|
||||
was_handled = false
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ module CyberarmEngine
|
||||
@dragging_element = nil
|
||||
@pending_recalculate_request = false
|
||||
@pending_element_recalculate_requests = []
|
||||
@hit_elements = []
|
||||
|
||||
@needs_repaint = false
|
||||
|
||||
@@ -81,6 +82,7 @@ module CyberarmEngine
|
||||
# Does NOT throw :focus event at element or set element as focused
|
||||
def focus=(element)
|
||||
@focus.publish(:blur) if @focus && element && @focus != element
|
||||
@hit_elements.delete(@focus)
|
||||
@focus = element
|
||||
end
|
||||
|
||||
@@ -163,22 +165,37 @@ module CyberarmEngine
|
||||
return unless window.has_focus?
|
||||
return unless window.current_state == self
|
||||
|
||||
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)
|
||||
# list of containers decending down to hit element
|
||||
new_hit_elements = (@menu || @root_container).hit_element?(window.mouse_x, window.mouse_y)
|
||||
# element the mouse is over, if any.
|
||||
new_mouse_over = new_hit_elements&.find { |c| c.is_a?(CyberarmEngine::Element::Widget) } || new_hit_elements&.last
|
||||
|
||||
if new_mouse_over
|
||||
new_mouse_over.publish(:enter) if new_mouse_over != @mouse_over
|
||||
new_mouse_over.publish(:hover)
|
||||
# puts "#{new_mouse_over.class}[#{new_mouse_over.value}]: #{new_mouse_over.x}:#{new_mouse_over.y} #{new_mouse_over.width}:#{new_mouse_over.height}" if new_mouse_over != @mouse_over
|
||||
# is the currently hit element the same as last hit element?
|
||||
same_element = @mouse_over && new_mouse_over == @mouse_over
|
||||
|
||||
unless @hit_elements == new_hit_elements
|
||||
added_hit_elements = (new_hit_elements || []) - @hit_elements
|
||||
removed_hit_elements = @hit_elements - (new_hit_elements || [])
|
||||
|
||||
added_hit_elements.each do |e|
|
||||
e.publish(:enter)
|
||||
e.publish(:hover)
|
||||
end
|
||||
@mouse_over.publish(:leave) if @mouse_over && new_mouse_over != @mouse_over
|
||||
|
||||
removed_hit_elements.each do |e|
|
||||
e.publish(:leave)
|
||||
end
|
||||
end
|
||||
|
||||
@mouse_over = new_mouse_over
|
||||
@hit_elements = new_hit_elements || []
|
||||
|
||||
redirect_holding_mouse_button(:left) if @mouse_over && Gosu.button_down?(Gosu::MS_LEFT)
|
||||
redirect_holding_mouse_button(:middle) if @mouse_over && Gosu.button_down?(Gosu::MS_MIDDLE)
|
||||
redirect_holding_mouse_button(:right) if @mouse_over && Gosu.button_down?(Gosu::MS_RIGHT)
|
||||
|
||||
if Vector.new(window.mouse_x, window.mouse_y) == @last_mouse_pos
|
||||
# handle tooltip
|
||||
if same_element
|
||||
if @mouse_over && (Gosu.milliseconds - @mouse_moved_at) > tool_tip_delay
|
||||
@tip.value = @mouse_over.tip if @mouse_over
|
||||
@tip.x = window.mouse_x
|
||||
@@ -261,6 +278,7 @@ module CyberarmEngine
|
||||
hide_menu unless @menu && (@menu == @mouse_over) || (@mouse_over&.parent == @menu)
|
||||
|
||||
if @focus && @mouse_over != @focus
|
||||
@hit_elements.delete(@focus)
|
||||
@focus.publish(:blur)
|
||||
@focus = nil
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
%i[
|
||||
x y z width height min_width min_height max_width max_height color background
|
||||
x y z design_width width height min_width min_height max_width max_height color background
|
||||
background_image background_image_mode background_image_color
|
||||
background_nine_slice background_nine_slice_mode background_nine_slice_color background_nine_slice_from_edge
|
||||
background_nine_slice_left background_nine_slice_top background_nine_slice_right background_nine_slice_bottom
|
||||
@@ -33,7 +33,10 @@ module CyberarmEngine
|
||||
margin margin_left margin_right margin_top margin_bottom
|
||||
aspect_ratio
|
||||
|
||||
fraction_background scroll fill text_wrap v_align h_align delay tag font text_size
|
||||
fraction_background scroll fill text_wrap v_align h_align delay tag font
|
||||
text_align text_static text_size
|
||||
text_shadow text_shadow_size text_shadow_alpha text_shadow_color
|
||||
text_border text_border_size text_border_alpha text_border_color
|
||||
image_width image_height
|
||||
].each do |item|
|
||||
define_method(item) do
|
||||
@@ -58,6 +61,10 @@ module CyberarmEngine
|
||||
def mark_clean!
|
||||
@dirty = false
|
||||
end
|
||||
|
||||
def empty?
|
||||
@hash.empty?
|
||||
end
|
||||
end
|
||||
|
||||
class Style < StyleData
|
||||
|
||||
@@ -30,6 +30,11 @@ module CyberarmEngine
|
||||
end
|
||||
end
|
||||
|
||||
# css-like style classes, however First In, First Out- that is,
|
||||
options[:style_class]&.each do |klass|
|
||||
hash = deep_merge(hash, _theme[klass]) if _theme[klass]
|
||||
end
|
||||
|
||||
deep_merge(hash, options)
|
||||
end
|
||||
|
||||
@@ -53,6 +58,7 @@ module CyberarmEngine
|
||||
y: 0,
|
||||
z: 30,
|
||||
|
||||
design_width: nil,
|
||||
width: nil,
|
||||
height: nil,
|
||||
color: Gosu::Color::WHITE,
|
||||
@@ -68,7 +74,7 @@ module CyberarmEngine
|
||||
debug_color: Gosu::Color::YELLOW
|
||||
},
|
||||
|
||||
Button: { # < Label
|
||||
Button: { # < TextBlock
|
||||
margin: 1,
|
||||
padding: 4,
|
||||
border_thickness: 1,
|
||||
@@ -121,7 +127,13 @@ module CyberarmEngine
|
||||
text_size: 28,
|
||||
text_wrap: :word_wrap, # :word_wrap, :break_word, :none
|
||||
text_shadow: false,
|
||||
text_shadow_color: 0,
|
||||
text_shadow_alpha: 30,
|
||||
text_shadow_size: 2,
|
||||
text_border: false,
|
||||
text_border_color: 0,
|
||||
text_border_alpha: 30,
|
||||
text_border_size: 2,
|
||||
text_align: :left,
|
||||
font: "Arial",
|
||||
margin: 0,
|
||||
|
||||
Reference in New Issue
Block a user