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.

316 lines
7.4 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: test.c
  3. *
  4. * Created: 09-Dec-1992 10:51:46
  5. * Author: Kirk Olynyk [kirko]
  6. *
  7. * Copyright (c) 1991 Microsoft Corporation
  8. *
  9. * Contains the test
  10. *
  11. \**************************************************************************/
  12. #include <windows.h>
  13. #include <objbase.h>
  14. #include <math.h> // sin & cos
  15. #include "wndstuff.h"
  16. #include "debug.h"
  17. //
  18. // Where is IStream included from?
  19. //
  20. #define IStream int
  21. #include <gdiplus.h>
  22. using namespace Gdiplus;
  23. #ifndef ASSERT
  24. #define ASSERT(cond) if (!(cond)) { DebugBreak(); }
  25. #endif
  26. // Figures out the Affine matrix mapping from the unit square to the
  27. // input parallelogram
  28. VOID InferAffineMatrix(
  29. const GpPointF* destPoints, // must be 3 points.
  30. Matrix *m
  31. )
  32. {
  33. float x0 = destPoints[0].X;
  34. float y0 = destPoints[0].Y;
  35. float x1 = destPoints[1].X;
  36. float y1 = destPoints[1].Y;
  37. float x2 = destPoints[2].X;
  38. float y2 = destPoints[2].Y;
  39. float u0 = 0.0f;
  40. float v0 = 0.0f;
  41. float u1 = u0 + 1.0f;
  42. float v1 = v0;
  43. float u2 = u0;
  44. float v2 = v0 + 1.0f;
  45. float d = u0*(v1-v2) - v0*(u1-u2) + (u1*v2-u2*v1);
  46. if (fabsf(d) < REAL_EPSILON)
  47. {
  48. ASSERT(FALSE);
  49. return;
  50. }
  51. d = 1.0f / d;
  52. float t0 = v1-v2;
  53. float t1 = v2-v0;
  54. float t2 = v0-v1;
  55. float M11 = d * (x0*t0 + x1*t1 + x2*t2);
  56. float M12 = d * (y0*t0 + y1*t1 + y2*t2);
  57. t0 = u2-u1;
  58. t1 = u0-u2;
  59. t2 = u1-u0;
  60. float M21 = d * (x0*t0 + x1*t1 + x2*t2);
  61. float M22 = d * (y0*t0 + y1*t1 + y2*t2);
  62. t0 = u1*v2-u2*v1;
  63. t1 = u2*v0-u0*v2;
  64. t2 = u2*v1-u1*v0;
  65. float Dx = d * (x0*t0 + x1*t1 + x2*t2);
  66. float Dy = d * (y0*t0 + y1*t1 + y2*t2);
  67. m->SetElements(M11, M12, M21, M22, Dx, Dy);
  68. }
  69. /******************************Public*Routine******************************\
  70. * vTest
  71. *
  72. * This is the workhorse routine that does the test. The test is
  73. * started by chosing it from the window menu.
  74. *
  75. * History:
  76. * Tue 08-Dec-1992 17:31:22 by Kirk Olynyk [kirko]
  77. * Wrote it.
  78. \**************************************************************************/
  79. const PointF center(400.0f, 400.0f);
  80. VOID Test(HWND hwnd)
  81. {
  82. Graphics *g = new Graphics(hwnd);
  83. //g->SetSmoothingMode(SmoothingModeAntiAlias);
  84. DWORD c0 = 0xff0000ff;
  85. DWORD c1 = 0xffff0000;
  86. DWORD c2 = 0xff00ff00;
  87. LinearGradientBrush brush(
  88. PointF(-0.5f, -0.5f),
  89. PointF(0.5f, 0.5f),
  90. Color(c0),
  91. Color(c1)
  92. );
  93. Pen edgePen(Color(0xff000000), 3.5f/400.0f);
  94. brush.SetGammaCorrection(TRUE);
  95. brush.SetWrapMode(WrapModeTile);
  96. brush.SetBlendTriangularShape(0.5f, 1.0f);
  97. // brush.SetBlendBellShape(0.2f, 0.5f);
  98. Matrix m;
  99. GraphicsPath gp;
  100. PointF points[4] = {
  101. PointF(-0.5f, -0.5f),
  102. PointF(0.5f, -0.5f),
  103. PointF(0.5f, 0.5f),
  104. PointF(-0.5f, 0.5f)
  105. };
  106. Matrix bm;
  107. brush.GetTransform(&bm);
  108. gp.AddPolygon(points, 4);
  109. g->TranslateTransform(center.X, center.Y);
  110. g->ScaleTransform(400.0f, 400.0f);
  111. /*
  112. m.SetElements(100.0f, 0.0f, 0.0f, 300.0f, 0.0f, 0.0f);
  113. gp.Transform(&m);
  114. brush.MultiplyTransform(&m, MatrixOrderAppend);
  115. g->FillPath(&brush, &gp);
  116. g->TranslateTransform(-200.0f, 0.0f);
  117. brush.SetTransform(&bm);
  118. brush.SetLinearPoints(PointF(0.0f, 0.0f), PointF(100.0f, 300.0f));
  119. brush.SetLinearColors(Color(c1), Color(c0));
  120. g->FillPath(&brush, &gp);
  121. */
  122. // Simple rotate on the brush transform
  123. g->DrawPath(&edgePen, &gp);
  124. for(int i = 0; i < 181; i++)
  125. {
  126. g->FillPath(&brush, &gp);
  127. brush.RotateTransform(1.0f);
  128. }
  129. brush.SetTransform(&bm);
  130. // Vertical stretch, no brush transform.
  131. for(int i = 0; i < 101; i++)
  132. {
  133. float t = i/100.0f;
  134. float r = 2.0f*(float)M_PI*(t);
  135. m.Reset();
  136. m.Scale(1.0f, 1.0f + (float)sin(r)/70.0f);
  137. gp.Transform(&m);
  138. g->FillPath(&brush, &gp);
  139. g->DrawPath(&edgePen, &gp);
  140. }
  141. brush.SetTransform(&bm);
  142. gp.Reset();
  143. gp.AddPolygon(points, 4);
  144. for(int i = 0; i < 101; i++)
  145. {
  146. float t = i/100.0f;
  147. float r = 2.0f*(float)M_PI*(t);
  148. m.Reset();
  149. m.Scale(1.0f + (float)sin(r)/70.0f, 1.0f);
  150. gp.Transform(&m);
  151. g->FillPath(&brush, &gp);
  152. g->DrawPath(&edgePen, &gp);
  153. }
  154. brush.SetTransform(&bm);
  155. gp.Reset();
  156. gp.AddPolygon(points, 4);
  157. for(int i = 0; i < 101; i++)
  158. {
  159. float r = (float)M_PI*(i/200.0f);
  160. m.Reset();
  161. m.Scale(1.0f, 1.0f + (float)sin(r));
  162. gp.Reset();
  163. gp.AddPolygon(points, 4);
  164. gp.Transform(&m);
  165. brush.SetTransform(&bm);
  166. brush.GetTransform(&m);
  167. m.Scale(1.0f, 1.0f+(float)sin(r), MatrixOrderAppend);
  168. brush.SetTransform(&m);
  169. g->FillPath(&brush, &gp);
  170. g->DrawPath(&edgePen, &gp);
  171. }
  172. for(int i = 0; i < 101; i++)
  173. {
  174. float r = (float)M_PI*(i/200.0f);
  175. m.Reset();
  176. m.Scale(
  177. 1.0f + (float)sin(r),
  178. 1.0f + (float)sin(r+M_PI/2.0f)
  179. );
  180. gp.Reset();
  181. gp.AddPolygon(points, 4);
  182. gp.Transform(&m);
  183. brush.SetTransform(&bm);
  184. brush.GetTransform(&m);
  185. m.Scale(
  186. 1.0f + (float)sin(r),
  187. 1.0f + (float)sin(r+M_PI/2.0f),
  188. MatrixOrderAppend
  189. );
  190. brush.SetTransform(&m);
  191. g->FillPath(&brush, &gp);
  192. g->DrawPath(&edgePen, &gp);
  193. }
  194. for(int i = 0; i < 101; i++)
  195. {
  196. float r = (float)M_PI*(i/200.0f);
  197. m.Reset();
  198. m.Scale(
  199. 1.0f + (float)sin(r+M_PI/2.0f),
  200. 1.0f
  201. );
  202. gp.Reset();
  203. gp.AddPolygon(points, 4);
  204. gp.Transform(&m);
  205. brush.SetTransform(&bm);
  206. brush.GetTransform(&m);
  207. m.Scale(
  208. 1.0f+(float)sin(r+M_PI/2.0f),
  209. 1.0f,
  210. MatrixOrderAppend
  211. );
  212. brush.SetTransform(&m);
  213. g->FillPath(&brush, &gp);
  214. g->DrawPath(&edgePen, &gp);
  215. }
  216. brush.SetTransform(&bm);
  217. gp.Reset();
  218. gp.AddPolygon(points, 4);
  219. Matrix gm;
  220. g->GetTransform(&gm);
  221. for(int i = 0; i < 181; i++)
  222. {
  223. g->FillPath(&brush, &gp);
  224. g->DrawPath(&edgePen, &gp);
  225. brush.RotateTransform(-1.0f);
  226. g->RotateTransform(1.0f);
  227. }
  228. for(int i = 0; i < 181; i++)
  229. {
  230. g->FillPath(&brush, &gp);
  231. g->DrawPath(&edgePen, &gp);
  232. g->RotateTransform(1.0f);
  233. }
  234. for(int i = 0; i < 181; i++)
  235. {
  236. float r = (float)M_PI*(i/180.0f);
  237. g->FillPath(&brush, &gp);
  238. g->SetTransform(&gm);
  239. g->RotateTransform((float)i);
  240. g->ScaleTransform(
  241. 1.0f+(float)sin(r)/2.0f,
  242. 1.0f,
  243. MatrixOrderAppend
  244. );
  245. }
  246. g->SetTransform(&gm);
  247. brush.SetTransform(&bm);
  248. gp.Reset();
  249. gp.AddPolygon(points, 4);
  250. g->FillPath(&brush, &gp);
  251. g->DrawPath(&edgePen, &gp);
  252. delete g;
  253. }