class CTioga2::Graphics::Styles::ArrowStyle
This class represents an arrow
Constants
- TiogaDefaults
Public Instance Methods
draw_arrow(t, x1, y1, x2, y2)
click to toggle source
Draws an arrow.
# File lib/ctioga2/graphics/styles/arrows.rb, line 59 def draw_arrow(t, x1, y1, x2, y2) dx = x2 - x1 dy = y2 - y1 angle = Types::Dimension.get_angle(t, dx, dy) len = Types::Dimension.get_distance(t, dx, dy) rs = symbol_size(t, "head") ls = symbol_size(t, "tail") x1n, y1n, x2n, y2n = *Types::Dimension::adjust_line(t, x1, y1, x2, y2, -ls, -rs) # Must shorten the path first... sv = t.line_cap # This has for effect to disable changing the line cap when # there are now arrows to draw. if ! (has_marker?('head') || has_marker?('tail')) sv = Tioga::FigureConstants::LINE_CAP_BUTT end if sv != Tioga::FigureConstants::LINE_CAP_BUTT t.line_cap = Tioga::FigureConstants::LINE_CAP_BUTT end draw_line(t, x1n, y1n, x2n, y2n) if sv != Tioga::FigureConstants::LINE_CAP_BUTT t.line_cap = sv end # Then, draw the arrow heads/tails draw_symbol(t, 'head', angle, x2, y2) draw_symbol(t, 'tail', angle - 180, x1, y1) end
old_draw_arrow(t, x1, y1, x2, y2)
click to toggle source
# File lib/ctioga2/graphics/styles/arrows.rb, line 43 def old_draw_arrow(t, x1, y1, x2, y2) dict = self.to_hash dict.rename_key('width', 'line_width') dict.rename_key('style', 'line_style') dict['head'] = [x2,y2] dict['tail'] = [x1,y1] for w in %w(head tail) if dict["#{w}_marker"] == false dict["#{w}_marker"] = "None" end end t.show_arrow(dict) end
Protected Instance Methods
draw_symbol(t, name, angle, x, y)
click to toggle source
Draw the arrow symbol for the given name (head or tail), with the given base angle and at the given position
# File lib/ctioga2/graphics/styles/arrows.rb, line 129 def draw_symbol(t, name, angle, x, y) hsh = {} for k in %w(marker scale color angle) tmp = self.send("#{name}_#{k}") if tmp hsh[k] = tmp end end mkr = hsh['marker'] if ! mkr or mkr == 'None' return end hsh['angle'] ||= 0 hsh['angle'] += angle hsh['x'] = x hsh['y'] = y # Color defaults to line color if @color and !hsh.key?('color') hsh['color'] = @color end hsh['justification'] = just(name) t.show_marker(hsh) end
has_marker?(name)
click to toggle source
# File lib/ctioga2/graphics/styles/arrows.rb, line 118 def has_marker?(name) mkr = self.send("#{name}_marker") if ! mkr or mkr == 'None' return false else return true end end
just(name)
click to toggle source
# File lib/ctioga2/graphics/styles/arrows.rb, line 108 def just(name) mkr = self.send("#{name}_marker") if mkr == Tioga::MarkerConstants::Arrowhead or mkr == Tioga::MarkerConstants::ArrowheadOpen Tioga::FigureConstants::RIGHT_JUSTIFIED else Tioga::FigureConstants::CENTERED end end
symbol_size(t, name)
click to toggle source
Return the dimension of the arrow size
# File lib/ctioga2/graphics/styles/arrows.rb, line 97 def symbol_size(t, name) sz = Types::Dimension.new(:dy,self.send("#{name}_scale") || 1.0) sz.value *= case just(name) when Tioga::FigureConstants::CENTERED 0 when Tioga::FigureConstants::RIGHT_JUSTIFIED 0.5 end return sz end