mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 05:02:34 +00:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| da69f057a0 | |||
| 4f4770db0e | |||
| b6730204e8 | |||
| d8dc621c62 | |||
| 739ae86966 | |||
| 3be16c644f | |||
| 805077d232 | |||
| db1a0683e2 | |||
| f489ad162f | |||
| df2dc25e34 | |||
| 6b319935d3 | |||
| f9d551a419 | |||
| f34dd21644 | |||
| 025f54a752 | |||
| cbc27b5d5d | |||
| 4af377b93c | |||
| cc97077b0f |
@@ -13,7 +13,6 @@ require_relative "cyberarm_engine/background"
|
||||
|
||||
require_relative "cyberarm_engine/objects/text"
|
||||
require_relative "cyberarm_engine/objects/timer"
|
||||
require_relative "cyberarm_engine/objects/multi_line_text"
|
||||
|
||||
require_relative "cyberarm_engine/ui/theme"
|
||||
require_relative "cyberarm_engine/ui/event"
|
||||
|
||||
@@ -48,6 +48,12 @@ module CyberarmEngine
|
||||
end
|
||||
end
|
||||
|
||||
def opacity(color, ratio = 1.0)
|
||||
alpha = 255 * ratio
|
||||
|
||||
return Gosu::Color.rgba(color.red, color.green, color.blue, alpha)
|
||||
end
|
||||
|
||||
def get_asset(path, hash, klass)
|
||||
asset = nil
|
||||
hash.detect do |_asset, instance|
|
||||
|
||||
@@ -15,10 +15,10 @@ module CyberarmEngine
|
||||
$window.last_frame_time/1000.0
|
||||
end
|
||||
|
||||
def initialize(width = 800, height = 600, fullscreen = false, update_interval = 1000.0/60)
|
||||
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0/60, resizable: false)
|
||||
@show_cursor = false
|
||||
|
||||
super(width, height, fullscreen, update_interval)
|
||||
super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable)
|
||||
$window = self
|
||||
@last_frame_time = Gosu.milliseconds-1
|
||||
@current_frame_time = Gosu.milliseconds
|
||||
@@ -48,10 +48,12 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
super
|
||||
current_state.button_down(id) if current_state
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
super
|
||||
current_state.button_up(id) if current_state
|
||||
end
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ module CyberarmEngine
|
||||
|
||||
setup
|
||||
|
||||
@debug_text = MultiLineText.new("", color: @debug_color, y: @position.y-(self.height*self.scale), z: 9999)
|
||||
@debug_text = Text.new("", color: @debug_color, y: @position.y-(self.height*self.scale), z: 9999)
|
||||
@debug_text.x = @position.x
|
||||
if @radius == 0 || @radius == nil
|
||||
@radius = options[:radius] ? options[:radius] : defined?(@image.width) ? ((@image.width+@image.height)/4)*scale : 1
|
||||
@@ -121,11 +121,11 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def width
|
||||
@image ? @image.width : 0
|
||||
@image ? @image.width * self.scale : 0
|
||||
end
|
||||
|
||||
def height
|
||||
@image ? @image.height : 0
|
||||
@image ? @image.height * self.scale : 0
|
||||
end
|
||||
|
||||
def pause
|
||||
|
||||
@@ -9,6 +9,7 @@ module CyberarmEngine
|
||||
@options = options
|
||||
@game_objects = []
|
||||
@global_pause = false
|
||||
$window.text_input = nil unless options[:preserve_text_input]
|
||||
|
||||
@down_keys = {}
|
||||
|
||||
|
||||
@@ -2,9 +2,23 @@ module CyberarmEngine
|
||||
class BoundingBox
|
||||
attr_accessor :min, :max
|
||||
|
||||
def initialize(minx = 0, miny = 0, minz = 0, maxx = 0, maxy = 0, maxz = 0)
|
||||
@min = Vector.new(minx, miny, minz)
|
||||
@max = Vector.new(maxx, maxy, maxz)
|
||||
def initialize(*args)
|
||||
case args.size
|
||||
when 0
|
||||
@min = Vector.new(0, 0, 0)
|
||||
@max = Vector.new(0, 0, 0)
|
||||
when 2
|
||||
@min = args.first.clone
|
||||
@max = args.last.clone
|
||||
when 4
|
||||
@min = Vector.new(args[0], args[1], 0)
|
||||
@max = Vector.new(args[2], args[3], 0)
|
||||
when 6
|
||||
@min = Vector.new(args[0], args[1], args[2])
|
||||
@max = Vector.new(args[3], args[4], args[5])
|
||||
else
|
||||
raise "Invalid number of arguments! Got: #{args.size}, expected: 0, 2, 4, or 6."
|
||||
end
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
module CyberarmEngine
|
||||
class Vector
|
||||
|
||||
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
||||
@x, @y, @z, @weight = x, y, z, weight
|
||||
end
|
||||
@@ -17,10 +16,6 @@ module CyberarmEngine
|
||||
def weight; @weight; end
|
||||
def weight=(n); @weight = n; end
|
||||
|
||||
# def xy=(nx, ny); @x = nx; @y = ny; end
|
||||
# def xyz=(nx, ny, nz); @x = nx; @y = ny; @z = nz; end
|
||||
# def xyzw=(nx, ny, nz, nw); @x = nx; @y = ny; @z = nz; @weight = nw; end
|
||||
|
||||
def ==(other)
|
||||
if other.is_a?(Numeric)
|
||||
@x == other &&
|
||||
@@ -35,43 +30,85 @@ module CyberarmEngine
|
||||
end
|
||||
end
|
||||
|
||||
def +(other)
|
||||
Vector.new(
|
||||
@x + other.x,
|
||||
@y + other.y,
|
||||
@z + other.z,
|
||||
@weight + other.weight
|
||||
)
|
||||
end
|
||||
|
||||
def -(other)
|
||||
Vector.new(
|
||||
@x - other.x,
|
||||
@y - other.y,
|
||||
@z - other.z,
|
||||
@weight - other.weight
|
||||
)
|
||||
end
|
||||
|
||||
def *(other)
|
||||
Vector.new(
|
||||
@x * other.x,
|
||||
@y * other.y,
|
||||
@z * other.z,
|
||||
@weight * other.weight
|
||||
# Performs math operation, excluding @weight
|
||||
private def operator(function, other)
|
||||
if other.is_a?(Numeric)
|
||||
Vector.new(
|
||||
@x.send(:"#{function}", other),
|
||||
@y.send(:"#{function}", other),
|
||||
@z.send(:"#{function}", other)
|
||||
)
|
||||
else
|
||||
Vector.new(
|
||||
@x.send(:"#{function}", other.x),
|
||||
@y.send(:"#{function}", other.y),
|
||||
@z.send(:"#{function}", other.z)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# Adds Vector and Numberic or Vector and Vector, excluding @weight
|
||||
def +(other)
|
||||
operator("+", other)
|
||||
end
|
||||
|
||||
# Subtracts Vector and Numberic or Vector and Vector, excluding @weight
|
||||
def -(other)
|
||||
operator("-", other)
|
||||
end
|
||||
|
||||
# Multiplies Vector and Numberic or Vector and Vector, excluding @weight
|
||||
def *(other)
|
||||
operator("*", other)
|
||||
end
|
||||
|
||||
# Divides Vector and Numberic or Vector and Vector, excluding @weight
|
||||
def /(other)
|
||||
# Endeavors to prevent division by zero
|
||||
# Duplicated to protect from DivideByZero
|
||||
if other.is_a?(Numeric)
|
||||
Vector.new(
|
||||
(@x == 0 ? 0 : @x / other),
|
||||
(@y == 0 ? 0 : @y / other),
|
||||
(@z == 0 ? 0 : @z / other)
|
||||
)
|
||||
else
|
||||
Vector.new(
|
||||
(@x == 0 ? 0 : @x / other.x),
|
||||
(@y == 0 ? 0 : @y / other.y),
|
||||
(@z == 0 ? 0 : @z / other.z)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def dot(other)
|
||||
product = 0
|
||||
|
||||
a = self.to_a
|
||||
b = other.to_a
|
||||
|
||||
3.times do |i|
|
||||
product = product + (a[i] * b[i])
|
||||
end
|
||||
|
||||
return product
|
||||
end
|
||||
|
||||
def cross(other)
|
||||
a = self.to_a
|
||||
b = other.to_a
|
||||
|
||||
Vector.new(
|
||||
@x == 0 || other.x == 0 ? 0 : @x / other.x,
|
||||
@y == 0 || other.y == 0 ? 0 : @y / other.y,
|
||||
@z == 0 || other.z == 0 ? 0 : @z / other.z,
|
||||
@weight == 0 || other.weight == 0 ? 0 : @weight / other.weight
|
||||
b[2] * a[1] - b[1] * a[2],
|
||||
b[0] * a[2] - b[2] * a[0],
|
||||
b[1] * a[0] - b[0] * a[1]
|
||||
)
|
||||
end
|
||||
|
||||
# returns degrees
|
||||
def angle(other)
|
||||
Math.acos( self.normalized.dot(other.normalized) ) * 180 / Math::PI
|
||||
end
|
||||
|
||||
# returns magnitude of Vector, ignoring #weight
|
||||
def magnitude
|
||||
Math.sqrt((@x * @x) + (@y * @y) + (@z * @z))
|
||||
@@ -82,8 +119,38 @@ module CyberarmEngine
|
||||
self / Vector.new(mag, mag, mag)
|
||||
end
|
||||
|
||||
def direction
|
||||
# z is pitch
|
||||
# y is yaw
|
||||
# x is roll
|
||||
_x = -Math.sin(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
||||
_y = Math.sin(@z.degrees_to_radians)
|
||||
_z = Math.cos(@y.degrees_to_radians) * Math.cos(@z.degrees_to_radians)
|
||||
|
||||
Vector.new(_x, _y, _z)
|
||||
end
|
||||
|
||||
def inverse
|
||||
Vector.new(1.0 / @x, 1.0 / @y, 1.0 / @z)
|
||||
end
|
||||
|
||||
def sum
|
||||
@x + @y + @z + @weight
|
||||
@x + @y + @z
|
||||
end
|
||||
|
||||
# 2D distance using X and Y
|
||||
def distance(other)
|
||||
Math.sqrt((@x-other.x)**2 + (@y-other.y)**2)
|
||||
end
|
||||
|
||||
# 2D distance using X and Z
|
||||
def gl_distance2d(other)
|
||||
Math.sqrt((@x-other.x)**2 + (@z-other.z)**2)
|
||||
end
|
||||
|
||||
# 3D distance using X, Y, and Z
|
||||
def distance3d(other)
|
||||
Math.sqrt((@x-other.x)**2 + (@y-other.y)**2 + (@z-other.z)**2)
|
||||
end
|
||||
|
||||
def to_a
|
||||
@@ -93,5 +160,9 @@ module CyberarmEngine
|
||||
def to_s
|
||||
"X: #{@x}, Y: #{@y}, Z: #{@z}, Weight: #{@weight}"
|
||||
end
|
||||
|
||||
def to_h
|
||||
{x: @x, y: @y, z: @z, weight: @weight}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,67 +0,0 @@
|
||||
module CyberarmEngine
|
||||
class MultiLineText
|
||||
attr_accessor :options, :x, :y, :width, :height
|
||||
|
||||
def initialize(text, options={})
|
||||
@texts = []
|
||||
text.split("\n").each_with_index do |line, i|
|
||||
_options = options
|
||||
_options[:y]+=_options[:size]
|
||||
@texts << Text.new(line, _options)
|
||||
end
|
||||
@options = options
|
||||
@x = @texts.first ? @texts.first.x : 0
|
||||
@y = @texts.first ? @texts.first.y : 0
|
||||
@width = 0
|
||||
@height = 0
|
||||
calculate_boundry
|
||||
end
|
||||
|
||||
def draw
|
||||
@texts.each(&:draw)
|
||||
end
|
||||
|
||||
def text
|
||||
string = ""
|
||||
@texts.each {|t| string << t.text}
|
||||
return string
|
||||
end
|
||||
|
||||
def text=(text)
|
||||
|
||||
if text.lines.count < @texts.count
|
||||
range = ((@texts.count - @text.lines.count)-1)..@texts.count-1
|
||||
p range
|
||||
@texts.slice!(range)
|
||||
end
|
||||
|
||||
text.split("\n").each_with_index do |line, i|
|
||||
if @texts[i]
|
||||
@texts[i].text = line
|
||||
else
|
||||
@texts << Text.new(line, @options)
|
||||
end
|
||||
end
|
||||
|
||||
self.y = @y
|
||||
calculate_boundry
|
||||
end
|
||||
|
||||
def x=(int)
|
||||
@x = int
|
||||
@texts.each {|t| t.x = int}
|
||||
end
|
||||
|
||||
def y=(int)
|
||||
@y = int
|
||||
@texts.each_with_index {|t, i| t.y=int+(i*t.size)}
|
||||
end
|
||||
|
||||
def calculate_boundry
|
||||
@width = 0
|
||||
@height= 0
|
||||
@texts.each {|t| @width = t.width if t.width > @width}
|
||||
@texts.each {|t| @height+=t.height}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,11 +2,11 @@ module CyberarmEngine
|
||||
class Text
|
||||
CACHE = {}
|
||||
|
||||
attr_accessor :text, :x, :y, :z, :size, :factor_x, :factor_y, :color, :shadow, :shadow_size, :options
|
||||
attr_reader :textobject
|
||||
attr_accessor :x, :y, :z, :size, :factor_x, :factor_y, :color, :shadow, :shadow_size, :options
|
||||
attr_reader :text, :textobject
|
||||
|
||||
def initialize(text, options={})
|
||||
@text = text || ""
|
||||
@text = text.to_s || ""
|
||||
@options = options
|
||||
@size = options[:size] || 18
|
||||
@font = options[:font] || "sans-serif"#Gosu.default_font_name
|
||||
@@ -62,35 +62,55 @@ module CyberarmEngine
|
||||
return font
|
||||
end
|
||||
|
||||
def text=(string)
|
||||
@rendered_shadow = nil
|
||||
@text = string
|
||||
end
|
||||
|
||||
def width
|
||||
textobject.text_width(@text)
|
||||
end
|
||||
|
||||
def height
|
||||
textobject.height
|
||||
@text.lines.count > 0 ? (@text.lines.count) * textobject.height : @textobject.height
|
||||
end
|
||||
|
||||
def draw
|
||||
if @shadow && !ARGV.join.include?("--no-shadow")
|
||||
_color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha) if @shadow_alpha <= @color.alpha
|
||||
_color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, @color.alpha) unless @shadow_alpha <= @color.alpha
|
||||
@shadow_alpha = 30 if @color.alpha > 30
|
||||
@shadow_alpha = @color.alpha if @color.alpha <= 30
|
||||
shadow_color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, @shadow_alpha)
|
||||
|
||||
@textobject.draw_markup(@text, @x-@shadow_size, @y, @z, @factor_x, @factor_y, _color)
|
||||
@textobject.draw_markup(@text, @x-@shadow_size, @y-@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
_x = @shadow_size
|
||||
_y = @shadow_size
|
||||
|
||||
@textobject.draw_markup(@text, @x, @y-@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
@textobject.draw_markup(@text, @x+@shadow_size, @y-@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
@rendered_shadow ||= Gosu.render((self.width+(shadow_size*2)).ceil, (self.height+(@shadow_size*2)).ceil) do
|
||||
@textobject.draw_markup(@text, _x-@shadow_size, _y, @z)
|
||||
@textobject.draw_markup(@text, _x-@shadow_size, _y-@shadow_size, @z)
|
||||
|
||||
@textobject.draw_markup(@text, @x, @y+@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
@textobject.draw_markup(@text, @x-@shadow_size, @y+@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
@textobject.draw_markup(@text, _x, _y-@shadow_size, @z, @factor_x)
|
||||
@textobject.draw_markup(@text, _x+@shadow_size, _y-@shadow_size, @z)
|
||||
|
||||
@textobject.draw_markup(@text, @x+@shadow_size, @y, @z, @factor_x, @factor_y, _color)
|
||||
@textobject.draw_markup(@text, @x+@shadow_size, @y+@shadow_size, @z, @factor_x, @factor_y, _color)
|
||||
@textobject.draw_markup(@text, _x, _y+@shadow_size, @z)
|
||||
@textobject.draw_markup(@text, _x-@shadow_size, _y+@shadow_size, @z)
|
||||
|
||||
@textobject.draw_markup(@text, _x+@shadow_size, _y, @z)
|
||||
@textobject.draw_markup(@text, _x+@shadow_size, _y+@shadow_size, @z)
|
||||
end
|
||||
@rendered_shadow.draw(@x-@shadow_size, @y-@shadow_size, @z, @factor_x, @factor_y, shadow_color)
|
||||
end
|
||||
|
||||
@textobject.draw_markup(@text, @x, @y, @z, @factor_x, @factor_y, @color)
|
||||
end
|
||||
|
||||
def alpha=(n)
|
||||
@color = Gosu::Color.rgba(@color.red, @color.green, @color.blue, n)
|
||||
end
|
||||
|
||||
def alpha
|
||||
@color.alpha
|
||||
end
|
||||
|
||||
def update; end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,6 +21,14 @@ module CyberarmEngine
|
||||
recalculate
|
||||
end
|
||||
|
||||
def value
|
||||
@toggle_button.value
|
||||
end
|
||||
|
||||
def value=(bool)
|
||||
@toggle_button.vlaue = bool
|
||||
end
|
||||
|
||||
def define_label_singletons
|
||||
@label.define_singleton_method(:_toggle_button) do |button|
|
||||
@_toggle_button = button
|
||||
|
||||
@@ -65,6 +65,11 @@ module CyberarmEngine
|
||||
|
||||
def recalculate
|
||||
@current_position = Vector.new(@margin_left, @margin_top)
|
||||
unless @visible
|
||||
@width = 0
|
||||
@height= 0
|
||||
return
|
||||
end
|
||||
|
||||
layout
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ module CyberarmEngine
|
||||
module DSL
|
||||
def flow(options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
_container = Flow.new(options, block)
|
||||
@containers << _container
|
||||
_container.build
|
||||
@@ -13,6 +14,7 @@ module CyberarmEngine
|
||||
|
||||
def stack(options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
_container = Stack.new(options, block)
|
||||
@containers << _container
|
||||
_container.build
|
||||
@@ -24,6 +26,7 @@ module CyberarmEngine
|
||||
|
||||
def label(text, options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
_element = Label.new(text, options, block)
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -32,6 +35,7 @@ module CyberarmEngine
|
||||
|
||||
def button(text, options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
_element = Button.new(text, options, block) { if block.is_a?(Proc); block.call; end }
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -40,6 +44,7 @@ module CyberarmEngine
|
||||
|
||||
def edit_line(text, options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
_element = EditLine.new(text, options, block)
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -48,6 +53,7 @@ module CyberarmEngine
|
||||
|
||||
def toggle_button(options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
_element = ToggleButton.new(options, block)
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -56,6 +62,7 @@ module CyberarmEngine
|
||||
|
||||
def check_box(text, options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
_element = CheckBox.new(text, options, block)
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -64,6 +71,7 @@ module CyberarmEngine
|
||||
|
||||
def image(path, options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
_element = Image.new(path, options, block)
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -78,5 +86,9 @@ module CyberarmEngine
|
||||
def color(color)
|
||||
@containers.last.color(color)
|
||||
end
|
||||
|
||||
def set_theme(theme)
|
||||
@current_theme = theme
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -77,6 +77,12 @@ module CyberarmEngine
|
||||
def recalculate
|
||||
super
|
||||
|
||||
unless @visible
|
||||
@width = 0
|
||||
@height= 0
|
||||
return
|
||||
end
|
||||
|
||||
@width = default(:width)
|
||||
update_background
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ module CyberarmEngine
|
||||
|
||||
def initialize(options = {}, block = nil)
|
||||
@parent = options[:parent] # parent Container (i.e. flow/stack)
|
||||
options = theme_defaults.merge(options)
|
||||
options = theme_defaults(options)
|
||||
@options = options
|
||||
@block = block
|
||||
|
||||
@@ -53,6 +53,7 @@ module CyberarmEngine
|
||||
# raise "#{self.class} 'padding' must be a number" unless @padding.is_a?(Numeric)
|
||||
|
||||
@enabled = true
|
||||
@visible = true
|
||||
|
||||
default_events
|
||||
end
|
||||
@@ -122,7 +123,28 @@ module CyberarmEngine
|
||||
@enabled
|
||||
end
|
||||
|
||||
def visible?
|
||||
@visible
|
||||
end
|
||||
|
||||
def toggle
|
||||
@visible = !@visible
|
||||
root.recalculate
|
||||
end
|
||||
|
||||
def show
|
||||
@visible = true
|
||||
root.recalculate
|
||||
end
|
||||
|
||||
def hide
|
||||
@visible = false
|
||||
root.recalculate
|
||||
end
|
||||
|
||||
def draw
|
||||
return unless @visible
|
||||
|
||||
@background_canvas.draw
|
||||
@border_canvas.draw
|
||||
render
|
||||
@@ -186,12 +208,36 @@ module CyberarmEngine
|
||||
@border_canvas.update
|
||||
end
|
||||
|
||||
def root
|
||||
unless @root && @root.parent.nil?
|
||||
@root = parent
|
||||
|
||||
loop do
|
||||
if @root.parent.nil?
|
||||
break
|
||||
else
|
||||
@root = @root.parent
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@root
|
||||
end
|
||||
|
||||
def recalculate
|
||||
raise "#{self.class}#recalculate was not overridden!"
|
||||
end
|
||||
|
||||
def reposition
|
||||
raise "#{self.class}#reposition was not overridden!"
|
||||
end
|
||||
|
||||
def value
|
||||
raise "#{self.class}#value was not overridden!"
|
||||
end
|
||||
|
||||
def value=(value)
|
||||
raise "#{self.class}#value= was not overridden!"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -31,6 +31,12 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def recalculate
|
||||
unless @visible
|
||||
@width = 0
|
||||
@height= 0
|
||||
return
|
||||
end
|
||||
|
||||
@width = @image.width * @scale_x
|
||||
@height = @image.height * @scale_y
|
||||
end
|
||||
|
||||
@@ -17,6 +17,12 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def recalculate
|
||||
unless @visible
|
||||
@width = 0
|
||||
@height= 0
|
||||
return
|
||||
end
|
||||
|
||||
@width = @text.width.round
|
||||
@height= @text.height.round
|
||||
|
||||
@@ -30,5 +36,14 @@ module CyberarmEngine
|
||||
def value
|
||||
@text.text
|
||||
end
|
||||
|
||||
def value=(value)
|
||||
@text.text = value
|
||||
|
||||
old_width, old_height = width, height
|
||||
recalculate
|
||||
|
||||
root.recalculate if old_width != width || old_height != height
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -9,21 +9,24 @@ module CyberarmEngine
|
||||
value
|
||||
end
|
||||
|
||||
def theme_defaults
|
||||
def theme_defaults(options)
|
||||
raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element)
|
||||
_theme = THEME
|
||||
_theme = _theme.merge(options[:theme]) if options[:theme]
|
||||
options.delete(:theme)
|
||||
|
||||
hash = {}
|
||||
class_names = self.class.ancestors
|
||||
class_names = class_names[0..class_names.index(CyberarmEngine::Element)].map! {|c| c.to_s.split("::").last.to_sym}.reverse!
|
||||
|
||||
class_names.each do |klass|
|
||||
next unless data = THEME.dig(klass)
|
||||
next unless data = _theme.dig(klass)
|
||||
data.each do |key, value|
|
||||
hash.merge!(data)
|
||||
end
|
||||
end
|
||||
|
||||
hash
|
||||
hash.merge(options)
|
||||
end
|
||||
|
||||
THEME = {
|
||||
@@ -86,6 +89,6 @@ module CyberarmEngine
|
||||
ToggleButton: { # < Button
|
||||
checkmark: "√"
|
||||
}
|
||||
}
|
||||
}.freeze
|
||||
end
|
||||
end
|
||||
@@ -38,6 +38,12 @@ module CyberarmEngine
|
||||
def recalculate
|
||||
super
|
||||
|
||||
unless @visible
|
||||
@width = 0
|
||||
@height= 0
|
||||
return
|
||||
end
|
||||
|
||||
@width = @text.textobject.text_width(@options[:checkmark])
|
||||
update_background
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module CyberarmEngine
|
||||
NAME = "InDev"
|
||||
VERSION = "0.1.0"
|
||||
VERSION = "0.7.0"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user