class DYI::Drawing::CubicPen
@since 0.0.0
Constants
- POSITION_TYPE_VALUES
Attributes
background_color[R]
background_opacity[R]
dx[R]
dy[R]
position_type[R]
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
DYI::Drawing::Pen::new
# File lib/dyi/drawing/pen_3d.rb, line 30 def initialize(options={}) self.position_type = options.delete(:position_type) self.background_color = options.delete(:background_color) self.background_opacity = options.delete(:background_opacity) self.dx = options.delete(:dx) self.dy = options.delete(:dy) super end
Public Instance Methods
background_color=(color)
click to toggle source
# File lib/dyi/drawing/pen_3d.rb, line 48 def background_color=(color) @background_color = Color.new_or_nil(color) end
background_opacity=(opacity)
click to toggle source
# File lib/dyi/drawing/pen_3d.rb, line 52 def background_opacity=(opacity) @background_opacity = opacity ? opacity.to_f : nil end
brush()
click to toggle source
# File lib/dyi/drawing/pen_3d.rb, line 72 def brush @brush ||= Brush.new(:color => background_color || color, :opacity => background_opacity || nil) end
draw_line(canvas, start_point, end_point, options={})
click to toggle source
Calls superclass method
DYI::Drawing::PenBase#draw_line
# File lib/dyi/drawing/pen_3d.rb, line 76 def draw_line(canvas, start_point, end_point, options={}) group = Shape::ShapeGroup.new draw_background_shape(group, start_point, end_point, options) super(group, start_point, end_point, options) adjust_z_coordinate(group) group.draw_on(canvas) end
draw_polyline(canvas, point, options={}, &block)
click to toggle source
Calls superclass method
DYI::Drawing::PenBase#draw_polyline
# File lib/dyi/drawing/pen_3d.rb, line 84 def draw_polyline(canvas, point, options={}, &block) group = Shape::ShapeGroup.new(options) polyline = super(group, point, {}, &block) (1...polyline.points.size).each do |i| draw_background_shape(group, polyline.points[i-1], polyline.points[i], {}) end polyline = super(group, point, {}, &block) adjust_z_coordinate(group) group.draw_on(canvas) end
dx=(value)
click to toggle source
# File lib/dyi/drawing/pen_3d.rb, line 60 def dx=(value) @dx = Length.new_or_nil(value) end
dy=(value)
click to toggle source
# File lib/dyi/drawing/pen_3d.rb, line 68 def dy=(value) @dy = Length.new_or_nil(value) end
position_type=(value)
click to toggle source
# File lib/dyi/drawing/pen_3d.rb, line 39 def position_type=(value) if value.to_s.size != 0 raise ArgumentError, "\"#{value}\" is invalid position-type" unless POSITION_TYPE_VALUES.include?(value) @position_type = value else @position_type = nil end end
Private Instance Methods
adjust_z_coordinate(shape)
click to toggle source
# File lib/dyi/drawing/pen_3d.rb, line 97 def adjust_z_coordinate(shape) case position_type when :center then shape.translate(-dx / 2, -dy / 2) when :backline then shape.translate(-dx, -dy) end end
draw_background_shape(canvas, start_point, end_point, options={})
click to toggle source
# File lib/dyi/drawing/pen_3d.rb, line 104 def draw_background_shape(canvas, start_point, end_point, options={}) brush.draw_polygon(canvas, start_point, options) {|polygon| polygon.line_to(end_point) polygon.line_to(Coordinate.new(end_point) + Coordinate.new(dx, dy)) polygon.line_to(Coordinate.new(start_point) + Coordinate.new(dx, dy)) } end