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