mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-09-19 21:33:51 +00:00
Make elements sizing by like css' border-box box-sizing instead of like content-box for elements with specific width/height that isn't a ratio, tweaks to gui debug display, make F12 key toggle gui debug display for convenience
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
|
GUI_DEBUG = false
|
||||||
|
|
||||||
module Common
|
module Common
|
||||||
ImageBlob = Data.define(:to_blob, :columns, :rows)
|
ImageBlob = Data.define(:to_blob, :columns, :rows)
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ module CyberarmEngine
|
|||||||
@visible = !@options.key?(:visible) ? true : @options[:visible]
|
@visible = !@options.key?(:visible) ? true : @options[:visible]
|
||||||
@tip = @options[:tip] || ""
|
@tip = @options[:tip] || ""
|
||||||
|
|
||||||
@debug = @options[:debug] || CyberarmEngine.const_defined?("GUI_DEBUG") && CyberarmEngine::GUI_DEBUG || false
|
@debug = @options[:debug].nil? ? nil : @options[:debug]
|
||||||
@debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color]
|
@debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color]
|
||||||
|
|
||||||
@style = Style.new(options)
|
@style = Style.new(options)
|
||||||
@@ -36,7 +36,7 @@ module CyberarmEngine
|
|||||||
@width = 0
|
@width = 0
|
||||||
@height = 0
|
@height = 0
|
||||||
|
|
||||||
@style.width = default(:width) || nil
|
@style.width = default(:width) || nil
|
||||||
@style.height = default(:height) || nil
|
@style.height = default(:height) || nil
|
||||||
|
|
||||||
@background_canvas = nil # Background.new
|
@background_canvas = nil # Background.new
|
||||||
@@ -340,7 +340,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def debug_draw
|
def debug_draw
|
||||||
return unless @debug # allow elements to opt out of debug drawing, makes debugging some things easier.
|
return if @debug == false || !CyberarmEngine::GUI_DEBUG # allow elements to opt out of debug drawing, makes debugging some things easier.
|
||||||
return if CyberarmEngine.const_defined?("GUI_DEBUG_ONLY_ELEMENT") && self.class == GUI_DEBUG_ONLY_ELEMENT
|
return if CyberarmEngine.const_defined?("GUI_DEBUG_ONLY_ELEMENT") && self.class == GUI_DEBUG_ONLY_ELEMENT
|
||||||
|
|
||||||
Gosu.draw_line(
|
Gosu.draw_line(
|
||||||
@@ -394,7 +394,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def width
|
def width
|
||||||
if visible?
|
if visible?
|
||||||
inner_width + @width
|
inner_width + content_width
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
@@ -418,7 +418,7 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def height
|
def height
|
||||||
if visible?
|
if visible?
|
||||||
inner_height + @height
|
inner_height + content_height
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
@@ -488,6 +488,8 @@ module CyberarmEngine
|
|||||||
|
|
||||||
new_size = if size.is_a?(Float) && size.between?(0.0, 1.0)
|
new_size = if size.is_a?(Float) && size.between?(0.0, 1.0)
|
||||||
(@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
|
(@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
|
||||||
|
elsif size.is_a?(Numeric)
|
||||||
|
(size - send(:"noncontent_#{dimension}")).floor
|
||||||
else
|
else
|
||||||
size
|
size
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -88,17 +88,20 @@ module CyberarmEngine
|
|||||||
|
|
||||||
Gosu.translate(@scroll_position.x, @scroll_position.y) do
|
Gosu.translate(@scroll_position.x, @scroll_position.y) do
|
||||||
@children.each(&:draw)
|
@children.each(&:draw)
|
||||||
|
|
||||||
|
@children.each do |child|
|
||||||
|
next unless child.visible?
|
||||||
|
|
||||||
|
child.debug_draw
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@children.each(&:debug_draw)
|
|
||||||
debug_draw
|
debug_draw
|
||||||
end
|
end
|
||||||
|
|
||||||
def debug_draw
|
def debug_draw
|
||||||
super
|
super
|
||||||
|
|
||||||
@children.each(&:debug_draw)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|||||||
@@ -239,6 +239,9 @@ module CyberarmEngine
|
|||||||
redirect_mouse_button(:right)
|
redirect_mouse_button(:right)
|
||||||
when Gosu::KB_F5
|
when Gosu::KB_F5
|
||||||
request_recalculate
|
request_recalculate
|
||||||
|
when Gosu::KB_F12
|
||||||
|
CyberarmEngine.const_set(:GUI_DEBUG, !CyberarmEngine::GUI_DEBUG)
|
||||||
|
request_repaint
|
||||||
end
|
end
|
||||||
|
|
||||||
@focus.button_down(id) if @focus.respond_to?(:button_down)
|
@focus.button_down(id) if @focus.respond_to?(:button_down)
|
||||||
|
|||||||
Reference in New Issue
Block a user