Leaked source code of windows server 2003
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.

613 lines
18 KiB

  1. #include "sol.h"
  2. #ifndef DLL
  3. VSZASSERT
  4. #else
  5. #ifdef DEBUG
  6. #undef Assert
  7. #define Assert(f) { if (!(f)) { ExitWindows(0L); } }
  8. #endif
  9. #endif
  10. #define COOLCARD
  11. #ifdef COOLCARD
  12. void SaveCorners(HDC hdc, LONG FAR *rgRGB, INT x, INT y, INT dx, INT dy);
  13. void RestoreCorners(HDC hdc, LONG FAR *rgRGB, INT x, INT y, INT dx, INT dy);
  14. #endif
  15. VOID APIENTRY cdtTerm(VOID);
  16. VOID MyDeleteHbm(HBITMAP hbm);
  17. static HBITMAP HbmFromCd(INT, HDC);
  18. static BOOL FLoadBack(INT);
  19. // we removed the older card decks that required Animation. The new
  20. // card deck doesn't involve any animation.
  21. #ifdef UNUSEDCODE
  22. typedef struct
  23. {
  24. INT id;
  25. DX dx;
  26. DY dy;
  27. } SPR;
  28. #define isprMax 4
  29. typedef struct
  30. {
  31. INT cdBase;
  32. DX dxspr;
  33. DY dyspr;
  34. INT isprMac;
  35. SPR rgspr[isprMax];
  36. } ANI;
  37. #define ianiMax 4
  38. static ANI rgani[ianiMax] =
  39. { IDFACEDOWN12, 32, 22, 4,
  40. {IDASLIME1, 32, 32,
  41. IDASLIME2, 32, 32,
  42. IDASLIME1, 32, 32,
  43. IDFACEDOWN12, 32, 32
  44. },
  45. IDFACEDOWN10, 36, 12, 2,
  46. {IDAKASTL1, 42, 12,
  47. IDFACEDOWN10, 42, 12,
  48. 0, 0, 0,
  49. 0, 0, 0
  50. },
  51. IDFACEDOWN11, 14, 12, 4,
  52. {
  53. IDAFLIPE1, 47, 1,
  54. IDAFLIPE2, 47, 1,
  55. IDAFLIPE1, 47, 1,
  56. IDFACEDOWN11, 47, 1
  57. },
  58. IDFACEDOWN3, 24, 7, 4,
  59. {
  60. IDABROBOT1, 24, 40,
  61. IDABROBOT2, 24, 40,
  62. IDABROBOT1, 24, 40,
  63. IDFACEDOWN3, 24, 40
  64. }
  65. /* remember to inc ianiMax */
  66. };
  67. #endif
  68. static HBITMAP hbmCard[52] =
  69. {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  70. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  71. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  72. NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  73. static HBITMAP hbmGhost = NULL;
  74. static HBITMAP hbmBack = NULL;
  75. static HBITMAP hbmDeckX = NULL;
  76. static HBITMAP hbmDeckO = NULL;
  77. static INT idback = 0;
  78. static INT dxCard, dyCard;
  79. static INT cInits = 0;
  80. #ifdef DLL
  81. HANDLE hinstApp;
  82. #else
  83. extern HANDLE hinstApp;
  84. #endif
  85. BOOL APIENTRY cdtInit(INT FAR *pdxCard, INT FAR *pdyCard)
  86. /*
  87. * Parameters:
  88. * pdxCard, pdyCard
  89. * Far pointers to ints where card size will be placed
  90. *
  91. * Returns:
  92. * True when successful, False when it can't find one of the standard
  93. * bitmaps.
  94. */
  95. {
  96. BITMAP bmCard;
  97. HDC hdc = NULL;
  98. HBITMAP hbmDstBitmap;
  99. HANDLE hDstOld;
  100. HANDLE hSrcOld;
  101. HDC hdcDstMemory;
  102. HDC hdcSrcMemory;
  103. #ifdef DLL
  104. if (cInits++ != 0)
  105. {
  106. *pdxCard = dxCard;
  107. *pdyCard = dyCard;
  108. return fTrue;
  109. }
  110. #endif
  111. hbmGhost = LoadBitmap( hinstApp, MAKEINTRESOURCE(IDGHOST));
  112. hbmDeckX = LoadBitmap( hinstApp, MAKEINTRESOURCE(IDX));
  113. hbmDeckO = LoadBitmap( hinstApp, MAKEINTRESOURCE(IDO));
  114. if(hbmGhost == NULL || hbmDeckX == NULL || hbmDeckO == NULL) {
  115. goto Fail;
  116. }
  117. GetObject( hbmGhost, sizeof( BITMAP), (LPSTR)&bmCard);
  118. dxCard = *pdxCard = bmCard.bmWidth;
  119. dyCard = *pdyCard = bmCard.bmHeight;
  120. //
  121. // Create two compatible memory DCs for bitmap conversion.
  122. //
  123. hdc = GetDC(NULL);
  124. hdcSrcMemory = CreateCompatibleDC(hdc);
  125. hdcDstMemory = CreateCompatibleDC(hdc);
  126. if ((hdcSrcMemory == NULL) || (hdcDstMemory == NULL)) {
  127. goto Fail;
  128. }
  129. //
  130. // Create a compatible bitmap for the conversion of the Ghost
  131. // bitmap, blt the loaded bitmap to the compatible bitmap, and
  132. // delete the original bitmap.
  133. //
  134. hbmDstBitmap = CreateCompatibleBitmap(hdc, dxCard, dyCard);
  135. if (hbmDstBitmap == NULL) {
  136. goto Fail;
  137. }
  138. hSrcOld = SelectObject(hdcSrcMemory, hbmGhost);
  139. hDstOld = SelectObject(hdcDstMemory, hbmDstBitmap);
  140. BitBlt(hdcDstMemory, 0, 0, dxCard, dyCard, hdcSrcMemory, 0, 0, SRCCOPY);
  141. SelectObject(hdcSrcMemory, hSrcOld);
  142. SelectObject(hdcDstMemory, hDstOld);
  143. DeleteObject(hbmGhost);
  144. hbmGhost = hbmDstBitmap;
  145. //
  146. // Create a compatible bitmap for the conversion of the DeckX
  147. // bitmap, blt the loaded bitmap to the compatible bitmap, and
  148. // delete the original bitmap.
  149. //
  150. hbmDstBitmap = CreateCompatibleBitmap(hdc, dxCard, dyCard);
  151. if (hbmDstBitmap == NULL) {
  152. goto Fail;
  153. }
  154. hSrcOld = SelectObject(hdcSrcMemory, hbmDeckX);
  155. hDstOld = SelectObject(hdcDstMemory, hbmDstBitmap);
  156. BitBlt(hdcDstMemory, 0, 0, dxCard, dyCard, hdcSrcMemory, 0, 0, SRCCOPY);
  157. SelectObject(hdcSrcMemory, hSrcOld);
  158. SelectObject(hdcDstMemory, hDstOld);
  159. DeleteObject(hbmDeckX);
  160. hbmDeckX = hbmDstBitmap;
  161. //
  162. // Create a compatible bitmap for the conversion of the DeckO
  163. // bitmap, blt the loaded bitmap to the compatible bitmap, and
  164. // delete the original bitmap.
  165. //
  166. hbmDstBitmap = CreateCompatibleBitmap(hdc, dxCard, dyCard);
  167. if (hbmDstBitmap == NULL) {
  168. }
  169. hSrcOld = SelectObject(hdcSrcMemory, hbmDeckO);
  170. hDstOld = SelectObject(hdcDstMemory, hbmDstBitmap);
  171. BitBlt(hdcDstMemory, 0, 0, dxCard, dyCard, hdcSrcMemory, 0, 0, SRCCOPY);
  172. SelectObject(hdcSrcMemory, hSrcOld);
  173. SelectObject(hdcDstMemory, hDstOld);
  174. DeleteObject(hbmDeckO);
  175. hbmDeckO = hbmDstBitmap;
  176. //
  177. // Delete the compatible DCs.
  178. //
  179. DeleteDC(hdcDstMemory);
  180. DeleteDC(hdcSrcMemory);
  181. ReleaseDC(NULL, hdc);
  182. return fTrue;
  183. Fail:
  184. if (hdc != NULL) {
  185. ReleaseDC(NULL, hdc);
  186. }
  187. cdtTerm();
  188. return fFalse;
  189. }
  190. BOOL APIENTRY cdtDrawExt(HDC hdc, INT x, INT y, INT dx, INT dy, INT cd, INT mode, DWORD rgbBgnd)
  191. /*
  192. * Parameters:
  193. * hdc HDC to window to draw cards on
  194. * x, y Where you'd like them
  195. * dx,dy card extents
  196. * cd Card to be drawn
  197. * mode Way you want it drawn
  198. *
  199. * Returns:
  200. * True if card successfully drawn, False otherwise
  201. */
  202. {
  203. HBITMAP hbmSav;
  204. HDC hdcMemory;
  205. DWORD dwRop;
  206. HBRUSH hbr;
  207. #ifdef COOLCARD
  208. LONG rgRGB[12];
  209. #endif
  210. Assert(hdc != NULL);
  211. switch (mode)
  212. {
  213. default:
  214. Assert(fFalse);
  215. break;
  216. case FACEUP:
  217. hbmSav = HbmFromCd(cd, hdc);
  218. dwRop = SRCCOPY;
  219. break;
  220. case FACEDOWN:
  221. if(!FLoadBack(cd))
  222. return fFalse;
  223. hbmSav = hbmBack;
  224. dwRop = SRCCOPY;
  225. break;
  226. case REMOVE:
  227. case GHOST:
  228. hbr = CreateSolidBrush( rgbBgnd);
  229. if(hbr == NULL)
  230. return fFalse;
  231. MUnrealizeObject( hbr);
  232. if((hbr = SelectObject( hdc, hbr)) != NULL)
  233. {
  234. PatBlt(hdc, x, y, dx, dy, PATCOPY);
  235. hbr = SelectObject( hdc, hbr);
  236. }
  237. DeleteObject( hbr);
  238. if(mode == REMOVE)
  239. return fTrue;
  240. Assert(mode == GHOST);
  241. /* default: fall thru */
  242. case INVISIBLEGHOST:
  243. hbmSav = hbmGhost;
  244. dwRop = SRCAND;
  245. break;
  246. case DECKX:
  247. hbmSav = hbmDeckX;
  248. dwRop = SRCCOPY;
  249. break;
  250. case DECKO:
  251. hbmSav = hbmDeckO;
  252. dwRop = SRCCOPY;
  253. break;
  254. case HILITE:
  255. hbmSav = HbmFromCd(cd, hdc);
  256. dwRop = NOTSRCCOPY;
  257. break;
  258. }
  259. if (hbmSav == NULL)
  260. return fFalse;
  261. else
  262. {
  263. hdcMemory = CreateCompatibleDC( hdc);
  264. if(hdcMemory == NULL)
  265. return fFalse;
  266. if((hbmSav = SelectObject( hdcMemory, hbmSav)) != NULL)
  267. {
  268. #ifdef COOLCARD
  269. if( !fKlondWinner )
  270. SaveCorners(hdc, rgRGB, x, y, dx, dy);
  271. #endif
  272. if(dx != dxCard || dy != dyCard)
  273. StretchBlt(hdc, x, y, dx, dy, hdcMemory, 0, 0, dxCard, dyCard, dwRop);
  274. else
  275. BitBlt( hdc, x, y, dxCard, dyCard, hdcMemory, 0, 0, dwRop);
  276. SelectObject( hdcMemory, hbmSav);
  277. /* draw the border for the red cards */
  278. if(mode == FACEUP)
  279. {
  280. INT icd;
  281. icd = RaFromCd(cd) % 13 + SuFromCd(cd) * 13+1;
  282. if((icd >= IDADIAMONDS && icd <= IDTDIAMONDS) ||
  283. (icd >= IDAHEARTS && icd <= IDTHEARTS))
  284. {
  285. PatBlt(hdc, x+2, y, dx-4, 1, BLACKNESS); /* top */
  286. PatBlt(hdc, x+dx-1, y+2, 1, dy-4, BLACKNESS); /* right */
  287. PatBlt(hdc, x+2, y+dy-1, dx-4, 1, BLACKNESS); /* bottom */
  288. PatBlt(hdc, x, y+2, 1, dy-4, BLACKNESS); /* left */
  289. SetPixel(hdc, x+1, y+1, 0L); /* top left */
  290. SetPixel(hdc, x+dx-2, y+1, 0L); /* top right */
  291. SetPixel(hdc, x+dx-2, y+dy-2, 0L); /* bot right */
  292. SetPixel(hdc, x+1, y+dy-2, 0L); /* bot left */
  293. }
  294. }
  295. #ifdef COOLCARD
  296. if( !fKlondWinner )
  297. RestoreCorners(hdc, rgRGB, x, y, dx, dy);
  298. #endif
  299. }
  300. DeleteDC( hdcMemory);
  301. return fTrue;
  302. }
  303. }
  304. BOOL APIENTRY cdtDraw(HDC hdc, INT x, INT y, INT cd, INT mode, DWORD rgbBgnd)
  305. /*
  306. * Parameters:
  307. * hdc HDC to window to draw cards on
  308. * x, y Where you'd like them
  309. * cd Card to be drawn
  310. * mode Way you want it drawn
  311. *
  312. * Returns:
  313. * True if card successfully drawn, False otherwise
  314. */
  315. {
  316. return cdtDrawExt(hdc, x, y, dxCard, dyCard, cd, mode, rgbBgnd);
  317. }
  318. #ifdef COOLCARD
  319. void SaveCorners(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. rgRGB[0] = GetPixel(hdc, x, y);
  325. rgRGB[1] = GetPixel(hdc, x+1, y);
  326. rgRGB[2] = GetPixel(hdc, x, y+1);
  327. /* Upper Right */
  328. x += dx -1;
  329. rgRGB[3] = GetPixel(hdc, x, y);
  330. rgRGB[4] = GetPixel(hdc, x-1, y);
  331. rgRGB[5] = GetPixel(hdc, x, y+1);
  332. /* Lower Right */
  333. y += dy-1;
  334. rgRGB[6] = GetPixel(hdc, x, y);
  335. rgRGB[7] = GetPixel(hdc, x, y-1);
  336. rgRGB[8] = GetPixel(hdc, x-1, y);
  337. /* Lower Left */
  338. x -= dx-1;
  339. rgRGB[9] = GetPixel(hdc, x, y);
  340. rgRGB[10] = GetPixel(hdc, x+1, y);
  341. rgRGB[11] = GetPixel(hdc, x, y-1);
  342. }
  343. void RestoreCorners(HDC hdc, LONG FAR *rgRGB, INT x, INT y, INT dx, INT dy)
  344. {
  345. if(dx != dxCard || dy != dyCard)
  346. return;
  347. /* Upper Left */
  348. SetPixel(hdc, x, y, rgRGB[0]);
  349. SetPixel(hdc, x+1, y, rgRGB[1]);
  350. SetPixel(hdc, x, y+1, rgRGB[2]);
  351. /* Upper Right */
  352. x += dx-1;
  353. SetPixel(hdc, x, y, rgRGB[3]);
  354. SetPixel(hdc, x-1, y, rgRGB[4]);
  355. SetPixel(hdc, x, y+1, rgRGB[5]);
  356. /* Lower Right */
  357. y += dy-1;
  358. SetPixel(hdc, x, y, rgRGB[6]);
  359. SetPixel(hdc, x, y-1, rgRGB[7]);
  360. SetPixel(hdc, x-1, y, rgRGB[8]);
  361. /* Lower Left */
  362. x -= dx-1;
  363. SetPixel(hdc, x, y, rgRGB[9]);
  364. SetPixel(hdc, x+1, y, rgRGB[10]);
  365. SetPixel(hdc, x, y-1, rgRGB[11]);
  366. }
  367. #endif
  368. BOOL APIENTRY cdtAnimate(HDC hdc, INT cd, INT x, INT y, INT ispr)
  369. {
  370. INT iani;
  371. ANI *pani;
  372. SPR *pspr;
  373. HBITMAP hbm;
  374. HDC hdcMem;
  375. X xSrc;
  376. Y ySrc;
  377. if(ispr < 0)
  378. return fFalse;
  379. Assert(hdc != NULL);
  380. for(iani = 0; iani < ianiMax; iani++)
  381. {
  382. if(cd == rgani[iani].cdBase)
  383. {
  384. pani = &rgani[iani];
  385. if(ispr < pani->isprMac)
  386. {
  387. pspr = &pani->rgspr[ispr];
  388. Assert(pspr->id != 0);
  389. if(pspr->id == cd)
  390. {
  391. xSrc = pspr->dx;
  392. ySrc = pspr->dy;
  393. }
  394. else
  395. xSrc = ySrc = 0;
  396. hbm = LoadBitmap(hinstApp, MAKEINTRESOURCE(pspr->id));
  397. if(hbm == NULL)
  398. return fFalse;
  399. hdcMem = CreateCompatibleDC(hdc);
  400. if(hdcMem == NULL)
  401. {
  402. DeleteObject(hbm);
  403. return fFalse;
  404. }
  405. if((hbm = SelectObject(hdcMem, hbm)) != NULL)
  406. {
  407. BitBlt(hdc, x+pspr->dx, y+pspr->dy, pani->dxspr, pani->dyspr,
  408. hdcMem, xSrc, ySrc, SRCCOPY);
  409. DeleteObject(SelectObject(hdcMem, hbm));
  410. }
  411. DeleteDC(hdcMem);
  412. return fTrue;
  413. }
  414. }
  415. }
  416. return fFalse;
  417. }
  418. /* loads global bitmap hbmBack */
  419. BOOL FLoadBack(INT idbackNew)
  420. {
  421. Assert(FInRange(idbackNew, IDFACEDOWNFIRST, IDFACEDOWNLAST));
  422. if(idback != idbackNew)
  423. {
  424. MyDeleteHbm(hbmBack);
  425. if((hbmBack = LoadBitmap(hinstApp, MAKEINTRESOURCE(idbackNew))) != NULL)
  426. idback = idbackNew;
  427. else
  428. idback = 0;
  429. }
  430. return idback != 0;
  431. }
  432. static HBITMAP HbmFromCd(INT cd, HDC hdc)
  433. {
  434. INT icd;
  435. HBITMAP hbmDstBitmap;
  436. HANDLE hDstOld;
  437. HANDLE hSrcOld;
  438. HDC hdcDstMemory;
  439. HDC hdcSrcMemory;
  440. if (hbmCard[cd] == NULL) {
  441. icd = RaFromCd(cd) % 13 + SuFromCd(cd) * 13;
  442. if ((hbmCard[cd] = LoadBitmap(hinstApp,MAKEINTRESOURCE(icd+1))) == NULL) {
  443. return NULL;
  444. }
  445. //
  446. // Create two compatible memory DCs for bitmap conversion.
  447. //
  448. hdcSrcMemory = CreateCompatibleDC(hdc);
  449. hdcDstMemory = CreateCompatibleDC(hdc);
  450. if ((hdcSrcMemory == NULL) || (hdcDstMemory == NULL)) {
  451. goto Finish;
  452. }
  453. //
  454. // Create a compatible bitmap for the conversion of the card
  455. // bitmap, blt the loaded bitmap to the compatible bitmap, and
  456. // delete the original bitmap.
  457. //
  458. hbmDstBitmap = CreateCompatibleBitmap(hdc, dxCard, dyCard);
  459. if (hbmDstBitmap == NULL) {
  460. goto Finish;
  461. }
  462. hSrcOld = SelectObject(hdcSrcMemory, hbmCard[cd]);
  463. hDstOld = SelectObject(hdcDstMemory, hbmDstBitmap);
  464. BitBlt(hdcDstMemory, 0, 0, dxCard, dyCard, hdcSrcMemory, 0, 0, SRCCOPY);
  465. SelectObject(hdcSrcMemory, hSrcOld);
  466. SelectObject(hdcDstMemory, hDstOld);
  467. DeleteObject(hbmCard[cd]);
  468. hbmCard[cd] = hbmDstBitmap;
  469. //
  470. // Delete the compatible DCs.
  471. //
  472. DeleteDC(hdcDstMemory);
  473. DeleteDC(hdcSrcMemory);
  474. }
  475. Finish:
  476. return hbmCard[cd];
  477. }
  478. VOID MyDeleteHbm(HBITMAP hbm)
  479. {
  480. if(hbm != NULL)
  481. DeleteObject(hbm);
  482. }
  483. VOID APIENTRY cdtTerm()
  484. /*
  485. * Free up space if it's time to do so.
  486. *
  487. * Parameters:
  488. * none
  489. *
  490. * Returns:
  491. * nothing
  492. */
  493. {
  494. INT i;
  495. #ifdef DLL
  496. if (--cInits > 0) return;
  497. #endif
  498. for (i = 0; i < 52; i++) {
  499. MyDeleteHbm(hbmCard[i]);
  500. hbmCard[i] = NULL;
  501. }
  502. MyDeleteHbm(hbmGhost);
  503. MyDeleteHbm(hbmBack);
  504. MyDeleteHbm(hbmDeckX);
  505. MyDeleteHbm(hbmDeckO);
  506. }