// **************************************************************************** // // Function Name: RSingleSelection::DrawResizeTrackingRect( ) // // Description: Draws the selection tracking rect for resizing. // // Returns: Nothing // // Exceptions: Memory // // **************************************************************************** // void RSingleSelection::DrawResizeTrackingFeedback( RDrawingSurface& drawingSurface, const R2dTransform& transform, const RRealPoint& scalingCenter, const RRealSize& scaleFactor, BOOLEAN fMaintainAspectRatio ) const { if( m_pSelectedObject->GetComponentAttributes( ).IsResizable( ) ) { // Setup the drawing surface drawingSurface.SetPenWidth( kSelectionOutlineWidth ); drawingSurface.SetPenStyle( kSolidPen ); // Get the components bounding rect YComponentBoundingRect boundingRect = m_pSelectedObject->GetBoundingRect( ); // Constrain the scale factor RRealSize constrainedScaleFactor = m_pSelectedObject->ApplyResizeConstraint( scaleFactor ); // Dont force to maintain aspect ratio if it really doesnt want to fMaintainAspectRatio = fMaintainAspectRatio && ::AreFloatsEqual( constrainedScaleFactor.m_dx, constrainedScaleFactor.m_dy ); // Add the scale operation boundingRect.UnrotateAndScaleAboutPoint( scalingCenter, constrainedScaleFactor, m_pSelectedObject->GetMinimumSize( ), m_pSelectedObject->GetMaximumSize( ), fMaintainAspectRatio ); // Tell the object to draw tracking feedback m_pSelectedObject->RenderTrackingFeedback( drawingSurface, boundingRect.GetTransform( ) * transform, *GetView( ) ); } }
// **************************************************************************** // // Function Name: RSingleSelection::GetResizeTrackingFeedbackBoundingRect( ) // // Description: Gets the bounding rect of resize tracking feedback // // Returns: Bounding rect // // Exceptions: Memory // // **************************************************************************** // RRealRect RSingleSelection::GetResizeTrackingFeedbackBoundingRect( const R2dTransform& transform, const RRealPoint& scalingCenter, const RRealSize& scaleFactor, BOOLEAN fMaintainAspectRatio ) const { // Get the components bounding rect YComponentBoundingRect boundingRect = m_pSelectedObject->GetBoundingRect( ); // Constrain the scale factor RRealSize constrainedScaleFactor = m_pSelectedObject->ApplyResizeConstraint( scaleFactor ); // Dont force to maintain aspect ratio if it really doesnt want to fMaintainAspectRatio = fMaintainAspectRatio && ::AreFloatsEqual( constrainedScaleFactor.m_dx, constrainedScaleFactor.m_dy ); // Add the scale operation boundingRect.UnrotateAndScaleAboutPoint( scalingCenter, constrainedScaleFactor, m_pSelectedObject->GetMinimumSize( ), m_pSelectedObject->GetMaximumSize( ), fMaintainAspectRatio ); // Get the objects feedback size return m_pSelectedObject->GetTrackingFeedbackBoundingRect( boundingRect.GetTransform( ) * transform ); }
// **************************************************************************** // // Function Name: RCompositeSelection::SetResizeCursor( ) // // Description: Calculates which resize cursor to use, and sets it // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RCompositeSelection::SetResizeCursor( RSingleSelection* pHitObject, EHitLocation eHitLocation ) const { // Get the center point of the object YComponentBoundingRect boundingRect; pHitObject->GetObjectBoundingRect( boundingRect ); RRealPoint centerPoint = boundingRect.GetCenterPoint( ); // Create a new bounding rect that is a square. YComponentBoundingRect squareRect = boundingRect; RRealSize size = squareRect.WidthHeight( ); if( size.m_dx > size.m_dy ) squareRect.UnrotateAndScaleAboutPoint( centerPoint, RRealSize( size.m_dy / size.m_dx, 1.0 ) ); else squareRect.UnrotateAndScaleAboutPoint( centerPoint, RRealSize( 1.0, size.m_dx / size.m_dy ) ); // Select a point from this square based on the hit location RRealPoint point; switch( eHitLocation ) { case kLeftResizeHandle : ::midpoint( point, squareRect.m_TopLeft,squareRect.m_BottomLeft); break; case kTopResizeHandle : ::midpoint( point, squareRect.m_TopLeft,squareRect.m_TopRight); break; case kRightResizeHandle : ::midpoint( point, squareRect.m_TopRight,squareRect.m_BottomRight); break; case kBottomResizeHandle : ::midpoint( point, squareRect.m_BottomLeft,squareRect.m_BottomRight); break; case kTopLeftResizeHandle : point = squareRect.m_TopLeft; break; case kTopRightResizeHandle : point = squareRect.m_TopRight; break; case kBottomLeftResizeHandle : point = squareRect.m_BottomLeft; break; case kBottomRightResizeHandle : point = squareRect.m_BottomRight; break; default : TpsAssertAlways( "Invalid hit location in RCompositeSelection::SetResizeCursor( )." ); } // Calculate the angle between a vertical line through the square center and // a line connecting the calculatated point and the square center. YAngle angle = ::atan2( (YFloatType)( point.m_x - centerPoint.m_x ), (YFloatType)( centerPoint.m_y - point.m_y ) ); // atan2 returns an angle between PI and -PI. Convert this to an angle between 0 and 2PI if( angle < 0 ) angle += ( 2 * kPI ); // Select a cursor. We have 4 cursors to choose from, rotated in 45 degree // increments. Divide the angle by 45 deg. and use the resulting octant // number mod 4 to index into an array of cursor ids. int nOctant = ::Round( angle / ( kPI / 4 ) ); TpsAssert( nOctant >= 0 && nOctant <= 8, "Invalid octant." ); #ifdef _WINDOWS static LPCTSTR cursorArray[ 4 ] = { IDC_SIZENS, IDC_SIZENESW, IDC_SIZEWE, IDC_SIZENWSE }; #else // REVIEW: define cursors for Mac #endif // Set the cursor ::GetCursorManager( ).SetCursor( cursorArray[ nOctant % 4 ] ); }