Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

GdiplusPen.h 13 KiB

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