// **************************************************************************** // // Function Name: RSingleSelection::GetRotateHandle( ) // // Description: Retrieves a vector rect representing the rotation handle. // // Returns: Nothing // // Exceptions: Nothing // // **************************************************************************** // void RSingleSelection::GetRotateHandle( RRealVectorRect& rotateHandleRect ) const { // Get the bounding rect YSelectionBoundingRect boundingRect; GetSelectionBoundingRect( boundingRect ); RRealPoint centerPoint = boundingRect.GetCenterPoint( ); R2dTransform transform( boundingRect.GetTransform( ) ); transform.PostTranslate( centerPoint.m_x-boundingRect.m_TopLeft.m_x, centerPoint.m_y-boundingRect.m_TopLeft.m_y ); // Break the transform into its components YAngle angle; YRealDimension xScale; YRealDimension yScale; transform.Decompose( angle, xScale, yScale ); // Figure out where to end the line RRealPoint lineEndPoint = GetRotateHandleCenterPoint( ); YRealDimension distance = centerPoint.Distance( lineEndPoint ); if ( xScale < 0 ) xScale = -xScale; rotateHandleRect.Set( RRealSize(distance/xScale,1), transform ); // Convert to device units RRealSize handleSize( kRotateHandleHitSize/2, kRotateHandleHitSize/2 ); ::DeviceUnitsToLogicalUnits( handleSize, *m_pView ); rotateHandleRect.Inflate( handleSize ); }
// **************************************************************************** // // Function Name: RResizeSelectionTracker::BeginTracking( ) // // Description: Called when tracking begins; ie. when the mouse button goes // down. // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RResizeSelectionTracker::BeginTracking( const RRealPoint& mousePoint, YModifierKey modifierKeys ) { // Remove the selection m_pSelection->Remove( FALSE ); // Get the hit object RSingleSelection* pHitObject = m_pSelection->GetHitSingleSelection( mousePoint ); TpsAssert( pHitObject, "No hit object!" ); // Get its selection bounding rect YSelectionBoundingRect selectionBoundingRect; pHitObject->GetSelectionBoundingRect( selectionBoundingRect ); // Get the bounding rect of the actual object YSelectionBoundingRect objectBoundingRect; pHitObject->GetObjectBoundingRect( objectBoundingRect ); // Calculate the minimum scale factor RRealSize minimumObjectSize = pHitObject->GetObjectMinimumSize( ); RRealSize maximumObjectSize = pHitObject->GetObjectMaximumSize( ); RRealSize currentObjectSize = objectBoundingRect.WidthHeight( ); m_MinimumScaleFactor.m_dx = minimumObjectSize.m_dx / currentObjectSize.m_dx; m_MinimumScaleFactor.m_dy = minimumObjectSize.m_dy / currentObjectSize.m_dy; m_MaximumScaleFactor.m_dx = maximumObjectSize.m_dx / currentObjectSize.m_dx; m_MaximumScaleFactor.m_dy = maximumObjectSize.m_dy / currentObjectSize.m_dy; // Hit test to figure out what kind of resizing we are doing RSelection::EHitLocation eHitLocation = m_pSelection->HitTest( mousePoint ); // Get the center and start of scaling RRealPoint selectionScalingCenter; switch( eHitLocation ) { case RSelection::kTopLeftResizeHandle : selectionScalingCenter = selectionBoundingRect.m_BottomRight; m_ScalingCenter = objectBoundingRect.m_BottomRight; m_MouseDownPoint = objectBoundingRect.m_TopLeft; break; case RSelection::kTopRightResizeHandle : selectionScalingCenter = selectionBoundingRect.m_BottomLeft; m_ScalingCenter = objectBoundingRect.m_BottomLeft; m_MouseDownPoint = objectBoundingRect.m_TopRight; break; case RSelection::kBottomRightResizeHandle : selectionScalingCenter = selectionBoundingRect.m_TopLeft; m_ScalingCenter = objectBoundingRect.m_TopLeft; m_MouseDownPoint = objectBoundingRect.m_BottomRight; break; case RSelection::kBottomLeftResizeHandle : selectionScalingCenter = selectionBoundingRect.m_TopRight; m_ScalingCenter = objectBoundingRect.m_TopRight; m_MouseDownPoint = objectBoundingRect.m_BottomLeft; break; case RSelection::kLeftResizeHandle : ::midpoint(selectionScalingCenter,selectionBoundingRect.m_TopRight,selectionBoundingRect.m_BottomRight); ::midpoint(m_ScalingCenter,objectBoundingRect.m_TopRight,objectBoundingRect.m_BottomRight); ::midpoint(m_MouseDownPoint,objectBoundingRect.m_TopLeft,objectBoundingRect.m_BottomLeft); m_fFixVertical = TRUE; break; case RSelection::kTopResizeHandle : ::midpoint(selectionScalingCenter,selectionBoundingRect.m_BottomLeft,selectionBoundingRect.m_BottomRight); ::midpoint(m_ScalingCenter,objectBoundingRect.m_BottomLeft,objectBoundingRect.m_BottomRight); ::midpoint(m_MouseDownPoint,objectBoundingRect.m_TopLeft,objectBoundingRect.m_TopRight); m_fFixHorizontal = TRUE; break; case RSelection::kRightResizeHandle : ::midpoint(selectionScalingCenter,selectionBoundingRect.m_TopLeft,selectionBoundingRect.m_BottomLeft); ::midpoint(m_ScalingCenter,objectBoundingRect.m_TopLeft,objectBoundingRect.m_BottomLeft); ::midpoint(m_MouseDownPoint,objectBoundingRect.m_TopRight,objectBoundingRect.m_BottomRight); m_fFixVertical = TRUE; break; case RSelection::kBottomResizeHandle : ::midpoint(selectionScalingCenter,selectionBoundingRect.m_TopLeft,selectionBoundingRect.m_TopRight); ::midpoint(m_ScalingCenter,objectBoundingRect.m_TopLeft,objectBoundingRect.m_TopRight); ::midpoint(m_MouseDownPoint,objectBoundingRect.m_BottomLeft,objectBoundingRect.m_BottomRight); m_fFixHorizontal = TRUE; break; default : TpsAssert( NULL, "Tracker is not resizing." ); } // Save the difference between the size of the selection and object rects m_RectDelta = selectionScalingCenter - m_ScalingCenter; // Determine if we should maintain aspect ratio or not. Ask the component what its default // behavior is, and invert that if the conrol key is down m_fMaintainAspectRatio = pHitObject->MaintainAspectRatioIsDefault( ); if( pHitObject->CanChangeDefaultAspect( ) && ( modifierKeys & kAspectModifier ) ) m_fMaintainAspectRatio = static_cast<BOOLEAN>( !m_fMaintainAspectRatio ); // If we are fixing either Vertical or Horizontal dimension, we can't be // maintaining aspect ratio if ( m_fFixVertical || m_fFixHorizontal ) m_fMaintainAspectRatio = FALSE; // Save the inverse transform of the object m_InverseTransform = objectBoundingRect.GetTransform( ); m_InverseTransform.Invert( ); // Call the base class RSelectionTracker::BeginTracking( mousePoint, modifierKeys ); }