Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencardbitmaps.cppGo to the documentation of this file.00001 // 00002 // CardLib - Card bitmap support 00003 // 00004 // Freeware 00005 // Copyright J Brown 2001 00006 // 00007 #include <windows.h> 00008 #include "globals.h" 00009 #include "cardcolor.h" 00010 00011 #ifndef __REACTOS__ 00012 #pragma comment( lib, "..\\CardLib\\cards16.lib" ) 00013 00014 extern "C" HINSTANCE WINAPI LoadLibrary16( PSTR ); 00015 extern "C" void WINAPI FreeLibrary16( HINSTANCE ); 00016 #endif 00017 00018 #define NUMCARDBITMAPS (52+16) 00019 00020 void PaintRect(HDC hdc, RECT *rect, COLORREF col); 00021 00022 void LoadCardBitmapsFromLibrary(HINSTANCE hCardDll, int *pwidth, int *pheight) 00023 { 00024 HBITMAP hBitmap; 00025 HDC hdcCard = NULL; 00026 HANDLE hOld; 00027 int i, xpos; 00028 int width, height; 00029 BITMAP bmp; 00030 00031 for(i = 0; i < NUMCARDBITMAPS; i++) 00032 { 00033 //convert into the range used by the cdt_xxx functions 00034 int val; 00035 00036 if(i < 52) val = (i % 4) * 13 + (i/4); 00037 else val = i; 00038 00039 hBitmap = LoadBitmap(hCardDll, MAKEINTRESOURCE(val + 1)); 00040 GetObject(hBitmap, sizeof(bmp), &bmp); 00041 00042 width = bmp.bmWidth; 00043 height = bmp.bmHeight; 00044 00045 if(i == 0) //if first time through, create BIG bitmap.. 00046 { 00047 HDC hdc = GetDC(0); 00048 __hdcCardBitmaps = CreateCompatibleDC(hdc); 00049 __hbmCardBitmaps = CreateCompatibleBitmap(hdc, width * NUMCARDBITMAPS, height); 00050 SelectObject(__hdcCardBitmaps, __hbmCardBitmaps); 00051 00052 hdcCard = CreateCompatibleDC(0); 00053 00054 ReleaseDC(0, hdc); 00055 } 00056 00057 hOld = SelectObject(hdcCard, hBitmap); 00058 BitBlt(__hdcCardBitmaps, i*width, 0, width, height, hdcCard, 0, 0, SRCCOPY); 00059 SelectObject(hdcCard, hOld); 00060 00061 //Now draw a black border around each card... 00062 xpos = i*width; 00063 MoveToEx(__hdcCardBitmaps, xpos+2, 0, 0); 00064 LineTo(__hdcCardBitmaps, xpos+width - 3, 0); 00065 LineTo(__hdcCardBitmaps, xpos+width - 1, 2); 00066 LineTo(__hdcCardBitmaps, xpos+width - 1, height - 3); //vertical 00067 LineTo(__hdcCardBitmaps, xpos+width - 3, height - 1); 00068 LineTo(__hdcCardBitmaps, xpos+2, height - 1); 00069 LineTo(__hdcCardBitmaps, xpos+0, height - 3); 00070 LineTo(__hdcCardBitmaps, xpos+0, 2); 00071 LineTo(__hdcCardBitmaps, xpos+2, 0); 00072 00073 DeleteObject(hBitmap); 00074 } 00075 00076 DeleteDC(hdcCard); 00077 00078 *pwidth = width; 00079 *pheight = height; 00080 00081 } 00082 00083 void LoadCardBitmaps(void) 00084 { 00085 HINSTANCE hCardDll; 00086 00087 00088 //If Windows NT/2000/XP 00089 if(GetVersion() < 0x80000000) 00090 { 00091 hCardDll = LoadLibrary(TEXT("cards.dll")); 00092 00093 if(hCardDll == 0) 00094 { 00095 MessageBox(0, TEXT("Error loading cards.dll (32bit)"), TEXT("Shed"), MB_OK | MB_ICONEXCLAMATION); 00096 PostQuitMessage(0); 00097 return; 00098 } 00099 00100 LoadCardBitmapsFromLibrary(hCardDll, &__cardwidth, &__cardheight); 00101 00102 FreeLibrary(hCardDll); 00103 } 00104 #ifndef __REACTOS__ 00105 //Else, Win9X 00106 else 00107 { 00108 hCardDll = LoadLibrary16("cards.dll"); 00109 00110 if(hCardDll == 0) 00111 { 00112 MessageBox(0, "Error loading cards.dll (16bit)", "Shed", MB_OK | MB_ICONEXCLAMATION); 00113 PostQuitMessage(0); 00114 return; 00115 } 00116 00117 LoadCardBitmapsFromLibrary(hCardDll, &__cardwidth, &__cardheight); 00118 00119 FreeLibrary16(hCardDll); 00120 } 00121 #endif 00122 } 00123 00124 void FreeCardBitmaps() 00125 { 00126 DeleteObject (__hbmCardBitmaps); 00127 DeleteDC (__hdcCardBitmaps); 00128 } 00129 // 00130 // Paint a checkered rectangle, with each alternate 00131 // pixel being assigned a different colour 00132 // 00133 static void DrawCheckedRect(HDC hdc, RECT *rect, COLORREF fg, COLORREF bg) 00134 { 00135 static WORD wCheckPat[8] = 00136 { 00137 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555 00138 }; 00139 00140 HBITMAP hbmp; 00141 HBRUSH hbr, hbrold; 00142 COLORREF fgold, bgold; 00143 00144 hbmp = CreateBitmap(8, 8, 1, 1, wCheckPat); 00145 hbr = CreatePatternBrush(hbmp); 00146 00147 //UnrealizeObject(hbr); 00148 00149 SetBrushOrgEx(hdc, rect->left, rect->top, 0); 00150 00151 hbrold = (HBRUSH)SelectObject(hdc, hbr); 00152 00153 fgold = SetTextColor(hdc, fg); 00154 bgold = SetBkColor(hdc, bg); 00155 00156 PatBlt(hdc, rect->left, rect->top, 00157 rect->right - rect->left, 00158 rect->bottom - rect->top, 00159 PATCOPY); 00160 00161 SetBkColor(hdc, bgold); 00162 SetTextColor(hdc, fgold); 00163 00164 SelectObject(hdc, hbrold); 00165 DeleteObject(hbr); 00166 DeleteObject(hbmp); 00167 } 00168 00169 void GetSinkCols(COLORREF crBase, COLORREF *fg, COLORREF *bg, COLORREF *sh1, COLORREF *sh2) 00170 { 00171 if(bg) *bg = crBase; 00172 if(fg) *fg = ColorScaleRGB(crBase, RGB(255,255,255), 0.2);//RGB(49, 99, 140); 00173 if(sh1) *sh1 = ColorScaleRGB(crBase, RGB(0,0,0), 0.4); 00174 if(sh2) *sh2 = ColorScaleRGB(crBase, RGB(0,0,0), 0.2); 00175 } 00176 00177 HBITMAP CreateSinkBmp(HDC hdcCompat, HDC hdc, COLORREF col, int width, int height) 00178 { 00179 HANDLE hold, hpold; 00180 HBITMAP hbm = CreateCompatibleBitmap(hdcCompat, width, height); 00181 00182 HPEN hpfg, hpbg, hpsh, hpsh2; 00183 00184 RECT rect; 00185 COLORREF fg, bg, shadow, shadow2; 00186 00187 GetSinkCols(col, &fg, &bg, &shadow, &shadow2); 00188 00189 hold = SelectObject(hdc, hbm); 00190 00191 //fill with a solid base colour 00192 SetRect(&rect, 0,0,width,height); 00193 PaintRect(hdc, &rect, MAKE_PALETTERGB(bg)); 00194 00195 //draw the outline 00196 hpfg = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(fg)); 00197 hpbg = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(bg)); 00198 hpsh = CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(shadow)); 00199 hpsh2= CreatePen(PS_SOLID, 0, MAKE_PALETTERGB(shadow2)); 00200 00201 hpold = SelectObject(hdc, hpsh); 00202 MoveToEx(hdc, 2, 0, NULL); 00203 LineTo (hdc, width-3,0); 00204 LineTo (hdc, width-1, 2); 00205 00206 SelectObject(hdc, hpold); 00207 hpold = SelectObject(hdc, hpsh2); 00208 LineTo (hdc, width-1, height-3); //vertical 00209 LineTo (hdc, width-3, height-1); 00210 LineTo (hdc, 2, height-1); 00211 LineTo (hdc, 0, height-3); 00212 SelectObject(hdc, hpold); 00213 hpold = SelectObject(hdc, hpsh); 00214 00215 //MoveToEx( hdc, 0, height-3,0); 00216 LineTo (hdc, 0, 2); 00217 LineTo (hdc, 2, 0); 00218 00219 SelectObject(hdc, hpold); 00220 00221 //draw the highlight (vertical) 00222 hpold = SelectObject(hdc, hpfg); 00223 MoveToEx(hdc, width - 2, 3, NULL); 00224 LineTo (hdc, width - 2, height - 2); 00225 00226 //(horz) 00227 MoveToEx(hdc, width - 3, height-2, NULL); 00228 LineTo (hdc, 3, height-2); 00229 SelectObject(hdc, hpold); 00230 00231 //draw the background 00232 InflateRect(&rect, -2, -2); 00233 DrawCheckedRect(hdc, &rect, MAKE_PALETTERGB(bg), MAKE_PALETTERGB(fg)); 00234 00235 //overwrite the top-left background pixel 00236 SetPixel(hdc, 2, 2, MAKE_PALETTERGB(bg)); 00237 00238 DeleteObject(hpsh); 00239 DeleteObject(hpsh2); 00240 DeleteObject(hpfg); 00241 DeleteObject(hpbg); 00242 00243 00244 return hbm; 00245 } 00246 00247 00248 00249 void CopyColor(PALETTEENTRY *pe, COLORREF col) 00250 { 00251 pe->peBlue = GetBValue(col); 00252 pe->peGreen = GetGValue(col); 00253 pe->peRed = GetRValue(col); 00254 pe->peFlags = 0; 00255 } 00256 00257 HPALETTE MakePaletteFromCols(COLORREF cols[], int nNumColours) 00258 { 00259 LOGPALETTE *lp; 00260 HPALETTE hPalette; 00261 00262 // Allocate memory for the logical palette 00263 lp = (LOGPALETTE *)HeapAlloc( 00264 GetProcessHeap(), 0, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * nNumColours); 00265 00266 lp->palNumEntries = (WORD)nNumColours; 00267 lp->palVersion = 0x300; 00268 00269 //copy the colours into the logical palette format 00270 for(int i = 0; i < nNumColours; i++) 00271 { 00272 CopyColor(&lp->palPalEntry[i], cols[i]); 00273 } 00274 00275 // create palette! 00276 hPalette = CreatePalette(lp); 00277 00278 HeapFree(GetProcessHeap(), 0, lp); 00279 00280 return hPalette; 00281 } Generated on Thu Feb 9 04:59:24 2012 for ReactOS by
1.6.3
|