mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 13:12:34 +00:00
Theming now implemented
This commit is contained in:
@@ -8,6 +8,10 @@ module CyberarmEngine
|
||||
$window.current_state
|
||||
end
|
||||
|
||||
def previous_state
|
||||
$window.previous_state
|
||||
end
|
||||
|
||||
def pop_state
|
||||
$window.pop_state
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ module CyberarmEngine
|
||||
def initialize(text, options = {}, block = nil)
|
||||
super(text, options, block)
|
||||
|
||||
@background_canvas.background = @options[:interactive_background]
|
||||
@background_canvas.background = default(:background)
|
||||
end
|
||||
|
||||
def render
|
||||
@@ -15,13 +15,13 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def enter(sender)
|
||||
@background_canvas.background = @options[:interactive_hover_background]
|
||||
@text.color = @options[:interactive_stroke]
|
||||
@background_canvas.background = default(:hover, :background)
|
||||
@text.color = default(:hover, :color)
|
||||
end
|
||||
|
||||
def left_mouse_button(sender, x, y)
|
||||
@background_canvas.background = @options[:interactive_active_background]
|
||||
@text.color = @options[:interactive_active_stroke]
|
||||
@background_canvas.background = default(:active, :background)
|
||||
@text.color = default(:active, :color)
|
||||
end
|
||||
|
||||
def released_left_mouse_button(sender,x, y)
|
||||
@@ -29,8 +29,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def leave(sender)
|
||||
@background_canvas.background = @options[:interactive_background]
|
||||
@text.color = @options[:interactive_stroke]
|
||||
@background_canvas.background = default(:background)
|
||||
@text.color = default(:color)
|
||||
end
|
||||
|
||||
def clicked_left_mouse_button(sender, x, y)
|
||||
|
||||
@@ -15,6 +15,7 @@ module CyberarmEngine
|
||||
@width = @toggle_button.width + @label.width
|
||||
@height = @toggle_button.height + @label.height
|
||||
|
||||
p @options
|
||||
recalculate
|
||||
end
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ module CyberarmEngine
|
||||
@scroll_x, @scroll_y = 0, 0
|
||||
@scroll_speed = 10
|
||||
|
||||
@text_color = options[:text_color] || Element::THEME[:stroke]
|
||||
@text_color = options[:color]
|
||||
|
||||
@children = []
|
||||
|
||||
@@ -69,11 +69,15 @@ module CyberarmEngine
|
||||
|
||||
def recalculate
|
||||
@current_position = Vector.new(@margin_left, @margin_top)
|
||||
if @children.first
|
||||
@current_position.x += @children.first.margin_left
|
||||
@current_position.y += @children.first.margin_top
|
||||
end
|
||||
|
||||
layout
|
||||
|
||||
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.width }.max + @margin_right || 0).round
|
||||
@height = @max_height ? @max_height : (@children.map {|c| c.y + c.height}.max + @margin_bottom || 0).round
|
||||
@width = @max_width ? @max_width : (@children.map {|c| c.x + c.width }.max || 0).round
|
||||
@height = @max_height ? @max_height : (@children.map {|c| c.y + c.height}.max || 0).round
|
||||
|
||||
# Move child to parent after positioning
|
||||
@children.each do |child|
|
||||
@@ -85,8 +89,6 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
update_background
|
||||
# puts unless @parent
|
||||
# puts "<#{self.class} X: #{@x}, Y: #{@y}, width: #{@width}, height: #{@height} (children: #{@children.count}) [#{children.first.class}]"
|
||||
end
|
||||
|
||||
def layout
|
||||
|
||||
@@ -2,7 +2,6 @@ module CyberarmEngine
|
||||
module DSL
|
||||
def flow(options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
puts "Flow"
|
||||
_container = Flow.new(options, block)
|
||||
@containers << _container
|
||||
_container.build
|
||||
@@ -14,7 +13,6 @@ module CyberarmEngine
|
||||
|
||||
def stack(options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
puts "Stack"
|
||||
_container = Stack.new(options, block)
|
||||
@containers << _container
|
||||
_container.build
|
||||
|
||||
@@ -3,13 +3,13 @@ module CyberarmEngine
|
||||
def initialize(text, options = {}, block = nil)
|
||||
super(text, options, block)
|
||||
|
||||
@type = @options[:type] || :plain
|
||||
@type = default(:type)
|
||||
|
||||
|
||||
@caret_width = @options[:caret_width]
|
||||
@caret_width = default(:caret_width)
|
||||
@caret_height= @text.height
|
||||
@caret_color = @options[:caret_color]
|
||||
@caret_interval = @options[:caret_interval]
|
||||
@caret_color = default(:caret_color)
|
||||
@caret_interval = default(:caret_interval)
|
||||
@caret_last_interval = Gosu.milliseconds
|
||||
@show_caret = true
|
||||
|
||||
@@ -26,7 +26,7 @@ module CyberarmEngine
|
||||
|
||||
def update
|
||||
if @type == :password
|
||||
@text.text = @options[:edit_line_password_character] * @text_input.text.length
|
||||
@text.text = default(:password_character) * @text_input.text.length
|
||||
else
|
||||
@text.text = @text_input.text
|
||||
end
|
||||
@@ -52,7 +52,7 @@ module CyberarmEngine
|
||||
|
||||
def caret_position
|
||||
if @type == :password
|
||||
@text.x + @text.textobject.text_width(@options[:edit_line_password_character] * @text_input.text[0..@text_input.caret_pos].length)
|
||||
@text.x + @text.textobject.text_width(default(:password_character) * @text_input.text[0..@text_input.caret_pos].length)
|
||||
else
|
||||
@text.x + @text.textobject.text_width(@text_input.text[0..@text_input.caret_pos])
|
||||
end
|
||||
@@ -61,7 +61,7 @@ module CyberarmEngine
|
||||
def recalculate
|
||||
super
|
||||
|
||||
@width = @options[:edit_line_width]
|
||||
@width = default(:width)
|
||||
update_background
|
||||
end
|
||||
|
||||
|
||||
@@ -15,31 +15,31 @@ module CyberarmEngine
|
||||
|
||||
def initialize(options = {}, block = nil)
|
||||
@parent = options[:parent] # parent Container (i.e. flow/stack)
|
||||
options = (THEME).merge(DEFAULTS).merge(options)
|
||||
options = theme_defaults.merge(options)
|
||||
@options = options
|
||||
@block = block
|
||||
|
||||
@background_canvas = Background.new
|
||||
@border_canvas = BorderCanvas.new(element: self)
|
||||
|
||||
@x = options.dig(:x)
|
||||
@y = options.dig(:y)
|
||||
@z = options.dig(:z)
|
||||
@x = default(:x)
|
||||
@y = default(:y)
|
||||
@z = default(:z)
|
||||
|
||||
@fixed_x = @x if @x != 0
|
||||
@fixed_y = @y if @y != 0
|
||||
|
||||
@width = options.dig(:width)
|
||||
@height = options.dig(:height)
|
||||
@width = default(:width)
|
||||
@height = default(:height)
|
||||
|
||||
set_border_thickness(options.dig(:border_thickness))
|
||||
set_border_thickness(default(:border_thickness))
|
||||
|
||||
set_padding(options.dig(:padding))
|
||||
set_padding(default(:padding))
|
||||
|
||||
set_margin(options.dig(:margin))
|
||||
set_margin(default(:margin))
|
||||
|
||||
set_background(options.dig(:background))
|
||||
set_border_color(options.dig(:border_color))
|
||||
set_background(default(:background))
|
||||
set_border_color(default(:border_color))
|
||||
|
||||
raise "#{self.class} 'x' must be a number" unless @x.is_a?(Numeric)
|
||||
raise "#{self.class} 'y' must be a number" unless @y.is_a?(Numeric)
|
||||
@@ -66,19 +66,19 @@ module CyberarmEngine
|
||||
def set_border_thickness(border_thickness)
|
||||
@border_thickness = border_thickness
|
||||
|
||||
@border_thickness_left = options.dig(:border_thickness_left) || @border_thickness
|
||||
@border_thickness_right = options.dig(:border_thickness_right) || @border_thickness
|
||||
@border_thickness_top = options.dig(:border_thickness_top) || @border_thickness
|
||||
@border_thickness_bottom = options.dig(:border_thickness_bottom) || @border_thickness
|
||||
@border_thickness_left = default(:border_thickness_left) || @border_thickness
|
||||
@border_thickness_right = default(:border_thickness_right) || @border_thickness
|
||||
@border_thickness_top = default(:border_thickness_top) || @border_thickness
|
||||
@border_thickness_bottom = default(:border_thickness_bottom) || @border_thickness
|
||||
end
|
||||
|
||||
def set_border_color(color)
|
||||
@border_color = color
|
||||
|
||||
@border_color_left = options.dig(:border_color_left) || @border_color
|
||||
@border_color_right = options.dig(:border_color_right) || @border_color
|
||||
@border_color_top = options.dig(:border_color_top) || @border_color
|
||||
@border_color_bottom = options.dig(:border_color_bottom) || @border_color
|
||||
@border_color_left = default(:border_color_left) || @border_color
|
||||
@border_color_right = default(:border_color_right) || @border_color
|
||||
@border_color_top = default(:border_color_top) || @border_color
|
||||
@border_color_bottom = default(:border_color_bottom) || @border_color
|
||||
|
||||
@border_canvas.color = color
|
||||
end
|
||||
@@ -86,19 +86,19 @@ module CyberarmEngine
|
||||
def set_padding(padding)
|
||||
@padding = padding
|
||||
|
||||
@padding_left = options.dig(:padding_left) || @padding
|
||||
@padding_right = options.dig(:padding_right) || @padding
|
||||
@padding_top = options.dig(:padding_top) || @padding
|
||||
@padding_bottom = options.dig(:padding_bottom) || @padding
|
||||
@padding_left = default(:padding_left) || @padding
|
||||
@padding_right = default(:padding_right) || @padding
|
||||
@padding_top = default(:padding_top) || @padding
|
||||
@padding_bottom = default(:padding_bottom) || @padding
|
||||
end
|
||||
|
||||
def set_margin(margin)
|
||||
@margin = margin
|
||||
|
||||
@margin_left = options.dig(:margin_left) || @margin
|
||||
@margin_right = options.dig(:margin_right) || @margin
|
||||
@margin_top = options.dig(:margin_top) || @margin
|
||||
@margin_bottom = options.dig(:margin_bottom) || @margin
|
||||
@margin_left = default(:margin_left) || @margin
|
||||
@margin_right = default(:margin_right) || @margin
|
||||
@margin_top = default(:margin_top) || @margin
|
||||
@margin_bottom = default(:margin_bottom) || @margin
|
||||
end
|
||||
|
||||
def default_events
|
||||
|
||||
@@ -23,7 +23,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def render
|
||||
@image.draw(@x + @padding_left, @y + @padding_top, @z + 2, @scale_x, @scale_y) # TODO: Add color support?
|
||||
@image.draw(@border_thickness_left + @padding_left + @x, @border_thickness_top + @padding_top + @y, @z + 2, @scale_x, @scale_y) # TODO: Add color support?
|
||||
end
|
||||
|
||||
def clicked_left_mouse_button(sender, x, y)
|
||||
|
||||
@@ -25,8 +25,8 @@ module CyberarmEngine
|
||||
@width = @text.width.round
|
||||
@height= @text.height.round
|
||||
|
||||
@text.x = @padding_left + @x
|
||||
@text.y = @padding_top + @y
|
||||
@text.x = @border_thickness_left + @padding_left + @x
|
||||
@text.y = @border_thickness_top + @padding_top + @y
|
||||
@text.z = @z + 3
|
||||
|
||||
update_background
|
||||
|
||||
@@ -1,43 +1,91 @@
|
||||
module CyberarmEngine
|
||||
module Theme
|
||||
DEFAULTS = {
|
||||
def default(*args)
|
||||
value = @options
|
||||
args.each do |arg|
|
||||
value = value.dig(arg)
|
||||
end
|
||||
|
||||
value
|
||||
end
|
||||
|
||||
def theme_defaults
|
||||
raise "Error" unless self.class.ancestors.include?(CyberarmEngine::Element)
|
||||
|
||||
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.reverse.each do |klass|
|
||||
next unless data = THEME.dig(klass)
|
||||
data.each do |key, value|
|
||||
hash[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
hash
|
||||
end
|
||||
|
||||
THEME = {
|
||||
Element: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 30,
|
||||
|
||||
width: 0,
|
||||
height: 0
|
||||
}
|
||||
|
||||
THEME = {
|
||||
height: 0,
|
||||
color: Gosu::Color::WHITE,
|
||||
background: Gosu::Color::NONE,
|
||||
checkmark: "√", # √
|
||||
|
||||
margin: 10,
|
||||
padding: 5,
|
||||
border_thickness: 2,
|
||||
border_color: [Gosu::Color.rgb(12,12,12)],
|
||||
margin: 2,
|
||||
padding: 2,
|
||||
border_thickness: 0,
|
||||
border_color: Gosu::Color::NONE,
|
||||
border_radius: 0,
|
||||
},
|
||||
|
||||
interactive_stroke: Gosu::Color::WHITE,
|
||||
interactive_active_stroke: Gosu::Color::GRAY,
|
||||
Button: {
|
||||
margin: 0,
|
||||
padding: 2,
|
||||
border_thickness: 2,
|
||||
border_color: ["ffd59674".hex, "ffff8746".hex],
|
||||
border_radius: 0,
|
||||
background: ["ffc75e61".to_i(16), "ffe26623".to_i(16)],
|
||||
|
||||
interactive_background: [Gosu::Color::GRAY, Gosu::Color::RED],
|
||||
interactive_hover_background: Gosu::Color.rgb(100, 100, 100),
|
||||
interactive_active_background: Gosu::Color.rgb(50, 50, 50),
|
||||
hover: {
|
||||
color: Gosu::Color.rgb(200,200,200),
|
||||
background: ["ffB23E41".to_i(16), "ffFF7C00".to_i(16)],
|
||||
},
|
||||
|
||||
edit_line_width: 200,
|
||||
edit_line_password_character: "•", # •
|
||||
active: {
|
||||
color: Gosu::Color::BLACK,
|
||||
background: ["ffB23E41".to_i(16)]
|
||||
}
|
||||
},
|
||||
|
||||
EditLine: {
|
||||
type: :text,
|
||||
width: 200,
|
||||
password_character: "•",
|
||||
caret_width: 2,
|
||||
caret_color: Gosu::Color.rgb(50,50,25),
|
||||
caret_color: Gosu::Color::WHITE,
|
||||
caret_interval: 500,
|
||||
},
|
||||
|
||||
image_retro: false,
|
||||
Image: {
|
||||
retro: false
|
||||
},
|
||||
|
||||
text_size: 22,
|
||||
text_shadow: true,
|
||||
font: "Sans Serif"
|
||||
Label: {
|
||||
text_size: 24,
|
||||
text_shadow: false,
|
||||
font: "Akaash"
|
||||
},
|
||||
|
||||
ToggleButton: {
|
||||
checkmark: "√",
|
||||
padding_left: 0,
|
||||
margin_left: 0
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user