Class: CyberarmEngine::BorderCanvas
- Inherits:
-
Object
- Object
- CyberarmEngine::BorderCanvas
- Defined in:
- lib/cyberarm_engine/ui/border_canvas.rb
Instance Attribute Summary collapse
-
#bottom ⇒ Object
readonly
Returns the value of attribute bottom.
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
-
#top ⇒ Object
readonly
Returns the value of attribute top.
Instance Method Summary collapse
- #color=(color) ⇒ Object
- #draw ⇒ Object
-
#initialize(element:) ⇒ BorderCanvas
constructor
A new instance of BorderCanvas.
- #update ⇒ Object
Constructor Details
#initialize(element:) ⇒ BorderCanvas
Returns a new instance of BorderCanvas.
5 6 7 8 9 10 11 12 |
# File 'lib/cyberarm_engine/ui/border_canvas.rb', line 5 def initialize(element:) @element = element @top = Background.new @right = Background.new @bottom = Background.new @left = Background.new end |
Instance Attribute Details
#bottom ⇒ Object (readonly)
Returns the value of attribute bottom.
3 4 5 |
# File 'lib/cyberarm_engine/ui/border_canvas.rb', line 3 def bottom @bottom end |
#element ⇒ Object (readonly)
Returns the value of attribute element.
3 4 5 |
# File 'lib/cyberarm_engine/ui/border_canvas.rb', line 3 def element @element end |
#left ⇒ Object (readonly)
Returns the value of attribute left.
3 4 5 |
# File 'lib/cyberarm_engine/ui/border_canvas.rb', line 3 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
3 4 5 |
# File 'lib/cyberarm_engine/ui/border_canvas.rb', line 3 def right @right end |
#top ⇒ Object (readonly)
Returns the value of attribute top.
3 4 5 |
# File 'lib/cyberarm_engine/ui/border_canvas.rb', line 3 def top @top end |
Instance Method Details
#color=(color) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cyberarm_engine/ui/border_canvas.rb', line 14 def color=(color) if color.is_a?(Numeric) @top.background = color @right.background = color @bottom.background = color @left.background = color elsif color.is_a?(Gosu::Color) @top.background = color @right.background = color @bottom.background = color @left.background = color elsif color.is_a?(Array) if color.size == 1 color = color.first elsif color.size == 2 @top.background = color.first @right.background = color.first @bottom.background = color.last @left.background = color.last elsif color.size == 4 @top.background = color[0] @right.background = color[1] @bottom.background = color[2] @left.background = color[3] else raise ArgumentError, "color array was empty or had wrong number of elements (expected 2 or 4 elements)" end elsif color.is_a?(Hash) @top.background = color[:top] @right.background = color[:right] @bottom.background = color[:bottom] @left.background = color[:left] else raise ArgumentError, "color '#{color}' of type '#{color.class}' was not able to be processed" end end |
#draw ⇒ Object
56 57 58 59 60 61 |
# File 'lib/cyberarm_engine/ui/border_canvas.rb', line 56 def draw @top.draw @right.draw @bottom.draw @left.draw end |
#update ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cyberarm_engine/ui/border_canvas.rb', line 63 def update # TOP @top.x = @element.x + @element.style.border_thickness_left @top.y = @element.y @top.z = @element.z @top.width = @element.width - @element.style.border_thickness_left @top.height = @element.style.border_thickness_top # RIGHT @right.x = @element.x + @element.width @right.y = @element.y + @element.style.border_thickness_top @right.z = @element.z @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.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.style.border_thickness_left @left.height = @element.height - @element.style.border_thickness_bottom @top.update @right.update @bottom.update @left.update end |