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.

217 lines
5.7 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: CMixedObjects.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 "CMixedObjects.h"
  14. class RectI
  15. {
  16. public:
  17. INT X;
  18. INT Y;
  19. INT Width;
  20. INT Height;
  21. };
  22. CMixedObjects::CMixedObjects(BOOL bRegression)
  23. {
  24. strcpy(m_szName,"MixedObjects");
  25. m_bRegression=bRegression;
  26. }
  27. CMixedObjects::~CMixedObjects()
  28. {
  29. }
  30. void CMixedObjects::Draw(Graphics *g)
  31. {
  32. Point points[10];
  33. REAL width = 4; // Pen width
  34. // Load bmp files.
  35. WCHAR *filename = L"..\\data\\winnt256.bmp";
  36. Bitmap *bitmap = new Bitmap(filename);
  37. // Create a texture brush.
  38. RectI copyRect;
  39. copyRect.X = 60;
  40. copyRect.Y = 60;
  41. copyRect.Width = 80;
  42. copyRect.Height = 60;
  43. Bitmap *copiedBitmap = bitmap->Clone(copyRect.X, copyRect.Y,
  44. copyRect.Width, copyRect.Height,
  45. PixelFormat32bppARGB);
  46. // Create a rectangular gradient brush.
  47. RectF brushRect(0, 0, 10, 10);
  48. Color colors[4] = {
  49. Color(255, 255, 255, 255),
  50. Color(255, 255, 0, 0),
  51. Color(255, 0, 255, 0),
  52. Color(255, 0, 0, 255)
  53. };
  54. // RectangleGradientBrush rectGrad(brushRect, (Color*)&colors, WrapModeTile);
  55. width = 8;
  56. // Pen gradPen(&rectGrad, width);
  57. if(copiedBitmap)
  58. {
  59. // Create a texture brush.
  60. TextureBrush textureBrush(copiedBitmap, WrapModeTile);
  61. delete copiedBitmap;
  62. // Create a radial gradient pen.
  63. points[3].X = (int)(50.0f/400.0f*TESTAREAWIDTH);
  64. points[3].Y = (int)(80.0f/400.0f*TESTAREAHEIGHT);
  65. points[2].X = (int)(200.0f/400.0f*TESTAREAWIDTH);
  66. points[2].Y = (int)(200.0f/400.0f*TESTAREAHEIGHT);
  67. points[1].X = (int)(220.0f/400.0f*TESTAREAWIDTH);
  68. points[1].Y = (int)(340.0f/400.0f*TESTAREAHEIGHT);
  69. points[0].X = (int)(50.0f/400.0f*TESTAREAWIDTH);
  70. points[0].Y = (int)(250.0f/400.0f*TESTAREAHEIGHT);
  71. Matrix mat;
  72. mat.Rotate(30);
  73. textureBrush.SetTransform(&mat);
  74. // gradPen.SetLineJoin(LineJoinMiter);
  75. // g->FillPolygon(&textureBrush, points, 4);
  76. Pen pen(&textureBrush, 30);
  77. g->DrawPolygon(&pen, points, 4);
  78. }
  79. delete bitmap;
  80. }
  81. /**************************************************************************\
  82. * TestTexts
  83. *
  84. * A test for drawing texts.
  85. *
  86. \**************************************************************************/
  87. VOID CMixedObjects::TestTexts(Graphics *g)
  88. {
  89. //Font font(L"Arial", 60);
  90. FontFamily ff(L"Arial");
  91. RectF rectf(20, 0, 300, 200);
  92. GraphicsPath path;
  93. // Solid color text.
  94. Color color(128, 100, 0, 200);
  95. SolidBrush brush(color);
  96. path.AddString(L"Color", 5, &ff, 0, 60, rectf, NULL);
  97. g->FillPath(&brush, &path);
  98. // Texture text.
  99. WCHAR filename[256];
  100. wcscpy(filename, L"..\\data\\marble1.jpg");
  101. Bitmap *bitmap = new Bitmap(filename);
  102. TextureBrush textureBrush(bitmap, WrapModeTile);
  103. path.Reset();
  104. rectf.X = 200;
  105. rectf.Y = 20;
  106. path.AddString(L"Texture", 7, &ff, 0, 60, rectf, NULL);
  107. g->FillPath(&textureBrush, &path);
  108. delete bitmap;
  109. // Gradient text.
  110. rectf.X = 40;
  111. rectf.Y = 80;
  112. path.Reset();
  113. path.AddString(L"Gradient", 8, &ff, 0, 60, rectf, NULL);
  114. Color color1(255, 255, 0, 0);
  115. Color color2(255, 0, 255, 0);
  116. LinearGradientBrush lineGrad(rectf, color1, color2, 0.0f);
  117. g->FillPath(&lineGrad, &path);
  118. // Shadow test
  119. REAL charHeight = 60;
  120. REAL topMargin = - 5;
  121. rectf.X = 0;
  122. rectf.Y = - charHeight - topMargin; // Make y-coord of the base line
  123. // of the characters to be 0.
  124. path.Reset();
  125. path.AddString(L"Shadow", 6, &ff, 0, charHeight, rectf, NULL);
  126. GraphicsPath* clonePath = path.Clone();
  127. Color redColor(255, 0, 0);
  128. Color grayColor(128, 0, 0, 0);
  129. SolidBrush redBrush(redColor);
  130. SolidBrush grayBrush(grayColor);
  131. // Shadow part.
  132. REAL tx = 180, ty = 200;
  133. Matrix skew;
  134. skew.Scale(1.0, 0.5);
  135. skew.Shear(-2.0, 0, MatrixOrderAppend);
  136. skew.Translate(tx, ty, MatrixOrderAppend);
  137. clonePath->Transform(&skew);
  138. g->FillPath(&grayBrush, clonePath);
  139. delete clonePath;
  140. // Front part.
  141. Matrix trans1;
  142. trans1.Translate(tx, ty);
  143. path.Transform(&trans1);
  144. g->FillPath(&redBrush, &path);
  145. return;
  146. /*
  147. REAL x = 200, y = 150;
  148. RectF brushRect(x, y, 150, 32);
  149. Color colors[4] = {
  150. Color(180, 255, 0, 0),
  151. Color(180, 0, 255, 0),
  152. Color(180, 255, 0, 0),
  153. Color(180, 0, 255, 0)
  154. };
  155. // RectangleGradientBrush rectGrad(brushRect, (Color*)&colors, WrapModeTile);
  156. // g->DrawString(L"GDI+", &font, &rectGrad, x, y);
  157. // And now with DrawText
  158. RectF rect(400, 200, 400, 400);
  159. g->DrawText(
  160. DrawTextDisplay,
  161. L"A few words powered by GDI+: \
  162. \x3c3\x3bb\x3b1\x3b4 \
  163. \x627\x644\x633\x644\x627\x645 \
  164. \x5e9\x5dc\x5d5\x5dd \
  165. \xe2d\xe4d\xe01\xe29\xe23\xe44\xe17\xe22 \
  166. \x110\x068\x0ea\x300\x103",
  167. &font, // Initial font
  168. &rectGrad, // Initial brush (ignored for the time being)
  169. LANG_NEUTRAL, // Initial language
  170. &rect // Formatting rectangle
  171. );
  172. */
  173. }