mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-05-06 07:58:15 +00:00
Improved handling of nine slice backgrounds, fixed scroll height, fixed container v/h_align
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
class BackgroundNineSlice
|
class BackgroundNineSlice
|
||||||
include CyberarmEngine::Common
|
include CyberarmEngine::Common
|
||||||
attr_accessor :x, :y, :z, :width, :height, :left, :top, :right, :bottom, :mode, :color
|
attr_accessor :x, :y, :z, :width, :height, :mode, :color
|
||||||
attr_reader :image
|
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)
|
||||||
@image = get_image(image_path) if image_path
|
@image = get_image(image_path) if image_path
|
||||||
@@ -32,8 +32,43 @@ module CyberarmEngine
|
|||||||
nine_slice if @image && old_image != @image
|
nine_slice if @image && old_image != @image
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_edges(left: @left, right: @right, top: @top, bottom: @bottom)
|
||||||
|
changed = [left == @left, right == @right, top == @top, bottom == @bottom].any?(false)
|
||||||
|
|
||||||
|
@left = left
|
||||||
|
@top = top
|
||||||
|
@right = right
|
||||||
|
@bottom = bottom
|
||||||
|
|
||||||
|
nine_slice if changed
|
||||||
|
end
|
||||||
|
|
||||||
|
def left=(n)
|
||||||
|
nine_slice if n != @left
|
||||||
|
@left = n
|
||||||
|
n
|
||||||
|
end
|
||||||
|
|
||||||
|
def right=(n)
|
||||||
|
nine_slice if n != @right
|
||||||
|
@right = n
|
||||||
|
n
|
||||||
|
end
|
||||||
|
|
||||||
|
def top=(n)
|
||||||
|
nine_slice if n != @top
|
||||||
|
@top = n
|
||||||
|
n
|
||||||
|
end
|
||||||
|
|
||||||
|
def bottom=(n)
|
||||||
|
nine_slice if n != @bottom
|
||||||
|
@bottom = n
|
||||||
|
n
|
||||||
|
end
|
||||||
|
|
||||||
def nine_slice
|
def nine_slice
|
||||||
# pp [@left, @top, @right, @bottom, @image.width]
|
# pp [@left, @top, @right, @bottom, @image.width, @image.height]
|
||||||
|
|
||||||
@segment_top_left = @image.subimage(0, 0, @left, @top)
|
@segment_top_left = @image.subimage(0, 0, @left, @top)
|
||||||
@segment_top_right = @image.subimage(@image.width - @right, 0, @right, @top)
|
@segment_top_right = @image.subimage(@image.width - @right, 0, @right, @top)
|
||||||
@@ -92,6 +127,7 @@ module CyberarmEngine
|
|||||||
@segment_bottom.draw(@x + @segment_bottom_left.width, (@y + @height) - @segment_bottom.height, @z, width_scale, 1, @color) # SCALE X
|
@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_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_left.draw(@x, @y + @top, @z, 1, height_scale, @color) # 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) # SCALE X and SCALE Y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -135,10 +135,12 @@ module CyberarmEngine
|
|||||||
|
|
||||||
@background_nine_slice_canvas.color = safe_style_fetch(:background_nine_slice_color) || Gosu::Color::WHITE
|
@background_nine_slice_canvas.color = safe_style_fetch(:background_nine_slice_color) || Gosu::Color::WHITE
|
||||||
|
|
||||||
@background_nine_slice_canvas.left = safe_style_fetch(:background_nine_slice_left, :background_nine_slice_from_edge)
|
@background_nine_slice_canvas.set_edges(
|
||||||
@background_nine_slice_canvas.top = safe_style_fetch(:background_nine_slice_top, :background_nine_slice_from_edge)
|
left: safe_style_fetch(:background_nine_slice_left, :background_nine_slice_from_edge) || 1,
|
||||||
@background_nine_slice_canvas.right = safe_style_fetch(:background_nine_slice_right, :background_nine_slice_from_edge)
|
top: safe_style_fetch(:background_nine_slice_top, :background_nine_slice_from_edge) || 1,
|
||||||
@background_nine_slice_canvas.bottom = safe_style_fetch(:background_nine_slice_bottom, :background_nine_slice_from_edge)
|
right: safe_style_fetch(:background_nine_slice_right, :background_nine_slice_from_edge) || 1,
|
||||||
|
bottom: safe_style_fetch(:background_nine_slice_bottom, :background_nine_slice_from_edge) || 1
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_background_image
|
def set_background_image
|
||||||
@@ -457,9 +459,9 @@ module CyberarmEngine
|
|||||||
|
|
||||||
pairs_ << a_ unless pairs_.last == a_
|
pairs_ << a_ unless pairs_.last == a_
|
||||||
|
|
||||||
@cached_scroll_height = pairs_.sum { |pair| + styled(:padding_top) + styled(:border_thickness_top) + pair.map(&:outer_height).max } + styled(:padding_bottom) + styled(:border_thickness_bottom)
|
@cached_scroll_height = pairs_.sum { |pair| pair.map(&:outer_height).max } + noncontent_height
|
||||||
else
|
else
|
||||||
@cached_scroll_height = styled(:padding_top) + styled(:border_thickness_top) + @children.sum(&:outer_height) + styled(:padding_bottom) + styled(:border_thickness_bottom)
|
@cached_scroll_height = noncontent_height + @children.sum(&:outer_height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -197,9 +197,9 @@ module CyberarmEngine
|
|||||||
|
|
||||||
case styled(:v_align)
|
case styled(:v_align)
|
||||||
when :center
|
when :center
|
||||||
@y = parent.y + parent.height / 2 - height / 2
|
@y = parent.y + parent.styled(:margin_top) + parent.height / 2 - height / 2
|
||||||
when :bottom
|
when :bottom
|
||||||
@y = parent.y + parent.height - height
|
@y = parent.y + parent.styled(:margin_top) + parent.height - height
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -208,9 +208,9 @@ module CyberarmEngine
|
|||||||
|
|
||||||
case styled(:h_align)
|
case styled(:h_align)
|
||||||
when :center
|
when :center
|
||||||
@x = parent.x + parent.width / 2 - width / 2
|
@x = parent.x + parent.styled(:margin_left) + parent.width / 2 - width / 2
|
||||||
when :right
|
when :right
|
||||||
@x = parent.x + parent.width - width
|
@x = parent.x + parent.styled(:margin_left) + parent.width - width
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user