class SyncSign::Widget::Rectangle

A widget that draws a rectangle.

Attributes

pen_width[RW]

Public Class Methods

new(x: nil, y: nil, width: nil, height: nil, colour: :black, bgcolour: :white, pen_width: 1, fillpattern: :none, strokepattern: :solid) click to toggle source

Initialize a new rectangle widget. @param x [Integer] horizontal position of the left side of the rectangle. @param y [Integer] vertical position of the top of the rectangle. @param width [Integer] how wide the rectangle should be. @param height [Integer] how tall the rectangle should be. @param colour [Symbol] The stroke colour used for the rectangle

(either black, white, or red).

@param bgcolour [Symbol] The fill colour used for the rectangle

(either black, white, or red).

@param pen_width [Integer] The width in pixels of the stroke.

Calls superclass method SyncSign::Widget::Box::new
# File lib/syncsign/widgets/rectangle.rb, line 19
def initialize(x: nil, y: nil, width: nil, height: nil, colour: :black, bgcolour: :white, pen_width: 1, fillpattern: :none, strokepattern: :solid)
  Widget::check_patterns [fillpattern, strokepattern]
  raise(AlignmentException, "Rect: x and width must both be a multiple of 8") if x % 8 != 0 or width % 8 != 0
  @pen_width = pen_width
  @fillpattern = fillpattern
  @strokepattern = strokepattern
  super(x: x, y: y, width: width, height: height, colour: colour, bgcolour: bgcolour)
end

Public Instance Methods

==(other) click to toggle source
# File lib/syncsign/widgets/rectangle.rb, line 44
def ==(other)
  @x == other.x                           &&
  @y == other.y                           &&
  @width == other.width                   &&
  @height == other.height                 &&
  @colour == other.colour                 &&
  @bgcolour == other.bgcolour             &&
  @pen_width == other.pen_width           &&
  @fillpattern == other.fillpattern       &&
  @strokepattern == other.strokepattern
end
to_a() click to toggle source

Convert the widget into an array for sending to the SyncSign service.

# File lib/syncsign/widgets/rectangle.rb, line 30
def to_a
  {
    'type': 'RECTANGLE',
    'data': {
      'block': {x: @x, y: @y, w: @width, h: @height},
      'fillColor': @bgcolour.to_s.upcase,
      'fillPattern': @fillpattern.to_s.upcase,
      'strokeColor': @colour.to_s.upcase,
      'strokePattern': @strokepattern.to_s.upcase,
      'strokeThickness': @pen_width
    }
  }
end