Class: Hokusai::Commands::Rect
- Defined in:
- ui/src/hokusai/commands/rect.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#outline ⇒ Object
Returns the value of attribute outline.
-
#outline_color ⇒ Object
Returns the value of attribute outline_color.
-
#padding ⇒ Object
Returns the value of attribute padding.
-
#rounding ⇒ Object
readonly
Returns the value of attribute rounding.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#background_boundary ⇒ Object
Returns a tuple with the computed geometric inner boundary for this rectangle with outlines subtracted.
-
#boundary ⇒ Object
Returns a tuple with the geometric boundary for this rectangle.
-
#h ⇒ Object
Shorthand for #height.
- #hash ⇒ Object
-
#initialize(x, y, width, height) ⇒ Rect
constructor
A new instance of Rect.
-
#outline? ⇒ Boolean
Returns true if this rectangle has an outline.
-
#outline_uniform? ⇒ Boolean
Returns true if this rectangle’s outline is uniform.
-
#padding? ⇒ Boolean
Returns true if the rectangle has any padding.
-
#round=(amount) ⇒ Object
Rounding amount for this rect.
-
#trim_canvas(canvas) ⇒ Object
Modifies the parameter Canvas to offset the boundary with this rectangle’s computed geometry.
-
#w ⇒ Object
Shorthand for #width.
Methods inherited from Base
#after_draw, draw, #draw, on_draw
Constructor Details
#initialize(x, y, width, height) ⇒ Rect
Returns a new instance of Rect.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'ui/src/hokusai/commands/rect.rb', line 7 def initialize(x, y, width, height) @x = x.to_f @y = y.to_f @width = width.to_f @height = height.to_f @outline = Outline.default @rounding = 0.0 @color = Color.new(0, 0, 0, 0) @outline_color = Color.new(0, 0, 0, 255) @padding = Padding.new(0.0, 0.0, 0.0, 0.0) end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
3 4 5 |
# File 'ui/src/hokusai/commands/rect.rb', line 3 def color @color end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
3 4 5 |
# File 'ui/src/hokusai/commands/rect.rb', line 3 def height @height end |
#outline ⇒ Object
Returns the value of attribute outline.
3 4 5 |
# File 'ui/src/hokusai/commands/rect.rb', line 3 def outline @outline end |
#outline_color ⇒ Object
Returns the value of attribute outline_color.
3 4 5 |
# File 'ui/src/hokusai/commands/rect.rb', line 3 def outline_color @outline_color end |
#padding ⇒ Object
Returns the value of attribute padding.
3 4 5 |
# File 'ui/src/hokusai/commands/rect.rb', line 3 def padding @padding end |
#rounding ⇒ Object (readonly)
Returns the value of attribute rounding.
3 4 5 |
# File 'ui/src/hokusai/commands/rect.rb', line 3 def rounding @rounding end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
3 4 5 |
# File 'ui/src/hokusai/commands/rect.rb', line 3 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
3 4 5 |
# File 'ui/src/hokusai/commands/rect.rb', line 3 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
3 4 5 |
# File 'ui/src/hokusai/commands/rect.rb', line 3 def y @y end |
Instance Method Details
#background_boundary ⇒ Object
Returns a tuple with the computed geometric inner boundary for this rectangle with outlines subtracted
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'ui/src/hokusai/commands/rect.rb', line 119 def background_boundary nx = x.dup ny = y.dup nw = width.dup nh = height.dup if outline.top > 0.0 ny += outline.top nh -= outline.top end if outline.left > 0.0 nx += outline.left nw -= outline.left end if outline.bottom > 0.0 nh -= outline.bottom end if outline.right > 0.0 nw -= outline.right end [nx, ny, nw, nh] end |
#boundary ⇒ Object
Returns a tuple with the geometric boundary for this rectangle
112 113 114 |
# File 'ui/src/hokusai/commands/rect.rb', line 112 def boundary [x, y, width, height] end |
#h ⇒ Object
Shorthand for #height
43 44 45 |
# File 'ui/src/hokusai/commands/rect.rb', line 43 def h height end |
#hash ⇒ Object
19 20 21 |
# File 'ui/src/hokusai/commands/rect.rb', line 19 def hash [self.class, x, y, width, height, rounding, color.hash, outline.hash, outline_color.hash, padding.hash].hash end |
#outline? ⇒ Boolean
Returns true if this rectangle has an outline
148 149 150 |
# File 'ui/src/hokusai/commands/rect.rb', line 148 def outline? outline.present? end |
#outline_uniform? ⇒ Boolean
Returns true if this rectangle’s outline is uniform
154 155 156 |
# File 'ui/src/hokusai/commands/rect.rb', line 154 def outline_uniform? outline.uniform? end |
#padding? ⇒ Boolean
Returns true if the rectangle has any padding
104 105 106 107 108 |
# File 'ui/src/hokusai/commands/rect.rb', line 104 def padding? [padding.t, padding.r, padding.b, padding.l].any? do |p| p != 0.0 end end |
#round=(amount) ⇒ Object
Rounding amount for this rect
97 98 99 100 101 |
# File 'ui/src/hokusai/commands/rect.rb', line 97 def round=(amount) @rounding = amount self end |
#trim_canvas(canvas) ⇒ Object
Modifies the parameter Canvas to offset the boundary with this rectangle’s computed geometry
26 27 28 29 30 31 32 33 34 35 |
# File 'ui/src/hokusai/commands/rect.rb', line 26 def trim_canvas(canvas) x, y, w, h = background_boundary canvas.x = x + padding.left + outline.left canvas.y = y + padding.top + outline.top canvas.width = w - (padding.left + padding.right + outline.left + outline.right) canvas.height = h - (padding.top + padding.bottom + outline.top + outline.bottom) canvas end |
#w ⇒ Object
Shorthand for #width
38 39 40 |
# File 'ui/src/hokusai/commands/rect.rb', line 38 def w width end |