コード例 #1
0
void	RRotateDialog::DeriveSourceAndDestinationRects( const RIntSize& sizeBmpRotated, RIntRect& rectSource, RIntRect& rectDest )
{
	rectSource.m_Left		= 0;
	rectSource.m_Top		= 0;
	rectSource.m_Right	= sizeBmpRotated.m_dx;
	rectSource.m_Bottom	= sizeBmpRotated.m_dy;

	RIntPoint	ptSourceCenter;
	ptSourceCenter.m_x	= sizeBmpRotated.m_dx / 2;
	ptSourceCenter.m_y	= sizeBmpRotated.m_dy / 2;

	rectDest					= rectSource;

	YFloatType flHorzCropFactor = 1.F;
	YFloatType flVertCropFactor = 1.F;

	if ( sizeBmpRotated.m_dx > m_rSizeStaticDisplay.m_dx )
	{
		flHorzCropFactor	= 1.F - YFloatType( sizeBmpRotated.m_dx - m_rSizeStaticDisplay.m_dx ) / YFloatType( sizeBmpRotated.m_dx );
		rectDest.m_Right	= YIntCoordinate( YFloatType( rectDest.m_Right ) * flHorzCropFactor ); 
	}

	if ( sizeBmpRotated.m_dy > m_rSizeStaticDisplay.m_dy )
	{
		flVertCropFactor	= 1.F - YFloatType( sizeBmpRotated.m_dy - m_rSizeStaticDisplay.m_dy ) / YFloatType( sizeBmpRotated.m_dy );
		rectDest.m_Bottom	= YIntCoordinate( YFloatType( rectDest.m_Bottom ) * flVertCropFactor );
	}

	rectDest.Offset( RIntSize(  
		m_rPtStaticCenter.m_x - YIntCoordinate( YFloatType( rectDest.Width() )  / 2.F ),
		m_rPtStaticCenter.m_y - YIntCoordinate( YFloatType( rectDest.Height() ) / 2.F ) )
	);

	if ( flHorzCropFactor < 1.F )
	{
		YIntDimension iHorzSrcCropDistance = YIntDimension( ( 1.F - flHorzCropFactor ) * YFloatType( rectSource.m_Right ) / 2.F );
		rectSource.m_Left		+= iHorzSrcCropDistance;
		rectSource.m_Right	-= iHorzSrcCropDistance;
	}

	if ( flVertCropFactor < 1.F )
	{
		YIntDimension iVertSrcCropDistance = YIntDimension( ( 1.F - flVertCropFactor ) * YFloatType( rectSource.m_Bottom ) / 2.F );
		rectSource.m_Top		+= iVertSrcCropDistance;
		rectSource.m_Bottom	-= iVertSrcCropDistance;
	}
}
コード例 #2
0
BOOL RRotateDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();

	TpsAssert( ( m_iRotation >= kMinRotation ) && ( m_iRotation <= kMaxRotation ), 
		"m_iRotation out of range" );
	
	m_spinRotate.SetRange( kMinRotation, kMaxRotation );
	m_spinRotate.SetPos( m_iRotation );
	
	m_rBitmapImage.Initialize((YImageHandle) GetResourceManager().GetResourceBitmap( YResourceId( BITMAP_NO_FRAME ) ) );

	m_sizeBmpImage.m_dx	= m_rBitmapImage.GetWidthInPixels();
	m_sizeBmpImage.m_dy	= m_rBitmapImage.GetHeightInPixels();

	CRect	rcStaticDisplay;
	m_staticDisplay.GetClientRect( &rcStaticDisplay );

	m_rectStaticDisplay.m_Left		= rcStaticDisplay.left;
	m_rectStaticDisplay.m_Top		= rcStaticDisplay.top;
	m_rectStaticDisplay.m_Right	= rcStaticDisplay.right;
	m_rectStaticDisplay.m_Bottom	= rcStaticDisplay.bottom;

	m_rSizeStaticDisplay	= RIntSize( m_rectStaticDisplay.Width(), m_rectStaticDisplay.Height() );
	m_rPtStaticCenter		= m_rectStaticDisplay.GetCenterPoint();

	// Create the rotate control
	CRect rectPlaceholder;
	m_rotatePlaceholder.GetWindowRect( rectPlaceholder );
	ScreenToClient(rectPlaceholder);
	m_dialRotate.Create(NULL, "", WS_CHILD | WS_VISIBLE, rectPlaceholder, this, (UINT)-1);

	m_bInitialised = TRUE;

	m_uTimerID = SetTimer( (UINT) kTimerID, kMinUpdateInterval, NULL );

	if ( m_uTimerID == 0 )
	{
		EndDialog( IDCANCEL );
		throw kResource;
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
コード例 #3
0
//////////////////////////////////////////////////////////////////////////////
//
//	void ExportGraphicComponent( RComponentView* pComponentView, RMBCString *pInitialDir ) 
//
//	export a graphic to file from a component view
//
//////////////////////////////////////////////////////////////////////////////
void ExportGraphicComponent( RComponentView* pComponentView, RMBCString *pInitialDir /*=NULL*/) 
{
	RImageLibrary rLibrary ;
	CArray<int, int> arrFileFormats ;

	//
	// Build the export file filter list...
	//
	CString strFilter, str ;

	for (int i = 0; i < kNumFormats - 1; i++)
	{
		if (rLibrary.IsFormatSupported( (EImageFormat) kImageExportFilters[i][0] ))
		{
			str.LoadString( kImageExportFilters[i][1] ) ;
			strFilter += str ;

			arrFileFormats.Add( kImageExportFilters[i][0] ) ;
		}
	}

	TpsAssert( kImageExportFilters[i][0] == kImageFormatXRX, "Invalid export format!" ) ;
	str.LoadString( kImageExportFilters[i][1] ) ;  
	strFilter += str ;
	strFilter += "|" ;

	arrFileFormats.Add( kImageExportFilters[i][0] ) ;

	//
	// Create and execute the dialog...
	//
	RExportGraphicDlg dlg( pComponentView, strFilter ) ;

	// Load in the dialog title string
	CString strTitle ;
	strTitle.LoadString( STRING_EXPORT_IMAGE_DIALOG_TITLE ) ;
	dlg.m_ofn.lpstrTitle = (LPCTSTR) strTitle ;
	if( pInitialDir )
	{
		dlg.m_ofn.lpstrInitialDir = (LPCTSTR)*pInitialDir;
	}

	if (IDOK == dlg.DoModal())
	{
		RMBCString   strPathName = dlg.GetPathName() ;
		RIntSize     szImageSize = dlg.GetSize() ;

		_nFilterIndex = dlg.m_ofn.nFilterIndex ;
		EImageFormat eFormat = (EImageFormat) arrFileFormats[dlg.m_ofn.nFilterIndex - 1] ;
		RRealSize pictureSize  = pComponentView->GetReferenceSize() ;

		try
		{
			if (kImageFormatXRX == eFormat)
			{
				RRealSize outputSize( szImageSize.m_dx, szImageSize.m_dy ) ; //   = pictureSize ;
				RRealSize screenDPI    = ::GetScreenDPI() ;

				RVectorImage vectorImage ;
				vectorImage.SetSuggestedWidthInInches( ::PixelsToInches( outputSize.m_dx, (uLONG) screenDPI.m_dx ) ) ;
				vectorImage.SetSuggestedHeightInInches( ::PixelsToInches( outputSize.m_dy, (uLONG) screenDPI.m_dy ) ) ;

				// Create an offscreen drawing surface and set the picture
				ROffscreenDrawingSurface drawingSurface;
				drawingSurface.SetImage( &vectorImage );

				R2dTransform transform ;

				// Scale to the device DPI
				RRealSize deviceDPI = drawingSurface.GetDPI( );
				transform.PreScale( (YFloatType) deviceDPI.m_dx / screenDPI.m_dy, 
					(YFloatType) deviceDPI.m_dy / screenDPI.m_dy );

				transform.PreScale( 
					outputSize.m_dx / pictureSize.m_dx,
					outputSize.m_dy / pictureSize.m_dy ) ;

				// Render the component
				RRealRect outputRect( pictureSize ) ;
				pComponentView->Render( drawingSurface, transform, outputRect ) ;

				drawingSurface.ReleaseImage( );

				rLibrary.ExportImage( vectorImage, strPathName, kImageFormatXRX ) ;
				if (rLibrary.GetLastException() != kNoError)
				{
					throw rLibrary.GetLastException() ;
				}
			} // if (XRX)
			else
			{
				// Check for a image interface
				RImageInterface* pInterface = (RImageInterface *) 
					pComponentView->GetInterface( kImageInterfaceId ) ;

				if (pInterface)
				{
					pInterface->Export( strPathName, eFormat ) ;
					delete pInterface ;
				}
				else
				{
					// Initialize the new bitmap at a bit depth of 24
					RBitmapImage image ;
					image.Initialize( szImageSize.m_dx, szImageSize.m_dy, 24 ) ;

					ROffscreenDrawingSurface dsMem ; 
					dsMem.SetImage( &image ) ;

					R2dTransform transform ;
					transform.PreScale( 
						szImageSize.m_dx / pictureSize.m_dx,
						szImageSize.m_dy / pictureSize.m_dy ) ;

					// Render the component
					dsMem.SetFillColor( RSolidColor( kWhite ) ) ;
					dsMem.FillRectangle( RRealRect( pictureSize ), transform ) ;
					pComponentView->Render( dsMem, transform, RIntRect( 
						RIntSize( pictureSize.m_dx, pictureSize.m_dy ) ) ) ;

					dsMem.ReleaseImage() ;
					
					rLibrary.ExportImage( image, strPathName, eFormat ) ;
				}

				if (rLibrary.GetLastException() != kNoError)
				{
					throw rLibrary.GetLastException() ;
				}
			
			} // else

		} // try

		catch( YException e)
		{
			ReportException( e ) ;
		}

	} // if (IDOK)
}
コード例 #4
0
void RWinColorPalette::OnPaint( )
{
	CPaintDC dc( this );
	RDcDrawingSurface ds;
	ds.Initialize( (HDC) dc ) ;

	CRect rcWindow;
	GetClientRect( rcWindow );
	RIntRect rcClient( rcWindow );

	RBitmapImage&	biPalette	= GetPaletteBitmapImage();
	biPalette.LockImage( );
	biPalette.Render( ds, rcClient );
	biPalette.UnlockImage( );
	ds.DetachDCs();

	CClientDC dcClient( this );
	ds.Initialize( (HDC) dcClient ) ;

	RColor crOldFill = ds.GetFillColor();
	RColor crOldPen  = ds.GetPenColor();

	if (m_ptSelected.m_x >= 0 && m_ptSelected.m_y >= 0)
	{
		//
		// Draw selected cell

		RIntRect rcSelected( 
			m_ptSelected.m_x + 1,
			m_ptSelected.m_y + 1,
			m_ptSelected.m_x + kCellSize.m_dx - 1,
			m_ptSelected.m_y + kCellSize.m_dy - 1 );

		RSolidColor crBlack( kBlack );
		RSolidColor crHilight( GetSysColor( COLOR_BTNHILIGHT ) );
		ds.Draw3dRect( rcSelected, crBlack, crHilight );

		RSolidColor crShadow( GetSysColor( COLOR_BTNSHADOW ) );
		rcSelected.m_Top -= 1; rcSelected.m_Left -= 1;
		ds.Draw3dRect( rcSelected, crShadow, crHilight );

		if (GetFocus() == this)
		{
			RSolidColor rSolid = GetSysColor( COLOR_HIGHLIGHT );
			RColor rSelected( rSolid );

			rcSelected.Inflate( RIntSize( 1, 1 ), RIntSize( 2, 2 ) );
			ds.SetPenColor( RColor( rSelected ) );
			ds.FrameRectangle( rcSelected );
		}
	}

	if (m_crHilited != (COLORREF) -1L)
	{
		// Draw color chip
		m_rcColorChip = RIntRect( 
			m_ptHilited.m_x,
			m_ptHilited.m_y,
			m_ptHilited.m_x + 2 * kCellSize.m_dx,
			m_ptHilited.m_y + 2 * kCellSize.m_dy );

		YIntDimension xOffset( 2 * kCellSize.m_dx );
		YIntDimension yOffset( 2 * kCellSize.m_dy );

		if (m_rcColorChip.m_Right + xOffset > rcWindow.right)
		{
			xOffset = -3 * kCellSize.m_dx;
		}

		if (m_rcColorChip.m_Bottom + yOffset > rcWindow.bottom)
		{
			yOffset = -3 * kCellSize.m_dy;
		}

		m_rcColorChip.Offset( RIntSize( xOffset, yOffset ) );

		RColor crFill = RSolidColor( m_crHilited );
		RColor crPen = RSolidColor( kWhite );

		ds.SetPenColor( crPen );
		ds.SetFillColor( crFill );
		ds.FillRectangle( m_rcColorChip );
		ds.FrameRectangle( m_rcColorChip );
	}
	else
	{
		m_rcColorChip = RIntRect( 0, 0, 1, 1 );
	}

	ds.SetPenColor( crOldPen );
	ds.SetFillColor( crOldFill );
	ds.DetachDCs();
}
コード例 #5
0
RBitmapImage&	RWinColorPalette::GetPaletteBitmapImage( )
{
	static BOOLEAN			m_fPaletteInitialized = FALSE;
	static RBitmapImage	m_biPalette;

	if ( !m_fPaletteInitialized )
	{
		// find the resource in the resource file
		HRSRC hRsrc = FindResource( AfxGetResourceHandle(), 
			MAKEINTRESOURCE( m_uPaletteBitmapID ), RT_BITMAP );

		if ( hRsrc != NULL )
		{
			// get a handle to the resource data
			HGLOBAL hTemp = LoadResource( AfxGetResourceHandle(), hRsrc );

			if ( hTemp != NULL )
			{
				// Initlize the palette bitmap with the resource data
				m_biPalette.Initialize( LockResource( hTemp ) );

				// unlock and free the resource
				UnlockResource( hTemp );
				FreeResource( hTemp );
			}
			else
				AfxThrowResourceException( );
		}
		else
			AfxThrowResourceException( );

		m_fPaletteInitialized = TRUE;

		COLORMAP crColorMap[] =
		{
			{ RGB( 255, 255, 255 ), GetSysColor( COLOR_BTNHIGHLIGHT ) },
			{ RGB( 192, 192, 192 ), GetSysColor( COLOR_BTNFACE )      },
			{ RGB( 128, 128, 128 ), GetSysColor( COLOR_BTNSHADOW )    }
		};

		RIntPoint ptCells[] = 
		{
			FindColor( crColorMap[0].from ),
			FindColor( crColorMap[1].from ),
			FindColor( crColorMap[2].from )
		};

		void*     pRawData   = m_biPalette.GetRawData();
		RGBQUAD*  pColorData = (RGBQUAD *) RBitmapImage::GetColorData( pRawData );
		LPBYTE    pImageData = (LPBYTE) RBitmapImage::GetImageData( pRawData );

		for (int j = 0; (LPVOID) pColorData < (LPVOID) pImageData; j++, pColorData++)
		{
			for (int i = 0; i < NumElements( crColorMap ); i++)
			{
				if (crColorMap[i].from == RGB( pColorData->rgbRed, pColorData->rgbGreen, pColorData->rgbBlue ))
				{
					pColorData->rgbBlue  = GetBValue( crColorMap[i].to );
					pColorData->rgbRed   = GetRValue( crColorMap[i].to );
					pColorData->rgbGreen = GetGValue( crColorMap[i].to );
					pColorData->rgbReserved = 0;
				}
			}

			if (j == 9)
			{
				// We only need to look at the system colors, so
				// jump to the last 10 entries in the palette.
				pColorData += 235;
			}
		}

		m_biPalette.UpdatePalette();

		//
		// Relace the cells that got remapped
		//
		ROffscreenDrawingSurface dsMem;
		dsMem.SetImage( &m_biPalette );

		RSolidColor rSolid;

		for (int i = 0; i < NumElements( ptCells ); i++)
		{
			if (ptCells[i].m_x >= 0 && ptCells[i].m_y >= 0)
			{
				RIntRect rcCell( RIntSize( kCellSize.m_dx - 2, kCellSize.m_dy - 2 ) );
				rcCell.Offset( RIntSize( ptCells[i].m_x + 1, ptCells[i].m_y + 1 ) );

				rSolid = crColorMap[i].from;

				RColor rColor( rSolid );
				dsMem.SetFillColor( rColor );
				dsMem.FillRectangle( rcCell );
			}
		}

		dsMem.ReleaseImage();
	}

	return m_biPalette;
}
コード例 #6
0
//@mFunc draws the listbox items in their proper state
void CQSLItemList::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);

	QSLItemData itemData;
	GetItemData( lpDrawItemStruct->itemID, itemData );
	
#ifdef USECACHE
	RImage* pImage = GetCachedBitmap( lpDrawItemStruct->itemID ) ;
#else
	RImage* pImage = itemData.GetImage();

	if (!itemData.m_pImage)
	{
		itemData.m_pImage = pImage;
		SetItemData( lpDrawItemStruct->itemID, itemData );
	}

//	HBITMAP hBitmap = itemData.m_hBitmap ;
//	HPALETTE hPalette = itemData.m_hPalette ;
	
//	if (!itemData.m_pImage)
//	{
//		hBitmap = itemData.m_hBitmap = 
//			LoadBitmapPreview( lpDrawItemStruct->itemID, &itemData.m_hPalette ) ;
//		hPalette = itemData.m_hPalette;
//
//		// Save the new data into the control
//		SetItemData( lpDrawItemStruct->itemID, itemData );
//	}
//
//	// If we have a palette with the bitmap, realize it into the DC prior to painting.
//	if (hPalette != NULL)
//	{
//		CPalette palBitmap;
//		palBitmap.Attach( hPalette );
//		CPalette *pOldPal = pDC->SelectPalette( &palBitmap, TRUE );
//		pDC->RealizePalette();
//		pDC->SelectPalette( pOldPal, TRUE );
//		palBitmap.Detach();
//	}
#endif

	BITMAP  bm= { 0, 0, 0, 0, 0, 0, NULL };
	HBITMAP hBitmap = NULL;
	
	if (pImage)
	{
		hBitmap = (HBITMAP) pImage->GetSystemHandle();
		::GetObject( hBitmap, sizeof( bm ), &bm );
	}

	// Determine colors to use for drawing text and selection
	//
	COLORREF crFillColor = GetSysColor( COLOR_WINDOW ) ;
	COLORREF crTextColor = GetSysColor( COLOR_WINDOWTEXT ) ;

	if (lpDrawItemStruct->itemState & ODS_SELECTED)
	{
		crFillColor = GetSysColor( COLOR_HIGHLIGHT ) ;
		crTextColor = GetSysColor( COLOR_HIGHLIGHTTEXT ) ;
	}

	// Handle drawing according to action
	//

	// Setup DC
	COLORREF oldTextColor = pDC->SetTextColor( crTextColor );
	COLORREF oldBkColor   = pDC->SetBkColor( crFillColor );
	CFont* pOldFont = pDC->SelectObject( GetParent()->GetFont() );

	// Determine location to draw bitmap.  This information 
	// is needed for all drawing modes, so might as well
	// just determine it once, and in one place.
	CSize	  szExtent = pDC->GetTextExtent( itemData.m_strDesc );

	RIntRect  cellRect( lpDrawItemStruct->rcItem );
	cellRect.Inset( RIntSize( 4, 4 ) );
	cellRect.m_Bottom -= szExtent.cy + 2; // + 2 is for spacing between graphic & text

	RIntRect  imgRect( 0, 0, bm.bmWidth - 1, bm.bmHeight - 1 );
	imgRect.ShrinkToFit( cellRect );
	imgRect.CenterRectInRect( cellRect );

	CSize  szImage( imgRect.Width(), imgRect.Height() );
//	CPoint centerPt( cellRect.CenterPoint() );
//	CPoint ptTopLeft( centerPt.x - szImage.cx / 2, centerPt.y - szImage.cy / 2 - 2 );

	switch (lpDrawItemStruct->itemAction)
	{
	case ODA_DRAWENTIRE:
		{
		CDC memDC;
		memDC.CreateCompatibleDC( pDC );

		// Get the bitmap
		CBitmap* pBmp    = CBitmap::FromHandle( hBitmap );
		CBitmap* pOldBmp = memDC.SelectObject( pBmp );

		pDC->StretchBlt( imgRect.m_Left, imgRect.m_Top, imgRect.Width(), imgRect.Height(), 
			&memDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY );

		memDC.SelectObject( pOldBmp );

		if (!(lpDrawItemStruct->itemState & ODS_SELECTED))
		{
			break ;
		}

		// Fall through
		}

	case ODA_SELECT:
		{
		// Draw/Clear the highlight rect
//		CRect bmpRect( ptTopLeft.x, ptTopLeft.y, ptTopLeft.x + bm.bmWidth, ptTopLeft.y + bm.bmHeight);
		
		CRect bmpRect( imgRect );
		bmpRect.InflateRect( 2, 2 );

		CPen pen( PS_SOLID, 2, crFillColor );
		CPen* pOldPen = pDC->SelectObject( &pen );

		pDC->MoveTo( bmpRect.left, bmpRect.top );
		pDC->LineTo( bmpRect.right, bmpRect.top );
		pDC->LineTo( bmpRect.right, bmpRect.bottom );
		pDC->LineTo( bmpRect.left, bmpRect.bottom );
		pDC->LineTo( bmpRect.left, bmpRect.top );
		pDC->SelectObject( pOldPen );
		}

	} // switch

	// Draw the text
	CPoint ptText( cellRect.m_Left + (cellRect.Width() - szExtent.cx) / 2, cellRect.m_Bottom + 4 );
	pDC->TextOut( ptText.x, ptText.y, itemData.m_strDesc );

//	pDC->DrawText( itemData.m_strDesc, &textRect, DT_CALCRECT | DT_SINGLELINE  );
//	textRect.OffsetRect( -textRect.Width() / 2, 2 );
//	pDC->DrawText( itemData.m_strDesc, &textRect, DT_CENTER | DT_VCENTER );

	// restore DC
	pDC->SelectObject( pOldFont );
	pDC->SetTextColor( oldTextColor );
	pDC->SetBkColor( oldBkColor );
}
コード例 #7
0
// ****************************************************************************
//
//  Function Name:	RGpDrawingSurface::GetTextSize( )
//
//  Description:		return the dimensions of the given text if drawn to the surface
//
//  Returns:			RIntSize dimensions
//
//  Exceptions:		None
//
// ****************************************************************************
//
RIntSize RGpDrawingSurface::GetActualTextSize( YCounter nChars, const uBYTE* pChars )
{
    UnimplementedCode();
    return RIntSize( 0, 0 );
}