Class Limelight::Pen
In: lib/limelight/pen.rb
Parent: Object

The Pen is acquired from Prop.pen. It is used to draw directly on the screen withing the bounds of the prop from which the Pen was acquired.

All points used by the Pen are relative to the bounds of the Prop. The top left corner of the Prop is represented by the point (0, 0). If a Prop has margin, border, or padding, the point (0, 0) may appear to be outside the Prop.

Methods

Attributes

context  [RW] 

Public Class methods

It is constructed with a context which is essentially a java.awt.Graphic2D object. Defaults are set:

  • color = "black"
  • width = 1
  • smooth = false

[Source]

    # File lib/limelight/pen.rb, line 21
21:     def initialize(context)
22:       @context = context
23:       self.color = "black"
24:       self.width = 1
25:       self.smooth = false
26:     end

Public Instance methods

Sets the color of the Pen. The passed value should be a string that either names a known color or specifies a hex color value.

[Source]

    # File lib/limelight/pen.rb, line 31
31:     def color=(value)
32:       resolve_color = Util::Colors.resolve(value)
33:       @context.setColor(resolve_color)
34:     end

Draws a line from the point (x1, y1) to the point (x2, y2)

[Source]

    # File lib/limelight/pen.rb, line 52
52:     def draw_line(x1, y1, x2, y2)
53:       @context.drawLine(x1, y1, x2, y2)
54:     end

Draws the largest oval that will fit in the specified rectangle. The top left corner of the bounding rectangle is at (x, y). The center of the oval will be at (x + width/2, y + height/2).

[Source]

    # File lib/limelight/pen.rb, line 71
71:     def draw_oval(x, y, width, height)
72:       @context.drawOval(x, y, width, height)
73:     end

Draws a rectangle with the top left corner at (x, y).

[Source]

    # File lib/limelight/pen.rb, line 58
58:     def draw_rectangle(x, y, width, height)
59:       @context.drawRect(x, y, width, height)
60:     end

Fills an oval specified by the bounding rectangle. See draw_oval.

[Source]

    # File lib/limelight/pen.rb, line 77
77:     def fill_oval(x, y, width, height)
78:       @context.fillOval(x, y, width, height)
79:     end

Fills a rectangle with the current color of the Pen. The top left corner of the rectangle is (x, y).

[Source]

    # File lib/limelight/pen.rb, line 64
64:     def fill_rectangle(x, y, width, height)
65:       @context.fillRect(x, y, width, height)
66:     end

Specifies whether the pen will use anti-aliasing to draw smooth shapes or not. Shapes will appear pixilated when smooth is set to false.

[Source]

    # File lib/limelight/pen.rb, line 45
45:     def smooth=(value)
46:       hint = value ? java.awt.RenderingHints::VALUE_ANTIALIAS_ON : java.awt.RenderingHints::VALUE_ANTIALIAS_OFF
47:       @context.setRenderingHint(java.awt.RenderingHints::KEY_ANTIALIASING, hint)
48:     end

Sets the width, in pixels, of the pen.

[Source]

    # File lib/limelight/pen.rb, line 38
38:     def width=(value)
39:       @context.setStroke(java.awt.BasicStroke.new(value))
40:     end

[Validate]