Class: TT::Gizmo::MoveGizmo

Inherits:
Object
  • Object
show all
Defined in:
TT_Lib2/gizmo_manipulator.rb

Overview

Since:

  • 2.7.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, origin, direction, color, active_color) ⇒ MoveGizmo

Returns a new instance of MoveGizmo

Parameters:

  • origin (Geom::Point3d)
  • direction (Geom::Vector3d)
  • color (Sketchup::Color)
  • active_color (Sketchup::Color)

Since:

  • 2.7.0



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

#directionObject

Since:

  • 2.7.0



506
507
508
# File 'TT_Lib2/gizmo_manipulator.rb', line 506

def direction
  @direction
end

#originObject

Since:

  • 2.7.0



506
507
508
# File 'TT_Lib2/gizmo_manipulator.rb', line 506

def origin
  @origin
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

Since:

  • 2.7.0



561
562
563
# File 'TT_Lib2/gizmo_manipulator.rb', line 561

def active?
  @interacting == true
end

#cancelObject

Since:

  • 2.7.0



686
687
688
689
# File 'TT_Lib2/gizmo_manipulator.rb', line 686

def cancel
  @selected = false
  @interacting = false
end

#draw(view) ⇒ Nil

Parameters:

  • view (Sketchup::View)

Returns:

  • (Nil)

Since:

  • 2.7.0



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

Returns:

  • (Boolean)

Since:

  • 2.7.0



567
568
569
# File 'TT_Lib2/gizmo_manipulator.rb', line 567

def mouse_active?
  @mouse_active == true
end

#on_transform(&block) ⇒ Object

Since:

  • 2.7.0



545
546
547
# File 'TT_Lib2/gizmo_manipulator.rb', line 545

def on_transform( &block )
  @callback = block
end

#on_transform_end(&block) ⇒ Object

Since:

  • 2.7.0



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

Since:

  • 2.7.0



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

Parameters:

  • flags (Integer)
  • x (Integer)
  • y (Integer)
  • view (Sketchup::View)

Returns:

  • (Boolean)

Since:

  • 2.7.0



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

Parameters:

  • flags (Integer)
  • x (Integer)
  • y (Integer)
  • view (Sketchup::View)

Returns:

  • (Boolean)

Since:

  • 2.7.0



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

Parameters:

  • flags (Integer)
  • x (Integer)
  • y (Integer)
  • view (Sketchup::View)

Returns:

  • (Boolean)

Since:

  • 2.7.0



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

#tooltipObject

Since:

  • 2.7.0



572
573
574
# File 'TT_Lib2/gizmo_manipulator.rb', line 572

def tooltip
  'Move'
end