void cbBarDragPlugin::DoDrawHintRect( wxRect& rect, bool isInClientRect) { wxRect scrRect; RectToScr( rect, scrRect ); int prevLF = mpScrDc->GetLogicalFunction(); mpScrDc->SetLogicalFunction( wxINVERT ); if ( isInClientRect ) { // BUG BUG BUG (wx):: somehow stippled brush works only // when the bitmap created on stack, not // as a member of the class wxBitmap checker( (const char*)_gCheckerImg, 8,8 ); wxBrush checkerBrush( checker ); mpScrDc->SetPen( mpLayout->mNullPen ); mpScrDc->SetBrush( checkerBrush ); int half = mInClientHintBorder / 2; mpScrDc->DrawRectangle( scrRect.x - half, scrRect.y - half, scrRect.width + 2*half, mInClientHintBorder ); mpScrDc->DrawRectangle( scrRect.x - half, scrRect.y + scrRect.height - half, scrRect.width + 2*half, mInClientHintBorder ); mpScrDc->DrawRectangle( scrRect.x - half, scrRect.y + half - 1, mInClientHintBorder, scrRect.height - 2*half + 2); mpScrDc->DrawRectangle( scrRect.x + scrRect.width - half, scrRect.y + half - 1, mInClientHintBorder, scrRect.height - 2*half + 2); mpScrDc->SetBrush( wxNullBrush ); } else { mpScrDc->SetPen( mpLayout->mBlackPen ); mpScrDc->DrawLine( scrRect.x, scrRect.y, scrRect.x + scrRect.width, scrRect.y ); mpScrDc->DrawLine( scrRect.x, scrRect.y + 1, scrRect.x, scrRect.y + scrRect.height ); mpScrDc->DrawLine( scrRect.x+1, scrRect.y + scrRect.height, scrRect.x + scrRect.width, scrRect.y + scrRect.height ); mpScrDc->DrawLine( scrRect.x + scrRect.width , scrRect.y, scrRect.x + scrRect.width, scrRect.y + scrRect.height + 1); } mpScrDc->SetLogicalFunction( prevLF ); }
void wxToolWindow::DrawHintRect( const wxRect& r ) { // BUG BUG BUG (wx):: somehow stippled brush works only // when the bitmap created on stack, not // as a member of the class int prevLF = mpScrDc->GetLogicalFunction(); mpScrDc->SetLogicalFunction( wxXOR ); wxBitmap checker( (const char*)_gCheckerImg, 8,8 ); wxBrush checkerBrush( checker ); mpScrDc->SetPen( *wxTRANSPARENT_PEN ); mpScrDc->SetBrush( checkerBrush ); int half = mHintBorder / 2; mpScrDc->DrawRectangle( r.x - half, r.y - half, r.width + 2*half, mHintBorder ); mpScrDc->DrawRectangle( r.x - half, r.y + r.height - half, r.width + 2*half, mHintBorder ); mpScrDc->DrawRectangle( r.x - half, r.y + half - 1, mHintBorder, r.height - 2*half + 2); mpScrDc->DrawRectangle( r.x + r.width - half, r.y + half - 1, mHintBorder, r.height - 2*half + 2); mpScrDc->SetBrush( wxNullBrush ); mpScrDc->SetLogicalFunction( prevLF ); }
void wxNewBitmapButton::RenderLabelImage( wxBitmap*& destBmp, wxBitmap* srcBmp, bool isEnabled, bool isPressed ) { if ( destBmp != 0 ) return; // render labels on-demand wxMemoryDC srcDc; srcDc.SelectObject( *srcBmp ); bool hasText = ( mTextAlignment != NB_NO_TEXT ) && ( mLabelText.length() != 0 ); bool hasImage = (mTextAlignment != NB_NO_IMAGE); wxSize destDim; wxPoint txtPos; wxPoint imgPos; if ( hasText ) { long txtWidth, txtHeight; srcDc.SetFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) ); srcDc.GetTextExtent( mLabelText, &txtWidth, &txtHeight ); if ( mTextAlignment == NB_ALIGN_TEXT_RIGHT ) { destDim.x = srcBmp->GetWidth() + 2*mTextToLabelGap + txtWidth; destDim.y = wxMax( srcBmp->GetHeight(), txtHeight ); txtPos.x = srcBmp->GetWidth() + mTextToLabelGap; txtPos.y = (destDim.y - txtHeight)/2; imgPos.x = 0; imgPos.y = (destDim.y - srcBmp->GetHeight())/2; } else if ( mTextAlignment == NB_ALIGN_TEXT_BOTTOM ) { destDim.x = wxMax( srcBmp->GetWidth(), txtWidth ); destDim.y = srcBmp->GetHeight() + mTextToLabelGap + txtHeight; txtPos.x = (destDim.x - txtWidth)/2; txtPos.y = srcBmp->GetHeight() + mTextToLabelGap; imgPos.x = (destDim.x - srcBmp->GetWidth())/2; imgPos.y = 0; } else { wxFAIL_MSG(wxT("Unsupported FL alignment type detected in wxNewBitmapButton::RenderLabelImage()")); } } else { imgPos.x = 0; imgPos.y = 0; destDim.x = srcBmp->GetWidth(); destDim.y = srcBmp->GetHeight(); } destBmp = new wxBitmap( int(destDim.x), int(destDim.y) ); wxMemoryDC destDc; destDc.SelectObject( *destBmp ); wxBrush grayBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE), wxSOLID ); destDc.SetBrush( grayBrush ); destDc.SetPen( *wxTRANSPARENT_PEN ); destDc.DrawRectangle( 0,0, destDim.x+1, destDim.y+1 ); if ( isPressed ) { ++imgPos.x; ++imgPos.y; ++txtPos.x; ++txtPos.y; } if ( hasImage ) { destDc.Blit( imgPos.x, imgPos.y, srcBmp->GetWidth(), srcBmp->GetHeight(), &srcDc, 0,0, wxCOPY,true ); } if ( hasText ) { wxWindow* pTopWnd = this; do { wxWindow* pParent = pTopWnd->GetParent(); if ( pParent == 0 ) break; pTopWnd = pParent; } while (1); destDc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT) ); if ( isEnabled ) { destDc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) ); } else { destDc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW) ); } destDc.SetTextBackground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE) ); destDc.DrawText( mLabelText, txtPos.x, txtPos.y ); } if ( !isEnabled ){ #ifdef __WXMSW__ // This is currently MSW specific gray_out_image_on_dc( destDc, destDim.x, destDim.y ); #else wxBitmap bmp( (const char*)_gDisableImage,8,8); wxBrush checkerBrush(bmp); checkerBrush.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) ); destDc.SetBrush( checkerBrush ); destDc.DrawRectangle( imgPos.x, imgPos.y, srcBmp->GetWidth()+1, srcBmp->GetHeight()+1); #endif } // adjust button size to fit the new dimensions of the label if ( !mSizeIsSet && 0 ) { mSizeIsSet = true; SetSize( wxDefaultCoord, wxDefaultCoord, destBmp->GetWidth() + mMarginX*2, destBmp->GetHeight() + mMarginY*2, 0 ); } destDc.SelectObject( wxNullBitmap ); #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) // Map to system colours (void) wxToolBar::MapBitmap(destBmp->GetHBITMAP(), destBmp->GetWidth(), destBmp->GetHeight()); #endif }