Class: TT::Gizmo::MoveGizmo
- Inherits:
-
Object
- Object
- TT::Gizmo::MoveGizmo
- Defined in:
- TT_Lib2/gizmo_manipulator.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #cancel ⇒ Object
- #draw(view) ⇒ Nil
-
#initialize(parent, origin, direction, color, active_color) ⇒ MoveGizmo
constructor
A new instance of MoveGizmo.
- #mouse_active? ⇒ Boolean
- #on_transform(&block) ⇒ Object
- #on_transform_end(&block) ⇒ Object
- #on_transform_start(&block) ⇒ Object
- #onLButtonDown(flags, x, y, view) ⇒ Boolean
- #onLButtonUp(flags, x, y, view) ⇒ Boolean
- #onMouseMove(flags, x, y, view) ⇒ Boolean
- #tooltip ⇒ Object
Constructor Details
#initialize(parent, origin, direction, color, active_color) ⇒ MoveGizmo
Returns a new instance of MoveGizmo
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 514 def initialize( parent, origin, direction, color, active_color ) @parent = parent @origin = origin.clone @direction = direction.clone @color = color @active_color = active_color @selected = false @interacting = false # Cache of the axis origin and orientation. Cached on onLButtonDown @old_origin = nil @old_vector = nil @old_axis = nil # [pt1, pt2] # User InputPoint @ip = Sketchup::InputPoint.new @pt_start = nil # Startpoint - IP projected to selected axis @pt_screen_start = nil # Screen projection of @pt_start @pt_mouse = nil # Mouse Point3d - projected to selected axis @pt_screen_mouse = nil # Event callbacks @callback = nil @callback_start = nil @callback_end = nil end |
Instance Attribute Details
#direction ⇒ Object
506 507 508 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 506 def direction @direction end |
#origin ⇒ Object
506 507 508 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 506 def origin @origin end |
Instance Method Details
#active? ⇒ Boolean
561 562 563 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 561 def active? @interacting == true end |
#cancel ⇒ Object
686 687 688 689 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 686 def cancel @selected = false @interacting = false end |
#draw(view) ⇒ Nil
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 648 def draw( view ) # Arrow Body segment = modelspace_segment( view ) segment2d = segment.map { |point| view.screen_coords( point ) } view.line_stipple = '' view.line_width = 2 view.drawing_color = (@selected) ? @active_color : @color view.draw2d( GL_LINES, segment2d ) # Arrowhead segments = arrow_segments( view ) # Arrowhead Edges view.line_stipple = '' view.line_width = 2 view.drawing_color = (@selected) ? @active_color : @color for segment in segments screen_points = segment.map { |point| view.screen_coords( point ) } view.draw2d( GL_LINE_STRIP, screen_points ) end # Arrowhead Fill if TT::SketchUp.support?( TT::SketchUp::COLOR_ALPHA ) circle = segments.last tip = segments.first.last triangles = [] (0...circle.size-1).each { |i| triangles << circle[ i ] triangles << circle[ i+1 ] triangles << tip } color = Sketchup::Color.new( *@color.to_a ) color.alpha = 45 view.drawing_color = color screen_points = triangles.map { |point| view.screen_coords( point ) } view.draw2d( GL_TRIANGLES, screen_points ) end end |
#mouse_active? ⇒ Boolean
567 568 569 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 567 def mouse_active? @mouse_active == true end |
#on_transform(&block) ⇒ Object
545 546 547 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 545 def on_transform( &block ) @callback = block end |
#on_transform_end(&block) ⇒ Object
555 556 557 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 555 def on_transform_end( &block ) @callback_end = block end |
#on_transform_start(&block) ⇒ Object
550 551 552 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 550 def on_transform_start( &block ) @callback_start = block end |
#onLButtonDown(flags, x, y, view) ⇒ Boolean
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 583 def onLButtonDown( flags, x, y, view ) if @selected @interacting = true # Cache the origin for use in onMouseMove to work out the distance # moved. @old_origin = @origin.clone @old_axis = [ @origin, @origin.offset( @direction, 10 ) ] # Line (3D) # Get input point closest to the selected axis ip = view.inputpoint( x, y ) @pt_start = ip.position.project_to_line( [@origin, @direction] ) # Project to screen axis screen_point = Geom::Point3d.new( x, y, 0 ) screen_axis = screen_points( @old_axis, view ) @pt_screen_start = screen_point.project_to_line( screen_axis ) @callback_start.call( self, 'Move' ) unless @callback_start.nil? true else false end end |
#onLButtonUp(flags, x, y, view) ⇒ Boolean
615 616 617 618 619 620 621 622 623 624 625 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 615 def onLButtonUp( flags, x, y, view ) if @interacting @ip.clear @callback_end.call( self, 'Move' ) unless @callback_end.nil? @interacting = false true else @interacting = false false end end |
#onMouseMove(flags, x, y, view) ⇒ Boolean
634 635 636 637 638 639 640 641 642 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 634 def onMouseMove(flags, x, y, view) if @interacting @mouse_active = true move_event( x, y, view ) # return true else @selected = mouse_over?( x, y, view ) @mouse_active = @selected end end |
#tooltip ⇒ Object
572 573 574 |
# File 'TT_Lib2/gizmo_manipulator.rb', line 572 def tooltip 'Move' end |