GdiPlusPen.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. //Download by http://www.NewXing.com
  2. /**************************************************************************\
  3. *
  4. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  5. *
  6. * Module Name:
  7. *
  8. * GdiplusPen.h
  9. *
  10. * Abstract:
  11. *
  12. * GDI+ Pen class
  13. *
  14. \**************************************************************************/
  15. #ifndef _GDIPLUSPEN_H
  16. #define _GDIPLUSPEN_H
  17. //--------------------------------------------------------------------------
  18. // Pen class
  19. //--------------------------------------------------------------------------
  20. class Pen : public GdiplusBase
  21. {
  22. public:
  23. friend class GraphicsPath;
  24. friend class Graphics;
  25. Pen(IN const GdiPlusColor& color,
  26. IN REAL width = 1.0f)
  27. {
  28. Unit unit = UnitWorld;
  29. nativePen = NULL;
  30. lastResult = DllExports::GdipCreatePen1(color.GetValue(),
  31. width, unit, &nativePen);
  32. }
  33. Pen(IN const Brush* brush,
  34. IN REAL width = 1.0f)
  35. {
  36. Unit unit = UnitWorld;
  37. nativePen = NULL;
  38. lastResult = DllExports::GdipCreatePen2(brush->nativeBrush,
  39. width, unit, &nativePen);
  40. }
  41. ~Pen()
  42. {
  43. DllExports::GdipDeletePen(nativePen);
  44. }
  45. Pen* Clone() const
  46. {
  47. GpPen *clonePen = NULL;
  48. lastResult = DllExports::GdipClonePen(nativePen, &clonePen);
  49. return new Pen(clonePen, lastResult);
  50. }
  51. Status SetWidth(IN REAL width)
  52. {
  53. return SetStatus(DllExports::GdipSetPenWidth(nativePen, width));
  54. }
  55. REAL GetWidth() const
  56. {
  57. REAL width;
  58. SetStatus(DllExports::GdipGetPenWidth(nativePen, &width));
  59. return width;
  60. }
  61. // Set/get line caps: start, end, and dash
  62. // Line cap and join APIs by using LineCap and LineJoin enums.
  63. Status SetLineCap(IN LineCap startCap,
  64. IN LineCap endCap,
  65. IN DashCap dashCap)
  66. {
  67. return SetStatus(DllExports::GdipSetPenLineCap197819(nativePen,
  68. startCap, endCap, dashCap));
  69. }
  70. Status SetStartCap(IN LineCap startCap)
  71. {
  72. return SetStatus(DllExports::GdipSetPenStartCap(nativePen, startCap));
  73. }
  74. Status SetEndCap(IN LineCap endCap)
  75. {
  76. return SetStatus(DllExports::GdipSetPenEndCap(nativePen, endCap));
  77. }
  78. Status SetDashCap(IN DashCap dashCap)
  79. {
  80. return SetStatus(DllExports::GdipSetPenDashCap197819(nativePen,
  81. dashCap));
  82. }
  83. LineCap GetStartCap() const
  84. {
  85. LineCap startCap;
  86. SetStatus(DllExports::GdipGetPenStartCap(nativePen, &startCap));
  87. return startCap;
  88. }
  89. LineCap GetEndCap() const
  90. {
  91. LineCap endCap;
  92. SetStatus(DllExports::GdipGetPenEndCap(nativePen, &endCap));
  93. return endCap;
  94. }
  95. DashCap GetDashCap() const
  96. {
  97. DashCap dashCap;
  98. SetStatus(DllExports::GdipGetPenDashCap197819(nativePen,
  99. &dashCap));
  100. return dashCap;
  101. }
  102. Status SetLineJoin(IN LineJoin lineJoin)
  103. {
  104. return SetStatus(DllExports::GdipSetPenLineJoin(nativePen, lineJoin));
  105. }
  106. LineJoin GetLineJoin() const
  107. {
  108. LineJoin lineJoin;
  109. SetStatus(DllExports::GdipGetPenLineJoin(nativePen, &lineJoin));
  110. return lineJoin;
  111. }
  112. Status SetCustomStartCap(IN const CustomLineCap* customCap)
  113. {
  114. GpCustomLineCap* nativeCap = NULL;
  115. if(customCap)
  116. nativeCap = customCap->nativeCap;
  117. return SetStatus(DllExports::GdipSetPenCustomStartCap(nativePen,
  118. nativeCap));
  119. }
  120. Status GetCustomStartCap(OUT CustomLineCap* customCap) const
  121. {
  122. if(!customCap)
  123. return SetStatus(InvalidParameter);
  124. return SetStatus(DllExports::GdipGetPenCustomStartCap(nativePen,
  125. &(customCap->nativeCap)));
  126. }
  127. Status SetCustomEndCap(IN const CustomLineCap* customCap)
  128. {
  129. GpCustomLineCap* nativeCap = NULL;
  130. if(customCap)
  131. nativeCap = customCap->nativeCap;
  132. return SetStatus(DllExports::GdipSetPenCustomEndCap(nativePen,
  133. nativeCap));
  134. }
  135. Status GetCustomEndCap(OUT CustomLineCap* customCap) const
  136. {
  137. if(!customCap)
  138. return SetStatus(InvalidParameter);
  139. return SetStatus(DllExports::GdipGetPenCustomEndCap(nativePen,
  140. &(customCap->nativeCap)));
  141. }
  142. Status SetMiterLimit(IN REAL miterLimit)
  143. {
  144. return SetStatus(DllExports::GdipSetPenMiterLimit(nativePen,
  145. miterLimit));
  146. }
  147. REAL GetMiterLimit() const
  148. {
  149. REAL miterLimit;
  150. SetStatus(DllExports::GdipGetPenMiterLimit(nativePen, &miterLimit));
  151. return miterLimit;
  152. }
  153. Status SetAlignment(IN PenAlignment penAlignment)
  154. {
  155. return SetStatus(DllExports::GdipSetPenMode(nativePen, penAlignment));
  156. }
  157. PenAlignment GetAlignment() const
  158. {
  159. PenAlignment penAlignment;
  160. SetStatus(DllExports::GdipGetPenMode(nativePen, &penAlignment));
  161. return penAlignment;
  162. }
  163. Status SetTransform(IN const Matrix* matrix)
  164. {
  165. return SetStatus(DllExports::GdipSetPenTransform(nativePen,
  166. matrix->nativeMatrix));
  167. }
  168. Status GetTransform(OUT Matrix* matrix) const
  169. {
  170. return SetStatus(DllExports::GdipGetPenTransform(nativePen,
  171. matrix->nativeMatrix));
  172. }
  173. Status ResetTransform()
  174. {
  175. return SetStatus(DllExports::GdipResetPenTransform(nativePen));
  176. }
  177. Status MultiplyTransform(IN const Matrix* matrix,
  178. IN MatrixOrder order = MatrixOrderPrepend)
  179. {
  180. return SetStatus(DllExports::GdipMultiplyPenTransform(nativePen,
  181. matrix->nativeMatrix,
  182. order));
  183. }
  184. Status TranslateTransform(IN REAL dx,
  185. IN REAL dy,
  186. IN MatrixOrder order = MatrixOrderPrepend)
  187. {
  188. return SetStatus(DllExports::GdipTranslatePenTransform(nativePen,
  189. dx,
  190. dy,
  191. order));
  192. }
  193. Status ScaleTransform(IN REAL sx,
  194. IN REAL sy,
  195. IN MatrixOrder order = MatrixOrderPrepend)
  196. {
  197. return SetStatus(DllExports::GdipScalePenTransform(nativePen,
  198. sx,
  199. sy,
  200. order));
  201. }
  202. Status RotateTransform(IN REAL angle,
  203. IN MatrixOrder order = MatrixOrderPrepend)
  204. {
  205. return SetStatus(DllExports::GdipRotatePenTransform(nativePen,
  206. angle,
  207. order));
  208. }
  209. PenType GetPenType() const
  210. {
  211. PenType type;
  212. SetStatus(DllExports::GdipGetPenFillType(nativePen, &type));
  213. return type;
  214. }
  215. Status SetColor(IN const GdiPlusColor& color)
  216. {
  217. return SetStatus(DllExports::GdipSetPenColor(nativePen,
  218. color.GetValue()));
  219. }
  220. Status SetBrush(IN const Brush* brush)
  221. {
  222. return SetStatus(DllExports::GdipSetPenBrushFill(nativePen,
  223. brush->nativeBrush));
  224. }
  225. Status GetColor(OUT GdiPlusColor* color) const
  226. {
  227. if (color == NULL)
  228. {
  229. return SetStatus(InvalidParameter);
  230. }
  231. PenType type = GetPenType();
  232. if (type != PenTypeSolidColor)
  233. {
  234. return WrongState;
  235. }
  236. ARGB argb;
  237. SetStatus(DllExports::GdipGetPenColor(nativePen,
  238. &argb));
  239. if (lastResult == Ok)
  240. {
  241. color->SetValue(argb);
  242. }
  243. return lastResult;
  244. }
  245. Brush* GetBrush() const
  246. {
  247. PenType type = GetPenType();
  248. Brush* brush = NULL;
  249. switch(type)
  250. {
  251. case PenTypeSolidColor:
  252. brush = new SolidBrush();
  253. break;
  254. case PenTypeHatchFill:
  255. brush = new HatchBrush();
  256. break;
  257. case PenTypeTextureFill:
  258. brush = new TextureBrush();
  259. break;
  260. case PenTypePathGradient:
  261. brush = new Brush();
  262. break;
  263. case PenTypeLinearGradient:
  264. brush = new LinearGradientBrush();
  265. break;
  266. default:
  267. break;
  268. }
  269. if(brush)
  270. {
  271. GpBrush* nativeBrush;
  272. SetStatus(DllExports::GdipGetPenBrushFill(nativePen,
  273. &nativeBrush));
  274. brush->SetNativeBrush(nativeBrush);
  275. }
  276. return brush;
  277. }
  278. DashStyle GetDashStyle() const
  279. {
  280. DashStyle dashStyle;
  281. SetStatus(DllExports::GdipGetPenDashStyle(nativePen, &dashStyle));
  282. return dashStyle;
  283. }
  284. Status SetDashStyle(IN DashStyle dashStyle)
  285. {
  286. return SetStatus(DllExports::GdipSetPenDashStyle(nativePen,
  287. dashStyle));
  288. }
  289. REAL GetDashOffset() const
  290. {
  291. REAL dashOffset;
  292. SetStatus(DllExports::GdipGetPenDashOffset(nativePen, &dashOffset));
  293. return dashOffset;
  294. }
  295. Status SetDashOffset(IN REAL dashOffset)
  296. {
  297. return SetStatus(DllExports::GdipSetPenDashOffset(nativePen,
  298. dashOffset));
  299. }
  300. Status SetDashPattern(IN const REAL* dashArray, IN INT count)
  301. {
  302. return SetStatus(DllExports::GdipSetPenDashArray(nativePen,
  303. dashArray,
  304. count));
  305. }
  306. INT GetDashPatternCount() const
  307. {
  308. INT count = 0;
  309. SetStatus(DllExports::GdipGetPenDashCount(nativePen, &count));
  310. return count;
  311. }
  312. Status GetDashPattern(OUT REAL* dashArray,
  313. IN INT count) const
  314. {
  315. if (dashArray == NULL || count <= 0)
  316. return SetStatus(InvalidParameter);
  317. return SetStatus(DllExports::GdipGetPenDashArray(nativePen,
  318. dashArray,
  319. count));
  320. }
  321. Status SetCompoundArray(IN const REAL* compoundArray,
  322. IN INT count)
  323. {
  324. return SetStatus(DllExports::GdipSetPenCompoundArray(nativePen,
  325. compoundArray,
  326. count));
  327. }
  328. INT GetCompoundArrayCount() const
  329. {
  330. INT count = 0;
  331. SetStatus(DllExports::GdipGetPenCompoundCount(nativePen, &count));
  332. return count;
  333. }
  334. Status GetCompoundArray(OUT REAL* compoundArray,
  335. IN INT count) const
  336. {
  337. if (compoundArray == NULL || count <= 0)
  338. return SetStatus(InvalidParameter);
  339. return SetStatus(DllExports::GdipGetPenCompoundArray(nativePen,
  340. compoundArray,
  341. count));
  342. }
  343. Status GetLastStatus() const
  344. {
  345. Status lastStatus = lastResult;
  346. lastResult = Ok;
  347. return lastStatus;
  348. }
  349. private:
  350. Pen(const Pen &);
  351. Pen& operator=(const Pen &);
  352. protected:
  353. Pen(GpPen* nativePen, Status status)
  354. {
  355. lastResult = status;
  356. SetNativePen(nativePen);
  357. }
  358. VOID SetNativePen(GpPen* nativePen)
  359. {
  360. this->nativePen = nativePen;
  361. }
  362. Status SetStatus(Status status) const
  363. {
  364. if (status != Ok)
  365. return (lastResult = status);
  366. else
  367. return status;
  368. }
  369. protected:
  370. GpPen* nativePen;
  371. mutable Status lastResult;
  372. };
  373. #endif