// **************************************************************************** // // Function Name: RSingleSelection::SelectionRectFromDeviceObjectRect( ) // // Description: Converts the given bounding rect to a selection rect // by inflating // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RSingleSelection::SelectionRectFromDeviceObjectRect( YComponentBoundingRect& objectBoundingRect, BOOLEAN fOutset ) { // Dont bother if the rect is too small if( objectBoundingRect.IsEmpty( ) ) return; // If Outsetting, inflate the rect. Otherwise, deflate the rect if( fOutset == TRUE ) objectBoundingRect.Inflate( RRealSize( (kSelectionOutlineWidth+kSelectionOutlineDistanceFromObject)/2.F, (kSelectionOutlineWidth+kSelectionOutlineDistanceFromObject)/2.F ) ); else objectBoundingRect.Inflate( RRealSize( -( kSelectionOutlineWidth+kSelectionOutlineDistanceFromObject ), -( kSelectionOutlineWidth+kSelectionOutlineDistanceFromObject ) ) ); }
// **************************************************************************** // // Function Name: RWindowView::InvalidateVectorRect( ) // // Description: Invalidates the given vector rect in this view // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::InvalidateVectorRect( const RRealVectorRect& rect, BOOLEAN fErase ) { // // Only invalidate if we have a CWnd if( !GetCWnd() ) return; // Get the bounding rect... RRealRect temp = rect.m_TransformedBoundingRect; // Get our transformation... R2dTransform transform; ApplyTransform( transform, FALSE, FALSE ); // Apply it to our bounds... temp *= transform; // Convert the bounds to device units ::LogicalUnitsToDeviceUnits( temp, *this ); // guard for roundoff... const YRealDimension kRoundOffGuard = 2.0; temp.Inflate( RRealSize( kRoundOffGuard, kRoundOffGuard ) ); // Put it in a CRect and do the invalidate CRect crect( ::Round(temp.m_Left), ::Round(temp.m_Top), ::Round(temp.m_Right), ::Round(temp.m_Bottom) ); GetCWnd( ).InvalidateRect( crect, fErase ); }
// **************************************************************************** // // 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: RWindowView::OnVScroll( ) // // Description: Called to do vertical scrolling // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::OnVScroll( UINT nSBCode, int nPos ) { YIntDimension scrollAmount = OnScroll( m_pVerticalScrollBar, nSBCode, nPos ); ScrollWindow( RRealSize( 0, scrollAmount ) ); }
// **************************************************************************** // // Function Name: RWindowView::OnHScroll( ) // // Description: Called to do horizontal scrolling // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::OnHScroll( UINT nSBCode, int nPos ) { YIntDimension scrollAmount = OnScroll( m_pHorizontalScrollBar, nSBCode, nPos ); ScrollWindow( RRealSize( scrollAmount, 0 ) ); }
// **************************************************************************** // // Function Name: RWindowView::GetScreenDPI( ) // // Description: Accessor // // Returns: The DPI of the screen // // Exceptions: None // // **************************************************************************** // RRealSize RWindowView::GetDPI( ) const { return RRealSize( m_ScreenDPI.m_dx, m_ScreenDPI.m_dy ); }
// **************************************************************************** // // 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 ] ); }
// **************************************************************************** // // Function Name: RPsd3RuledLineGraphic::RenderRails() // // Description: Draws the rails of the Ruled Line // // Returns: Nothing // // Exceptions: None // // **************************************************************************** void RPsd3RuledLineGraphic::RenderRails(RDrawingSurface* pDS, RPath* pPath, const RRealSize& rLineSize, const R2dTransform& rTransform, const RIntRect& rRender, const RColor& rMonoColor) const { // Make sure we have a rail (is this necessary?) if ( !m_pRail ) return; // Compute the inverse of the transform R2dTransform invTransform( rTransform ); invTransform.Invert( ); YRealDimension xScale; YRealDimension yScale; YAngle rotation; rTransform.Decompose( rotation, xScale, yScale ); // Compute the size of the right and left caps respectively (if they exist) YRealDimension leftCapSize = (m_pLeftCap!=NULL)? rLineSize.m_dy * m_pLeftCap->GetAspectRatio( ) : 0.0; YRealDimension rightCapSize = (m_pRightCap!=NULL)? rLineSize.m_dy * m_pRightCap->GetAspectRatio( ) : ((m_fMirrorCaps)? leftCapSize : 0.0 ); YRealDimension halfLine = rLineSize.m_dx / 2.0; if ( leftCapSize > halfLine ) leftCapSize = halfLine; if ( rightCapSize > halfLine) rightCapSize = halfLine; // Count the number of rails needed YRealDimension yVariableLength( rLineSize.m_dx - leftCapSize - rightCapSize ); YRealDimension yNominalXDimension( rLineSize.m_dy * m_pRail->GetAspectRatio() ); sLONG sRailCount = ::GetRailCount(yVariableLength, yNominalXDimension ); // // If no rails are needed, we are done if (sRailCount == 0) return; // Compute the new rail sizes (the small and large ones) RRealSize smallRailSize( yVariableLength / (YFloatType)sRailCount, rLineSize.m_dy ); smallRailSize *= rTransform; smallRailSize = RRealSize( floor( smallRailSize.m_dx ), floor( smallRailSize.m_dy ) ); RRealSize largeRailSize( smallRailSize.m_dx+1.0, smallRailSize.m_dy+1.0 ); // // Re-expand to logical units smallRailSize *= invTransform; largeRailSize *= invTransform; // // Reset the y dimension smallRailSize.m_dy = largeRailSize.m_dy = rLineSize.m_dy; // What is the excess YIntDimension smallSize = sRailCount; YIntDimension increment = static_cast<YIntDimension>( (yVariableLength - (smallRailSize.m_dx * sRailCount)) * xScale) + 1; YRealDimension xStartOffset = 0.0; YIntDimension excessCounter = 0; TpsAssert( smallSize>=0, "Extra space is negative" ); if (m_pLeftCap) xStartOffset += leftCapSize; RRealSize rRailSize( rLineSize ); for (int nRail = 0; nRail < sRailCount-1; ++nRail) { // Create a transform and offset it to the proper location R2dTransform renderTransform( rTransform ); renderTransform.PreTranslate( xStartOffset, 0 ); // Add the extra to the excessCounter excessCounter += increment; if ( excessCounter >= smallSize ) { rRailSize = largeRailSize;//smallRailSize; excessCounter -= smallSize; } else rRailSize = smallRailSize;//largeRailSize; if (pDS) m_pRail->Render(*pDS, rRailSize, renderTransform, rRender, rMonoColor); if (pPath) m_pRail->GetOutlinePath(*pPath, rRailSize, renderTransform); xStartOffset += rRailSize.m_dx; } // Render the last rail, but make sure it is large enough R2dTransform tmpTransform( rTransform ); tmpTransform.PreTranslate( xStartOffset, 0 ); rRailSize.m_dx = yVariableLength + leftCapSize - xStartOffset; if (pDS) m_pRail->Render(*pDS, rRailSize, tmpTransform, rRender, rMonoColor); if (pPath) m_pRail->GetOutlinePath(*pPath, rRailSize, tmpTransform); }
// **************************************************************************** // // Function Name: RSingleSelection::GetResizeSelectionHandle( ) // // Description: Retrieves a vector rect representing requested resize handle. // // Returns: Nothing // // Exceptions: Memory // // **************************************************************************** // void RSingleSelection::GetResizeSelectionHandle( RRealRect& rHandle, const R2dTransform& transform, EHitLocation eHit, BOOLEAN fRender ) const { RRealPoint point; YSelectionBoundingRect boundingRect; RIntSize outsetSize = (fRender)? RRealSize( kCornerResizeHandleRenderSize, kCornerResizeHandleRenderSize ) : RRealSize( kResizeHandleHitSize, kResizeHandleHitSize ); // Get the bounding rectangle GetSelectionBoundingRect( boundingRect ); // Get the proper point to transform switch ( eHit ) { case kLeftResizeHandle: ::midpoint( point, boundingRect.m_TopLeft, boundingRect.m_BottomLeft ); outsetSize.m_dx = Max( kEdgeResizeHandleRenderSize, YIntDimension(outsetSize.m_dx/2) ); break; case kTopResizeHandle: ::midpoint( point, boundingRect.m_TopLeft, boundingRect.m_TopRight ); outsetSize.m_dy = Max( kEdgeResizeHandleRenderSize, YIntDimension(outsetSize.m_dy/2) ); break; case kRightResizeHandle: ::midpoint( point, boundingRect.m_TopRight, boundingRect.m_BottomRight ); outsetSize.m_dx = Max( kEdgeResizeHandleRenderSize, YIntDimension(outsetSize.m_dx/2) ); break; case kBottomResizeHandle: ::midpoint( point, boundingRect.m_BottomLeft, boundingRect.m_BottomRight ); outsetSize.m_dy = Max( kEdgeResizeHandleRenderSize, YIntDimension(outsetSize.m_dy/2) ); break; case kTopLeftResizeHandle: point = boundingRect.m_TopLeft; break; case kTopRightResizeHandle: point = boundingRect.m_TopRight; break; case kBottomLeftResizeHandle: point = boundingRect.m_BottomLeft; break; case kBottomRightResizeHandle: point = boundingRect.m_BottomRight; break; default : TpsAssertAlways( "Asking for the selection handle of invalid type" ); point = boundingRect.GetCenterPoint(); } RIntSize halfOutset( outsetSize.m_dx/2, outsetSize.m_dy/2); ::LogicalUnitsToDeviceUnits( point, *m_pView ); rHandle.m_Left = point.m_x - halfOutset.m_dx; rHandle.m_Top = point.m_y - halfOutset.m_dy; rHandle.m_Right = point.m_x + outsetSize.m_dx - halfOutset.m_dx; rHandle.m_Bottom = point.m_y + outsetSize.m_dy - halfOutset.m_dy; ::DeviceUnitsToLogicalUnits( rHandle, *m_pView ); rHandle *= transform; }