Module: TaskJuggler::Painter::Primitives
- Included in:
- TaskJuggler::Painter, Element, Group
- Defined in:
- lib/taskjuggler/Painter/Primitives.rb
Overview
This module contains utility methods to create the canvas Elements with minimal overhead. The element is added to it’s current parent and mandatory arguments are enforced. It also eliminates the need to call ‘new’ methods of each Element.
Constant Summary collapse
- StrokeAttrs =
[ :stroke, :stroke_opacity, :stroke_width ]
- FillAttrs =
[ :fill, :fill_opacity ]
- FillAndStrokeAttrs =
StrokeAttrs + FillAttrs
- TextAttrs =
FillAndStrokeAttrs + [ :font_family, :font_size ]
Instance Method Summary collapse
- #circle(cx, cy, r, attrs = {}) ⇒ Object
- #color(*args) ⇒ Object
- #ellipse(cx, cy, rx, ry, attrs = {}) ⇒ Object
- #group(attrs = {}, &block) ⇒ Object
- #line(x1, y1, x2, y2, attrs = {}) ⇒ Object
- #points(arr) ⇒ Object
- #polyline(points, attrs = {}) ⇒ Object
- #rect(x, y, width, height, attrs = {}) ⇒ Object
- #text(x, y, str, attrs = {}) ⇒ Object
Instance Method Details
#circle(cx, cy, r, attrs = {}) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/taskjuggler/Painter/Primitives.rb', line 48 def circle(cx, cy, r, attrs = {}) attrs[:cx] = cx attrs[:cy] = cy attrs[:r] = r @elements << (c = Circle.new(attrs)) c end |
#color(*args) ⇒ Object
35 36 37 |
# File 'lib/taskjuggler/Painter/Primitives.rb', line 35 def color(*args) Color.new(*args) end |
#ellipse(cx, cy, rx, ry, attrs = {}) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/taskjuggler/Painter/Primitives.rb', line 56 def ellipse(cx, cy, rx, ry, attrs = {}) attrs[:cx] = cx attrs[:cy] = cy attrs[:rx] = rx attrs[:ry] = ry @elements << (e = Ellipse.new(attrs)) e end |
#group(attrs = {}, &block) ⇒ Object
43 44 45 46 |
# File 'lib/taskjuggler/Painter/Primitives.rb', line 43 def group(attrs = {}, &block) @elements << (g = Group.new(attrs, &block)) g end |
#line(x1, y1, x2, y2, attrs = {}) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/taskjuggler/Painter/Primitives.rb', line 65 def line(x1, y1, x2, y2, attrs = {}) attrs[:x1] = x1 attrs[:y1] = y1 attrs[:x2] = x2 attrs[:y2] = y2 @elements << (l = Line.new(attrs)) l end |
#points(arr) ⇒ Object
39 40 41 |
# File 'lib/taskjuggler/Painter/Primitives.rb', line 39 def points(arr) Points.new(arr) end |
#polyline(points, attrs = {}) ⇒ Object
74 75 76 77 78 |
# File 'lib/taskjuggler/Painter/Primitives.rb', line 74 def polyline(points, attrs = {}) attrs[:points] = points.is_a?(Array) ? Points.new(points) : points @elements << (l = PolyLine.new(attrs)) l end |