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.

1780 lines
37 KiB

  1. #include "gdiptest.h"
  2. extern const TCHAR* fileExtList =
  3. _T("BMP files\0*.BMP\0"
  4. "JPG files\0*.JPG\0"
  5. "GIF files\0*.GIF\0"
  6. "All files\0*.*\0");
  7. extern const TCHAR* defaultExt = _T("jpg");
  8. TestBrush* TestBrush::CreateNewBrush(INT type)
  9. {
  10. switch (type)
  11. {
  12. case SolidColorBrush:
  13. return new TestSolidBrush();
  14. case TextureFillBrush:
  15. return new TestTextureBrush();
  16. case RectGradBrush:
  17. return new TestRectGradBrush();
  18. case RadialGradBrush:
  19. return new TestRadialGradBrush();
  20. case TriangleGradBrush:
  21. return new TestTriangleGradBrush();
  22. case PathGradBrush:
  23. return new TestPathGradBrush();
  24. case HatchFillBrush:
  25. return new TestHatchBrush();
  26. // !!! Other brush types
  27. default:
  28. NotImplementedBox();
  29. return NULL;
  30. }
  31. }
  32. //*******************************************************************
  33. //
  34. // TestSolidBrush
  35. //
  36. //
  37. //
  38. //*******************************************************************
  39. BOOL TestSolidBrush :: ChangeSettings(HWND hwndParent)
  40. {
  41. BOOL ok = DialogBoxParam(hInst,
  42. MAKEINTRESOURCE(IDD_SOLIDBRUSH_DLG),
  43. hwndParent,
  44. AllDialogBox,
  45. (LPARAM)((TestDialogInterface*)this));
  46. if (ok)
  47. {
  48. // initialize a new GDI+ brush with settings
  49. delete brush;
  50. Color solidcolor(argb);
  51. brush = new SolidBrush(solidcolor);
  52. return TRUE;
  53. }
  54. return FALSE;
  55. };
  56. VOID TestSolidBrush :: Initialize()
  57. {
  58. argb = 0x80000000;
  59. delete brush;
  60. Color solidcolor(argb);
  61. brush = new SolidBrush(solidcolor);
  62. }
  63. VOID TestSolidBrush :: AddToFile(OutputFile* outfile, INT id)
  64. {
  65. TCHAR colorStr[MAX_PATH];
  66. TCHAR brushStr[MAX_PATH];
  67. if (id)
  68. {
  69. _stprintf(&colorStr[0], _T("color%d"), id);
  70. _stprintf(&brushStr[0], _T("brush%d"), id);
  71. }
  72. else
  73. {
  74. _tcscpy(&colorStr[0], _T("color"));
  75. _tcscpy(&brushStr[0], _T("brush"));
  76. }
  77. outfile->ColorDeclaration(&colorStr[0],
  78. &argb);
  79. outfile->BlankLine();
  80. outfile->Declaration(_T("SolidBrush"),
  81. &brushStr[0],
  82. _T("%s"),
  83. &colorStr[0]);
  84. }
  85. VOID TestSolidBrush :: InitDialog(HWND hwnd)
  86. {
  87. SetDialogLong(hwnd, IDC_SB_ALPHA, argb >> Color::AlphaShift);
  88. }
  89. BOOL TestSolidBrush :: SaveValues(HWND hwnd)
  90. {
  91. BOOL warning = FALSE;
  92. argb = (argb & ~Color::AlphaMask) |
  93. (GetDialogLong(hwnd, IDC_SB_ALPHA)
  94. << Color::AlphaShift);
  95. if (warning)
  96. InitDialog(hwnd);
  97. return warning;
  98. }
  99. BOOL TestSolidBrush :: ProcessDialog(HWND hwnd,
  100. UINT msg,
  101. WPARAM wParam,
  102. LPARAM lParam)
  103. {
  104. if (msg == WM_COMMAND)
  105. {
  106. switch(LOWORD(wParam))
  107. {
  108. case IDC_OK:
  109. if (SaveValues(hwnd))
  110. WarningBeep();
  111. else
  112. ::EndDialog(hwnd, TRUE);
  113. break;
  114. case IDC_SB_COLORBUTTON:
  115. UpdateRGBColor(hwnd, IDC_SB_PIC, argb);
  116. break;
  117. case IDC_REFRESH_PIC:
  118. UpdateColorPicture(hwnd, IDC_SB_PIC, argb);
  119. break;
  120. case IDC_CANCEL:
  121. ::EndDialog(hwnd, FALSE);
  122. break;
  123. default:
  124. return FALSE;
  125. }
  126. return TRUE;
  127. }
  128. return FALSE;
  129. }
  130. //*******************************************************************
  131. //
  132. // TestTextureBrush
  133. //
  134. //
  135. //
  136. //*******************************************************************
  137. BOOL TestTextureBrush :: ChangeSettings(HWND hwndParent)
  138. {
  139. BOOL ok = DialogBoxParam(hInst,
  140. MAKEINTRESOURCE(IDD_TEXTURE_DLG),
  141. hwndParent,
  142. AllDialogBox,
  143. (LPARAM)((TestDialogInterface*)this));
  144. if (ok)
  145. {
  146. // try open file first
  147. if (!filename || !bitmap)
  148. return FALSE;
  149. // initialize a new GDI+ brush with settings
  150. delete brush;
  151. TextureBrush *texBrush = new TextureBrush(bitmap,
  152. wrapValue[wrapMode]);
  153. texBrush->SetTransform(matrix);
  154. brush = texBrush;
  155. // release bitmap
  156. delete bitmap;
  157. bitmap = NULL;
  158. return TRUE;
  159. }
  160. return FALSE;
  161. };
  162. VOID TestTextureBrush :: Initialize()
  163. {
  164. filename = NULL;
  165. wrapMode = Tile;
  166. delete matrix;
  167. matrix = new Matrix();
  168. ASSERT(!bitmap);
  169. delete brush;
  170. // no image is black
  171. brush = blackBrush->Clone();
  172. }
  173. VOID TestTextureBrush::AddToFile(OutputFile* outfile, INT id)
  174. {
  175. TCHAR brushStr[MAX_PATH];
  176. TCHAR matrixStr[MAX_PATH];
  177. TCHAR bitmapStr[MAX_PATH];
  178. if (id)
  179. {
  180. _stprintf(&brushStr[0], _T("brush%d"), id);
  181. _stprintf(&matrixStr[0], _T("matrix%d"), id);
  182. _stprintf(&bitmapStr[0], _T("bitmap%d"), id);
  183. }
  184. else
  185. {
  186. _tcscpy(&brushStr[0], _T("brush"));
  187. _tcscpy(&matrixStr[0], _T("matrix"));
  188. _tcscpy(&bitmapStr[0], _T("bitmap"));
  189. }
  190. outfile->Declaration(_T("Bitmap"),
  191. &bitmapStr[0],
  192. "%s",
  193. outfile->WStr(filename));
  194. outfile->BlankLine();
  195. outfile->Declaration(_T("TextureBrush"),
  196. &brushStr[0],
  197. _T("%s, %s"),
  198. outfile->Ref(&bitmapStr[0]),
  199. wrapStr[wrapMode]);
  200. outfile->BlankLine();
  201. outfile->SetMatrixDeclaration(&brushStr[0],
  202. _T("SetTransform"),
  203. &matrixStr[0],
  204. matrix);
  205. }
  206. VOID TestTextureBrush :: InitDialog(HWND hwnd)
  207. {
  208. SetDialogText(hwnd, IDC_TEXTURE_FILENAME, filename, FALSE);
  209. SetDialogCombo(hwnd, IDC_BRUSH_WRAP, wrapList, numWrap, wrapMode);
  210. }
  211. BOOL TestTextureBrush :: SaveValues(HWND hwnd)
  212. {
  213. BOOL warning = FALSE;
  214. TCHAR fname[MAX_PATH];
  215. GetDialogText(hwnd, IDC_TEXTURE_FILENAME, &fname[0], MAX_PATH-1);
  216. if (filename)
  217. free(filename);
  218. filename = _tcsdup(&fname[0]);
  219. wrapMode = GetDialogCombo(hwnd, IDC_BRUSH_WRAP);
  220. return FALSE;
  221. }
  222. BOOL TestTextureBrush :: ProcessDialog(HWND hwnd,
  223. UINT msg,
  224. WPARAM wParam,
  225. LPARAM lParam)
  226. {
  227. if (msg == WM_COMMAND)
  228. {
  229. switch(LOWORD(wParam))
  230. {
  231. case IDC_OK:
  232. if (SaveValues(hwnd))
  233. WarningBeep();
  234. else
  235. ::EndDialog(hwnd, TRUE);
  236. break;
  237. case IDC_TEXTURE_FILEBUTTON:
  238. {
  239. TCHAR fname[MAX_PATH];
  240. GetDialogText(hwnd, IDC_TEXTURE_FILENAME, &fname[0], MAX_PATH-1);
  241. OPENFILENAME ofn =
  242. {
  243. sizeof(OPENFILENAME),
  244. hwnd,
  245. 0,
  246. fileExtList,
  247. NULL,
  248. 0,
  249. 1,
  250. &fname[0],
  251. MAX_PATH-1,
  252. NULL,
  253. 0,
  254. NULL,
  255. NULL,
  256. OFN_PATHMUSTEXIST,
  257. 0,
  258. 0,
  259. defaultExt,
  260. NULL,
  261. NULL,
  262. NULL
  263. };
  264. if ((GetOpenFileName(&ofn) == TRUE) &&
  265. fname[0] != '\0')
  266. {
  267. HANDLE hFile = CreateFile(fname,
  268. GENERIC_READ,
  269. FILE_SHARE_READ,
  270. NULL,
  271. OPEN_EXISTING,
  272. 0,
  273. 0);
  274. if (!hFile)
  275. {
  276. WarningBox(_T("Can't open file for reading."));
  277. return TRUE;
  278. }
  279. CloseHandle(hFile);
  280. #ifdef UNICODE
  281. LPWSTR wFilename = &fname[0];
  282. #else // !UNICODE
  283. LPWSTR wFilename = (LPWSTR)malloc(sizeof(WCHAR)*(strlen(&fname[0])+1));
  284. MultiByteToWideChar(CP_ACP,
  285. 0,
  286. &fname[0],
  287. strlen(&fname[0])+1,
  288. wFilename,
  289. strlen(&fname[0])+1);
  290. #endif
  291. if (bitmap)
  292. delete bitmap;
  293. bitmap = new Bitmap(wFilename);
  294. #ifndef UNICODE
  295. free(wFilename);
  296. #endif
  297. if (!bitmap || bitmap->GetLastStatus() != Ok)
  298. {
  299. WarningBox(_T("Can't load bitmap file."));
  300. if (bitmap)
  301. delete bitmap;
  302. }
  303. else
  304. {
  305. SetDialogText(hwnd, IDC_TEXTURE_FILENAME, &fname[0], FALSE);
  306. }
  307. }
  308. }
  309. break;
  310. case IDC_BRUSH_TRANSFORM:
  311. {
  312. TestTransform transDlg;
  313. transDlg.Initialize(&matrix);
  314. transDlg.ChangeSettings(hwnd);
  315. }
  316. break;
  317. case IDC_CANCEL:
  318. ::EndDialog(hwnd, FALSE);
  319. break;
  320. default:
  321. return FALSE;
  322. }
  323. return TRUE;
  324. }
  325. return FALSE;
  326. }
  327. //*******************************************************************
  328. //
  329. // TestRectGradBrush
  330. //
  331. //
  332. //
  333. //*******************************************************************
  334. BOOL TestRectGradBrush :: ChangeSettings(HWND hwndParent)
  335. {
  336. BOOL ok = DialogBoxParam(hInst,
  337. MAKEINTRESOURCE(IDD_RECTGRAD_DLG),
  338. hwndParent,
  339. AllDialogBox,
  340. (LPARAM)((TestDialogInterface*)this));
  341. if (ok)
  342. {
  343. // initialize a new GDI+ brush with settings
  344. delete brush;
  345. Color colors[4] =
  346. {
  347. Color(argb[0]),
  348. Color(argb[1]),
  349. Color(argb[2]),
  350. Color(argb[3])
  351. };
  352. RectangleGradientBrush* rectBrush =
  353. new RectangleGradientBrush(rect,
  354. (Color*)&colors[0],
  355. wrapValue[wrapMode]);
  356. rectBrush->SetTransform(matrix);
  357. rectBrush->SetHorizontalBlend(horzBlend, horzCount);
  358. rectBrush->SetVerticalBlend(vertBlend, vertCount);
  359. brush = rectBrush;
  360. return TRUE;
  361. }
  362. return FALSE;
  363. };
  364. VOID TestRectGradBrush :: Initialize()
  365. {
  366. rect.X = rect.Y = 0;
  367. rect.Width = rect.Height = 100;
  368. // !! need editing support for these...
  369. horzCount = 0;
  370. horzBlend = NULL;
  371. vertCount = 0;
  372. vertBlend = NULL;
  373. wrapMode = 0;
  374. delete matrix;
  375. matrix = new Matrix();
  376. argb[0] = 0xFFFFFFFF;
  377. argb[1] = 0xFFFF0000;
  378. argb[2] = 0xFF00FF00;
  379. argb[3] = 0xFF0000FF;
  380. Color colors[4] =
  381. {
  382. Color(argb[0]),
  383. Color(argb[1]),
  384. Color(argb[2]),
  385. Color(argb[3])
  386. };
  387. delete brush;
  388. RectangleGradientBrush *rectBrush =
  389. new RectangleGradientBrush(rect,
  390. (Color*)&colors[0],
  391. wrapValue[wrapMode]);
  392. rectBrush->SetTransform(matrix);
  393. rectBrush->SetHorizontalBlend(horzBlend, horzCount);
  394. rectBrush->SetVerticalBlend(vertBlend, vertCount);
  395. brush = rectBrush;
  396. }
  397. VOID TestRectGradBrush::AddToFile(OutputFile* outfile, INT id)
  398. {
  399. TCHAR brushStr[MAX_PATH];
  400. TCHAR rectStr[MAX_PATH];
  401. TCHAR matrixStr[MAX_PATH];
  402. TCHAR colorsStr[MAX_PATH];
  403. TCHAR blend1Str[MAX_PATH];
  404. TCHAR blend2Str[MAX_PATH];
  405. if (id)
  406. {
  407. _stprintf(&brushStr[0], _T("brush%d"), id);
  408. _stprintf(&rectStr[0], _T("rect%db"), id);
  409. _stprintf(&matrixStr[0], _T("matrix%d"), id);
  410. _stprintf(&colorsStr[0], _T("colors%db"), id);
  411. _stprintf(&blend1Str[0], _T("horzBlend%db"), id);
  412. _stprintf(&blend2Str[0], _T("vertBlend%db"), id);
  413. }
  414. else
  415. {
  416. _tcscpy(&brushStr[0], _T("brush"));
  417. _tcscpy(&rectStr[0], _T("rectb"));
  418. _tcscpy(&matrixStr[0], _T("matrixb"));
  419. _tcscpy(&colorsStr[0], _T("colors"));
  420. _tcscpy(&blend1Str[0], _T("horzBlend"));
  421. _tcscpy(&blend2Str[0], _T("vertBlend"));
  422. }
  423. outfile->ColorDeclaration(&colorsStr[0],
  424. &argb[0],
  425. 4);
  426. outfile->BlankLine();
  427. outfile->RectangleDeclaration(&rectStr[0],
  428. rect);
  429. outfile->BlankLine();
  430. outfile->Declaration(_T("RectangleGradientBrush"),
  431. &brushStr[0],
  432. _T("%s, %s, %s"),
  433. &rectStr[0],
  434. outfile->RefArray(&colorsStr[0]),
  435. wrapStr[wrapMode]);
  436. outfile->BlankLine();
  437. outfile->SetMatrixDeclaration(&brushStr[0],
  438. _T("SetTransform"),
  439. &matrixStr[0],
  440. matrix);
  441. if (horzBlend && horzCount)
  442. {
  443. outfile->BlankLine();
  444. outfile->SetBlendDeclaration(&brushStr[0],
  445. _T("SetHorizontalBlend"),
  446. &blend1Str[0],
  447. horzBlend,
  448. horzCount);
  449. }
  450. if (vertBlend && vertCount)
  451. {
  452. outfile->BlankLine();
  453. outfile->SetBlendDeclaration(&brushStr[0],
  454. _T("SetVerticalBlend"),
  455. &blend2Str[0],
  456. vertBlend,
  457. vertCount);
  458. }
  459. }
  460. VOID TestRectGradBrush :: InitDialog(HWND hwnd)
  461. {
  462. SetDialogReal(hwnd, IDC_RECTGRAD_X, rect.X);
  463. SetDialogReal(hwnd, IDC_RECTGRAD_Y, rect.Y);
  464. SetDialogReal(hwnd, IDC_RECTGRAD_WIDTH, rect.Width);
  465. SetDialogReal(hwnd, IDC_RECTGRAD_HEIGHT, rect.Height);
  466. SetDialogLong(hwnd, IDC_RECTGRAD_ALPHA1, argb[0] >> Color::AlphaShift);
  467. SetDialogLong(hwnd, IDC_RECTGRAD_ALPHA2, argb[1] >> Color::AlphaShift);
  468. SetDialogLong(hwnd, IDC_RECTGRAD_ALPHA3, argb[2] >> Color::AlphaShift);
  469. SetDialogLong(hwnd, IDC_RECTGRAD_ALPHA4, argb[3] >> Color::AlphaShift);
  470. SetDialogCombo(hwnd, IDC_BRUSH_WRAP, wrapList, numWrap, wrapMode);
  471. // !! is this a bug: can't paint colors in this call??
  472. SendMessage(hwnd, WM_COMMAND, IDC_REFRESH_PIC, 0);
  473. }
  474. BOOL TestRectGradBrush :: SaveValues(HWND hwnd)
  475. {
  476. BOOL warning = FALSE;
  477. rect.X = GetDialogReal(hwnd, IDC_RECTGRAD_X);
  478. rect.Y = GetDialogReal(hwnd, IDC_RECTGRAD_Y);
  479. rect.Width = GetDialogReal(hwnd, IDC_RECTGRAD_WIDTH);
  480. rect.Height = GetDialogReal(hwnd, IDC_RECTGRAD_HEIGHT);
  481. argb[0] = (argb[0] & ~Color::AlphaMask)
  482. | (GetDialogLong(hwnd, IDC_RECTGRAD_ALPHA1)
  483. << Color::AlphaShift);
  484. argb[1] = (argb[1] & ~Color::AlphaMask)
  485. | (GetDialogLong(hwnd, IDC_RECTGRAD_ALPHA2)
  486. << Color::AlphaShift);
  487. argb[2] = (argb[2] & ~Color::AlphaMask)
  488. | (GetDialogLong(hwnd, IDC_RECTGRAD_ALPHA3)
  489. << Color::AlphaShift);
  490. argb[3] = (argb[3] & ~Color::AlphaMask)
  491. | (GetDialogLong(hwnd, IDC_RECTGRAD_ALPHA4)
  492. << Color::AlphaShift);
  493. wrapMode = GetDialogCombo(hwnd, IDC_BRUSH_WRAP);
  494. return FALSE;
  495. }
  496. BOOL TestRectGradBrush :: ProcessDialog(HWND hwnd,
  497. UINT msg,
  498. WPARAM wParam,
  499. LPARAM lParam)
  500. {
  501. if (msg == WM_COMMAND)
  502. {
  503. switch(LOWORD(wParam))
  504. {
  505. case IDC_OK:
  506. if (SaveValues(hwnd))
  507. WarningBeep();
  508. else
  509. ::EndDialog(hwnd, TRUE);
  510. break;
  511. case IDC_RECTGRAD_COLOR1:
  512. UpdateRGBColor(hwnd, IDC_RECTGRAD_PIC1, argb[0]);
  513. break;
  514. case IDC_RECTGRAD_COLOR2:
  515. UpdateRGBColor(hwnd, IDC_RECTGRAD_PIC2, argb[1]);
  516. break;
  517. case IDC_RECTGRAD_COLOR3:
  518. UpdateRGBColor(hwnd, IDC_RECTGRAD_PIC3, argb[2]);
  519. break;
  520. case IDC_RECTGRAD_COLOR4:
  521. UpdateRGBColor(hwnd, IDC_RECTGRAD_PIC4, argb[3]);
  522. break;
  523. case IDC_REFRESH_PIC:
  524. UpdateColorPicture(hwnd, IDC_RECTGRAD_PIC1, argb[0] & ~Color::AlphaMask);
  525. UpdateColorPicture(hwnd, IDC_RECTGRAD_PIC2, argb[1] & ~Color::AlphaMask);
  526. UpdateColorPicture(hwnd, IDC_RECTGRAD_PIC3, argb[2] & ~Color::AlphaMask);
  527. UpdateColorPicture(hwnd, IDC_RECTGRAD_PIC4, argb[3] & ~Color::AlphaMask);
  528. break;
  529. case IDC_BRUSH_TRANSFORM:
  530. {
  531. TestTransform transDlg;
  532. transDlg.Initialize(&matrix);
  533. transDlg.ChangeSettings(hwnd);
  534. }
  535. break;
  536. case IDC_CANCEL:
  537. ::EndDialog(hwnd, FALSE);
  538. break;
  539. default:
  540. return FALSE;
  541. }
  542. return TRUE;
  543. }
  544. return FALSE;
  545. }
  546. //*******************************************************************
  547. //
  548. // TestRadialGradBrush
  549. //
  550. //
  551. //
  552. //*******************************************************************
  553. BOOL TestRadialGradBrush :: ChangeSettings(HWND hwndParent)
  554. {
  555. BOOL ok = DialogBoxParam(hInst,
  556. MAKEINTRESOURCE(IDD_RADGRAD_DLG),
  557. hwndParent,
  558. AllDialogBox,
  559. (LPARAM)((TestDialogInterface*)this));
  560. if (ok)
  561. {
  562. // initialize a new GDI+ brush with settings
  563. delete brush;
  564. Color centerColor(centerARGB);
  565. Color boundaryColor(boundaryARGB);
  566. RadialGradientBrush *radBrush
  567. = new RadialGradientBrush(rect,
  568. centerColor,
  569. boundaryColor,
  570. wrapValue[wrapMode]);
  571. radBrush->SetTransform(matrix);
  572. if (blend && blendCount)
  573. radBrush->SetBlend(blend, blendCount);
  574. brush = radBrush;
  575. return TRUE;
  576. }
  577. return FALSE;
  578. };
  579. VOID TestRadialGradBrush :: Initialize()
  580. {
  581. delete matrix;
  582. matrix = new Matrix();
  583. rect.X = rect.Y = 0;
  584. rect.Width = rect.Height = 100;
  585. // !! need editing support for these...
  586. blendCount = 0;
  587. blend = NULL;
  588. wrapMode = 0;
  589. matrix->Reset();
  590. centerARGB = 0xFFFFFFFF;
  591. boundaryARGB = 0xFF000000;
  592. Color centerColor(centerARGB);
  593. Color boundaryColor(boundaryARGB);
  594. delete brush;
  595. RadialGradientBrush *radBrush =
  596. new RadialGradientBrush(rect,
  597. centerColor,
  598. boundaryColor,
  599. wrapValue[wrapMode]);
  600. radBrush->SetTransform(matrix);
  601. radBrush->SetBlend(blend, blendCount);
  602. brush = radBrush;
  603. }
  604. VOID TestRadialGradBrush::AddToFile(OutputFile* outfile, INT id)
  605. {
  606. TCHAR brushStr[MAX_PATH];
  607. TCHAR matrixStr[MAX_PATH];
  608. TCHAR rectStr[MAX_PATH];
  609. TCHAR color1Str[MAX_PATH];
  610. TCHAR color2Str[MAX_PATH];
  611. TCHAR blendStr[MAX_PATH];
  612. if (id)
  613. {
  614. _stprintf(&brushStr[0], _T("brush%d"), id);
  615. _stprintf(&matrixStr[0], _T("matrix%d"), id);
  616. _stprintf(&rectStr[0], _T("rect%db"), id);
  617. _stprintf(&color1Str[0], _T("centerColor%db"), id);
  618. _stprintf(&color2Str[0], _T("boundaryColor%db"), id);
  619. _stprintf(&blendStr[0], _T("radialBlend%db"), id);
  620. }
  621. else
  622. {
  623. _tcscpy(&brushStr[0], _T("brush"));
  624. _tcscpy(&matrixStr[0], _T("matrix"));
  625. _tcscpy(&rectStr[0], _T("rectb"));
  626. _tcscpy(&color1Str[0], _T("centerColor"));
  627. _tcscpy(&color2Str[0], _T("boundaryColor"));
  628. _tcscpy(&blendStr[0], _T("radialBlend"));
  629. }
  630. outfile->ColorDeclaration(&color1Str[0],
  631. &centerARGB,
  632. 0);
  633. outfile->BlankLine();
  634. outfile->ColorDeclaration(&color2Str[0],
  635. &boundaryARGB,
  636. 0);
  637. outfile->BlankLine();
  638. outfile->RectangleDeclaration(&rectStr[0],
  639. rect);
  640. outfile->BlankLine();
  641. outfile->Declaration(_T("RadialGradientBrush"),
  642. &brushStr[0],
  643. _T("%s, %s, %s, %s"),
  644. &rectStr[0],
  645. &color1Str[0],
  646. &color2Str[0],
  647. wrapStr[wrapMode]);
  648. outfile->BlankLine();
  649. outfile->SetMatrixDeclaration(&brushStr[0],
  650. _T("SetTransform"),
  651. &matrixStr[0],
  652. matrix);
  653. outfile->BlankLine();
  654. if (blend && blendCount)
  655. {
  656. outfile->BlankLine();
  657. outfile->SetBlendDeclaration(&brushStr[0],
  658. _T("SetBlend"),
  659. &blendStr[0],
  660. blend,
  661. blendCount);
  662. }
  663. }
  664. VOID TestRadialGradBrush :: InitDialog(HWND hwnd)
  665. {
  666. SetDialogReal(hwnd, IDC_RADGRAD_X, rect.X);
  667. SetDialogReal(hwnd, IDC_RADGRAD_Y, rect.Y);
  668. SetDialogReal(hwnd, IDC_RADGRAD_WIDTH, rect.Width);
  669. SetDialogReal(hwnd, IDC_RADGRAD_HEIGHT, rect.Height);
  670. SetDialogLong(hwnd, IDC_RADGRAD_CENTERALPHA, centerARGB >> Color::AlphaShift);
  671. SetDialogLong(hwnd, IDC_RADGRAD_BOUNDARYALPHA, boundaryARGB >> Color::AlphaShift);
  672. SetDialogCombo(hwnd, IDC_BRUSH_WRAP, wrapList, numWrap, wrapMode);
  673. }
  674. BOOL TestRadialGradBrush :: SaveValues(HWND hwnd)
  675. {
  676. BOOL warning = FALSE;
  677. rect.X = GetDialogReal(hwnd, IDC_RADGRAD_X);
  678. rect.Y = GetDialogReal(hwnd, IDC_RADGRAD_Y);
  679. rect.Width = GetDialogReal(hwnd, IDC_RADGRAD_WIDTH);
  680. rect.Height = GetDialogReal(hwnd, IDC_RADGRAD_HEIGHT);
  681. centerARGB = (centerARGB & ~Color::AlphaMask)
  682. | (GetDialogLong(hwnd, IDC_RADGRAD_CENTERALPHA)
  683. << Color::AlphaShift);
  684. boundaryARGB = (boundaryARGB & ~Color::AlphaMask)
  685. | (GetDialogLong(hwnd, IDC_RADGRAD_BOUNDARYALPHA)
  686. << Color::AlphaShift);
  687. wrapMode = GetDialogCombo(hwnd, IDC_BRUSH_WRAP);
  688. return FALSE;
  689. }
  690. BOOL TestRadialGradBrush :: ProcessDialog(HWND hwnd,
  691. UINT msg,
  692. WPARAM wParam,
  693. LPARAM lParam)
  694. {
  695. if (msg == WM_COMMAND)
  696. {
  697. switch(LOWORD(wParam))
  698. {
  699. case IDC_OK:
  700. if (SaveValues(hwnd))
  701. WarningBeep();
  702. else
  703. ::EndDialog(hwnd, TRUE);
  704. break;
  705. case IDC_RADGRAD_CENTER:
  706. UpdateRGBColor(hwnd, IDC_RADGRAD_PICC, centerARGB);
  707. break;
  708. case IDC_RADGRAD_BOUNDARY:
  709. UpdateRGBColor(hwnd, IDC_RADGRAD_PICB, boundaryARGB);
  710. break;
  711. case IDC_REFRESH_PIC:
  712. UpdateColorPicture(hwnd, IDC_RADGRAD_PICC, centerARGB & ~Color::AlphaMask);
  713. UpdateColorPicture(hwnd, IDC_RADGRAD_PICB, boundaryARGB & ~Color::AlphaMask);
  714. break;
  715. case IDC_BRUSH_TRANSFORM:
  716. {
  717. TestTransform transDlg;
  718. transDlg.Initialize(&matrix);
  719. transDlg.ChangeSettings(hwnd);
  720. }
  721. break;
  722. case IDC_CANCEL:
  723. ::EndDialog(hwnd, FALSE);
  724. break;
  725. default:
  726. return FALSE;
  727. }
  728. return TRUE;
  729. }
  730. return FALSE;
  731. }
  732. //*******************************************************************
  733. //
  734. // TestTriangleGradBrush
  735. //
  736. //
  737. //
  738. //*******************************************************************
  739. BOOL TestTriangleGradBrush :: ChangeSettings(HWND hwndParent)
  740. {
  741. BOOL ok = DialogBoxParam(hInst,
  742. MAKEINTRESOURCE(IDD_TRIGRAD_DLG),
  743. hwndParent,
  744. AllDialogBox,
  745. (LPARAM)((TestDialogInterface*)this));
  746. if (ok)
  747. {
  748. // initialize a new GDI+ brush with settings
  749. delete brush;
  750. Color colors[3] =
  751. {
  752. Color(argb[0]),
  753. Color(argb[1]),
  754. Color(argb[2])
  755. };
  756. TriangleGradientBrush *triBrush
  757. = new TriangleGradientBrush(
  758. (Point*)&pts[0],
  759. (Color*)&colors[0],
  760. wrapValue[wrapMode]);
  761. triBrush->SetTransform(matrix);
  762. triBrush->SetBlend0(blend[0], count[0]);
  763. triBrush->SetBlend1(blend[1], count[1]);
  764. triBrush->SetBlend2(blend[2], count[2]);
  765. brush = triBrush;
  766. return TRUE;
  767. }
  768. return FALSE;
  769. };
  770. VOID TestTriangleGradBrush :: Initialize()
  771. {
  772. delete matrix;
  773. matrix = new Matrix();
  774. pts[0].X = 10; pts[0].Y = 10;
  775. pts[1].X = 90; pts[1].Y = 10;
  776. pts[2].X = 50; pts[2].Y = 100;
  777. blend[0] = blend[1] = blend[2] = NULL;
  778. count[0] = count[1] = count[2] = 0;
  779. argb[0] = 0x80FF0000;
  780. argb[1] = 0x8000FF00;
  781. argb[2] = 0x800000FF;
  782. Color colors[3] =
  783. {
  784. Color(argb[0]),
  785. Color(argb[1]),
  786. Color(argb[2])
  787. };
  788. wrapMode = 0;
  789. delete brush;
  790. TriangleGradientBrush *triBrush
  791. = new TriangleGradientBrush(
  792. (Point*)(&pts[0]),
  793. (Color*)(&colors[0]),
  794. wrapValue[wrapMode]);
  795. triBrush->SetTransform(matrix);
  796. triBrush->SetBlend0(blend[0], count[0]);
  797. triBrush->SetBlend1(blend[1], count[1]);
  798. triBrush->SetBlend2(blend[2], count[2]);
  799. brush = triBrush;
  800. }
  801. VOID TestTriangleGradBrush::AddToFile(OutputFile* outfile, INT id)
  802. {
  803. INT pos;
  804. TCHAR brushStr[MAX_PATH];
  805. TCHAR matrixStr[MAX_PATH];
  806. TCHAR ptsStr[MAX_PATH];
  807. TCHAR colorsStr[MAX_PATH];
  808. TCHAR blendStr[3][MAX_PATH];
  809. if (id)
  810. {
  811. _stprintf(&brushStr[0], _T("brush%d"), id);
  812. _stprintf(&matrixStr[0], _T("matrix%db"), id);
  813. _stprintf(&ptsStr[0], _T("pts%db"), id);
  814. _stprintf(&colorsStr[0], _T("colors%db"), id);
  815. _stprintf(&blendStr[0][0], _T("blend%db01"), id);
  816. _stprintf(&blendStr[1][0], _T("blend%db12"), id);
  817. _stprintf(&blendStr[2][0], _T("blend%db20"), id);
  818. }
  819. else
  820. {
  821. _tcscpy(&brushStr[0], _T("brush"));
  822. _tcscpy(&brushStr[0], _T("matrixb"));
  823. _tcscpy(&ptsStr[0], _T("ptsb"));
  824. _tcscpy(&colorsStr[0], _T("colors"));
  825. _tcscpy(&blendStr[0][0], _T("blend01"));
  826. _tcscpy(&blendStr[1][0], _T("blend12"));
  827. _tcscpy(&blendStr[2][0], _T("blend20"));
  828. }
  829. outfile->PointDeclaration(&ptsStr[0],
  830. &pts[0],
  831. 3);
  832. outfile->BlankLine();
  833. outfile->ColorDeclaration(&colorsStr[0],
  834. &argb[0],
  835. 3);
  836. outfile->BlankLine();
  837. outfile->Declaration(_T("TriangleGradientBrush"),
  838. &brushStr[0],
  839. _T("%s, %s, %s"),
  840. outfile->RefArray(&ptsStr[0]),
  841. outfile->RefArray(&colorsStr[0]),
  842. wrapStr[wrapMode]);
  843. outfile->BlankLine();
  844. outfile->SetMatrixDeclaration(&brushStr[0],
  845. _T("SetTransform"),
  846. &matrixStr[0],
  847. matrix);
  848. if (blend[0] && count[0])
  849. {
  850. outfile->BlankLine();
  851. outfile->SetBlendDeclaration(&brushStr[0],
  852. _T("SetBlend01"),
  853. &blendStr[0][0],
  854. blend[0],
  855. count[0]);
  856. }
  857. if (blend[1] && count[1])
  858. {
  859. outfile->BlankLine();
  860. outfile->SetBlendDeclaration(&brushStr[0],
  861. _T("SetBlend12"),
  862. &blendStr[1][0],
  863. blend[1],
  864. count[1]);
  865. }
  866. if (blend[2] && count[2])
  867. {
  868. outfile->BlankLine();
  869. outfile->SetBlendDeclaration(&brushStr[0],
  870. _T("SetBlend20"),
  871. &blendStr[2][0],
  872. blend[2],
  873. count[2]);
  874. }
  875. }
  876. VOID TestTriangleGradBrush :: InitDialog(HWND hwnd)
  877. {
  878. TCHAR tmp[MAX_PATH];
  879. _stprintf(tmp, "(%.f,%.f)", pts[0].X, pts[0].Y);
  880. SetDialogText(hwnd, IDC_TRIGRAD_PT1, &tmp[0], FALSE);
  881. _stprintf(tmp, "(%.f,%.f)", pts[1].X, pts[1].Y);
  882. SetDialogText(hwnd, IDC_TRIGRAD_PT2, &tmp[0], FALSE);
  883. _stprintf(tmp, "(%.f,%.f)", pts[2].X, pts[2].Y);
  884. SetDialogText(hwnd, IDC_TRIGRAD_PT3, &tmp[0], FALSE);
  885. SetDialogCombo(hwnd, IDC_BRUSH_WRAP, wrapList, numWrap, wrapMode);
  886. }
  887. BOOL TestTriangleGradBrush :: SaveValues(HWND hwnd)
  888. {
  889. BOOL warning = FALSE;
  890. wrapMode = GetDialogCombo(hwnd, IDC_BRUSH_WRAP);
  891. return FALSE;
  892. }
  893. BOOL TestTriangleGradBrush :: ProcessDialog(HWND hwnd,
  894. UINT msg,
  895. WPARAM wParam,
  896. LPARAM lParam)
  897. {
  898. if (msg == WM_COMMAND)
  899. {
  900. switch(LOWORD(wParam))
  901. {
  902. case IDC_OK:
  903. if (SaveValues(hwnd))
  904. WarningBeep();
  905. else
  906. ::EndDialog(hwnd, TRUE);
  907. break;
  908. case IDC_TRIGRAD_BUTTON:
  909. {
  910. EnableDialogControl(hwnd, IDC_TRIGRAD_BUTTON, FALSE);
  911. // create gradient edit shape
  912. TestTriangleGradShape *triGradShape
  913. = new TestTriangleGradShape();
  914. triGradShape->Initialize(&pts[0],
  915. &argb[0],
  916. (REAL**)&blend,
  917. &count[0]);
  918. // create new draw object for window
  919. // and initialize it with this shape
  920. TestGradDraw *gradDraw = new TestGradDraw();
  921. gradDraw->Initialize(triGradShape);
  922. if (gradDraw->ChangeSettings(hwnd))
  923. {
  924. memcpy(&pts[0],
  925. triGradShape->GetPoints(),
  926. sizeof(Point)*3);
  927. memcpy(&argb[0],
  928. triGradShape->GetARGB(),
  929. sizeof(ARGB)*3);
  930. INT newCount[3];
  931. memcpy(&newCount[0],
  932. triGradShape->GetBlendCount(),
  933. sizeof(INT)*3);
  934. REAL** newBlend = triGradShape->GetBlend();
  935. for (INT i = 0; i < 3; i++)
  936. {
  937. if (count[i] && blend[i])
  938. {
  939. count[i] = 0;
  940. free(blend[i]);
  941. blend[i] = NULL;
  942. }
  943. count[i] = newCount[i];
  944. blend[i] = (REAL*) malloc(sizeof(REAL)*count[i]);
  945. memcpy(blend[i], newBlend[i], sizeof(REAL)*count[i]);
  946. }
  947. // update points in dialog box
  948. InitDialog(hwnd);
  949. // update color pictures
  950. InvalidateRect(hwnd, NULL, TRUE);
  951. } // ChangeSettings(hwnd);
  952. delete triGradShape;
  953. delete gradDraw;
  954. EnableDialogControl(hwnd, IDC_TRIGRAD_BUTTON, TRUE);
  955. EnableDialogControl(hwnd, IDC_OK, TRUE);
  956. EnableDialogControl(hwnd, IDC_CANCEL, TRUE);
  957. // update color pictures if necessary
  958. UpdateWindow(hwnd);
  959. InvalidateRect(hwnd, NULL, FALSE);
  960. break;
  961. }
  962. case IDC_REFRESH_PIC:
  963. UpdateColorPicture(hwnd, IDC_TRIGRAD_PIC1, argb[0] & ~Color::AlphaMask);
  964. UpdateColorPicture(hwnd, IDC_TRIGRAD_PIC2, argb[1] & ~Color::AlphaMask);
  965. UpdateColorPicture(hwnd, IDC_TRIGRAD_PIC3, argb[2] & ~Color::AlphaMask);
  966. break;
  967. case IDC_BRUSH_TRANSFORM:
  968. {
  969. TestTransform transDlg;
  970. transDlg.Initialize(&matrix);
  971. transDlg.ChangeSettings(hwnd);
  972. }
  973. break;
  974. case IDC_CANCEL:
  975. ::EndDialog(hwnd, FALSE);
  976. break;
  977. default:
  978. return FALSE;
  979. }
  980. return TRUE;
  981. }
  982. return FALSE;
  983. }
  984. //*******************************************************************
  985. //
  986. // TestPathGradBrush
  987. //
  988. //
  989. //
  990. //*******************************************************************
  991. BOOL TestPathGradBrush :: ChangeSettings(HWND hwndParent)
  992. {
  993. BOOL ok = DialogBoxParam(hInst,
  994. MAKEINTRESOURCE(IDD_POLYGRAD_DLG),
  995. hwndParent,
  996. AllDialogBox,
  997. (LPARAM)((TestDialogInterface*)this));
  998. if (ok)
  999. {
  1000. // initialize a new GDI+ brush with settings
  1001. delete brush;
  1002. PathGradientBrush *polyBrush
  1003. = new PathGradientBrush((Point*)&pts[1],
  1004. pts.GetCount()-1);
  1005. polyBrush->SetTransform(matrix);
  1006. polyBrush->SetWrapMode(wrapValue[wrapMode]);
  1007. // polyBrush->SetSurroundBlend(surroundBlend, surroundCount);
  1008. polyBrush->SetBlend(centerBlend, centerCount);
  1009. polyBrush->SetCenterPoint(pts[0]);
  1010. Color centerColor(argb[0]);
  1011. polyBrush->SetCenterColor(argb[0]);
  1012. for (INT pos = 1; pos < argb.GetCount(); pos++)
  1013. {
  1014. Color color(argb[pos]);
  1015. polyBrush->SetSurroundColor(color, pos-1);
  1016. }
  1017. brush = polyBrush;
  1018. return TRUE;
  1019. }
  1020. return FALSE;
  1021. };
  1022. VOID TestPathGradBrush :: Initialize()
  1023. {
  1024. delete matrix;
  1025. matrix = new Matrix();
  1026. pts.Reset();
  1027. pts.Add(Point(100,100));
  1028. pts.Add(Point(100,50));
  1029. pts.Add(Point(150,150));
  1030. pts.Add(Point(50,150));
  1031. surroundBlend = centerBlend = NULL;
  1032. surroundCount = centerCount = 0;
  1033. argb.Reset();
  1034. argb.Add((ARGB)0x80000000);
  1035. argb.Add((ARGB)0x80FF0000);
  1036. argb.Add((ARGB)0x8000FF00);
  1037. argb.Add((ARGB)0x800000FF);
  1038. wrapMode = 0;
  1039. // initialize a new GDI+ brush with settings
  1040. delete brush;
  1041. PathGradientBrush *polyBrush
  1042. = new PathGradientBrush((Point*)&pts[1],
  1043. pts.GetCount()-1);
  1044. polyBrush->SetTransform(matrix);
  1045. polyBrush->SetWrapMode(wrapValue[wrapMode]);
  1046. polyBrush->SetCenterPoint(pts[0]);
  1047. Color centerColor(argb[0]);
  1048. polyBrush->SetCenterColor(argb[0]);
  1049. for (INT pos = 1; pos < argb.GetCount(); pos++)
  1050. {
  1051. Color color(argb[pos]);
  1052. polyBrush->SetSurroundColor(color, pos-1);
  1053. }
  1054. brush = polyBrush;
  1055. }
  1056. VOID TestPathGradBrush :: AddToFile(OutputFile* outfile, INT id)
  1057. {
  1058. INT pos;
  1059. TCHAR brushStr[MAX_PATH];
  1060. TCHAR matrixStr[MAX_PATH];
  1061. TCHAR ptsStr[MAX_PATH];
  1062. TCHAR colorStr[MAX_PATH];
  1063. TCHAR blendStr[MAX_PATH];
  1064. if (id)
  1065. {
  1066. _stprintf(&brushStr[0], _T("brush%d"), id);
  1067. _stprintf(&matrixStr[0], _T("matrix%d"), id);
  1068. _stprintf(&ptsStr[0], _T("pts%db"), id);
  1069. _stprintf(&colorStr[0], _T("centerColor%db"), id);
  1070. _stprintf(&blendStr[0], _T("radialBlend%db01"), id);
  1071. }
  1072. else
  1073. {
  1074. _tcscpy(&brushStr[0], _T("brush"));
  1075. _tcscpy(&matrixStr[0], _T("matrixb"));
  1076. _tcscpy(&ptsStr[0], _T("ptsb"));
  1077. _tcscpy(&colorStr[0], _T("centerColor"));
  1078. _tcscpy(&blendStr[0], _T("radialBlend"));
  1079. }
  1080. outfile->PointDeclaration(&ptsStr[0],
  1081. &pts[1],
  1082. pts.GetCount()-1);
  1083. outfile->BlankLine();
  1084. outfile->Declaration(_T("PathGradientBrush"),
  1085. &brushStr[0],
  1086. _T("%s, %d, %s"),
  1087. outfile->RefArray(&ptsStr[0]),
  1088. pts.GetCount()-1,
  1089. wrapStr[wrapMode]);
  1090. if (id)
  1091. {
  1092. _stprintf(&ptsStr[0], _T("centerpt%db"), id);
  1093. _stprintf(&colorStr[0], _T("centerColor%db"), id);
  1094. }
  1095. else
  1096. {
  1097. _tcscpy(&ptsStr[0], _T("centerpt"));
  1098. _stprintf(&colorStr[0], _T("centerColor"));
  1099. }
  1100. outfile->BlankLine();
  1101. outfile->SetMatrixDeclaration(&brushStr[0],
  1102. _T("SetTransform"),
  1103. &matrixStr[0],
  1104. matrix);
  1105. outfile->BlankLine();
  1106. outfile->SetPointDeclaration(&brushStr[0],
  1107. _T("SetCenterPoint"),
  1108. &ptsStr[0],
  1109. &pts[0]);
  1110. outfile->BlankLine();
  1111. outfile->SetColorDeclaration(&brushStr[0],
  1112. _T("SetCenterColor"),
  1113. &colorStr[0],
  1114. &argb[0]);
  1115. if (centerBlend && centerCount)
  1116. {
  1117. outfile->BlankLine();
  1118. outfile->SetBlendDeclaration(&brushStr[0],
  1119. _T("SetRadialBlend"),
  1120. &blendStr[0],
  1121. centerBlend,
  1122. centerCount);
  1123. }
  1124. // No surround blend since outer edge blend is fixed by
  1125. // by radial blend
  1126. for (pos = 1; pos < pts.GetCount()-1; pos++)
  1127. {
  1128. if (id)
  1129. _stprintf(&colorStr[0], _T("color%db%d"), id, pos);
  1130. else
  1131. _stprintf(&colorStr[0], _T("color%d"), pos);
  1132. outfile->BlankLine();
  1133. outfile->ColorDeclaration(&colorStr[0],
  1134. &argb[pos]);
  1135. outfile->ObjectCommand(&brushStr[0],
  1136. _T("SetSurroundColor"),
  1137. _T("%s, %d"),
  1138. &colorStr[0],
  1139. pos-1);
  1140. }
  1141. }
  1142. VOID TestPathGradBrush :: InitDialog(HWND hwnd)
  1143. {
  1144. TCHAR tmp[MAX_PATH];
  1145. HWND hwndList = GetDlgItem(hwnd, IDC_POLYGRAD_POINTLIST);
  1146. INT count = SendMessage(hwndList, LB_GETCOUNT, 0, 0);
  1147. while (count)
  1148. {
  1149. // remove all items in list and repopulate
  1150. count = SendMessage(hwndList, LB_DELETESTRING, 0, 0);
  1151. }
  1152. for (INT pos = 0; pos < pts.GetCount(); pos++)
  1153. {
  1154. if (!pos)
  1155. _stprintf(tmp,"Center (%.f,%.f), Color=%08X",
  1156. pts[0].X, pts[0].Y, argb[0]);
  1157. else
  1158. _stprintf(tmp,"Point (%.f,%.f), Color=%08X",
  1159. pts[pos].X, pts[pos].Y, argb[pos]);
  1160. SendMessage(hwndList, LB_ADDSTRING, 0, (WPARAM)tmp);
  1161. }
  1162. DeleteObject(hwndList);
  1163. SetDialogCombo(hwnd, IDC_BRUSH_WRAP, wrapList, numWrap, wrapMode);
  1164. }
  1165. BOOL TestPathGradBrush :: SaveValues(HWND hwnd)
  1166. {
  1167. BOOL warning = FALSE;
  1168. wrapMode = GetDialogCombo(hwnd, IDC_BRUSH_WRAP);
  1169. return FALSE;
  1170. }
  1171. BOOL TestPathGradBrush :: ProcessDialog(HWND hwnd,
  1172. UINT msg,
  1173. WPARAM wParam,
  1174. LPARAM lParam)
  1175. {
  1176. if (msg == WM_COMMAND)
  1177. {
  1178. switch(LOWORD(wParam))
  1179. {
  1180. case IDC_OK:
  1181. if (SaveValues(hwnd))
  1182. WarningBeep();
  1183. else
  1184. ::EndDialog(hwnd, TRUE);
  1185. break;
  1186. case IDC_POLYGRAD_BUTTON:
  1187. {
  1188. EnableDialogControl(hwnd, IDC_POLYGRAD_BUTTON, FALSE);
  1189. EnableDialogControl(hwnd, IDC_OK, FALSE);
  1190. EnableDialogControl(hwnd, IDC_CANCEL, FALSE);
  1191. // create gradient edit shape
  1192. TestPathGradShape *polyGradShape
  1193. = new TestPathGradShape();
  1194. polyGradShape->Initialize(&pts,
  1195. &argb,
  1196. surroundBlend,
  1197. surroundCount,
  1198. centerBlend,
  1199. centerCount);
  1200. // create new draw object for window
  1201. // and initialize it with this shape
  1202. TestGradDraw *gradDraw = new TestGradDraw();
  1203. gradDraw->Initialize(polyGradShape);
  1204. if (gradDraw->ChangeSettings(hwnd))
  1205. {
  1206. pts.Reset();
  1207. argb.Reset();
  1208. pts.AddMultiple(polyGradShape->GetPoints(),
  1209. polyGradShape->GetCount());
  1210. argb.AddMultiple(polyGradShape->GetARGB(),
  1211. polyGradShape->GetCount());
  1212. if (surroundBlend)
  1213. free(surroundBlend);
  1214. if (centerBlend)
  1215. free(centerBlend);
  1216. surroundCount = polyGradShape->GetSurroundBlendCount();
  1217. centerCount = polyGradShape->GetCenterBlendCount();
  1218. if (surroundCount)
  1219. {
  1220. surroundBlend = (REAL*) malloc(sizeof(REAL)*surroundCount);
  1221. memcpy(surroundBlend, polyGradShape->GetSurroundBlend(),
  1222. sizeof(REAL)*surroundCount);
  1223. }
  1224. else
  1225. surroundBlend = NULL;
  1226. if (centerCount)
  1227. {
  1228. centerBlend = (REAL*) malloc(sizeof(REAL)*centerCount);
  1229. memcpy(centerBlend, polyGradShape->GetCenterBlend(),
  1230. sizeof(REAL)*centerCount);
  1231. }
  1232. else
  1233. centerBlend = NULL;
  1234. // update points in dialog box
  1235. InitDialog(hwnd);
  1236. // update color pictures
  1237. InvalidateRect(hwnd, NULL, TRUE);
  1238. } // ChangeSettings(hwnd);
  1239. delete polyGradShape;
  1240. delete gradDraw;
  1241. EnableDialogControl(hwnd, IDC_POLYGRAD_BUTTON, TRUE);
  1242. EnableDialogControl(hwnd, IDC_OK, TRUE);
  1243. EnableDialogControl(hwnd, IDC_CANCEL, TRUE);
  1244. // update color pictures if necessary
  1245. UpdateWindow(hwnd);
  1246. InvalidateRect(hwnd, NULL, FALSE);
  1247. break;
  1248. }
  1249. case IDC_BRUSH_TRANSFORM:
  1250. {
  1251. TestTransform transDlg;
  1252. transDlg.Initialize(&matrix);
  1253. transDlg.ChangeSettings(hwnd);
  1254. }
  1255. break;
  1256. case IDC_CANCEL:
  1257. ::EndDialog(hwnd, FALSE);
  1258. break;
  1259. default:
  1260. return FALSE;
  1261. }
  1262. return TRUE;
  1263. }
  1264. return FALSE;
  1265. }
  1266. //*******************************************************************
  1267. //
  1268. // TestHatchBrush
  1269. //
  1270. //
  1271. //
  1272. //*******************************************************************
  1273. BOOL TestHatchBrush :: ChangeSettings(HWND hwndParent)
  1274. {
  1275. BOOL ok = DialogBoxParam(hInst,
  1276. MAKEINTRESOURCE(IDD_HATCH_DLG),
  1277. hwndParent,
  1278. AllDialogBox,
  1279. (LPARAM)((TestDialogInterface*)this));
  1280. if (ok)
  1281. {
  1282. // initialize a new GDI+ brush with settings
  1283. delete brush;
  1284. Color foreColor(foreArgb);
  1285. Color backColor(backArgb);
  1286. hatch = 0;
  1287. brush = new HatchBrush(hatchValue[hatch],
  1288. foreColor,
  1289. backColor);
  1290. return TRUE;
  1291. }
  1292. return FALSE;
  1293. };
  1294. VOID TestHatchBrush :: Initialize()
  1295. {
  1296. foreArgb = 0xFF000000;
  1297. backArgb = 0xFFFFFFFF;
  1298. delete brush;
  1299. Color foreColor(foreArgb);
  1300. Color backColor(backArgb);
  1301. hatch = 0;
  1302. brush = new HatchBrush(hatchValue[hatch],
  1303. foreColor,
  1304. backColor);
  1305. }
  1306. VOID TestHatchBrush::AddToFile(OutputFile* outfile, INT id)
  1307. {
  1308. TCHAR brushStr[MAX_PATH];
  1309. TCHAR color1Str[MAX_PATH];
  1310. TCHAR color2Str[MAX_PATH];
  1311. if (id)
  1312. {
  1313. _stprintf(&brushStr[0], _T("brush%d"), id);
  1314. _stprintf(&color1Str[0], _T("foreColor%db"), id);
  1315. _stprintf(&color2Str[0], _T("backColor%db"), id);
  1316. }
  1317. else
  1318. {
  1319. _tcscpy(&brushStr[0], _T("brush"));
  1320. _tcscpy(&color1Str[0], _T("foreColor"));
  1321. _tcscpy(&color2Str[0], _T("backColor"));
  1322. }
  1323. outfile->ColorDeclaration(&color1Str[0],
  1324. &foreArgb);
  1325. outfile->BlankLine();
  1326. outfile->ColorDeclaration(&color2Str[0],
  1327. &backArgb);
  1328. outfile->BlankLine();
  1329. outfile->Declaration(_T("HatchBrush"),
  1330. &brushStr[0],
  1331. _T("%s, %s, %s"),
  1332. &color1Str[0],
  1333. &color2Str[0],
  1334. hatchStr[hatch]);
  1335. }
  1336. VOID TestHatchBrush :: InitDialog(HWND hwnd)
  1337. {
  1338. SetDialogLong(hwnd, IDC_HATCH_FOREALPHA,
  1339. foreArgb >> Color::AlphaShift);
  1340. SetDialogLong(hwnd, IDC_HATCH_BACKALPHA,
  1341. backArgb >> Color::AlphaShift);
  1342. SetDialogCombo(hwnd, IDC_HATCH_STYLE, hatchList, numHatch, hatch);
  1343. }
  1344. BOOL TestHatchBrush :: SaveValues(HWND hwnd)
  1345. {
  1346. BOOL warning = FALSE;
  1347. foreArgb = (foreArgb & ~Color::AlphaMask) |
  1348. (GetDialogLong(hwnd, IDC_HATCH_FOREALPHA)
  1349. << Color::AlphaShift);
  1350. backArgb = (backArgb & ~Color::AlphaMask) |
  1351. (GetDialogLong(hwnd, IDC_HATCH_BACKALPHA)
  1352. << Color::AlphaShift);
  1353. hatch = GetDialogCombo(hwnd, IDC_HATCH_STYLE);
  1354. if (warning)
  1355. InitDialog(hwnd);
  1356. return warning;
  1357. }
  1358. BOOL TestHatchBrush :: ProcessDialog(HWND hwnd,
  1359. UINT msg,
  1360. WPARAM wParam,
  1361. LPARAM lParam)
  1362. {
  1363. if (msg == WM_COMMAND)
  1364. {
  1365. switch(LOWORD(wParam))
  1366. {
  1367. case IDC_OK:
  1368. if (SaveValues(hwnd))
  1369. WarningBeep();
  1370. else
  1371. ::EndDialog(hwnd, TRUE);
  1372. break;
  1373. case IDC_HATCH_FORECOLOR:
  1374. UpdateRGBColor(hwnd, IDC_HATCH_FOREPIC, foreArgb);
  1375. break;
  1376. case IDC_HATCH_BACKCOLOR:
  1377. UpdateRGBColor(hwnd, IDC_HATCH_BACKPIC, backArgb);
  1378. break;
  1379. case IDC_REFRESH_PIC:
  1380. UpdateColorPicture(hwnd, IDC_HATCH_FOREPIC, foreArgb);
  1381. UpdateColorPicture(hwnd, IDC_HATCH_BACKPIC, backArgb);
  1382. break;
  1383. case IDC_CANCEL:
  1384. ::EndDialog(hwnd, FALSE);
  1385. break;
  1386. default:
  1387. return FALSE;
  1388. }
  1389. return TRUE;
  1390. }
  1391. return FALSE;
  1392. }