void CardWindow::Paint(HDC hdc) { int i; RECT rect; HPALETTE hOldPal; hOldPal = UseNicePalette(hdc, __hPalette); // // Clip the card stacks so that they won't // get painted over // for(i = 0; i < nNumCardRegions; i++) { Regions[i]->Clip(hdc); } // // Clip the buttons // for(i = 0; i < nNumButtons; i++) { Buttons[i]->Clip(hdc); } // Now paint the whole screen with background colour, // GetClientRect(m_hWnd, &rect); //PaintRect(hdc, &rect, MAKE_PALETTERGB(crBackgnd)); PaintCardRgn(hdc, 0, 0, rect.right, rect.bottom, 0, 0); SelectClipRgn(hdc, NULL); // Don't let cards draw over buttons, so clip buttons again // for(i = 0; i < nNumButtons; i++) { Buttons[i]->Clip(hdc); } // Paint each card stack in turn // for(i = 0; i < nNumCardRegions; i++) { Regions[i]->Render(hdc); } // Paint each button now // SelectClipRgn(hdc, NULL); for(i = 0; i < nNumButtons; i++) { Buttons[i]->Redraw(); } RestorePalette(hdc, hOldPal); }
void CardButton::Redraw() { HDC hdc = GetDC((HWND)parentWnd); HPALETTE hOldPal = UseNicePalette(hdc, __hPalette); Draw(hdc, !fButtonDown); RestorePalette(hdc, hOldPal); ReleaseDC((HWND)parentWnd, hdc); }
void CardWindow::SetBackColor(COLORREF cr) { crBackgnd = cr; int i; // // Create the exact palette we need to render the buttons/stacks // RestorePalette(__hdcPlaceHolder, __holdplacepal); if(__hPalette) DeleteObject(__hPalette); __hPalette = CreateCardPalette(); // // re-create the place-holder! HDC hdc = GetDC(m_hWnd); DeleteObject(__hbmPlaceHolder); __holdplacepal = UseNicePalette(__hdcPlaceHolder, __hPalette); __hbmPlaceHolder = CreateSinkBmp(hdc, __hdcPlaceHolder, crBackgnd, __cardwidth, __cardheight); //SelectObject(__hdcPlaceHolder, __hbmPlaceHolder); //reset all buttons to same colour for(i = 0; i < nNumButtons; i++) { if(Buttons[i]->GetStyle() & CB_PUSHBUTTON) { Buttons[i]->SetBackColor(ColorScaleRGB(crBackgnd, RGB(255,255,255), 0.1)); } else { Buttons[i]->SetBackColor(crBackgnd); } } for(i = 0; i < nNumCardRegions; i++) { Regions[i]->SetBackColor(crBackgnd); } ReleaseDC(m_hWnd, hdc); }
CardWindow::CardWindow() : m_hWnd(0) { HDC hdc = GetDC(0); nNumButtons = 0; nNumCardRegions = 0; nNumDropZones = 0; nBackCardIdx = 53; ResizeWndCallback = 0; hbmBackImage = 0; hdcBackImage = 0; srand((unsigned)GetTickCount()); //All colours (buttons, highlights, decks) //are calculated off this single base colour crBackgnd = PALETTERGB(0,80,0);//PALETTERGB(0,64,100); // If uCardBitmapRef was previously zero, then // load the card bitmaps if(1 == InterlockedIncrement(&uCardBitmapRef)) { LoadCardBitmaps(); __hPalette = CreateCardPalette(); __hdcPlaceHolder = CreateCompatibleDC(hdc); __holdplacepal = UseNicePalette(__hdcPlaceHolder, __hPalette); __hbmPlaceHolder = CreateSinkBmp(hdc, __hdcPlaceHolder, crBackgnd, __cardwidth, __cardheight); } ReleaseDC(0, hdc); //register the window class if necessary if(!fRegistered) { fRegistered = true; RegisterCardWindow(); } }
void CardRegion::PrepareDragBitmapsThreed(int numtodrag) { RECT rect; HDC hdc; int icard; int numunder = 0; int iwhichcard; int numcards = cardstack.NumCards(); //work out how big the bitmaps need to be nDragCardWidth = (numtodrag - 1) * abs(xoffset) + __cardwidth; nDragCardHeight = (numtodrag - 1) * abs(yoffset) + __cardheight; //Create bitmap for the back-buffer hdc = GetDC(NULL); hdcBackGnd = CreateCompatibleDC(hdc); hbmBackGnd = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); SelectObject(hdcBackGnd, hbmBackGnd); //create bitmap for the drag-image hdcDragCard = CreateCompatibleDC(hdc); hbmDragCard = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); SelectObject(hdcDragCard, hbmDragCard); ReleaseDC(NULL, hdc); UseNicePalette(hdcBackGnd, __hPalette); UseNicePalette(hdcDragCard, __hPalette); //grab the first bit of background so we can prep the back buffer; do this by //rendering the card stack (minus the card we are dragging) to the temporary //background buffer, so it appears if we have lifted the card from the stack //--SetRect(&rect, 0, 0, nDragCardWidth, nDragCardHeight); //--PaintRect(hdcBackGnd, &rect, crBackgnd); int threedadjust = numcards % nThreedCount == 0; numunder = CalcApparentCards(numcards); iwhichcard = (numcards+numtodrag) - numunder - 1; if(nThreedCount == 1) iwhichcard = 0; int xoff = calc_offset(xoffset, numunder, numtodrag, numunder); int yoff = calc_offset(yoffset, numunder, numtodrag, numunder); parentWnd.PaintCardRgn(hdcBackGnd, 0,0, nDragCardWidth,nDragCardHeight, xpos - xoff,ypos - yoff); // // Render the cardstack into the back-buffer. The stack // has already had the dragcards removed, so just draw // what is left // for(icard = 0; icard < numunder; icard++) { Card card = cardstack.cardlist[iwhichcard]; int nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; CardBlt(hdcBackGnd, xoffset * icard - xoffset*(numunder-numtodrag+threedadjust), yoffset * icard - yoffset*(numunder-numtodrag+threedadjust), nCardVal); iwhichcard++; } // // If there are no cards under this one, just draw the place holder // if(numcards == 0) { switch(uEmptyImage) { case CS_EI_NONE: //no need! we've already cleared the whole //back-buffer before the main loop! //SetRect(&rect, 0, 0, __cardwidth, __cardheight); //PaintRect(hdcBackGnd, &rect, MAKE_PALETTERGB(crBackgnd)); break; case CS_EI_SUNK: DrawCard(hdcBackGnd, 0, 0, __hdcPlaceHolder, __cardwidth, __cardheight); break; case CS_EI_CIRC: case CS_EI_X: CardBlt(hdc, 0, 0, uEmptyImage); break; } } // // now render the drag-cards into the dragcard image // PaintRect(hdcDragCard, &rect, crBackgnd); for(icard = 0; icard < numtodrag; icard++) { Card card = dragstack.cardlist[icard]; int nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; CardBlt(hdcDragCard, xoffset * icard, yoffset * icard, nCardVal); } }
void CardRegion::PrepareDragBitmaps(int numtodrag) { RECT rect; HDC hdc; int icard; int numcards = cardstack.NumCards(); int xoff, yoff; if(nThreedCount > 1) { PrepareDragBitmapsThreed(numtodrag); return; } //work out how big the bitmaps need to be nDragCardWidth = (numtodrag - 1) * abs(xoffset) + __cardwidth; nDragCardHeight = (numtodrag - 1) * abs(yoffset) + __cardheight; //Create bitmap for the back-buffer hdc = GetDC(NULL); hdcBackGnd = CreateCompatibleDC(hdc); hbmBackGnd = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); SelectObject(hdcBackGnd, hbmBackGnd); //Create bitmap for the drag-image hdcDragCard = CreateCompatibleDC(hdc); hbmDragCard = CreateCompatibleBitmap(hdc, nDragCardWidth, nDragCardHeight); SelectObject(hdcDragCard, hbmDragCard); ReleaseDC(NULL, hdc); UseNicePalette(hdcBackGnd, __hPalette); UseNicePalette(hdcDragCard, __hPalette); int realvisible = numcards / nThreedCount; //if(numcards > 0 && realvisible == 0) realvisible = 1; int iwhichcard = numcards - 1; if(nThreedCount == 1) iwhichcard = 0; //grab the first bit of background so we can prep the back buffer; do this by //rendering the card stack (minus the card we are dragging) to the temporary //background buffer, so it appears if we have lifted the card from the stack //PaintRect(hdcBackGnd, &rect, crBackgnd); SetRect(&rect, 0, 0, nDragCardWidth, nDragCardHeight); xoff = calc_offset(xoffset, numcards, numtodrag, realvisible); yoff = calc_offset(yoffset, numcards, numtodrag, realvisible); parentWnd.PaintCardRgn(hdcBackGnd, 0, 0, nDragCardWidth, nDragCardHeight, xpos - xoff, ypos - yoff); // // Render the cardstack into the back-buffer. The stack // has already had the dragcards removed, so just draw // what is left // for(icard = 0; icard < realvisible; icard++) { Card card = cardstack.cardlist[iwhichcard]; int nCardVal; nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; xoff = xoffset * icard + calc_offset(xoffset, numcards, numtodrag, realvisible);//- xoffset * ((numcards+numtodrag) / nThreedCount - numtodrag); yoff = yoffset * icard + calc_offset(yoffset, numcards, numtodrag, realvisible);//- yoffset * ((numcards+numtodrag) / nThreedCount - numtodrag); CardBlt(hdcBackGnd, xoff, yoff, nCardVal); iwhichcard++; } // // If there are no cards under this one, just draw the place holder // if(numcards == 0) { int xoff = 0, yoff = 0; if(xoffset < 0) xoff = nDragCardWidth - __cardwidth; if(yoffset < 0) yoff = nDragCardHeight - __cardheight; switch(uEmptyImage) { case CS_EI_NONE: //No need to draw anything: We already cleared the //back-buffer before the main loop.. //SetRect(&rc, xoff, yoff, xoff+ __cardwidth, yoff + __cardheight); //PaintRect(hdcBackGnd, &rc, MAKE_PALETTERGB(crBackgnd)); //parentWnd.PaintCardRgn(hdcBackGnd, xoff, yoff, __cardwidth, __cardheight, xpos, ypos);// + xoff, ypos + yoff); break; case CS_EI_SUNK: DrawCard(hdcBackGnd, xoff, yoff, __hdcPlaceHolder, __cardwidth, __cardheight); break; case CS_EI_CIRC: case CS_EI_X: CardBlt(hdc, xoff, yoff, uEmptyImage); break; } } // // now render the drag-cards into the dragcard image // PaintRect(hdcDragCard, &rect, crBackgnd); for(icard = 0; icard < numtodrag; icard++) { int nCardVal; if(xoffset >= 0) xoff = xoffset * icard; else xoff = -xoffset * (numtodrag - icard - 1); if(yoffset >= 0) yoff = yoffset * icard; else yoff = -yoffset * (numtodrag - icard - 1); Card card = dragstack.cardlist[icard]; nCardVal = card.FaceUp() ? card.Idx() : nBackCardIdx; CardBlt(hdcDragCard, xoff, yoff, nCardVal); } }