ReactOS  0.4.14-dev-583-g2a1ba2c
cardbitmaps.cpp
Go to the documentation of this file.
1 //
2 // CardLib - Card bitmap support
3 //
4 // Freeware
5 // Copyright J Brown 2001
6 //
7 
8 #include "cardlib.h"
9 
10 #ifndef __REACTOS__
11 #pragma comment( lib, "..\\CardLib\\cards16.lib" )
12 
13 extern "C" HINSTANCE WINAPI LoadLibrary16( PSTR );
14 extern "C" void WINAPI FreeLibrary16( HINSTANCE );
15 #endif
16 
17 #define NUMCARDBITMAPS (52+16)
18 
19 void PaintRect(HDC hdc, RECT *rect, COLORREF col);
20 
21 void LoadCardBitmapsFromLibrary(HINSTANCE hCardDll, int *pwidth, int *pheight)
22 {
24  HDC hdcCard = NULL;
25  HANDLE hOld;
26  int i, xpos;
27  int width, height;
28  BITMAP bmp;
29 
30  for(i = 0; i < NUMCARDBITMAPS; i++)
31  {
32  //convert into the range used by the cdt_xxx functions
33  int val;
34 
35  if(i < 52) val = (i % 4) * 13 + (i/4);
36  else val = i;
37 
38  hBitmap = LoadBitmap(hCardDll, MAKEINTRESOURCE(val + 1));
39  GetObject(hBitmap, sizeof(bmp), &bmp);
40 
41  width = bmp.bmWidth;
42  height = bmp.bmHeight;
43 
44  if(i == 0) //if first time through, create BIG bitmap..
45  {
46  HDC hdc = GetDC(0);
50 
51  hdcCard = CreateCompatibleDC(0);
52 
53  ReleaseDC(0, hdc);
54  }
55 
56  hOld = SelectObject(hdcCard, hBitmap);
57  BitBlt(__hdcCardBitmaps, i*width, 0, width, height, hdcCard, 0, 0, SRCCOPY);
58  SelectObject(hdcCard, hOld);
59 
60  //Now draw a black border around each card...
61  xpos = i*width;
62  MoveToEx(__hdcCardBitmaps, xpos+2, 0, 0);
63  LineTo(__hdcCardBitmaps, xpos+width - 3, 0);
64  LineTo(__hdcCardBitmaps, xpos+width - 1, 2);
65  LineTo(__hdcCardBitmaps, xpos+width - 1, height - 3); //vertical
66  LineTo(__hdcCardBitmaps, xpos+width - 3, height - 1);
67  LineTo(__hdcCardBitmaps, xpos+2, height - 1);
68  LineTo(__hdcCardBitmaps, xpos+0, height - 3);
69  LineTo(__hdcCardBitmaps, xpos+0, 2);
70  LineTo(__hdcCardBitmaps, xpos+2, 0);
71 
73  }
74 
75  DeleteDC(hdcCard);
76 
77  *pwidth = width;
78  *pheight = height;
79 
80 }
81 
82 void LoadCardBitmaps(void)
83 {
84  HINSTANCE hCardDll;
85 
86 
87  //If Windows NT/2000/XP
88  if(GetVersion() < 0x80000000)
89  {
90  hCardDll = LoadLibrary(TEXT("cards.dll"));
91 
92  if(hCardDll == 0)
93  {
94  MessageBox(0, TEXT("Error loading cards.dll (32bit)"), TEXT("Shed"), MB_OK | MB_ICONEXCLAMATION);
95  PostQuitMessage(0);
96  return;
97  }
98 
100 
101  FreeLibrary(hCardDll);
102  }
103 #ifndef __REACTOS__
104  //Else, Win9X
105  else
106  {
107  hCardDll = LoadLibrary16("cards.dll");
108 
109  if(hCardDll == 0)
110  {
111  MessageBox(0, "Error loading cards.dll (16bit)", "Shed", MB_OK | MB_ICONEXCLAMATION);
112  PostQuitMessage(0);
113  return;
114  }
115 
117 
118  FreeLibrary16(hCardDll);
119  }
120 #endif
121 }
122 
124 {
127 }
128 //
129 // Paint a checkered rectangle, with each alternate
130 // pixel being assigned a different colour
131 //
133 {
134  static WORD wCheckPat[8] =
135  {
136  0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555
137  };
138 
139  HBITMAP hbmp;
140  HBRUSH hbr, hbrold;
141  COLORREF fgold, bgold;
142 
143  hbmp = CreateBitmap(8, 8, 1, 1, wCheckPat);
144  hbr = CreatePatternBrush(hbmp);
145 
146  //UnrealizeObject(hbr);
147 
148  SetBrushOrgEx(hdc, rect->left, rect->top, 0);
149 
150  hbrold = (HBRUSH)SelectObject(hdc, hbr);
151 
152  fgold = SetTextColor(hdc, fg);
153  bgold = SetBkColor(hdc, bg);
154 
155  PatBlt(hdc, rect->left, rect->top,
156  rect->right - rect->left,
157  rect->bottom - rect->top,
158  PATCOPY);
159 
160  SetBkColor(hdc, bgold);
161  SetTextColor(hdc, fgold);
162 
163  SelectObject(hdc, hbrold);
164  DeleteObject(hbr);
166 }
167 
168 void GetSinkCols(COLORREF crBase, COLORREF *fg, COLORREF *bg, COLORREF *sh1, COLORREF *sh2)
169 {
170  if(bg) *bg = crBase;
171  if(fg) *fg = ColorScaleRGB(crBase, RGB(255,255,255), 0.2);//RGB(49, 99, 140);
172  if(sh1) *sh1 = ColorScaleRGB(crBase, RGB(0,0,0), 0.4);
173  if(sh2) *sh2 = ColorScaleRGB(crBase, RGB(0,0,0), 0.2);
174 }
175 
176 HBITMAP CreateSinkBmp(HDC hdcCompat, HDC hdc, COLORREF col, int width, int height)
177 {
178  HANDLE hold, hpold;
180 
181  HPEN hpfg, hpbg, hpsh, hpsh2;
182 
183  RECT rect;
184  COLORREF fg, bg, shadow, shadow2;
185 
186  GetSinkCols(col, &fg, &bg, &shadow, &shadow2);
187 
188  hold = SelectObject(hdc, hbm);
189 
190  //fill with a solid base colour
191  SetRect(&rect, 0,0,width,height);
193 
194  //draw the outline
195  hpfg = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(fg));
196  hpbg = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(bg));
197  hpsh = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(shadow));
198  hpsh2= CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(shadow2));
199 
200  hpold = SelectObject(hdc, hpsh);
201  MoveToEx(hdc, 2, 0, NULL);
202  LineTo (hdc, width-3,0);
203  LineTo (hdc, width-1, 2);
204 
205  SelectObject(hdc, hpold);
206  hpold = SelectObject(hdc, hpsh2);
207  LineTo (hdc, width-1, height-3); //vertical
208  LineTo (hdc, width-3, height-1);
209  LineTo (hdc, 2, height-1);
210  LineTo (hdc, 0, height-3);
211  SelectObject(hdc, hpold);
212  hpold = SelectObject(hdc, hpsh);
213 
214  //MoveToEx( hdc, 0, height-3,0);
215  LineTo (hdc, 0, 2);
216  LineTo (hdc, 2, 0);
217 
218  SelectObject(hdc, hpold);
219 
220  //draw the highlight (vertical)
221  hpold = SelectObject(hdc, hpfg);
222  MoveToEx(hdc, width - 2, 3, NULL);
223  LineTo (hdc, width - 2, height - 2);
224 
225  //(horz)
226  MoveToEx(hdc, width - 3, height-2, NULL);
227  LineTo (hdc, 3, height-2);
228  SelectObject(hdc, hpold);
229 
230  //draw the background
231  InflateRect(&rect, -2, -2);
233 
234  //overwrite the top-left background pixel
235  SetPixel(hdc, 2, 2, MAKE_PALETTERGB(bg));
236 
237  DeleteObject(hpsh);
238  DeleteObject(hpsh2);
239  DeleteObject(hpfg);
240  DeleteObject(hpbg);
241 
242 
243  return hbm;
244 }
245 
246 
247 
249 {
250  pe->peBlue = GetBValue(col);
251  pe->peGreen = GetGValue(col);
252  pe->peRed = GetRValue(col);
253  pe->peFlags = 0;
254 }
255 
256 HPALETTE MakePaletteFromCols(COLORREF cols[], int nNumColours)
257 {
258  LOGPALETTE *lp;
259  HPALETTE hPalette;
260 
261  // Allocate memory for the logical palette
262  lp = (LOGPALETTE *)HeapAlloc(
263  GetProcessHeap(), 0, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * nNumColours);
264 
265  lp->palNumEntries = (WORD)nNumColours;
266  lp->palVersion = 0x300;
267 
268  //copy the colours into the logical palette format
269  for(int i = 0; i < nNumColours; i++)
270  {
271  CopyColor(&lp->palPalEntry[i], cols[i]);
272  }
273 
274  // create palette!
275  hPalette = CreatePalette(lp);
276 
277  HeapFree(GetProcessHeap(), 0, lp);
278 
279  return hPalette;
280 }
void GetSinkCols(COLORREF crBase, COLORREF *fg, COLORREF *bg, COLORREF *sh1, COLORREF *sh2)
HBITMAP __hbmCardBitmaps
Definition: cardlib.cpp:19
#define MAKEINTRESOURCE
Definition: winuser.h:591
GLint GLint GLsizei width
Definition: gl.h:1546
BOOL WINAPI InflateRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define MAKE_PALETTERGB(colref)
Definition: cardcolor.h:17
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
COLORREF ColorScaleRGB(const COLORREF Col1, const COLORREF Col2, const double Ratio)
Definition: cardcolor.cpp:154
#define LoadLibrary
Definition: winbase.h:3696
static void DrawCheckedRect(HDC hdc, RECT *rect, COLORREF fg, COLORREF bg)
HDC WINAPI GetDC(_In_opt_ HWND)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
static HDC
Definition: imagelist.c:92
#define GetRValue(rgb)
Definition: wingdi.h:2934
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
BOOL WINAPI LineTo(_In_ HDC, _In_ int, _In_ int)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define NUMCARDBITMAPS
Definition: cardbitmaps.cpp:17
void PaintRect(HDC hdc, RECT *rect, COLORREF col)
Definition: cardlib.cpp:116
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:410
& rect
Definition: startmenu.cpp:1413
HDC __hdcCardBitmaps
Definition: cardlib.cpp:18
DWORD WINAPI GetVersion(VOID)
Definition: version.c:22
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
WORD palVersion
Definition: wingdi.h:1832
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:975
#define GetGValue(rgb)
Definition: wingdi.h:2935
BOOL WINAPI PatBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
BOOL WINAPI MoveToEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
#define PS_SOLID
Definition: wingdi.h:585
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI SetBrushOrgEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
void CopyColor(PALETTEENTRY *pe, COLORREF col)
GLuint GLfloat * val
Definition: glext.h:7180
HBITMAP hbmp
FORCEINLINE VOID SetPixel(IN ULONG Left, IN ULONG Top, IN UCHAR Color)
Definition: vga.c:93
#define LoadBitmap
Definition: winuser.h:5786
HBRUSH WINAPI CreatePatternBrush(_In_ HBITMAP)
#define FreeLibrary(x)
Definition: compat.h:413
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
DWORD COLORREF
Definition: windef.h:300
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
#define RGB(r, g, b)
Definition: wingdi.h:2939
#define WINAPI
Definition: msvc.h:6
unsigned short WORD
Definition: ntddk_ex.h:93
#define GetObject
Definition: wingdi.h:4467
HBITMAP CreateSinkBmp(HDC hdcCompat, HDC hdc, COLORREF col, int width, int height)
BITMAP bmp
Definition: alphablend.c:62
void LoadCardBitmapsFromLibrary(HINSTANCE hCardDll, int *pwidth, int *pheight)
Definition: cardbitmaps.cpp:21
HDC hdc
Definition: main.c:9
void FreeCardBitmaps()
void LoadCardBitmaps(void)
Definition: cardbitmaps.cpp:82
#define MessageBox
Definition: winuser.h:5797
int __cardwidth
Definition: cardlib.cpp:25
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#define PATCOPY
Definition: wingdi.h:334
HINSTANCE WINAPI LoadLibrary16(PSTR)
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:888
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
#define TEXT(s)
Definition: k32.h:26
BOOL WINAPI DeleteDC(_In_ HDC)
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
Definition: bl.h:1331
signed char * PSTR
Definition: retypes.h:7
void WINAPI FreeLibrary16(HINSTANCE)
struct tagLOGPALETTE LOGPALETTE
#define MB_OK
Definition: winuser.h:784
int __cardheight
Definition: cardlib.cpp:26
#define GetBValue(rgb)
Definition: wingdi.h:2936
WORD palNumEntries
Definition: wingdi.h:1833
static HBITMAP
Definition: button.c:44
HPALETTE MakePaletteFromCols(COLORREF cols[], int nNumColours)
static HBITMAP hBitmap
Definition: timezone.c:35
#define HeapFree(x, y, z)
Definition: compat.h:402
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define SRCCOPY
Definition: wingdi.h:332
HBITMAP WINAPI CreateBitmap(_In_ INT cx, _In_ INT cy, _In_ UINT cPlanes, _In_ UINT cBitsPerPel, _In_opt_ const VOID *pvBits)