Shapes.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // Shapes.cs
  3. //
  4. // Authors:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Drawing;
  30. using System.Drawing.Drawing2D;
  31. namespace Samples.Common {
  32. public class Shapes {
  33. static public object[] GetList ()
  34. {
  35. return new object[] {
  36. "Arc",
  37. "Bezier",
  38. "Beziers",
  39. "Closed Curve",
  40. "Curve",
  41. "Ellipse",
  42. "Line",
  43. "Lines",
  44. "Pie",
  45. "Polygon",
  46. "Rectangle",
  47. "Rectangles",
  48. "String",
  49. "Complex (AddPath)"
  50. };
  51. }
  52. static public GraphicsPath GetShape (int index)
  53. {
  54. switch (index) {
  55. case 0:
  56. return Arc ();
  57. case 1:
  58. return Bezier ();
  59. case 2:
  60. return Beziers ();
  61. case 3:
  62. return ClosedCurve ();
  63. case 4:
  64. return Curve ();
  65. case 5:
  66. return Ellipse ();
  67. case 6:
  68. return Line ();
  69. case 7:
  70. return Lines ();
  71. case 8:
  72. return Pie ();
  73. case 9:
  74. return Polygon ();
  75. case 10:
  76. return Rectangle ();
  77. case 11:
  78. return Rectangles ();
  79. case 12:
  80. return String ();
  81. case 13:
  82. return Complex ();
  83. default:
  84. // nothing to show
  85. return null;
  86. }
  87. }
  88. static private GraphicsPath Arc ()
  89. {
  90. GraphicsPath path = new GraphicsPath ();
  91. path.AddArc (20, 20, 200, 200, 60, 120);
  92. return path;
  93. }
  94. static private GraphicsPath Bezier ()
  95. {
  96. GraphicsPath path = new GraphicsPath ();
  97. path.AddBezier (
  98. new Point (20, 100), new Point (70, 10),
  99. new Point (130, 200), new Point (180, 100)
  100. );
  101. return path;
  102. }
  103. static private GraphicsPath Beziers ()
  104. {
  105. GraphicsPath path = new GraphicsPath ();
  106. path.AddBeziers (new Point[7] {
  107. new Point (20, 100), new Point (70, 10),
  108. new Point (130, 200), new Point (180, 100),
  109. new Point (200, 100), new Point (240, 240),
  110. new Point (20, 100)
  111. });
  112. return path;
  113. }
  114. static private GraphicsPath ClosedCurve ()
  115. {
  116. GraphicsPath path = new GraphicsPath ();
  117. path.AddClosedCurve (new Point[4] {
  118. new Point (20, 100), new Point (70, 10),
  119. new Point (130, 200), new Point (180, 100)
  120. });
  121. return path;
  122. }
  123. static private GraphicsPath Curve ()
  124. {
  125. GraphicsPath path = new GraphicsPath ();
  126. path.AddCurve (new Point[4] {
  127. new Point (20, 100), new Point (70, 10),
  128. new Point (130, 200), new Point (180, 100)
  129. });
  130. return path;
  131. }
  132. static private GraphicsPath Ellipse ()
  133. {
  134. GraphicsPath path = new GraphicsPath ();
  135. path.AddEllipse (20, 20, 200, 100);
  136. return path;
  137. }
  138. static private GraphicsPath Line ()
  139. {
  140. GraphicsPath path = new GraphicsPath ();
  141. path.AddLine (20, 20, 200, 100);
  142. return path;
  143. }
  144. static private GraphicsPath Lines ()
  145. {
  146. GraphicsPath path = new GraphicsPath ();
  147. path.AddLines (new Point[4] {
  148. new Point (20, 100), new Point (70, 10),
  149. new Point (130, 200), new Point (180, 100)
  150. });
  151. return path;
  152. }
  153. static private GraphicsPath Pie ()
  154. {
  155. GraphicsPath path = new GraphicsPath ();
  156. path.AddPie (20, 20, 200, 200, 60, 120);
  157. return path;
  158. }
  159. static private GraphicsPath Polygon ()
  160. {
  161. GraphicsPath path = new GraphicsPath ();
  162. path.AddPolygon (new Point[4] {
  163. new Point (20, 100), new Point (70, 10),
  164. new Point (130, 200), new Point (180, 100)
  165. });
  166. return path;
  167. }
  168. static private GraphicsPath Rectangle ()
  169. {
  170. GraphicsPath path = new GraphicsPath ();
  171. path.AddRectangle (new Rectangle (20, 20, 200, 200));
  172. return path;
  173. }
  174. static private GraphicsPath Rectangles ()
  175. {
  176. GraphicsPath path = new GraphicsPath ();
  177. path.AddRectangles (new Rectangle[2] {
  178. new Rectangle (20, 20, 100, 100),
  179. new Rectangle (100, 100, 20, 20)
  180. });
  181. return path;
  182. }
  183. static private GraphicsPath String ()
  184. {
  185. GraphicsPath path = new GraphicsPath ();
  186. try {
  187. path.AddString ("Mono", FontFamily.GenericMonospace, 0, 10f, new Point (20, 20), StringFormat.GenericDefault);
  188. }
  189. catch (NotImplementedException) {
  190. // not implemented in libgdiplus
  191. }
  192. return path;
  193. }
  194. static private GraphicsPath Complex ()
  195. {
  196. GraphicsPath path = new GraphicsPath ();
  197. path.AddPath (Pie (), false);
  198. path.AddPath (Rectangle (), true);
  199. path.AddPath (Polygon (), false);
  200. return path;
  201. }
  202. }
  203. }