// **************************************************************************** // // Function Name: RWindowView::RWindowView( ) // // Description: Render this views background // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::RenderBackground( RDrawingSurface& drawingSurface, const R2dTransform&, const RIntRect& rcRender ) const { // Fill in the background if( !drawingSurface.IsPrinting( ) ) { RColor backgroundColor = GetBackgroundColor( ); if ( backgroundColor.GetFillMethod() == RColor::kSolid ) { RSolidColor solid = backgroundColor.GetSolidColor( ); // Check for something close to TRUE GRAY and alter it slightly #ifdef _WINDOWS const YColorComponent kHitBits = 0xC0; const YColorComponent kNewColor = 0x77; const YColorComponent kGrayColor = 0x80; #elif defined( MAC ) const YColorComponent kHitBits = 0xF000; const YColorComponent kNewColor = 0x7777; const YColorComponent kGrayColor = 0x8000; #endif // _WINDOWS or MAC YColorComponent redColor = (solid.GetRed( ) & kHitBits); YColorComponent greenColor = (solid.GetGreen( ) & kHitBits); YColorComponent blueColor = (solid.GetBlue( ) & kHitBits); if ( (kGrayColor == redColor) && (redColor == greenColor) && (greenColor == blueColor) ) { backgroundColor = RSolidColor( kNewColor, kNewColor, kNewColor ); } } drawingSurface.SetForegroundMode( kNormal ); drawingSurface.SetFillColor( backgroundColor ); drawingSurface.FillRectangle( rcRender ); } }
// **************************************************************************** // // 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: RCompositeSelection::Render( ) // // Description: Draws the selection rect and handles // // Returns: Nothing // // Exceptions: Memory // // **************************************************************************** // void RCompositeSelection::Render( RDrawingSurface& drawingSurface, const R2dTransform& transform, const RIntRect& rcRender, BOOLEAN fRenderIfLocked ) const { // Only do if the selection is visible or we have a deferred render pending if( !m_fSelectionHidden && m_fSelectionVisible ) { // Dont bother rendering if there are no selected objects if( m_SelectionCollection.Count( ) != 0 ) { drawingSurface.RestoreDefaults( ); // Setup the drawing surface for rendering feedback RSolidColor color; YDrawMode drawMode; m_pView->GetFeedbackSettings( color, drawMode ); drawingSurface.SetForegroundMode( drawMode ); drawingSurface.SetPenColor( color ); drawingSurface.SetFillColor( color ); // Go through our selection collection and render each selection YSelectionCollectionIterator iterator = m_SelectionCollection.Start( ); for( ; iterator != m_SelectionCollection.End( ); ++iterator ) ( *iterator )->Render( drawingSurface, transform, rcRender, fRenderIfLocked ); } } }
// **************************************************************************** // // Function Name: RSingleSelection::DrawRotateHandle( ) // // Description: Draws the rotation line and handle // // Returns: Nothing // // Exceptions: Memory // // **************************************************************************** // void RSingleSelection::DrawRotateHandle( RDrawingSurface& drawingSurface, const R2dTransform& transform, const RIntRect& ) const { // Get the bounding rect YSelectionBoundingRect boundingRect; GetSelectionBoundingRect( boundingRect ); // Get the center point; this will be one end point of the rotate handle line RRealPoint centerPoint = boundingRect.GetCenterPoint( ); // Get the other end point RRealPoint lineEndPoint = GetRotateHandleCenterPoint( ); // Draw the line drawingSurface.MoveTo( centerPoint, transform ); drawingSurface.LineTo( lineEndPoint, transform ); // Now draw the rotate handle // Convert to device units ::LogicalUnitsToDeviceUnits( lineEndPoint, *m_pView ); // Now build the rotate handle, using this point as the middle of the left side RRealRect rotateHandleRect; rotateHandleRect.m_Left = lineEndPoint.m_x - ( kRotateHandleRenderSize / 2 ); rotateHandleRect.m_Top = lineEndPoint.m_y - ( kRotateHandleRenderSize / 2 ); rotateHandleRect.m_Right = lineEndPoint.m_x + ( kRotateHandleRenderSize / 2 ) + 1; rotateHandleRect.m_Bottom = lineEndPoint.m_y + ( kRotateHandleRenderSize / 2 ) + 1; ::DeviceUnitsToLogicalUnits( rotateHandleRect, *m_pView ); // Now draw the rotate handle rotateHandleRect *= transform; drawingSurface.FillRectangle( rotateHandleRect ); }
// **************************************************************************** // // Function Name: RRotateSelectionTracker::Render( ) // // Description: Called to render the tracker feedback // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RRotateSelectionTracker::Render( RDrawingSurface& drawingSurface, const R2dTransform& transform, const RRealPoint& point ) const { // Calculate the angle YAngle angle = CalcAngle( point ); // Draw the feedback line drawingSurface.MoveTo( m_TrackingRotationCenter, transform ); drawingSurface.LineTo( point, transform ); // Render the tracking rectangle m_pSelection->DrawRotateTrackingFeedback( drawingSurface, transform, m_TrackingRotationCenter, angle ); }
void RRotateDialog::RotateDisplay( int iPos ) { if ( iPos == m_iPrevPos ) return; // We need to use the RBitmap::Rotate() function, so to do that, convert to // Renaissance types. CClientDC clientDC( &m_staticDisplay ); HDC hClientDC = clientDC.GetSafeHdc(); RDcDrawingSurface drawSurface; drawSurface.Initialize( hClientDC, hClientDC ); R2dTransform transform; // Prepare the image on an offscreen DC RAutoDrawingSurface drawSurfaceOffscreen; RRealRect rRealStaticRect(m_rectStaticDisplay); BOOLEAN fPrepared = drawSurfaceOffscreen.Prepare( &drawSurface, transform, rRealStaticRect ); RDrawingSurface* pSurface = ( (fPrepared)? &drawSurfaceOffscreen : &drawSurface ); // Paint the offscreen DC white RColor rColor = RSolidColor( kWhite ); pSurface->SetFillColor( rColor ); pSurface->SetPenColor( rColor ); pSurface->FillRectangle( m_rectStaticDisplay ); YAngle flRadiansRotation = ::DegreesToRadians( YFloatType( iPos ) ); // The rotation leaves a black background, so blit with a mask. The mask // has to be created the same size as the original (not rotated) bitmap // size, so create it and then rotate it. RBitmapImage bmpRotated; RBitmapImage bmpMaskRotated; RImageLibrary rLibrary; rLibrary.Rotate( m_rBitmapImage, bmpRotated, bmpMaskRotated, flRadiansRotation ); RIntSize sizeBmpRotated; sizeBmpRotated.m_dx = bmpRotated.GetWidthInPixels(); sizeBmpRotated.m_dy = bmpRotated.GetHeightInPixels(); RIntRect rectSource; RIntRect rectDest; DeriveSourceAndDestinationRects( sizeBmpRotated, rectSource, rectDest ); bmpRotated.RenderWithMask( *pSurface, bmpMaskRotated, rectSource, rectDest ); if ( fPrepared ) drawSurfaceOffscreen.Release(); drawSurface.DetachDCs(); m_iPrevPos = iPos; }
// **************************************************************************** // // Function Name: RCompositeSelection::SetupRender( ) // // Description: Prepares the given drawing surface and transform for // rendering. // // Returns: Nothing // // Exceptions: Memory // // **************************************************************************** // void RCompositeSelection::SetupRender( RDrawingSurface& drawingSurface, R2dTransform& transform ) const { drawingSurface.RestoreDefaults( ); // Setup the drawing surface for rendering feedback RSolidColor color; YDrawMode drawMode; m_pView->GetFeedbackSettings( color, drawMode ); drawingSurface.SetForegroundMode( drawMode ); drawingSurface.SetPenColor( color ); drawingSurface.SetFillColor( color ); m_pView->GetViewTransform( transform, drawingSurface, TRUE ); // // We can't set the clipping here for the components could // lie outside of the view bounds //m_pView->SetClipRegion( drawingSurface, transform ); }
// **************************************************************************** // // Function Name: RView::SetClipRegion( ) // // Description: Creates a new clip region that is the intersection of the // current clip region and a region that will clip all output // to the bounds of this view // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RPathView::SetClipRegion( RDrawingSurface& drawingSurface, const R2dTransform& transform ) const { // Intersect our useable area RRealSize oneUnit( 1, 1 ); ::DeviceUnitsToLogicalUnits( oneUnit, drawingSurface ); RRealRect rect( GetUseableArea( !kInsetFrame ) ); rect.m_Right += oneUnit.m_dx; rect.m_Bottom += oneUnit.m_dy; drawingSurface.IntersectClipRect( rect, transform ); }
// **************************************************************************** // // Function Name: RSingleSelection::DrawDragTrackingRect( ) // // Description: Draws the selection tracking rect for dragging // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RSingleSelection::DrawDragTrackingFeedback( RDrawingSurface& drawingSurface, const R2dTransform& transform, const RRealSize& offset ) const { if( m_pSelectedObject->GetComponentAttributes( ).IsMovable( ) ) { // Setup the drawing surface drawingSurface.SetPenWidth( kSelectionOutlineWidth ); drawingSurface.SetPenStyle( kSolidPen ); // Get the components bounding rect YComponentBoundingRect boundingRect = m_pSelectedObject->GetBoundingRect( ); // Add the translate operation boundingRect.Offset( offset ); // Tell the object to draw tracking feedback m_pSelectedObject->RenderTrackingFeedback( drawingSurface, boundingRect.GetTransform( ) * transform, *GetView( ) ); } }
void RSingleSelection::DrawRotateTrackingFeedback( RDrawingSurface& drawingSurface, const R2dTransform& transform, const RRealPoint& rotationCenter, YAngle rotationAngle ) const { if( m_pSelectedObject->GetComponentAttributes( ).IsRotatable( ) ) { // Setup the drawing surface drawingSurface.SetPenWidth( kSelectionOutlineWidth ); drawingSurface.SetPenStyle( kSolidPen ); // Get the components bounding rect YComponentBoundingRect boundingRect = m_pSelectedObject->GetBoundingRect( ); // Add the rotate operation boundingRect.RotateAboutPoint( rotationCenter, rotationAngle ); // Tell the object to draw tracking feedback m_pSelectedObject->RenderTrackingFeedback( drawingSurface, boundingRect.GetTransform( ) * transform, *GetView( ) ); } }
// **************************************************************************** // // Function Name: RGpDrawingSurface::BlitDrawingSurface( ) // // Description: Copy from one the given drawing surface to this one // // Returns: Nothing // // Exceptions: None // // **************************************************************************** void RGpDrawingSurface::BlitDrawingSurface( const RDrawingSurface& rSrcDS, RIntRect rSrcRect, RIntRect rDestRect, EBlitMode eBlitMode ) { short mode; Rect srcRect, destRect; GrafPtr pSrcGrafPort, pDestGrafPort; GrafPtr savePort; RGBColor whiteColor, blackColor, foreColor, backColor; TpsAssertValid( this ); TpsAssertIsObject( RGpDrawingSurface, this ); TpsAssertIsObject(RGpDrawingSurface, &rSrcDS); pSrcGrafPort = (GrafPtr)rSrcDS.GetSurface(); pDestGrafPort = (GrafPtr)GetSurface(); TpsAssert( ( pSrcGrafPort != NULL ), "Source device is nil."); TpsAssert( ( pDestGrafPort != NULL ), "Destination device is nil."); // Set the port to the dest port GetPort(&savePort); SetPort(pDestGrafPort); switch ( eBlitMode ) { case kBlitSourceCopy : mode = srcCopy; break; case kBlitSourceAnd : mode = srcBic; break; case kBlitSourcePaint : mode = srcOr; break; case kBlitNotSourceAnd : mode = notSrcBic; break; case kBlitMergePaint : mode = notSrcOr; break; case kBlitSourceErase : default: TpsAssertAlways( "Invalid blit mode" ); break; } ::SetRect( &srcRect, rSrcRect.m_Left, rSrcRect.m_Top, rSrcRect.m_Right, rSrcRect.m_Bottom ); ::SetRect( &destRect, rDestRect.m_Left, rDestRect.m_Top, rDestRect.m_Right, rDestRect.m_Bottom ); ::GetBackColor( &backColor ); ::GetForeColor( &foreColor ); whiteColor.red = 0xFFFF; whiteColor.green = 0xFFFF; whiteColor.blue = 0xFFFF; blackColor.red = 0x0000; blackColor.green = 0x0000; blackColor.blue = 0x0000; ::RGBForeColor( &blackColor ); ::RGBBackColor( &whiteColor ); ::CopyBits( &(pSrcGrafPort->portBits), &(pDestGrafPort->portBits), &srcRect, &destRect, mode, nil ); ::RGBForeColor( &foreColor ); ::RGBBackColor( &backColor ); // Restore the saved port SetPort(savePort); }
// **************************************************************************** // // Function Name: RSingleSelection::Render( ) // // Description: Draws the selection rect and handles // // Returns: Nothing // // Exceptions: Memory // // **************************************************************************** // void RSingleSelection::Render( RDrawingSurface& drawingSurface, const R2dTransform& transform, const RIntRect& rcRender, BOOLEAN fRenderIfLocked ) const { // Get the component attributes const RComponentAttributes& componentAttributes = m_pSelectedObject->GetComponentAttributes( ); BOOLEAN fIsLocked = componentAttributes.IsLocked( ); if( fRenderIfLocked || !fIsLocked ) { // Set surface attributes drawingSurface.SetPenWidth( kSelectionOutlineWidth ); drawingSurface.SetPenStyle( kSolidPen ); RRealRect resizeHandleRect; // Draw the resize handles if( componentAttributes.IsResizable( FALSE ) ) { RArray<RRealRect> rectList; RRealSize scaleFactor( kDummyScale, kDummyScale ); scaleFactor = m_pSelectedObject->ApplyResizeConstraint( scaleFactor ); GetResizeSelectionHandle( resizeHandleRect, transform, kTopLeftResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); GetResizeSelectionHandle( resizeHandleRect, transform, kTopRightResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); GetResizeSelectionHandle( resizeHandleRect, transform, kBottomRightResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); GetResizeSelectionHandle( resizeHandleRect, transform, kBottomLeftResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); if ( !AreFloatsEqual( scaleFactor.m_dy, kConstrainedScale ) ) { GetResizeSelectionHandle( resizeHandleRect, transform, kBottomResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); GetResizeSelectionHandle( resizeHandleRect, transform, kTopResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); } if ( !AreFloatsEqual( scaleFactor.m_dx, kConstrainedScale ) ) { GetResizeSelectionHandle( resizeHandleRect, transform, kRightResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); GetResizeSelectionHandle( resizeHandleRect, transform, kLeftResizeHandle, TRUE ); rectList.InsertAtEnd( resizeHandleRect ); } RArray<RRealRect>::YIterator iterator = rectList.Start( ); RArray<RRealRect>::YIterator iteratorEnd = rectList.End( ); if( fIsLocked ) { while ( iterator != iteratorEnd ) drawingSurface.FrameRectangle( *iterator++ ); } else { while ( iterator != iteratorEnd ) drawingSurface.FillRectangle( *iterator++ ); } } // Draw the rotate line and handle if( componentAttributes.IsRotatable( ) ) DrawRotateHandle( drawingSurface, transform, rcRender ); // Draw the selection frame m_pSelectedObject->DrawSelectionFrame( drawingSurface, transform ); } }