mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 13:12:34 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 55382a7c14 | |||
| 883de3db9f | |||
| 41c0b27937 | |||
| 2fd5d398cf | |||
| 2e66509f87 | |||
| 521b3937dd | |||
| ab9f9e8e7a | |||
| 705138f7ad | |||
| 94a65f447c |
@@ -27,7 +27,6 @@ Gem::Specification.new do |spec|
|
||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = %w[lib assets]
|
||||
|
||||
spec.add_dependency "clipboard", "~> 1.3"
|
||||
spec.add_dependency "excon", "~> 0.88"
|
||||
spec.add_dependency "gosu", "~> 1.1"
|
||||
spec.add_dependency "gosu_more_drawables", "~> 0.3"
|
||||
|
||||
@@ -8,7 +8,6 @@ end
|
||||
require "json"
|
||||
require "excon"
|
||||
require "gosu_more_drawables"
|
||||
require "clipboard"
|
||||
|
||||
require_relative "cyberarm_engine/version"
|
||||
require_relative "cyberarm_engine/stats"
|
||||
|
||||
@@ -8,8 +8,11 @@ module CyberarmEngine
|
||||
window.current_state
|
||||
end
|
||||
|
||||
def previous_state
|
||||
window.previous_state
|
||||
def previous_state(state = nil)
|
||||
raise "Only available for CyberarmEngine::GameState and subclasses" unless is_a?(CyberarmEngine::GameState) || state.is_a?(CyberarmEngine::GameState)
|
||||
|
||||
i = window.states.index(state || self)
|
||||
window.states[i - 1] unless (i - 1).negative?
|
||||
end
|
||||
|
||||
def pop_state
|
||||
|
||||
@@ -22,19 +22,21 @@ module CyberarmEngine
|
||||
else
|
||||
@color = Gosu::Color::WHITE
|
||||
end
|
||||
@mode = options[:mode] || :default
|
||||
@mode = options[:mode] || :default
|
||||
@alignment = options[:alignment] || nil
|
||||
|
||||
@border = options[:border]
|
||||
@border = true if options[:border].nil?
|
||||
@border_size = options[:border_size] || 1
|
||||
@border_alpha = options[:border_alpha] || 30
|
||||
@border_color = options[:border_color]
|
||||
@border_color = options[:border_color] || Gosu::Color::BLACK
|
||||
|
||||
@shadow = options[:shadow]
|
||||
@shadow_size = options[:shadow_size] || 2
|
||||
@shadow_alpha = options[:shadow_alpha] || 30
|
||||
@shadow_color = options[:shadow_color]
|
||||
@shadow_color = options[:shadow_color] || Gosu::Color::BLACK
|
||||
|
||||
@static = options[:static] || (options[:static].nil? || options[:static] == false ? false : true)
|
||||
|
||||
@textobject = check_cache(@size, @font)
|
||||
|
||||
@@ -84,46 +86,49 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def text=(string)
|
||||
@rendered_border = nil
|
||||
invalidate_cache! if @text != string
|
||||
@text = string
|
||||
end
|
||||
|
||||
def factor_x=(n)
|
||||
@rendered_border = nil
|
||||
invalidate_cache! if @factor_x != n
|
||||
@factor_x = n
|
||||
end
|
||||
|
||||
def factor_y=(n)
|
||||
@rendered_border = nil
|
||||
invalidate_cache! if @factor_y != n
|
||||
@factor_y = n
|
||||
end
|
||||
|
||||
def color=(color)
|
||||
@rendered_border = nil
|
||||
old_color = @color
|
||||
|
||||
if color
|
||||
@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 border=(boolean)
|
||||
@rendered_border = nil
|
||||
invalidate_cache! if @border != boolean
|
||||
@border = boolean
|
||||
end
|
||||
|
||||
def border_size=(n)
|
||||
@rendered_border = nil
|
||||
invalidate_cache! if @border_size != n
|
||||
@border_size = n
|
||||
end
|
||||
|
||||
def border_alpha=(n)
|
||||
@rendered_border = nil
|
||||
invalidate_cache! if @border_alpha != n
|
||||
@border_alpha = n
|
||||
end
|
||||
|
||||
def border_color=(n)
|
||||
@rendered_border = nil
|
||||
invalidate_cache! if @border_color != n
|
||||
@border_color = n
|
||||
end
|
||||
|
||||
@@ -132,11 +137,27 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def text_width(text = @text)
|
||||
textobject.text_width(text) + @border_size + @shadow_size
|
||||
spacing = 0
|
||||
spacing += @border_size if @border
|
||||
spacing += @shadow_size if @shadow
|
||||
|
||||
if text == @text && @static && @gosu_cached_text_image
|
||||
@gosu_cached_text_image&.width + spacing
|
||||
else
|
||||
textobject.text_width(text) + spacing
|
||||
end
|
||||
end
|
||||
|
||||
def markup_width(text = @text)
|
||||
textobject.markup_width(text) + @border_size + @shadow_size
|
||||
spacing = 0
|
||||
spacing += @border_size if @border
|
||||
spacing += @shadow_size if @shadow
|
||||
|
||||
if text == @text && @static && @gosu_cached_text_image
|
||||
@gosu_cached_text_image&.width + spacing
|
||||
else
|
||||
textobject.markup_width(text) + spacing
|
||||
end
|
||||
end
|
||||
|
||||
def height(text = @text)
|
||||
@@ -148,39 +169,72 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def draw(method = :draw_markup)
|
||||
if @border && !ARGV.join.include?("--no-border")
|
||||
border_alpha = @color.alpha <= 30 ? @color.alpha : @border_alpha
|
||||
border_color = @border_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
|
||||
border_alpha)
|
||||
white = Gosu::Color::WHITE
|
||||
if @static
|
||||
if @border && !@cached_text_border_image
|
||||
_x = @border_size
|
||||
_y = @border_size
|
||||
_width = method == :draw_markup ? text_width : markup_width
|
||||
img = Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font)
|
||||
|
||||
_x = @border_size
|
||||
_y = @border_size
|
||||
_width = method == :draw_markup ? text_width : markup_width
|
||||
@cached_text_border_image = Gosu.render((_width + (@border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
|
||||
img.draw(-_x, 0, @z, @factor_x, @factor_y, @border_color, @mode)
|
||||
img.draw(-_x, -_y, @z, @factor_x, @factor_y, @border_color, @mode)
|
||||
|
||||
@rendered_border ||= Gosu.render((_width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
|
||||
@textobject.send(method, @text, _x - @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
||||
@textobject.send(method, @text, _x - @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
img.draw(0, -_y, @z, @factor_x, @factor_y, @border_color, @mode)
|
||||
img.draw(_x, -_y, @z, @factor_x, @factor_y, @border_color, @mode)
|
||||
|
||||
@textobject.send(method, @text, _x, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
@textobject.send(method, @text, _x + @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
img.draw(_x, 0, @z, @factor_x, @factor_y, @border_color, @mode)
|
||||
img.draw(_x, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
||||
|
||||
@textobject.send(method, @text, _x, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
@textobject.send(method, @text, _x - @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
|
||||
@textobject.send(method, @text, _x + @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
||||
@textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
img.draw(0, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
||||
img.draw(-_x, _y, @z, @factor_x, @factor_y, @border_color, @mode)
|
||||
end
|
||||
end
|
||||
|
||||
@rendered_border.draw(@x - @border_size, @y - @border_size, @z, @factor_x, @factor_y, border_color)
|
||||
end
|
||||
@cached_text_shadow_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font) if @shadow
|
||||
|
||||
if @shadow
|
||||
shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
|
||||
@textobject.send(method, @text, @x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, shadow_color, @mode)
|
||||
end
|
||||
@gosu_cached_text_image ||= Gosu::Image.send(:"from_#{method.to_s.split("_").last}", @text, @size, font: @font)
|
||||
|
||||
@textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
||||
@cached_text_border_image.draw(@x, @y, @z, @factor_x, @factor_y, @border_color, @mode) if @border
|
||||
|
||||
@cached_text_shadow_image.draw(@x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, @shadow_color, @mode) if @shadow
|
||||
|
||||
@gosu_cached_text_image.draw(@x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
||||
else
|
||||
if @border && !ARGV.join.include?("--no-border")
|
||||
border_alpha = @color.alpha <= 30 ? @color.alpha : @border_alpha
|
||||
border_color = @border_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue,
|
||||
border_alpha)
|
||||
white = Gosu::Color::WHITE
|
||||
|
||||
_x = @border_size
|
||||
_y = @border_size
|
||||
_width = method == :draw_markup ? text_width : markup_width
|
||||
|
||||
@cached_text_border_image ||= Gosu.render((_width + (border_size * 2)).ceil, (height + (@border_size * 2)).ceil) do
|
||||
@textobject.send(method, @text, _x - @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
||||
@textobject.send(method, @text, _x - @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
|
||||
@textobject.send(method, @text, _x, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
@textobject.send(method, @text, _x + @border_size, _y - @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
|
||||
@textobject.send(method, @text, _x, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
@textobject.send(method, @text, _x - @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
|
||||
@textobject.send(method, @text, _x + @border_size, _y, @z, @factor_x, @factor_y, white, @mode)
|
||||
@textobject.send(method, @text, _x + @border_size, _y + @border_size, @z, @factor_x, @factor_y, white, @mode)
|
||||
end
|
||||
|
||||
@cached_text_border_image.draw(@x - @border_size, @y - @border_size, @z, @factor_x, @factor_y, border_color)
|
||||
end
|
||||
|
||||
if @shadow
|
||||
shadow_color = @shadow_color || Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
|
||||
@textobject.send(method, @text, @x + @shadow_size, @y + @shadow_size, @z, @factor_x, @factor_y, shadow_color, @mode)
|
||||
end
|
||||
|
||||
@textobject.send(method, @text, @x, @y, @z, @factor_x, @factor_y, @color, @mode)
|
||||
end
|
||||
end
|
||||
|
||||
def alpha=(n)
|
||||
@@ -193,5 +247,11 @@ module CyberarmEngine
|
||||
|
||||
def update
|
||||
end
|
||||
|
||||
def invalidate_cache!
|
||||
@cached_text_border_image = nil
|
||||
@cached_text_shadow_image = nil
|
||||
@gosu_cached_text_image = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -447,29 +447,37 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
if @parent && @style.fill # Handle fill behavior
|
||||
fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f # include self since we're dividing
|
||||
|
||||
if dimension == :width && @parent.is_a?(Flow)
|
||||
space_available_width = ((@parent.content_width - (@parent.children.reject { |c| c.style.fill }).map(&:outer_width).sum) / fill_siblings)
|
||||
space_available_width = space_available_width.nan? ? 0 : space_available_width.floor # The parent element might not have its dimensions, yet.
|
||||
|
||||
return space_available_width - noncontent_width
|
||||
|
||||
elsif dimension == :height && @parent.is_a?(Stack)
|
||||
space_available_height = ((@parent.content_height - (@parent.children.reject { |c| c.style.fill }).map(&:outer_height).sum) / fill_siblings)
|
||||
space_available_height = space_available_height.nan? ? 0 : space_available_height.floor # The parent element might not have its dimensions, yet.
|
||||
|
||||
return space_available_height - noncontent_height
|
||||
end
|
||||
|
||||
else # Handle min_width/height and max_width/height
|
||||
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size < @style.send(:"min_#{dimension}")
|
||||
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size > @style.send(:"max_#{dimension}")
|
||||
return @style.send(:"min_#{dimension}") if @style.send(:"min_#{dimension}") && new_size.to_f < @style.send(:"min_#{dimension}")
|
||||
return @style.send(:"max_#{dimension}") if @style.send(:"max_#{dimension}") && new_size.to_f > @style.send(:"max_#{dimension}")
|
||||
end
|
||||
|
||||
new_size
|
||||
end
|
||||
|
||||
def space_available_width
|
||||
# TODO: This may get expensive if there are a lot of children, probably should cache it somehow
|
||||
fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f # include self since we're dividing
|
||||
|
||||
available_space = ((@parent.content_width - (@parent.children.reject { |c| c.style.fill }).map(&:outer_width).sum) / fill_siblings)
|
||||
(available_space.nan? || available_space.infinite?) ? 0 : available_space.floor # The parent element might not have its dimensions, yet.
|
||||
end
|
||||
|
||||
def space_available_height
|
||||
# TODO: This may get expensive if there are a lot of children, probably should cache it somehow
|
||||
fill_siblings = @parent.children.select { |c| c.style.fill }.count.to_f # include self since we're dividing
|
||||
|
||||
available_space = ((@parent.content_height - (@parent.children.reject { |c| c.style.fill }).map(&:outer_height).sum) / fill_siblings)
|
||||
(available_space.nan? || available_space.infinite?) ? 0 : available_space.floor # The parent element might not have its dimensions, yet.
|
||||
end
|
||||
|
||||
def background=(_background)
|
||||
@style.background_canvas.background = _background
|
||||
update_background
|
||||
|
||||
@@ -136,7 +136,31 @@ module CyberarmEngine
|
||||
@height = _height || (@children.map { |c| c.y + c.outer_height }.max || 0).floor
|
||||
end
|
||||
|
||||
# Move child to parent after positioning
|
||||
# FIXME: Correctly handle alignment when element has siblings
|
||||
# FIXME: Enable alignment for any element, not just containers
|
||||
if @style.v_align
|
||||
space = space_available_height
|
||||
|
||||
case @style.v_align
|
||||
when :center
|
||||
@y = parent.height / 2 - height / 2
|
||||
when :bottom
|
||||
@y = parent.height - height
|
||||
end
|
||||
end
|
||||
|
||||
if @style.h_align
|
||||
space = space_available_width
|
||||
|
||||
case @style.h_align
|
||||
when :center
|
||||
@x = parent.width / 2 - width / 2
|
||||
when :right
|
||||
@x = parent.width - width
|
||||
end
|
||||
end
|
||||
|
||||
# Move children to parent after positioning
|
||||
@children.each do |child|
|
||||
child.x += (@x + @style.border_thickness_left) - style.margin_left
|
||||
child.y += (@y + @style.border_thickness_top) - style.margin_top
|
||||
@@ -172,7 +196,6 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def fits_on_line?(element) # Flow
|
||||
p [@options[:id], @width] if @options[:id]
|
||||
@current_position.x + element.outer_width <= max_width &&
|
||||
@current_position.x + element.outer_width <= window.width
|
||||
end
|
||||
@@ -182,7 +205,6 @@ module CyberarmEngine
|
||||
element.y = element.style.margin_top + @current_position.y
|
||||
|
||||
@current_position.x += element.outer_width
|
||||
@current_position.x = @style.margin_left if @current_position.x >= max_width
|
||||
end
|
||||
|
||||
def tallest_neighbor(querier, _y_position) # Flow
|
||||
@@ -195,14 +217,14 @@ module CyberarmEngine
|
||||
response
|
||||
end
|
||||
|
||||
def position_on_next_line(child) # Flow
|
||||
@current_position.x = @style.margin_left
|
||||
@current_position.y += tallest_neighbor(child, @current_position.y).outer_height
|
||||
def position_on_next_line(element) # Flow
|
||||
@current_position.x = @style.margin_left + @style.padding_left
|
||||
@current_position.y += tallest_neighbor(element, @current_position.y).outer_height
|
||||
|
||||
child.x = child.style.margin_left + @current_position.x
|
||||
child.y = child.style.margin_top + @current_position.y
|
||||
element.x = element.style.margin_left + @current_position.x
|
||||
element.y = element.style.margin_top + @current_position.y
|
||||
|
||||
@current_position.x += child.outer_width
|
||||
@current_position.x += element.outer_width
|
||||
end
|
||||
|
||||
def move_to_next_line(element) # Stack
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
module CyberarmEngine
|
||||
class Element
|
||||
class EditLine < Button
|
||||
class TextInput < Gosu::TextInput
|
||||
def filter=(filter)
|
||||
@filter = filter
|
||||
end
|
||||
|
||||
def filter(text_in)
|
||||
if @filter
|
||||
@filter.call(text_in)
|
||||
else
|
||||
text_in
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(text, options = {}, block = nil)
|
||||
@filter = options.delete(:filter)
|
||||
super(text, options, block)
|
||||
@@ -14,17 +28,11 @@ module CyberarmEngine
|
||||
@caret_last_interval = Gosu.milliseconds
|
||||
@show_caret = true
|
||||
|
||||
@text_input = Gosu::TextInput.new
|
||||
@text_input = TextInput.new
|
||||
@text_input.filter = @filter
|
||||
@text_input.text = text
|
||||
@last_text_value = text
|
||||
|
||||
if @filter && @filter.respond_to?(:call)
|
||||
@text_input.instance_variable_set(:@filter, @filter)
|
||||
|
||||
def @text_input.filter(text_in)
|
||||
@filter.call(text_in)
|
||||
end
|
||||
end
|
||||
@last_caret_position = @text_input.caret_pos
|
||||
|
||||
@offset_x = 0
|
||||
@offset_y = 0
|
||||
@@ -75,6 +83,12 @@ module CyberarmEngine
|
||||
publish(:changed, value)
|
||||
end
|
||||
|
||||
if @last_caret_position != @text_input.caret_pos
|
||||
@last_caret_position = @text_input.caret_pos
|
||||
@show_caret = true
|
||||
@caret_last_interval = Gosu.milliseconds
|
||||
end
|
||||
|
||||
if Gosu.milliseconds >= @caret_last_interval + @caret_interval
|
||||
@caret_last_interval = Gosu.milliseconds
|
||||
|
||||
@@ -98,20 +112,20 @@ module CyberarmEngine
|
||||
@text_input.caret_pos = @text_input.text.length
|
||||
|
||||
when Gosu::KB_C
|
||||
if @text_input.selection_start < @text_input.caret_pos
|
||||
Clipboard.copy(@text_input.text[@text_input.selection_start...@text_input.caret_pos])
|
||||
else
|
||||
Clipboard.copy(@text_input.text[@text_input.caret_pos...@text_input.selection_start])
|
||||
end
|
||||
Gosu.clipboard = if @text_input.selection_start < @text_input.caret_pos
|
||||
@text_input.text[@text_input.selection_start...@text_input.caret_pos]
|
||||
else
|
||||
@text_input.text[@text_input.caret_pos...@text_input.selection_start]
|
||||
end
|
||||
|
||||
when Gosu::KB_X
|
||||
chars = @text_input.text.chars
|
||||
|
||||
if @text_input.selection_start < @text_input.caret_pos
|
||||
Clipboard.copy(@text_input.text[@text_input.selection_start...@text_input.caret_pos])
|
||||
Gosu.clipboard = @text_input.text[@text_input.selection_start...@text_input.caret_pos]
|
||||
chars.slice!(@text_input.selection_start, @text_input.caret_pos)
|
||||
else
|
||||
Clipboard.copy(@text_input.text[@text_input.caret_pos...@text_input.selection_start])
|
||||
Gosu.clipboard = @text_input.text[@text_input.caret_pos...@text_input.selection_start]
|
||||
chars.slice!(@text_input.caret_pos, @text_input.selection_start)
|
||||
end
|
||||
|
||||
@@ -119,10 +133,9 @@ module CyberarmEngine
|
||||
|
||||
when Gosu::KB_V
|
||||
if instance_of?(EditLine) # EditLine assumes a single line of text
|
||||
@text_input.text = @text_input.text.insert(@text_input.caret_pos,
|
||||
Clipboard.paste.encode("UTF-8").gsub("\n", ""))
|
||||
@text_input.insert_text(Gosu.clipboard.gsub("\n", ""))
|
||||
else
|
||||
@text_input.text = @text_input.text.insert(@text_input.caret_pos, Clipboard.paste.encode("UTF-8"))
|
||||
@text_input.insert_text(Gosu.clipboard)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -180,7 +193,7 @@ module CyberarmEngine
|
||||
if @type == :password
|
||||
@text.x + @text.width(default(:password_character) * @text_input.text[0...@text_input.send(method)].length)
|
||||
else
|
||||
@text.x + @text.width(@text_input.text[0...@text_input.send(method)])
|
||||
@text.x + @text.width(@text_input.text[0...@text_input.send(method)]) - @style.border_thickness_left
|
||||
end
|
||||
end
|
||||
|
||||
@@ -197,20 +210,35 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def focus(sender)
|
||||
super
|
||||
|
||||
@focus = true
|
||||
window.text_input = @text_input
|
||||
@text_input.caret_pos = @text_input.selection_start = @text_input.text.length
|
||||
|
||||
update_styles(:active)
|
||||
|
||||
:handled
|
||||
end
|
||||
|
||||
def enter(sender)
|
||||
_has_focus = @focus
|
||||
if @enabled && @focus
|
||||
update_styles(:active)
|
||||
elsif @enabled && !@focus
|
||||
update_styles(:hover)
|
||||
else
|
||||
update_styles(:disabled)
|
||||
end
|
||||
|
||||
super
|
||||
:handled
|
||||
end
|
||||
|
||||
@focus = _has_focus
|
||||
def leave(sender)
|
||||
if @enabled && @focus
|
||||
update_styles(:active)
|
||||
elsif @enabled && !@focus
|
||||
update_styles
|
||||
else
|
||||
update_styles(:disabled)
|
||||
end
|
||||
|
||||
:handled
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ module CyberarmEngine
|
||||
@style.background_canvas.background = default(:background)
|
||||
|
||||
# TODO: "Clean Up" into own class?
|
||||
@menu = Stack.new(parent: parent, width: @options[:width], theme: @options[:theme])
|
||||
@menu = Stack.new(parent: self, theme: @options[:theme])
|
||||
@menu.define_singleton_method(:recalculate_menu) do
|
||||
@x = @__list_box.x
|
||||
@y = @__list_box.y + @__list_box.height
|
||||
@@ -64,6 +64,8 @@ module CyberarmEngine
|
||||
def show_menu
|
||||
@menu.clear
|
||||
|
||||
@menu.style.width = width
|
||||
|
||||
@items.each do |item|
|
||||
next if item == self.value
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ module CyberarmEngine
|
||||
@step_size = @options[:step] || 0.1
|
||||
@value = @options[:value] || (@range.first + @range.last) / 2
|
||||
|
||||
@handle = Handle.new("", parent: self, width: 8, height: 1.0) { close }
|
||||
@handle = Handle.new("", parent: self, theme: options[:theme], width: 8, height: 1.0) { close }
|
||||
add(@handle)
|
||||
end
|
||||
|
||||
@@ -61,10 +61,10 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def position_handle
|
||||
@handle.x = @x + @style.padding_left + @style.border_thickness_left +
|
||||
@handle.x = @x + @handle.style.margin_left + @style.padding_left + @style.border_thickness_left +
|
||||
((content_width - @handle.outer_width) * (@value - @range.min) / (@range.max - @range.min).to_f)
|
||||
|
||||
@handle.y = @y + @style.border_thickness_top + @style.padding_top
|
||||
@handle.y = @y + @handle.style.margin_top + @style.border_thickness_top + @style.padding_top
|
||||
end
|
||||
|
||||
def draw
|
||||
|
||||
@@ -7,6 +7,7 @@ module CyberarmEngine
|
||||
@text = Text.new(
|
||||
text, font: @options[:font], z: @z, color: @options[:color],
|
||||
size: @options[:text_size], shadow: @options[:text_shadow],
|
||||
static: @options[:text_static],
|
||||
shadow_size: @options[:text_shadow_size],
|
||||
shadow_color: @options[:text_shadow_color],
|
||||
border: @options[:text_border],
|
||||
@@ -49,7 +50,7 @@ module CyberarmEngine
|
||||
@text.y = @style.border_thickness_top + @style.padding_top + @y
|
||||
@text.z = @z + 3
|
||||
|
||||
if (text_alignment = @options[:text_align])
|
||||
if (text_alignment = @options[:text_align] || @options[:text_h_align])
|
||||
case text_alignment
|
||||
when :left
|
||||
@text.x = @style.border_thickness_left + @style.padding_left + @x
|
||||
@@ -64,6 +65,19 @@ module CyberarmEngine
|
||||
end
|
||||
end
|
||||
|
||||
if (vertical_alignment = @options[:text_v_align])
|
||||
case vertical_alignment
|
||||
when :center
|
||||
@text.y = if @text.height <= height
|
||||
@y + height / 2 - @text.height / 2
|
||||
else
|
||||
@style.border_thickness_top + @style.padding_top + @y
|
||||
end
|
||||
when :bottom
|
||||
@text.y = @y + outer_height - (@text.height + @style.border_thickness_bottom + @style.padding_bottom)
|
||||
end
|
||||
end
|
||||
|
||||
update_background
|
||||
end
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ module CyberarmEngine
|
||||
|
||||
def initialize(options, block = nil)
|
||||
if options.dig(:theme, :ToggleButton, :checkmark_image)
|
||||
options[:theme][:ToggleButton][:image_width] ||= options[:theme][:Label][:text_size]
|
||||
options[:theme][:ToggleButton][:image_width] ||= options[:theme][:TextBlock][:text_size]
|
||||
super(get_image(options.dig(:theme, :ToggleButton, :checkmark_image)), options, block)
|
||||
|
||||
@_image = @image
|
||||
|
||||
@@ -171,6 +171,9 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
@focus.button_up(id) if @focus.respond_to?(:button_up)
|
||||
|
||||
# Prevents menu from popping back up if the listbox is clicked to hide it.
|
||||
@hid_menu_for = nil
|
||||
end
|
||||
|
||||
def tool_tip_delay
|
||||
@@ -185,7 +188,7 @@ module CyberarmEngine
|
||||
@focus = nil
|
||||
end
|
||||
|
||||
if @mouse_over
|
||||
if @mouse_over && @hid_menu_for != @mouse_over
|
||||
@mouse_down_position[button] = Vector.new(window.mouse_x, window.mouse_y)
|
||||
@mouse_down_on[button] = @mouse_over
|
||||
|
||||
@@ -199,7 +202,7 @@ module CyberarmEngine
|
||||
def redirect_released_mouse_button(button)
|
||||
hide_menu if @menu && (@menu == @mouse_over) || (@mouse_over&.parent == @menu)
|
||||
|
||||
if @mouse_over
|
||||
if @mouse_over && @hid_menu_for != @mouse_over
|
||||
@mouse_over.publish(:"released_#{button}_mouse_button", window.mouse_x, window.mouse_y)
|
||||
if @mouse_over == @mouse_down_on[button]
|
||||
@mouse_over.publish(:"clicked_#{button}_mouse_button", window.mouse_x,
|
||||
@@ -255,6 +258,9 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def hide_menu
|
||||
return unless @menu
|
||||
|
||||
@hid_menu_for = @menu.parent
|
||||
@menu = nil
|
||||
end
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ module CyberarmEngine
|
||||
border_radius: 0,
|
||||
background: ["ffc75e61".to_i(16), "ffe26623".to_i(16)],
|
||||
text_align: :center,
|
||||
text_v_align: :center,
|
||||
text_wrap: :none,
|
||||
|
||||
hover: {
|
||||
@@ -102,7 +103,12 @@ module CyberarmEngine
|
||||
caret_color: Gosu::Color::WHITE,
|
||||
caret_interval: 500,
|
||||
selection_color: Gosu::Color.rgba(255, 128, 50, 200),
|
||||
text_align: :left
|
||||
text_align: :left,
|
||||
text_static: false # static text causes issues correctly displaying caret position
|
||||
},
|
||||
|
||||
EditBox: { # < EditLine
|
||||
text_v_align: :top
|
||||
},
|
||||
|
||||
Image: { # < Element
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module CyberarmEngine
|
||||
NAME = "InDev".freeze
|
||||
VERSION = "0.21.0".freeze
|
||||
VERSION = "0.22.0".freeze
|
||||
end
|
||||
|
||||
@@ -139,12 +139,6 @@ module CyberarmEngine
|
||||
@states.last
|
||||
end
|
||||
|
||||
def previous_state
|
||||
if @states.size > 1 && (state = @states[@states.size - 2])
|
||||
state
|
||||
end
|
||||
end
|
||||
|
||||
def pop_state
|
||||
@states.pop
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user