Class: Wx::SF::ConnectionPoint
- Inherits:
-
Object
- Object
- Wx::SF::ConnectionPoint
- Includes:
- FIRM::Serializable
- Defined in:
- lib/wx/shapes/connection_point.rb
Defined Under Namespace
Modules: DEFAULT Classes: CPORTHODIR, CPTYPE
Constant Summary collapse
- RADIUS =
3
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
-
#contains(pos) ⇒ Boolean
(also: #contains?)
True if the point is inside the handle, otherwise false.
- #draw(dc) ⇒ Object
- #draw_hover(dc) ⇒ Object protected
- #draw_normal(dc) ⇒ Object protected
-
#get_connection_point ⇒ Wx::RealPoint
(also: #connection_point)
Absolute position of the connection point.
-
#get_ortho_direction ⇒ CPORTHODIR
(also: #ortho_direction)
Current direction.
-
#get_parent_shape ⇒ Wx::SF::Shape
(also: #parent_shape)
Parent shape.
-
#get_relative_position ⇒ Wx::RealPoint
(also: #relative_position)
Relative position in percentages.
-
#get_type ⇒ CPTYPE
(also: #type)
Connection point type.
-
#initialize(*args) ⇒ ConnectionPoint
constructor
Constructor.
-
#refresh ⇒ Object
Refresh (repaint) the dock point.
- #set_ortho_direction(dir) ⇒ Object (also: #ortho_direction=)
- #set_parent_shape(parent) ⇒ Object (also: #parent_shape=)
-
#set_relative_position(pos) ⇒ Object
(also: #relative_position=)
Set relative position of custom connection point.
-
#set_type(type) ⇒ Object
(also: #type=)
Set connection point type.
Constructor Details
#initialize ⇒ ConnectionPoint #initialize(parent, pos, id = nil) ⇒ ConnectionPoint #initialize(parent, type) ⇒ ConnectionPoint
Constructor
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/wx/shapes/connection_point.rb', line 57 def initialize(*args) @parent_shape, type_or_pos, id = *args if type_or_pos # allow parent to be nil (mainly for testing purposes) if CPTYPE === type_or_pos @type = type_or_pos @rel_position = DEFAULT::RELPOS @id = nil elsif Wx::RealPoint === type_or_pos || Array === type_or_pos @type = CPTYPE::CUSTOM @rel_position = Wx::RealPoint === type_or_pos ? type_or_pos : Wx::RealPoint.new(*type_or_pos) @id = id else ::Kernel.raise ArgumentError, 'Invalid arguments' end @ortho_dir = DEFAULT::ORTHODIR @mouse_over = false end end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
76 77 78 |
# File 'lib/wx/shapes/connection_point.rb', line 76 def id @id end |
Instance Method Details
#contains(pos) ⇒ Boolean Also known as: contains?
Returns true if the point is inside the handle, otherwise false.
181 182 183 184 |
# File 'lib/wx/shapes/connection_point.rb', line 181 def contains(pos) # HINT: overload it for custom actions... connection_point.distance_to(pos.to_real_point) < (3 * RADIUS) end |
#draw(dc) ⇒ Object
189 190 191 192 193 194 195 |
# File 'lib/wx/shapes/connection_point.rb', line 189 def draw(dc) if @mouse_over draw_hover(dc) else draw_normal(dc) end end |
#draw_hover(dc) ⇒ Object (protected)
213 214 215 216 217 218 219 220 |
# File 'lib/wx/shapes/connection_point.rb', line 213 def draw_hover(dc) # HINT: overload it for custom actions... dc.with_pen(Wx::BLACK_PEN) do dc.with_brush(Wx::RED_BRUSH) do dc.draw_circle(connection_point.to_point, RADIUS) end end end |
#draw_normal(dc) ⇒ Object (protected)
206 207 208 |
# File 'lib/wx/shapes/connection_point.rb', line 206 def draw_normal(dc) # HINT: overload it for custom actions... end |
#get_connection_point ⇒ Wx::RealPoint Also known as: connection_point
Returns Absolute position of the connection point.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/wx/shapes/connection_point.rb', line 138 def get_connection_point if @parent_shape rctParent = @parent_shape.get_bounding_box case @type when CPTYPE::TOPLEFT return rctParent.top_left.to_real when CPTYPE::TOPMIDDLE return Wx::RealPoint.new((rctParent.left + rctParent.width/2).to_f, rctParent.top.to_f) when CPTYPE::TOPRIGHT return rctParent.top_right.to_real when CPTYPE::CENTERLEFT return Wx::RealPoint.new(rctParent.left.to_f, (rctParent.top + rctParent.height/2).to_f) when CPTYPE::CENTERMIDDLE return Wx::RealPoint.new((rctParent.left + rctParent.width/2).to_f, (rctParent.top + rctParent.height/2).to_f) when CPTYPE::CENTERRIGHT return Wx::RealPoint.new(rctParent.right.to_f, (rctParent.top + rctParent.height/2).to_f) when CPTYPE::BOTTOMLEFT return rctParent.bottom_left.to_real when CPTYPE::BOTTOMMIDDLE return Wx::RealPoint.new((rctParent.left + rctParent.width/2).to_f, rctParent.bottom.to_f) when CPTYPE::BOTTOMRIGHT return rctParent.bottom_right.to_real when CPTYPE::CUSTOM return Wx::RealPoint.new(rctParent.left + rctParent.width * @rel_position.x/100, rctParent.top + rctParent.height * @rel_position.y/100) end end Wx::RealPoint.new end |
#get_ortho_direction ⇒ CPORTHODIR Also known as: ortho_direction
Returns Current direction.
103 104 105 |
# File 'lib/wx/shapes/connection_point.rb', line 103 def get_ortho_direction @ortho_dir end |
#get_parent_shape ⇒ Wx::SF::Shape Also known as: parent_shape
Returns parent shape.
117 118 119 |
# File 'lib/wx/shapes/connection_point.rb', line 117 def get_parent_shape @parent_shape end |
#get_relative_position ⇒ Wx::RealPoint Also known as: relative_position
Returns Relative position in percentages.
131 132 133 |
# File 'lib/wx/shapes/connection_point.rb', line 131 def get_relative_position @rel_position end |
#get_type ⇒ CPTYPE Also known as: type
Returns Connection point type.
80 81 82 |
# File 'lib/wx/shapes/connection_point.rb', line 80 def get_type @type end |
#refresh ⇒ Object
Refresh (repaint) the dock point
198 199 200 |
# File 'lib/wx/shapes/connection_point.rb', line 198 def refresh @parent_shape.refresh(DELAYED) end |
#set_ortho_direction(dir) ⇒ Object Also known as: ortho_direction=
95 96 97 |
# File 'lib/wx/shapes/connection_point.rb', line 95 def set_ortho_direction(dir) @ortho_dir = dir end |
#set_parent_shape(parent) ⇒ Object Also known as: parent_shape=
110 111 112 |
# File 'lib/wx/shapes/connection_point.rb', line 110 def set_parent_shape(parent) @parent_shape = parent end |
#set_relative_position(pos) ⇒ Object Also known as: relative_position=
Set relative position of custom connection point.
@param [Wx::RealPoint,Array(Float, Float)] pos Relative position in percentages
124 125 126 |
# File 'lib/wx/shapes/connection_point.rb', line 124 def set_relative_position(pos) @rel_position = Wx::RealPoint === pos ? pos : Wx::RealPoint.new(*pos) end |
#set_type(type) ⇒ Object Also known as: type=
Set connection point type.
87 88 89 |
# File 'lib/wx/shapes/connection_point.rb', line 87 def set_type(type) @type = type end |