Added missing \n in trace.
[wine/hacks.git] / dlls / cards / cards.c
blob0bf0c49a461c272003cd77436bfba51334ebb0f7
1 /*
2 * Cards dll implementation
4 * Copyright (C) 2004 Sami Nopanen
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
30 #include "cards.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(cards);
36 void WINAPI cdtTerm(void);
39 static HINSTANCE hInst;
40 static int cardWidth;
41 static int cardHeight;
42 static HBITMAP cardBitmaps[CARD_MAX + 1];
45 /***********************************************************************
46 * Initializes the cards.dll library. Loads the card bitmaps from the
47 * resources, and initializes the card size variables.
49 BOOL WINAPI cdtInit(int *width, int *height)
51 BITMAP bm;
52 int i;
54 TRACE("(%p, %p)\n", width, height);
56 for(i = 0; i <= CARD_MAX; i++)
57 cardBitmaps[i] = 0;
59 for(i = 0; i <= CARD_MAX; i++)
61 cardBitmaps[i] = LoadBitmapA(hInst, MAKEINTRESOURCEA(i));
62 if(cardBitmaps[i] == 0)
64 cdtTerm();
65 return FALSE;
69 GetObjectA(cardBitmaps[0], sizeof(BITMAP), &bm);
70 *width = cardWidth = bm.bmWidth;
71 *height = cardHeight = bm.bmHeight;
72 return TRUE;
76 /***********************************************************************
77 * Draw a card. Unlike cdtDrawCard, this version allows you to stretch
78 * card bitmaps to the size you specify (dx, dy). See cdtDraw for info
79 * on card, mode and color parameters.
81 BOOL WINAPI cdtDrawExt(HDC hdc, int x, int y, int dx, int dy, int card, int mode, DWORD color)
83 HDC hMemoryDC;
84 HBITMAP hCardBitmap;
85 HGDIOBJ result;
86 DWORD rasterOp = SRCCOPY;
88 TRACE("(%p, %d, %d, %d, %d, %d, %d, %ld)\n", hdc, x, y, dx, dy, card, mode, color);
90 if((card < 0) || (card > CARD_MAX))
92 FIXME("Unexpected card: %d\n", card);
93 return FALSE;
96 if((mode < MODE_FACEUP) || (mode > MODE_DECKO))
98 FIXME("Unexpected mode: %d\n", mode);
99 return FALSE;
102 if(mode == MODE_INVISIBLEGHOST || mode == MODE_DECKX || mode == MODE_DECKO)
104 FIXME("Mode %d not implemented.\n", mode);
105 return FALSE;
108 hMemoryDC = CreateCompatibleDC(hdc);
109 if(hMemoryDC == 0)
110 return FALSE;
112 if((mode == MODE_REMOVE) || (mode == MODE_GHOST))
114 HBRUSH hBrush;
115 RECT rect;
116 hBrush = CreateSolidBrush(color);
117 rect.left = x;
118 rect.top = y;
119 rect.right = x + cardWidth - 1;
120 rect.bottom = y + cardHeight - 1;
121 FillRect(hdc, &rect, hBrush);
123 if(mode == MODE_GHOST)
125 hBrush = CreateSolidBrush(RGB(255, 255, 255));
126 FrameRect(hdc, &rect, hBrush);
129 else /* MODE_FACEUP, MODE_FACEDOWN, MODE_HILITE */
131 if(mode == MODE_HILITE)
132 rasterOp = NOTSRCCOPY;
134 hCardBitmap = cardBitmaps[card];
135 if(hCardBitmap == 0)
136 return FALSE;
138 result = SelectObject(hMemoryDC, hCardBitmap);
139 if((result == 0) || (result == HGDI_ERROR))
141 DeleteDC(hMemoryDC);
142 return FALSE;
145 SetBkColor(hdc, color);
147 if((cardWidth == dx) && (cardHeight == dy))
148 BitBlt(hdc, x, y, cardWidth, cardHeight, hMemoryDC, 0, 0, rasterOp);
149 else
150 StretchBlt(hdc, x, y, dx, dy, hMemoryDC, 0, 0, cardWidth, cardHeight, rasterOp);
153 DeleteDC(hMemoryDC);
155 return TRUE;
159 /***********************************************************************
160 * Draws a card at position x, y in its default size (as returned by
161 * cdtInit.
163 * Mode controls how the card gets drawn:
164 * MODE_FACEUP ; draw card facing up
165 * MODE_FACEDOWN ; draw card facing down
166 * MODE_HILITE ; draw face up, with NOTSRCCOPY
167 * MODE_GHOST ; draw 'ghost' card
168 * MODE_REMOVE ; draw with background color
169 * MODE_INVISIBLEGHOST ; ?
170 * MODE_DECKX ; draw X
171 * MODE_DECKO ; draw O
173 * The card parameter defines the card graphic to be drawn. If we are
174 * drawing fronts of cards, card should have a value from 0 through 51
175 * to represent the card face. If we are drawing card backs, 53 through
176 * 68 represent different card backs.
178 * When drawing card faces, two lowest bits represent the card suit
179 * (clubs, diamonds, hearts, spades), and the bits above that define the
180 * card value (ace, 2, ..., king). That is,
181 * card = face * 4 + suit.
183 * Color parameter defines the background color, used when drawing some
184 * card backs.
186 BOOL WINAPI cdtDraw(HDC hdc, int x, int y, int card, int mode, DWORD color)
188 TRACE("(%p, %d, %d, %d, %d, %ld)\n", hdc, x, y, card, mode, color);
190 return cdtDrawExt(hdc, x, y, cardWidth, cardHeight, card, mode, color);
194 /***********************************************************************
195 * Animates the card backs, e.g. blinking lights on the robot, the sun
196 * donning sunglasses, bats flying across the caste, etc.. Works only
197 * for cards of normal size (as drawn with cdtDraw). To draw frames of
198 * the card back animation, start with frame = 0, and increment the
199 * frame by one, until cdtAnimate returns FALSE (to indicate that we
200 * have gone through all frames of animation).
202 BOOL WINAPI cdtAnimate(HDC hdc, int cardback, int x, int y, int frame)
204 TRACE("(%p, %d, %d, %d, %d)\n", hdc, cardback, x, y, frame);
205 FIXME("Implement me.\n");
207 return FALSE;
211 /***********************************************************************
212 * Frees resources reserved by cdtInitialize.
214 void WINAPI cdtTerm()
216 int i;
218 TRACE("()\n");
220 for(i = 0; i <= CARD_MAX; i++)
222 if(cardBitmaps[i] != 0)
223 DeleteObject(cardBitmaps[i]);
224 cardBitmaps[i] = 0;
229 /***********************************************************************
230 * DllMain.
232 BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved)
234 switch (reason)
236 case DLL_PROCESS_ATTACH:
237 hInst = inst;
238 DisableThreadLibraryCalls( inst );
239 break;
240 case DLL_PROCESS_DETACH:
241 break;
243 return TRUE;