Compare commits

...

7 Commits

8 changed files with 67 additions and 68 deletions

View File

@@ -35,7 +35,7 @@ class Hello < CyberarmEngine::GuiState
background Gosu::Color::GRAY
stack do
label "Hello World!"
banner "Hello World!"
button "close" do
window.close

View File

@@ -69,6 +69,8 @@ require_relative "cyberarm_engine/ui/gui_state"
require_relative "cyberarm_engine/builtin/intro_state"
at_exit do
StackProf.results("./_prof.txt") if RUBY_ENGINE != "mruby" && defined?(StackProf)
if RUBY_ENGINE != "mruby" && defined?(StackProf)
at_exit do
StackProf.results("./_stackprof.dmp")
end
end

View File

@@ -35,36 +35,14 @@ module CyberarmEngine
end
def update
origin_x = (@x + (@width / 2))
origin_y = (@y + (@height / 2))
points = [
@top_left = Vector.new(@x, @y),
@top_right = Vector.new(@x + @width, @y),
@bottom_left = Vector.new(@x, @y + @height),
@bottom_right = Vector.new(@x + @width, @y + @height)
]
[@top_left, @top_right, @bottom_left, @bottom_right].each do |vector|
temp_x = vector.x - origin_x
temp_y = vector.y - origin_y
# 90 is up here, while gosu uses 0 for up.
radians = (@angle + 90).gosu_to_radians
vector.x = (@x + (@width / 2)) + ((temp_x * Math.cos(radians)) - (temp_y * Math.sin(radians)))
vector.y = (@y + (@height / 2)) + ((temp_x * Math.sin(radians)) + (temp_y * Math.cos(radians)))
end
# [
# [:top, @top_left, @top_right],
# [:right, @top_right, @bottom_right],
# [:bottom, @bottom_right, @bottom_left],
# [:left, @bottom_left, @top_left]
# ].each do |edge|
# points.each do |point|
# puts "#{edge.first} -> #{shortest_distance(point, edge[1], edge[2])}"
# end
# end
@top_left.x = @x
@top_left.y = @y
@top_right.x = @x + @width
@top_right.y = @y
@bottom_left.x = @x
@bottom_left.y = @y + @height
@bottom_right.x = @x + @width
@bottom_right.y = @y + @height
end
def shortest_distance(point, la, lb)

View File

@@ -210,7 +210,7 @@ module CyberarmEngine
end
end
t = Gosu.milliseconds
# t = Gosu.milliseconds
# Move children to parent after positioning
@children.each do |child|
child.x += (@x + @style.border_thickness_left) - style.margin_left
@@ -224,7 +224,7 @@ module CyberarmEngine
update_child_element_visibity(child)
end
puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{object_id.to_s(16)}'s #{@children.count} children" if is_root?
# puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{object_id.to_s(16)}'s #{@children.count} children" if is_root?
update_background

View File

@@ -16,6 +16,8 @@ module CyberarmEngine
)
@raw_text = text
@text_width = @text.width
@text_height = @text.height
end
def update
@@ -29,7 +31,7 @@ module CyberarmEngine
def render
# Gosu.clip_to is too expensive to always use so check if we actually need it.
if @text.width > width || @text.height > height
if @text_width > width || @text_height > height
Gosu.clip_to(@x, @y, width, height) do
@text.draw
end
@@ -53,8 +55,12 @@ module CyberarmEngine
handle_text_wrapping(_width)
@width = _width || @text.width.floor
@height = _height || @text.height.floor
# Update cached text width and height
@text_width = @text.width
@text_height = @text.height
@width = _width || @text_width.floor
@height = _height || @text_height.floor
@text.y = @style.border_thickness_top + @style.padding_top + @y
@text.z = @z + 3
@@ -64,26 +70,26 @@ module CyberarmEngine
when :left
@text.x = @style.border_thickness_left + @style.padding_left + @x
when :center
@text.x = if @text.width <= width
@x + width / 2 - @text.width / 2
@text.x = if @text_width <= width
@x + width / 2 - @text_width / 2
else # Act as left aligned
@style.border_thickness_left + @style.padding_left + @x
end
when :right
@text.x = @x + outer_width - (@text.width + @style.border_thickness_right + @style.padding_right)
@text.x = @x + outer_width - (@text_width + @style.border_thickness_right + @style.padding_right)
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
@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)
@text.y = @y + outer_height - (@text_height + @style.border_thickness_bottom + @style.padding_bottom)
end
end

View File

@@ -54,27 +54,29 @@ module CyberarmEngine
end
def draw
# t = Gosu.milliseconds
# report_recalculate_time = @pending_recalculate_request || @pending_element_recalculate_requests.size.positive?
StackProf.start(mode: :wall) if RUBY_ENGINE != "mruby" && defined?(StackProf)
Stats.frame.start_timing(:gui_element_recalculate_requests)
# puts "PENDING REQUESTS: #{@pending_element_recalculate_requests.size}" if @pending_element_recalculate_requests.size.positive?
@pending_recalculate_request = true if @pending_element_recalculate_requests.size.positive?
# @pending_element_recalculate_requests.each(&:recalculate)
@pending_element_recalculate_requests.clear
@pending_element_recalculate_requests.shift(&:recalculate)
Stats.frame.end_timing(:gui_element_recalculate_requests)
if @pending_recalculate_request
Stats.frame.start_timing(:gui_recalculate)
StackProf.start(mode: :wall) if RUBY_ENGINE != "mruby" && defined?(StackProf)
@root_container.recalculate
StackProf.stop if RUBY_ENGINE != "mruby" && defined?(StackProf)
Stats.frame.start_timing(:gui_recalculate)
while(@pending_recalculate_request)
@pending_recalculate_request = false
Stats.frame.end_timing(:gui_recalculate)
@root_container.recalculate
end
StackProf.stop if RUBY_ENGINE != "mruby" && defined?(StackProf)
Stats.frame.end_timing(:gui_recalculate)
# puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{object_id.to_s(16)}" if report_recalculate_time && Gosu.milliseconds - t > 0
super
if @menu

View File

@@ -19,6 +19,30 @@ module CyberarmEngine
class Style
attr_reader :hash
%i[
x y z width height min_width min_height max_width max_height color background
background_image background_image_mode background_image_color
background_nine_slice background_nine_slice_mode background_nine_slice_color background_nine_slice_from_edge
background_nine_slice_left background_nine_slice_top background_nine_slice_right background_nine_slice_bottom
border_color border_color_left border_color_right border_color_top border_color_bottom
border_thickness border_thickness_left border_thickness_right border_thickness_top border_thickness_bottom
padding padding_left padding_right padding_top padding_bottom
margin margin_left margin_right margin_top margin_bottom
background_canvas background_nine_slice_canvas background_image_canvas border_canvas
fraction_background scroll fill text_wrap v_align h_align delay tag
image_width image_height
default hover active disabled
].each do |item|
define_method(item) do
@hash[item]
end
define_method(:"#{item}=") do |value|
@hash[item] = value
end
end
def initialize(hash = {})
h = hash
# h = Marshal.load(Marshal.dump(hash))
@@ -33,18 +57,5 @@ module CyberarmEngine
@hash = h
end
def method_missing(method, *args)
if method.to_s.end_with?("=")
raise "Did not expect more than 1 argument" if args.size > 1
@hash[method.to_s.sub("=", "").to_sym] = args.first
elsif args.empty?
@hash[method]
else
raise ArgumentError, "Did not expect arguments"
end
end
end
end

View File

@@ -1,4 +1,4 @@
module CyberarmEngine
NAME = "InDev".freeze
VERSION = "0.24.5".freeze
VERSION = "0.25.0".freeze
end