Example #1
0
bool wxWizard::ResizeBitmap(wxBitmap& bmp)
{
    if (!GetBitmapPlacement())
        return false;

    if (bmp.Ok())
    {
        wxSize pageSize = m_sizerPage->GetSize();
        if (pageSize == wxSize(0,0))
            pageSize = GetPageSize();
        int bitmapWidth = wxMax(bmp.GetWidth(), GetMinimumBitmapWidth());
        int bitmapHeight = pageSize.y;

        if (!m_statbmp->GetBitmap().Ok() || m_statbmp->GetBitmap().GetHeight() != bitmapHeight)
        {
            wxBitmap bitmap(bitmapWidth, bitmapHeight);
            {
                wxMemoryDC dc;
                dc.SelectObject(bitmap);
                dc.SetBackground(wxBrush(m_bitmapBackgroundColour));
                dc.Clear();

                if (GetBitmapPlacement() & wxWIZARD_TILE)
                {
                    TileBitmap(wxRect(0, 0, bitmapWidth, bitmapHeight), dc, bmp);
                }
                else
                {
                    int x, y;

                    if (GetBitmapPlacement() & wxWIZARD_HALIGN_LEFT)
                        x = 0;
                    else if (GetBitmapPlacement() & wxWIZARD_HALIGN_RIGHT)
                        x = bitmapWidth - bmp.GetWidth();
                    else
                        x = (bitmapWidth - bmp.GetWidth())/2;

                    if (GetBitmapPlacement() & wxWIZARD_VALIGN_TOP)
                        y = 0;
                    else if (GetBitmapPlacement() & wxWIZARD_VALIGN_BOTTOM)
                        y = bitmapHeight - bmp.GetHeight();
                    else
                        y = (bitmapHeight - bmp.GetHeight())/2;

                    dc.DrawBitmap(bmp, x, y, true);
                    dc.SelectObject(wxNullBitmap);
                }
            }

            bmp = bitmap;
        }
    }

    return true;
}
Example #2
0
void CProgressST::DrawProgress(CDC * pDC)
{
	CRect ctrlRect;

    CDC memDC;
	memDC.CreateCompatibleDC(pDC);

	// Select bitmap
	CBitmap* pOldBitmap = memDC.SelectObject(&m_bmPattern);

	GetClientRect(ctrlRect);

	// Create temporary DC & bitmap
	CDC tempDC;
	tempDC.CreateCompatibleDC(pDC);

	CBitmap bitmapTemp;
	bitmapTemp.CreateCompatibleBitmap(&memDC, ctrlRect.Width(), ctrlRect.Height());
	CBitmap* pOldTempBitmap = tempDC.SelectObject(&bitmapTemp);

	// Calculate control's percentage to draw
	int nPercentage;
	nPercentage = (int)((100.0/m_nRange)*(abs(m_nLower)+m_nPos));

	// Adjust rectangle to draw on screen
	float f = ((float)(ctrlRect.Width())/100)*nPercentage;
	if ((ctrlRect.left + (int)f) > ctrlRect.right)
	{
		ctrlRect.right -= 1;
	}
	else
	{
		ctrlRect.right = ctrlRect.left + (int)f;
	}
	// Leave space for border
	ctrlRect.DeflateRect(1, 1);

	// Tile the bitmap into the temporary rectangle
	TileBitmap(&tempDC, &memDC, ctrlRect);

	// Select and realize the palette
	if(pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE && m_Palette.m_hObject != NULL)
	{
		pDC->SelectPalette(&m_Palette, FALSE);
		pDC->RealizePalette();
	}

	// Copy from temporary DC to screen (only the percentage rectangle)
	if (ctrlRect.IsRectEmpty() == FALSE)
		pDC->BitBlt(2, 2, ctrlRect.Width(), ctrlRect.Height(), &tempDC, 0, 0, SRCCOPY);

	/* RFU
	CRect R;
	GetClientRect(R);
	pDC->SetBkMode(TRANSPARENT);
	pDC->DrawText("Title", -1, R, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
	*/

	// Restore old selected bitmaps
	tempDC.SelectObject(pOldTempBitmap);
	memDC.SelectObject(pOldBitmap);
} // End of DrawProgress
Example #3
0
void CProgressCtrlST::OnPaint() 
{
	// If there is no bitmap loaded
	if (m_hBitmap == NULL) 
	{
		CProgressCtrl::OnPaint();
		return;
	} // if

	CRect		rcCtrl;
	DWORD		dwStyle			= 0;
	BOOL		bVertical		= FALSE;
	float		f				= 0;
	int			nPercentage		= 0;
	HDC			hdcMem			= NULL;
	HDC			hdcTemp			= NULL;
	HBITMAP		hOldBitmap		= NULL;
	HBITMAP		hbmpTemp		= NULL;
	HBITMAP		hOldTempBitmap	= NULL;
	CPaintDC	dc(this);

	GetClientRect(rcCtrl);

	dwStyle = GetStyle();
	bVertical = (dwStyle & PBS_VERTICAL) == PBS_VERTICAL;

	// Has border ?
	if ((dwStyle & WS_BORDER) == WS_BORDER)
	{
		CBrush brBtnShadow(RGB(0, 0, 0));
		dc.FrameRect(rcCtrl, &brBtnShadow);
		rcCtrl.DeflateRect(1, 1);
	} // if

	rcCtrl.DeflateRect(1, 1);

	hdcMem = ::CreateCompatibleDC(dc.m_hDC);

	// Select bitmap
	hOldBitmap = (HBITMAP)::SelectObject(hdcMem, m_hBitmap);

	// Create temporary DC & bitmap
	hdcTemp = ::CreateCompatibleDC(dc.m_hDC);

	hbmpTemp = ::CreateCompatibleBitmap(hdcMem, rcCtrl.Width(), rcCtrl.Height());
	hOldTempBitmap = (HBITMAP)::SelectObject(hdcTemp, hbmpTemp);

	// Calculate control's percentage to draw
	nPercentage = (int)((100.0/m_nRange)*(abs(m_nLower)+m_nPos));

	// Adjust rectangle to draw on screen
	if (bVertical)
	{
		f = ((float)(rcCtrl.Height())/100)*nPercentage;
		if ((rcCtrl.bottom - (int)f) < rcCtrl.top)
			rcCtrl.top += 1;
		else
			rcCtrl.top = rcCtrl.bottom - (int)f;
	} // if
	else
	{
		f = ((float)(rcCtrl.Width())/100)*nPercentage;
		if ((rcCtrl.left + (int)f) > rcCtrl.right)
			rcCtrl.right -= 1;
		else
			rcCtrl.right = rcCtrl.left + (int)f;
	} // else

	// Tile the bitmap into the temporary rectangle
	TileBitmap(hdcTemp, hdcMem, rcCtrl);

	// Copy from temporary DC to screen (only the percentage rectangle)
	if (rcCtrl.IsRectEmpty() == FALSE)
		::BitBlt(dc.m_hDC, rcCtrl.left, rcCtrl.top, rcCtrl.Width(), rcCtrl.Height(), hdcTemp, 0, 0, SRCCOPY);


	CRect	rcFullCtrl;
	GetClientRect(rcFullCtrl);

	OnDrawText(&dc, nPercentage, rcFullCtrl, rcCtrl, bVertical);
	// Restore old selected bitmaps
	::SelectObject(hdcTemp, hOldTempBitmap);
	::SelectObject(hdcMem, hOldBitmap);

	::DeleteObject( hbmpTemp );
    ::DeleteDC( hdcTemp );
	::DeleteDC( hdcMem );
} // End of OnPaint