Compare commits

...

20 Commits

Author SHA1 Message Date
3102bbe4c3 Fixed HOME/END PAGE UP/DOWN keys incorrectly scrolling container when an EditLine or EditBox has focus 2026-03-19 16:49:53 -05:00
530e01d939 Fixed EditBox causing crash if parent container is scrolled and EditBox is clicked 2026-03-19 16:22:13 -05:00
752a4752ba Bump version 2026-01-28 10:53:34 -06:00
e4a4f779b0 Added Result class to make writing failure resistant code easier 2026-01-28 10:36:30 -06:00
958d4e65f9 Bump version 2026-01-09 09:36:08 -06:00
0519253e03 Improved GuiState to fully recalculate before returning from draw 2026-01-09 09:29:41 -06:00
97055885a6 Cache TextBlock text width and height 2026-01-09 08:59:06 -06:00
b5912de980 Remove unused code from Background#update, improves performance notably. 2026-01-09 08:34:59 -06:00
b0376d85d9 Reduce allocations in Background 2026-01-09 08:26:55 -06:00
a30d66fafb Refactored Style to remove usage of method_missing 2026-01-09 08:20:27 -06:00
0fac4a0397 Add StackProf hooks for profile recalculate 2026-01-08 22:16:54 -06:00
498cf06916 Style fixes, wip layout speed up work 2025-12-01 10:03:45 -06:00
1f57dfd38c Update to support Gosu 2.0.0 (Gosu::Image taking in a Gosu::Image fails) 2025-11-29 11:27:27 -06:00
76a8bf95c7 Update Gosu.draw_arc to support partial segments 2025-11-29 11:11:53 -06:00
1c25eeb32b Bump version 2025-06-24 13:55:40 -05:00
eabad4abd4 Refactored mesh handling, imported AABB tree implementation from I-MIC FPS 2025-05-03 18:21:11 -05:00
b3561f02c1 Fixed edit_line's with prefilled values having an offset_x that hides the text unless caret is manually moved left 2024-04-09 09:27:12 -05:00
9694cc2270 Fix compatibility issue with gosu 2.0 pre-release 2024-03-12 19:20:25 -05:00
a7df9a660d Bump version 2024-03-05 14:16:25 -06:00
d2f757eb23 Fixed hidden Container elements not recalculating when becoming visible 2024-03-05 14:16:07 -06:00
27 changed files with 519 additions and 161 deletions

25
Gemfile.lock Normal file
View File

@@ -0,0 +1,25 @@
PATH
remote: .
specs:
cyberarm_engine (0.24.5)
gosu (~> 1.1)
GEM
remote: https://rubygems.org/
specs:
gosu (1.4.6)
minitest (5.25.5)
rake (13.2.1)
PLATFORMS
x64-mingw-ucrt
x86_64-linux
DEPENDENCIES
bundler (~> 2.2)
cyberarm_engine!
minitest (~> 5.0)
rake (~> 13.0)
BUNDLED WITH
2.6.8

View File

@@ -1,14 +1,15 @@
#version 330 core
@include "light_struct"
out vec4 frag_color;
@include "light_struct"
const int DIRECTIONAL = 0;
const int POINT = 1;
const int SPOT = 2;
flat in Light out_lights[7];
in vec2 out_tex_coords;
flat in int out_light_count;
flat in Light out_lights[7];
uniform sampler2D diffuse, position, texcoord, normal, depth;
@@ -27,43 +28,88 @@ vec4 directionalLight(Light light) {
return vec4(_diffuse + _ambient + _specular, 1.0);
}
vec4 pointLight(Light light) {
return vec4(0.25, 0.25, 0.25, 1);
}
vec4 spotLight(Light light) {
return vec4(0.5, 0.5, 0.5, 1);
}
vec4 calculateLighting(Light light) {
vec4 result;
// switch(light.type) {
// case DIRECTIONAL: {
// result = directionalLight(light);
// }
// case SPOT: {
// result = spotLight(light);
// }
// default: {
// result = pointLight(light);
// }
// }
if (light.type == DIRECTIONAL) {
result = directionalLight(light);
} else {
result = pointLight(light);
}
return result;
}
void main() {
frag_color = vec4(0.0);
Light light;
light.type = DIRECTIONAL;
for(int i = 0; i < out_light_count; i++)
{
frag_color += texture(diffuse, out_tex_coords) * calculateLighting(out_lights[i]);
}
light.position = vec3(100, 100, 100);
light.diffuse = vec3(0.5, 0.5, 0.5);
light.ambient = vec3(0.8, 0.8, 0.8);
light.specular = vec3(0.2, 0.2, 0.2);
light.intensity = 1.0;
frag_color = texture(diffuse, out_tex_coords) * directionalLight(light);
}
// #version 330 core
// @include "light_struct"
// out vec4 frag_color;
// const int DIRECTIONAL = 0;
// const int POINT = 1;
// const int SPOT = 2;
// in vec2 out_tex_coords;
// flat in int out_light_count;
// flat in Light out_lights[7];
// uniform sampler2D diffuse, position, texcoord, normal, depth;
// vec4 directionalLight(Light light) {
// vec3 norm = normalize(texture(normal, out_tex_coords).rgb);
// vec3 diffuse_color = texture(diffuse, out_tex_coords).rgb;
// vec3 frag_pos = texture(position, out_tex_coords).rgb;
// vec3 lightDir = normalize(light.position - frag_pos);
// float diff = max(dot(norm, lightDir), 0);
// vec3 _ambient = light.ambient;
// vec3 _diffuse = light.diffuse * diff;
// vec3 _specular = light.specular;
// return vec4(_diffuse + _ambient + _specular, 1.0);
// }
// vec4 pointLight(Light light) {
// return vec4(0.25, 0.25, 0.25, 1);
// }
// vec4 spotLight(Light light) {
// return vec4(0.5, 0.5, 0.5, 1);
// }
// vec4 calculateLighting(Light light) {
// vec4 result;
// // switch(light.type) {
// // case DIRECTIONAL: {
// // result = directionalLight(light);
// // }
// // case SPOT: {
// // result = spotLight(light);
// // }
// // default: {
// // result = pointLight(light);
// // }
// // }
// if (light.type == DIRECTIONAL) {
// result = directionalLight(light);
// } else {
// result = pointLight(light);
// }
// return result;
// }
// void main() {
// frag_color = vec4(0.0);
// for(int i = 0; i < out_light_count; i++)
// {
// frag_color += texture(diffuse, out_tex_coords) * calculateLighting(out_lights[i]);
// }
// }

View File

@@ -1,4 +1,4 @@
# version 330 core
#version 330 core
layout(location = 0) in vec3 in_position;
layout(location = 1) in vec3 in_color;

View File

@@ -9,6 +9,7 @@ require "json"
require_relative "cyberarm_engine/version"
require_relative "cyberarm_engine/stats"
require_relative "cyberarm_engine/result"
require_relative "cyberarm_engine/common"
@@ -67,12 +68,10 @@ require_relative "cyberarm_engine/ui/elements/menu_item"
require_relative "cyberarm_engine/game_state"
require_relative "cyberarm_engine/ui/gui_state"
require_relative "cyberarm_engine/model"
require_relative "cyberarm_engine/model_cache"
require_relative "cyberarm_engine/model/material"
require_relative "cyberarm_engine/model/model_object"
require_relative "cyberarm_engine/model/parser"
require_relative "cyberarm_engine/model/parsers/wavefront_parser"
require_relative "cyberarm_engine/model/parsers/collada_parser" if RUBY_ENGINE != "mruby" && defined?(Nokogiri)
require_relative "cyberarm_engine/builtin/intro_state"
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)
@@ -170,10 +148,11 @@ module CyberarmEngine
end
# Add <=> method to support Range based gradients
module Gosu
class Color
def <=>(_other)
self
end
end
end
# NOTE: Disabled, causes stack overflow 🙃
# module Gosu
# class Color
# def <=>(_other)
# self
# end
# end
# end

View File

@@ -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

View File

@@ -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

View File

@@ -1,5 +1,8 @@
module CyberarmEngine
class Model
include OpenGL
include CyberarmEngine
attr_accessor :objects, :materials, :vertices, :uvs, :texures, :normals, :faces, :colors, :bones, :material_file,
:current_material, :current_object, :vertex_count, :smoothing
attr_reader :position, :bounding_box, :textured_material, :file_path, :positions_buffer_id, :colors_buffer_id,
@@ -49,9 +52,9 @@ module CyberarmEngine
@objects.each { |o| @vertex_count += o.vertices.size }
# start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
# build_collision_tree
# puts " Building mesh collision tree took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) - start_time) / 1000.0).round(2)} seconds"
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
build_collision_tree
puts " Building mesh collision tree took #{((Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond) - start_time) / 1000.0).round(2)} seconds"
end
def parse(parser)
@@ -178,7 +181,7 @@ module CyberarmEngine
end
def build_collision_tree
@aabb_tree = IMICFPS::AABBTree.new
@aabb_tree = AABBTree.new
@faces.each do |face|
box = BoundingBox.new

View File

@@ -1,6 +1,6 @@
module CyberarmEngine
class Model
class ModelObject
class Mesh
attr_reader :id, :name, :vertices, :uvs, :normals, :materials, :bounding_box, :debug_color
attr_accessor :faces, :scale

View File

@@ -48,12 +48,12 @@ module CyberarmEngine
if _model
@model.current_object = _model
else
raise "Couldn't find ModelObject!"
raise "Couldn't find Mesh!"
end
end
def change_object(id, name)
@model.objects << Model::ModelObject.new(id, name)
@model.objects << Model::Mesh.new(id, name)
@model.current_object = @model.objects.last
end

View File

@@ -1,5 +1,6 @@
begin
require "opengl"
require "glu"
rescue LoadError
puts "Required gem is not installed, please install 'opengl-bindings' and try again."
exit(1)
@@ -8,7 +9,7 @@ end
module CyberarmEngine
def gl_error?
e = glGetError
if e != GL_NO_ERROR
if e != OpenGL::GL_NO_ERROR
warn "OpenGL error detected by handler at: #{caller[0]}"
warn " #{gluErrorString(e)} (#{e})\n"
exit if Window.instance&.exit_on_opengl_error?
@@ -38,3 +39,15 @@ require_relative "opengl/renderer/g_buffer"
require_relative "opengl/renderer/bounding_box_renderer"
require_relative "opengl/renderer/opengl_renderer"
require_relative "opengl/renderer/renderer"
require_relative "trees/aabb_tree_debug"
require_relative "trees/aabb_node"
require_relative "trees/aabb_tree"
require_relative "model"
require_relative "model_cache"
require_relative "model/material"
require_relative "model/mesh"
require_relative "model/parser"
require_relative "model/parsers/wavefront_parser"
require_relative "model/parsers/collada_parser" if RUBY_ENGINE != "mruby" && defined?(Nokogiri)

View File

@@ -1,5 +1,7 @@
module CyberarmEngine
class Light
include OpenGL
DIRECTIONAL = 0
POINT = 1
SPOT = 2

View File

@@ -1,5 +1,8 @@
module CyberarmEngine
class PerspectiveCamera
include OpenGL
include GLU
attr_accessor :position, :orientation, :aspect_ratio, :field_of_view,
:min_view_distance, :max_view_distance

View File

@@ -1,5 +1,7 @@
module CyberarmEngine
class GBuffer
include OpenGL
attr_reader :screen_vbo, :vertices, :uvs
attr_reader :width, :height

View File

@@ -1,5 +1,8 @@
module CyberarmEngine
class OpenGLRenderer
include OpenGL
include CyberarmEngine
@@immediate_mode_warning = false
attr_accessor :show_wireframe

View File

@@ -2,6 +2,7 @@ module CyberarmEngine
# Ref: https://github.com/vaiorabbit/ruby-opengl/blob/master/sample/OrangeBook/brick.rb
class Shader
include OpenGL
@@shaders = {} # Cache for {Shader} instances
PREPROCESSOR_CHARACTER = "@".freeze # magic character for preprocessor phase of {Shader} compilation
@@ -298,6 +299,7 @@ module CyberarmEngine
# @see Shader.use Shader.use
def use(&block)
return unless compiled?
raise "Another shader is already in use! #{Shader.active_shader.name.inspect}" if Shader.active_shader
Shader.active_shader = self

View File

@@ -0,0 +1,20 @@
module CyberarmEngine
# result pattern
class Result
attr_accessor :error, :data
def initialize(data: nil, error: nil)
@data = data
@error = error
end
def okay?
!@error
end
def error?
@error || @data.nil?
end
end
end

View File

@@ -0,0 +1,126 @@
# frozen_string_literal: true
module CyberarmEngine
class AABBTree
class AABBNode
attr_accessor :bounding_box, :parent, :object
attr_reader :a, :b
def initialize(parent:, object:, bounding_box:)
@parent = parent
@object = object
@bounding_box = bounding_box
@a = nil
@b = nil
end
def a=(leaf)
@a = leaf
@a.parent = self
end
def b=(leaf)
@b = leaf
@b.parent = self
end
def leaf?
@object
end
def insert_subtree(leaf)
if leaf?
new_node = AABBNode.new(parent: nil, object: nil, bounding_box: @bounding_box.union(leaf.bounding_box))
new_node.a = self
new_node.b = leaf
new_node
else
cost_a = @a.bounding_box.volume + @b.bounding_box.union(leaf.bounding_box).volume
cost_b = @b.bounding_box.volume + @a.bounding_box.union(leaf.bounding_box).volume
if cost_a == cost_b
cost_a = @a.proximity(leaf)
cost_b = @b.proximity(leaf)
end
if cost_b < cost_a
self.b = @b.insert_subtree(leaf)
else
self.a = @a.insert_subtree(leaf)
end
@bounding_box = @bounding_box.union(leaf.bounding_box)
self
end
end
def search_subtree(collider, items = [])
if @bounding_box.intersect?(collider)
if leaf?
items << self
else
@a.search_subtree(collider, items)
@b.search_subtree(collider, items)
end
end
items
end
def remove_subtree(leaf)
if leaf
self
elsif leaf.parent == self
other_child = other(leaf)
other_child.parent = @parent
other_child
else
leaf.parent.disown_child(leaf)
self
end
end
def other(leaf)
@a == leaf ? @b : @a
end
def disown_child(leaf)
value = other(leaf)
raise "Can not replace child of a leaf!" if @parent.leaf?
raise "Node is not a child of parent!" unless leaf.child_of?(@parent)
if @parent.a == self
@parent.a = value
else
@parent.b = value
end
@parent.update_bounding_box
end
def child_of?(leaf)
self == leaf.a || self == leaf.b
end
def proximity(leaf)
(@bounding_box - leaf.bounding_box).sum.abs
end
def update_bounding_box
node = self
unless node.leaf?
node.bounding_box = node.a.bounding_box.union(node.b.bounding_box)
while (node = node.parent)
node.bounding_box = node.a.bounding_box.union(node.b.bounding_box)
end
end
end
end
end
end

View File

@@ -0,0 +1,55 @@
# frozen_string_literal: true
module CyberarmEngine
class AABBTree
include AABBTreeDebug
attr_reader :root, :objects, :branches, :leaves
def initialize
@objects = {}
@root = nil
@branches = 0
@leaves = 0
end
def insert(object, bounding_box)
raise "BoundingBox can't be nil!" unless bounding_box
raise "Object can't be nil!" unless object
# raise "Object already in tree!" if @objects[object] # FIXME
leaf = AABBNode.new(parent: nil, object: object, bounding_box: bounding_box.dup)
@objects[object] = leaf
insert_leaf(leaf)
end
def insert_leaf(leaf)
@root = @root ? @root.insert_subtree(leaf) : leaf
end
def update(object, bounding_box)
leaf = remove(object)
leaf.bounding_box = bounding_box
insert_leaf(leaf)
end
# Returns a list of all objects that collided with collider
def search(collider, return_nodes = false)
items = []
if @root
items = @root.search_subtree(collider)
items.map!(&:object) unless return_nodes
end
items
end
def remove(object)
leaf = @objects.delete(object)
@root = @root.remove_subtree(leaf) if leaf
leaf
end
end
end

View File

@@ -0,0 +1,29 @@
# frozen_string_literal: true
module CyberarmEngine
# Gets included into AABBTree
module AABBTreeDebug
def inspect
@branches = 0
@leaves = 0
if @root
node = @root
debug_search(node.a)
debug_search(node.b)
end
puts "<#{self.class}:#{object_id}> has #{@branches} branches and #{@leaves} leaves"
end
def debug_search(node)
if node.leaf?
@leaves += 1
else
@branches += 1
debug_search(node.a)
debug_search(node.b)
end
end
end
end

View File

@@ -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
@@ -151,10 +154,6 @@ module CyberarmEngine
end
def recalculate
return if @in_recalculate
@in_recalculate = true
@current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
return unless visible?
@@ -225,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
@@ -243,8 +242,6 @@ module CyberarmEngine
recalculate_if_size_changed
# puts "TOOK: #{Gosu.milliseconds - s}ms to recalculate #{self.class}:0x#{self.object_id.to_s(16)}"
@in_recalculate = false
end
def layout
@@ -305,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)
@@ -321,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)
@@ -336,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)
@@ -345,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)
@@ -355,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)
@@ -365,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

View File

@@ -79,7 +79,19 @@ module CyberarmEngine
end
def caret_position_under_mouse(mouse_x, mouse_y)
active_line = row_at(mouse_y)
# get y scroll offset of element to get EditBox's selected row
y_scroll_offset = 0
e = parent
while (e)
if e.is_a?(Container)
y_scroll_offset += e.scroll_position.y
# root element has no parent so loop will terminate
e = e.parent
end
end
active_line = row_at(mouse_y - y_scroll_offset)
right_offset = column_at(mouse_x, mouse_y)
buffer = @text_input.text.lines[0..active_line].join if active_line != 0

View File

@@ -168,7 +168,7 @@ module CyberarmEngine
@last_text = @text.text
@last_pos = caret_pos
if caret_pos.between?(@offset_x, @width + @offset_x)
if caret_pos.between?(@offset_x + 1, @width + @offset_x)
# Do nothing
elsif caret_pos < @offset_x
@@ -197,7 +197,7 @@ module CyberarmEngine
def text_input_position_for(method)
if @type == :password
@text.x + @text.width(default(:password_character) * @text_input.text[0...@text_input.send(method)].length)
@text.x + @text.width(default(:password_character) * @text_input.text[0...@text_input.send(method)].length) - @style.border_thickness_left
else
@text.x + @text.width(@text_input.text[0...@text_input.send(method)]) - @style.border_thickness_left
end

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,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
@@ -266,10 +271,14 @@ module CyberarmEngine
end
def redirect_scroll_jump_to(edge)
return if window.text_input
@mouse_over.publish(:"scroll_jump_to_#{edge}", window.mouse_x, window.mouse_y) if (@mouse_over && !@menu) || (@mouse_over && @mouse_over == @menu)
end
def redirect_scroll_page(edge)
return if window.text_input
@mouse_over.publish(:"scroll_page_#{edge}", window.mouse_x, window.mouse_y) if (@mouse_over && !@menu) || (@mouse_over && @mouse_over == @menu)
end

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.3".freeze
VERSION = "0.25.1".freeze
end