mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 21:22:33 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 20970e5aa9 | |||
| 76eb1a85d5 | |||
| e9d75d17bf | |||
| e8bb2cac17 | |||
| 29fbac7140 | |||
| d050f63c2b | |||
| af24fc8690 |
@@ -29,11 +29,11 @@ Gem::Specification.new do |spec|
|
||||
|
||||
spec.add_dependency "clipboard", "~> 1.3.5"
|
||||
spec.add_dependency "excon", "~> 0.78.0"
|
||||
spec.add_dependency "gosu", "~> 1.0.0"
|
||||
spec.add_dependency "gosu", "~> 1.1"
|
||||
spec.add_dependency "gosu_more_drawables", "~> 0.3"
|
||||
# spec.add_dependency "ffi", :platforms => [:mswin, :mingw] # Required by Clipboard on Windows
|
||||
|
||||
spec.add_development_dependency "bundler", "~> 1.16"
|
||||
spec.add_development_dependency "bundler", "~> 2.2"
|
||||
spec.add_development_dependency "minitest", "~> 5.0"
|
||||
spec.add_development_dependency "rake", "~> 13.0"
|
||||
end
|
||||
|
||||
@@ -39,6 +39,8 @@ module CyberarmEngine
|
||||
stylize
|
||||
|
||||
default_events
|
||||
|
||||
root.gui_state.request_focus(self) if @options[:autofocus]
|
||||
end
|
||||
|
||||
def stylize
|
||||
@@ -116,6 +118,7 @@ module CyberarmEngine
|
||||
event(:hover)
|
||||
event(:leave)
|
||||
|
||||
event(:focus)
|
||||
event(:blur)
|
||||
|
||||
event(:changed)
|
||||
@@ -226,6 +229,22 @@ module CyberarmEngine
|
||||
(@style.border_thickness_top + @style.padding_top) + (@style.padding_bottom + @style.border_thickness_bottom)
|
||||
end
|
||||
|
||||
def scroll_width
|
||||
@children.sum { |c| c.width } + noncontent_width
|
||||
end
|
||||
|
||||
def scroll_height
|
||||
@children.sum { |c| c.height } + noncontent_height
|
||||
end
|
||||
|
||||
def max_scroll_width
|
||||
scroll_width - width
|
||||
end
|
||||
|
||||
def max_scroll_height
|
||||
scroll_height - height
|
||||
end
|
||||
|
||||
def dimensional_size(size, dimension)
|
||||
raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)
|
||||
|
||||
@@ -277,6 +296,12 @@ module CyberarmEngine
|
||||
@gui_state != nil
|
||||
end
|
||||
|
||||
def focus(_)
|
||||
warn "#{self.class}#focus was not overridden!"
|
||||
|
||||
:handled
|
||||
end
|
||||
|
||||
def recalculate
|
||||
raise "#{self.class}#recalculate was not overridden!"
|
||||
end
|
||||
@@ -295,5 +320,9 @@ module CyberarmEngine
|
||||
def to_s
|
||||
"#{self.class} x=#{x} y=#{y} width=#{width} height=#{height} value=#{value.is_a?(String) ? "\"#{value}\"" : value}"
|
||||
end
|
||||
|
||||
def inspect
|
||||
to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,19 +4,20 @@ module CyberarmEngine
|
||||
include Common
|
||||
|
||||
attr_accessor :stroke_color, :fill_color
|
||||
attr_reader :children, :gui_state, :scroll_x, :scroll_y
|
||||
attr_reader :children, :gui_state, :scroll_position
|
||||
|
||||
def initialize(options = {}, block = nil)
|
||||
@gui_state = options.delete(:gui_state)
|
||||
super
|
||||
|
||||
@scroll_x = 0
|
||||
@scroll_y = 0
|
||||
@scroll_speed = 10
|
||||
@scroll_position = Vector.new(0, 0)
|
||||
@scroll_speed = 40
|
||||
|
||||
@text_color = options[:color]
|
||||
|
||||
@children = []
|
||||
|
||||
event(:window_size_changed)
|
||||
end
|
||||
|
||||
def build
|
||||
@@ -44,6 +45,17 @@ module CyberarmEngine
|
||||
root.gui_state.request_recalculate
|
||||
end
|
||||
|
||||
def apend(&block)
|
||||
old_container = $__current_container__
|
||||
|
||||
$__current_container__ = self
|
||||
block.call(self) if block
|
||||
|
||||
$__current_container__ = old_container
|
||||
|
||||
root.gui_state.request_recalculate
|
||||
end
|
||||
|
||||
def render
|
||||
Gosu.clip_to(@x, @y, width, height) do
|
||||
@children.each(&:draw)
|
||||
@@ -98,6 +110,8 @@ module CyberarmEngine
|
||||
|
||||
def recalculate
|
||||
@current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
|
||||
@current_position += @scroll_position
|
||||
|
||||
return unless visible?
|
||||
|
||||
Stats.increment(:gui_recalculations_last_frame, 1)
|
||||
@@ -189,15 +203,31 @@ module CyberarmEngine
|
||||
@current_position.y += element.outer_height
|
||||
end
|
||||
|
||||
# def mouse_wheel_up(sender, x, y)
|
||||
# @children.each {|c| c.y -= @scroll_speed}
|
||||
# @children.each {|c| c.recalculate}
|
||||
# end
|
||||
def mouse_wheel_up(sender, x, y)
|
||||
return unless @style.scroll
|
||||
return if height < max_scroll_height
|
||||
|
||||
# def mouse_wheel_down(sender, x, y)
|
||||
# @children.each {|c| c.y += @scroll_speed}
|
||||
# @children.each {|c| c.recalculate}
|
||||
# end
|
||||
if @scroll_position.y < 0
|
||||
@scroll_position.y += @scroll_speed
|
||||
@scroll_position.y = 0 if @scroll_position.y > 0
|
||||
recalculate
|
||||
|
||||
return :handled
|
||||
end
|
||||
end
|
||||
|
||||
def mouse_wheel_down(sender, x, y)
|
||||
return unless @style.scroll
|
||||
return if height < max_scroll_height
|
||||
|
||||
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
|
||||
|
||||
return :handled
|
||||
end
|
||||
end
|
||||
|
||||
def value
|
||||
@children.map { |c| c.class }.join(", ")
|
||||
|
||||
@@ -67,6 +67,8 @@ module CyberarmEngine
|
||||
|
||||
if @last_text_value != value
|
||||
@last_text_value = value
|
||||
@show_caret = true
|
||||
@caret_last_interval = Gosu.milliseconds
|
||||
|
||||
publish(:changed, value)
|
||||
end
|
||||
@@ -210,6 +212,16 @@ module CyberarmEngine
|
||||
:handled
|
||||
end
|
||||
|
||||
def focus(sender)
|
||||
@focus = true
|
||||
@style.background_canvas.background = default(:active, :background)
|
||||
@text.color = default(:active, :color)
|
||||
window.text_input = @text_input
|
||||
@text_input.caret_pos = @text_input.selection_start = @text_input.text.length
|
||||
|
||||
:handled
|
||||
end
|
||||
|
||||
def blur(_sender)
|
||||
@focus = false
|
||||
@style.background_canvas.background = default(:background)
|
||||
@@ -251,6 +263,10 @@ module CyberarmEngine
|
||||
def value
|
||||
@text_input.text
|
||||
end
|
||||
|
||||
def value=(string)
|
||||
@text_input.text = string
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -66,6 +66,13 @@ module CyberarmEngine
|
||||
@pending_recalculate_request = false
|
||||
end
|
||||
|
||||
if @pending_focus_request
|
||||
@pending_focus_request = false
|
||||
|
||||
self.focus = @pending_focus_element
|
||||
@pending_focus_element.publish(:focus)
|
||||
end
|
||||
|
||||
@menu&.update
|
||||
super
|
||||
|
||||
@@ -105,7 +112,10 @@ module CyberarmEngine
|
||||
@last_mouse_pos = Vector.new(window.mouse_x, window.mouse_y)
|
||||
@mouse_pos = @last_mouse_pos.clone
|
||||
|
||||
request_recalculate if @active_width != window.width || @active_height != window.height
|
||||
if @active_width != window.width || @active_height != window.height
|
||||
request_recalculate
|
||||
@root_container.publish(:window_size_changed)
|
||||
end
|
||||
|
||||
@active_width = window.width
|
||||
@active_height = window.height
|
||||
@@ -212,6 +222,11 @@ module CyberarmEngine
|
||||
@pending_recalculate_request = true
|
||||
end
|
||||
|
||||
def request_focus(element)
|
||||
@pending_focus_request = true
|
||||
@pending_focus_element = element
|
||||
end
|
||||
|
||||
def show_menu(list_box)
|
||||
@menu = list_box
|
||||
end
|
||||
@@ -219,5 +234,14 @@ module CyberarmEngine
|
||||
def hide_menu
|
||||
@menu = nil
|
||||
end
|
||||
|
||||
def to_s
|
||||
# "#{self.class} children=#{@children.map { |c| c.to_s }}"
|
||||
@root_container.to_s
|
||||
end
|
||||
|
||||
def inspect
|
||||
to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module CyberarmEngine
|
||||
NAME = "InDev".freeze
|
||||
VERSION = "0.16.0".freeze
|
||||
VERSION = "0.17.1".freeze
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user