mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-03-22 03:56:13 +00:00
Compare commits
11 Commits
v0.24.5
...
4ce6c1f499
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ce6c1f499 | |||
| 958d4e65f9 | |||
| 0519253e03 | |||
| 97055885a6 | |||
| b5912de980 | |||
| b0376d85d9 | |||
| a30d66fafb | |||
| 0fac4a0397 | |||
| 498cf06916 | |||
| 1f57dfd38c | |||
| 76a8bf95c7 |
@@ -1,7 +1,7 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
cyberarm_engine (0.24.4)
|
||||
cyberarm_engine (0.24.5)
|
||||
gosu (~> 1.1)
|
||||
|
||||
GEM
|
||||
@@ -13,6 +13,7 @@ GEM
|
||||
|
||||
PLATFORMS
|
||||
x64-mingw-ucrt
|
||||
x86_64-linux
|
||||
|
||||
DEPENDENCIES
|
||||
bundler (~> 2.2)
|
||||
@@ -21,4 +22,4 @@ DEPENDENCIES
|
||||
rake (~> 13.0)
|
||||
|
||||
BUNDLED WITH
|
||||
2.5.3
|
||||
2.6.8
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -68,3 +68,9 @@ require_relative "cyberarm_engine/game_state"
|
||||
require_relative "cyberarm_engine/ui/gui_state"
|
||||
|
||||
require_relative "cyberarm_engine/builtin/intro_state"
|
||||
|
||||
if RUBY_ENGINE != "mruby" && defined?(StackProf)
|
||||
at_exit do
|
||||
StackProf.results("./_stackprof.dmp")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
module CyberarmEngine
|
||||
module Common
|
||||
ImageBlob = Data.define(:to_blob, :columns, :rows)
|
||||
|
||||
def push_state(klass, options = {})
|
||||
window.push_state(klass, options)
|
||||
end
|
||||
@@ -85,7 +87,8 @@ module CyberarmEngine
|
||||
unless asset
|
||||
instance = nil
|
||||
instance = if klass == Gosu::Image
|
||||
klass.new(path, retro: retro, tileable: tileable)
|
||||
path_or_blob = path.is_a?(String) ? path : ImageBlob.new(path.to_blob, path.width, path.height)
|
||||
klass.new(path_or_blob, retro: retro, tileable: tileable)
|
||||
else
|
||||
klass.new(path)
|
||||
end
|
||||
|
||||
@@ -33,12 +33,23 @@ module Gosu
|
||||
#
|
||||
# @return [void]
|
||||
def self.draw_arc(x, y, radius, percentage = 1.0, segments = 128, thickness = 4, color = Gosu::Color::WHITE, z = 0, mode = :default)
|
||||
segments = 360.0 / segments
|
||||
|
||||
return if percentage == 0.0
|
||||
|
||||
0.step((359 * percentage), percentage > 0 ? segments : -segments) do |angle|
|
||||
angle2 = angle + segments
|
||||
angle_per_segment = 360.0 / segments
|
||||
arc_completion = 360 * percentage
|
||||
next_segment_angle = angle_per_segment
|
||||
|
||||
angle = 0
|
||||
loop do
|
||||
break if angle >= arc_completion
|
||||
|
||||
if angle + angle_per_segment > arc_completion
|
||||
next_segment_angle = arc_completion - angle
|
||||
else
|
||||
next_segment_angle = angle_per_segment
|
||||
end
|
||||
|
||||
angle2 = angle + next_segment_angle
|
||||
|
||||
point_a_left_x = x + Gosu.offset_x(angle, radius - thickness)
|
||||
point_a_left_y = y + Gosu.offset_y(angle, radius - thickness)
|
||||
@@ -93,6 +104,8 @@ module Gosu
|
||||
z, mode
|
||||
)
|
||||
end
|
||||
|
||||
angle += next_segment_angle
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,13 +7,13 @@ module CyberarmEngine
|
||||
attr_reader :children, :gui_state, :scroll_position, :scroll_target_position
|
||||
|
||||
def self.current_container
|
||||
@@current_container
|
||||
@current_container
|
||||
end
|
||||
|
||||
def self.current_container=(container)
|
||||
raise ArgumentError, "Expected container to an an instance of CyberarmEngine::Element::Container, got #{container.class}" unless container.is_a?(CyberarmEngine::Element::Container)
|
||||
|
||||
@@current_container = container
|
||||
@current_container = container
|
||||
end
|
||||
|
||||
def initialize(options = {}, block = nil)
|
||||
@@ -26,6 +26,11 @@ module CyberarmEngine
|
||||
@scroll_chunk = 120
|
||||
@scroll_speed = 40
|
||||
|
||||
if @gui_state
|
||||
@width = window.width
|
||||
@height = window.height
|
||||
end
|
||||
|
||||
@text_color = options[:color]
|
||||
|
||||
@children = []
|
||||
@@ -34,7 +39,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def build
|
||||
@block.call(self) if @block
|
||||
@block&.call(self)
|
||||
|
||||
root.gui_state.request_recalculate_for(self)
|
||||
end
|
||||
@@ -53,7 +58,7 @@ module CyberarmEngine
|
||||
old_container = CyberarmEngine::Element::Container.current_container
|
||||
|
||||
CyberarmEngine::Element::Container.current_container = self
|
||||
block.call(self) if block
|
||||
block&.call(self)
|
||||
|
||||
CyberarmEngine::Element::Container.current_container = old_container
|
||||
|
||||
@@ -66,7 +71,7 @@ module CyberarmEngine
|
||||
old_container = CyberarmEngine::Element::Container.current_container
|
||||
|
||||
CyberarmEngine::Element::Container.current_container = self
|
||||
block.call(self) if block
|
||||
block&.call(self)
|
||||
|
||||
CyberarmEngine::Element::Container.current_container = old_container
|
||||
|
||||
@@ -89,9 +94,7 @@ module CyberarmEngine
|
||||
def debug_draw
|
||||
super
|
||||
|
||||
@children.each do |child|
|
||||
child.debug_draw
|
||||
end
|
||||
@children.each(&:debug_draw)
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -111,7 +114,7 @@ module CyberarmEngine
|
||||
|
||||
case child
|
||||
when Container
|
||||
if element = child.hit_element?(child_x, child_y)
|
||||
if (element = child.hit_element?(child_x, child_y))
|
||||
return element
|
||||
end
|
||||
else
|
||||
@@ -221,7 +224,7 @@ module CyberarmEngine
|
||||
|
||||
update_child_element_visibity(child)
|
||||
end
|
||||
# puts "TOOK: #{Gosu.milliseconds - t}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}'s #{@children.count} children"
|
||||
# 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
|
||||
|
||||
@@ -299,15 +302,15 @@ module CyberarmEngine
|
||||
return unless @style.scroll
|
||||
|
||||
# Allow overscrolling UP, only if one can scroll DOWN
|
||||
if height < scroll_height
|
||||
if @scroll_target_position.y > 0
|
||||
@scroll_target_position.y = @scroll_chunk
|
||||
else
|
||||
@scroll_target_position.y += @scroll_chunk
|
||||
end
|
||||
return unless height < scroll_height
|
||||
|
||||
return :handled
|
||||
if @scroll_target_position.y.positive?
|
||||
@scroll_target_position.y = @scroll_chunk
|
||||
else
|
||||
@scroll_target_position.y += @scroll_chunk
|
||||
end
|
||||
|
||||
:handled
|
||||
end
|
||||
|
||||
def mouse_wheel_down(sender, x, y)
|
||||
@@ -315,13 +318,13 @@ module CyberarmEngine
|
||||
|
||||
return unless height < scroll_height
|
||||
|
||||
if @scroll_target_position.y > 0
|
||||
if @scroll_target_position.y.positive?
|
||||
@scroll_target_position.y = -@scroll_chunk
|
||||
else
|
||||
@scroll_target_position.y -= @scroll_chunk
|
||||
end
|
||||
|
||||
return :handled
|
||||
:handled
|
||||
end
|
||||
|
||||
def scroll_jump_to_top(sender, x, y)
|
||||
@@ -330,7 +333,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = 0
|
||||
@scroll_target_position.y = 0
|
||||
|
||||
return :handled
|
||||
:handled
|
||||
end
|
||||
|
||||
def scroll_jump_to_end(sender, x, y)
|
||||
@@ -339,7 +342,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = -max_scroll_height
|
||||
@scroll_target_position.y = -max_scroll_height
|
||||
|
||||
return :handled
|
||||
:handled
|
||||
end
|
||||
|
||||
def scroll_page_up(sender, x, y)
|
||||
@@ -349,7 +352,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = 0 if @scroll_position.y > 0
|
||||
@scroll_target_position.y = @scroll_position.y
|
||||
|
||||
return :handled
|
||||
:handled
|
||||
end
|
||||
|
||||
def scroll_page_down(sender, x, y)
|
||||
@@ -359,7 +362,7 @@ module CyberarmEngine
|
||||
@scroll_position.y = -max_scroll_height if @scroll_position.y < -max_scroll_height
|
||||
@scroll_target_position.y = @scroll_position.y
|
||||
|
||||
return :handled
|
||||
:handled
|
||||
end
|
||||
|
||||
def scroll_top
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -54,24 +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_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)
|
||||
|
||||
@root_container.recalculate
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module CyberarmEngine
|
||||
NAME = "InDev".freeze
|
||||
VERSION = "0.24.5".freeze
|
||||
VERSION = "0.25.0".freeze
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user