4 * Copyright (C) 2003 Filip Navara <xnavara@volny.org>
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
26 HBITMAP g_CardBitmaps
[MAX_CARD_BITMAPS
];
27 HINSTANCE g_hModule
= 0;
30 * Redundant function from 16-bit Windows time
32 BOOL WINAPI
WEP(DWORD Unknown
)
38 * Initialize card library and return cards width and height
40 BOOL WINAPI
cdtInit(INT
*Width
, INT
*Height
)
44 /* Report card width and height to user */
46 *Height
= CARD_HEIGHT
;
49 for (dwIndex
= 0; dwIndex
< MAX_CARD_BITMAPS
; ++dwIndex
)
50 g_CardBitmaps
[dwIndex
] =
51 (HBITMAP
)LoadBitmapA(g_hModule
, MAKEINTRESOURCEA(dwIndex
+ 1));
57 * Terminate card library
59 VOID WINAPI
cdtTerm(VOID
)
64 for (dwIndex
= 0; dwIndex
< MAX_CARD_BITMAPS
; dwIndex
++)
65 DeleteObject(g_CardBitmaps
[dwIndex
]);
69 * Render card with no stretching
71 BOOL WINAPI
cdtDraw(HDC hdc
, INT x
, INT y
, INT card
, INT type
, COLORREF color
)
73 return cdtDrawExt(hdc
, x
, y
, CARD_WIDTH
, CARD_HEIGHT
, card
, type
, color
);
79 static __inline VOID
BltCard(HDC hdc
, INT x
, INT y
, INT dx
, INT dy
, HDC hdcCard
, DWORD dwRasterOp
, BOOL bStretch
)
83 StretchBlt(hdc
, x
, y
, dx
, dy
, hdcCard
, 0, 0, CARD_WIDTH
, CARD_HEIGHT
, dwRasterOp
);
86 BitBlt(hdc
, x
, y
, dx
, dy
, hdcCard
, 0, 0, dwRasterOp
);
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.
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);
111 * hdc - Handle of destination device context
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 (?)
120 BOOL WINAPI
cdtDrawExt(HDC hdc
, INT x
, INT y
, INT dx
, INT dy
, INT card
, INT type
, COLORREF color
)
123 DWORD dwRasterOp
= SRCCOPY
, OldBkColor
;
124 BOOL bSaveEdges
= TRUE
;
125 BOOL bStretch
= FALSE
;
127 if (type
& ectSAVEEDGESMASK
)
129 type
&= ~ectSAVEEDGESMASK
;
133 if (dx
!= CARD_WIDTH
|| dy
!= CARD_HEIGHT
)
142 dwRasterOp
= NOTSRCCOPY
;
144 card
= (card
% 4) * 13 + (card
/ 4);
166 if (type
== ectEMPTY
|| type
== ectERASE
)
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
);
177 if (type
!= ectERASE
)
179 hdcCard
= CreateCompatibleDC(hdc
);
180 SelectObject(hdcCard
, g_CardBitmaps
[card
]);
181 OldBkColor
= SetBkColor(hdc
, (type
== ectFACES
) ? 0xFFFFFF : color
);
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);
198 BltCard(hdc
, x
, y
, dx
, dy
, hdcCard
, dwRasterOp
, bStretch
);
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]);
215 BltCard(hdc
, x
, y
, dx
, dy
, hdcCard
, dwRasterOp
, bStretch
);
217 SetBkColor(hdc
, OldBkColor
);
225 /***********************************************************************
226 * cdtAnimate (CARDS.@)
228 * Animate card background, we don't use it
230 BOOL WINAPI
cdtAnimate(HDC hdc
, int cardback
, int x
, int y
, int frame
)
235 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
237 if (fdwReason
== DLL_PROCESS_ATTACH
)
238 g_hModule
= hinstDLL
;