Class: Wx::SF::ArrowBase
- Inherits:
-
Object
- Object
- Wx::SF::ArrowBase
- Includes:
- FIRM::Serializable
- Defined in:
- lib/wx/shapes/arrow_base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#draw(from, to, dc) ⇒ Wx::Point
Translated connection point for arrow.
-
#get_parent_shape ⇒ Wx::SF::Shape?
(also: #parent_shape)
Get pointer to a parent shape.
-
#initialize(parent = nil) ⇒ ArrowBase
constructor
Constructor.
-
#set_parent_shape(parent) ⇒ Object
(also: #parent_shape=)
Set a parent of the arrow shape.
-
#translate_arrow(src, from, to, trg = []) ⇒ Array<Wx::Point>
protected
Array with translated vertices.
Constructor Details
#initialize(parent = nil) ⇒ ArrowBase
Constructor
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.
37 38 39 |
# File 'lib/wx/shapes/arrow_base.rb', line 37 def draw(from, to, dc) raise NotImplementedError, 'Overload missing' end |
#get_parent_shape ⇒ Wx::SF::Shape? Also known as: parent_shape
Get pointer to a parent shape.
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.
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.
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 |