Class: Wx::SF::LineShape
- Defined in:
- lib/wx/shapes/shapes/line_shape.rb
Direct Known Subclasses
Defined Under Namespace
Modules: DEFAULT Classes: LINEMODE
Instance Method Summary collapse
-
#contains?(pos) ⇒ Boolean
can be overridden if necessary.
-
#create_handles ⇒ Object
at the creation time.
-
#draw_complete_line(dc) ⇒ Object
protected
Draw completed line.
- #draw_highlighted(dc) ⇒ Object protected
- #draw_hover(dc) ⇒ Object protected
-
#draw_normal(dc) ⇒ Object
protected
Draw the shape in the normal way.
-
#get_absolute_position ⇒ Wx::RealPoint
Get the shape’s absolute position in the canvas.
-
#get_border_point(_start_pt, _end_pt) ⇒ Wx::RealPoint
Intersection point.
-
#get_bounding_box ⇒ Wx::Rect
Bounding rectangle.
-
#get_control_points ⇒ Array<Wx::RealPoint>
Get a list of the line’s control points (their positions).
-
#get_direct_line ⇒ Array(Wx::RealPoint, Wx::RealPoint)
Starting line point and ending line point.
-
#get_dock_point ⇒ Integer
Get the line dock point.
-
#get_dock_point_position(dp) ⇒ Wx::RealPoint
Get a position of given line dock point.
-
#get_hit_linesegment(pos) ⇒ Integer
protected
Zero-based index of line segment located under the given point.
-
#get_line_mode ⇒ LINEMODE
Get current working mode.
-
#get_line_pen ⇒ Wx::Pen
(also: #line_pen)
Get line type.
-
#get_line_segment(index) ⇒ Array(Wx::RealPoint,Wx::RealPoint)
Starting and ending point of line segment.
-
#get_line_segment_count ⇒ Integer
(also: #line_segment_count, #segment_count)
Get number of line segments for this shape.
-
#get_mod_src_point ⇒ Wx::RealPoint
protected
Modified starting line point.
-
#get_mod_trg_point ⇒ Wx::RealPoint
protected
Modified ending line point.
-
#get_src_arrow ⇒ Wx::SF::ArrowBase?
(also: #src_arrow)
Get source arrow.
-
#get_src_point ⇒ Wx::RealPoint
(also: #src_point)
Get source point.
-
#get_src_shape ⇒ Shape?
(also: #src_shape)
Get source shape.
-
#get_stand_alone ⇒ Boolean
(also: #stand_alone?)
Returns true if stand alone line.
-
#get_trg_arrow ⇒ Wx::SF::ArrowBase?
(also: #trg_arrow)
Get target arrow.
-
#get_trg_point ⇒ Wx::RealPoint
(also: #trg_point)
Get target point.
-
#get_trg_shape ⇒ Shape?
(also: #trg_shape)
Get target shape.
-
#initialize(src = nil, trg = nil, path: nil, diagram: nil) ⇒ LineShape
constructor
A new instance of LineShape.
- #move_by(x, y) ⇒ Object
- #move_to(x, y) ⇒ Object
- #on_begin_drag(pos) ⇒ Object
- #on_end_handle(handle) ⇒ Object
-
#on_handle(handle) ⇒ Object
Event handler called during dragging of the shape handle.
- #on_left_double_click(pos) ⇒ Object
-
#scale(x, y, children: WITHCHILDREN) ⇒ Object
(new implementation should call default one or scale shape’s children manually if necessary).
-
#set_dock_point(index) ⇒ Object
(also: #dock_point=)
Set the line dock point.
-
#set_ending_connection_point(cp) ⇒ Object
Initialize line’s ending point with existing fixed connection point.
-
#set_line_mode(mode) ⇒ Object
protected
Set line shape’s working mode.
-
#set_line_pen(*args) ⇒ Object
(also: #line_pen=)
Set line type.
-
#set_src_arrow(arg) ⇒ Object
(also: #src_arrow=)
Set source arrow.
-
#set_src_point(pt) ⇒ Object
Set source point.
-
#set_src_shape(shape) ⇒ Object
(also: #src_shape=)
Set source shape.
-
#set_stand_alone(f = true) ⇒ Object
(also: #stand_alone=)
Set stand alone line mode.
-
#set_starting_connection_point(cp) ⇒ Object
Initialize line’s starting point with existing fixed connection point.
-
#set_trg_arrow(arg) ⇒ Object
(also: #trg_arrow=)
Set target arrow.
-
#set_trg_point(pt) ⇒ Object
Set target point.
-
#set_trg_shape(shape) ⇒ Object
(also: #trg_shape=)
Set target shape.
- #set_unfinished_point(pos) ⇒ Object protected
Methods inherited from Shape
#accept_child, #accept_connection, #accept_currently_dragged_shapes, #accept_src_neighbour, #accept_trg_neighbour, #activate, #active?, #add_child_shape, #add_connection_point, #add_handle, #add_style, #ancestor?, #clear_accepted_childs, #clear_accepted_connections, #clear_accepted_src_neighbours, #clear_accepted_trg_neighbours, component, component_shapes, #contains_style, #descendant?, #do_alignment, #does_not_accept_children?, #draw, #draw_selected, #draw_shadow, #fit_to_children, #get_accepted_children, #get_accepted_connections, #get_accepted_src_neighbours, #get_accepted_trg_neighbours, #get_assigned_connections, #get_center, #get_child_shapes, #get_children, #get_children_recursively, #get_complete_bounding_box, #get_connection_point, #get_connection_points, #get_custom_dock_point, #get_diagram, #get_grand_parent_shape, #get_h_align, #get_h_border, #get_handle, #get_handles, #get_hover_colour, #get_nearest_connection_point, #get_neighbours, #get_parent_absolute_position, #get_parent_canvas, #get_parent_shape, #get_relative_position, #get_shape_canvas, #get_style, #get_user_data, #get_v_align, #get_v_border, #has_children, #has_selected_parent?, #include_child_shape?, #inside?, #inspect, #intersects?, #is_child_accepted, #is_connection_accepted, #is_managed, #is_manager, #is_src_neighbour_accepted, #is_trg_neighbour_accepted, lines_intersection, #lines_intersection, #on_begin_handle, #on_child_dropped, #on_dragging, #on_end_drag, #on_import, #on_key, #on_left_click, #on_mouse_enter, #on_mouse_leave, #on_mouse_over, #on_right_click, #on_right_double_click, #refresh, #refresh_rect, #remove_connection_point, #remove_handle, #remove_style, #scale_children, #select, #selected?, #set_custom_dock_point, #set_diagram, #set_h_align, #set_h_border, #set_hover_colour, #set_parent_shape, #set_relative_position, #set_style, #set_user_data, #set_v_align, #set_v_border, #show, #show_handles, #to_s, #update, #visible?
Constructor Details
#initialize(src = nil, trg = nil, path: nil, manager: nil) ⇒ LineShape #initialize(src, trg, path: nil, manager: nil) ⇒ LineShape
Returns a new instance of LineShape.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 59 def initialize(src = nil, trg = nil, path: nil, diagram: nil) super(diagram: diagram) if src.respond_to?(:to_real_point) && trg.respond_to?(:to_real_point) @src_point = Wx::Point === src ? src.to_real_point : src.dup @trg_point = Wx::Point === trg ? trg.to_real_point : trg.dup @src_shape = @trg_shape = nil @stand_alone = true elsif (src.nil? && trg.nil?) || (src.is_a?(Shape) && trg.is_a?(Shape)) @src_point = DEFAULT::POINT.dup @trg_point = DEFAULT::POINT.dup @src_shape = src @trg_shape = trg @stand_alone = false else ::Kernel.raise ArgumentError, "Invalid arguments #{args}" end path ||= [] @lst_points = path.select { |pt| pt.respond_to?(:to_real_point) }.collect { |pt| pt.to_real_point } ::Kernel.raise ArgumentError, "Invalid arguments #{args}" unless path.size == @lst_points.size @src_arrow = nil @trg_arrow = nil @dock_point = DEFAULT::DOCKPOINT @pen = nil @src_offset = DEFAULT::OFFSET.dup @trg_offset = DEFAULT::OFFSET.dup @mode = LINEMODE::READY @prev_position = Wx::RealPoint.new @unfinished_point = Wx::Point.new end |
Instance Method Details
#contains?(pos) ⇒ Boolean
can be overridden if necessary.
469 470 471 472 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 469 def contains?(pos) return true if @mode != LINEMODE::UNDERCONSTRUCTION && get_hit_linesegment(pos) >= 0 false end |
#create_handles ⇒ Object
at the creation time. The function can be overridden if necessary.
506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 506 def create_handles # first clear all previously used handles and then create new ones @handles.clear # create control points handles @lst_points.size.times { |i| add_handle(Shape::Handle::TYPE::LINECTRL, i) } # create border handles add_handle(Shape::Handle::TYPE::LINESTART) add_handle(Shape::Handle::TYPE::LINEEND) end |
#draw_complete_line(dc) ⇒ Object (protected)
Draw completed line.
692 693 694 695 696 697 698 699 700 701 702 703 704 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 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 692 def draw_complete_line(dc) return unless diagram case @mode when LINEMODE::READY # draw line parts n = line_segment_count-1 (0..n).each do |i| src, trg = get_line_segment(i) # at starting (src) segment draw src arrow and get updated arrow connection point src = @src_arrow.draw(trg, src, dc) if i == 0 && @src_arrow # at end (tgt) segment draw tgt arrow and get updated connection point trg = @trg_arrow.draw(src, trg, dc) if i == n && @trg_arrow # draw line segment dc.draw_line(src.to_point, trg.to_point) end when LINEMODE::UNDERCONSTRUCTION # draw basic line parts trg = nil @lst_points.size.times do |i| src, trg = get_line_segment(i) dc.draw_line(src.to_point, trg.to_point) end # draw unfinished line segment if any (for interactive line creation) dc.with_pen(Wx::Pen.new(Wx::BLACK, 1, Wx::PENSTYLE_DOT)) do if @lst_points.size > 0 dc.draw_line(trg.to_point, @unfinished_point) else if @src_shape if @src_shape.get_connection_points.empty? dc.draw_line((@src_shape.get_border_point(@src_shape.get_center, @unfinished_point.to_real)).to_point, @unfinished_point) else dc.draw_line(get_mod_src_point.to_point, @unfinished_point) end end end end when LINEMODE::SRCCHANGE # draw basic line parts @lst_points.size.times do |i| src, trg = get_line_segment(i+1) dc.draw_line(src.to_point, trg.to_point) end # draw linesegment being updated _, trg = get_line_segment(0) dc.set_pen(Wx::Pen.new(Wx::BLACK, 1, Wx::PENSTYLE_DOT)) unless @stand_alone dc.draw_line(@unfinished_point, trg.to_point) dc.set_pen(Wx::NULL_PEN) unless @stand_alone when LINEMODE::TRGCHANGE # draw basic line parts trg = nil if @lst_points.empty? trg = get_src_point else @lst_points.size.times do |i| src, trg = get_line_segment(i) dc.draw_line(src.to_point, trg.to_point) end end # draw linesegment being updated dc.set_pen(Wx::Pen.new(Wx::BLACK, 1, Wx::PENSTYLE_DOT)) unless @stand_alone dc.draw_line(trg.to_point, @unfinished_point) dc.set_pen(Wx::NULL_PEN) unless @stand_alone end end |
#draw_highlighted(dc) ⇒ Object (protected)
684 685 686 687 688 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 684 def draw_highlighted(dc) dc.with_pen(Wx::Pen.new(hover_colour, 2)) do draw_complete_line(dc) end end |
#draw_hover(dc) ⇒ Object (protected)
674 675 676 677 678 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 674 def draw_hover(dc) dc.with_pen(Wx::Pen.new(hover_colour, 1)) do draw_complete_line(dc) end end |
#draw_normal(dc) ⇒ Object (protected)
Draw the shape in the normal way. The function can be overridden if necessary.
665 666 667 668 669 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 665 def draw_normal(dc) dc.with_pen(line_pen) do draw_complete_line(dc) end end |
#get_absolute_position ⇒ Wx::RealPoint
Get the shape’s absolute position in the canvas.
452 453 454 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 452 def get_absolute_position get_dock_point_position(@dock_point) end |
#get_border_point(_start_pt, _end_pt) ⇒ Wx::RealPoint
Returns Intersection point.
461 462 463 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 461 def get_border_point(_start_pt, _end_pt) get_absolute_position end |
#get_bounding_box ⇒ Wx::Rect
Returns Bounding rectangle.
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 410 def get_bounding_box line_rct = nil # calculate control points area if they exist if !@lst_points.empty? prev_pt = get_src_point.to_point @lst_points.each do |pt| pt = pt.to_point if line_rct.nil? line_rct = Wx::Rect.new(prev_pt, pt) else line_rct.union!(Wx::Rect.new(prev_pt, pt)) end prev_pt = pt end line_rct.union!(Wx::Rect.new(prev_pt, get_trg_point.to_point)) else # include starting point pt = get_src_point line_rct = Wx::Rect.new(pt.x.to_i, pt.y.to_i, 1, 1) # include ending point pt = get_trg_point line_rct.union!(Wx::Rect.new(pt.x.to_i, pt.y.to_i, 1, 1)) end # include unfinished point if the line is under construction if @mode == LINEMODE::UNDERCONSTRUCTION || @mode == LINEMODE::SRCCHANGE || @mode == LINEMODE::TRGCHANGE if line_rct.nil? line_rct = Wx::Rect.new(@unfinished_point.x, @unfinished_point.y, 1, 1) else line_rct.union!(Wx::Rect.new(@unfinished_point.x, @unfinished_point.y, 1, 1)) end end line_rct ? line_rct : Wx::Rect.new end |
#get_control_points ⇒ Array<Wx::RealPoint>
Get a list of the line’s control points (their positions).
333 334 335 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 333 def get_control_points @lst_points end |
#get_direct_line ⇒ Array(Wx::RealPoint, Wx::RealPoint)
Returns starting line point and ending line point.
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 281 def get_direct_line if @stand_alone return [@src_point, @trg_point] else if @src_shape && @trg_shape trg_center = get_mod_trg_point src_center = get_mod_src_point if @src_shape.get_parent_shape == @trg_shape || @trg_shape.get_parent_shape == @src_shape trg_bb = @trg_shape.get_bounding_box src_bb = @src_shape.get_bounding_box if trg_bb.contains?(src_center.x.to_i, src_center.y.to_i) if src_center.y > trg_center.y src = Wx::RealPoint.new(src_center.x, src_bb.bottom.to_f) trg = Wx::RealPoint.new(src_center.x, trg_bb.bottom.to_f) else src = Wx::RealPoint.new(src_center.x, src_bb.top.to_f) trg = Wx::RealPoint.new(src_center.x, trg_bb.top.to_f) end return [src, trg] elsif src_bb.contains?(trg_center.x.to_i, trg_center.y.to_i) if trg_center.y > src_center.y src = Wx::RealPoint.new(trg_center.x, src_bb.bottom.to_f) trg = Wx::RealPoint.new(trg_center.x, trg_bb.bottom.to_f) else src = Wx::RealPoint.new(trg_center.x, src_bb.top.to_f) trg = Wx::RealPoint.new(trg_center.x, trg_bb.top.to_f) end return [src, trg] end end if @src_shape.get_connection_points.empty? src = @src_shape.get_border_point(src_center, trg_center) else src = src_center end if @trg_shape.get_connection_points.empty? trg = @trg_shape.get_border_point(trg_center, src_center) else trg = trg_center end return [src, trg] end end raise SFException, 'Missing src and/or trg for line' end |
#get_dock_point ⇒ Integer
Get the line dock point. It is a zero based index of the line control point which will act as the shape position (value returned by Shape#get_relative_position function).
261 262 263 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 261 def get_dock_point @dock_point end |
#get_dock_point_position(dp) ⇒ Wx::RealPoint
Get a position of given line dock point.
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 340 def get_dock_point_position(dp) pts_cnt = @lst_points.size if dp >= 0 if pts_cnt > dp return @lst_points[dp] elsif pts_cnt > 0 return @lst_points[pts_cnt/2] end elsif dp == -1 # start line point return get_src_point elsif dp == -2 # end line point return get_trg_point end get_center end |
#get_hit_linesegment(pos) ⇒ Integer (protected)
Returns Zero-based index of line segment located under the given point.
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 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 767 def get_hit_linesegment(pos) return -1 unless get_bounding_box.contains?(pos) pos = pos.to_point # Get all polyline segments line_segment_count.times do |i| src, trg = get_line_segment(i) # calculate line segment bounding box ls_bb = Wx::Rect.new(src.to_point, trg.to_point) ls_bb.inflate!(2) # convert line segment to its parametric form a = trg.y - src.y b = src.x - trg.x c = -a*src.x - b*src.y # calculate distance of the line and give point d = (a*pos.x + b*pos.y + c)/::Math.sqrt(a*a + b*b) # NaN will be the result if src and trg are equal # (which can happen for lines between parent and child shapes) return i if (d.nan? || d.to_i.abs <= 5) && ls_bb.contains?(pos) end -1 end |
#get_line_mode ⇒ LINEMODE
Get current working mode.
657 658 659 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 657 def get_line_mode @mode end |
#get_line_pen ⇒ Wx::Pen Also known as: line_pen
Get line type
229 230 231 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 229 def get_line_pen @pen || (@diagram&.shape_canvas ? @diagram.shape_canvas.line_pen : DEFAULT.pen) end |
#get_line_segment(index) ⇒ Array(Wx::RealPoint,Wx::RealPoint)
Returns starting and ending point of line segment.
393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 393 def get_line_segment(index) if @lst_points.empty? return get_direct_line if index == 0 else if index == 0 return [get_src_point, @lst_points.first] elsif index == @lst_points.size return [@lst_points.last, get_trg_point] elsif index > 0 && index < @lst_points.size return @lst_points[index-1, 2].collect {|p| p} end end [Wx::RealPoint.new, Wx::RealPoint.new] end |
#get_line_segment_count ⇒ Integer Also known as: line_segment_count, segment_count
Get number of line segments for this shape.
384 385 386 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 384 def get_line_segment_count @lst_points.size+1 end |
#get_mod_src_point ⇒ Wx::RealPoint (protected)
Returns Modified starting line point.
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 810 def get_mod_src_point return Wx::RealPoint.new unless @src_shape if @src_offset != DEFAULT::OFFSET bb_rct = @src_shape.get_bounding_box mod_point = @src_shape.get_absolute_position.dup mod_point.x += bb_rct.width.to_f * @src_offset.x mod_point.y += bb_rct.height.to_f * @src_offset.y else mod_point = @src_shape.get_center end conn_pt = @src_shape.get_nearest_connection_point(mod_point) mod_point = conn_pt.get_connection_point if conn_pt mod_point end |
#get_mod_trg_point ⇒ Wx::RealPoint (protected)
Returns Modified ending line point.
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 831 def get_mod_trg_point return Wx::RealPoint.new unless @trg_shape if @trg_offset != DEFAULT::OFFSET bb_rct = @trg_shape.get_bounding_box mod_point = @trg_shape.get_absolute_position.dup mod_point.x += bb_rct.width.to_f * @trg_offset.x mod_point.y += bb_rct.height.to_f * @trg_offset.y else mod_point = @trg_shape.get_center end conn_pt = @trg_shape.get_nearest_connection_point(mod_point) mod_point = conn_pt.get_connection_point if conn_pt mod_point end |
#get_src_arrow ⇒ Wx::SF::ArrowBase? Also known as: src_arrow
Get source arrow.
181 182 183 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 181 def get_src_arrow @src_arrow end |
#get_src_point ⇒ Wx::RealPoint Also known as: src_point
Get source point.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 123 def get_src_point unless @stand_alone if @src_shape && !@lst_points.empty? if @src_shape.get_connection_points.empty? return @src_shape.get_border_point(get_mod_src_point, @lst_points.first) else return get_mod_src_point end else if @mode != LINEMODE::UNDERCONSTRUCTION pt1, _ = get_direct_line else pt1 = get_mod_src_point end return pt1 end end @src_point end |
#get_src_shape ⇒ Shape? Also known as: src_shape
Get source shape
95 96 97 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 95 def get_src_shape @src_shape end |
#get_stand_alone ⇒ Boolean Also known as: stand_alone?
Returns true if stand alone line
267 268 269 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 267 def get_stand_alone @stand_alone end |
#get_trg_arrow ⇒ Wx::SF::ArrowBase? Also known as: trg_arrow
Get target arrow.
205 206 207 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 205 def get_trg_arrow @trg_arrow end |
#get_trg_point ⇒ Wx::RealPoint Also known as: trg_point
Get target point.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 152 def get_trg_point unless @stand_alone if @trg_shape && !@lst_points.empty? if @trg_shape.get_connection_points.empty? return @trg_shape.get_border_point(get_mod_trg_point, @lst_points.last) else return get_mod_trg_point end else if @mode != LINEMODE::UNDERCONSTRUCTION _, pt2 = get_direct_line else pt2 = @unfinished_point.to_real end return pt2 end end @trg_point end |
#get_trg_shape ⇒ Shape? Also known as: trg_shape
Get target shape.
109 110 111 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 109 def get_trg_shape @trg_shape end |
#move_by(x, y) ⇒ Object
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 488 def move_by(x, y) @lst_points.each do |pt| pt.x += x pt.y += y end if @stand_alone @src_point += [x, y] @trg_point += [x, y] end update unless @child_shapes.empty? get_diagram.set_modified if get_diagram end |
#move_to(x, y) ⇒ Object
478 479 480 481 482 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 478 def move_to(x, y) move_by(x - @prev_position.x, y - @prev_position.y) @prev_position.x = x @prev_position.y = y end |
#on_begin_drag(pos) ⇒ Object
584 585 586 587 588 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 584 def on_begin_drag(pos) @prev_position = get_absolute_position.dup super end |
#on_end_handle(handle) ⇒ Object
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 550 def on_end_handle(handle) # update percentual offset of the line's ending points parent = get_parent_canvas.get_shape_under_cursor # propagate request for interactive connection editing if requested while parent && parent.has_style?(Shape::STYLE::PROPAGATE_INTERACTIVE_CONNECTION) parent = parent.get_parent_shape end if parent && !@stand_alone bb_rect = parent.get_bounding_box case handle.type when Shape::Handle::TYPE::LINESTART if parent == @src_shape @src_offset.x = (handle.get_position.x - bb_rect.left).to_f / bb_rect.width @src_offset.y = (handle.get_position.y - bb_rect.top).to_f / bb_rect.height end when Shape::Handle::TYPE::LINEEND if parent == @trg_shape @trg_offset.x = (handle.get_position.x - bb_rect.left).to_f / bb_rect.width @trg_offset.y = (handle.get_position.y - bb_rect.top).to_f / bb_rect.height end end end super end |
#on_handle(handle) ⇒ Object
Event handler called during dragging of the shape handle. The function can be overridden if necessary.
The function is called by the framework (by the shape canvas).
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 523 def on_handle(handle) case handle.type when Shape::Handle::TYPE::LINECTRL pt = @lst_points[handle.id] if pt pt.x = handle.get_position.x pt.y = handle.get_position.y end when Shape::Handle::TYPE::LINEEND @unfinished_point = handle.get_position @trg_point = handle.get_position.to_real if @stand_alone when Shape::Handle::TYPE::LINESTART @unfinished_point = handle.get_position @src_point = handle.get_position.to_real if @stand_alone end super end |
#on_left_double_click(pos) ⇒ Object
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 596 def on_left_double_click(pos) # HINT: override it for custom actions if get_parent_canvas # remove existing handle if exist otherwise create a new one at the # given position handle = get_parent_canvas.get_topmost_handle_at_position(pos) if handle && handle.get_parent_shape == self if handle.type == Shape::Handle::TYPE::LINECTRL if has_style?(STYLE::EMIT_EVENTS) evt = Wx::SF::ShapeHandleEvent.new(EVT_SF_LINE_HANDLE_REMOVE, self.object_id) evt.set_shape(self) evt.set_handle(handle) get_parent_canvas.get_event_handler.process_event(evt) end @lst_points.delete_at(handle.id) create_handles show_handles(true) end else index = get_hit_linesegment(pos) if index > -1 @lst_points.insert(index, Wx::RealPoint.new(pos.x, pos.y)) create_handles show_handles(true) if has_style?(STYLE::EMIT_EVENTS) handle = get_parent_canvas.get_topmost_handle_at_position(pos) if handle evt = ShapeHandleEvent.new(EVT_SF_LINE_HANDLE_ADD, self.object_id) evt.set_shape(this) evt.set_handle(handle) get_parent_canvas.get_event_handler.process_event(evt) end end end end end end |
#scale(x, y, children: WITHCHILDREN) ⇒ Object
(new implementation should call default one or scale shape’s children manually if necessary).
644 645 646 647 648 649 650 651 652 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 644 def scale(x, y, children: WITHCHILDREN) @lst_points.each do |pt| pt.x *= x pt.y *= y end # call default function implementation (needed for scaling of shape's children) super end |
#set_dock_point(index) ⇒ Object Also known as: dock_point=
Set the line dock point. It is a zero based index of the line control point which will act as the shape position (value returned by Shape#get_relative_position function).
253 254 255 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 253 def set_dock_point(index) @dock_point = index end |
#set_ending_connection_point(cp) ⇒ Object
Initialize line’s ending point with existing fixed connection point.
372 373 374 375 376 377 378 379 380 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 372 def set_ending_connection_point(cp) if cp&.get_parent_shape pos_cp = cp.get_connection_point rct_bb = cp.get_parent_shape.get_bounding_box @trg_offset.x = (pos_cp.x - rct_bb.left).to_f / rct_bb.width @trg_offset.y = (pos_cp.y - rct_bb.top).to_f / rct_bb.height end end |
#set_line_mode(mode) ⇒ Object (protected)
Set line shape’s working mode.
797 798 799 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 797 def set_line_mode(mode) @mode = mode end |
#set_line_pen(pen) ⇒ Object #set_line_pen(color, width = 1, style = Wx::PenStyle::PENSTYLE_SOLID) ⇒ Object Also known as: line_pen=
Set line type
241 242 243 244 245 246 247 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 241 def set_line_pen(*args) @pen = if args.size == 1 && Wx::Pen === args.first args.first else Wx::Pen.new(*args) end end |
#set_src_arrow(arrow) ⇒ Wx::SF::ArrowBase? #set_src_arrow(arrow_klass) ⇒ Wx::SF::ArrowBase? Also known as: src_arrow=
Set source arrow
193 194 195 196 197 198 199 200 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 193 def set_src_arrow(arg) if arg.nil? || (arg.is_a?(::Class) && arg < ArrowBase) || arg.is_a?(ArrowBase) @src_arrow = (arg.nil? || arg.is_a?(ArrowBase)) ? arg : arg.new @src_arrow.set_parent_shape(self) if @src_arrow return @src_arrow end nil end |
#set_src_point(pt) ⇒ Object
Set source point.
146 147 148 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 146 def set_src_point(pt) @src_point = pt.to_real_point end |
#set_src_shape(shape) ⇒ Object Also known as: src_shape=
Set source shape.
102 103 104 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 102 def set_src_shape(shape) @src_shape = shape end |
#set_stand_alone(f = true) ⇒ Object Also known as: stand_alone=
Set stand alone line mode
274 275 276 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 274 def set_stand_alone(f = true) @stand_alone = !!f end |
#set_starting_connection_point(cp) ⇒ Object
Initialize line’s starting point with existing fixed connection point.
360 361 362 363 364 365 366 367 368 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 360 def set_starting_connection_point(cp) if cp&.get_parent_shape pos_cp = cp.get_connection_point rct_bb = cp.get_parent_shape.get_bounding_box @src_offset.x = (pos_cp.x - rct_bb.left).to_f / rct_bb.width @src_offset.y = (pos_cp.y - rct_bb.top).to_f / rct_bb.height end end |
#set_trg_arrow(arrow) ⇒ Wx::SF::ArrowBase? #set_trg_arrow(arrow_klass) ⇒ Wx::SF::ArrowBase? Also known as: trg_arrow=
Set target arrow
217 218 219 220 221 222 223 224 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 217 def set_trg_arrow(arg) if arg.nil? || (arg.is_a?(::Class) && arg < ArrowBase) || arg.is_a?(ArrowBase) @trg_arrow = (arg.nil? || arg.is_a?(ArrowBase)) ? arg : arg.new @trg_arrow.set_parent_shape(self) if @trg_arrow return @trg_arrow end nil end |
#set_trg_point(pt) ⇒ Object
Set target point.
175 176 177 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 175 def set_trg_point(pt) @trg_point = pt.to_real_point end |
#set_trg_shape(shape) ⇒ Object Also known as: trg_shape=
Set target shape.
116 117 118 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 116 def set_trg_shape(shape) @trg_shape = shape end |
#set_unfinished_point(pos) ⇒ Object (protected)
804 805 806 |
# File 'lib/wx/shapes/shapes/line_shape.rb', line 804 def set_unfinished_point(pos) @unfinished_point = pos.to_point end |