5 Commits

6 changed files with 71 additions and 16 deletions

View File

@@ -29,11 +29,11 @@ Gem::Specification.new do |spec|
spec.add_dependency "clipboard", "~> 1.3.5" spec.add_dependency "clipboard", "~> 1.3.5"
spec.add_dependency "excon", "~> 0.78.0" 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 "gosu_more_drawables", "~> 0.3"
# spec.add_dependency "ffi", :platforms => [:mswin, :mingw] # Required by Clipboard on Windows # 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 "minitest", "~> 5.0"
spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency "rake", "~> 13.0"
end end

View File

@@ -226,6 +226,22 @@ module CyberarmEngine
(@style.border_thickness_top + @style.padding_top) + (@style.padding_bottom + @style.border_thickness_bottom) (@style.border_thickness_top + @style.padding_top) + (@style.padding_bottom + @style.border_thickness_bottom)
end 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) def dimensional_size(size, dimension)
raise "dimension must be either :width or :height" unless %i[width height].include?(dimension) raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)

View File

@@ -4,19 +4,20 @@ module CyberarmEngine
include Common include Common
attr_accessor :stroke_color, :fill_color 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) def initialize(options = {}, block = nil)
@gui_state = options.delete(:gui_state) @gui_state = options.delete(:gui_state)
super super
@scroll_x = 0 @scroll_position = Vector.new(0, 0)
@scroll_y = 0 @scroll_speed = 40
@scroll_speed = 10
@text_color = options[:color] @text_color = options[:color]
@children = [] @children = []
event(:window_size_changed)
end end
def build def build
@@ -44,6 +45,17 @@ module CyberarmEngine
root.gui_state.request_recalculate root.gui_state.request_recalculate
end 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 def render
Gosu.clip_to(@x, @y, width, height) do Gosu.clip_to(@x, @y, width, height) do
@children.each(&:draw) @children.each(&:draw)
@@ -98,6 +110,8 @@ module CyberarmEngine
def recalculate def recalculate
@current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top) @current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
@current_position += @scroll_position
return unless visible? return unless visible?
Stats.increment(:gui_recalculations_last_frame, 1) Stats.increment(:gui_recalculations_last_frame, 1)
@@ -189,15 +203,31 @@ module CyberarmEngine
@current_position.y += element.outer_height @current_position.y += element.outer_height
end end
# def mouse_wheel_up(sender, x, y) def mouse_wheel_up(sender, x, y)
# @children.each {|c| c.y -= @scroll_speed} return unless @style.scroll
# @children.each {|c| c.recalculate} return if height < max_scroll_height
# end
# def mouse_wheel_down(sender, x, y) if @scroll_position.y < 0
# @children.each {|c| c.y += @scroll_speed} @scroll_position.y += @scroll_speed
# @children.each {|c| c.recalculate} @scroll_position.y = 0 if @scroll_position.y > 0
# end 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 def value
@children.map { |c| c.class }.join(", ") @children.map { |c| c.class }.join(", ")

View File

@@ -67,6 +67,8 @@ module CyberarmEngine
if @last_text_value != value if @last_text_value != value
@last_text_value = value @last_text_value = value
@show_caret = true
@caret_last_interval = Gosu.milliseconds
publish(:changed, value) publish(:changed, value)
end end
@@ -251,6 +253,10 @@ module CyberarmEngine
def value def value
@text_input.text @text_input.text
end end
def value=(string)
@text_input.text = string
end
end end
end end
end end

View File

@@ -105,7 +105,10 @@ module CyberarmEngine
@last_mouse_pos = Vector.new(window.mouse_x, window.mouse_y) @last_mouse_pos = Vector.new(window.mouse_x, window.mouse_y)
@mouse_pos = @last_mouse_pos.clone @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_width = window.width
@active_height = window.height @active_height = window.height

View File

@@ -1,4 +1,4 @@
module CyberarmEngine module CyberarmEngine
NAME = "InDev".freeze NAME = "InDev".freeze
VERSION = "0.16.0".freeze VERSION = "0.17.0".freeze
end end