mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 05:02:34 +00:00
Moved Element styles into Style
This commit is contained in:
@@ -66,31 +66,31 @@ module CyberarmEngine
|
||||
@top.z = @element.z
|
||||
|
||||
@top.width = @element.width
|
||||
@top.height = @element.border_thickness_top
|
||||
@top.height = @element.style.border_thickness_top
|
||||
|
||||
# RIGHT
|
||||
@right.x = @element.x + @element.width
|
||||
@right.y = @element.y + @element.border_thickness_top
|
||||
@right.y = @element.y + @element.style.border_thickness_top
|
||||
@right.z = @element.z
|
||||
|
||||
@right.width = -@element.border_thickness_right
|
||||
@right.height = @element.height - @element.border_thickness_top
|
||||
@right.width = -@element.style.border_thickness_right
|
||||
@right.height = @element.height - @element.style.border_thickness_top
|
||||
|
||||
# BOTTOM
|
||||
@bottom.x = @element.x
|
||||
@bottom.y = @element.y + @element.height
|
||||
@bottom.z = @element.z
|
||||
|
||||
@bottom.width = @element.width - @element.border_thickness_right
|
||||
@bottom.height = -@element.border_thickness_bottom
|
||||
@bottom.width = @element.width - @element.style.border_thickness_right
|
||||
@bottom.height = -@element.style.border_thickness_bottom
|
||||
|
||||
# LEFT
|
||||
@left.x = @element.x
|
||||
@left.y = @element.y
|
||||
@left.z = @element.z
|
||||
|
||||
@left.width = @element.border_thickness_left
|
||||
@left.height = @element.height - @element.border_thickness_bottom
|
||||
@left.width = @element.style.border_thickness_left
|
||||
@left.height = @element.height - @element.style.border_thickness_bottom
|
||||
|
||||
@top.update
|
||||
@right.update
|
||||
|
||||
@@ -3,7 +3,7 @@ module CyberarmEngine
|
||||
def initialize(text, options = {}, block = nil)
|
||||
super(text, options, block)
|
||||
|
||||
@background_canvas.background = default(:background)
|
||||
@style.background_canvas.background = default(:background)
|
||||
end
|
||||
|
||||
def render
|
||||
@@ -18,17 +18,17 @@ module CyberarmEngine
|
||||
@focus = false unless window.button_down?(Gosu::MsLeft)
|
||||
|
||||
if @focus
|
||||
@background_canvas.background = default(:active, :background)
|
||||
@style.background_canvas.background = default(:active, :background)
|
||||
@text.color = default(:active, :color)
|
||||
else
|
||||
@background_canvas.background = default(:hover, :background)
|
||||
@style.background_canvas.background = default(:hover, :background)
|
||||
@text.color = default(:hover, :color)
|
||||
end
|
||||
end
|
||||
|
||||
def left_mouse_button(sender, x, y)
|
||||
@focus = true
|
||||
@background_canvas.background = default(:active, :background)
|
||||
@style.background_canvas.background = default(:active, :background)
|
||||
window.current_state.focus = self
|
||||
@text.color = default(:active, :color)
|
||||
end
|
||||
@@ -42,7 +42,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def leave(sender)
|
||||
@background_canvas.background = default(:background)
|
||||
@style.background_canvas.background = default(:background)
|
||||
@text.color = default(:color)
|
||||
end
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def recalculate
|
||||
@current_position = Vector.new(@margin_left + @padding_left, @margin_top + @padding_top)
|
||||
@current_position = Vector.new(@style.margin_left + @style.padding_left, @style.margin_top + @style.padding_top)
|
||||
unless @visible
|
||||
@width = 0
|
||||
@height= 0
|
||||
@@ -93,7 +93,7 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def max_width
|
||||
@max_width ? @max_width : window.width - (@parent ? @parent.margin_right + @margin_right : @margin_right)
|
||||
@max_width ? @max_width : window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
|
||||
end
|
||||
|
||||
def fits_on_line?(element) # Flow
|
||||
@@ -102,13 +102,13 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def position_on_current_line(element) # Flow
|
||||
element.x = element.margin_left + @current_position.x
|
||||
element.y = element.margin_top + @current_position.y
|
||||
element.x = element.style.margin_left + @current_position.x
|
||||
element.y = element.style.margin_top + @current_position.y
|
||||
|
||||
element.recalculate
|
||||
|
||||
@current_position.x += element.outer_width
|
||||
@current_position.x = @margin_left if @current_position.x >= max_width
|
||||
@current_position.x = @style.margin_left if @current_position.x >= max_width
|
||||
end
|
||||
|
||||
def tallest_neighbor(querier, y_position) # Flow
|
||||
@@ -122,11 +122,11 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def position_on_next_line(child) # Flow
|
||||
@current_position.x = @margin_left
|
||||
@current_position.x = @style.margin_left
|
||||
@current_position.y += tallest_neighbor(child, @current_position.y).outer_height
|
||||
|
||||
child.x = child.margin_left + @current_position.x
|
||||
child.y = child.margin_top + @current_position.y
|
||||
child.x = child.style.margin_left + @current_position.x
|
||||
child.y = child.style.margin_top + @current_position.y
|
||||
|
||||
child.recalculate
|
||||
|
||||
@@ -134,8 +134,8 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def move_to_next_line(element) # Stack
|
||||
element.x = element.margin_left + @current_position.x
|
||||
element.y = element.margin_top + @current_position.y
|
||||
element.x = element.style.margin_left + @current_position.x
|
||||
element.y = element.style.margin_top + @current_position.y
|
||||
|
||||
element.recalculate
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ module CyberarmEngine
|
||||
|
||||
def label(text, options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
options[:theme] = current_theme
|
||||
_element = Label.new(text, options, block)
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -35,7 +35,7 @@ module CyberarmEngine
|
||||
|
||||
def button(text, options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
options[:theme] = current_theme
|
||||
_element = Button.new(text, options, block) { if block.is_a?(Proc); block.call; end }
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -44,7 +44,7 @@ module CyberarmEngine
|
||||
|
||||
def edit_line(text, options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
options[:theme] = current_theme
|
||||
_element = EditLine.new(text, options, block)
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -53,7 +53,7 @@ module CyberarmEngine
|
||||
|
||||
def toggle_button(options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
options[:theme] = current_theme
|
||||
_element = ToggleButton.new(options, block)
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -62,7 +62,7 @@ module CyberarmEngine
|
||||
|
||||
def check_box(text, options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
options[:theme] = current_theme
|
||||
_element = CheckBox.new(text, options, block)
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -71,7 +71,7 @@ module CyberarmEngine
|
||||
|
||||
def image(path, options = {}, &block)
|
||||
options[:parent] = @containers.last
|
||||
options[:theme] = @current_theme
|
||||
options[:theme] = current_theme
|
||||
_element = Image.new(path, options, block)
|
||||
@containers.last.add(_element)
|
||||
|
||||
@@ -87,8 +87,12 @@ module CyberarmEngine
|
||||
@containers.last.color(color)
|
||||
end
|
||||
|
||||
def set_theme(theme)
|
||||
def theme(theme)
|
||||
@current_theme = theme
|
||||
end
|
||||
|
||||
def current_theme
|
||||
@containers.last.options[:theme]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -47,10 +47,10 @@ module CyberarmEngine
|
||||
|
||||
def enter(sender)
|
||||
if @focus
|
||||
@background_canvas.background = default(:active, :background)
|
||||
@style.background_canvas.background = default(:active, :background)
|
||||
@text.color = default(:active, :color)
|
||||
else
|
||||
@background_canvas.background = default(:hover, :background)
|
||||
@style.background_canvas.background = default(:hover, :background)
|
||||
@text.color = default(:hover, :color)
|
||||
end
|
||||
end
|
||||
@@ -63,7 +63,7 @@ module CyberarmEngine
|
||||
|
||||
def blur(sender)
|
||||
@focus = false
|
||||
@background_canvas.background = default(:background)
|
||||
@style.background_canvas.background = default(:background)
|
||||
@text.color = default(:color)
|
||||
window.text_input = nil
|
||||
end
|
||||
|
||||
@@ -5,13 +5,7 @@ module CyberarmEngine
|
||||
include Common
|
||||
|
||||
attr_accessor :x, :y, :z, :enabled
|
||||
attr_reader :width, :height, :parent, :options, :event_handler, :background_canvas, :border_canvas
|
||||
|
||||
attr_reader :border_thickness, :border_thickness_left, :border_thickness_right, :border_thickness_top, :border_thickness_bottom
|
||||
attr_reader :border_color, :border_color_left, :border_color_right, :border_color_top, :border_color_bottom
|
||||
|
||||
attr_reader :padding, :padding_left, :padding_right, :padding_top, :padding_bottom
|
||||
attr_reader :margin, :margin_left, :margin_right, :margin_top, :margin_bottom
|
||||
attr_reader :width, :height, :parent, :options, :style, :event_handler, :background_canvas, :border_canvas
|
||||
|
||||
def initialize(options = {}, block = nil)
|
||||
@parent = options[:parent] # parent Container (i.e. flow/stack)
|
||||
@@ -21,8 +15,8 @@ module CyberarmEngine
|
||||
|
||||
@style = Style.new(options)
|
||||
@focus = false
|
||||
@background_canvas = Background.new
|
||||
@border_canvas = BorderCanvas.new(element: self)
|
||||
@style.background_canvas = Background.new
|
||||
@style.border_canvas = BorderCanvas.new(element: self)
|
||||
|
||||
@x = default(:x)
|
||||
@y = default(:y)
|
||||
@@ -59,46 +53,46 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def set_background(background)
|
||||
@background = background
|
||||
@background_canvas.background = background
|
||||
@style.background = background
|
||||
@style.background_canvas.background = background
|
||||
end
|
||||
|
||||
def set_border_thickness(border_thickness)
|
||||
@border_thickness = border_thickness
|
||||
@style.border_thickness = 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
|
||||
@style.border_thickness_left = default(:border_thickness_left) || @style.border_thickness
|
||||
@style.border_thickness_right = default(:border_thickness_right) || @style.border_thickness
|
||||
@style.border_thickness_top = default(:border_thickness_top) || @style.border_thickness
|
||||
@style.border_thickness_bottom = default(:border_thickness_bottom) || @style.border_thickness
|
||||
end
|
||||
|
||||
def set_border_color(color)
|
||||
@border_color = color
|
||||
@style.border_color = 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
|
||||
@style.border_color_left = default(:border_color_left) || @style.border_color
|
||||
@style.border_color_right = default(:border_color_right) || @style.border_color
|
||||
@style.border_color_top = default(:border_color_top) || @style.border_color
|
||||
@style.border_color_bottom = default(:border_color_bottom) || @style.border_color
|
||||
|
||||
@border_canvas.color = color
|
||||
@style.border_canvas.color = color
|
||||
end
|
||||
|
||||
def set_padding(padding)
|
||||
@padding = padding
|
||||
@style.padding = 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
|
||||
@style.padding_left = default(:padding_left) || @style.padding
|
||||
@style.padding_right = default(:padding_right) || @style.padding
|
||||
@style.padding_top = default(:padding_top) || @style.padding
|
||||
@style.padding_bottom = default(:padding_bottom) || @style.padding
|
||||
end
|
||||
|
||||
def set_margin(margin)
|
||||
@margin = margin
|
||||
@style.margin = 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
|
||||
@style.margin_left = default(:margin_left) || @style.margin
|
||||
@style.margin_right = default(:margin_right) || @style.margin
|
||||
@style.margin_top = default(:margin_top) || @style.margin
|
||||
@style.margin_bottom = default(:margin_bottom) || @style.margin
|
||||
end
|
||||
|
||||
def default_events
|
||||
@@ -145,8 +139,8 @@ module CyberarmEngine
|
||||
def draw
|
||||
return unless @visible
|
||||
|
||||
@background_canvas.draw
|
||||
@border_canvas.draw
|
||||
@style.background_canvas.draw
|
||||
@style.border_canvas.draw
|
||||
render
|
||||
end
|
||||
|
||||
@@ -168,44 +162,36 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def width
|
||||
(@border_thickness_left + @padding_left) + @width + (@padding_right + @border_thickness_right)
|
||||
(@style.border_thickness_left + @style.padding_left) + @width + (@style.padding_right + @style.border_thickness_right)
|
||||
end
|
||||
|
||||
def outer_width
|
||||
@margin_left + width + @margin_right
|
||||
@style.margin_left + width + @style.margin_right
|
||||
end
|
||||
|
||||
def height
|
||||
(@border_thickness_top + @padding_top) + @height + (@padding_bottom + @border_thickness_bottom)
|
||||
(@style.border_thickness_top + @style.padding_top) + @height + (@style.padding_bottom + @style.border_thickness_bottom)
|
||||
end
|
||||
|
||||
def outer_height
|
||||
@margin_top + height + @margin_bottom
|
||||
end
|
||||
|
||||
def style(hash)
|
||||
if hash
|
||||
@style.set(hash)
|
||||
else
|
||||
@style.hash
|
||||
end
|
||||
@style.margin_top + height + @style.margin_bottom
|
||||
end
|
||||
|
||||
def background=(_background)
|
||||
@background_canvas.background=(_background)
|
||||
@style.background_canvas.background=(_background)
|
||||
update_background
|
||||
end
|
||||
|
||||
def update_background
|
||||
@background_canvas.x = @x
|
||||
@background_canvas.y = @y
|
||||
@background_canvas.z = @z
|
||||
@background_canvas.width = width
|
||||
@background_canvas.height = height
|
||||
@style.background_canvas.x = @x
|
||||
@style.background_canvas.y = @y
|
||||
@style.background_canvas.z = @z
|
||||
@style.background_canvas.width = width
|
||||
@style.background_canvas.height = height
|
||||
|
||||
@background_canvas.update
|
||||
@style.background_canvas.update
|
||||
|
||||
@border_canvas.update
|
||||
@style.border_canvas.update
|
||||
end
|
||||
|
||||
def root
|
||||
|
||||
@@ -23,7 +23,11 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def render
|
||||
@image.draw(@border_thickness_left + @padding_left + @x, @border_thickness_top + @padding_top + @y, @z + 2, @scale_x, @scale_y) # TODO: Add color support?
|
||||
@image.draw(
|
||||
@style.border_thickness_left + @style.padding_left + @x,
|
||||
@style.border_thickness_top + @style.padding_top + @y,
|
||||
@z + 2,
|
||||
@scale_x, @scale_y) # TODO: Add color support?
|
||||
end
|
||||
|
||||
def clicked_left_mouse_button(sender, x, y)
|
||||
|
||||
@@ -26,8 +26,8 @@ module CyberarmEngine
|
||||
@width = @text.width.round
|
||||
@height= @text.height.round
|
||||
|
||||
@text.x = @border_thickness_left + @padding_left + @x
|
||||
@text.y = @border_thickness_top + @padding_top + @y
|
||||
@text.x = @style.border_thickness_left + @style.padding_left + @x
|
||||
@text.y = @style.border_thickness_top + @style.padding_top + @y
|
||||
@text.z = @z + 3
|
||||
|
||||
update_background
|
||||
|
||||
@@ -4,12 +4,17 @@ module CyberarmEngine
|
||||
@hash = hash
|
||||
end
|
||||
|
||||
def hash
|
||||
@hash
|
||||
end
|
||||
def method_missing(method, *args, &block)
|
||||
if method.to_s.end_with?("=")
|
||||
raise "Did not expect more than 1 argument" if args.size > 1
|
||||
return @hash[method.to_s.sub("=", "").to_sym] = args.first
|
||||
|
||||
def set(hash)
|
||||
@hash.merge!(hash)
|
||||
elsif args.size == 0
|
||||
return @hash[method]
|
||||
|
||||
else
|
||||
raise ArgumentError, "Did not expect arguments"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user