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.

2307 lines
43 KiB

  1. #include "gdiptest.h"
  2. //*******************************************************************
  3. //
  4. // TestShape
  5. //
  6. //
  7. //
  8. //*******************************************************************
  9. TestShape* TestShape :: CreateNewShape(INT type)
  10. {
  11. switch (type)
  12. {
  13. case LineType:
  14. return new LineShape();
  15. case ArcType:
  16. return new ArcShape();
  17. case BezierType:
  18. return new BezierShape();
  19. case RectType:
  20. return new RectShape();
  21. case EllipseType:
  22. return new EllipseShape();
  23. case PieType:
  24. return new PieShape();
  25. case PolygonType:
  26. return new PolygonShape();
  27. case CurveType:
  28. return new CurveShape();
  29. break;
  30. case ClosedCurveType:
  31. return new ClosedCurveShape();
  32. break;
  33. // !!! Other shapes types
  34. default:
  35. NotImplementedBox();
  36. return NULL;
  37. }
  38. }
  39. // black squares
  40. VOID TestShape :: DrawPoints(Graphics* g)
  41. {
  42. INT count = pts.GetCount();
  43. Point* ptbuf = (Point*)pts.GetDataBuffer();
  44. while (count)
  45. {
  46. ERectangle rect(ptbuf->X-pointRadius,
  47. ptbuf->Y-pointRadius,
  48. 2*pointRadius,
  49. 2*pointRadius);
  50. g->FillRectangle(blackBrush, rect);
  51. // g->FillEllipse(ptBrush, rect);
  52. count--, ptbuf++;
  53. }
  54. }
  55. BOOL TestShape::EndPoint(HWND hwnd, Point pt)
  56. {
  57. AddPoint(hwnd, pt);
  58. DoneShape(hwnd);
  59. return FALSE;
  60. }
  61. INT TestGradShape :: FindLocationToInsert(Point pt)
  62. {
  63. // !! Not implemented yet.
  64. return 0;
  65. }
  66. // square color from ARGB value
  67. VOID TestGradShape :: DrawPoints(Graphics* g)
  68. {
  69. INT count = pts.GetCount();
  70. Point* ptbuf = (Point*)pts.GetDataBuffer();
  71. for (INT i = 0; i < count; i++)
  72. {
  73. ERectangle rect(ptbuf->X-pointRadius,
  74. ptbuf->Y-pointRadius,
  75. 2*pointRadius,
  76. 2*pointRadius);
  77. Color solidColor((argb[i] & ~Color::AlphaMask)
  78. | (0xFF << Color::AlphaShift));
  79. SolidBrush solidBrush((argb[i] & ~Color::AlphaMask) == 0
  80. ? *blackColor : solidColor);
  81. g->FillRectangle(&solidBrush, rect);
  82. ptbuf++;
  83. }
  84. }
  85. BOOL TestShape :: MoveControlPoint(Point origPt, Point newPt)
  86. {
  87. INT count = pts.GetCount();
  88. INT pos = 0;
  89. // !!! what if multiple control points overlap?
  90. // can't get to one of them
  91. for (pos = 0; pos<count; pos++)
  92. {
  93. Point *ctrlPt = &pts[pos];
  94. ERectangle ctrlRect(ctrlPt->X-pointRadius,
  95. ctrlPt->Y-pointRadius,
  96. 2*pointRadius,
  97. 2*pointRadius);
  98. if (origPt.X>ctrlPt->X-pointRadius &&
  99. origPt.X<ctrlPt->X+pointRadius &&
  100. origPt.Y>ctrlPt->Y-pointRadius &&
  101. origPt.Y<ctrlPt->Y+pointRadius)
  102. {
  103. ctrlPt->X = newPt.X;
  104. ctrlPt->Y = newPt.Y;
  105. return TRUE;
  106. }
  107. }
  108. return FALSE;
  109. }
  110. INT TestGradShape :: FindControlPoint(Point pt)
  111. {
  112. INT count = pts.GetCount();
  113. INT pos = 0;
  114. // !!! what if multiple control points overlap?
  115. // can't get to one of them
  116. for (pos = 0; pos < count; pos++)
  117. {
  118. Point *ctrlPt = &pts[pos];
  119. ERectangle ctrlRect(ctrlPt->X-pointRadius,
  120. ctrlPt->Y-pointRadius,
  121. 2*pointRadius,
  122. 2*pointRadius);
  123. if (pt.X>ctrlPt->X-pointRadius &&
  124. pt.X<ctrlPt->X+pointRadius &&
  125. pt.Y>ctrlPt->Y-pointRadius &&
  126. pt.Y<ctrlPt->Y+pointRadius)
  127. {
  128. return pos;
  129. }
  130. }
  131. return -1;
  132. }
  133. BOOL TestShape :: RemovePoint(HWND hwnd)
  134. {
  135. return FALSE;
  136. }
  137. VOID TestShape :: AddToPath(GraphicsPath* path)
  138. {
  139. }
  140. VOID TestShape :: AddToFile(OutputFile* outfile)
  141. {
  142. }
  143. HDC TestShape :: CreatePictureDC(HWND hwnd, RECT *dstRect)
  144. {
  145. // always return the cached version if possible
  146. HWND hwndLast = GetWindow(hwnd, GW_OWNER);
  147. HDC hdc;
  148. HDC hdc2;
  149. HDC hdcWindow;
  150. HBITMAP hbm;
  151. HBITMAP hbm2;
  152. // get handle to main window
  153. while (hwndLast)
  154. {
  155. hwnd = hwndLast;
  156. hwndLast = GetWindow(hwnd, GW_OWNER);
  157. }
  158. // !! BUG BUG: we are actually getting handle
  159. // to the dialog, not the main window
  160. // IS THIS TRUE?!?!
  161. RECT srcRect;
  162. GetClientRect(hwnd, &srcRect);
  163. hdcWindow = GetDC(hwnd);
  164. SIZE size;
  165. size.cx = srcRect.right-srcRect.left;
  166. size.cy = srcRect.bottom-srcRect.top;
  167. if (hdcPic)
  168. {
  169. hbm = CreateCompatibleBitmap(hdcPic, 1, 1);
  170. hbm = (HBITMAP) SelectObject(hdcPic, (HGDIOBJ)hbm);
  171. SIZE origSize;
  172. GetBitmapDimensionEx(hbm, &origSize);
  173. DeleteObject(SelectObject(hdcPic, (HGDIOBJ)hbm));
  174. // if size hasn't changed, don't recreate
  175. if (origSize.cx == size.cx &&
  176. origSize.cy == size.cy)
  177. {
  178. ReleaseDC(hwnd, hdcWindow);
  179. return hdcPic;
  180. }
  181. // clean up the old picture DC
  182. DeleteObject(hdcPic);
  183. hdcPic = NULL;
  184. // create new picture image
  185. }
  186. SIZE size2;
  187. size2.cx = dstRect->right-dstRect->left;
  188. size2.cy = dstRect->bottom-dstRect->top;
  189. hdc = CreateCompatibleDC(hdcWindow); // source
  190. hdc2 = CreateCompatibleDC(hdcWindow); // destination
  191. hbm = CreateCompatibleBitmap(hdcWindow, size.cx, size.cy);
  192. hbm2 = CreateCompatibleBitmap(hdcWindow, size2.cx, size2.cy);
  193. SetBitmapDimensionEx(hbm2, size.cx, size.cy, NULL);
  194. DeleteObject((HBITMAP) SelectObject(hdc, (HGDIOBJ) hbm));
  195. DeleteObject((HBITMAP) SelectObject(hdc2, (HGDIOBJ) hbm2));
  196. // white GDI brush
  197. HBRUSH hbr = CreateSolidBrush(0x00FFFFFF);
  198. srcRect.left = srcRect.top = 0;
  199. srcRect.right = size.cx;
  200. srcRect.bottom = size.cy;
  201. FillRect(hdc, &srcRect, hbr);
  202. DeleteObject(hbr);
  203. {
  204. // create GDI+ graphics context for this memory DC
  205. Graphics g(hdc);
  206. DrawShape(&g);
  207. }
  208. StretchBlt(hdc2,
  209. 0,
  210. 0,
  211. size2.cx,
  212. size2.cy,
  213. hdc,
  214. srcRect.left,
  215. srcRect.top,
  216. size.cx,
  217. size.cy,
  218. SRCCOPY);
  219. ReleaseDC(hwnd, hdcWindow);
  220. ReleaseDC(hwnd, hdc);
  221. // !! necessary?
  222. DeleteObject(hbm);
  223. // return DC with GDI+ drawn graphics shape, cache it
  224. return (hdcPic = hdc2);
  225. }
  226. //*******************************************************************
  227. //
  228. // LineShape
  229. //
  230. //
  231. //
  232. //*******************************************************************
  233. BOOL LineShape :: AddPoint(HWND hwnd, Point pt)
  234. {
  235. pts.Add(pt);
  236. return TRUE;
  237. }
  238. VOID LineShape :: DoneShape(HWND hwnd)
  239. {
  240. if (pts.GetCount()>1)
  241. done = TRUE;
  242. else
  243. done = FALSE;
  244. }
  245. BOOL LineShape :: IsComplete()
  246. {
  247. return done;
  248. }
  249. BOOL LineShape :: RemovePoint(HWND hwnd)
  250. {
  251. INT count = pts.GetCount();
  252. if (count > 0)
  253. {
  254. pts.SetCount(count-1);
  255. done = TRUE;
  256. return TRUE;
  257. }
  258. else
  259. return FALSE;
  260. }
  261. VOID LineShape :: DrawShape(Graphics* g)
  262. {
  263. INT count = pts.GetCount();
  264. Point* ptbuf = (Point*)pts.GetDataBuffer();
  265. ASSERT(IsComplete());
  266. if (pen)
  267. g->DrawLines(pen->GetPen(), ptbuf, count);
  268. // brush is not used
  269. }
  270. VOID LineShape :: AddToPath(GraphicsPath* path)
  271. {
  272. INT count = pts.GetCount();
  273. Point* ptbuf = (Point*)pts.GetDataBuffer();
  274. ASSERT(Path);
  275. path->AddLines(ptbuf, count);
  276. }
  277. VOID LineShape :: AddToFile(OutputFile* outfile)
  278. {
  279. INT count = pts.GetCount();
  280. pen->AddToFile(outfile);
  281. outfile->BlankLine();
  282. outfile->PointDeclaration(_T("pts"),
  283. (Point*)pts.GetDataBuffer(),
  284. count);
  285. outfile->BlankLine();
  286. outfile->GraphicsCommand(_T("DrawLine"),
  287. _T("%s, %s, %d"),
  288. outfile->Ref(_T("pen")),
  289. outfile->RefArray(_T("pts")),
  290. count);
  291. }
  292. // Configuration management functions
  293. BOOL LineShape :: ChangeSettings(HWND hwnd)
  294. {
  295. return TRUE;
  296. }
  297. VOID LineShape :: Initialize()
  298. {
  299. // do nothing
  300. };
  301. VOID LineShape :: Initialize(TestShape* shape)
  302. {
  303. // do nothing
  304. }
  305. // Dialog management functions (not used)
  306. VOID LineShape :: InitDialog(HWND hwnd)
  307. {
  308. DebugBreak();
  309. }
  310. BOOL LineShape :: SaveValues(HWND hwnd)
  311. {
  312. DebugBreak();
  313. return FALSE;
  314. }
  315. BOOL LineShape :: ProcessDialog(HWND hwnd,
  316. UINT msg,
  317. WPARAM wParam,
  318. LPARAM lParam)
  319. {
  320. DebugBreak();
  321. return FALSE;
  322. }
  323. //*******************************************************************
  324. //
  325. // ArcShape
  326. //
  327. //
  328. //
  329. //*******************************************************************
  330. BOOL ArcShape :: AddPoint(HWND hwnd, Point pt)
  331. {
  332. ASSERT(pts.GetCount() < 2);
  333. pts.Add(pt);
  334. // force complete on point pairs (rect) if possible
  335. DoneShape(hwnd);
  336. return TRUE;
  337. }
  338. VOID ArcShape :: DoneShape(HWND hwnd)
  339. {
  340. ASSERT(pts.GetCount() <= 2);
  341. if (pts.GetCount() == 2)
  342. {
  343. done = TRUE;
  344. if (popup)
  345. {
  346. // !!! cheating, we use global HWND, should use
  347. // HWND passed in.
  348. ChangeSettings(hwnd);
  349. }
  350. }
  351. else
  352. done = FALSE;
  353. }
  354. BOOL ArcShape :: RemovePoint(HWND hwnd)
  355. {
  356. INT count = pts.GetCount();
  357. if (count > 0)
  358. {
  359. pts.SetCount(count-1);
  360. done = FALSE;
  361. return TRUE;
  362. }
  363. else
  364. return FALSE;
  365. }
  366. BOOL ArcShape :: IsComplete()
  367. {
  368. return done;
  369. }
  370. VOID ArcShape :: DrawShape(Graphics* g)
  371. {
  372. INT count = pts.GetCount();
  373. Point* pt1 = (Point*)pts.GetDataBuffer();
  374. Point* pt2 = pt1++;
  375. ASSERT(IsComplete());
  376. ASSERT(count == 2);
  377. if (pen)
  378. {
  379. // create appropriate rectangle
  380. // !! cache this?
  381. ERectangle rect(min(pt1->X, pt2->X),
  382. min(pt1->Y, pt2->Y),
  383. fabsf(pt1->X-pt2->X),
  384. fabsf(pt1->Y-pt2->Y));
  385. g->DrawArc(pen->GetPen(), rect, start, sweep);
  386. }
  387. // brush is not used
  388. }
  389. VOID ArcShape :: AddToPath(GraphicsPath* path)
  390. {
  391. ASSERT(Path);
  392. INT count = pts.GetCount();
  393. Point* pt1 = (Point*)pts.GetDataBuffer();
  394. Point* pt2 = pt1++;
  395. if (count < 2)
  396. return;
  397. ERectangle rect(min(pt1->X, pt2->X),
  398. min(pt1->Y, pt2->Y),
  399. fabsf(pt1->X-pt2->X),
  400. fabsf(pt1->Y-pt2->Y));
  401. path->AddArc(rect, start, sweep);
  402. }
  403. VOID ArcShape :: AddToFile(OutputFile* outfile)
  404. {
  405. Point* pt1 = (Point*)pts.GetDataBuffer();
  406. Point* pt2 = pt1++;
  407. ERectangle rect(min(pt1->X, pt2->X),
  408. min(pt1->Y, pt2->Y),
  409. fabsf(pt1->X-pt2->X),
  410. fabsf(pt1->Y-pt2->Y));
  411. pen->AddToFile(outfile);
  412. outfile->BlankLine();
  413. outfile->RectangleDeclaration(_T("rect"),
  414. rect);
  415. outfile->BlankLine();
  416. outfile->GraphicsCommand(_T("DrawArc"),
  417. _T("%s, %s, %e, %e"),
  418. outfile->Ref(_T("pen")),
  419. _T("rect"),
  420. start,
  421. sweep);
  422. }
  423. // Configuration management functions
  424. BOOL ArcShape :: ChangeSettings(HWND hwndParent)
  425. {
  426. BOOL ok = DialogBoxParam(hInst,
  427. MAKEINTRESOURCE(IDD_ARC_DLG),
  428. hwndParent,
  429. AllDialogBox,
  430. (LPARAM)((TestDialogInterface*)this));
  431. return ok;
  432. }
  433. VOID ArcShape :: Initialize()
  434. {
  435. sweep = 90.0f;
  436. start = 0.0f;
  437. popup = FALSE;
  438. };
  439. VOID ArcShape :: Initialize(TestShape *shape)
  440. {
  441. // if compatible, copy parameters from another compatible shape
  442. if (shape && shape->GetType() == GetType())
  443. {
  444. ArcShape* arcshape = static_cast<ArcShape*>(shape);
  445. sweep = arcshape->sweep;
  446. start = arcshape->start;
  447. popup = arcshape->popup;
  448. }
  449. else
  450. Initialize();
  451. }
  452. // Dialog management functions (not used)
  453. VOID ArcShape :: InitDialog(HWND hwnd)
  454. {
  455. SetDialogReal(hwnd, IDC_ARC_START, start);
  456. SetDialogReal(hwnd, IDC_ARC_SWEEP, sweep);
  457. SetDialogCheck(hwnd, IDC_ARC_POPUP, popup);
  458. }
  459. BOOL ArcShape :: SaveValues(HWND hwnd)
  460. {
  461. start = GetDialogReal(hwnd, IDC_ARC_START);
  462. sweep = GetDialogReal(hwnd, IDC_ARC_SWEEP);
  463. popup = GetDialogCheck(hwnd, IDC_ARC_POPUP);
  464. // no warnings, anything goes
  465. return FALSE;
  466. }
  467. BOOL ArcShape :: ProcessDialog(HWND hwnd,
  468. UINT msg,
  469. WPARAM wParam,
  470. LPARAM lParam)
  471. {
  472. if (msg == WM_COMMAND &&
  473. LOWORD(wParam) == IDC_OK)
  474. {
  475. if (SaveValues(hwnd))
  476. WarningBeep();
  477. else
  478. ::EndDialog(hwnd, TRUE);
  479. return TRUE;
  480. }
  481. return FALSE;
  482. }
  483. //*******************************************************************
  484. //
  485. // BezierShape
  486. //
  487. //
  488. //
  489. //*******************************************************************
  490. BOOL BezierShape :: AddPoint(HWND hwnd, Point pt)
  491. {
  492. pts.Add(pt);
  493. return TRUE;
  494. }
  495. VOID BezierShape :: DoneShape(HWND hwnd)
  496. {
  497. INT count = pts.GetCount();
  498. if (count>3)
  499. {
  500. if (count % 3 != 1)
  501. {
  502. // if they have wrong # of pts, but want to stop,
  503. // then draw with control points we have.
  504. while (count % 3 != 1) count--;
  505. pts.SetCount(count);
  506. }
  507. done = TRUE;
  508. }
  509. else
  510. {
  511. done = FALSE;
  512. }
  513. }
  514. BOOL BezierShape :: RemovePoint(HWND hwnd)
  515. {
  516. INT count = pts.GetCount();
  517. if (count > 0)
  518. {
  519. pts.SetCount(count-1);
  520. done = FALSE;
  521. return TRUE;
  522. }
  523. else
  524. return FALSE;
  525. }
  526. BOOL BezierShape :: IsComplete()
  527. {
  528. return done;
  529. }
  530. VOID BezierShape :: DrawShape(Graphics* g)
  531. {
  532. INT count = pts.GetCount();
  533. Point* ptbuf = (Point*)pts.GetDataBuffer();
  534. ASSERT(IsComplete());
  535. if (pen)
  536. g->DrawBeziers(pen->GetPen(), ptbuf, count);
  537. // brush is not used
  538. }
  539. VOID BezierShape :: AddToPath(GraphicsPath* path)
  540. {
  541. ASSERT(Path);
  542. INT count = pts.GetCount();
  543. Point* ptbuf = (Point*)pts.GetDataBuffer();
  544. if (count > 0)
  545. path->AddBeziers(ptbuf, count);
  546. }
  547. VOID BezierShape :: AddToFile(OutputFile* outfile)
  548. {
  549. INT count = pts.GetCount();
  550. pen->AddToFile(outfile);
  551. outfile->BlankLine();
  552. outfile->PointDeclaration(_T("pts"),
  553. (Point*)pts.GetDataBuffer(),
  554. count);
  555. outfile->BlankLine();
  556. outfile->GraphicsCommand(_T("DrawBezier"),
  557. _T("%s, %s, %d"),
  558. outfile->Ref(_T("pen")),
  559. outfile->RefArray(_T("pts")),
  560. count);
  561. }
  562. // Configuration management functions
  563. BOOL BezierShape :: ChangeSettings(HWND hwnd)
  564. {
  565. return TRUE;
  566. }
  567. VOID BezierShape :: Initialize()
  568. {
  569. pts.Reset();
  570. };
  571. VOID BezierShape :: Initialize(TestShape *shape)
  572. {
  573. }
  574. // Dialog management functions (not used)
  575. VOID BezierShape :: InitDialog(HWND hwnd)
  576. {
  577. DebugBreak();
  578. }
  579. BOOL BezierShape :: SaveValues(HWND hwnd)
  580. {
  581. DebugBreak();
  582. return FALSE;
  583. }
  584. BOOL BezierShape :: ProcessDialog(HWND hwnd,
  585. UINT msg,
  586. WPARAM wParam,
  587. LPARAM lParam)
  588. {
  589. DebugBreak();
  590. return FALSE;
  591. }
  592. //*******************************************************************
  593. //
  594. // RectShape
  595. //
  596. //
  597. //
  598. //*******************************************************************
  599. BOOL RectShape :: AddPoint(HWND hwnd, Point pt)
  600. {
  601. ASSERT(pts.GetCount() < 2);
  602. pts.Add(pt);
  603. // force complete on point pairs (rect) if possible
  604. DoneShape(hwnd);
  605. return TRUE;
  606. }
  607. VOID RectShape :: DoneShape(HWND hwnd)
  608. {
  609. ASSERT(pts.GetCount() <= 2);
  610. if (pts.GetCount() == 2)
  611. done = TRUE;
  612. else
  613. done = FALSE;
  614. }
  615. BOOL RectShape :: RemovePoint(HWND hwnd)
  616. {
  617. INT count = pts.GetCount();
  618. if (count > 0)
  619. {
  620. pts.SetCount(count-1);
  621. done = FALSE;
  622. return TRUE;
  623. }
  624. else
  625. return FALSE;
  626. }
  627. BOOL RectShape :: IsComplete()
  628. {
  629. return done;
  630. }
  631. VOID RectShape :: DrawShape(Graphics* g)
  632. {
  633. INT count = pts.GetCount();
  634. Point* pt1 = (Point*)pts.GetDataBuffer();
  635. Point* pt2 = pt1++;
  636. ASSERT(IsComplete());
  637. ASSERT(count == 2);
  638. if (pen && brush)
  639. {
  640. // create appropriate rectangle
  641. // !! cache this?
  642. ERectangle rect(min(pt1->X, pt2->X),
  643. min(pt1->Y, pt2->Y),
  644. fabsf(pt1->X-pt2->X),
  645. fabsf(pt1->Y-pt2->Y));
  646. g->FillRectangle(brush->GetBrush(), rect);
  647. g->DrawRectangle(pen->GetPen(), rect);
  648. }
  649. }
  650. VOID RectShape :: AddToPath(GraphicsPath* path)
  651. {
  652. ASSERT(Path);
  653. INT count = pts.GetCount();
  654. Point* pt1 = (Point*)pts.GetDataBuffer();
  655. Point* pt2 = pt1++;
  656. if (count < 2)
  657. return;
  658. ERectangle rect(min(pt1->X, pt2->X),
  659. min(pt1->Y, pt2->Y),
  660. fabsf(pt1->X-pt2->X),
  661. fabsf(pt1->Y-pt2->Y));
  662. path->AddRectangle(rect);
  663. }
  664. VOID RectShape :: AddToFile(OutputFile* outfile)
  665. {
  666. Point* pt1 = (Point*)pts.GetDataBuffer();
  667. Point* pt2 = pt1++;
  668. ERectangle rect(min(pt1->X, pt2->X),
  669. min(pt1->Y, pt2->Y),
  670. fabsf(pt1->X-pt2->X),
  671. fabsf(pt1->Y-pt2->Y));
  672. brush->AddToFile(outfile);
  673. outfile->BlankLine();
  674. outfile->RectangleDeclaration(_T("rect"), rect);
  675. outfile->GraphicsCommand(_T("FillRectangle"),
  676. _T("%s, %s"),
  677. outfile->Ref(_T("brush")),
  678. _T("rect"));
  679. outfile->BlankLine();
  680. pen->AddToFile(outfile);
  681. outfile->BlankLine();
  682. outfile->GraphicsCommand(_T("DrawRectangle"),
  683. _T("%s, %s"),
  684. outfile->Ref(_T("pen")),
  685. _T("rect"));
  686. }
  687. // Configuration management functions
  688. BOOL RectShape :: ChangeSettings(HWND hwndParent)
  689. {
  690. return TRUE;
  691. }
  692. VOID RectShape :: Initialize()
  693. {
  694. pts.Reset();
  695. }
  696. VOID RectShape :: Initialize(TestShape *shape)
  697. {
  698. }
  699. // Dialog management functions (not used)
  700. VOID RectShape :: InitDialog(HWND hwnd)
  701. {
  702. DebugBreak();
  703. }
  704. BOOL RectShape :: SaveValues(HWND hwnd)
  705. {
  706. DebugBreak();
  707. return FALSE;
  708. }
  709. BOOL RectShape :: ProcessDialog(HWND hwnd,
  710. UINT msg,
  711. WPARAM wParam,
  712. LPARAM lParam)
  713. {
  714. DebugBreak();
  715. return FALSE;
  716. }
  717. //*******************************************************************
  718. //
  719. // EllipseShape
  720. //
  721. //
  722. //
  723. //*******************************************************************
  724. BOOL EllipseShape :: AddPoint(HWND hwnd, Point pt)
  725. {
  726. ASSERT(pts.GetCount() < 2);
  727. pts.Add(pt);
  728. // force complete on point pairs (rect) if possible
  729. DoneShape(hwnd);
  730. return TRUE;
  731. }
  732. VOID EllipseShape :: DoneShape(HWND hwnd)
  733. {
  734. ASSERT(pts.GetCount() <= 2);
  735. if (pts.GetCount() == 2)
  736. done = TRUE;
  737. else
  738. done = FALSE;
  739. }
  740. BOOL EllipseShape :: RemovePoint(HWND hwnd)
  741. {
  742. INT count = pts.GetCount();
  743. if (count > 0)
  744. {
  745. pts.SetCount(count-1);
  746. done = FALSE;
  747. return TRUE;
  748. }
  749. else
  750. return FALSE;
  751. }
  752. BOOL EllipseShape :: IsComplete()
  753. {
  754. return done;
  755. }
  756. VOID EllipseShape :: DrawShape(Graphics* g)
  757. {
  758. INT count = pts.GetCount();
  759. Point* pt1 = (Point*)pts.GetDataBuffer();
  760. Point* pt2 = pt1++;
  761. ASSERT(IsComplete());
  762. ASSERT(count == 2);
  763. if (pen && brush)
  764. {
  765. // create appropriate rectangle
  766. // !! cache this?
  767. ERectangle rect(min(pt1->X, pt2->X),
  768. min(pt1->Y, pt2->Y),
  769. fabsf(pt1->X-pt2->X),
  770. fabsf(pt1->Y-pt2->Y));
  771. g->FillEllipse(brush->GetBrush(), rect);
  772. g->DrawEllipse(pen->GetPen(), rect);
  773. }
  774. }
  775. VOID EllipseShape :: AddToPath(GraphicsPath* path)
  776. {
  777. ASSERT(Path);
  778. INT count = pts.GetCount();
  779. Point* pt1 = (Point*)pts.GetDataBuffer();
  780. Point* pt2 = pt1++;
  781. if (count < 2)
  782. return;
  783. ERectangle rect(min(pt1->X, pt2->X),
  784. min(pt1->Y, pt2->Y),
  785. fabsf(pt1->X-pt2->X),
  786. fabsf(pt1->Y-pt2->Y));
  787. path->AddEllipse(rect);
  788. }
  789. VOID EllipseShape :: AddToFile(OutputFile* outfile)
  790. {
  791. Point* pt1 = (Point*)pts.GetDataBuffer();
  792. Point* pt2 = pt1++;
  793. ERectangle rect(min(pt1->X, pt2->X),
  794. min(pt1->Y, pt2->Y),
  795. fabsf(pt1->X-pt2->X),
  796. fabsf(pt1->Y-pt2->Y));
  797. brush->AddToFile(outfile);
  798. outfile->BlankLine();
  799. outfile->RectangleDeclaration(_T("rect"), rect);
  800. outfile->BlankLine();
  801. outfile->GraphicsCommand(_T("FillEllipse"),
  802. _T("%s, %s"),
  803. outfile->Ref(_T("brush")),
  804. _T("rect"));
  805. outfile->BlankLine();
  806. pen->AddToFile(outfile);
  807. outfile->BlankLine();
  808. outfile->GraphicsCommand(_T("DrawEllipse"),
  809. _T("%s, %s"),
  810. outfile->Ref(_T("pen")),
  811. _T("rect"));
  812. }
  813. // Configuration management functions
  814. BOOL EllipseShape :: ChangeSettings(HWND hwndParent)
  815. {
  816. return TRUE;
  817. }
  818. VOID EllipseShape :: Initialize()
  819. {
  820. pts.Reset();
  821. }
  822. VOID EllipseShape :: Initialize(TestShape *shape)
  823. {
  824. }
  825. // Dialog management functions (not used)
  826. VOID EllipseShape :: InitDialog(HWND hwnd)
  827. {
  828. DebugBreak();
  829. }
  830. BOOL EllipseShape :: SaveValues(HWND hwnd)
  831. {
  832. DebugBreak();
  833. return FALSE;
  834. }
  835. BOOL EllipseShape :: ProcessDialog(HWND hwnd,
  836. UINT msg,
  837. WPARAM wParam,
  838. LPARAM lParam)
  839. {
  840. DebugBreak();
  841. return FALSE;
  842. }
  843. //*******************************************************************
  844. //
  845. // PieShape
  846. //
  847. //
  848. //
  849. //*******************************************************************
  850. BOOL PieShape :: AddPoint(HWND hwnd, Point pt)
  851. {
  852. ASSERT(pts.GetCount() < 2);
  853. pts.Add(pt);
  854. // force complete on point pairs (rect) if possible
  855. DoneShape(hwnd);
  856. return TRUE;
  857. }
  858. VOID PieShape :: DoneShape(HWND hwnd)
  859. {
  860. if (pts.GetCount() >= 2)
  861. {
  862. done = TRUE;
  863. if (popup)
  864. {
  865. // !!! cheating, we use global HWND, should use
  866. // HWND passed in.
  867. ChangeSettings(hwnd);
  868. }
  869. }
  870. else
  871. done = FALSE;
  872. }
  873. BOOL PieShape :: RemovePoint(HWND hwnd)
  874. {
  875. INT count = pts.GetCount();
  876. if (count > 0)
  877. {
  878. pts.SetCount(count-1);
  879. done = FALSE;
  880. return TRUE;
  881. }
  882. else
  883. return FALSE;
  884. }
  885. BOOL PieShape :: IsComplete()
  886. {
  887. return done;
  888. }
  889. VOID PieShape :: DrawShape(Graphics* g)
  890. {
  891. INT count = pts.GetCount();
  892. Point* pt1 = (Point*)pts.GetDataBuffer();
  893. Point* pt2 = pt1++;
  894. ASSERT(IsComplete());
  895. ASSERT(count<2);
  896. if (pen && brush)
  897. {
  898. // create appropriate rectangle
  899. // !! cache this?
  900. ERectangle rect(min(pt1->X, pt2->X),
  901. min(pt1->Y, pt2->Y),
  902. fabsf(pt1->X-pt2->X),
  903. fabsf(pt1->Y-pt2->Y));
  904. g->FillPie(brush->GetBrush(), rect, start, sweep);
  905. g->DrawPie(pen->GetPen(), rect, start, sweep);
  906. }
  907. }
  908. VOID PieShape :: AddToPath(GraphicsPath* path)
  909. {
  910. ASSERT(Path);
  911. INT count = pts.GetCount();
  912. Point* pt1 = (Point*)pts.GetDataBuffer();
  913. Point* pt2 = pt1++;
  914. if (count < 2)
  915. return;
  916. ERectangle rect(min(pt1->X, pt2->X),
  917. min(pt1->Y, pt2->Y),
  918. fabsf(pt1->X-pt2->X),
  919. fabsf(pt1->Y-pt2->Y));
  920. path->AddPie(rect, start, sweep);
  921. }
  922. VOID PieShape :: AddToFile(OutputFile* outfile)
  923. {
  924. Point* pt1 = (Point*)pts.GetDataBuffer();
  925. Point* pt2 = pt1++;
  926. ERectangle rect(min(pt1->X, pt2->X),
  927. min(pt1->Y, pt2->Y),
  928. fabsf(pt1->X-pt2->X),
  929. fabsf(pt1->Y-pt2->Y));
  930. brush->AddToFile(outfile);
  931. outfile->BlankLine();
  932. outfile->RectangleDeclaration(_T("rect"), rect);
  933. outfile->BlankLine();
  934. outfile->GraphicsCommand(_T("FillPie"),
  935. _T("%s, %s, %e, %e"),
  936. outfile->Ref(_T("brush")),
  937. _T("rect"),
  938. start,
  939. sweep);
  940. outfile->BlankLine();
  941. pen->AddToFile(outfile);
  942. outfile->BlankLine();
  943. outfile->GraphicsCommand(_T("DrawPie"),
  944. _T("%s, %s, %e, %e"),
  945. outfile->Ref(_T("pen")),
  946. _T("rect"),
  947. start,
  948. sweep);
  949. }
  950. // Configuration management functions
  951. BOOL PieShape :: ChangeSettings(HWND hwndParent)
  952. {
  953. BOOL ok = DialogBoxParam(hInst,
  954. MAKEINTRESOURCE(IDD_ARC_DLG),
  955. hwndParent,
  956. AllDialogBox,
  957. (LPARAM)((TestDialogInterface*)this));
  958. return ok;
  959. }
  960. VOID PieShape :: Initialize()
  961. {
  962. sweep = 90.0f;
  963. start = 0.0f;
  964. popup = FALSE;
  965. };
  966. VOID PieShape :: Initialize(TestShape *shape)
  967. {
  968. // if compatible, copy parameters from another compatible shape
  969. if (shape && shape->GetType() == GetType())
  970. {
  971. PieShape* pieshape = static_cast<PieShape*>(shape);
  972. sweep = pieshape->sweep;
  973. start = pieshape->start;
  974. popup = pieshape->popup;
  975. }
  976. else
  977. Initialize();
  978. }
  979. // Dialog management functions (not used)
  980. VOID PieShape :: InitDialog(HWND hwnd)
  981. {
  982. SetWindowText(hwnd, _T("Pie Shape Parameters"));
  983. SetDialogReal(hwnd, IDC_ARC_START, start);
  984. SetDialogReal(hwnd, IDC_ARC_SWEEP, sweep);
  985. SetDialogCheck(hwnd, IDC_ARC_POPUP, popup);
  986. }
  987. BOOL PieShape :: SaveValues(HWND hwnd)
  988. {
  989. start = GetDialogReal(hwnd, IDC_ARC_START);
  990. sweep = GetDialogReal(hwnd, IDC_ARC_SWEEP);
  991. popup = GetDialogCheck(hwnd, IDC_ARC_POPUP);
  992. // no warnings, anything goes
  993. return FALSE;
  994. }
  995. BOOL PieShape :: ProcessDialog(HWND hwnd,
  996. UINT msg,
  997. WPARAM wParam,
  998. LPARAM lParam)
  999. {
  1000. if (msg == WM_COMMAND &&
  1001. LOWORD(wParam) == IDC_OK)
  1002. {
  1003. if (SaveValues(hwnd))
  1004. WarningBeep();
  1005. else
  1006. ::EndDialog(hwnd, TRUE);
  1007. return TRUE;
  1008. }
  1009. return FALSE;
  1010. }
  1011. //*******************************************************************
  1012. //
  1013. // PolygonShape
  1014. //
  1015. //
  1016. //
  1017. //*******************************************************************
  1018. BOOL PolygonShape :: AddPoint(HWND hwnd, Point pt)
  1019. {
  1020. pts.Add(pt);
  1021. return TRUE;
  1022. }
  1023. VOID PolygonShape :: DoneShape(HWND hwnd)
  1024. {
  1025. if (pts.GetCount()>=3)
  1026. done = TRUE;
  1027. else
  1028. done = FALSE;
  1029. }
  1030. BOOL PolygonShape :: RemovePoint(HWND hwnd)
  1031. {
  1032. INT count = pts.GetCount();
  1033. if (count > 0)
  1034. {
  1035. pts.SetCount(count-1);
  1036. done = FALSE;
  1037. return TRUE;
  1038. }
  1039. else
  1040. return FALSE;
  1041. }
  1042. BOOL PolygonShape :: IsComplete()
  1043. {
  1044. return done;
  1045. }
  1046. VOID PolygonShape :: DrawShape(Graphics* g)
  1047. {
  1048. INT count = pts.GetCount();
  1049. Point* ptbuf = (Point*)pts.GetDataBuffer();
  1050. ASSERT(IsComplete());
  1051. ASSERT(count >= 3);
  1052. if (pen && brush)
  1053. {
  1054. g->FillPolygon(brush->GetBrush(), ptbuf, count);
  1055. g->DrawPolygon(pen->GetPen(), ptbuf, count);
  1056. }
  1057. }
  1058. VOID PolygonShape :: AddToPath(GraphicsPath* path)
  1059. {
  1060. ASSERT(Path);
  1061. INT count = pts.GetCount();
  1062. Point* ptbuf = (Point*)pts.GetDataBuffer();
  1063. if (count > 2)
  1064. path->AddPolygon(ptbuf, count);
  1065. }
  1066. VOID PolygonShape :: AddToFile(OutputFile* outfile)
  1067. {
  1068. INT count = pts.GetCount();
  1069. brush->AddToFile(outfile);
  1070. outfile->BlankLine();
  1071. outfile->PointDeclaration(_T("pts"),
  1072. (Point*)pts.GetDataBuffer(),
  1073. count);
  1074. outfile->BlankLine();
  1075. outfile->GraphicsCommand(_T("FillPolygon"),
  1076. _T("%s, %s, %d"),
  1077. outfile->Ref(_T("brush")),
  1078. outfile->RefArray(_T("pts")),
  1079. count);
  1080. outfile->BlankLine();
  1081. pen->AddToFile(outfile);
  1082. outfile->BlankLine();
  1083. outfile->GraphicsCommand(_T("DrawPolygon"),
  1084. _T("%s, %s, %d"),
  1085. outfile->Ref(_T("pen")),
  1086. outfile->RefArray(_T("pts")),
  1087. count);
  1088. }
  1089. // Configuration management functions
  1090. BOOL PolygonShape :: ChangeSettings(HWND hwnd)
  1091. {
  1092. return TRUE;
  1093. }
  1094. VOID PolygonShape :: Initialize()
  1095. {
  1096. // do nothing
  1097. };
  1098. VOID PolygonShape :: Initialize(TestShape* shape)
  1099. {
  1100. // do nothing
  1101. }
  1102. // Dialog management functions (not used)
  1103. VOID PolygonShape :: InitDialog(HWND hwnd)
  1104. {
  1105. DebugBreak();
  1106. }
  1107. BOOL PolygonShape :: SaveValues(HWND hwnd)
  1108. {
  1109. DebugBreak();
  1110. return FALSE;
  1111. }
  1112. BOOL PolygonShape :: ProcessDialog(HWND hwnd,
  1113. UINT msg,
  1114. WPARAM wParam,
  1115. LPARAM lParam)
  1116. {
  1117. DebugBreak();
  1118. return FALSE;
  1119. }
  1120. //*******************************************************************
  1121. //
  1122. // CurveShape
  1123. //
  1124. //
  1125. //
  1126. //*******************************************************************
  1127. BOOL CurveShape :: AddPoint(HWND hwnd, Point pt)
  1128. {
  1129. pts.Add(pt);
  1130. return TRUE;
  1131. }
  1132. VOID CurveShape :: DoneShape(HWND hwnd)
  1133. {
  1134. if (pts.GetCount() >= 2)
  1135. {
  1136. done = TRUE;
  1137. if (popup)
  1138. {
  1139. // !!! cheating, we use global HWND, should use
  1140. // HWND passed in.
  1141. ChangeSettings(hwnd);
  1142. }
  1143. }
  1144. else
  1145. done = FALSE;
  1146. }
  1147. BOOL CurveShape :: RemovePoint(HWND hwnd)
  1148. {
  1149. INT count = pts.GetCount();
  1150. if (count > 0)
  1151. {
  1152. pts.SetCount(count-1);
  1153. done = FALSE;
  1154. return TRUE;
  1155. }
  1156. else
  1157. return FALSE;
  1158. }
  1159. BOOL CurveShape :: IsComplete()
  1160. {
  1161. return done;
  1162. }
  1163. VOID CurveShape :: DrawShape(Graphics* g)
  1164. {
  1165. INT count = pts.GetCount();
  1166. Point* ptbuf = (Point*)pts.GetDataBuffer();
  1167. ASSERT(IsComplete());
  1168. ASSERT(count<2);
  1169. if (pen)
  1170. {
  1171. g->DrawCurve(pen->GetPen(), ptbuf, count, offset, numSegments, tension);
  1172. }
  1173. }
  1174. VOID CurveShape :: AddToPath(GraphicsPath* path)
  1175. {
  1176. ASSERT(Path);
  1177. INT count = pts.GetCount();
  1178. Point* ptbuf = (Point*)pts.GetDataBuffer();
  1179. if (count > 2)
  1180. path->AddCurve(ptbuf, count, tension, offset, numSegments);
  1181. }
  1182. VOID CurveShape :: AddToFile(OutputFile* outfile)
  1183. {
  1184. INT count = pts.GetCount();
  1185. pen->AddToFile(outfile);
  1186. outfile->BlankLine();
  1187. outfile->PointDeclaration(_T("pts"),
  1188. (Point*)pts.GetDataBuffer(),
  1189. count);
  1190. outfile->BlankLine();
  1191. outfile->GraphicsCommand(_T("DrawCurve"),
  1192. _T("%s, %s, %d, %d, %d, %e"),
  1193. outfile->Ref(_T("pen")),
  1194. outfile->RefArray(_T("pts")),
  1195. count,
  1196. offset,
  1197. numSegments,
  1198. tension);
  1199. }
  1200. // Configuration management functions
  1201. BOOL CurveShape :: ChangeSettings(HWND hwndParent)
  1202. {
  1203. BOOL ok = DialogBoxParam(hInst,
  1204. MAKEINTRESOURCE(IDD_CURVE_DLG),
  1205. hwndParent,
  1206. AllDialogBox,
  1207. (LPARAM)((TestDialogInterface*)this));
  1208. return ok;
  1209. }
  1210. VOID CurveShape :: Initialize()
  1211. {
  1212. tension = 0.0;
  1213. offset = 0;
  1214. numSegments = 1;
  1215. popup = FALSE;
  1216. };
  1217. VOID CurveShape :: Initialize(TestShape *shape)
  1218. {
  1219. // if compatible, copy parameters from another compatible shape
  1220. if (shape && shape->GetType() == GetType())
  1221. {
  1222. CurveShape* curveshape = static_cast<CurveShape*>(shape);
  1223. tension = curveshape->tension;
  1224. offset = curveshape->offset;
  1225. numSegments = curveshape->numSegments;
  1226. popup = curveshape->popup;
  1227. }
  1228. else
  1229. Initialize();
  1230. }
  1231. // Dialog management functions (not used)
  1232. VOID CurveShape :: InitDialog(HWND hwnd)
  1233. {
  1234. SetDialogReal(hwnd, IDC_CURVE_TENSION, tension);
  1235. SetDialogLong(hwnd, IDC_CURVE_OFFSET, offset);
  1236. SetDialogLong(hwnd, IDC_CURVE_SEGMENTS, numSegments);
  1237. SetDialogCheck(hwnd, IDC_ARC_POPUP, popup);
  1238. }
  1239. BOOL CurveShape :: SaveValues(HWND hwnd)
  1240. {
  1241. tension = GetDialogReal(hwnd, IDC_CURVE_TENSION);
  1242. offset = GetDialogLong(hwnd, IDC_CURVE_OFFSET);
  1243. numSegments = GetDialogLong(hwnd, IDC_CURVE_SEGMENTS);
  1244. popup = GetDialogCheck(hwnd, IDC_ARC_POPUP);
  1245. // !! could add some warnings...
  1246. // no warnings, anything goes
  1247. return FALSE;
  1248. }
  1249. BOOL CurveShape :: ProcessDialog(HWND hwnd,
  1250. UINT msg,
  1251. WPARAM wParam,
  1252. LPARAM lParam)
  1253. {
  1254. if (msg == WM_COMMAND &&
  1255. LOWORD(wParam) == IDC_OK)
  1256. {
  1257. if (SaveValues(hwnd))
  1258. WarningBeep();
  1259. else
  1260. ::EndDialog(hwnd, TRUE);
  1261. return TRUE;
  1262. }
  1263. return FALSE;
  1264. }
  1265. //*******************************************************************
  1266. //
  1267. // ClosedCurveShape
  1268. //
  1269. //
  1270. //
  1271. //*******************************************************************
  1272. BOOL ClosedCurveShape :: AddPoint(HWND hwnd, Point pt)
  1273. {
  1274. pts.Add(pt);
  1275. return TRUE;
  1276. }
  1277. VOID ClosedCurveShape :: DoneShape(HWND hwnd)
  1278. {
  1279. if (pts.GetCount() >= 2)
  1280. {
  1281. done = TRUE;
  1282. if (popup)
  1283. {
  1284. // !!! cheating, we use global HWND, should use
  1285. // HWND passed in.
  1286. ChangeSettings(hwnd);
  1287. }
  1288. }
  1289. else
  1290. done = FALSE;
  1291. }
  1292. BOOL ClosedCurveShape :: RemovePoint(HWND hwnd)
  1293. {
  1294. INT count = pts.GetCount();
  1295. if (count > 0)
  1296. {
  1297. pts.SetCount(count-1);
  1298. done = FALSE;
  1299. return TRUE;
  1300. }
  1301. else
  1302. return FALSE;
  1303. }
  1304. BOOL ClosedCurveShape :: IsComplete()
  1305. {
  1306. return done;
  1307. }
  1308. VOID ClosedCurveShape :: DrawShape(Graphics* g)
  1309. {
  1310. INT count = pts.GetCount();
  1311. Point* ptbuf = (Point*)pts.GetDataBuffer();
  1312. ASSERT(IsComplete());
  1313. ASSERT(count<2);
  1314. if (pen && brush)
  1315. {
  1316. g->FillClosedCurve(brush->GetBrush(), ptbuf, count, tension, Alternate);
  1317. g->DrawClosedCurve(pen->GetPen(), ptbuf, count, tension);
  1318. }
  1319. }
  1320. VOID ClosedCurveShape :: AddToPath(GraphicsPath* path)
  1321. {
  1322. ASSERT(Path);
  1323. INT count = pts.GetCount();
  1324. Point* ptbuf = (Point*)pts.GetDataBuffer();
  1325. if (count > 2)
  1326. path->AddClosedCurve(ptbuf, count, tension);
  1327. }
  1328. VOID ClosedCurveShape :: AddToFile(OutputFile* outfile)
  1329. {
  1330. INT count = pts.GetCount();
  1331. brush->AddToFile(outfile);
  1332. outfile->BlankLine();
  1333. outfile->PointDeclaration(_T("pts"),
  1334. (Point*)pts.GetDataBuffer(),
  1335. count);
  1336. outfile->BlankLine();
  1337. outfile->GraphicsCommand(_T("FillClosedCurve"),
  1338. _T("%s, %s, %d, %e, %s"),
  1339. outfile->Ref(_T("brush")),
  1340. outfile->RefArray(_T("pts")),
  1341. count,
  1342. tension,
  1343. _T("Alternate"));
  1344. outfile->BlankLine();
  1345. pen->AddToFile(outfile);
  1346. outfile->BlankLine();
  1347. outfile->GraphicsCommand(_T("DrawClosedCurve"),
  1348. _T("%s, %s, %d, %e"),
  1349. outfile->Ref(_T("pen")),
  1350. outfile->RefArray(_T("pts")),
  1351. count,
  1352. tension);
  1353. }
  1354. // Configuration management functions
  1355. BOOL ClosedCurveShape :: ChangeSettings(HWND hwndParent)
  1356. {
  1357. BOOL ok = DialogBoxParam(hInst,
  1358. MAKEINTRESOURCE(IDD_CURVE_DLG),
  1359. hwndParent,
  1360. AllDialogBox,
  1361. (LPARAM)((TestDialogInterface*)this));
  1362. return ok;
  1363. }
  1364. VOID ClosedCurveShape :: Initialize()
  1365. {
  1366. tension = 0.0;
  1367. popup = FALSE;
  1368. };
  1369. VOID ClosedCurveShape :: Initialize(TestShape *shape)
  1370. {
  1371. // if compatible, copy parameters from another compatible shape
  1372. if (shape && shape->GetType() == GetType())
  1373. {
  1374. ClosedCurveShape* closedcurveshape =
  1375. static_cast<ClosedCurveShape*>(shape);
  1376. tension = closedcurveshape->tension;
  1377. popup = closedcurveshape->popup;
  1378. }
  1379. else
  1380. Initialize();
  1381. }
  1382. // Dialog management functions (not used)
  1383. VOID ClosedCurveShape :: InitDialog(HWND hwnd)
  1384. {
  1385. SetWindowText(hwnd, _T("Closed Curve Shape Parameters"));
  1386. SetDialogReal(hwnd, IDC_CURVE_TENSION, tension);
  1387. SetDialogLong(hwnd, IDC_CURVE_OFFSET, 0, FALSE);
  1388. SetDialogLong(hwnd, IDC_CURVE_SEGMENTS, 0, FALSE);
  1389. SetDialogCheck(hwnd, IDC_ARC_POPUP, popup);
  1390. }
  1391. BOOL ClosedCurveShape :: SaveValues(HWND hwnd)
  1392. {
  1393. tension = GetDialogReal(hwnd, IDC_CURVE_TENSION);
  1394. popup = GetDialogCheck(hwnd, IDC_ARC_POPUP);
  1395. // no warnings, anything goes
  1396. return FALSE;
  1397. }
  1398. BOOL ClosedCurveShape :: ProcessDialog(HWND hwnd,
  1399. UINT msg,
  1400. WPARAM wParam,
  1401. LPARAM lParam)
  1402. {
  1403. if (msg == WM_COMMAND &&
  1404. LOWORD(wParam) == IDC_OK)
  1405. {
  1406. if (SaveValues(hwnd))
  1407. WarningBeep();
  1408. else
  1409. ::EndDialog(hwnd, TRUE);
  1410. return TRUE;
  1411. }
  1412. return FALSE;
  1413. }
  1414. //*******************************************************************
  1415. //
  1416. // TestTriangleGradShape
  1417. //
  1418. //
  1419. //
  1420. //*******************************************************************
  1421. BOOL TestTriangleGradShape :: AddPoint(HWND hwnd, Point pt)
  1422. {
  1423. return FALSE;
  1424. }
  1425. VOID TestTriangleGradShape :: DoneShape(HWND hwnd)
  1426. {
  1427. DebugBreak();
  1428. }
  1429. BOOL TestTriangleGradShape :: EndPoint(HWND hwnd, Point pt)
  1430. {
  1431. curIndex = FindControlPoint(pt);
  1432. // we aren't at a control point, no dialog box
  1433. if (curIndex < 0)
  1434. {
  1435. WarningBeep();
  1436. }
  1437. else
  1438. {
  1439. // pop-up dialog to configure color & blend at this point.
  1440. return ChangeSettings(hwnd);
  1441. }
  1442. return FALSE;
  1443. }
  1444. BOOL TestTriangleGradShape :: RemovePoint(HWND hwnd)
  1445. {
  1446. return FALSE;
  1447. }
  1448. BOOL TestTriangleGradShape :: IsComplete()
  1449. {
  1450. return TRUE;
  1451. }
  1452. BOOL TestTriangleGradShape :: MoveControlPoint(Point origPt, Point newPt)
  1453. {
  1454. INT pos = 0;
  1455. // !!! what if multiple control points overlap?
  1456. // can't get to one of them
  1457. for (pos = 0; pos<3; pos++)
  1458. {
  1459. Point *ctrlPt = &pts[pos];
  1460. ERectangle ctrlRect(ctrlPt->X-pointRadius,
  1461. ctrlPt->Y-pointRadius,
  1462. 2*pointRadius,
  1463. 2*pointRadius);
  1464. if (origPt.X>ctrlPt->X-pointRadius &&
  1465. origPt.X<ctrlPt->X+pointRadius &&
  1466. origPt.Y>ctrlPt->Y-pointRadius &&
  1467. origPt.Y<ctrlPt->Y+pointRadius)
  1468. {
  1469. ctrlPt->X = newPt.X;
  1470. ctrlPt->Y = newPt.Y;
  1471. gdiBrush->SetTriangle(&pts[0]);
  1472. return TRUE;
  1473. }
  1474. }
  1475. return FALSE;
  1476. }
  1477. VOID TestTriangleGradShape :: DrawShape(Graphics* g)
  1478. {
  1479. if (gdiBrush)
  1480. g->FillPolygon(gdiBrush, (Point*)&pts[0], 3);
  1481. }
  1482. // Configuration management functions
  1483. BOOL TestTriangleGradShape :: ChangeSettings(HWND hwndParent)
  1484. {
  1485. BOOL ok = DialogBoxParam(hInst,
  1486. MAKEINTRESOURCE(IDD_TRIGRAD_DLG2),
  1487. hwndParent,
  1488. AllDialogBox,
  1489. (LPARAM)((TestDialogInterface*)this));
  1490. if (ok)
  1491. {
  1492. // !! really only need to set one blend & color, but
  1493. // the API requires we set all three.
  1494. gdiBrush->SetBlend0(blend[0], count[0]);
  1495. gdiBrush->SetBlend1(blend[1], count[1]);
  1496. gdiBrush->SetBlend2(blend[2], count[2]);
  1497. Color colors[3] =
  1498. {
  1499. Color(argb[0]),
  1500. Color(argb[1]),
  1501. Color(argb[2])
  1502. };
  1503. gdiBrush->SetColors(&colors[0]);
  1504. gdiBrush->SetTriangle(&pts[0]);
  1505. }
  1506. return ok;
  1507. }
  1508. VOID TestTriangleGradShape :: Initialize()
  1509. {
  1510. DebugBreak();
  1511. };
  1512. VOID TestTriangleGradShape :: Initialize(TestShape* shape)
  1513. {
  1514. DebugBreak();
  1515. }
  1516. VOID TestTriangleGradShape :: Initialize(Point* newPts,
  1517. ARGB* newArgb,
  1518. REAL** newBlend,
  1519. INT* newBlendCount)
  1520. {
  1521. Color color[3];
  1522. pts.Reset();
  1523. argb.Reset();
  1524. for (INT i = 0; i < 3; i++)
  1525. {
  1526. pts.Add(newPts[i]);
  1527. argb.Add(newArgb[i]);
  1528. count[i] = newBlendCount[i];
  1529. if (count[i])
  1530. {
  1531. blend[i] = (REAL*) malloc(sizeof(REAL)*count[i]);
  1532. memcpy(blend[i], newBlend[i], sizeof(REAL)*count[i]);
  1533. }
  1534. else
  1535. blend[i] = NULL;
  1536. color[i] = Color(argb[i]);
  1537. }
  1538. gdiBrush = new TriangleGradientBrush(newPts, &color[0]);
  1539. gdiBrush->SetBlend0(blend[0], count[0]);
  1540. gdiBrush->SetBlend1(blend[1], count[1]);
  1541. gdiBrush->SetBlend2(blend[2], count[2]);
  1542. }
  1543. // Dialog management functions (not used)
  1544. VOID TestTriangleGradShape :: InitDialog(HWND hwnd)
  1545. {
  1546. tmpArgb = argb[curIndex];
  1547. SetDialogLong(hwnd, IDC_TRIGRAD_ALPHA, (tmpArgb & Color::AlphaMask) >> Color::AlphaShift);
  1548. SetDialogRealList(hwnd, IDC_TRIGRAD_BLEND, blend[curIndex], count[curIndex]);
  1549. }
  1550. BOOL TestTriangleGradShape :: SaveValues(HWND hwnd)
  1551. {
  1552. argb[curIndex] = ((tmpArgb & ~Color::AlphaMask) |
  1553. (GetDialogLong(hwnd, IDC_TRIGRAD_ALPHA)
  1554. << Color::AlphaShift));
  1555. if (count[curIndex] > 0)
  1556. free(blend[curIndex]);
  1557. GetDialogRealList(hwnd, IDC_TRIGRAD_BLEND, &(blend[curIndex]),
  1558. &(count[curIndex]));
  1559. return FALSE;
  1560. }
  1561. BOOL TestTriangleGradShape :: ProcessDialog(HWND hwnd,
  1562. UINT msg,
  1563. WPARAM wParam,
  1564. LPARAM lParam)
  1565. {
  1566. if (msg == WM_COMMAND)
  1567. {
  1568. switch(LOWORD(wParam))
  1569. {
  1570. case IDC_OK:
  1571. if (SaveValues(hwnd))
  1572. WarningBeep();
  1573. else
  1574. ::EndDialog(hwnd, TRUE);
  1575. break;
  1576. case IDC_TRIGRAD_COLORBUTTON:
  1577. UpdateRGBColor(hwnd, IDC_TRIGRAD_PIC, tmpArgb);
  1578. break;
  1579. case IDC_REFRESH_PIC:
  1580. UpdateColorPicture(hwnd, IDC_TRIGRAD_PIC, tmpArgb);
  1581. break;
  1582. case IDC_CANCEL:
  1583. ::EndDialog(hwnd, FALSE);
  1584. break;
  1585. default:
  1586. return FALSE;
  1587. }
  1588. return TRUE;
  1589. }
  1590. return FALSE;
  1591. }
  1592. //*******************************************************************
  1593. //
  1594. // TestPathGradShape
  1595. //
  1596. //
  1597. //
  1598. //*******************************************************************
  1599. BOOL TestPathGradShape :: AddPoint(HWND hwnd, Point pt)
  1600. {
  1601. // Find point pair to insert between
  1602. // INT insertAt = FindLocationToInsert(pt);
  1603. curIndex = pts.GetCount();
  1604. pts.Add(pt);
  1605. argb.Add(0x80000000);
  1606. if(!ChangeSettings(hwnd))
  1607. {
  1608. // undo this add, we canceled the point.
  1609. pts.SetCount(curIndex);
  1610. }
  1611. return FALSE;
  1612. }
  1613. VOID TestPathGradShape :: DoneShape(HWND hwnd)
  1614. {
  1615. DebugBreak();
  1616. }
  1617. BOOL TestPathGradShape :: EndPoint(HWND hwnd, Point pt)
  1618. {
  1619. curIndex = FindControlPoint(pt);
  1620. // we aren't at a control point, no dialog box
  1621. if (curIndex < 0)
  1622. {
  1623. WarningBeep();
  1624. }
  1625. else
  1626. {
  1627. // pop-up dialog to configure color & blend at this point.
  1628. return ChangeSettings(hwnd);
  1629. }
  1630. return FALSE;
  1631. }
  1632. BOOL TestPathGradShape :: RemovePoint(HWND hwnd)
  1633. {
  1634. INT count = pts.GetCount();
  1635. if (count > 4)
  1636. {
  1637. pts.SetCount(count-1);
  1638. return TRUE;
  1639. }
  1640. else
  1641. return FALSE;
  1642. }
  1643. BOOL TestPathGradShape :: IsComplete()
  1644. {
  1645. return TRUE;
  1646. }
  1647. BOOL TestPathGradShape :: MoveControlPoint(Point origPt, Point newPt)
  1648. {
  1649. INT count = pts.GetCount();
  1650. INT pos = 0;
  1651. // !!! what if multiple control points overlap?
  1652. // can't get to one of them
  1653. for (pos = 0; pos<count; pos++)
  1654. {
  1655. Point *ctrlPt = &pts[pos];
  1656. ERectangle ctrlRect(ctrlPt->X-pointRadius,
  1657. ctrlPt->Y-pointRadius,
  1658. 2*pointRadius,
  1659. 2*pointRadius);
  1660. if (origPt.X>ctrlPt->X-pointRadius &&
  1661. origPt.X<ctrlPt->X+pointRadius &&
  1662. origPt.Y>ctrlPt->Y-pointRadius &&
  1663. origPt.Y<ctrlPt->Y+pointRadius)
  1664. {
  1665. ctrlPt->X = newPt.X;
  1666. ctrlPt->Y = newPt.Y;
  1667. if (pos > 0)
  1668. gdiBrush->SetPoint(ctrlPt,pos-1);
  1669. else
  1670. gdiBrush->SetCenterPoint(*ctrlPt);
  1671. return TRUE;
  1672. }
  1673. }
  1674. return FALSE;
  1675. }
  1676. VOID TestPathGradShape :: DrawShape(Graphics* g)
  1677. {
  1678. INT count = pts.GetCount();
  1679. Point* ptbuf = (Point*)pts.GetDataBuffer();
  1680. if (gdiBrush)
  1681. g->FillPolygon(gdiBrush, (Point*)&pts[1], count-1);
  1682. }
  1683. // Configuration management functions
  1684. BOOL TestPathGradShape :: ChangeSettings(HWND hwndParent)
  1685. {
  1686. BOOL ok = DialogBoxParam(hInst,
  1687. MAKEINTRESOURCE(IDD_POLYGRAD_DLG2),
  1688. hwndParent,
  1689. AllDialogBox,
  1690. (LPARAM)((TestDialogInterface*)this));
  1691. if (ok)
  1692. {
  1693. delete gdiBrush;
  1694. gdiBrush = new PathGradientBrush((Point*)&pts[1],
  1695. pts.GetCount()-1);
  1696. // set blending factors
  1697. gdiBrush->SetBlend(centerBlend, centerCount);
  1698. //gdiBrush->SetSurroundBlend(surroundBlend, surroundCount);
  1699. // set colors
  1700. Color center(argb[0]);
  1701. gdiBrush->SetCenterColor(center);
  1702. for (INT pos = 1; pos < pts.GetCount(); pos++)
  1703. {
  1704. Color color(argb[pos]);
  1705. gdiBrush->SetSurroundColor(color, pos-1);
  1706. }
  1707. // set points
  1708. gdiBrush->SetCenterPoint(pts[0]);
  1709. gdiBrush->SetPolygon(&pts[1]);
  1710. }
  1711. return ok;
  1712. }
  1713. VOID TestPathGradShape :: Initialize()
  1714. {
  1715. DebugBreak();
  1716. };
  1717. VOID TestPathGradShape :: Initialize(TestShape* shape)
  1718. {
  1719. DebugBreak();
  1720. }
  1721. VOID TestPathGradShape :: Initialize(PointArray* newPts,
  1722. ARGBArray* newArgb,
  1723. REAL* newSurroundBlend,
  1724. INT newSurroundCount,
  1725. REAL* newCenterBlend,
  1726. INT newCenterCount)
  1727. {
  1728. INT pos;
  1729. pts.Reset();
  1730. argb.Reset();
  1731. for (pos = 0; pos < newPts->GetCount(); pos++)
  1732. {
  1733. pts.Add((*newPts)[pos]);
  1734. argb.Add((*newArgb)[pos]);
  1735. }
  1736. surroundCount = newSurroundCount;
  1737. centerCount = newCenterCount;
  1738. if (surroundCount && newSurroundBlend)
  1739. {
  1740. surroundBlend = (REAL*) malloc(sizeof(REAL)*surroundCount);
  1741. memcpy(surroundBlend, newSurroundBlend, sizeof(REAL)*surroundCount);
  1742. }
  1743. else
  1744. surroundBlend = NULL;
  1745. if (centerCount && newCenterBlend)
  1746. {
  1747. centerBlend = (REAL*) malloc(sizeof(REAL)*centerCount);
  1748. memcpy(centerBlend, newCenterBlend, sizeof(REAL)*centerCount);
  1749. }
  1750. else
  1751. centerBlend = NULL;
  1752. gdiBrush = new PathGradientBrush((Point*)&pts[1],
  1753. newPts->GetCount()-1);
  1754. gdiBrush->SetCenterPoint(pts[0]);
  1755. Color centerColor(argb[0]);
  1756. gdiBrush->SetCenterColor(centerColor);
  1757. for (pos = 1; pos < pts.GetCount(); pos++)
  1758. {
  1759. Color color(argb[pos]);
  1760. gdiBrush->SetSurroundColor(color, pos-1);
  1761. }
  1762. // set blending factors
  1763. gdiBrush->SetBlend(centerBlend, centerCount);
  1764. //gdiBrush->SetSurroundBlend(surroundBlend, surroundCount);
  1765. }
  1766. // Dialog management functions (not used)
  1767. VOID TestPathGradShape :: InitDialog(HWND hwnd)
  1768. {
  1769. tmpArgb = argb[curIndex];
  1770. SetDialogLong(hwnd, IDC_POLYGRAD_ALPHA, (tmpArgb & Color::AlphaMask) >> Color::AlphaShift);
  1771. if (curIndex)
  1772. {
  1773. SetDialogRealList(hwnd,
  1774. IDC_POLYGRAD_BLEND,
  1775. surroundBlend,
  1776. surroundCount);
  1777. }
  1778. else
  1779. {
  1780. SetDialogRealList(hwnd,
  1781. IDC_POLYGRAD_BLEND,
  1782. centerBlend,
  1783. centerCount);
  1784. }
  1785. }
  1786. BOOL TestPathGradShape :: SaveValues(HWND hwnd)
  1787. {
  1788. argb[curIndex] = ((tmpArgb & ~Color::AlphaMask) |
  1789. (GetDialogLong(hwnd, IDC_POLYGRAD_ALPHA)
  1790. << Color::AlphaShift));
  1791. if (curIndex)
  1792. {
  1793. if (surroundBlend)
  1794. free(surroundBlend);
  1795. GetDialogRealList(hwnd, IDC_POLYGRAD_BLEND, &surroundBlend,
  1796. &surroundCount);
  1797. }
  1798. else
  1799. {
  1800. if (centerBlend)
  1801. free(centerBlend);
  1802. GetDialogRealList(hwnd, IDC_POLYGRAD_BLEND, &centerBlend,
  1803. &centerCount);
  1804. }
  1805. return FALSE;
  1806. }
  1807. BOOL TestPathGradShape :: ProcessDialog(HWND hwnd,
  1808. UINT msg,
  1809. WPARAM wParam,
  1810. LPARAM lParam)
  1811. {
  1812. if (msg == WM_COMMAND)
  1813. {
  1814. switch(LOWORD(wParam))
  1815. {
  1816. case IDC_OK:
  1817. if (SaveValues(hwnd))
  1818. WarningBeep();
  1819. else
  1820. ::EndDialog(hwnd, TRUE);
  1821. break;
  1822. case IDC_POLYGRAD_COLORBUTTON:
  1823. UpdateRGBColor(hwnd, IDC_POLYGRAD_PIC, tmpArgb);
  1824. break;
  1825. case IDC_REFRESH_PIC:
  1826. UpdateColorPicture(hwnd, IDC_POLYGRAD_PIC, tmpArgb);
  1827. break;
  1828. case IDC_CANCEL:
  1829. ::EndDialog(hwnd, FALSE);
  1830. break;
  1831. default:
  1832. return FALSE;
  1833. }
  1834. return TRUE;
  1835. }
  1836. return FALSE;
  1837. }