Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

515 lines
12 KiB

  1. #include <windows.h>
  2. #include <port1632.h>
  3. #include "std.h"
  4. #include "crd.h"
  5. #include "back.h"
  6. #include "debug.h"
  7. #ifdef DEBUG
  8. #undef Assert
  9. #define Assert(f) { if (!(f)) { char s[80]; wsprintf(s, "CARDS.DLL: %s(%d)", (LPSTR) __FILE__, __LINE__); MessageBox(NULL, s, "Assert Failure", MB_OK); return FALSE; } }
  10. #endif
  11. VOID SaveCorners(HDC hdc, LONG FAR *rgRGB, INT x, INT y, INT dx, INT dy);
  12. VOID RestoreCorners(HDC hdc, LONG FAR *rgRGB, INT x, INT y, INT dx, INT dy);
  13. static HBITMAP HbmFromCd(INT cd);
  14. BOOL FLoadBack(INT cd);
  15. VOID MyDeleteHbm(HBITMAP hbm);
  16. typedef struct
  17. {
  18. INT id;
  19. DX dx;
  20. DY dy;
  21. } SPR;
  22. #define isprMax 4
  23. typedef struct
  24. {
  25. INT cdBase;
  26. DX dxspr;
  27. DY dyspr;
  28. INT isprMac;
  29. SPR rgspr[isprMax];
  30. } ANI;
  31. // we removed the older card decks that required Animation. The new
  32. // card deck doesn't involve any animation.
  33. #define ianiMax 0
  34. static INT cLoaded = 0;
  35. static HBITMAP hbmCard[52] =
  36. {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  37. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  38. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  39. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  40. static HBITMAP hbmGhost = NULL;
  41. static HBITMAP hbmBack = NULL;
  42. static HBITMAP hbmDeckX = NULL;
  43. static HBITMAP hbmDeckO = NULL;
  44. static INT idback = 0;
  45. static INT dxCard, dyCard;
  46. static INT cInits = 0;
  47. HANDLE hinstApp;
  48. /****** L I B M A I N ******/
  49. /* Called once to initialize data */
  50. /* Determines if display is color and remembers the hInstance for the DLL */
  51. INT APIENTRY LibMain(HANDLE hInst, ULONG ul_reason_being_called, LPVOID lpReserved)
  52. {
  53. hinstApp = hInst;
  54. return 1;
  55. UNREFERENCED_PARAMETER(ul_reason_being_called);
  56. UNREFERENCED_PARAMETER(lpReserved);
  57. }
  58. BOOL FInRange(INT w, INT wFirst, INT wLast)
  59. {
  60. Assert(wFirst <= wLast);
  61. return(w >= wFirst && w <= wLast);
  62. }
  63. BOOL APIENTRY cdtInit(INT FAR *pdxCard, INT FAR *pdyCard)
  64. /*
  65. * Parameters:
  66. * pdxCard, pdyCard
  67. * Far pointers to ints where card size will be placed
  68. *
  69. * Returns:
  70. * True when successful, False when it can't find one of the standard
  71. * bitmaps.
  72. */
  73. {
  74. BITMAP bmCard;
  75. HDC hdc;
  76. if (cInits++ != 0)
  77. {
  78. *pdxCard = dxCard;
  79. *pdyCard = dyCard;
  80. return fTrue;
  81. }
  82. hbmGhost = LoadBitmap( hinstApp, MAKEINTRESOURCE(IDGHOST));
  83. hbmDeckX = LoadBitmap( hinstApp, MAKEINTRESOURCE(IDX));
  84. hbmDeckO = LoadBitmap( hinstApp, MAKEINTRESOURCE(IDO));
  85. if(hbmGhost == NULL || hbmDeckX == NULL || hbmDeckO == NULL)
  86. goto Fail;
  87. GetObject( hbmGhost, sizeof( BITMAP), (LPSTR)&bmCard);
  88. dxCard = *pdxCard = bmCard.bmWidth;
  89. dyCard = *pdyCard = bmCard.bmHeight;
  90. return fTrue;
  91. Fail:
  92. MyDeleteHbm(hbmGhost);
  93. MyDeleteHbm(hbmDeckX);
  94. MyDeleteHbm(hbmDeckO);
  95. return fFalse;
  96. UNREFERENCED_PARAMETER(hdc);
  97. }
  98. BOOL APIENTRY cdtDrawExt(HDC hdc, INT x, INT y, INT dx, INT dy,
  99. INT cd, INT mode, DWORD rgbBgnd)
  100. /*
  101. * Parameters:
  102. * hdc HDC to window to draw cards on
  103. * x, y Where you'd like them
  104. * dx,dy card extents
  105. * cd Card to be drawn
  106. * mode Way you want it drawn (or with MINLONG if to be fast)
  107. *
  108. * Returns:
  109. * True if card successfully drawn, False otherwise
  110. */
  111. {
  112. static HBITMAP hbmSav;
  113. HDC hdcMemory;
  114. DWORD dwRop = 0;
  115. HBRUSH hbr;
  116. PT pt;
  117. POINT ptReal;
  118. LONG rgRGB[12];
  119. DWORD dwOldBknd;
  120. BOOL bFast=FALSE; // true if we shouldn't save corners
  121. if( mode & MINLONG )
  122. {
  123. mode= mode + MINLONG;
  124. bFast= TRUE;
  125. }
  126. Assert(hdc != NULL);
  127. switch (mode)
  128. {
  129. default:
  130. Assert(fFalse);
  131. break;
  132. case FACEUP:
  133. hbmSav = HbmFromCd(cd);
  134. dwRop = SRCCOPY;
  135. rgbBgnd = RGB(255,255,255);
  136. break;
  137. case FACEDOWN:
  138. if(!FLoadBack(cd))
  139. return fFalse;
  140. hbmSav = hbmBack;
  141. dwRop = SRCCOPY;
  142. break;
  143. case REMOVE:
  144. case GHOST:
  145. hbr = CreateSolidBrush( rgbBgnd);
  146. if(hbr == NULL)
  147. return fFalse;
  148. /* *(LONG *)&pt = +++GetDCOrg - NO 32BIT FORM(probably can noop)+++(hdc); */
  149. //guess again! -- 12-Jul-1994 JonPa
  150. GetDCOrgEx(hdc, &ptReal);
  151. pt.x = ptReal.x;
  152. pt.y = ptReal.y;
  153. (VOID)MSetBrushOrg( hdc, pt.x, pt.y);
  154. MUnrealizeObject( hbr);
  155. if((hbr = SelectObject( hdc, hbr)) != NULL)
  156. {
  157. PatBlt(hdc, x, y, dx, dy, PATCOPY);
  158. hbr = SelectObject( hdc, hbr);
  159. }
  160. if (hbr)
  161. DeleteObject( hbr);
  162. if(mode == REMOVE)
  163. return fTrue;
  164. Assert(mode == GHOST);
  165. // default: fall thru
  166. case INVISIBLEGHOST:
  167. hbmSav = hbmGhost;
  168. dwRop = SRCAND;
  169. break;
  170. case DECKX:
  171. hbmSav = hbmDeckX;
  172. dwRop = SRCCOPY;
  173. break;
  174. case DECKO:
  175. hbmSav = hbmDeckO;
  176. dwRop = SRCCOPY;
  177. break;
  178. case HILITE:
  179. hbmSav = HbmFromCd( cd);
  180. dwRop = NOTSRCCOPY;
  181. break;
  182. }
  183. if (hbmSav == NULL)
  184. return fFalse;
  185. else
  186. {
  187. hdcMemory = CreateCompatibleDC( hdc);
  188. if(hdcMemory == NULL)
  189. return fFalse;
  190. if((hbmSav = SelectObject( hdcMemory, hbmSav)) != NULL)
  191. {
  192. dwOldBknd = SetBkColor(hdc, rgbBgnd);
  193. if( !bFast )
  194. SaveCorners(hdc, rgRGB, x, y, dx, dy);
  195. if(dx != dxCard || dy != dyCard)
  196. StretchBlt(hdc, x, y, dx, dy, hdcMemory, 0, 0, dxCard, dyCard, dwRop);
  197. else
  198. BitBlt( hdc, x, y, dxCard, dyCard, hdcMemory, 0, 0, dwRop);
  199. SelectObject( hdcMemory, hbmSav);
  200. /* draw the border for the red cards */
  201. if(mode == FACEUP)
  202. {
  203. INT icd;
  204. icd = RaFromCd(cd) % 13 + SuFromCd(cd) * 13+1;
  205. if((icd >= IDADIAMONDS && icd <= IDTDIAMONDS) ||
  206. (icd >= IDAHEARTS && icd <= IDTHEARTS))
  207. {
  208. PatBlt(hdc, x+2, y, dx-4, 1, BLACKNESS); // top
  209. PatBlt(hdc, x+dx-1, y+2, 1, dy-4, BLACKNESS); // right
  210. PatBlt(hdc, x+2, y+dy-1, dx-4, 1, BLACKNESS); // bottom
  211. PatBlt(hdc, x, y+2, 1, dy-4, BLACKNESS); // left
  212. SetPixel(hdc, x+1, y+1, 0L); // top left
  213. SetPixel(hdc, x+dx-2, y+1, 0L); // top right
  214. SetPixel(hdc, x+dx-2, y+dy-2, 0L); // bot right
  215. SetPixel(hdc, x+1, y+dy-2, 0L); // bot left
  216. }
  217. }
  218. if( !bFast )
  219. RestoreCorners(hdc, rgRGB, x, y, dx, dy);
  220. SetBkColor(hdc, dwOldBknd);
  221. }
  222. DeleteDC( hdcMemory);
  223. return fTrue;
  224. }
  225. }
  226. BOOL APIENTRY cdtDraw(HDC hdc, INT x, INT y, INT cd, INT mode, DWORD rgbBgnd)
  227. /*
  228. * Parameters:
  229. * hdc HDC to window to draw cards on
  230. * x, y Where you'd like them
  231. * cd Card to be drawn
  232. * mode Way you want it drawn
  233. *
  234. * Returns:
  235. * True if card successfully drawn, False otherwise
  236. */
  237. {
  238. return cdtDrawExt(hdc, x, y, dxCard, dyCard, cd, mode, rgbBgnd);
  239. }
  240. VOID SaveCorners(HDC hdc, LONG FAR *rgRGB, INT x, INT y, INT dx, INT dy)
  241. {
  242. if(dx != dxCard || dy != dyCard)
  243. return;
  244. // Upper Left
  245. rgRGB[0] = GetPixel(hdc, x, y);
  246. rgRGB[1] = GetPixel(hdc, x+1, y);
  247. rgRGB[2] = GetPixel(hdc, x, y+1);
  248. // Upper Right
  249. x += dx -1;
  250. rgRGB[3] = GetPixel(hdc, x, y);
  251. rgRGB[4] = GetPixel(hdc, x-1, y);
  252. rgRGB[5] = GetPixel(hdc, x, y+1);
  253. // Lower Right
  254. y += dy-1;
  255. rgRGB[6] = GetPixel(hdc, x, y);
  256. rgRGB[7] = GetPixel(hdc, x, y-1);
  257. rgRGB[8] = GetPixel(hdc, x-1, y);
  258. // Lower Left
  259. x -= dx-1;
  260. rgRGB[9] = GetPixel(hdc, x, y);
  261. rgRGB[10] = GetPixel(hdc, x+1, y);
  262. rgRGB[11] = GetPixel(hdc, x, y-1);
  263. }
  264. BOOL APIENTRY cdtAnimate(HDC hdc, INT cd, INT x, INT y, INT ispr)
  265. {
  266. INT iani;
  267. ANI *pani;
  268. SPR *pspr;
  269. HBITMAP hbm;
  270. HDC hdcMem;
  271. X xSrc;
  272. Y ySrc;
  273. // remove animation as we are removing those card decks but just in case
  274. // someone calls this function, don't do anything.
  275. return fTrue;
  276. #ifdef UNUSEDCODE
  277. if(ispr < 0)
  278. return fFalse;
  279. Assert(hdc != NULL);
  280. for(iani = 0; iani < ianiMax; iani++)
  281. {
  282. if(cd == rgani[iani].cdBase)
  283. {
  284. pani = &rgani[iani];
  285. if(ispr < pani->isprMac)
  286. {
  287. pspr = &pani->rgspr[ispr];
  288. Assert(pspr->id != 0);
  289. if(pspr->id == cd)
  290. {
  291. xSrc = pspr->dx;
  292. ySrc = pspr->dy;
  293. }
  294. else
  295. xSrc = ySrc = 0;
  296. hbm = LoadBitmap(hinstApp, MAKEINTRESOURCE(pspr->id));
  297. if(hbm == NULL)
  298. return fFalse;
  299. hdcMem = CreateCompatibleDC(hdc);
  300. if(hdcMem == NULL)
  301. {
  302. DeleteObject(hbm);
  303. return fFalse;
  304. }
  305. if((hbm = SelectObject(hdcMem, hbm)) != NULL)
  306. {
  307. BitBlt(hdc, x+pspr->dx, y+pspr->dy, pani->dxspr, pani->dyspr,
  308. hdcMem, xSrc, ySrc, SRCCOPY);
  309. DeleteObject(SelectObject(hdcMem, hbm));
  310. }
  311. DeleteDC(hdcMem);
  312. return fTrue;
  313. }
  314. }
  315. }
  316. return fFalse;
  317. #endif
  318. }
  319. VOID RestoreCorners(HDC hdc, LONG FAR *rgRGB, INT x, INT y, INT dx, INT dy)
  320. {
  321. if(dx != dxCard || dy != dyCard)
  322. return;
  323. // Upper Left
  324. SetPixel(hdc, x, y, rgRGB[0]);
  325. SetPixel(hdc, x+1, y, rgRGB[1]);
  326. SetPixel(hdc, x, y+1, rgRGB[2]);
  327. // Upper Right
  328. x += dx-1;
  329. SetPixel(hdc, x, y, rgRGB[3]);
  330. SetPixel(hdc, x-1, y, rgRGB[4]);
  331. SetPixel(hdc, x, y+1, rgRGB[5]);
  332. // Lower Right
  333. y += dy-1;
  334. SetPixel(hdc, x, y, rgRGB[6]);
  335. SetPixel(hdc, x, y-1, rgRGB[7]);
  336. SetPixel(hdc, x-1, y, rgRGB[8]);
  337. // Lower Left
  338. x -= dx-1;
  339. SetPixel(hdc, x, y, rgRGB[9]);
  340. SetPixel(hdc, x+1, y, rgRGB[10]);
  341. SetPixel(hdc, x, y-1, rgRGB[11]);
  342. }
  343. /* loads global bitmap hbmBack */
  344. BOOL FLoadBack(INT idbackNew)
  345. {
  346. extern HBITMAP hbmBack;
  347. extern INT idback;
  348. CHAR szPath[64];
  349. INT fh;
  350. CHAR *pch;
  351. Assert(FInRange(idbackNew, IDFACEDOWNFIRST, IDFACEDOWNLAST));
  352. if(idback != idbackNew)
  353. {
  354. MyDeleteHbm(hbmBack);
  355. if((hbmBack = LoadBitmap(hinstApp, MAKEINTRESOURCE(idbackNew))) != NULL)
  356. idback = idbackNew;
  357. else
  358. idback = 0;
  359. }
  360. return idback != 0;
  361. UNREFERENCED_PARAMETER(pch);
  362. UNREFERENCED_PARAMETER(szPath);
  363. UNREFERENCED_PARAMETER(fh);
  364. }
  365. static HBITMAP HbmFromCd(INT cd)
  366. {
  367. static INT iNext = 0;
  368. INT icd;
  369. if (hbmCard[cd] == NULL)
  370. {
  371. if (cLoaded >= CLOADMAX)
  372. {
  373. for (; hbmCard[iNext] == NULL;
  374. iNext = (iNext == 51) ? 0 : iNext + 1);
  375. DeleteObject( hbmCard[iNext]);
  376. hbmCard[iNext] = NULL;
  377. cLoaded--;
  378. }
  379. icd = RaFromCd(cd) % 13 + SuFromCd(cd) * 13;
  380. while ((hbmCard[cd]=LoadBitmap(hinstApp,MAKEINTRESOURCE(icd+1)))
  381. == NULL)
  382. {
  383. if (cLoaded == 0)
  384. return NULL;
  385. else
  386. {
  387. for (; hbmCard[iNext] == NULL;
  388. iNext = (iNext == 51) ? 0 : iNext + 1);
  389. DeleteObject( hbmCard[iNext]);
  390. hbmCard[iNext] = NULL;
  391. cLoaded--;
  392. }
  393. }
  394. cLoaded++;
  395. }
  396. return hbmCard[cd];
  397. }
  398. VOID MyDeleteHbm(HBITMAP hbm)
  399. {
  400. if(hbm != NULL)
  401. DeleteObject(hbm);
  402. }
  403. VOID APIENTRY cdtTerm()
  404. /*
  405. * Free up space if it's time to do so.
  406. *
  407. * Parameters:
  408. * none
  409. *
  410. * Returns:
  411. * nothing
  412. */
  413. {
  414. INT i;
  415. if (--cInits > 0)
  416. return;
  417. for (i = 0; i < 52; i++)
  418. MyDeleteHbm(hbmCard[i]);
  419. MyDeleteHbm(hbmGhost);
  420. MyDeleteHbm(hbmBack);
  421. MyDeleteHbm(hbmDeckX);
  422. MyDeleteHbm(hbmDeckO);
  423. }
  424. INT APIENTRY WEP(INT nCmd)
  425. {
  426. return 1;
  427. UNREFERENCED_PARAMETER(nCmd);
  428. }