Class: Wx::SF::Shape
- Inherits:
-
Object
- Object
- Wx::SF::Shape
- Includes:
- FIRM::Serializable
- Defined in:
- lib/wx/shapes/shape.rb,
lib/wx/shapes/shape_handle.rb
Overview
Base class for all shapes providing fundamental functionality and publishing set of virtual functions which must be defined by the user in derived shapes. This class shouldn’t be used as it is.
Shape objects derived from this class use hierarchical approach. It means that every shape must have defined parent shape (can be NULL for topmost shapes). An absolute shape position is then calculated as a summation of all relative positions of all parent shapes. Also the size of the parent shape can be limited be a bounding box of all children shapes.
This class also declares set of virtual functions used as event handlers for various events (moving, sizing, drawing, mouse events, serialization and deserialization requests, …) mostly triggered by a parent shape canvas.
Defined Under Namespace
Modules: DEFAULT Classes: BBMODE, CONNECTMODE, HALIGN, Handle, SEARCHMODE, STYLE, VALIGN
Class Method Summary collapse
-
.component(*args) ⇒ Object
Declare a component shape property for the shape class.
- .component_shapes ⇒ Object
-
.lines_intersection(from1, to1, from2, to2) ⇒ Wx::RealPoint?
Returns intersection point of two lines (if any).
Instance Method Summary collapse
-
#accept_child(type) ⇒ Object
Add given shape type to an acceptance list.
-
#accept_connection(type) ⇒ Object
Add given connection type to an acceptance list.
-
#accept_currently_dragged_shapes ⇒ Boolean
Returns true if all currently dragged shapes can be accepted as children of this shape.
-
#accept_src_neighbour(type) ⇒ Object
Add given shape type to an source neighbours’ acceptance list.
-
#accept_trg_neighbour(type) ⇒ Object
Add given shape type to an target neighbours’ acceptance list.
- #activate(active) ⇒ Object (also: #set_active)
-
#active? ⇒ Boolean
(also: #active)
True if the shape is active, otherwise false.
-
#add_child_shape(child) ⇒ Wx::SF::Shape?
Adds child shape is accepted.
- #add_connection_point(arg, *rest, persistent: true) ⇒ Object
- #add_handle(type, id = -1)) ⇒ Object
- #add_style(style) ⇒ Object
-
#ancestor?(child) ⇒ Boolean
Determine whether this shape is ancestor of given child shape.
- #clear_accepted_childs ⇒ Object
- #clear_accepted_connections ⇒ Object
- #clear_accepted_src_neighbours ⇒ Object
- #clear_accepted_trg_neighbours ⇒ Object
-
#contains?(pos) ⇒ Boolean
Test whether the given point is inside the shape.
- #contains_style(style) ⇒ Object (also: #contains_style?, #has_style?)
-
#create_handles ⇒ Object
Function called by the framework responsible for creation of shape handles at the creation time.
-
#descendant?(parent) ⇒ Boolean
Determine whether this shape is descendant of given parent shape.
-
#do_alignment ⇒ Object
Update the shape’s position in order to its alignment.
-
#does_not_accept_children? ⇒ Boolean
(also: #no_children_accepted?, #accepts_no_children?)
Tells whether the shape does not accept ANY children.
-
#draw(dc, children = WITHCHILDREN) ⇒ Object
Draw shape.
-
#draw_highlighted(_dc) ⇒ Object
protected
Draw the shape in the highlighted mode (another shape is dragged over this shape and this shape will accept the dragged one if it will be dropped on it).
-
#draw_hover(_dc) ⇒ Object
protected
Draw the shape in the hover mode (the mouse cursor is above the shape).
-
#draw_normal(_dc) ⇒ Object
protected
Draw the shape in the normal way.
-
#draw_selected(dc) ⇒ Object
protected
Draw the shape in the selected way.
-
#draw_shadow(_dc) ⇒ Object
protected
Draw shadow under the shape.
-
#fit_to_children ⇒ Object
Resize the shape to bound all child shapes.
-
#get_absolute_position ⇒ Wx::RealPoint
Get the shape’s absolute position in the canvas (calculated as a summation of all relative positions in the shapes’ hierarchy. The function can be overridden if necessary..
-
#get_accepted_children ⇒ Set<String>
(also: #accepted_children)
String set with class names of accepted shape types.
-
#get_accepted_connections ⇒ Set<String>
(also: #accepted_connections)
String set with class names of accepted connection types.
-
#get_accepted_src_neighbours ⇒ Set<String>
(also: #accepted_src_neighbours)
String set with class names of accepted source neighbours types.
-
#get_accepted_trg_neighbours ⇒ Set<String>
(also: #accepted_trg_neighbours)
String set with class names of accepted target neighbours types.
- #get_assigned_connections(shape_info, mode, lines = []) ⇒ Object
-
#get_border_point(_start, _finish) ⇒ Wx::RealPoint
Get intersection point of the shape border and a line leading from ‘start’ point to ‘finish’ point.
-
#get_bounding_box ⇒ Wx::Rect
Get shape’s bounding box.
-
#get_center ⇒ Wx::RealPoint
Get shape’s center.
-
#get_child_shapes(type, recursive = NORECURSIVE, mode = SEARCHMODE::BFS, list = []) ⇒ Array<Wx::SF::Shape>
Get child shapes associated with this (parent) shape.
-
#get_children(type, list) ⇒ Array<Wx::SF::Shape>
Get children of given type.
-
#get_children_recursively(type, mode = SEARCHMODE::BFS, list = []) ⇒ Object
Get all children of given type recursively (i.e. children of children of .… ).
- #get_complete_bounding_box(rct, mask = BBMODE::ALL) ⇒ Object
-
#get_connection_point(type, id = nil) ⇒ Wx::SF::ConnectionPoint?
(also: #connection_point)
Connection point if exists, otherwise nil.
-
#get_connection_points ⇒ Array<Wx::SF::ConnectionPoint>
(also: #connection_points)
Connection points list.
-
#get_custom_dock_point ⇒ Integer
(also: #custom_dock_point)
Get custom dock point used if the shape is child shape of a line shape.
-
#get_diagram ⇒ Wx::SF::Diagram
(also: #diagram)
Get managing diagram.
-
#get_grand_parent_shape ⇒ Wx::SF::Shape
(also: #grand_parent_shape)
Get pointer to the topmost parent shape.
-
#get_h_align ⇒ HALIGN
(also: #h_align)
Get horizontal alignment of this shape inside its parent.
-
#get_h_border ⇒ Float
(also: #h_border)
Get horizontal border between this shape and its parent (if horizontal alignment is set).
-
#get_handle(type, id = -1)) ⇒ Wx::SF::Shape::Handle?
(also: #handle)
Shape handle object if exist.
-
#get_handles ⇒ Array<Wx::SF::Shape::Handle>
(also: #handles)
Get list of currently assigned shape handles.
-
#get_hover_colour ⇒ Wx::Colour
(also: #hover_colour)
Current hover color.
-
#get_nearest_connection_point(pos) ⇒ Wx::SF::ConnectionPoint?
(also: #nearest_connection_point)
Closest connection point if exists, otherwise nil.
- #get_neighbours(shape_info, condir, direct = DIRECT, neighbours = []) ⇒ Object
-
#get_parent_absolute_position ⇒ Wx::RealPoint
protected
Get absolute position of the shape parent.
-
#get_parent_canvas ⇒ Wx::SF::ShapeCanvas?
Get the shape canvas of the parent diagram.
-
#get_parent_shape ⇒ Wx::SF::Shape?
(also: #parent_shape)
Get parent shape.
-
#get_relative_position ⇒ Wx::RealPoint
Get shape’s relative position.
-
#get_shape_canvas ⇒ Wx::SF::ShapeCanvas?
(also: #shape_canvas)
Get shape’s diagram canvas.
-
#get_style ⇒ Integer
(also: #style)
Get current shape style.
-
#get_user_data ⇒ Object?
(also: #user_data)
Get associated user data.
-
#get_v_align ⇒ VALIGN
(also: #v_align)
Get vertical alignment of this shape inside its parent.
-
#get_v_border ⇒ Float
(also: #v_border)
Get vertical border between this shape and its parent (if vertical alignment is set).
-
#has_children ⇒ Boolean
(also: #has_children?)
Find out whether this shape has some children.
-
#has_selected_parent? ⇒ Boolean
(also: #selected_parent?)
Returns true if any (grand-)parent is selected?.
-
#include_child_shape?(shape, recursive = false) ⇒ Boolean
Returns true if the given shape is included in the child shapes list.
-
#initialize(pos = DEFAULT::POSITION, diagram: nil) ⇒ Shape
constructor
Constructor.
-
#inside?(rct) ⇒ Boolean
Test whether the shape is completely inside given rectangle.
- #inspect ⇒ Object
-
#intersects?(rct) ⇒ Boolean
Test whether the given rectangle intersects the shape.
-
#is_child_accepted(type) ⇒ Boolean
(also: #child_accepted?)
Tells whether the given shape type is accepted by this shape (it means whether this shape can be its parent).
-
#is_connection_accepted(type) ⇒ Object
(also: #connection_accepted?)
Tells whether the given connection type is accepted by this shape (it means whether this shape can be connected to another one by a connection of given type).
-
#is_managed ⇒ Boolean
(also: #managed?)
Returns true if this shape is managed (size/position/alignment) by it’s parent shape.
-
#is_manager ⇒ Boolean
(also: #manager?)
Returns true if this shape manages (size/position/alignment) of it’s child shapes.
-
#is_src_neighbour_accepted(type) ⇒ Object
(also: #src_neighbour_accepted?)
Tells whether the given shape type is accepted by this shape as its source neighbour(it means whether this shape can be connected from another one of given type).
-
#is_trg_neighbour_accepted(type) ⇒ Boolean
(also: #trg_neighbour_accepted?)
Tells whether the given shape type is accepted by this shape as its target neighbour(it means whether this shape can be connected to another one of given type).
-
#lines_intersection(*args) ⇒ Object
Allow shapes to call class method as instance method.
- #move_by(delta) ⇒ Object
- #move_to(pos) ⇒ Object
- #on_begin_drag(pos) ⇒ Object
-
#on_begin_handle(handle) ⇒ Object
The function can be overridden if necessary.
-
#on_child_dropped(_pos, child) ⇒ Object
shape is accepted as a child of this shape).
-
#on_dragging(pos) ⇒ Object
The function can be overridden if necessary.
-
#on_end_drag(pos) ⇒ Object
The function can be overridden if necessary.
- #on_end_handle(handle) ⇒ Object
- #on_handle(handle) ⇒ Object
-
#on_import ⇒ Object
protected
called after the shape has been newly imported/pasted/dropped allows for checking stale links by default does nothing.
-
#on_key(key) ⇒ Object
The function can be overridden if necessary.
-
#on_left_click(pos) ⇒ Object
the left mouse button.
-
#on_left_double_click(pos) ⇒ Object
the left mouse button.
-
#on_mouse_enter(pos) ⇒ Object
The function can be overridden if necessary.
-
#on_mouse_leave(pos) ⇒ Object
The function can be overridden if necessary.
-
#on_mouse_over(pos) ⇒ Object
The function can be overridden if necessary.
-
#on_right_click(pos) ⇒ Object
the right mouse button.
-
#on_right_double_click(pos) ⇒ Object
the right mouse button.
-
#refresh(delayed = false) ⇒ Object
Refresh (redraw) the shape.
- #refresh_rect(rct, delayed = false) ⇒ Object protected
- #remove_connection_point(type) ⇒ Object
-
#remove_handle(type, id = -1)) ⇒ Object
Remove given shape handle (if exists).
- #remove_style(style) ⇒ Object
-
#scale(*args, children: WITHCHILDREN) ⇒ Object
Scale the shape size in both directions.
-
#scale_children(x, y) ⇒ Object
Scale shape’s children.
-
#select(state) ⇒ Object
Set the shape as a selected/deselected one.
-
#selected? ⇒ Boolean
Function returns true if the shape is selected, otherwise returns false.
-
#set_custom_dock_point(dp) ⇒ Object
(also: #custom_dock_point=)
Set custom dock point used if the shape is child shape of a line shape.
-
#set_diagram(diagram) ⇒ Object
Set managing diagram.
-
#set_h_align(val) ⇒ Object
(also: #h_align=)
Set horizontal alignment of this shape inside its parent.
-
#set_h_border(border) ⇒ Object
(also: #h_border=)
Set horizontal border between this shape and its parent (if horizontal alignment is set).
-
#set_hover_colour(col) ⇒ Object
(also: #hover_colour=)
Set shape’s hover color.
-
#set_parent_shape(parent) ⇒ Object
(also: #parent_shape=)
Set parent shape object.
-
#set_relative_position(*arg) ⇒ Object
Set shape’s relative position.
-
#set_style(style) ⇒ Object
(also: #style=)
Set shape’s style.
-
#set_user_data(data) ⇒ Object
(also: #user_data=)
Associate user data with the shape.
-
#set_v_align(val) ⇒ Object
(also: #v_align=)
Set vertical alignment of this shape inside its parent.
-
#set_v_border(border) ⇒ Object
(also: #v_border=)
Set vertical border between this shape and its parent (if vertical alignment is set).
- #show(show) ⇒ Object (also: #set_visibility)
-
#show_handles(show) ⇒ Object
Show/hide shape handles.
- #to_s ⇒ Object
-
#update(recurse = true) ⇒ Object
Update shape (align all child shapes and resize it to fit them).
-
#visible? ⇒ Boolean
(also: #visibility)
True if the shape is visible, otherwise false.
Constructor Details
#initialize(pos = DEFAULT::POSITION, diagram: nil) ⇒ Shape
Constructor
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/wx/shapes/shape.rb', line 246 def initialize(pos = DEFAULT::POSITION, diagram: nil) ::Kernel.raise ArgumentError, "Invalid arguments pos: #{pos}, diagram: #{diagram}" unless Wx::RealPoint === pos && (diagram.nil? || Wx::SF::Diagram === diagram) @diagram = diagram @parent_shape = nil @child_shapes = ShapeList.new @components = ::Set.new # by default the common canvas hover colour will be used @hover_color = nil @selected = false @mouse_over = false @first_move = false @highlight_parent = false @user_data = nil # archived properties @visible = DEFAULT::VISIBILITY @active = DEFAULT::ACTIVITY @style = DEFAULT::DEFAULT_STYLE @v_align = DEFAULT::VALIGN @h_align = DEFAULT::HALIGN @v_border = DEFAULT::VBORDER @h_border = DEFAULT::HBORDER @custom_dock_point = DEFAULT::DOCK_POINT @relative_position = Wx::RealPoint === pos ? pos.dup : pos.to_real_point @handles = [] @connection_pts = [] @accepted_children = ::Set.new @accepted_connections = ::Set.new @accepted_src_neighbours = ::Set.new @accepted_trg_neighbours = ::Set.new end |
Class Method Details
.component(*comp_id) ⇒ Object .component(hash) ⇒ Object
Declare a component shape property for the shape class.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/wx/shapes/shape.rb', line 198 def self.component(*args) args.flatten.each do |arg| if arg.is_a?(::Hash) arg.each_pair do |pn, pp| # define serialized property for component (checks for duplicates) property({pn => pp}, force: true) # get the property definition and register as component component_shapes << self.serializer_properties.last end else # define serialized property for component (checks for duplicates) property(arg, force: true) # get the property definition and register as component component_shapes << self.serializer_properties.last end end # check if the current class already has the appropriate support unless self.const_defined?(:ComponentSerializerMethods) class << self def disable_component_serialize(obj) component_shapes.each { |pd| pd.get(obj).disable_serialize } superclass.disable_component_serialize(obj) if superclass.respond_to?(:disable_component_serialize) end # override the #new method def new(*) instance = super disable_component_serialize(instance) instance end end self.class_eval <<~__CODE module ComponentSerializerMethods def from_serialized(hash) super(hash) #{self.name}.component_shapes.each { |pd| pd.get(self).set_parent_shape(self) } self end protected :from_serialized end include ComponentSerializerMethods __CODE end end |
.component_shapes ⇒ Object
169 170 171 |
# File 'lib/wx/shapes/shape.rb', line 169 def component_shapes @component_shapes ||= ::Set.new end |
.lines_intersection(from1, to1, from2, to2) ⇒ Wx::RealPoint?
Returns intersection point of two lines (if any)
2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 |
# File 'lib/wx/shapes/shape.rb', line 2129 def self.lines_intersection(from1, to1, from2, to2) # create line 1 info a1 = to1.y - from1.y b1 = from1.x - to1.x c1 = -a1*from1.x - b1*from1.y # create line 2 info a2 = to2.y - from2.y b2 = from2.x - to2.x c2 = -a2*from2.x - b2*from2.y # check, whether the lines are parallel... ka = a1 / a2 kb = b1 / b2 return nil if ka == kb xi = (b1*c2 - c1*b2) / (a1*b2 - a2*b1) yi = -(a1*c2 - a2*c1) / (a1*b2 - a2*b1) if ((from1.x - xi) * (xi - to1.x) >= 0.0) && ((from2.x - xi) * (xi - to2.x) >= 0.0) && ((from1.y - yi) * (yi - to1.y) >= 0.0) && ((from2.y - yi) * (yi - to2.y) >= 0.0) return Wx::RealPoint.new(xi, yi) end nil end |
Instance Method Details
#accept_child(type) ⇒ Object
Add given shape type to an acceptance list. The acceptance list contains class names of the shapes which can be accepted as children of this shape. Note: Constant value ACCEPT_ALL behaves like any class.
1062 1063 1064 1065 |
# File 'lib/wx/shapes/shape.rb', line 1062 def accept_child(type) ::Kernel.raise ArgumentError, 'Class or ACCEPT_ALL expected' unless type.is_a?(::Class) @accepted_children << type end |
#accept_connection(type) ⇒ Object
Add given connection type to an acceptance list. The acceptance list contains class names of the connection which can be accepted by this shape. Note: Constant value ACCEPT_ALL behaves like any class.
1099 1100 1101 1102 |
# File 'lib/wx/shapes/shape.rb', line 1099 def accept_connection(type) ::Kernel.raise ArgumentError, 'Class or ACCEPT_ALL expected' unless type.is_a?(::Class) @accepted_connections << type end |
#accept_currently_dragged_shapes ⇒ Boolean
Returns true if all currently dragged shapes can be accepted as children of this shape.
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 |
# File 'lib/wx/shapes/shape.rb', line 1046 def accept_currently_dragged_shapes return false unless get_shape_canvas unless @accepted_children.include?(ACCEPT_ALL) lst_selection = get_shape_canvas.get_selected_shapes return false if lst_selection.any? { |shape| !@accepted_children.include?(shape.class) } end true end |
#accept_src_neighbour(type) ⇒ Object
Add given shape type to an source neighbours’ acceptance list. The acceptance list contains class names of the shape types which can be accepted by this shape as its source neighbour. Note: Constant value ACCEPT_ALL behaves like any class.
1128 1129 1130 1131 |
# File 'lib/wx/shapes/shape.rb', line 1128 def accept_src_neighbour(type) ::Kernel.raise ArgumentError, 'Class or ACCEPT_ALL expected' unless type.is_a?(::Class) @accepted_src_neighbours << type end |
#accept_trg_neighbour(type) ⇒ Object
Add given shape type to an target neighbours’ acceptance list. The acceptance list contains class names of the shape types which can be accepted by this shape as its target neighbour. Note: Constant value ACCEPT_ALL behaves like any class.
1157 1158 1159 1160 |
# File 'lib/wx/shapes/shape.rb', line 1157 def accept_trg_neighbour(type) ::Kernel.raise ArgumentError, 'Class or ACCEPT_ALL expected' unless type.is_a?(::Class) @accepted_trg_neighbours << type end |
#activate(active) ⇒ Object Also known as: set_active
1025 1026 1027 |
# File 'lib/wx/shapes/shape.rb', line 1025 def activate(active) @active = active end |
#active? ⇒ Boolean Also known as: active
Returns true if the shape is active, otherwise false.
1016 1017 1018 |
# File 'lib/wx/shapes/shape.rb', line 1016 def active? @active end |
#add_child_shape(child) ⇒ Wx::SF::Shape?
Adds child shape is accepted. Removes the child shape as a toplevel diagram shape if appropriate.
325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/wx/shapes/shape.rb', line 325 def add_child_shape(child) raise SFException, 'Illegal attempt to add self as Shape child' if child == self if is_child_accepted(child.class) if child.get_diagram child.get_diagram.reparent_shape(child, self) else child.set_parent_shape(self) end child.update return child end nil end |
#add_connection_point(arg, *rest, persistent: true) ⇒ Object
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 |
# File 'lib/wx/shapes/shape.rb', line 1280 def add_connection_point(arg, *rest, persistent: true) cp = nil case arg when ConnectionPoint::CPTYPE unless get_connection_point(arg) cp = ConnectionPoint.new(self, arg) cp.disable_serialize unless persistent end when Wx::RealPoint, ::Array cp = ConnectionPoint.new(self, arg.to_real_point, *rest) cp.disable_serialize unless persistent when ConnectionPoint cp = arg cp.disable_serialize unless persistent else ::Kernel.raise ArgumentError, "Invalid arguments: arg: #{arg}, rest: #{rest}" end @connection_pts << cp if cp cp end |
#add_handle(type, id = -1)) ⇒ Object
1218 1219 1220 1221 1222 |
# File 'lib/wx/shapes/shape.rb', line 1218 def add_handle(type, id = -1) unless get_handle(type, id) @handles << Handle.new(self, type, id) end end |
#add_style(style) ⇒ Object
515 516 517 |
# File 'lib/wx/shapes/shape.rb', line 515 def add_style(style) @style |= style end |
#ancestor?(child) ⇒ Boolean
Determine whether this shape is ancestor of given child shape.
947 948 949 |
# File 'lib/wx/shapes/shape.rb', line 947 def ancestor?(child) @child_shapes.include?(child) || @child_shapes.any? { |c| c.ancestor?(child) } end |
#clear_accepted_childs ⇒ Object
1172 1173 1174 |
# File 'lib/wx/shapes/shape.rb', line 1172 def clear_accepted_childs @accepted_children.clear end |
#clear_accepted_connections ⇒ Object
1178 1179 1180 |
# File 'lib/wx/shapes/shape.rb', line 1178 def clear_accepted_connections @accepted_connections.clear end |
#clear_accepted_src_neighbours ⇒ Object
1184 1185 1186 |
# File 'lib/wx/shapes/shape.rb', line 1184 def clear_accepted_src_neighbours @accepted_src_neighbours.clear end |
#clear_accepted_trg_neighbours ⇒ Object
1190 1191 1192 |
# File 'lib/wx/shapes/shape.rb', line 1190 def clear_accepted_trg_neighbours @accepted_trg_neighbours.clear end |
#contains?(pos) ⇒ Boolean
Test whether the given point is inside the shape. The function can be overridden if necessary.
430 431 432 433 434 |
# File 'lib/wx/shapes/shape.rb', line 430 def contains?(pos) # HINT: overload it for custom actions... get_bounding_box.contains?(pos) end |
#contains_style(style) ⇒ Object Also known as: contains_style?, has_style?
521 522 523 |
# File 'lib/wx/shapes/shape.rb', line 521 def contains_style(style) @style.allbits?(style) end |
#create_handles ⇒ Object
Function called by the framework responsible for creation of shape handles at the creation time. Default implementation does nothing. The function can be overridden if necessary.
488 489 490 |
# File 'lib/wx/shapes/shape.rb', line 488 def create_handles # HINT: overload it for custom actions... end |
#descendant?(parent) ⇒ Boolean
Determine whether this shape is descendant of given parent shape.
954 955 956 |
# File 'lib/wx/shapes/shape.rb', line 954 def descendant?(parent) parent && parent.ancestor?(self) end |
#do_alignment ⇒ Object
Update the shape’s position in order to its alignment
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
# File 'lib/wx/shapes/shape.rb', line 705 def do_alignment # align to parent unless parent is manager unless @parent_shape.nil? || managed? if @parent_shape.is_a?(Wx::SF::LineShape) line_pos = get_parent_absolute_position parent_bb = Wx::Rect.new(line_pos.x.to_i, line_pos.y.to_i, 1, 1) else parent_bb = @parent_shape.get_bounding_box end shape_bb = get_bounding_box # do vertical alignment case @v_align when VALIGN::TOP @relative_position.y = @v_border when VALIGN::MIDDLE @relative_position.y = parent_bb.height/2 - shape_bb.height/2 when VALIGN::BOTTOM @relative_position.y = parent_bb.height - shape_bb.height - @v_border when VALIGN::EXPAND if has_style?(STYLE::SIZE_CHANGE) @relative_position.y = @v_border scale(1.0, ((parent_bb.height - 2*@v_border)/shape_bb.height).to_f) end when VALIGN::LINE_START if @parent_shape.is_a?(Wx::SF::LineShape) line_start, line_end = @parent_shape.get_line_segment(0) if line_end.y >= line_start.y @relative_position.y = line_start.y - line_pos.y + @v_border else @relative_position.y = line_start.y - line_pos.y - shape_bb.height - @v_border end end when VALIGN::LINE_END if @parent_shape.is_a?(Wx::SF::LineShape) line_start, line_end = @parent_shape.get_line_segment(parent.get_control_points.get_count) if line_end.y >= line_start.y @relative_position.y = line_end.y - line_pos.y - shape_bb.height - @v_border else @relative_position.y = line_end.y - line_pos.y + @v_border end end end # do horizontal alignment case @h_align when HALIGN::LEFT @relative_position.x = @h_border when HALIGN::CENTER @relative_position.x = parent_bb.width/2 - shape_bb.width/2 when HALIGN::RIGHT @relative_position.x = parent_bb.width - shape_bb.width - @h_border when HALIGN::EXPAND if has_style?(STYLE::SIZE_CHANGE) @relative_position.x = @h_border scale(((parent_bb.width - 2*@h_border)/shape_bb.width).to_f, 1.0) end when HALIGN::LINE_START if @parent_shape.is_a?(Wx::SF::LineShape) line_start, line_end = @parent_shape.get_line_segment(0) if line_end.x >= line_start.x @relative_position.x = line_start.x - line_pos.x + @h_border else @relative_position.x = line_start.x - line_pos.x - shape_bb.width - @h_border end end when HALIGN::LINE_END if @parent_shape.is_a?(Wx::SF::LineShape) line_start, line_end = @parent_shape.get_line_segment(@parent_shape.get_control_points.get_count) if line_end.x >= line_start.x @relative_position.x = line_end.x - line_pos.x - shape_bb.width - @h_border else @relative_position.x = line_end.x - line_pos.x + @h_border end end end end end |
#does_not_accept_children? ⇒ Boolean Also known as: no_children_accepted?, accepts_no_children?
Tells whether the shape does not accept ANY children
1077 1078 1079 |
# File 'lib/wx/shapes/shape.rb', line 1077 def does_not_accept_children? @accepted_children.empty? end |
#draw(dc, children = WITHCHILDREN) ⇒ Object
Draw shape. Default implementation tests basic shape visual states (normal/ready, mouse is over the shape, dragged shape can be accepted) and call appropriate virtual functions (DrawNormal, DrawHover, DrawHighlighted) for its visualisation. The function can be overridden if necessary.
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/wx/shapes/shape.rb', line 392 def draw(dc, children = WITHCHILDREN) return unless @diagram && @diagram.shape_canvas return unless @visible unless has_style?(STYLE::NOT_DRAWN) # draw the shape shadow if required draw_shadow(dc) if !@selected && has_style?(STYLE::SHOW_SHADOW) # first, draw itself if @mouse_over && (@highlight_parent || has_style?(STYLE::HOVERING)) if @highlight_parent draw_highlighted(dc) @highlight_parent = false else draw_hover(dc) end else draw_normal(dc) end draw_selected(dc) if @selected # ... then draw connection points ... @connection_pts.each { |cpt| cpt.draw(dc) } unless has_style?(STYLE::PROPAGATE_INTERACTIVE_CONNECTION) end # ... then draw child shapes if children @child_shapes.each { |child| child.draw(dc) } end end |
#draw_highlighted(_dc) ⇒ Object (protected)
Draw the shape in the highlighted mode (another shape is dragged over this shape and this shape will accept the dragged one if it will be dropped on it). The function can be overridden if necessary.
1620 1621 1622 |
# File 'lib/wx/shapes/shape.rb', line 1620 def draw_highlighted(_dc) # HINT: overload it for custom actions... end |
#draw_hover(_dc) ⇒ Object (protected)
Draw the shape in the hover mode (the mouse cursor is above the shape). The function can be overridden if necessary.
1612 1613 1614 |
# File 'lib/wx/shapes/shape.rb', line 1612 def draw_hover(_dc) # HINT: overload it for custom actions... end |
#draw_normal(_dc) ⇒ Object (protected)
Draw the shape in the normal way. The function can be overridden if necessary.
1595 1596 1597 |
# File 'lib/wx/shapes/shape.rb', line 1595 def draw_normal(_dc) # HINT: overload it for custom actions... end |
#draw_selected(dc) ⇒ Object (protected)
Draw the shape in the selected way. The function can be overridden if necessary.
1601 1602 1603 1604 1605 1606 1607 |
# File 'lib/wx/shapes/shape.rb', line 1601 def draw_selected(dc) # HINT: overload it for custom actions... if has_style?(STYLE::SHOW_HANDLES) @handles.each { |h| h.send(:draw, dc) } end end |
#draw_shadow(_dc) ⇒ Object (protected)
Draw shadow under the shape. The function can be overridden if necessary.
1626 1627 1628 |
# File 'lib/wx/shapes/shape.rb', line 1626 def draw_shadow(_dc) # HINT: overload it for custom actions... end |
#fit_to_children ⇒ Object
Resize the shape to bound all child shapes. The function can be overridden if necessary.
818 819 820 |
# File 'lib/wx/shapes/shape.rb', line 818 def fit_to_children # HINT: overload it for custom actions... end |
#get_absolute_position ⇒ Wx::RealPoint
Get the shape’s absolute position in the canvas (calculated as a summation of all relative positions in the shapes’ hierarchy. The function can be overridden if necessary.
458 459 460 461 462 463 464 465 |
# File 'lib/wx/shapes/shape.rb', line 458 def get_absolute_position # HINT: overload it for custom actions... if @parent_shape @relative_position + get_parent_absolute_position else @relative_position end end |
#get_accepted_children ⇒ Set<String> Also known as: accepted_children
Returns String set with class names of accepted shape types.
1070 1071 1072 |
# File 'lib/wx/shapes/shape.rb', line 1070 def get_accepted_children @accepted_children end |
#get_accepted_connections ⇒ Set<String> Also known as: accepted_connections
Returns String set with class names of accepted connection types.
1107 1108 1109 |
# File 'lib/wx/shapes/shape.rb', line 1107 def get_accepted_connections @accepted_connections end |
#get_accepted_src_neighbours ⇒ Set<String> Also known as: accepted_src_neighbours
Returns String set with class names of accepted source neighbours types.
1136 1137 1138 |
# File 'lib/wx/shapes/shape.rb', line 1136 def get_accepted_src_neighbours @accepted_src_neighbours end |
#get_accepted_trg_neighbours ⇒ Set<String> Also known as: accepted_trg_neighbours
Returns String set with class names of accepted target neighbours types.
1165 1166 1167 |
# File 'lib/wx/shapes/shape.rb', line 1165 def get_accepted_trg_neighbours @accepted_trg_neighbours end |
#get_assigned_connections(shape_info, mode, lines = []) ⇒ Object
595 596 597 598 |
# File 'lib/wx/shapes/shape.rb', line 595 def get_assigned_connections(shape_info, mode, lines = []) @diagram.get_assigned_connections(self, shape_info, mode, lines) if @diagram lines end |
#get_border_point(_start, _finish) ⇒ Wx::RealPoint
Get intersection point of the shape border and a line leading from ‘start’ point to ‘finish’ point. Default implementation does nothing. The function can be overridden if necessary.
472 473 474 475 |
# File 'lib/wx/shapes/shape.rb', line 472 def get_border_point(_start, _finish) # HINT: overload it for custom actions... Wx::RealPoint.new end |
#get_bounding_box ⇒ Wx::Rect
Get shape’s bounding box. The function can be overridden if necessary.
602 603 604 605 606 |
# File 'lib/wx/shapes/shape.rb', line 602 def get_bounding_box # HINT: overload it for custom actions... Wx::Rect.new end |
#get_center ⇒ Wx::RealPoint
Get shape’s center. Default implementation does nothing. The function can be overridden if necessary.
479 480 481 482 483 484 |
# File 'lib/wx/shapes/shape.rb', line 479 def get_center # HINT: overload it for custom actions... bb = get_bounding_box Wx::RealPoint.new(bb.left + bb.width/2, bb.top + bb.height/2) end |
#get_child_shapes(type, recursive = NORECURSIVE, mode = SEARCHMODE::BFS, list = []) ⇒ Array<Wx::SF::Shape>
Get child shapes associated with this (parent) shape.
564 565 566 567 568 569 570 |
# File 'lib/wx/shapes/shape.rb', line 564 def get_child_shapes(type, recursive = NORECURSIVE, mode = SEARCHMODE::BFS, list = []) if recursive get_children_recursively(type, mode, list) else get_children(type, list) end end |
#get_children(type, list) ⇒ Array<Wx::SF::Shape>
Get children of given type.
538 539 540 |
# File 'lib/wx/shapes/shape.rb', line 538 def get_children(type, list) @child_shapes.each_with_object(list) { |child, lst| lst << child if type.nil? || type === child } end |
#get_children_recursively(type, mode = SEARCHMODE::BFS, list = []) ⇒ Object
Get all children of given type recursively (i.e. children of children of .… ).
547 548 549 550 551 552 553 554 555 556 |
# File 'lib/wx/shapes/shape.rb', line 547 def get_children_recursively(type, mode = SEARCHMODE::BFS, list = []) @child_shapes.each do |child| list << child if type.nil? || type === child child.get_children_recursively(type, mode, list) if mode == SEARCHMODE::DFS end if mode == SEARCHMODE::BFS @child_shapes.each { |child| child.get_children_recursively(type, mode, list) } end list end |
#get_complete_bounding_box(rct, mask = BBMODE::ALL) ⇒ Object
613 614 615 |
# File 'lib/wx/shapes/shape.rb', line 613 def get_complete_bounding_box(rct, mask = BBMODE::ALL) _get_complete_bounding_box(rct, mask) end |
#get_connection_point(type, id = nil) ⇒ Wx::SF::ConnectionPoint? Also known as: connection_point
Returns connection point if exists, otherwise nil.
1244 1245 1246 |
# File 'lib/wx/shapes/shape.rb', line 1244 def get_connection_point(type, id = nil) @connection_pts.find { |cp| cp.type == type && cp.id == id } end |
#get_connection_points ⇒ Array<Wx::SF::ConnectionPoint> Also known as: connection_points
Returns connection points list.
1234 1235 1236 |
# File 'lib/wx/shapes/shape.rb', line 1234 def get_connection_points @connection_pts end |
#get_custom_dock_point ⇒ Integer Also known as: custom_dock_point
Get custom dock point used if the shape is child shape of a line shape.
939 940 941 |
# File 'lib/wx/shapes/shape.rb', line 939 def get_custom_dock_point @custom_dock_point end |
#get_diagram ⇒ Wx::SF::Diagram Also known as: diagram
Get managing diagram
297 298 299 |
# File 'lib/wx/shapes/shape.rb', line 297 def get_diagram @diagram end |
#get_grand_parent_shape ⇒ Wx::SF::Shape Also known as: grand_parent_shape
Get pointer to the topmost parent shape
373 374 375 |
# File 'lib/wx/shapes/shape.rb', line 373 def get_grand_parent_shape @parent_shape ? @parent_shape.get_grand_parent_shape : self end |
#get_h_align ⇒ HALIGN Also known as: h_align
Get horizontal alignment of this shape inside its parent
889 890 891 |
# File 'lib/wx/shapes/shape.rb', line 889 def get_h_align @h_align end |
#get_h_border ⇒ Float Also known as: h_border
Get horizontal border between this shape and its parent (if horizontal alignment is set).
925 926 927 |
# File 'lib/wx/shapes/shape.rb', line 925 def get_h_border @h_border end |
#get_handle(type, id = -1)) ⇒ Wx::SF::Shape::Handle? Also known as: handle
Returns shape handle object if exist.
1206 1207 1208 |
# File 'lib/wx/shapes/shape.rb', line 1206 def get_handle(type, id = -1) @handles.find { |h| h.type == type && (id == -1 || h.id == id) } end |
#get_handles ⇒ Array<Wx::SF::Shape::Handle> Also known as: handles
Get list of currently assigned shape handles.
1196 1197 1198 |
# File 'lib/wx/shapes/shape.rb', line 1196 def get_handles @handles end |
#get_hover_colour ⇒ Wx::Colour Also known as: hover_colour
Returns Current hover color.
1008 1009 1010 |
# File 'lib/wx/shapes/shape.rb', line 1008 def get_hover_colour @hover_color || (@diagram&.shape_canvas ? @diagram.shape_canvas.hover_colour : DEFAULT.hover_colour) end |
#get_nearest_connection_point(pos) ⇒ Wx::SF::ConnectionPoint? Also known as: nearest_connection_point
Returns closest connection point if exists, otherwise nil.
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 |
# File 'lib/wx/shapes/shape.rb', line 1252 def get_nearest_connection_point(pos) pos = pos.to_real_point min_dist = Float::MAX @connection_pts.inject(nil) do |nearest, cp| if (curr_dist = pos.distance_to(cp.get_connection_point)) < min_dist min_dist = curr_dist nearest = cp end nearest end end |
#get_neighbours(shape_info, condir, direct = DIRECT, neighbours = []) ⇒ Object
579 580 581 582 583 584 585 586 |
# File 'lib/wx/shapes/shape.rb', line 579 def get_neighbours(shape_info, condir, direct = DIRECT, neighbours = []) unless Wx::SF::LineShape === self _get_neighbours(shape_info, condir, direct, neighbours) # delete starting object if necessary (can be added in a case of complex connection network) neighbours.delete(self) end neighbours end |
#get_parent_absolute_position ⇒ Wx::RealPoint (protected)
Get absolute position of the shape parent.
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 |
# File 'lib/wx/shapes/shape.rb', line 1647 def get_parent_absolute_position if @parent_shape if @parent_shape.is_a?(Wx::SF::LineShape) && @custom_dock_point != DEFAULT::DOCK_POINT return @parent_shape.get_dock_point_position(@custom_dock_point) else return @parent_shape.get_absolute_position end end Wx::RealPoint.new(0, 0) end |
#get_parent_canvas ⇒ Wx::SF::ShapeCanvas?
Get the shape canvas of the parent diagram
304 305 306 |
# File 'lib/wx/shapes/shape.rb', line 304 def get_parent_canvas @diagram ? @diagram.get_shape_canvas : nil end |
#get_parent_shape ⇒ Wx::SF::Shape? Also known as: parent_shape
Get parent shape
366 367 368 |
# File 'lib/wx/shapes/shape.rb', line 366 def get_parent_shape @parent_shape end |
#get_relative_position ⇒ Wx::RealPoint
Get shape’s relative position.
858 859 860 |
# File 'lib/wx/shapes/shape.rb', line 858 def get_relative_position @relative_position end |
#get_shape_canvas ⇒ Wx::SF::ShapeCanvas? Also known as: shape_canvas
Get shape’s diagram canvas
978 979 980 981 982 |
# File 'lib/wx/shapes/shape.rb', line 978 def get_shape_canvas return nil unless @diagram @diagram.shape_canvas end |
#get_style ⇒ Integer Also known as: style
Get current shape style.
510 511 512 |
# File 'lib/wx/shapes/shape.rb', line 510 def get_style @style end |
#get_user_data ⇒ Object? Also known as: user_data
Get associated user data.
970 971 972 |
# File 'lib/wx/shapes/shape.rb', line 970 def get_user_data @user_data end |
#get_v_align ⇒ VALIGN Also known as: v_align
Get vertical alignment of this shape inside its parent
873 874 875 |
# File 'lib/wx/shapes/shape.rb', line 873 def get_v_align @v_align end |
#get_v_border ⇒ Float Also known as: v_border
Get vertical border between this shape and its parent (if vertical alignment is set).
907 908 909 |
# File 'lib/wx/shapes/shape.rb', line 907 def get_v_border @v_border end |
#has_children ⇒ Boolean Also known as: has_children?
Find out whether this shape has some children.
529 530 531 |
# File 'lib/wx/shapes/shape.rb', line 529 def has_children !@child_shapes.empty? end |
#has_selected_parent? ⇒ Boolean Also known as: selected_parent?
Returns true if any (grand-)parent is selected?
828 829 830 |
# File 'lib/wx/shapes/shape.rb', line 828 def has_selected_parent? @parent_shape&.selected? || @parent_shape&.has_selected_parent? end |
#include_child_shape?(shape, recursive = false) ⇒ Boolean
Returns true if the given shape is included in the child shapes list. Performs a recursive search in case :recursive is true.
345 346 347 |
# File 'lib/wx/shapes/shape.rb', line 345 def include_child_shape?(shape, recursive = false) @child_shapes.include?(shape, recursive) end |
#inside?(rct) ⇒ Boolean
Test whether the shape is completely inside given rectangle. The function can be overridden if necessary.
440 441 442 443 444 |
# File 'lib/wx/shapes/shape.rb', line 440 def inside?(rct) # HINT: overload it for custom actions... rct.contains?(get_bounding_box) end |
#inspect ⇒ Object
1580 1581 1582 |
# File 'lib/wx/shapes/shape.rb', line 1580 def inspect to_s end |
#intersects?(rct) ⇒ Boolean
Test whether the given rectangle intersects the shape.
449 450 451 452 453 |
# File 'lib/wx/shapes/shape.rb', line 449 def intersects?(rct) # HINT: overload it for custom actions... rct.intersects(get_bounding_box) end |
#is_child_accepted(type) ⇒ Boolean Also known as: child_accepted?
Tells whether the given shape type is accepted by this shape (it means whether this shape can be its parent).
The function is typically used by the framework for determination whether a dropped shape can be assigned to an underlying shape as its child.
1037 1038 1039 |
# File 'lib/wx/shapes/shape.rb', line 1037 def is_child_accepted(type) @accepted_children.include?(type) || @accepted_children.include?(ACCEPT_ALL) end |
#is_connection_accepted(type) ⇒ Object Also known as: connection_accepted?
Tells whether the given connection type is accepted by this shape (it means whether this shape can be connected to another one by a connection of given type).
The function is typically used by the framework during interactive connection creation.
1089 1090 1091 |
# File 'lib/wx/shapes/shape.rb', line 1089 def is_connection_accepted(type) @accepted_connections.include?(type) || @accepted_connections.include?(ACCEPT_ALL) end |
#is_managed ⇒ Boolean Also known as: managed?
Returns true if this shape is managed (size/position/alignment) by it’s parent shape.
698 699 700 |
# File 'lib/wx/shapes/shape.rb', line 698 def is_managed !!@parent_shape&.is_manager end |
#is_manager ⇒ Boolean Also known as: manager?
Returns true if this shape manages (size/position/alignment) of it’s child shapes. Returns false by default.
691 692 693 |
# File 'lib/wx/shapes/shape.rb', line 691 def is_manager false end |
#is_src_neighbour_accepted(type) ⇒ Object Also known as: src_neighbour_accepted?
Tells whether the given shape type is accepted by this shape as its source neighbour(it means whether this shape can be connected from another one of given type).
The function is typically used by the framework during interactive connection creation.
1118 1119 1120 |
# File 'lib/wx/shapes/shape.rb', line 1118 def is_src_neighbour_accepted(type) @accepted_src_neighbours.include?(type) || @accepted_src_neighbours.include?(ACCEPT_ALL) end |
#is_trg_neighbour_accepted(type) ⇒ Boolean Also known as: trg_neighbour_accepted?
Tells whether the given shape type is accepted by this shape as its target neighbour(it means whether this shape can be connected to another one of given type).
The function is typically used by the framework during interactive connection creation.
1147 1148 1149 |
# File 'lib/wx/shapes/shape.rb', line 1147 def is_trg_neighbour_accepted(type) @accepted_trg_neighbours.include?(type) || @accepted_trg_neighbours.include?(ACCEPT_ALL) end |
#lines_intersection(*args) ⇒ Object
Allow shapes to call class method as instance method.
2160 2161 2162 |
# File 'lib/wx/shapes/shape.rb', line 2160 def lines_intersection(*args) Shape.lines_intersection(*args) end |
#move_by(delta) ⇒ Object
678 679 680 681 682 683 684 685 686 |
# File 'lib/wx/shapes/shape.rb', line 678 def move_by(*args) # HINT: overload it for custom actions... x, y = (args.size == 1 ? args.first : args) @relative_position.x += x @relative_position.y += y @diagram.set_modified(true) if @diagram end |
#move_to(pos) ⇒ Object
663 664 665 666 667 668 669 670 |
# File 'lib/wx/shapes/shape.rb', line 663 def move_to(*args) # HINT: overload it for custom actions... pos = (args.size == 1 ? args.first.to_real_point : Wx::RealPoint.new(*args)) @relative_position = pos - get_parent_absolute_position @diagram.set_modified(true) if @diagram end |
#on_begin_drag(pos) ⇒ Object
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 |
# File 'lib/wx/shapes/shape.rb', line 1387 def on_begin_drag(pos) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeMouseEvent.new(Wx::SF::EVT_SF_SHAPE_DRAG_BEGIN, self.object_id) evt.set_shape(self) evt.set_mouse_position(pos) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_begin_handle(handle) ⇒ Object
The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_HANDLE_BEGIN event.
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 |
# File 'lib/wx/shapes/shape.rb', line 1440 def on_begin_handle(handle) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeHandleEvent.new(Wx::SF::EVT_SF_SHAPE_HANDLE_BEGIN, self.object_id) evt.set_shape(self) evt.set_handle(handle) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_child_dropped(_pos, child) ⇒ Object
shape is accepted as a child of this shape). The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_CHILD_DROP event.
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 |
# File 'lib/wx/shapes/shape.rb', line 1565 def on_child_dropped(_pos, child) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeChildDropEvent.new(Wx::SF::EVT_SF_SHAPE_CHILD_DROP, self.object_id) evt.set_shape(self) evt.set_child_shape(child) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_dragging(pos) ⇒ Object
The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_DRAG event.
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 |
# File 'lib/wx/shapes/shape.rb', line 1405 def on_dragging(pos) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeMouseEvent.new(Wx::SF::EVT_SF_SHAPE_DRAG, self.object_id) evt.set_shape(self) evt.set_mouse_position(pos) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_end_drag(pos) ⇒ Object
The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_DRAG_END event.
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 |
# File 'lib/wx/shapes/shape.rb', line 1423 def on_end_drag(pos) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeMouseEvent.new(Wx::SF::EVT_SF_SHAPE_DRAG_END, self.object_id) evt.set_shape(self) evt.set_mouse_position(pos) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_end_handle(handle) ⇒ Object
1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 |
# File 'lib/wx/shapes/shape.rb', line 1474 def on_end_handle(handle) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeHandleEvent.new(Wx::SF::EVT_SF_SHAPE_HANDLE_END, self.object_id) evt.set_shape(self) evt.set_handle(handle) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_handle(handle) ⇒ Object
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 |
# File 'lib/wx/shapes/shape.rb', line 1457 def on_handle(handle) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeHandleEvent.new(Wx::SF::EVT_SF_SHAPE_HANDLE, self.object_id) evt.set_shape(self) evt.set_handle(handle) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_import ⇒ Object (protected)
called after the shape has been newly imported/pasted/dropped allows for checking stale links by default does nothing
1589 1590 1591 |
# File 'lib/wx/shapes/shape.rb', line 1589 def on_import # nothing end |
#on_key(key) ⇒ Object
The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_KEYDOWN event.
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 |
# File 'lib/wx/shapes/shape.rb', line 1545 def on_key(key) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeKeyEvent.new(Wx::SF::EVT_SF_SHAPE_KEYDOWN, self.object_id) evt.set_shape(self) evt.set_key_code(key) get_shape_canvas.get_event_handler.process_event(evt) end true end |
#on_left_click(pos) ⇒ Object
the left mouse button. The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_LEFT_DOWN event.
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 |
# File 'lib/wx/shapes/shape.rb', line 1315 def on_left_click(pos) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeMouseEvent.new(Wx::SF::EVT_SF_SHAPE_LEFT_DOWN, self.object_id) evt.set_shape(self) evt.set_mouse_position(pos) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_left_double_click(pos) ⇒ Object
the left mouse button. The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_LEFT_DCLICK event.
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 |
# File 'lib/wx/shapes/shape.rb', line 1351 def on_left_double_click(pos) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeMouseEvent.new(Wx::SF::EVT_SF_SHAPE_LEFT_DCLICK, self.object_id) evt.set_shape(self) evt.set_mouse_position(pos) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_mouse_enter(pos) ⇒ Object
The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_MOUSE_ENTER event.
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 |
# File 'lib/wx/shapes/shape.rb', line 1491 def on_mouse_enter(pos) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeMouseEvent.new(Wx::SF::EVT_SF_SHAPE_MOUSE_ENTER, self.object_id) evt.set_shape(self) evt.set_mouse_position(pos) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_mouse_leave(pos) ⇒ Object
The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_MOUSE_LEAVE event.
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 |
# File 'lib/wx/shapes/shape.rb', line 1525 def on_mouse_leave(pos) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeMouseEvent.new(Wx::SF::EVT_SF_SHAPE_MOUSE_LEAVE, self.object_id) evt.set_shape(self) evt.set_mouse_position(pos) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_mouse_over(pos) ⇒ Object
The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_MOUSE_OVER event.
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 |
# File 'lib/wx/shapes/shape.rb', line 1508 def on_mouse_over(pos) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeMouseEvent.new(Wx::SF::EVT_SF_SHAPE_MOUSE_OVER, self.object_id) evt.set_shape(self) evt.set_mouse_position(pos) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_right_click(pos) ⇒ Object
the right mouse button. The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_RIGHT_DOWN event.
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 |
# File 'lib/wx/shapes/shape.rb', line 1333 def on_right_click(pos) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeMouseEvent.new(Wx::SF::EVT_SF_SHAPE_RIGHT_DOWN, self.object_id) evt.set_shape(self) evt.set_mouse_position(pos) get_shape_canvas.get_event_handler.process_event(evt) end end |
#on_right_double_click(pos) ⇒ Object
the right mouse button. The function can be overridden if necessary.
The function is called by the framework (by the shape canvas). Default implementation emits Wx::SF::EVT_SF_SHAPE_RIGHT_DCLICK event.
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 |
# File 'lib/wx/shapes/shape.rb', line 1369 def on_right_double_click(pos) # HINT: overload it for custom actions... if has_style?(STYLE::EMIT_EVENTS) && get_shape_canvas evt = Wx::SF::ShapeMouseEvent.new(Wx::SF::EVT_SF_SHAPE_RIGHT_DCLICK, self.object_id) evt.set_shape(self) evt.set_mouse_position(pos) get_shape_canvas.get_event_handler.process_event(evt) end end |
#refresh(delayed = false) ⇒ Object
Refresh (redraw) the shape
382 383 384 |
# File 'lib/wx/shapes/shape.rb', line 382 def refresh(delayed = false) refresh_rect(get_bounding_box, delayed) end |
#refresh_rect(rct, delayed = false) ⇒ Object (protected)
1635 1636 1637 1638 1639 1640 1641 1642 1643 |
# File 'lib/wx/shapes/shape.rb', line 1635 def refresh_rect(rct, delayed = false) if get_shape_canvas if delayed get_shape_canvas.invalidate_rect(rct) else get_shape_canvas.refresh_canvas(false, rct) end end end |
#remove_connection_point(type) ⇒ Object
1304 1305 1306 |
# File 'lib/wx/shapes/shape.rb', line 1304 def remove_connection_point(type) @connection_pts.delete_if { |cp| cp.type == type } end |
#remove_handle(type, id = -1)) ⇒ Object
Remove given shape handle (if exists).
1228 1229 1230 |
# File 'lib/wx/shapes/shape.rb', line 1228 def remove_handle(type, id = -1) @handles.delete_if { |h| h.type == type && (id == -1 || h.id == id) } end |
#remove_style(style) ⇒ Object
518 519 520 |
# File 'lib/wx/shapes/shape.rb', line 518 def remove_style(style) @style &= ~style end |
#scale(x, y, children: WITHCHILDREN) ⇒ Object #scale(scale, children: WITHCHILDREN) ⇒ Object
Scale the shape size in both directions. The function can be overridden if necessary (new implementation should call default one or scale shape’s children manually if necessary).
626 627 628 629 630 631 632 633 634 |
# File 'lib/wx/shapes/shape.rb', line 626 def scale(*args, children: WITHCHILDREN) # HINT: overload it for custom actions... x, y = (args.size == 1 ? args.first : args) scale_children(x, y) if children @diagram.set_modified(true) if @diagram # self.update end |
#scale_children(x, y) ⇒ Object
Scale shape’s children
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/wx/shapes/shape.rb', line 640 def scale_children(x, y) lst_children = get_child_shapes(ANY, RECURSIVE) lst_children.each do |shape| if shape.has_style?(STYLE::SIZE_CHANGE) && shape.is_a?(Wx::SF::TextShape) shape.scale(x, y, children: WITHOUTCHILDREN) end if shape.has_style?(STYLE::POSITION_CHANGE) && (shape.get_v_align == VALIGN::NONE || shape.get_h_align == HALIGN::NONE) shape.set_relative_position(shape.get_relative_position.x*x, shape.get_relative_position.y*y) end # re-align shapes which have set any alignment mode shape.do_alignment end end |
#select(state) ⇒ Object
Set the shape as a selected/deselected one
835 836 837 838 |
# File 'lib/wx/shapes/shape.rb', line 835 def select(state) @selected = state show_handles(state && has_style?(STYLE::SHOW_HANDLES)) end |
#selected? ⇒ Boolean
Function returns true if the shape is selected, otherwise returns false
823 824 825 |
# File 'lib/wx/shapes/shape.rb', line 823 def selected? @selected end |
#set_custom_dock_point(dp) ⇒ Object Also known as: custom_dock_point=
Set custom dock point used if the shape is child shape of a line shape.
932 933 934 |
# File 'lib/wx/shapes/shape.rb', line 932 def set_custom_dock_point(dp) @custom_dock_point = dp end |
#set_diagram(diagram) ⇒ Object
Set managing diagram
287 288 289 290 291 292 293 |
# File 'lib/wx/shapes/shape.rb', line 287 def set_diagram(diagram) if @diagram != diagram @diagram = diagram @child_shapes.each { |child| child.set_diagram(diagram) } end self end |
#set_h_align(val) ⇒ Object Also known as: h_align=
Set horizontal alignment of this shape inside its parent
881 882 883 |
# File 'lib/wx/shapes/shape.rb', line 881 def set_h_align(val) @h_align = val end |
#set_h_border(border) ⇒ Object Also known as: h_border=
Set horizontal border between this shape and its parent (if horizontal alignment is set).
916 917 918 |
# File 'lib/wx/shapes/shape.rb', line 916 def set_h_border(border) @h_border = border end |
#set_hover_colour(col) ⇒ Object Also known as: hover_colour=
Set shape’s hover color
1001 1002 1003 |
# File 'lib/wx/shapes/shape.rb', line 1001 def set_hover_colour(col) @hover_color = Wx::Colour === col ? col : Wx::Colour.new(col) end |
#set_parent_shape(parent) ⇒ Object Also known as: parent_shape=
Note that this does not check this shape against the acceptance list of the parent. Use #add_child_shape if that is required.
Note that this does not add (if parent == nil) or remove (if parent != nil) the shape from the diagram’s
Set parent shape object. toplevel shapes. Use Diagram#reparent_shape when that is needed.
354 355 356 357 358 359 360 361 |
# File 'lib/wx/shapes/shape.rb', line 354 def set_parent_shape(parent) raise SFException, 'Illegal to set Shape parent to self' if parent == self raise SFException, 'Illegal to set Shape parent to (grand-)child of self' if parent && include_child_shape?(parent, true) @parent_shape.send(:remove_child, self) if @parent_shape parent.send(:add_child, self) if parent set_diagram(parent.get_diagram) if parent @parent_shape = parent end |
#set_relative_position(pos) ⇒ Object #set_relative_position(x, y) ⇒ Object
Set shape’s relative position. Absolute shape’s position is then calculated as a summation of the relative positions of this shape and all parent shapes in the shape’s hierarchy.
849 850 851 852 853 |
# File 'lib/wx/shapes/shape.rb', line 849 def set_relative_position(*arg) x, y = (arg.size == 1 ? arg.first.to_real_point : arg) @relative_position.x = x @relative_position.y = y end |
#set_style(style) ⇒ Object Also known as: style=
Set shape’s style.
Default value is STYLE::PARENT_CHANGE | STYLE::POSITION_CHANGE | STYLE::SIZE_CHANGE | STYLE::HOVERING | STYLE::HIGHLIGHTING | STYLE::SHOW_HANDLES | STYLE::ALWAYS_INSIDE
503 504 505 |
# File 'lib/wx/shapes/shape.rb', line 503 def set_style(style) @style = style end |
#set_user_data(data) ⇒ Object Also known as: user_data=
Associate user data with the shape. If the data object is properly set then its marked properties will be serialized together with the parent shape. This means the user data must either be a serializable core type or a FIRM::Serializable.
963 964 965 |
# File 'lib/wx/shapes/shape.rb', line 963 def set_user_data(data) @user_data = data end |
#set_v_align(val) ⇒ Object Also known as: v_align=
Set vertical alignment of this shape inside its parent
865 866 867 |
# File 'lib/wx/shapes/shape.rb', line 865 def set_v_align(val) @v_align = val end |
#set_v_border(border) ⇒ Object Also known as: v_border=
Set vertical border between this shape and its parent (if vertical alignment is set).
898 899 900 |
# File 'lib/wx/shapes/shape.rb', line 898 def set_v_border(border) @v_border = border end |
#show(show) ⇒ Object Also known as: set_visibility
994 995 996 |
# File 'lib/wx/shapes/shape.rb', line 994 def show(show) @visible = show end |
#show_handles(show) ⇒ Object
Show/hide shape handles. Hidden handles are inactive.
494 495 496 |
# File 'lib/wx/shapes/shape.rb', line 494 def show_handles(show) @handles.each { |h| h.show(show) } end |
#to_s ⇒ Object
1576 1577 1578 |
# File 'lib/wx/shapes/shape.rb', line 1576 def to_s "#<#{self.class}:#{self.object_id}#{@parent_shape ? " parent=#{@parent_shape.object_id}" : ''}>" end |
#update(recurse = true) ⇒ Object
Update shape (align all child shapes and resize it to fit them)
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 |
# File 'lib/wx/shapes/shape.rb', line 801 def update(recurse = true) # do self-alignment do_alignment # do alignment of shape's children (if required) @child_shapes.each { |child| child.do_alignment } # fit the shape to its children fit_to_children unless has_style?(STYLE::NO_FIT_TO_CHILDREN) # do it recursively on all parent shapes if recurse && (parent = get_parent_shape) parent.update(recurse) end end |
#visible? ⇒ Boolean Also known as: visibility
Returns true if the shape is visible, otherwise false.
987 988 989 |
# File 'lib/wx/shapes/shape.rb', line 987 def visible? @visible end |