reshuffling of dlls
[reactos.git] / reactos / dll / win32 / cards / cards.c
1 /*
2 * ReactOS Cards
3 *
4 * Copyright (C) 2003 Filip Navara <xnavara@volny.org>
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <stdarg.h>
22
23 #include "windows.h"
24 #include "cards.h"
25
26 HBITMAP g_CardBitmaps[MAX_CARD_BITMAPS];
27 HINSTANCE g_hModule = 0;
28
29 /*
30 * Redundant function from 16-bit Windows time
31 */
32 BOOL WINAPI WEP(DWORD Unknown)
33 {
34 return TRUE;
35 }
36
37 /*
38 * Initialize card library and return cards width and height
39 */
40 BOOL WINAPI cdtInit(INT *Width, INT *Height)
41 {
42 DWORD dwIndex;
43
44 /* Report card width and height to user */
45 *Width = CARD_WIDTH;
46 *Height = CARD_HEIGHT;
47
48 /* Load images */
49 for (dwIndex = 0; dwIndex < MAX_CARD_BITMAPS; ++dwIndex)
50 g_CardBitmaps[dwIndex] =
51 (HBITMAP)LoadBitmapA(g_hModule, MAKEINTRESOURCEA(dwIndex + 1));
52
53 return TRUE;
54 }
55
56 /*
57 * Terminate card library
58 */
59 VOID WINAPI cdtTerm(VOID)
60 {
61 DWORD dwIndex;
62
63 /* Unload images */
64 for (dwIndex = 0; dwIndex < MAX_CARD_BITMAPS; dwIndex++)
65 DeleteObject(g_CardBitmaps[dwIndex]);
66 }
67
68 /*
69 * Render card with no stretching
70 */
71 BOOL WINAPI cdtDraw(HDC hdc, INT x, INT y, INT card, INT type, COLORREF color)
72 {
73 return cdtDrawExt(hdc, x, y, CARD_WIDTH, CARD_HEIGHT, card, type, color);
74 }
75
76 /*
77 * internal
78 */
79 static __inline VOID BltCard(HDC hdc, INT x, INT y, INT dx, INT dy, HDC hdcCard, DWORD dwRasterOp, BOOL bStretch)
80 {
81 if (bStretch)
82 {
83 StretchBlt(hdc, x, y, dx, dy, hdcCard, 0, 0, CARD_WIDTH, CARD_HEIGHT, dwRasterOp);
84 } else
85 {
86 BitBlt(hdc, x, y, dx, dy, hdcCard, 0, 0, dwRasterOp);
87 /*
88 * This is need when using Microsoft images, because they use two-color red/white images for
89 * red cards and thus needs fix-up of the edge to black color.
90 */
91 #if 0
92 if (ISREDCARD(card))
93 {
94 PatBlt(hdc, x, y + 2, 1, dy - 4, BLACKNESS);
95 PatBlt(hdc, x + dx - 1, y + 2, 1, dy - 4, BLACKNESS);
96 PatBlt(hdc, x + 2, y, dx - 4, 1, BLACKNESS);
97 PatBlt(hdc, x + 2, y + dy - 1, dx - 4, 1, BLACKNESS);
98 SetPixel(hdc, x + 1, y + 1, 0);
99 SetPixel(hdc, x + dx - 2, y + 1, 0);
100 SetPixel(hdc, x + 1, y + dy - 2, 0);
101 SetPixel(hdc, x + dx - 2, y + dy - 2, 0);
102 }
103 #endif
104 }
105 }
106
107 /*
108 * Render card
109 *
110 * Parameters:
111 * hdc - Handle of destination device context
112 * x - Position left
113 * y - Position right
114 * dx - Destination width
115 * dy - Destination height
116 * card - Image id (meaning depend on type)
117 * type - One of edt* constants
118 * color - Background color (?)
119 */
120 BOOL WINAPI cdtDrawExt(HDC hdc, INT x, INT y, INT dx, INT dy, INT card, INT type, COLORREF color)
121 {
122 HDC hdcCard;
123 DWORD dwRasterOp = SRCCOPY, OldBkColor;
124 BOOL bSaveEdges = TRUE;
125 BOOL bStretch = FALSE;
126
127 if (type & ectSAVEEDGESMASK)
128 {
129 type &= ~ectSAVEEDGESMASK;
130 bSaveEdges = FALSE;
131 }
132
133 if (dx != CARD_WIDTH || dy != CARD_HEIGHT)
134 {
135 bStretch = TRUE;
136 bSaveEdges = FALSE;
137 }
138
139 switch (type)
140 {
141 case ectINVERTED:
142 dwRasterOp = NOTSRCCOPY;
143 case ectFACES:
144 card = (card % 4) * 13 + (card / 4);
145 break;
146 case ectBACKS:
147 --card;
148 break;
149 case ectEMPTYNOBG:
150 dwRasterOp = SRCAND;
151 case ectEMPTY:
152 card = 52;
153 break;
154 case ectERASE:
155 break;
156 case ectREDX:
157 card = 66;
158 break;
159 case ectGREENO:
160 card = 67;
161 break;
162 default:
163 return FALSE;
164 }
165
166 if (type == ectEMPTY || type == ectERASE)
167 {
168 POINT pPoint;
169 HBRUSH hBrush;
170
171 hBrush = CreateSolidBrush(color);
172 GetDCOrgEx(hdc, &pPoint);
173 SetBrushOrgEx(hdc, pPoint.x, pPoint.y, 0);
174 SelectObject(hdc, hBrush);
175 PatBlt(hdc, x, y, dx, dy, PATCOPY);
176 }
177 if (type != ectERASE)
178 {
179 hdcCard = CreateCompatibleDC(hdc);
180 SelectObject(hdcCard, g_CardBitmaps[card]);
181 OldBkColor = SetBkColor(hdc, (type == ectFACES) ? 0xFFFFFF : color);
182 if (bSaveEdges)
183 {
184 COLORREF SavedPixels[12];
185 SavedPixels[0] = GetPixel(hdc, x, y);
186 SavedPixels[1] = GetPixel(hdc, x + 1, y);
187 SavedPixels[2] = GetPixel(hdc, x, y + 1);
188 SavedPixels[3] = GetPixel(hdc, x + dx - 1, y);
189 SavedPixels[4] = GetPixel(hdc, x + dx - 2, y);
190 SavedPixels[5] = GetPixel(hdc, x + dx - 1, y + 1);
191 SavedPixels[6] = GetPixel(hdc, x, y + dy - 1);
192 SavedPixels[7] = GetPixel(hdc, x + 1, y + dy - 1);
193 SavedPixels[8] = GetPixel(hdc, x, y + dy - 2);
194 SavedPixels[9] = GetPixel(hdc, x + dx - 1, y + dy - 1);
195 SavedPixels[10] = GetPixel(hdc, x + dx - 2, y + dy - 1);
196 SavedPixels[11] = GetPixel(hdc, x + dx - 1, y + dy - 2);
197
198 BltCard(hdc, x, y, dx, dy, hdcCard, dwRasterOp, bStretch);
199
200 SetPixel(hdc, x, y, SavedPixels[0]);
201 SetPixel(hdc, x + 1, y, SavedPixels[1]);
202 SetPixel(hdc, x, y + 1, SavedPixels[2]);
203 SetPixel(hdc, x + dx - 1, y, SavedPixels[3]);
204 SetPixel(hdc, x + dx - 2, y, SavedPixels[4]);
205 SetPixel(hdc, x + dx - 1, y + 1, SavedPixels[5]);
206 SetPixel(hdc, x, y + dy - 1, SavedPixels[6]);
207 SetPixel(hdc, x + 1, y + dy - 1, SavedPixels[7]);
208 SetPixel(hdc, x, y + dy - 2, SavedPixels[8]);
209 SetPixel(hdc, x + dx - 1, y + dy - 1, SavedPixels[9]);
210 SetPixel(hdc, x + dx - 2, y + dy - 1, SavedPixels[10]);
211 SetPixel(hdc, x + dx - 1, y + dy - 2, SavedPixels[11]);
212 }
213 else
214 {
215 BltCard(hdc, x, y, dx, dy, hdcCard, dwRasterOp, bStretch);
216 }
217 SetBkColor(hdc, OldBkColor);
218 DeleteDC(hdcCard);
219 }
220
221 return TRUE;
222 }
223
224
225 /***********************************************************************
226 * cdtAnimate (CARDS.@)
227 *
228 * Animate card background, we don't use it
229 */
230 BOOL WINAPI cdtAnimate(HDC hdc, int cardback, int x, int y, int frame)
231 {
232 return TRUE;
233 }
234
235 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
236 {
237 if (fdwReason == DLL_PROCESS_ATTACH)
238 g_hModule = hinstDLL;
239
240 return TRUE;
241 }