VOID DrawCard(CRD *pcrd) { AssertHdcCur(); cdtDrawExt( hdcCur, pcrd->pt.x-xOrgCur, pcrd->pt.y-yOrgCur, dxCrd, dyCrd, pcrd->fUp ? pcrd->cd : modeFaceDown, pcrd->fUp ? FACEUP : FACEDOWN, rgbTable); }
BOOL APIENTRY cdtDraw(HDC hdc, INT x, INT y, INT cd, INT mode, DWORD rgbBgnd) /* * Parameters: * hdc HDC to window to draw cards on * x, y Where you'd like them * cd Card to be drawn * mode Way you want it drawn * * Returns: * True if card successfully drawn, False otherwise */ { return cdtDrawExt(hdc, x, y, dxCard, dyCard, cd, mode, rgbBgnd); }
VOID DrawCardExt(PT *ppt, INT cd, INT mode) { VOID DrawBackground(); AssertHdcCur(); cdtDrawExt( hdcCur, ppt->x-xOrgCur, ppt->y-yOrgCur, dxCrd, dyCrd, cd, mode, rgbTable); }
VOID DrawCardPt(CRD *pcrd, PT *ppt) { DWORD dwModeExt=0; // turn on sign bit if moving fast // cdtDrawExt must support this! if( fKlondWinner ) { dwModeExt= MINLONG; } AssertHdcCur(); cdtDrawExt(hdcCur, ppt->x-xOrgCur, ppt->y-yOrgCur, dxCrd, dyCrd, pcrd->fUp ? pcrd->cd : modeFaceDown, (pcrd->fUp ? FACEUP : FACEDOWN ) | dwModeExt, rgbTable); }
long FAR PASCAL BinDemoWndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam) { PAINTSTRUCT ps; HDC hDC; RECT rect; switch (message) { case WM_CREATE: cdtInit(&csx,&csy); /* Get the card size */ csize = 1; /* display normal size */ cardoffset = 4; firstcard = 0; /* clubs */ cardback = 0; /* show front */ SetCardMarks(hWnd, IDM_CLUBS); SetCardMarks(hWnd, IDM_NORMAL); carddx = (int) (csize * csx); carddy = (int) (csize * csy); break; case WM_SIZE: InvalidateRect(hWnd, NULL, TRUE); break; case WM_COMMAND: switch(wParam) { case IDM_EXIT: DestroyWindow(hWnd); break; case IDM_ABOUT: { HICON hIcon; hIcon = LoadIcon(hInst, "BinDemoIcon"); ShellAbout(hWnd, "BinDemo Sample Application", "BinDemo", hIcon); DestroyIcon(hIcon); break; } case IDM_CLUBS: case IDM_DIAMONDS: case IDM_HEARTS: case IDM_SPADES: ClearCardMarks(hWnd, ID_FIRSTCARDID, ID_LASTCARDID); SetCardMarks(hWnd, wParam); firstcard = wParam - ID_FIRSTCARDID; cardoffset =4; cardback = 0; InvalidateRect(hWnd, NULL, TRUE); break; case IDM_BACKSIDES: ClearCardMarks(hWnd, ID_FIRSTCARDID, ID_LASTCARDID); SetCardMarks(hWnd, IDM_BACKSIDES); cardback = 1; cardoffset =1; firstcard = 53; InvalidateRect(hWnd, NULL, TRUE); break; case IDM_SMALL: case IDM_NORMAL: case IDM_LARGE: csize = sizes[wParam - ID_FIRSTSIZEID]; carddx = (int) (csize*csx); carddy = (int) (csize*csy); ClearCardMarks(hWnd, ID_FIRSTSIZEID, ID_LASTSIZEID); SetCardMarks(hWnd, wParam); InvalidateRect(hWnd, NULL, TRUE); break; } break; case WM_PAINT: { int i, d, x0, y0, dx, dy, dd; double phi, dphi; RECT r1, r2; hDC = BeginPaint(hWnd,&ps); GetClientRect(hWnd, &rect); /* calculate the starting position */ phi = 0; d = 0; x0 = (rect.right-carddx) /2; y0 = (rect.bottom-carddy)/2; dd = min(x0, y0) / 12; dphi = 3.1415926535 / 12; for(i=0;i<13;i++) { dy = (int) (d * cos(phi)); dx = (int) (d * sin(phi)); SetRect(&r1, x0+dx, y0+dy, x0+dx+carddx, y0+dy+carddy); if(IntersectRect(&r2, &r1, &ps.rcPaint)) cdtDrawExt(hDC,x0+dx,y0+dy,carddx, carddy, i*cardoffset+firstcard,cardback,RGBBKND); if(i!=0) /* the first card is the same for both directions */ { SetRect(&r1, x0-dx, y0-dy, x0-dx+carddx, y0-dy+carddy); if(IntersectRect(&r2, &r1, &ps.rcPaint)) cdtDrawExt(hDC,x0-dx,y0-dy,carddx, carddy, i*cardoffset+firstcard,cardback,RGBBKND); } phi += dphi; d += dd; } EndPaint(hWnd,&ps); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return (DefWindowProc(hWnd, message, wParam, lParam)); } return (0); }
/*********************************************************************** * Draws a card at position x, y in its default size (as returned by * cdtInit. * * Mode controls how the card gets drawn: * MODE_FACEUP ; draw card facing up * MODE_FACEDOWN ; draw card facing down * MODE_HILITE ; draw face up, with NOTSRCCOPY * MODE_GHOST ; draw 'ghost' card * MODE_REMOVE ; draw with background color * MODE_INVISIBLEGHOST ; draw 'ghost' card, without clearing background * MODE_DECKX ; draw X * MODE_DECKO ; draw O * * The card parameter defines the card graphic to be drawn. If we are * drawing fronts of cards, card should have a value from 0 through 51 * to represent the card face. If we are drawing card backs, 53 through * 68 represent different card backs. * * When drawing card faces, two lowest bits represent the card suit * (clubs, diamonds, hearts, spades), and the bits above that define the * card value (ace, 2, ..., king). That is, * card = face * 4 + suit. * * Color parameter defines the background color, used when drawing some * card backs. */ BOOL WINAPI cdtDraw(HDC hdc, int x, int y, int card, int mode, DWORD color) { TRACE("(%p, %d, %d, %d, %d, %d)\n", hdc, x, y, card, mode, color); return cdtDrawExt(hdc, x, y, cardWidth, cardHeight, card, mode, color); }
/* * Render card with no stretching */ BOOL WINAPI cdtDraw(HDC hdc, INT x, INT y, INT card, INT type, COLORREF color) { return cdtDrawExt(hdc, x, y, CARD_WIDTH, CARD_HEIGHT, card, type, color); }