void CardButton::DrawRect(HDC hdc, RECT *rect, bool fNormal) { RECT fill; HANDLE hOld; HPEN hhi = CreatePen(0, 0, MAKE_PALETTERGB(crHighlight)); HPEN hsh = CreatePen(0, 0, MAKE_PALETTERGB(crShadow)); HPEN hbl = (HPEN)GetStockObject(BLACK_PEN); int x = rect->left; int y = rect->top; int width = rect->right-rect->left - 1; int height = rect->bottom-rect->top - 1; SetRect(&fill, x+1, y+1, x+width-1, y+height-1); int one = 1; if(!fNormal) { x += width; y += height; width = -width; height = -height; one = -1; OffsetRect(&fill, 1, 1); } if(fNormal) hOld = SelectObject(hdc, hhi); else hOld = SelectObject(hdc, hhi); MoveToEx(hdc, x, y+height, 0); LineTo(hdc, x, y); LineTo(hdc, x+width, y); SelectObject(hdc, hOld); hOld = SelectObject(hdc, hbl); LineTo(hdc, x+width, y+height); LineTo(hdc, x-one, y+height); SelectObject(hdc, hOld); hOld = SelectObject(hdc, hsh); MoveToEx(hdc, x+one, y+height-one, 0); LineTo(hdc, x+width-one, y+height-one); LineTo(hdc, x+width-one, y); SelectObject(hdc, hOld); PaintRect(hdc, &fill, MAKE_PALETTERGB(crBack)); DeleteObject(hhi); DeleteObject(hsh); }
void CardWindow::PaintCardRgn(HDC hdc, int dx, int dy, int width, int height, int sx, int sy) { RECT rect; //if just a solid background colour if(hbmBackImage == 0) { SetRect(&rect, dx, dy, dx+width, dy+height); /*if(GetVersion() < 0x80000000) { PaintRect(hdc, &rect, MAKE_PALETTERGB(crBackgnd)); } else*/ { HBRUSH hbr = CreateSolidBrush(MAKE_PALETTERGB(crBackgnd)); FillRect(hdc, &rect, hbr); DeleteObject(hbr); } } //otherwise, paint using the bitmap else { // Draw whatever part of background we can BitBlt(hdc, dx, dy, width, height, hdcBackImage, sx, sy, SRCCOPY); // Now we need to paint any area outside the bitmap, // just in case the bitmap is too small to fill whole window if(0)//sx + width > bm.bmWidth || sy + height > bm.bmHeight) { // Find out size of bitmap BITMAP bm; GetObject(hbmBackImage, sizeof(bm), &bm); HRGN hr1 = CreateRectRgn(sx, sy, sx+width, sy+height); HRGN hr2 = CreateRectRgn(0, 0, bm.bmWidth, bm.bmHeight); HRGN hr3 = CreateRectRgn(0,0, 1, 1); HRGN hr4 = CreateRectRgn(0,0, 1, 1); CombineRgn(hr3, hr1, hr2, RGN_DIFF); GetClipRgn(hdc, hr4); CombineRgn(hr3, hr4, hr3, RGN_AND); SelectClipRgn(hdc, hr3); // Fill remaining space not filled with bitmap HBRUSH hbr = CreateSolidBrush(crBackgnd); FillRgn(hdc, hr3, hbr); DeleteObject(hbr); // Clean up SelectClipRgn(hdc, hr4); DeleteObject(hr1); DeleteObject(hr2); DeleteObject(hr3); DeleteObject(hr4); } } }
void CardButton::Draw(HDC hdc, bool fNormal) { SIZE textsize; int x, y; //text x, y int ix, iy; //icon x, y int iconwidth = 0; RECT cliprect; if(fVisible == 0) return; if(hFont == 0) SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT)); else SelectObject(hdc, hFont); GetTextExtentPoint32(hdc, szText, lstrlen(szText), &textsize); if(hIcon) { x = rect.left + 32 + 8; } else { if(uStyle & CB_ALIGN_LEFT) { x = rect.left + iconwidth; } else if(uStyle & CB_ALIGN_RIGHT) { x = rect.left + (rect.right-rect.left-iconwidth-textsize.cx); } else //centered { x = rect.right - rect.left - iconwidth; x = (x - textsize.cx) / 2; x += rect.left + iconwidth; } } y = rect.bottom - rect.top; y = (y - textsize.cy) / 2; y += rect.top; //calc icon position.. ix = rect.left + 4; iy = rect.top + (rect.bottom-rect.top-32) / 2; //if button is pressed, then shift text if(fNormal == false && (uStyle & CB_PUSHBUTTON)) { x += 1; y += 1; ix += 1; iy += 1; } SetRect(&cliprect, x, y, x+textsize.cx, y+textsize.cy); ExcludeClipRect(hdc, x, y, x+textsize.cx, y+textsize.cy); // // Calc icon pos // if(hIcon) { ExcludeClipRect(hdc, ix, iy, ix + 32, iy + 32); } if(uStyle & CB_PUSHBUTTON) { DrawRect(hdc, &rect, fNormal); SetBkColor(hdc, MAKE_PALETTERGB(crBack)); SetTextColor(hdc, crText);//MAKE_PALETTERGB(crText)); SelectClipRgn(hdc, 0); ExtTextOut(hdc, x, y, ETO_OPAQUE, &cliprect, szText, lstrlen(szText), 0); } else { SetBkColor(hdc, MAKE_PALETTERGB(crBack)); SetTextColor(hdc, crText);//MAKE_PALETTERGB(crText)); SelectClipRgn(hdc, 0); ExtTextOut(hdc, x, y, ETO_OPAQUE, &rect, szText, lstrlen(szText), 0); } if(hIcon) { HBRUSH hbr = CreateSolidBrush(MAKE_PALETTERGB(crBack)); DrawIconEx(hdc, ix, iy, hIcon, 32, 32, 0, hbr, 0); DeleteObject(hbr); } }