void LWSlider::OnPaint(wxDC &dc, bool selected) { //thumbPos should be in pixels int thumbPos = ValueToPosition(mCurrentValue); int thumbY = mCenterY - (mThumbHeight/2); wxBitmap *bitmap; wxBitmap *thumbBitmap; if (selected) { bitmap = mSelBitmap; thumbBitmap = mSelThumbBitmap; } else { bitmap = mBitmap; thumbBitmap = mThumbBitmap; } #if defined(__WXMAC__) || defined(__WXMSW__) dc.DrawBitmap(*bitmap, mLeft, mTop); dc.DrawBitmap(*thumbBitmap, mLeft+thumbPos, mTop+thumbY); #else wxMemoryDC memDC; memDC.SelectObject(*bitmap); dc.Blit(mLeft, mTop, mWidth, mHeight, &memDC, 0, 0, wxCOPY, FALSE); memDC.SelectObject(*thumbBitmap); dc.Blit(mLeft+thumbPos, mTop+thumbY, mThumbWidth, mThumbHeight, &memDC, 0, 0, wxCOPY, FALSE); #endif if (mPopWin) mPopWin->Refresh(); }
static void wxDrawSplashBitmap(wxDC& dc, const wxBitmap& bitmap, int WXUNUSED(x), int WXUNUSED(y)) { wxMemoryDC dcMem; #ifdef USE_PALETTE_IN_SPLASH bool hiColour = (wxDisplayDepth() >= 16) ; if (bitmap.GetPalette() && !hiColour) { dcMem.SetPalette(* bitmap.GetPalette()); } #endif // USE_PALETTE_IN_SPLASH dcMem.SelectObjectAsSource(bitmap); dc.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), &dcMem, 0, 0, wxCOPY, true /* use mask */); dcMem.SelectObject(wxNullBitmap); #ifdef USE_PALETTE_IN_SPLASH if (bitmap.GetPalette() && !hiColour) { dcMem.SetPalette(wxNullPalette); } #endif // USE_PALETTE_IN_SPLASH }
/// This draws the background of a toolbar void ToolBar::DrawBackground(wxDC &dc, int width, int height) { #if defined(__WXMAC__) if (mBackgroundWidth < width) { if (mBackgroundBitmap) delete mBackgroundBitmap; wxImage *aquaImage = CreateAquaBackground(width, height, 0); mBackgroundBitmap = new wxBitmap(aquaImage); delete aquaImage; } wxMemoryDC memDC; memDC.SelectObject(*mBackgroundBitmap); dc.Blit(0, 0, width, height, &memDC, 0, 0, wxCOPY, FALSE); #if 0 height = mIdealSize.GetHeight(); dc.SetPen(*wxBLACK_PEN); dc.DrawLine(27, 0, 27, height - 1); dc.DrawLine(55, 0, 55, height - 1); dc.DrawLine(83, 0, 83, 27); dc.DrawLine(0, 27, 83, 27); #endif #else dc.SetBrush(mBackgroundBrush); dc.SetPen(mBackgroundPen); height = mIdealSize.GetHeight(); dc.DrawRectangle(0, 0, width, height); #if 0 // JKC: This code draws a grid of lines around the first few // buttons on the toolbar. // TODO: Do we want this at all? // If so this should be moved to ControlToolbar. // Having it here means that it is also drawn in EditToolBar, // which we probably don't want. (same for the Mac // version in other half of #ifdef). dc.SetPen(*wxBLACK_PEN); dc.DrawLine(27, 0, 27, height - 1); dc.DrawLine(55, 0, 55, height - 1); dc.DrawLine(83, 0, 83, height - 1); dc.DrawLine(0, 27, 83, 27); #endif #endif }
void VdkDC::Flush(wxDC &dc) { SetDeviceOrigin(0, 0); dc.Blit(m_Rect.x, m_Rect.y, m_Rect.width, m_Rect.height, this, m_Rect.x, m_Rect.y); if (m_Window->GetCachedDC() == this) { m_Window->ResetCachedDC(dc); } }
void Timeline::DrawTimeline(wxDC& dc) { const wxSize size = GetClientSize(); const wxRect rect(0, m_scrollPos, size.x, size.y); DrawTimeline(rect); // Copy MemoryDC to Display dc.Blit(0, 0, size.x, size.y, &m_mdc, 0, 0); m_needRedrawing = false; }
//--------------------------------------------------------------------------- void wxPagedWindow::DrawPaperBar( twTabInfo& tab, int x, int y, wxBrush& brush, wxPen& pen, wxDC& dc ) { wxPoint poly[4]; // draw organizer-style paper outlet poly[0].x = x - mTabTrianGap; poly[0].y = y; poly[1].x = x + mTabTrianGap; poly[1].y = y + tab.mDims.y-1; poly[2].x = x + tab.mDims.x - mTabTrianGap; poly[2].y = y + tab.mDims.y-1; poly[3].x = x + tab.mDims.x + mTabTrianGap; poly[3].y = y; dc.SetPen( pen ); dc.SetBrush( brush ); dc.DrawPolygon( 4, poly ); long w,h; // set select default font of the window into it's device context //dc.SetFont( GetLabelingFont() ); dc.SetTextBackground( brush.GetColour() ); dc.GetTextExtent(tab.mText, &w, &h ); if ( tab.HasImg() ) { wxMemoryDC tmpDc; tmpDc.SelectObject( tab.GetImg() ); dc.Blit( x + mTitleHorizGap, y + ( tab.mDims.y - tab.ImgHeight() ) / 2, tab.ImgWidth(), tab.ImgHeight(), &tmpDc, 0, 0, wxCOPY ); } if ( tab.HasText() ) { int tx = x + mTitleHorizGap + tab.ImgWidth() + tab.ImageToTxtGap(mImageTextGap); dc.DrawText( tab.GetText(), tx, y + ( tab.mDims.y - h ) / 2 ); } } // wxPagedWindow::DrawPaperBar()
/** this draws the data on the Control */ void wxLEDPanel::DrawField(wxDC& dc, bool backgroundMode) { wxPoint point; int w=m_ledsize.GetWidth()+m_padding; int h=m_ledsize.GetHeight()+m_padding; char data; // Zähler für Zeile und Spalte int x=0,y=0; // Pointer to avoid unnesecerie if blocks in the for block wxMemoryDC* p_mdc_data=((m_invert)?((m_show_inactivs)?(&m_mdc_led_off):(&m_mdc_led_none)):(&m_mdc_led_on)); wxMemoryDC* p_mdc_nodata=((m_invert)?(&m_mdc_led_on):((m_show_inactivs)?(&m_mdc_led_off):(&m_mdc_led_none))); int l = m_field.GetLength(); int fw = m_field.GetWidth(); const char* field = m_field.GetData(); for(int i=0;i<l;++i) { // Daten des Feldes data=field[i]; // Koordinaten point.x=x*w+m_padding; point.y=y*h+m_padding; // zeichnen if(field[i] && !backgroundMode) { dc.Blit(point.x,point.y,w,h,p_mdc_data,0,0); } else if(backgroundMode) { dc.Blit(point.x,point.y,w,h,p_mdc_nodata,0,0); } // hochzählen ++x; if(x==fw) {++y; x=0;} } }
void ImageRoll::DrawBitmap(wxDC &dc, wxBitmap &bitmap, int x, int y, int logicalFunc) { if (logicalFunc == wxCOPY) dc.DrawBitmap(bitmap, x, y); else { wxMemoryDC memDC; memDC.SelectObject(bitmap); dc.Blit(x, y, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0, logicalFunc); } }
void ToolBar::DrawBackground(wxDC &dc, int width, int height) { #if defined(__WXMAC__) if (mBackgroundWidth < width) { if (mBackgroundBitmap) delete mBackgroundBitmap; mBackgroundBitmap = new wxBitmap(width, height); wxMemoryDC memDC; memDC.SelectObject(*mBackgroundBitmap); int y; memDC.SetPen(wxPen(wxColour(231, 231, 231), 1, wxSOLID)); for (y = 0; y < height; y += 4) memDC.DrawLine(0, y, width, y); memDC.SetPen(wxPen(wxColour(239, 239, 239), 1, wxSOLID)); for (y = 1; y < height; y += 2) memDC.DrawLine(0, y, width, y); memDC.SetPen(wxPen(wxColour(255, 255, 255), 1, wxSOLID)); for (y = 2; y < height; y += 4) memDC.DrawLine(0, y, width, y); } wxMemoryDC memDC; memDC.SelectObject(*mBackgroundBitmap); dc.Blit(0, 0, width, height, &memDC, 0, 0, wxCOPY, FALSE); dc.SetPen(*wxBLACK_PEN); dc.DrawLine(27, 0, 27, height - 1); dc.DrawLine(55, 0, 55, height - 1); dc.DrawLine(83, 0, 83, 27); dc.DrawLine(0, 27, 83, 27); #else dc.SetBrush(mBackgroundBrush); dc.SetPen(mBackgroundPen); dc.DrawRectangle(0, 0, width, height); dc.SetPen(*wxBLACK_PEN); dc.DrawLine(27, 0, 27, height - 1); dc.DrawLine(55, 0, 55, height - 1); dc.DrawLine(83, 0, 83, height - 1); dc.DrawLine(0, 27, 83, 27); #endif }
void hoxUtil::DrawBitmapOnDC( wxDC& dc, wxBitmap& bitmap, const wxCoord x, const wxCoord y ) { #ifdef __WXMAC__ dc.DrawBitmap( bitmap, x, y, true ); #else wxMemoryDC memDC( bitmap ); dc.Blit( x, y, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0, wxCOPY, true ); #endif }
bool DragShape::Draw(wxDC& dc, int op) { if (m_bitmap.Ok()) { wxMemoryDC memDC; memDC.SelectObject(m_bitmap); dc.Blit(m_pos.x, m_pos.y, m_bitmap.GetWidth(), m_bitmap.GetHeight(), & memDC, 0, 0, op, true); return true; } else return false; }
void Stage::PaintStage(wxDC &inDC, const wxRegion &inDirtyRegion) { // Make sure we don't overdraw any heavyweight elements. ClipElementsThatDrawThemselves(inDC); // Blit our offscreen pixmap to the screen. { wxMemoryDC srcDC; srcDC.SelectObjectAsSource(GetCompositingPixmap()); wxRegionIterator i(inDirtyRegion); while (i) { inDC.Blit(i.GetX(), i.GetY(), i.GetW(), i.GetH(), &srcDC, i.GetX(), i.GetY()); i++; } } // If necessary, draw the grid. if (mIsDisplayingGrid) { int width = mStageSize.GetWidth(); int height = mStageSize.GetHeight(); int small_spacing = 10; int large_spacing = small_spacing * 10; // Draw the minor divisions of the grid. inDC.SetPen(*wxLIGHT_GREY_PEN); for (int x = 0; x < width; x += small_spacing) if (x % large_spacing) inDC.DrawLine(x, 0, x, height); for (int y = 0; y < width; y += small_spacing) if (y % large_spacing) inDC.DrawLine(0, y, width, y); // Draw the major divisions of the grid. inDC.SetPen(*wxGREEN_PEN); for (int x2 = 0; x2 < width; x2 += large_spacing) inDC.DrawLine(x2, 0, x2, height); for (int y2 = 0; y2 < width; y2 += large_spacing) inDC.DrawLine(0, y2, width, y2); } // If necessary, draw the borders. if (mIsDisplayingBorders) { ElementCollection::iterator i = mElements.begin(); for (; i != mElements.end(); i++) if ((*i)->IsShown()) DrawElementBorder(inDC, *i); } }
bool TileBitmap::draw(wxDC& dc, size_t tilenum, size_t x, size_t y, const TileAttributes& attrs) { if(drawn_) { tilenum %= N_TILES; if( attrs.getAttribute(TileAttributes::ATTR_VFLIP)) { tilenum += N_TILES * 2; } if(attrs.getAttribute(TileAttributes::ATTR_HFLIP)) { tilenum += N_TILES; } //dc.StretchBlit(left, top, width, height, &memDC, 0, 0, WIDTH, HEIGHT, wxCOPY, true, 0, 0); dc.Blit(x*WIDTH, y*HEIGHT, WIDTH, HEIGHT, &memDC, 0, tilenum*HEIGHT, wxCOPY, true); } return drawn_; }
bool wxWizard::TileBitmap(const wxRect& rect, wxDC& dc, const wxBitmap& bitmap) { int w = bitmap.GetWidth(); int h = bitmap.GetHeight(); wxMemoryDC dcMem; dcMem.SelectObjectAsSource(bitmap); int i, j; for (i = rect.x; i < rect.x + rect.width; i += w) { for (j = rect.y; j < rect.y + rect.height; j+= h) dc.Blit(i, j, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0); } dcMem.SelectObject(wxNullBitmap); return true; }
bool DragShape::Draw(wxDC& dc, bool highlight) { if (m_bitmap.IsOk()) { wxMemoryDC memDC; memDC.SelectObject(m_bitmap); dc.Blit(m_pos.x, m_pos.y, m_bitmap.GetWidth(), m_bitmap.GetHeight(), & memDC, 0, 0, wxCOPY, true); if (highlight) { dc.SetPen(*wxWHITE_PEN); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(m_pos.x, m_pos.y, m_bitmap.GetWidth(), m_bitmap.GetHeight()); } return true; } else return false; }
void ManageFieldTextureDialog::DrawImage(wxDC& dc) { if (main_img.IsOk()) { int mainposx = 0; int mainposy = 0; int extrax = 0; int extray = 0; if (imported_img.IsOk()) { mainposx = max(0,-imported_img_x)/scale_ratio; mainposy = max(0,-imported_img_y)/scale_ratio; extrax = max(0,int(imported_img_x/scale_ratio+imported_img.GetWidth()-main_img.GetWidth())); extray = max(0,int(imported_img_y/scale_ratio+imported_img.GetHeight()-main_img.GetHeight())); } m_texturewindow->SetVirtualSize(main_img.GetWidth()+mainposx+extrax,main_img.GetHeight()+mainposy+extray); MACRO_CREATE_MEMORY_DC(dc,m_texturewindow) mdc.DrawBitmap(main_img,mainposx,mainposy); if (imported_img.IsOk()) mdc.DrawBitmap(imported_img,mainposx+imported_img_x/scale_ratio,mainposy+imported_img_y/scale_ratio); if (foreground_img.IsOk()) mdc.DrawBitmap(foreground_img,mainposx,mainposy); m_texturewindow->DoPrepareDC(dc); dc.Blit(wxPoint(0,0),mdc.GetSize(),&mdc,wxPoint(0,0)); } }
bool wxEffectsImpl::TileBitmap(const wxRect& rect, wxDC& dc, const wxBitmap& bitmap) { int w = bitmap.GetWidth(); int h = bitmap.GetHeight(); wxMemoryDC dcMem; #if wxUSE_PALETTE static bool hiColour = (wxDisplayDepth() >= 16) ; if (bitmap.GetPalette() && !hiColour) { dc.SetPalette(* bitmap.GetPalette()); dcMem.SetPalette(* bitmap.GetPalette()); } #endif // wxUSE_PALETTE dcMem.SelectObjectAsSource(bitmap); int i, j; for (i = rect.x; i < rect.x + rect.width; i += w) { for (j = rect.y; j < rect.y + rect.height; j+= h) dc.Blit(i, j, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0); } dcMem.SelectObject(wxNullBitmap); #if wxUSE_PALETTE if (bitmap.GetPalette() && !hiColour) { dc.SetPalette(wxNullPalette); dcMem.SetPalette(wxNullPalette); } #endif // wxUSE_PALETTE return true; }
void wxNewBitmapButton::DrawLabel( wxDC& dc ) { wxBitmap* pCurBmp = GetStateLabel(); if ( pCurBmp == NULL ) { wxSizeEvent evt; OnSize( evt ); // fake it up! //RenderLabelImages(); pCurBmp = GetStateLabel(); } wxMemoryDC mdc; mdc.SelectObject( *pCurBmp ); dc.Blit( mMarginX, mMarginY, pCurBmp->GetWidth(), pCurBmp->GetHeight(), &mdc, 0,0, wxCOPY ); mdc.SelectObject( wxNullBitmap ); }
void CODListBox::OnDrawItem(wxDC &dc, const wxRect &rect, size_t n)const { wxMemoryDC tempDC; wxString *text; int len; int i; byte pi; if (n >= items.Count()) return; if (this->IsSelected(n)) { tempDC.SelectObject(selBitmap); } else { tempDC.SelectObject(stdBitmap); } text = GetItem(n); len = text->Len(); for (i = 0; i < len; i++) { pi = text->GetChar(i); if (pi >= 64 && pi < 128) pi -= 64; if (pi >= 192) // TODO: ARGH !! Can we get this easier ?? pi -= 64; if (pi >= 64) pi -= 64; dc.Blit(i * charWidth + rect.x, rect.y, charWidth, charHeigth, &tempDC, pi<<3, 0); } tempDC.SelectObject(wxNullBitmap); }
void DocHistory::DrawLayout(wxDC& dc) { if (!IsShown()) { // Sometimes OnSize() might get called while control is hidden m_needRedrawing = true; return; } const wxSize size = GetClientSize(); wxRect rect; if (m_isScrolling) { // If there is overlap, then move the image if (m_scrollPos + size.y > m_oldScrollPos && m_scrollPos < m_oldScrollPos + size.y) { const int top = wxMax(m_scrollPos, m_oldScrollPos); const int bottom = wxMin(m_scrollPos, m_oldScrollPos) + size.y; const int overlap_height = bottom - top; m_mdc.Blit(0, (top - m_oldScrollPos) + (m_oldScrollPos - m_scrollPos), size.x, overlap_height, &m_mdc, 0, top - m_oldScrollPos); const int new_height = size.y - overlap_height; const int newtop = (top == m_scrollPos) ? bottom : m_scrollPos; rect = wxRect(0,newtop,size.x,new_height); // Just redraw the revealed part } else { rect = wxRect(0,m_scrollPos,size.x,size.y); } SetScrollPos(wxVERTICAL, m_scrollPos); m_isScrolling = false; } else { // Check if we need a scrollbar bool hasScroll = (GetScrollThumb(wxVERTICAL) != 0); if (m_treeHeight > size.y) { SetScrollbar(wxVERTICAL, m_scrollPos, size.y, m_treeHeight); if (!hasScroll) return; // have sent a size event } else { SetScrollbar(wxVERTICAL, 0, 0, 0); if (hasScroll) return; // have sent a size event } // Can we make room for more of the history? if (m_scrollPos + size.y > m_treeHeight) { m_scrollPos = wxMax(0, m_treeHeight-size.y); } rect = wxRect(0, m_scrollPos, size.x, size.y); } // Resize & scroll the versiontree wxSize timelinesize = m_pTimeline->GetBestSize(); wxSize treesize = m_pTree->GetBestSize(); if (timelinesize.x + treesize.x >= size.x) { timelinesize.x = treesize.x = size.x / 3; } m_pTimeline->Move(0, 0); m_pTimeline->SetSize(wxSize(timelinesize.x, size.y)); m_pTimeline->Scroll(m_scrollPos); m_pTimeline->ReDraw(); // Resize & scroll the versiontree (positioned right of Timeline) m_pTree->Move(timelinesize.x, 0); m_pTree->SetSize(wxSize(treesize.x, size.y)); m_pTree->Scroll(m_scrollPos); m_xposDesc = timelinesize.x + treesize.x; const int textwidth = size.x - m_xposDesc; rect = wxRect(m_xposDesc, rect.y, textwidth, rect.height); // resize the bitmap used for doublebuffering if (m_bitmap.GetWidth() < textwidth || m_bitmap.GetHeight() < size.y) { m_bitmap = wxBitmap(textwidth, size.y); m_mdc.SelectObject(m_bitmap); } // Draw the description area // Notice that the memDc is moved so that m_xposDesc=0 { // Clear the background m_mdc.SetBrush(bgBrush); m_mdc.SetPen(*wxWHITE_PEN); m_mdc.DrawRectangle(0, rect.y - m_scrollPos, textwidth, rect.height); // Find the first visible node unsigned int i; for (i = 0; i < m_items.size(); ++i) { if (m_items[i].ypos+m_lineHeight >= rect.y) break; } const int ybottom = m_scrollPos + size.y; // Draw Label & Description m_mdc.SetTextForeground(*wxBLACK); const int textindent = 3; cxLOCK_READ(m_catalyst) while (i < m_items.size() && m_items[i].ypos < ybottom) { wxString label = catalyst.GetLabel(m_items[i].doc); if (!label.empty()) { label = label.BeforeFirst('\n'); label += wxT(": "); } int x; int y; m_mdc.GetTextExtent(label, &x, &y); m_mdc.DrawText(label, textindent, m_items[i].ypos-m_scrollPos); wxString desc = catalyst.GetDescription(m_items[i].doc); desc = desc.BeforeFirst('\n'); m_mdc.DrawText(desc, textindent+x, m_items[i].ypos-m_scrollPos); ++i; } cxENDLOCK } // Copy MemoryDC to Display dc.Blit(m_xposDesc, 0, textwidth, size.y, &m_mdc, 0, 0); m_needRedrawing = false; }
bool wxMenuItem::OnDrawItem( wxDC& rDC, const wxRect& rRect, wxODAction eAction, wxODStatus eStatus ) { // // Select the font and draw the text // --------------------------------- // CHARBUNDLE vCbnd; wxPMDCImpl *impl = (wxPMDCImpl*) rDC.GetImpl(); HPS hPS= impl->GetHPS(); wxFont vFont; wxColour vColBack; wxColour vColText; COLORREF vRef; RECTL vRect = {rRect.x + 4, rRect.y + 1, rRect.x + (rRect.width - 2), rRect.y + rRect.height}; memset(&vCbnd, 0, sizeof(CHARBUNDLE)); GetFontToUse(vFont); GetColourToUse(eStatus, vColText, vColBack); rDC.SetFont(vFont); rDC.SetTextBackground(vColBack); rDC.SetTextForeground(vColText); rDC.SetBackgroundMode(wxTRANSPARENT); vCbnd.lColor = vColText.GetPixel(); vCbnd.lBackColor = vColBack.GetPixel(); ::GpiSetAttrs( hPS ,PRIM_CHAR ,CBB_BACK_COLOR | CBB_COLOR ,0 ,&vCbnd ); ::GpiSetBackMix( hPS ,BM_LEAVEALONE ); // // Paint the background // ::WinFillRect(hPS, &vRect, vColBack.GetPixel()); // // Determine where to draw and leave space for a check-mark. // int nX = rRect.x + GetMarginWidth(); // // Unfortunately, unlike Win32, PM has no owner drawn specific text // drawing methods like ::DrawState that can cleanly handle accel // mnemonics and deal, automatically, with various states, so we have // to handle them ourselves. Notice Win32 can't handle \t in ownerdrawn // strings either. We cannot handle mnemonics either. We display // them, though, in the hope we can figure them out some day. // // // Display main text and accel text separately to align better // wxString sTgt = wxT("\t"); wxString sFullString = GetItemLabel(); // need to save the original text wxString sAccel; int nIndex; size_t nWidth; size_t nCharWidth; size_t nHeight; bool bFoundMnemonic = false; bool bFoundAccel = false; // // Deal with the tab, extracting the Accel text // nIndex = sFullString.Find(sTgt); if (nIndex != -1) { bFoundAccel = true; sAccel = sFullString.Mid(nIndex + 1); sFullString.Remove(nIndex); } // // Deal with the mnemonic character // sTgt = wxT("~"); nIndex = sFullString.Find(sTgt); if (nIndex != -1) { wxString sTmp = sFullString; bFoundMnemonic = true; sTmp.Remove(nIndex); rDC.GetTextExtent( sTmp ,(wxCoord *)&nWidth ,(wxCoord *)&nHeight ); sTmp = sFullString[(size_t)(nIndex + 1)]; rDC.GetTextExtent( sTmp ,(wxCoord *)&nCharWidth ,(wxCoord *)&nHeight ); sFullString.Replace(sTgt.c_str(), wxEmptyString, true); } // // Draw the main item text sans the accel text // POINTL vPntStart = {nX, rRect.y + 4}; ::GpiCharStringAt( impl->GetHPS() ,&vPntStart ,sFullString.length() ,sFullString.char_str() ); if (bFoundMnemonic) { // // Underline the mnemonic -- still won't work, but at least it "looks" right // wxPen vPen; POINTL vPntEnd = {nX + nWidth + nCharWidth - 3, rRect.y + 2}; //CharWidth is bit wide vPntStart.x = nX + nWidth - 1; vPntStart.y = rRect.y + 2; // Make it look pretty! vPen = wxPen(vColText, 1, wxSOLID); // Assuming we are always black rDC.SetPen(vPen); ::GpiMove(hPS, &vPntStart); ::GpiLine(hPS, &vPntEnd); } // // Now draw the accel text // if (bFoundAccel) { size_t nWidth; size_t nHeight; rDC.GetTextExtent( sAccel ,(wxCoord *)&nWidth ,(wxCoord *)&nHeight ); // // Back off the starting position from the right edge // vPntStart.x = rRect.width - (nWidth + 7); vPntStart.y = rRect.y + 4; ::GpiCharStringAt( impl->GetHPS() ,&vPntStart ,sAccel.length() ,sAccel.char_str() ); } // // Draw the bitmap // --------------- // if (IsCheckable() && !m_bmpChecked.IsOk()) { if (eStatus & wxODChecked) { RECTL vRect; HBITMAP hBmpCheck = ::WinGetSysBitmap(HWND_DESKTOP, SBMP_MENUCHECK); vRect.xLeft = rRect.x; vRect.xRight = rRect.x + GetMarginWidth(); vRect.yBottom = rRect.y; vRect.yTop = rRect.y + m_nHeight - 3; ::WinDrawBitmap( hPS // PS for this menuitem ,hBmpCheck // system checkmark ,NULL // draw the whole bitmap ,(PPOINTL)&vRect // destination -- bottom left corner of the menuitem area ,0L // ignored ,0L // draw a bitmap ,DBM_NORMAL // draw normal size ); } } else { // // For uncheckable item we use only the 'checked' bitmap // wxBitmap vBmp(GetBitmap(IsCheckable() ? ((eStatus & wxODChecked) != 0) : TRUE)); if (vBmp.IsOk()) { wxMemoryDC vDCMem(&rDC); wxMemoryDC* pOldDC = (wxMemoryDC*)vBmp.GetSelectedInto(); if(pOldDC != NULL) { vBmp.SetSelectedInto(NULL); } vDCMem.SelectObject(vBmp); // // Center bitmap // int nBmpWidth = vBmp.GetWidth(); int nBmpHeight = vBmp.GetHeight(); // // There should be enough space! // wxASSERT((nBmpWidth <= rRect.width) && (nBmpHeight <= rRect.height)); int nHeightDiff = m_nHeight - nBmpHeight; rDC.Blit( rRect.x + (GetMarginWidth() - nBmpWidth) / 2 ,rRect.y + nHeightDiff / 2 ,nBmpWidth ,nBmpHeight ,&vDCMem ,0 ,0 ,wxCOPY ,true ); if (eStatus & wxODSelected) { POINTL vPnt1 = {rRect.x + 1, rRect.y + 3}; // Leave a little background border POINTL vPnt2 = {rRect.x + GetMarginWidth(), rRect.y + m_nHeight - 3}; LINEBUNDLE vLine; vLine.lColor = vColBack.GetPixel(); ::GpiSetAttrs( hPS ,PRIM_LINE ,LBB_COLOR ,0 ,&vLine ); ::GpiMove(hPS, &vPnt1); ::GpiBox( hPS ,DRO_OUTLINE ,&vPnt2 ,0L ,0L ); } vBmp.SetSelectedInto(NULL); } } return true; } // end of wxOwnerDrawn::OnDrawItem
void Game::MouseMove(wxDC& dc, int mx, int my) { if (m_liftedCard) { wxMemoryDC memoryDC; memoryDC.SelectObject(*m_bmap); int dx = mx + m_xOffset - m_xPos; int dy = my + m_yOffset - m_yPos; if (abs(dx) >= CardWidth || abs(dy) >= CardHeight) { // Restore the area under the card dc.Blit(m_xPos, m_yPos, CardWidth, CardHeight, &memoryDC, 0, 0, wxCOPY); // Copy the area under the card in the new position memoryDC.Blit(0, 0, CardWidth, CardHeight, &dc, m_xPos + dx, m_yPos + dy, wxCOPY); } else if (dx >= 0) { // dx >= 0 dc.Blit(m_xPos, m_yPos, dx, CardHeight, &memoryDC, 0, 0, wxCOPY); if (dy >= 0) { // dy >= 0 dc.Blit(m_xPos + dx, m_yPos, CardWidth - dx, dy, &memoryDC, dx, 0, wxCOPY); memoryDC.Blit(0, 0, CardWidth - dx, CardHeight - dy, &memoryDC, dx, dy, wxCOPY); memoryDC.Blit(0, CardHeight - dy, CardWidth - dx, dy, &dc, m_xPos + dx, m_yPos + CardHeight, wxCOPY); } else { // dy < 0 dc.Blit(m_xPos + dx, m_yPos + dy + CardHeight, CardWidth - dx, -dy, &memoryDC, dx, CardHeight + dy, wxCOPY); memoryDC.Blit(0, -dy, CardWidth - dx, CardHeight + dy, &memoryDC, dx, 0, wxCOPY); memoryDC.Blit(0, 0, CardWidth - dx, -dy, &dc, m_xPos + dx, m_yPos + dy, wxCOPY); } memoryDC.Blit(CardWidth - dx, 0, dx, CardHeight, &dc, m_xPos + CardWidth, m_yPos + dy, wxCOPY); } else { // dx < 0 dc.Blit(m_xPos + CardWidth + dx, m_yPos, -dx, CardHeight, &memoryDC, CardWidth + dx, 0, wxCOPY); if (dy >= 0) { dc.Blit(m_xPos, m_yPos, CardWidth + dx, dy, &memoryDC, 0, 0, wxCOPY); memoryDC.Blit(-dx, 0, CardWidth + dx, CardHeight - dy, &memoryDC, 0, dy, wxCOPY); memoryDC.Blit(-dx, CardHeight - dy, CardWidth + dx, dy, &dc, m_xPos, m_yPos + CardHeight, wxCOPY); } else { // dy < 0 dc.Blit(m_xPos, m_yPos + CardHeight + dy, CardWidth + dx, -dy, &memoryDC, 0, CardHeight + dy, wxCOPY); memoryDC.Blit(-dx, -dy, CardWidth + dx, CardHeight + dy, &memoryDC, 0, 0, wxCOPY); memoryDC.Blit(-dx, 0, CardWidth + dx, -dy, &dc, m_xPos, m_yPos + dy, wxCOPY); } memoryDC.Blit(0, 0, -dx, CardHeight, &dc, m_xPos + dx, m_yPos + dy, wxCOPY); } m_xPos += dx; m_yPos += dy; // draw the card in its new position memoryDC.SelectObject(*m_bmapCard); dc.Blit(m_xPos, m_yPos, CardWidth, CardHeight, &memoryDC, 0, 0, wxCOPY); } }
// Called when the left button is released after dragging a card // Scan the piles to see if this card overlaps a pile and can be added // to the pile. If the card overlaps more than one pile on which it can be placed // then put it on the nearest pile. void Game::LButtonUp(wxDC& dc, int x, int y) { if (m_srcPile) { // work out the position of the dragged card x += m_xOffset; y += m_yOffset; Pile* nearestPile = 0; int distance = (CardHeight + CardWidth) * (CardHeight + CardWidth); // find the nearest pile which will accept the card int i; for (i = 0; i < 8; i++) { if (DropCard(x, y, m_foundations[i], m_liftedCard)) { if (m_foundations[i]->CalcDistance(x, y) < distance) { nearestPile = m_foundations[i]; distance = nearestPile->CalcDistance(x, y); } } } for (i = 0; i < 10; i++) { if (DropCard(x, y, m_bases[i], m_liftedCard)) { if (m_bases[i]->CalcDistance(x, y) < distance) { nearestPile = m_bases[i]; distance = nearestPile->CalcDistance(x, y); } } } // Restore the area under the card wxMemoryDC memoryDC; memoryDC.SelectObject(*m_bmap); dc.Blit(m_xPos, m_yPos, CardWidth, CardHeight, &memoryDC, 0, 0, wxCOPY); // Draw the card in its new position if (nearestPile) { // Add to new pile nearestPile->AddCard(dc, m_liftedCard); if (nearestPile != m_srcPile) { DoMove(dc, m_srcPile, nearestPile); } } else { // Return card to src pile m_srcPile->AddCard(dc, m_liftedCard); } m_srcPile = 0; m_liftedCard = 0; } }
//+-------------------------------------------------------------+ //| Card::Draw() | //+-------------------------------------------------------------+ //| Description: | //| Draw the card at (x, y). | //| If the card is facedown draw the back of the card. | //| If the card is faceup draw the front of the card. | //| Cards are not held in bitmaps, instead they are drawn | //| from their constituent parts when required. | //| hbmap_symbols contains large and small suit symbols and | //| pip values. These are copied to the appropriate part of | //| the card. Picture cards use the pictures defined in | //| hbmap_pictures. Note that only one picture is defined | //| for the Jack, Queen and King, unlike a real pack where | //| each suit is different. | //| | //| WARNING: | //| The locations of these symbols is 'hard-wired' into the | //| code. Editing the bitmaps or the numbers below will | //| result in the wrong symbols being displayed. | //+-------------------------------------------------------------+ void Card::Draw(wxDC& dc, int x, int y) { wxBrush backgroundBrush( dc.GetBackground() ); dc.SetBrush(* wxWHITE_BRUSH); dc.SetPen(* wxBLACK_PEN); dc.DrawRoundedRectangle(x, y, m_width, m_height, 4); if (m_wayUp == facedown) { dc.SetBackground(* wxRED_BRUSH); dc.SetBackgroundMode(wxSOLID); wxBrush* brush = wxTheBrushList->FindOrCreateBrush( *wxBLACK, wxCROSSDIAG_HATCH ); dc.SetBrush(* brush); dc.DrawRoundedRectangle( x + 4, y + 4, m_width - 8, m_height - 8, 2 ); } else { wxMemoryDC memoryDC; memoryDC.SelectObject(*m_symbolBmap); // dc.SetBackgroundMode(wxTRANSPARENT); dc.SetTextBackground(*wxWHITE); switch (m_suit) { case spades: case clubs: dc.SetTextForeground(*wxBLACK); break; case diamonds: case hearts: dc.SetTextForeground(*wxRED); break; } int symsize = 11; int sympos = 14; int sympos2 = 25; int symdist = 5; int symdist2 = 6; int pipsize,pippos,valueheight,valuewidth; int valuepos; if (m_scale > 1.2) { pipsize = symsize; pippos = sympos; valueheight = 10; valuewidth = 9; valuepos = 50; } else { pipsize = 7; pippos = 0; valueheight = 7; valuewidth = 6; valuepos = 36; } // Draw the value dc.Blit((wxCoord)(x + m_scale*3), (wxCoord)(y + m_scale*3), valuewidth, valueheight, &memoryDC, valuewidth * (m_pipValue - 1), valuepos, wxCOPY); dc.Blit((wxCoord)(x + m_width - m_scale*3 - valuewidth), (wxCoord)(y + m_height - valueheight - m_scale*3), valuewidth, valueheight, &memoryDC, valuewidth * (m_pipValue - 1), valuepos+valueheight, wxCOPY); // Draw the pips dc.Blit((wxCoord)(x + m_scale*3 + valuewidth+2), (wxCoord)(y + m_scale*3), pipsize, pipsize, &memoryDC, pipsize * m_suit, pippos, wxCOPY); dc.Blit((wxCoord)(x + m_width - m_scale*3-valuewidth-pipsize-2), (wxCoord)(y + m_height - pipsize - m_scale*3), pipsize, pipsize, &memoryDC, pipsize * m_suit, pipsize+pippos, wxCOPY); switch (m_pipValue) { case 1: dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - m_scale*5 + m_height / 2), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); break; case 3: dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - symdist + m_height / 2), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); case 2: dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - symdist + m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); break; case 5: dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - symdist + m_height / 2), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); case 4: dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist + m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), (wxCoord)(y - symdist + m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); break; case 8: dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10), (wxCoord)(y - symdist + 5 * m_height / 8), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); case 7: dc.Blit((wxCoord)(x - symdist + 5 * m_width / 10), (wxCoord)(y - symdist + 3 * m_height / 8), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); case 6: dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist + m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist + m_height / 2), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), (wxCoord)(y - symdist + m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), (wxCoord)(y - symdist + m_height / 2), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); break; case 10: dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - symdist + 2 * m_height / 3), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); case 9: dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist2 + m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist2 + 5 * m_height / 12), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist + 7 * m_height / 12), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); dc.Blit((wxCoord)(x - symdist + m_width / 4), (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), (wxCoord)(y - symdist2 + m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), (wxCoord)(y - symdist2 + 5 * m_height / 12), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), (wxCoord)(y - symdist + 7 * m_height / 12), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); dc.Blit((wxCoord)(x - symdist + 3 * m_width / 4), (wxCoord)(y - symdist + 3 * m_height / 4), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); dc.Blit((wxCoord)(x - symdist + m_width / 2), (wxCoord)(y - symdist + m_height / 3), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); break; case 11: case 12: case 13: memoryDC.SelectObject(*m_pictureBmap); int picwidth = 40,picheight = 45; dc.Blit((wxCoord)(x + (m_width-picwidth)/2), (wxCoord)(y - picheight/2 + m_height/2), picwidth, picheight, &memoryDC, picwidth * (m_pipValue - 11), 0, wxCOPY); memoryDC.SelectObject(*m_symbolBmap); dc.Blit((wxCoord)(x + m_width-(m_width-picwidth)/2-symsize-3), (wxCoord)(y - picheight/2+m_height/2+1), symsize, symsize, &memoryDC, symsize * m_suit, sympos, wxCOPY); dc.Blit((wxCoord)(x + (m_width-picwidth)/2+2), (wxCoord)(y + picheight/2 + m_height/2-symsize), symsize, symsize, &memoryDC, symsize * m_suit, sympos2, wxCOPY); break; } } dc.SetBackground( backgroundBrush ); } // Card:Draw()
void GutterCtrl::DrawGutter(wxDC& dc) { const Lines& lines = m_editorCtrl.GetLines(); const wxSize size = GetClientSize(); m_mdc.Clear(); const unsigned int bg_xpos = m_gutterLeft ? size.x-1 : 0; const unsigned int edge_xpos = m_gutterLeft ? size.x-2 : 1; // Draw the edge m_mdc.SetPen(m_theme.backgroundColor); m_mdc.DrawLine(bg_xpos, 0, bg_xpos, size.y); m_mdc.SetPen(m_edgecolor); m_mdc.DrawLine(edge_xpos, 0, edge_xpos, size.y); // Draw the line numbers m_mdc.SetTextForeground(m_numbercolor); wxString number; const int scrollPos = m_editorCtrl.GetYScrollPos(); const unsigned int firstline = lines.GetLineFromYPos(scrollPos); const unsigned int linecount = lines.GetLineCount(); // Prepare for foldings const vector<cxFold>& folds = m_editorCtrl.GetFolds(); vector<cxFold>::const_iterator nextFold = folds.begin(); const unsigned int line_middle = lines.GetLineHeight() / 2; vector<const cxFold*> foldStack; if (m_showFolds) { m_editorCtrl.UpdateFolds(); #ifdef __WXDEBUG__ bool debug = false; if (debug) { for (vector<cxFold>::const_iterator f = folds.begin(); f != folds.end(); ++f) { const wxString indent(wxT('.'), f->indent); wxLogDebug(wxT("%d: %s%d"), f->line_id, indent.c_str(), f->type); } } #endif for (nextFold = folds.begin(); nextFold != folds.end() && nextFold->line_id < firstline; ++nextFold) { if (nextFold->type != cxFOLD_END) { foldStack.push_back(&*nextFold); continue; } // check if end marker matches any starter on the stack for (vector<const cxFold*>::reverse_iterator p = foldStack.rbegin(); p != foldStack.rend(); ++p) { if ((*p)->indent != nextFold->indent) continue; foldStack.erase(p.base()-1, foldStack.end()); // pop break; } } } // Prepare for bookmarks const vector<cxBookmark>& bookmarks = m_editorCtrl.GetBookmarks(); vector<cxBookmark>::const_iterator nextBookmark = bookmarks.begin(); while(nextBookmark != bookmarks.end() && nextBookmark->line_id < firstline) ++nextBookmark; // Draw each line for (unsigned int i = firstline; i < linecount; ++i) { number.Printf(wxT("%*u"), m_max_digits, i+1); const int ypos = lines.GetYPosFromLine(i) - scrollPos; if (ypos > size.y) break; // Highlight selections if (m_currentSel != -1 && ((i >= m_sel_startline && i <= m_sel_endline) || (i >= m_sel_endline && i <= m_sel_startline))) { const int ypos2 = lines.GetBottomYPosFromLine(i) - scrollPos; m_mdc.SetPen(m_hlightcolor); m_mdc.SetBrush(wxBrush(m_hlightcolor, wxSOLID)); m_mdc.DrawRectangle(0, ypos, size.x-2, ypos2-ypos); } // Draw bookmark if (m_showBookmarks && nextBookmark != bookmarks.end() && nextBookmark->line_id == i) { //m_mdc.DrawText(wxT("\u066D"), 3, ypos); m_mdc.DrawBitmap(m_bmBookmark, 2, ypos + line_middle - 5); ++nextBookmark; } // Draw the line number m_mdc.DrawText(number, m_numberX, ypos); // Draw fold markers if (m_showFolds) { bool drawFoldLine = (!foldStack.empty()); if (nextFold != folds.end() && nextFold->line_id == i) { if (nextFold->type == cxFOLD_START) { const int ypos2 = lines.GetBottomYPosFromLine(i) - scrollPos; const unsigned int box_y = ypos + line_middle - 5; m_mdc.DrawBitmap(m_bmFoldOpen, m_foldStartX, box_y); if (&*nextFold == m_currentFold) m_mdc.SetPen(wxPen(m_edgecolor, 2)); else m_mdc.SetPen(m_edgecolor); m_mdc.DrawLine(m_foldStartX+4, box_y+9, m_foldStartX+4, ypos2); foldStack.push_back(&*nextFold); drawFoldLine = false; ++nextFold; } else if (nextFold->type == cxFOLD_START_FOLDED) { const unsigned int box_y = ypos + line_middle - 5; m_mdc.DrawBitmap(m_bmFoldClosed, m_foldStartX, box_y); drawFoldLine = false; // Advance to end of fold i += nextFold->count; while (nextFold != folds.end() && nextFold->line_id <= i) ++nextFold; } else if (nextFold->type == cxFOLD_END) { if (!foldStack.empty()) { // check if end marker matches any starter on the stack (ignore unmatched) for (vector<const cxFold*>::reverse_iterator f = foldStack.rbegin(); f != foldStack.rend(); ++f) { if (nextFold->indent == (*f)->indent) { vector<const cxFold*>::iterator fb = (++f).base(); // Check if we should highlight fold line if (*fb == m_currentFold) m_mdc.SetPen(wxPen(m_edgecolor, 2)); else m_mdc.SetPen(m_edgecolor); // If we are closing other folds, we want to leave a gap const unsigned int ytop = (fb < foldStack.end()-1) ? ypos + 2 : ypos; // Draw end marker const unsigned int middle_y = ypos + line_middle+1; m_mdc.DrawLine(m_foldStartX+4, ytop, m_foldStartX+4, middle_y); m_mdc.DrawLine(m_foldStartX+4, middle_y, m_foldStartX+9, middle_y); foldStack.erase(fb, foldStack.end()); // pop drawFoldLine = false; break; } } } ++nextFold; } } if (drawFoldLine) { const int ypos2 = lines.GetBottomYPosFromLine(i) - scrollPos; // Check if we should highlight fold line if (!foldStack.empty() && foldStack.back() == m_currentFold) { m_mdc.SetPen(wxPen(m_edgecolor, 2)); } else m_mdc.SetPen(m_edgecolor); m_mdc.DrawLine(m_foldStartX+4, ypos, m_foldStartX+4, ypos2); } } } // Copy MemoryDC to Display #ifdef __WXMSW__ ::BitBlt(GetHdcOf(dc), 0, 0,(int)size.x, (int)size.y, GetHdcOf(m_mdc), 0, 0, SRCCOPY); #else dc.Blit(0, 0, size.x, size.y, &m_mdc, 0, 0); #endif }
void VideoSlider::DrawImage(wxDC &destdc) { int w,h; GetClientSize(&w,&h); // Back buffer wxMemoryDC dc; wxBitmap bmp(w,h); dc.SelectObject(bmp); // Colors wxColour shad = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW); wxColour high = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); wxColour face = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); wxColour sel(123,251,232); wxColour notSel(sel.Red()*2/5,sel.Green()*2/5,sel.Blue()*2/5); wxColour bord(0,0,0); int x1,x2,y1,y2; // Background dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(face); dc.DrawRectangle(0,0,w,h); // Selection border bool selected = wxWindow::FindFocus() == this; if (selected) { dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetPen(wxPen(shad,1,wxDOT)); dc.DrawRectangle(0,0,w,h); } // Draw slider x1 = 5; x2 = w-5; y1 = 8; y2 = h-8; dc.SetPen(wxPen(shad)); dc.DrawLine(x1,y1,x2,y1); dc.DrawLine(x1,y1,x1,y2); dc.SetPen(wxPen(high)); dc.DrawLine(x1,y2,x2,y2); dc.DrawLine(x2,y1,x2,y2); // Draw keyframes int curX; if (OPT_GET("Video/Slider/Show Keyframes")->GetBool()) { dc.SetPen(wxPen(shad)); for (size_t i=0;i<keyframes.size();i++) { curX = GetXAtValue(keyframes[i]); dc.DrawLine(curX,2,curX,8); } } // Draw cursor curX = GetXAtValue(val); // Fill bg dc.SetBrush(wxBrush(face)); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(curX-2,y1-1,4,y2-y1+5); dc.SetBrush(wxNullBrush); // Draw cursor highlights dc.SetPen(wxPen(high)); dc.DrawLine(curX,y1-2,curX-4,y1+2); dc.DrawLine(curX-3,y1+2,curX-3,y2+5); // Draw cursor shades dc.SetPen(wxPen(shad)); dc.DrawLine(curX+1,y1-1,curX+4,y1+2); dc.DrawLine(curX+3,y1+2,curX+3,y2+5); dc.DrawLine(curX-3,y2+4,curX+3,y2+4); // Draw cursor outline dc.SetPen(wxPen(bord)); dc.DrawLine(curX,y1-3,curX-4,y1+1); dc.DrawLine(curX,y1-3,curX+4,y1+1); dc.DrawLine(curX-4,y1+1,curX-4,y2+5); dc.DrawLine(curX+4,y1+1,curX+4,y2+5); dc.DrawLine(curX-3,y2+5,curX+4,y2+5); dc.DrawLine(curX-3,y2,curX+4,y2); // Draw selection dc.SetPen(*wxTRANSPARENT_PEN); if (selected) dc.SetBrush(wxBrush(sel)); else dc.SetBrush(wxBrush(notSel)); dc.DrawRectangle(curX-3,y2+1,7,4); // Draw final destdc.Blit(0,0,w,h,&dc,0,0); }
bool wxMenuItem::OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction WXUNUSED(act), wxODStatus stat) { const MenuDrawData* data = MenuDrawData::Get(); wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); HDC hdc = GetHdcOf(*impl); RECT rect; wxCopyRectToRECT(rc, rect); int imgWidth = wxMax(GetMarginWidth(), data->CheckSize.cx); if ( IsOwnerDrawn() ) { // font and colors to use wxFont font; GetFontToUse(font); wxColour colText, colBack; GetColourToUse(stat, colText, colBack); // calculate metrics of item parts RECT rcSelection = rect; data->ItemMargin.ApplyTo(rcSelection); RECT rcSeparator = rcSelection; data->SeparatorMargin.ApplyTo(rcSeparator); RECT rcGutter = rcSelection; rcGutter.right = data->ItemMargin.cxLeftWidth + data->CheckBgMargin.cxLeftWidth + data->CheckMargin.cxLeftWidth + imgWidth + data->CheckMargin.cxRightWidth + data->CheckBgMargin.cxRightWidth; RECT rcText = rcSelection; rcText.left = rcGutter.right + data->TextBorder; // we draw the text label vertically centered, but this results in it // being 1px too low compared to native menus for some reason, fix it if ( data->MenuLayout() != MenuDrawData::FullTheme ) rcText.top--; #if wxUSE_UXTHEME // If a custom background colour is explicitly specified, we should use // it instead of the default theme background. wxUxThemeEngine* const theme = GetBackgroundColour().IsOk() ? NULL : MenuDrawData::GetUxThemeEngine(); if ( theme ) { POPUPITEMSTATES state; if ( stat & wxODDisabled ) { state = (stat & wxODSelected) ? MPI_DISABLEDHOT : MPI_DISABLED; } else if ( stat & wxODSelected ) { state = MPI_HOT; } else { state = MPI_NORMAL; } wxUxThemeHandle hTheme(GetMenu()->GetWindow(), L"MENU"); if ( theme->IsThemeBackgroundPartiallyTransparent(hTheme, MENU_POPUPITEM, state) ) { theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPBACKGROUND, 0, &rect, NULL); } theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPGUTTER, 0, &rcGutter, NULL); if ( IsSeparator() ) { rcSeparator.left = rcGutter.right; theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPSEPARATOR, 0, &rcSeparator, NULL); return true; } theme->DrawThemeBackground(hTheme, hdc, MENU_POPUPITEM, state, &rcSelection, NULL); } else #endif // wxUSE_UXTHEME { if ( IsSeparator() ) { DrawEdge(hdc, &rcSeparator, EDGE_ETCHED, BF_TOP); return true; } AutoHBRUSH hbr(colBack.GetPixel()); SelectInHDC selBrush(hdc, hbr); ::FillRect(hdc, &rcSelection, hbr); } // draw text label // using native API because it recognizes '&' HDCTextColChanger changeTextCol(hdc, colText.GetPixel()); HDCBgColChanger changeBgCol(hdc, colBack.GetPixel()); HDCBgModeChanger changeBgMode(hdc, TRANSPARENT); SelectInHDC selFont(hdc, GetHfontOf(font)); // item text name without mnemonic for calculating size wxString text = GetName(); SIZE textSize; ::GetTextExtentPoint32(hdc, text.c_str(), text.length(), &textSize); // item text name with mnemonic text = GetItemLabel().BeforeFirst('\t'); int flags = DST_PREFIXTEXT; // themes menu is using specified color for disabled labels if ( data->MenuLayout() == MenuDrawData::Classic && (stat & wxODDisabled) && !(stat & wxODSelected) ) flags |= DSS_DISABLED; if ( (stat & wxODHidePrefix) && !data->AlwaysShowCues ) flags |= DSS_HIDEPREFIX; int x = rcText.left; int y = rcText.top + (rcText.bottom - rcText.top - textSize.cy) / 2; ::DrawState(hdc, NULL, NULL, wxMSW_CONV_LPARAM(text), text.length(), x, y, 0, 0, flags); // ::SetTextAlign(hdc, TA_RIGHT) doesn't work with DSS_DISABLED or DSS_MONO // as the last parameter in DrawState() (at least with Windows98). So we have // to take care of right alignment ourselves. wxString accel = GetItemLabel().AfterFirst(wxT('\t')); if ( !accel.empty() ) { SIZE accelSize; ::GetTextExtentPoint32(hdc, accel.c_str(), accel.length(), &accelSize); flags = DST_TEXT; // themes menu is using specified color for disabled labels if ( data->MenuLayout() == MenuDrawData::Classic && (stat & wxODDisabled) && !(stat & wxODSelected) ) flags |= DSS_DISABLED; x = rcText.right - data->ArrowMargin.GetTotalX() - data->ArrowSize.cx - data->ArrowBorder; // right align accel on FullTheme menu, left otherwise if ( data->MenuLayout() == MenuDrawData::FullTheme) x -= accelSize.cx; else x -= m_parentMenu->GetMaxAccelWidth(); y = rcText.top + (rcText.bottom - rcText.top - accelSize.cy) / 2; ::DrawState(hdc, NULL, NULL, wxMSW_CONV_LPARAM(accel), accel.length(), x, y, 0, 0, flags); } } // draw the bitmap RECT rcImg; SetRect(&rcImg, rect.left + data->ItemMargin.cxLeftWidth + data->CheckBgMargin.cxLeftWidth + data->CheckMargin.cxLeftWidth, rect.top + data->ItemMargin.cyTopHeight + data->CheckBgMargin.cyTopHeight + data->CheckMargin.cyTopHeight, rect.left + data->ItemMargin.cxLeftWidth + data->CheckBgMargin.cxLeftWidth + data->CheckMargin.cxLeftWidth + imgWidth, rect.bottom - data->ItemMargin.cyBottomHeight - data->CheckBgMargin.cyBottomHeight - data->CheckMargin.cyBottomHeight); if ( IsCheckable() && !m_bmpChecked.IsOk() ) { if ( stat & wxODChecked ) { DrawStdCheckMark((WXHDC)hdc, &rcImg, stat); } } else { wxBitmap bmp; if ( stat & wxODDisabled ) { bmp = GetDisabledBitmap(); } if ( !bmp.IsOk() ) { // for not checkable bitmaps we should always use unchecked one // because their checked bitmap is not set bmp = GetBitmap(!IsCheckable() || (stat & wxODChecked)); #if wxUSE_IMAGE if ( bmp.IsOk() && stat & wxODDisabled ) { // we need to grey out the bitmap as we don't have any specific // disabled bitmap wxImage imgGrey = bmp.ConvertToImage().ConvertToGreyscale(); if ( imgGrey.IsOk() ) bmp = wxBitmap(imgGrey); } #endif // wxUSE_IMAGE } if ( bmp.IsOk() ) { wxMemoryDC dcMem(&dc); dcMem.SelectObjectAsSource(bmp); // center bitmap int nBmpWidth = bmp.GetWidth(), nBmpHeight = bmp.GetHeight(); int x = rcImg.left + (imgWidth - nBmpWidth) / 2; int y = rcImg.top + (rcImg.bottom - rcImg.top - nBmpHeight) / 2; dc.Blit(x, y, nBmpWidth, nBmpHeight, &dcMem, 0, 0, wxCOPY, true); } } return true; }
//--------------------------------------------------------------------------- void wxPagedWindow::DrawDecorations( wxDC& dc ) { // FIXME:: the is big body have to be split! int width, height; GetClientSize( &width, &height ); int curX = mHorizGap; int curY = mVertGap; int xSize = width - mHorizGap*2; int ySize = height - mVertGap*2; DrawShadedRect( curX, curY, xSize, ySize, mDarkPen, mWhitePen, dc ); DrawShadedRect( curX+1, curY+1, xSize-2, ySize-2, mBlackPen, mGrayPen, dc ); // draw inactive tab title bars frist (left-to-right) wxObjectList::compatibility_iterator pNode = mTabs.GetFirst(); size_t tabNo = 0; /* OLD STUFF:: curX = mTitleRowStart; curY = height - mVertGap - BORDER_SZ - mTitleHeight; */ curX = mTabTrianGap; curY = 0; // FOR NOW:: avoid creating bitmap with invalid dimensions if ( mTitleRowLen < 1 || mTitleHeight < 1 ) return; wxMemoryDC tmpDc; wxBitmap tmpBmp( mTitleRowLen, mTitleHeight ); tmpDc.SelectObject( tmpBmp ); tmpDc.SetPen( mGrayPen ); tmpDc.SetBrush( mGrayBrush ); tmpDc.DrawRectangle( 0,0, mTitleRowLen, mTitleHeight ); tmpDc.SetDeviceOrigin( mCurentRowOfs, 0 ); while( pNode ) { twTabInfo& tab = *((twTabInfo*)(pNode->GetData())); if ( tabNo != mActiveTab ) DrawPaperBar( tab, curX, curY, mGrayBrush, mBlackPen, tmpDc ); curX += tab.mDims.x; pNode = pNode->GetNext(); ++tabNo; } // finally, draw the active tab (white-filled) pNode = mTabs.GetFirst(); tabNo = 0; curX = mTabTrianGap; while( pNode ) { twTabInfo& tab = *((twTabInfo*)(pNode->GetData())); if ( tabNo == mActiveTab ) { DrawPaperBar( tab, curX, curY, mWhiteBrush, mBlackPen, tmpDc ); tmpDc.SetPen( mWhitePen ); tmpDc.DrawLine( curX - mTabTrianGap+1, curY, curX + tab.mDims.x + mTabTrianGap, curY ); break; } curX += tab.mDims.x; pNode = pNode->GetNext(); ++tabNo; } // back to initial device origin tmpDc.SetDeviceOrigin( 0, 0 ); // draw resize-hint-stick curX = mTitleRowLen - 6; DrawShadedRect( curX+0, 0+0, 6, mTitleHeight, mGrayPen, mBlackPen, tmpDc ); DrawShadedRect( curX+1, 0+1, 6-2, mTitleHeight-2, mWhitePen, mDarkPen, tmpDc ); DrawShadedRect( curX+2, 0+2, 6-4, mTitleHeight-4, mGrayPen, mGrayPen, tmpDc ); dc.Blit( mTitleRowStart, height - mVertGap - BORDER_SZ - mTitleHeight, mTitleRowLen, mTitleHeight, &tmpDc, 0,0, wxCOPY ); } // wxPagedWindow::DrawDecorations()
void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource) { wxRect r = wxRectFromPRectangle(rc); hdc->Blit(r.x, r.y, r.width, r.height, ((SurfaceImpl&)surfaceSource).hdc, from.x, from.y, wxCOPY); }
//--------------------------------------------------------------------------- void wxTabbedWindow::DrawDecorations( wxDC& dc ) { // Protability NOTE::: DrawLine(..) draws a line from the first position, // but not including the point specified by last position. // This way Windows draws lines, not sure how Motif and Gtk // prots behave... int width, height; GetClientSize( &width, &height ); // check if there's at least a bit of space to draw things if ( width < mHorizGap*2 + BORDER_SZ*2+1 || height < mVertGap*2 + BORDER_SZ*2+1 + mTitleHeight ) return; // step #1 - draw border around the tab content area // setup position for kind of "pencil" int curX = mHorizGap; int curY = mVertGap; int xSize = width - mHorizGap*2; int ySize = height - mVertGap *2 - mTitleHeight; // layer 1 (upper white) DrawShadedRect( curX+0, curY+0, xSize-0, ySize-0, mWhitePen, mBlackPen, dc ); // layer 2 (upper gray) DrawShadedRect( curX+1, curY+1, xSize-2-1, ySize-2-1, mGrayPen, mGrayPen, dc ); // layer 3 (upper darkGray) DrawShadedRect( curX+2, curY+2, xSize-3-2, ySize-3-2, mDarkPen, mWhitePen, dc ); // layer 4 (upper black) DrawShadedRect( curX+3, curY+3, xSize-4-3, ySize-4-3, mBlackPen, mGrayPen, dc ); // add non-siemtric layer from the lower-right side (confroming to MFC-look) dc.SetPen( mDarkPen ); dc.DrawLine( curX+1, curY + ySize - 2, curX + xSize - 1, curY + ySize - 2 ); // horiz dc.DrawLine( curX + xSize - 2, curY + 1, curX + xSize - 2, curY + ySize - 2 ); // vert // step #2 - draw tab title bars curX = mFirstTitleGap; curY = height - mVertGap - mTitleHeight; size_t tabNo = 0; wxObjectList::compatibility_iterator pNode = mTabs.GetFirst(); while( pNode ) { // "hard-coded metafile" for decorations twTabInfo& tab = *((twTabInfo*)(pNode->GetData())); xSize = tab.mDims.x; ySize = mTitleHeight; if ( tabNo == mActiveTab ) { dc.SetPen( mGrayPen ); dc.DrawLine( curX+1, curY-2, curX+xSize-2, curY-2 ); dc.DrawLine( curX+1, curY-1, curX+xSize-2, curY-1 ); } dc.SetPen( mWhitePen ); if ( tabNo == mActiveTab ) dc.DrawLine( curX, curY-2, curX, curY+ySize-2 ); else dc.DrawLine( curX, curY, curX, curY+ySize-2 ); dc.SetPen( mDarkPen ); dc.DrawLine( curX+1, curY+ySize-3, curX+1, curY+ySize-1 ); // to pix down dc.DrawLine( curX+2, curY+ySize-2, curX+xSize-2, curY+ySize-2 ); dc.DrawLine( curX+xSize-3, curY+ySize-3, curX+xSize-2, curY+ySize-3 ); if ( tabNo == mActiveTab ) dc.DrawLine( curX+xSize-2, curY+ySize-3, curX+xSize-2, curY-3 ); else dc.DrawLine( curX+xSize-2, curY+ySize-3, curX+xSize-2, curY-1 ); dc.SetPen( mBlackPen ); dc.DrawLine( curX+xSize-1, curY, curX+xSize-1, curY+ySize-2 ); dc.DrawLine( curX+xSize-2, curY+ySize-2, curX+xSize-3, curY+ySize-2 ); dc.DrawLine( curX+xSize-3, curY+ySize-1, curX+1, curY+ySize-1 ); pNode = pNode->GetNext(); ++tabNo; // darw image and (or without) text centered within the // title bar rectangle if ( mLayoutType != wxTITLE_BORDER_ONLY && tab.HasImg() ) { wxMemoryDC tmpDc; tmpDc.SelectObject( tab.GetImg() ); dc.Blit( curX + mTitleHorizGap, curY + ( ySize - tab.ImgHeight() ) / 2, tab.ImgWidth(), tab.ImgHeight(), &tmpDc, 0, 0, wxCOPY ); } if ( mLayoutType == wxTITLE_IMG_AND_TEXT && tab.HasText() ) { long x,w,h; // set select default font of the window into it's device context //dc.SetFont( GetLabelingFont() ); dc.SetTextBackground( GetBackgroundColour() ); dc.GetTextExtent(tab.mText, &w, &h ); x = curX + mTitleHorizGap + tab.ImgWidth() + tab.ImageToTxtGap(mImageTextGap); dc.DrawText( tab.GetText(), x, curY + ( ySize - h ) / 2 ); } curX += xSize; } // end of `while (pNode)' } // wxTabbedWindow::DrawDecorations()