mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-09-20 05:43:51 +00:00
Compare commits
6 Commits
349222f387
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
| 9fca64b643 | |||
| abe99ce949 | |||
| 66fb136c83 | |||
| b23e5c2a42 | |||
| 747822aa61 | |||
| 140e7a3619 |
@@ -4,10 +4,10 @@ module CyberarmEngine
|
||||
|
||||
CACHE = {}
|
||||
|
||||
attr_accessor :x, :y, :z, :width, :height, :mode, :color
|
||||
attr_accessor :x, :y, :z, :width, :height, :mode, :color, :render_mode
|
||||
attr_reader :image, :left, :top, :right, :bottom
|
||||
|
||||
def initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :tiled, left: 1, top: 1, right: 1, bottom: 1, color: Gosu::Color::WHITE)
|
||||
def initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :tiled, left: 1, top: 1, right: 1, bottom: 1, color: Gosu::Color::WHITE, render_mode: :default)
|
||||
@image = get_image(image_path) if image_path
|
||||
|
||||
@x = x
|
||||
@@ -25,6 +25,7 @@ module CyberarmEngine
|
||||
@bottom = bottom
|
||||
|
||||
@color = color
|
||||
@render_mode = render_mode
|
||||
|
||||
nine_slice if @image
|
||||
end
|
||||
@@ -121,58 +122,58 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def draw_stretched
|
||||
@segment_top_left.draw(@x, @y, @z, 1, 1, @color)
|
||||
@segment_top.draw(@x + @segment_top_left.width, @y, @z, width_scale, 1, @color) # SCALE X
|
||||
@segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z, 1, 1, @color)
|
||||
@segment_top_left.draw(@x, @y, @z, 1, 1, @color, @render_mode)
|
||||
@segment_top.draw(@x + @segment_top_left.width, @y, @z, width_scale, 1, @color, @render_mode) # SCALE X
|
||||
@segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z, 1, 1, @color, @render_mode)
|
||||
|
||||
@segment_right.draw((@x + @width) - @segment_right.width, @y + @top, @z, 1, height_scale, @color) # SCALE Y
|
||||
@segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z, 1, 1, @color)
|
||||
@segment_bottom.draw(@x + @segment_bottom_left.width, (@y + @height) - @segment_bottom.height, @z, width_scale, 1, @color) # SCALE X
|
||||
@segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z, 1, 1, @color)
|
||||
@segment_left.draw(@x, @y + @top, @z, 1, height_scale, @color) # SCALE Y
|
||||
@segment_right.draw((@x + @width) - @segment_right.width, @y + @top, @z, 1, height_scale, @color, @render_mode) # SCALE Y
|
||||
@segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z, 1, 1, @color, @render_mode)
|
||||
@segment_bottom.draw(@x + @segment_bottom_left.width, (@y + @height) - @segment_bottom.height, @z, width_scale, 1, @color, @render_mode) # SCALE X
|
||||
@segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z, 1, 1, @color, @render_mode)
|
||||
@segment_left.draw(@x, @y + @top, @z, 1, height_scale, @color, @render_mode) # SCALE Y
|
||||
|
||||
@segment_middle.draw(@x + @segment_top_left.width, @y + @segment_top.height, @z, width_scale, height_scale, @color) # SCALE X and SCALE Y
|
||||
@segment_middle.draw(@x + @segment_top_left.width, @y + @segment_top.height, @z, width_scale, height_scale, @color, @render_mode) # SCALE X and SCALE Y
|
||||
end
|
||||
|
||||
def draw_tiled
|
||||
@segment_top_left.draw(@x, @y, @z, 1, 1, @color)
|
||||
@segment_top_left.draw(@x, @y, @z, 1, 1, @color, @render_mode)
|
||||
|
||||
# p [width_scale, height_scale]
|
||||
|
||||
Gosu.clip_to(@x + @segment_top_left.width, @y, @segment_top.width * width_scale, @segment_top.height) do
|
||||
width_scale.ceil.times do |i|
|
||||
@segment_top.draw(@x + @segment_top_left.width + (@segment_top.width * i), @y, @z, 1, 1, @color) # SCALE X
|
||||
@segment_top.draw(@x + @segment_top_left.width + (@segment_top.width * i), @y, @z, 1, 1, @color, @render_mode) # SCALE X
|
||||
end
|
||||
end
|
||||
|
||||
@segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z, 1, 1, @color)
|
||||
@segment_top_right.draw((@x + @width) - @segment_top_right.width, @y, @z, 1, 1, @color, @render_mode)
|
||||
|
||||
Gosu.clip_to(@x + @width - @segment_top_right.width, @y + @top, @segment_right.width, @segment_right.height * height_scale) do
|
||||
height_scale.ceil.times do |i|
|
||||
@segment_right.draw((@x + @width) - @segment_right.width, @y + @top + (@segment_right.height * i), @z, 1, 1, @color) # SCALE Y
|
||||
@segment_right.draw((@x + @width) - @segment_right.width, @y + @top + (@segment_right.height * i), @z, 1, 1, @color, @render_mode) # SCALE Y
|
||||
end
|
||||
end
|
||||
|
||||
@segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z, 1, 1, @color)
|
||||
@segment_bottom_right.draw((@x + @width) - @segment_bottom_right.width, @y + @height - @segment_bottom_right.height, @z, 1, 1, @color, @render_mode)
|
||||
|
||||
Gosu.clip_to(@x + @segment_top_left.width, @y + @height - @segment_bottom.height, @segment_top.width * width_scale, @segment_bottom.height) do
|
||||
width_scale.ceil.times do |i|
|
||||
@segment_bottom.draw(@x + @segment_bottom_left.width + (@segment_bottom.width * i), (@y + @height) - @segment_bottom.height, @z, 1, 1, @color) # SCALE X
|
||||
@segment_bottom.draw(@x + @segment_bottom_left.width + (@segment_bottom.width * i), (@y + @height) - @segment_bottom.height, @z, 1, 1, @color, @render_mode) # SCALE X
|
||||
end
|
||||
end
|
||||
|
||||
@segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z, 1, 1, @color)
|
||||
@segment_bottom_left.draw(@x, (@y + @height) - @segment_bottom_left.height, @z, 1, 1, @color, @render_mode)
|
||||
|
||||
Gosu.clip_to(@x, @y + @top, @segment_left.width, @segment_left.height * height_scale) do
|
||||
height_scale.ceil.times do |i|
|
||||
@segment_left.draw(@x, @y + @top + (@segment_left.height * i), @z, 1, 1, @color) # SCALE Y
|
||||
@segment_left.draw(@x, @y + @top + (@segment_left.height * i), @z, 1, 1, @color, @render_mode) # SCALE Y
|
||||
end
|
||||
end
|
||||
|
||||
Gosu.clip_to(@x + @segment_top_left.width, @y + @segment_top.height, @width - (@segment_left.width + @segment_right.width), @height - (@segment_top.height + @segment_bottom.height)) do
|
||||
height_scale.ceil.times do |y|
|
||||
width_scale.ceil.times do |x|
|
||||
@segment_middle.draw(@x + @segment_top_left.width + (@segment_middle.width * x), @y + @segment_top.height + (@segment_middle.height * y), @z, 1, 1, @color) # SCALE X and SCALE Y
|
||||
@segment_middle.draw(@x + @segment_top_left.width + (@segment_middle.width * x), @y + @segment_top.height + (@segment_middle.height * y), @z, 1, 1, @color, @render_mode) # SCALE X and SCALE Y
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
module CyberarmEngine
|
||||
GUI_DEBUG = false
|
||||
|
||||
module Common
|
||||
ImageBlob = Data.define(:to_blob, :columns, :rows)
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ module CyberarmEngine
|
||||
@visible = !@options.key?(:visible) ? true : @options[:visible]
|
||||
@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]
|
||||
|
||||
@style = Style.new(options)
|
||||
@@ -215,6 +215,7 @@ module CyberarmEngine
|
||||
event(:blur)
|
||||
|
||||
event(:changed)
|
||||
event(:size_changed)
|
||||
end
|
||||
|
||||
def enter(_sender)
|
||||
@@ -339,7 +340,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
Gosu.draw_line(
|
||||
@@ -393,7 +394,7 @@ module CyberarmEngine
|
||||
|
||||
def width
|
||||
if visible?
|
||||
inner_width + @width
|
||||
inner_width + content_width
|
||||
else
|
||||
0
|
||||
end
|
||||
@@ -417,7 +418,7 @@ module CyberarmEngine
|
||||
|
||||
def height
|
||||
if visible?
|
||||
inner_height + @height
|
||||
inner_height + content_height
|
||||
else
|
||||
0
|
||||
end
|
||||
@@ -487,6 +488,8 @@ module CyberarmEngine
|
||||
|
||||
new_size = if size.is_a?(Float) && size.between?(0.0, 1.0)
|
||||
(@parent.send(:"content_#{dimension}") * size).floor - send(:"noncontent_#{dimension}").floor
|
||||
elsif size.is_a?(Numeric)
|
||||
(size - send(:"noncontent_#{dimension}")).floor
|
||||
else
|
||||
size
|
||||
end
|
||||
@@ -515,7 +518,7 @@ module CyberarmEngine
|
||||
|
||||
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.styled(:fill) }.count.to_f # include self since we're dividing
|
||||
fill_siblings = @parent.children.select { |c| c.styled(:fill) && c.visible? }.count.to_f # include self since we're dividing
|
||||
|
||||
available_space = ((@parent.content_height - (@parent.children.reject { |c| c.styled(: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.
|
||||
@@ -576,6 +579,8 @@ module CyberarmEngine
|
||||
|
||||
@old_width = width
|
||||
@old_height = height
|
||||
|
||||
publish(:size_changed)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -88,17 +88,20 @@ module CyberarmEngine
|
||||
|
||||
Gosu.translate(@scroll_position.x, @scroll_position.y) do
|
||||
@children.each(&:draw)
|
||||
|
||||
@children.each do |child|
|
||||
next unless child.visible?
|
||||
|
||||
child.debug_draw
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@children.each(&:debug_draw)
|
||||
debug_draw
|
||||
end
|
||||
|
||||
def debug_draw
|
||||
super
|
||||
|
||||
@children.each(&:debug_draw)
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -203,9 +206,9 @@ module CyberarmEngine
|
||||
|
||||
case styled(:v_align)
|
||||
when :center
|
||||
@y = parent.y + parent.styled(:margin_top) + parent.height / 2 - height / 2
|
||||
@y = parent.y + parent.outer_height / 2 - outer_height / 2
|
||||
when :bottom
|
||||
@y = parent.y + parent.styled(:margin_top) + parent.height - height
|
||||
@y = parent.y + parent.outer_height - outer_height
|
||||
end
|
||||
end
|
||||
|
||||
@@ -214,9 +217,9 @@ module CyberarmEngine
|
||||
|
||||
case styled(:h_align)
|
||||
when :center
|
||||
@x = parent.x + parent.styled(:margin_left) + parent.width / 2 - width / 2
|
||||
@x = parent.x + parent.outer_width / 2 - outer_width / 2
|
||||
when :right
|
||||
@x = parent.x + parent.styled(:margin_left) + parent.width - width
|
||||
@x = parent.x + parent.outer_width - outer_width
|
||||
end
|
||||
end
|
||||
|
||||
@@ -285,7 +288,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def position_on_next_line(element) # Flow
|
||||
@current_position.x = 0
|
||||
@current_position.x = styled(:margin_left) + styled(:padding_left)
|
||||
@current_position.y += tallest_neighbor(element, @current_position.y).outer_height
|
||||
|
||||
element.x = @current_position.x
|
||||
|
||||
@@ -98,7 +98,15 @@ module CyberarmEngine
|
||||
Stats.frame.start_timing(:gui_element_recalculate_requests)
|
||||
|
||||
# puts "PENDING REQUESTS: #{@pending_element_recalculate_requests.size}" if @pending_element_recalculate_requests.size.positive?
|
||||
@pending_element_recalculate_requests.shift(&:recalculate)
|
||||
while (e = @pending_element_recalculate_requests.shift)
|
||||
# its pointless to recalculate individual elements when we've been asked to recalculate the whole gui
|
||||
if @pending_recalculate_request
|
||||
@pending_element_recalculate_requests.clear
|
||||
break
|
||||
end
|
||||
|
||||
e.recalculate
|
||||
end
|
||||
|
||||
Stats.frame.end_timing(:gui_element_recalculate_requests)
|
||||
|
||||
@@ -231,6 +239,9 @@ module CyberarmEngine
|
||||
redirect_mouse_button(:right)
|
||||
when Gosu::KB_F5
|
||||
request_recalculate
|
||||
when Gosu::KB_F12
|
||||
CyberarmEngine.const_set(:GUI_DEBUG, !CyberarmEngine::GUI_DEBUG)
|
||||
request_repaint
|
||||
end
|
||||
|
||||
@focus.button_down(id) if @focus.respond_to?(:button_down)
|
||||
|
||||
Reference in New Issue
Block a user