Class: Wx::SF::ArrowBase

Inherits:
Object
  • Object
show all
Includes:
FIRM::Serializable
Defined in:
lib/wx/shapes/arrow_base.rb

Direct Known Subclasses

LineArrow

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ ArrowBase

Constructor

Parameters:



15
16
17
# File 'lib/wx/shapes/arrow_base.rb', line 15

def initialize(parent=nil)
  @parent_shape = parent
end

Instance Method Details

#draw(from, to, dc) ⇒ Wx::Point

Returns translated connection point for arrow.

Returns:

  • (Wx::Point)

    translated connection point for arrow

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/wx/shapes/arrow_base.rb', line 37

def draw(from, to, dc)
  raise NotImplementedError, 'Overload missing'
end

#get_parent_shapeWx::SF::Shape? Also known as: parent_shape

Get pointer to a parent shape.

Returns:



28
29
30
# File 'lib/wx/shapes/arrow_base.rb', line 28

def get_parent_shape
  @parent_shape
end

#set_parent_shape(parent) ⇒ Object Also known as: parent_shape=

Set a parent of the arrow shape.

Parameters:



21
22
23
# File 'lib/wx/shapes/arrow_base.rb', line 21

def set_parent_shape(parent)
  @parent_shape = parent
end

#translate_arrow(src, from, to, trg = []) ⇒ Array<Wx::Point> (protected)

Returns array with translated vertices.

Parameters:

  • trg (Array<Wx::Point>) (defaults to: [])

    array where translated vertices will be stored

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/wx/shapes/arrow_base.rb', line 49

def translate_arrow(src, from, to, trg = [])
  # calculate distance between line points
  from = from.to_real_point; to = to.to_real_point
  dist = from.distance_to(to)

  if dist == 0.0
    src.each do |pt|
      trg << Wx::Point.new(((pt.x-pt.y)+to.x).to_i,
                           ((pt.x+pt.y)+to.y).to_i)
    end
  else
    # calculate sin and cos of given line segment
    sina = (from.y - to.y)/dist
    cosa = (from.x - to.x)/dist

    # rotate arrow
    src.each do |pt|
      trg << Wx::Point.new(((pt.x*cosa-pt.y*sina)+to.x).to_i,
                           ((pt.x*sina+pt.y*cosa)+to.y).to_i)
    end
  end
  trg
end