Module: DYI::Shape::Markable
Overview
This module defines the method to attach a marker symbol to the lines, the polylines, the polygons or the paths.
Instance Method Summary collapse
-
#has_marker?(position) ⇒ Boolean
Returns whether this shape has a marker symbol.
-
#marker(position) ⇒ Marker
Returns a marker symbol at the specified position.
-
#set_marker(position, *args) ⇒ Object
Attaches a marker symbol to the shape.
Instance Method Details
#has_marker?(position) ⇒ Boolean
Returns whether this shape has a marker symbol.
111 112 113 |
# File 'lib/dyi/shape/base.rb', line 111 def has_marker?(position) !@marker[position].nil? end |
#marker(position) ⇒ Marker
Returns a marker symbol at the specified position.
36 37 38 |
# File 'lib/dyi/shape/base.rb', line 36 def marker(position) @marker[position] end |
#set_marker(position, marker) ⇒ Object #set_marker(position, marker_type, options = {}) ⇒ Object
Attaches a marker symbol to the shape.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/dyi/shape/base.rb', line 62 def set_marker(position, *args) pos = case position when :start then 0x1 when :mid then 0x2 when :end then 0x4 when :start_mid then 0x3 when :start_end then 0x5 when :mid_end then 0x6 when :all then 0x7 else raise ArgumentError, "illegal argument: #{position.inspect}" end case args.first when Symbol opts = args[1].clone || {} opts[:painting] ||= Painting.new(:fill => painting.stroke, :fill_opacity => painting.stroke_opacity, :opacity => painting.opacity) if opts[:orient] == 'auto' opts[:direction] = position == :end ? :to_end : :to_start end marker = Marker.new(args.first, opts) when Marker marker = args.first else raise TypeError, "illegal argument: #{value}" end marker.set_canvas(canvas) @marker[:start] = marker if pos & 0x01 != 0 @marker[:mid] = marker if pos & 0x02 != 0 if pos & 0x04 != 0 if pos & 0x01 != 0 && args.first.is_a?(Symbol) && opts[:orient] == 'auto' opts[:painting] ||= Painting.new(:fill => painting.stroke, :fill_opacity => painting.stroke_opacity, :opacity => painting.opacity) opts[:direction] = :to_end marker = Marker.new(args.first, opts) marker.set_canvas(canvas) @marker[:end] = marker else @marker[:end] = marker end end end |