mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 21:22:33 +00:00
Packing now works! (Broke clicked_#{button}_mouse_button events)
This commit is contained in:
@@ -36,11 +36,11 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
Gosu.clip_to(@x, @y, @width, @height) do
|
# Gosu.clip_to(@x, @y, @width, @height) do
|
||||||
background
|
background
|
||||||
|
|
||||||
@children.each(&:draw)
|
@children.each(&:draw)
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@@ -79,12 +79,23 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
@current_position = Vector.new(@margin_left + @x, @margin_top + @y)
|
@current_position = Vector.new(@margin_left, @margin_top)
|
||||||
|
|
||||||
layout
|
layout
|
||||||
|
|
||||||
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.width }.max + @margin_right || 0)
|
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.width }.max + @margin_right || 0)
|
||||||
@height = @max_height ? @max_height : (@children.map {|c| c.y + c.height}.max + @margin_bottom || 0)
|
@height = @max_height ? @max_height : (@children.map {|c| c.y + c.height}.max + @margin_bottom || 0)
|
||||||
|
|
||||||
|
# Move child to parent after positioning
|
||||||
|
@children.each do |child|
|
||||||
|
child.x += @x
|
||||||
|
child.y += @y
|
||||||
|
|
||||||
|
# Fix child being displaced
|
||||||
|
child.recalculate
|
||||||
|
end
|
||||||
|
# puts unless @parent
|
||||||
|
# puts "<#{self.class} X: #{@x}, Y: #{@y}, width: #{@width}, height: #{@height} (children: #{@children.count}) [#{children.first.class}]"
|
||||||
end
|
end
|
||||||
|
|
||||||
def layout
|
def layout
|
||||||
@@ -92,7 +103,7 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def max_width
|
def max_width
|
||||||
@max_width ? @max_width : window.width
|
@max_width ? @max_width : window.width - (@parent ? @parent.margin_right + @margin_right : @margin_right)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fits_on_line?(element)
|
def fits_on_line?(element)
|
||||||
@@ -103,6 +114,8 @@ module CyberarmEngine
|
|||||||
element.x = @current_position.x
|
element.x = @current_position.x
|
||||||
element.y = @current_position.y
|
element.y = @current_position.y
|
||||||
|
|
||||||
|
element.recalculate
|
||||||
|
|
||||||
@current_position.x += element.width + element.margin_right
|
@current_position.x += element.width + element.margin_right
|
||||||
@current_position.x = @margin_left + @x if @current_position.x >= max_width
|
@current_position.x = @margin_left + @x if @current_position.x >= max_width
|
||||||
end
|
end
|
||||||
@@ -111,7 +124,23 @@ module CyberarmEngine
|
|||||||
element.x = @current_position.x
|
element.x = @current_position.x
|
||||||
element.y = @current_position.y
|
element.y = @current_position.y
|
||||||
|
|
||||||
|
element.recalculate
|
||||||
|
|
||||||
@current_position.y += element.height + element.margin_bottom
|
@current_position.y += element.height + element.margin_bottom
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# def mouse_wheel_up(sender, x, y)
|
||||||
|
# @children.each {|c| c.y -= @scroll_speed}
|
||||||
|
# @children.each {|c| c.recalculate}
|
||||||
|
# end
|
||||||
|
|
||||||
|
# def mouse_wheel_down(sender, x, y)
|
||||||
|
# @children.each {|c| c.y += @scroll_speed}
|
||||||
|
# @children.each {|c| c.recalculate}
|
||||||
|
# end
|
||||||
|
|
||||||
|
def value
|
||||||
|
@children.map {|c| c.class}.join(", ")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -4,14 +4,18 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def layout
|
def layout
|
||||||
@children.each do |child|
|
@children.each do |child|
|
||||||
child.recalculate
|
|
||||||
|
|
||||||
if fits_on_line?(child)
|
if fits_on_line?(child)
|
||||||
position_on_current_line(child)
|
position_on_current_line(child)
|
||||||
else
|
else
|
||||||
@current_position.x = @margin_left + @x
|
@current_position.x = @margin_left + @x
|
||||||
|
@current_position.y += child.height + child.margin_bottom
|
||||||
|
|
||||||
move_to_next_line(child)
|
child.x = @current_position.x
|
||||||
|
child.y = @current_position.y
|
||||||
|
|
||||||
|
child.recalculate
|
||||||
|
|
||||||
|
@current_position.x += child.width + child.margin_right
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ module CyberarmEngine
|
|||||||
if new_mouse_over
|
if new_mouse_over
|
||||||
new_mouse_over.publish(:enter) if new_mouse_over != @mouse_over
|
new_mouse_over.publish(:enter) if new_mouse_over != @mouse_over
|
||||||
new_mouse_over.publish(:hover)
|
new_mouse_over.publish(:hover)
|
||||||
|
# puts "#{new_mouse_over.class}[#{new_mouse_over.value}]: #{new_mouse_over.x}:#{new_mouse_over.y} #{new_mouse_over.width}:#{new_mouse_over.height}" if new_mouse_over != @mouse_over
|
||||||
end
|
end
|
||||||
@mouse_over.publish(:leave) if @mouse_over && new_mouse_over != @mouse_over
|
@mouse_over.publish(:leave) if @mouse_over && new_mouse_over != @mouse_over
|
||||||
@mouse_over = new_mouse_over
|
@mouse_over = new_mouse_over
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ module CyberarmEngine
|
|||||||
class Image < Element
|
class Image < Element
|
||||||
def initialize(path, options = {}, block = nil)
|
def initialize(path, options = {}, block = nil)
|
||||||
super(options, block)
|
super(options, block)
|
||||||
|
@path = path
|
||||||
|
|
||||||
@image = Gosu::Image.new(path, retro: @options[:image_retro])
|
@image = Gosu::Image.new(path, retro: @options[:image_retro])
|
||||||
if @options[:width].nonzero? && @options[:height].nonzero?
|
if @options[:width].nonzero? && @options[:height].nonzero?
|
||||||
@@ -35,5 +36,9 @@ module CyberarmEngine
|
|||||||
@width = @image.width * @scale_x
|
@width = @image.width * @scale_x
|
||||||
@height = @image.height * @scale_y
|
@height = @image.height * @scale_y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def value
|
||||||
|
@path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -4,8 +4,6 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def layout
|
def layout
|
||||||
@children.each do |child|
|
@children.each do |child|
|
||||||
child.recalculate
|
|
||||||
|
|
||||||
move_to_next_line(child)
|
move_to_next_line(child)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user