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.

383 lines
12 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: CGradients.cpp
  3. *
  4. * This file contains the code to support the functionality test harness
  5. * for GDI+. This includes menu options and calling the appropriate
  6. * functions for execution.
  7. *
  8. * Created: 05-May-2000 - Jeff Vezina [t-jfvez]
  9. *
  10. * Copyright (c) 2000 Microsoft Corporation
  11. *
  12. \**************************************************************************/
  13. #include "CGradients.h"
  14. GraphicsPath *CreateHeartPath(const RectF& rect)
  15. {
  16. GpPointF points[7];
  17. points[0].X = 0;
  18. points[0].Y = 0;
  19. points[1].X = 1.00;
  20. points[1].Y = -1.00;
  21. points[2].X = 2.00;
  22. points[2].Y = 1.00;
  23. points[3].X = 0;
  24. points[3].Y = 2.00;
  25. points[4].X = -2.00;
  26. points[4].Y = 1.00;
  27. points[5].X = -1.00;
  28. points[5].Y = -1.00;
  29. points[6].X = 0;
  30. points[6].Y = 0;
  31. Matrix matrix;
  32. matrix.Scale(rect.Width/2, rect.Height/3, MatrixOrderAppend);
  33. matrix.Translate(3*rect.Width/2, 4*rect.Height/3, MatrixOrderAppend);
  34. matrix.TransformPoints(&points[0], 7);
  35. GraphicsPath* path = new GraphicsPath();
  36. if(path)
  37. {
  38. path->AddBeziers(&points[0], 7);
  39. path->CloseFigure();
  40. }
  41. return path;
  42. }
  43. CScaledGradients::CScaledGradients(BOOL bRegression)
  44. {
  45. strcpy(m_szName,"Gradient : Path,Scaled,Tiled");
  46. m_bRegression=bRegression;
  47. }
  48. void CScaledGradients::Draw(Graphics *g)
  49. {
  50. Status st;
  51. RectF heartRect(-100,0,500,500);
  52. GraphicsPath *heartPath = CreateHeartPath(heartRect);
  53. Matrix matrix;
  54. matrix.Translate(-460, -480);
  55. st = heartPath->Flatten(&matrix);
  56. Bitmap bitmap(250,250);
  57. Graphics *bg = Graphics::FromImage(&bitmap);
  58. PathGradientBrush pathGrad(heartPath);
  59. INT count = 3;
  60. REAL blend[3];
  61. blend[0] = (REAL) 0;
  62. blend[1] = (REAL) 0.5;
  63. blend[2] = (REAL) 1;
  64. REAL positions[3];
  65. positions[0] = (REAL) 0;
  66. positions[1] = (REAL) 0.4;
  67. positions[2] = (REAL) 1;
  68. st = pathGrad.SetBlend(&blend[0], &positions[0], count);
  69. st = pathGrad.SetCenterColor(Color(128,0,128,80));
  70. st = pathGrad.SetWrapMode(WrapModeTileFlipXY);
  71. count = heartPath->GetPointCount();
  72. Color* surColors = (Color*)new Color[count];
  73. INT iColor = 255/count;
  74. for (INT i=0; i<count; i++)
  75. {
  76. float pos = (float)i/(count-1);
  77. surColors[i].SetValue(
  78. (((INT)(255.0f-i)) << 24) |
  79. (((INT)(255.0f*pos)) << 16) |
  80. ((INT)(255.0f*(1.0f-pos)))
  81. );
  82. }
  83. st = pathGrad.SetSurroundColors(surColors, &count);
  84. GraphicsPath r1, r2;
  85. RectF sqrect(0,140,600,1000);
  86. r1.AddRectangle(sqrect);
  87. sqrect.Width *= 2.3f;
  88. r2.AddRectangle(sqrect);
  89. st = bg->ScaleTransform(0.2f, 0.2f);
  90. st = bg->FillPath(&pathGrad, &r1);
  91. st = bg->TranslateTransform(400, 0);
  92. st = bg->ScaleTransform(0.66f, 1.33f);
  93. st = bg->FillPath(&pathGrad, &r2);
  94. st = g->DrawImage(&bitmap,0,0,0,0,250,250,UnitPixel);
  95. delete heartPath;
  96. delete surColors;
  97. delete bg;
  98. }
  99. CGradients::CGradients(BOOL bRegression)
  100. {
  101. strcpy(m_szName,"Gradient : Misc");
  102. m_bRegression=bRegression;
  103. }
  104. void CGradients::Draw(Graphics *g)
  105. {
  106. // Test FillRectangle call
  107. Color rc1(0xFF,0xFF,0,0); // red
  108. Color rc2(0xFF,0xFF,0,0);
  109. Color rc3(0x80,0xFF,0,0);
  110. Color rc4(0x80,0,0xff,0);
  111. Color rc5(0x40,0,0,0xff);
  112. Color rc6(0x40,0x80,0x80,0);
  113. SolidBrush rcb1(rc1);
  114. SolidBrush rcb2(rc2);
  115. SolidBrush rcb3(rc3);
  116. SolidBrush rcb4(rc4);
  117. SolidBrush rcb5(rc5);
  118. SolidBrush rcb6(rc6);
  119. g->FillRectangle(&rcb1, RectF((int)(0.0f/360.0f*TESTAREAWIDTH), (int)(0.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT)));
  120. g->FillRectangle(&rcb2, RectF((int)(50.0f/360.0f*TESTAREAWIDTH), (int)(0.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT)));
  121. g->FillRectangle(&rcb3, RectF((int)(100.0f/360.0f*TESTAREAWIDTH), (int)(0.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT)));
  122. g->FillRectangle(&rcb4, RectF((int)(150.0f/360.0f*TESTAREAWIDTH), (int)(0.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT)));
  123. g->FillRectangle(&rcb5, RectF((int)(200.0f/360.0f*TESTAREAWIDTH), (int)(0.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT)));
  124. g->FillRectangle(&rcb6, RectF((int)(250.0f/360.0f*TESTAREAWIDTH), (int)(0.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT)));
  125. RectF rf[6] = {
  126. RectF((int)(0.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT)),
  127. RectF((int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT)),
  128. RectF((int)(100.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT)),
  129. RectF((int)(150.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT)),
  130. RectF((int)(200.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT)),
  131. RectF((int)(250.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT), (int)(50.0f/360.0f*TESTAREAWIDTH), (int)(50.0f/360.0f*TESTAREAHEIGHT))
  132. };
  133. RectF polyRect;
  134. Color centerColor(255, 255, 255, 255);
  135. Color boundaryColor(255, 0, 0, 0);
  136. REAL width = 4; // Pen width
  137. // Create a rectangular gradient brush.
  138. RectF brushRect(0, 0, 3, 3);
  139. Color colors[5] = {
  140. Color(255, 255, 255, 255),
  141. Color(255, 255, 0, 0),
  142. Color(255, 0, 255, 0),
  143. Color(255, 0, 0, 255),
  144. Color(255, 0, 0, 0)
  145. };
  146. PointF points[7];
  147. // Rotate a brush.
  148. GpMatrix xForm;
  149. xForm.Rotate(155);
  150. // Change the wrapping mode and fill.
  151. REAL blend[10];
  152. Color presetColors[10];
  153. Color presetColorsb[10];
  154. REAL positions[10];
  155. INT count;
  156. Color blackColor(0, 0, 0);
  157. SolidBrush blackBrush(blackColor);
  158. Pen blackPen(&blackBrush, width);
  159. g->DrawRectangle(&blackPen, brushRect);
  160. // Create a radial gradient brush.
  161. brushRect.X = (int)(380.0f/360.0f*TESTAREAWIDTH);
  162. brushRect.Y = (int)(130.0f/360.0f*TESTAREAHEIGHT);
  163. brushRect.Width = (int)(60.0f/360.0f*TESTAREAWIDTH);
  164. brushRect.Height = (int)(32.0f/360.0f*TESTAREAHEIGHT);
  165. PointF center;
  166. center.X = brushRect.X + brushRect.Width/2;
  167. center.Y = brushRect.Y + brushRect.Height/2;
  168. xForm.Reset();
  169. xForm.RotateAt(-30, center, MatrixOrderAppend);
  170. // Triangle Gradient Brush no longer supported.
  171. points[0].X = (int)(200.0f/360.0f*TESTAREAWIDTH);
  172. points[0].Y = (int)(300.0f/360.0f*TESTAREAHEIGHT);
  173. points[1].X = (int)(280.0f/360.0f*TESTAREAWIDTH);
  174. points[1].Y = (int)(350.0f/360.0f*TESTAREAHEIGHT);
  175. points[2].X = (int)(220.0f/360.0f*TESTAREAWIDTH);
  176. points[2].Y = (int)(420.0f/360.0f*TESTAREAHEIGHT);
  177. points[3].X = (int)(160.0f/360.0f*TESTAREAWIDTH);
  178. points[3].Y = (int)(440.0f/360.0f*TESTAREAHEIGHT);
  179. points[4].X = (int)(120.0f/360.0f*TESTAREAWIDTH);
  180. points[4].Y = (int)(370.0f/360.0f*TESTAREAHEIGHT);
  181. Matrix matrix;
  182. matrix.Translate((int)(20.0f/360.0f*TESTAREAWIDTH), -(int)(160.0f/360.0f*TESTAREAHEIGHT));
  183. matrix.TransformPoints(points, 5);
  184. PathGradientBrush polyGrad(points, 5, WrapModeTile);
  185. count = 3;
  186. blend[0] = (REAL) 0;
  187. blend[1] = (REAL) 0;
  188. blend[2] = (REAL) 1;
  189. positions[0] = (REAL) 0;
  190. positions[1] = (REAL) 0.4;
  191. positions[2] = (REAL) 1;
  192. // Test for blending factors.
  193. polyGrad.SetBlend(&blend[0], &positions[0], count);
  194. polyGrad.SetCenterColor(centerColor);
  195. count = 5;
  196. polyGrad.SetSurroundColors(colors, &count);
  197. polyRect.X = 0;
  198. polyRect.Y = 0;
  199. polyRect.Width = (int) TESTAREAWIDTH;
  200. polyRect.Height = (int) TESTAREAHEIGHT;
  201. g->FillRectangle(&polyGrad, polyRect);
  202. // Create a heart shaped path.
  203. RectF rect;
  204. rect.X = (int)(300.0f/360.0f*TESTAREAWIDTH);
  205. rect.Y = (int)(300.0f/360.0f*TESTAREAHEIGHT);
  206. rect.Width = (int)(150.0f/360.0f*TESTAREAWIDTH);
  207. rect.Height = (int)(150.0f/360.0f*TESTAREAHEIGHT);
  208. GraphicsPath *path = CreateHeartPath(rect);
  209. // Create a gradient from a path.
  210. PathGradientBrush pathGrad(path);
  211. delete path;
  212. pathGrad.SetCenterColor(centerColor);
  213. count = pathGrad.GetSurroundColorCount();
  214. Color* surColors = (Color*)new Color[count];
  215. pathGrad.GetSurroundColors(surColors, &count);
  216. surColors[0] = Color(255, 255, 0, 0);
  217. count = 1;
  218. pathGrad.SetSurroundColors(surColors, &count);
  219. pathGrad.GetRectangle(&polyRect);
  220. // Set the rect focus.
  221. PointF centerPt;
  222. pathGrad.GetCenterPoint(&centerPt);
  223. centerPt.X -= 3;
  224. centerPt.Y += 6;
  225. pathGrad.SetCenterPoint(centerPt);
  226. REAL xScale, yScale;
  227. pathGrad.GetFocusScales(&xScale, &yScale);
  228. xScale = 0.4f;
  229. yScale = 0.3f;
  230. pathGrad.SetFocusScales(xScale, yScale);
  231. g->FillRectangle(&pathGrad, polyRect);
  232. RectF lineRect((int)(120.0f/360.0f*TESTAREAWIDTH), (int)(0.0f/360.0f*TESTAREAHEIGHT), (int)(200.0f/360.0f*TESTAREAWIDTH), (int)(60.0f/360.0f*TESTAREAHEIGHT));
  233. Color color1(200, 255, 255, 0);
  234. Color color2(200, 0, 0, 255);
  235. LinearGradientBrush LinearGrad(lineRect, color1, color1,
  236. LinearGradientModeForwardDiagonal);
  237. RectF lineRectb((int)(120.0f/360.0f*TESTAREAWIDTH), (int)(300.0f/360.0f*TESTAREAHEIGHT), (int)(200.0f/360.0f*TESTAREAWIDTH), (int)(60.0f/360.0f*TESTAREAHEIGHT));
  238. Color color1b(20, 255, 255, 0);
  239. Color color2b(20, 0, 0, 255);
  240. LinearGradientBrush LinearGradb(lineRectb, color1b, color1b,
  241. LinearGradientModeForwardDiagonal);
  242. // Test for preset colors
  243. presetColors[0] = Color(200, 0, 255, 255);
  244. presetColors[1] = Color(200, 255, 255, 0);
  245. presetColors[2] = Color(200, 0, 255, 0);
  246. presetColorsb[0] = Color(20, 0, 255, 255);
  247. presetColorsb[1] = Color(20, 255, 255, 0);
  248. presetColorsb[2] = Color(20, 0, 255, 0);
  249. count = 3;
  250. count = 3;
  251. blend[0] = (REAL) 0;
  252. blend[1] = (REAL) 0;
  253. blend[2] = (REAL) 1;
  254. positions[0] = (REAL) 0;
  255. positions[1] = (REAL) 0.4;
  256. positions[2] = (REAL) 1;
  257. LinearGrad.SetInterpolationColors(&presetColors[0], &positions[0], count);
  258. LinearGradb.SetInterpolationColors(&presetColorsb[0], &positions[0], count);
  259. g->FillRectangle(&LinearGrad, lineRect);
  260. g->FillRectangle(&LinearGradb, lineRectb);
  261. RectF rectl(90.0f/360.0f*TESTAREAWIDTH, 120.0f/360.0f*TESTAREAHEIGHT, 120.0f/360.0f*TESTAREAWIDTH, 120.0f/360.0f*TESTAREAHEIGHT);
  262. PointF pt1(rectl.X+rectl.Width/2.0f, rectl.Y);
  263. PointF pt2(rectl.X+rectl.Width/2.0f, rectl.Y+rectl.Height);
  264. LinearGradientBrush linbrush(pt1, pt2,
  265. Color(0xFF, 0xFF, 0, 0),
  266. Color(0xFF, 0, 0xFF, 0));
  267. GraphicsPath pathl;
  268. pathl.AddRectangle(rectl);
  269. SolidBrush sbrush(Color(0xFF,0xFF,0,0));
  270. g->FillRectangle(&sbrush, rectl);
  271. g->FillPath(&linbrush, &pathl);
  272. }
  273. CAlphaGradient::CAlphaGradient(BOOL bRegression)
  274. {
  275. strcpy(m_szName,"Gradient : Premultiplied Interpolation");
  276. m_bRegression=bRegression;
  277. }
  278. void CAlphaGradient::Draw(Graphics *g)
  279. {
  280. GraphicsPath gp;
  281. PointF points[3];
  282. points[0].X = (int)(0.5f*TESTAREAWIDTH);
  283. points[0].Y = (int)(0.0f*TESTAREAHEIGHT);
  284. points[1].X = (int)(1.0f*TESTAREAWIDTH);
  285. points[1].Y = (int)(0.7f*TESTAREAHEIGHT);
  286. points[2].X = (int)(0.0f*TESTAREAWIDTH);
  287. points[2].Y = (int)(0.4f*TESTAREAHEIGHT);
  288. gp.AddPolygon(points, 3);
  289. Color colors[3] = { 0xffff0000, 0xff00ff00, 0x00000000 };
  290. int count = 3;
  291. PathGradientBrush brush(&gp);
  292. brush.SetSurroundColors(colors, &count);
  293. brush.SetCenterColor(0xaa555500);
  294. brush.SetCenterPoint(PointF(
  295. (points[0].X+points[1].X+points[2].X)/3.0f,
  296. (points[0].Y+points[1].Y+points[2].Y)/3.0f
  297. ));
  298. g->FillPath(&brush, &gp);
  299. }