gdipluspen.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * gdipluspen.h
  3. *
  4. * GDI+ Pen class
  5. *
  6. * This file is part of the w32api package.
  7. *
  8. * Contributors:
  9. * Created by Markus Koenig <markus@stber-koenig.de>
  10. *
  11. * THIS SOFTWARE IS NOT COPYRIGHTED
  12. *
  13. * This source code is offered for use in the public domain. You may
  14. * use, modify or distribute it freely.
  15. *
  16. * This code is distributed in the hope that it will be useful but
  17. * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  18. * DISCLAIMED. This includes but is not limited to warranties of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. */
  22. #ifndef __GDIPLUS_PEN_H
  23. #define __GDIPLUS_PEN_H
  24. #if __GNUC__ >=3
  25. #pragma GCC system_header
  26. #endif
  27. #ifndef __cplusplus
  28. #error "A C++ compiler is required to include gdipluspen.h."
  29. #endif
  30. class Pen: public GdiplusBase
  31. {
  32. friend class Graphics;
  33. friend class GraphicsPath;
  34. public:
  35. Pen(const Color& color, REAL width = 1.0f):
  36. nativePen(NULL), lastStatus(Ok)
  37. {
  38. lastStatus = DllExports::GdipCreatePen1(
  39. color.GetValue(), width, UnitWorld,
  40. &nativePen);
  41. }
  42. Pen(const Brush *brush, REAL width = 1.0f):
  43. nativePen(NULL), lastStatus(Ok)
  44. {
  45. lastStatus = DllExports::GdipCreatePen2(
  46. brush ? brush->nativeBrush : NULL,
  47. width, UnitWorld, &nativePen);
  48. }
  49. ~Pen()
  50. {
  51. DllExports::GdipDeletePen(nativePen);
  52. }
  53. Pen* Clone() const
  54. {
  55. GpPen *clonePen = NULL;
  56. Status status = updateStatus(DllExports::GdipClonePen(
  57. nativePen, &clonePen));
  58. if (status == Ok) {
  59. Pen *result = new Pen(clonePen, lastStatus);
  60. if (!result) {
  61. DllExports::GdipDeletePen(clonePen);
  62. lastStatus = OutOfMemory;
  63. }
  64. return result;
  65. } else {
  66. return NULL;
  67. }
  68. }
  69. PenAlignment GetAlignment() const
  70. {
  71. PenAlignment result = PenAlignmentCenter;
  72. updateStatus(DllExports::GdipGetPenMode(nativePen, &result));
  73. return result;
  74. }
  75. // TODO: implement Pen::GetBrush()
  76. //Brush *GetBrush() const
  77. //{
  78. // // where is the pen brush allocated (static,member,new,other)?
  79. // // GdipGetPenBrushFill just returns a GpBrush*
  80. // updateStatus(NotImplemented);
  81. // return NULL;
  82. //}
  83. Status GetColor(Color *color) const
  84. {
  85. return updateStatus(DllExports::GdipGetPenColor(
  86. nativePen, color ? &color->Value : NULL));
  87. }
  88. Status GetCompoundArray(REAL *compoundArray, INT count) const
  89. {
  90. return updateStatus(DllExports::GdipGetPenCompoundArray(
  91. nativePen, compoundArray, count));
  92. }
  93. INT GetCompoundArrayCount() const
  94. {
  95. INT result = 0;
  96. updateStatus(DllExports::GdipGetPenCompoundCount(
  97. nativePen, &result));
  98. return result;
  99. }
  100. Status GetCustomEndCap(CustomLineCap *customCap) const
  101. {
  102. if (!customCap) return lastStatus = InvalidParameter;
  103. // FIXME: do we need to call GdipDeleteCustomLineCap first?
  104. return updateStatus(DllExports::GdipGetPenCustomEndCap(
  105. nativePen, &customCap->nativeCustomLineCap));
  106. }
  107. Status GetCustomStartCap(CustomLineCap *customCap) const
  108. {
  109. if (!customCap) return lastStatus = InvalidParameter;
  110. // FIXME: do we need to call GdipDeleteCustomLineCap first?
  111. return updateStatus(DllExports::GdipGetPenCustomStartCap(
  112. nativePen, &customCap->nativeCustomLineCap));
  113. }
  114. DashCap GetDashCap() const
  115. {
  116. DashCap result = DashCapFlat;
  117. updateStatus(DllExports::GdipGetPenDashCap197819(
  118. nativePen, &result));
  119. return result;
  120. }
  121. REAL GetDashOffset() const
  122. {
  123. REAL result = 0.0f;
  124. updateStatus(DllExports::GdipGetPenDashOffset(
  125. nativePen, &result));
  126. return result;
  127. }
  128. Status GetDashPattern(REAL *dashArray, INT count) const
  129. {
  130. return updateStatus(DllExports::GdipGetPenDashArray(
  131. nativePen, dashArray, count));
  132. }
  133. INT GetDashPatternCount() const
  134. {
  135. INT result = 0;
  136. updateStatus(DllExports::GdipGetPenDashCount(
  137. nativePen, &result));
  138. return result;
  139. }
  140. DashStyle GetDashStyle() const
  141. {
  142. DashStyle result = DashStyleSolid;
  143. updateStatus(DllExports::GdipGetPenDashStyle(
  144. nativePen, &result));
  145. return result;
  146. }
  147. LineCap GetEndCap() const
  148. {
  149. LineCap result = LineCapFlat;
  150. updateStatus(DllExports::GdipGetPenEndCap(nativePen, &result));
  151. return result;
  152. }
  153. Status GetLastStatus() const
  154. {
  155. Status result = lastStatus;
  156. lastStatus = Ok;
  157. return result;
  158. }
  159. LineJoin GetLineJoin() const
  160. {
  161. LineJoin result = LineJoinMiter;
  162. updateStatus(DllExports::GdipGetPenLineJoin(
  163. nativePen, &result));
  164. return result;
  165. }
  166. REAL GetMiterLimit() const
  167. {
  168. REAL result = 10.0f;
  169. updateStatus(DllExports::GdipGetPenMiterLimit(
  170. nativePen, &result));
  171. return result;
  172. }
  173. PenType GetPenType() const
  174. {
  175. PenType result = PenTypeUnknown;
  176. updateStatus(DllExports::GdipGetPenFillType(
  177. nativePen, &result));
  178. return result;
  179. }
  180. LineCap GetStartCap() const
  181. {
  182. LineCap result = LineCapFlat;
  183. updateStatus(DllExports::GdipGetPenStartCap(
  184. nativePen, &result));
  185. return result;
  186. }
  187. Status GetTransform(Matrix *matrix) const
  188. {
  189. return updateStatus(DllExports::GdipGetPenTransform(
  190. nativePen,
  191. matrix ? matrix->nativeMatrix : NULL));
  192. }
  193. REAL GetWidth() const
  194. {
  195. REAL result = 1.0f;
  196. updateStatus(DllExports::GdipGetPenWidth(nativePen, &result));
  197. return result;
  198. }
  199. Status MultiplyTransform(const Matrix *matrix,
  200. MatrixOrder order = MatrixOrderPrepend)
  201. {
  202. return updateStatus(DllExports::GdipMultiplyPenTransform(
  203. nativePen,
  204. matrix ? matrix->nativeMatrix : NULL, order));
  205. }
  206. Status ResetTransform()
  207. {
  208. return updateStatus(DllExports::GdipResetPenTransform(
  209. nativePen));
  210. }
  211. Status RotateTransform(REAL angle,
  212. MatrixOrder order = MatrixOrderPrepend)
  213. {
  214. return updateStatus(DllExports::GdipRotatePenTransform(
  215. nativePen, angle, order));
  216. }
  217. Status ScaleTransform(REAL sx, REAL sy,
  218. MatrixOrder order = MatrixOrderPrepend)
  219. {
  220. return updateStatus(DllExports::GdipScalePenTransform(
  221. nativePen, sx, sy, order));
  222. }
  223. Status SetAlignment(PenAlignment penAlignment)
  224. {
  225. return updateStatus(DllExports::GdipSetPenMode(
  226. nativePen, penAlignment));
  227. }
  228. Status SetBrush(const Brush *brush)
  229. {
  230. return updateStatus(DllExports::GdipSetPenBrushFill(
  231. nativePen, brush ? brush->nativeBrush : NULL));
  232. }
  233. Status SetColor(const Color& color)
  234. {
  235. return updateStatus(DllExports::GdipSetPenColor(
  236. nativePen, color.GetValue()));
  237. }
  238. Status SetCompoundArray(const REAL *compoundArray, INT count)
  239. {
  240. return updateStatus(DllExports::GdipSetPenCompoundArray(
  241. nativePen, compoundArray, count));
  242. }
  243. Status SetCustomEndCap(const CustomLineCap *customCap)
  244. {
  245. return updateStatus(DllExports::GdipSetPenCustomEndCap(
  246. nativePen,
  247. customCap ? customCap->nativeCustomLineCap : NULL));
  248. }
  249. Status SetCustomStartCap(const CustomLineCap *customCap)
  250. {
  251. return updateStatus(DllExports::GdipSetPenCustomStartCap(
  252. nativePen,
  253. customCap ? customCap->nativeCustomLineCap : NULL));
  254. }
  255. Status SetDashCap(DashCap dashCap)
  256. {
  257. return updateStatus(DllExports::GdipSetPenDashCap197819(
  258. nativePen, dashCap));
  259. }
  260. Status SetDashOffset(REAL dashOffset)
  261. {
  262. return updateStatus(DllExports::GdipSetPenDashOffset(
  263. nativePen, dashOffset));
  264. }
  265. Status SetDashPattern(const REAL *dashArray, INT count)
  266. {
  267. return updateStatus(DllExports::GdipSetPenDashArray(
  268. nativePen, dashArray, count));
  269. }
  270. Status SetDashStyle(DashStyle dashStyle)
  271. {
  272. return updateStatus(DllExports::GdipSetPenDashStyle(
  273. nativePen, dashStyle));
  274. }
  275. Status SetEndCap(LineCap endCap)
  276. {
  277. return updateStatus(DllExports::GdipSetPenEndCap(
  278. nativePen, endCap));
  279. }
  280. Status SetLineCap(LineCap startCap, LineCap endCap, DashCap dashCap)
  281. {
  282. return updateStatus(DllExports::GdipSetPenLineCap197819(
  283. nativePen, startCap, endCap, dashCap));
  284. }
  285. Status SetLineJoin(LineJoin lineJoin)
  286. {
  287. return updateStatus(DllExports::GdipSetPenLineJoin(
  288. nativePen, lineJoin));
  289. }
  290. Status SetMiterLimit(REAL miterLimit)
  291. {
  292. return updateStatus(DllExports::GdipSetPenMiterLimit(
  293. nativePen, miterLimit));
  294. }
  295. Status SetStartCap(LineCap startCap)
  296. {
  297. return updateStatus(DllExports::GdipSetPenStartCap(
  298. nativePen, startCap));
  299. }
  300. Status SetTransform(const Matrix *matrix)
  301. {
  302. return updateStatus(DllExports::GdipSetPenTransform(
  303. nativePen,
  304. matrix ? matrix->nativeMatrix : NULL));
  305. }
  306. Status SetWidth(REAL width)
  307. {
  308. return updateStatus(DllExports::GdipSetPenWidth(
  309. nativePen, width));
  310. }
  311. Status TranslateTransform(REAL dx, REAL dy,
  312. MatrixOrder order = MatrixOrderPrepend)
  313. {
  314. return updateStatus(DllExports::GdipTranslatePenTransform(
  315. nativePen, dx, dy, order));
  316. }
  317. private:
  318. Pen(GpPen *pen, Status status): nativePen(pen), lastStatus(status) {}
  319. Pen(const Pen& pen);
  320. Pen& operator=(const Pen&);
  321. Status updateStatus(Status newStatus) const
  322. {
  323. if (newStatus != Ok) lastStatus = newStatus;
  324. return newStatus;
  325. }
  326. GpPen *nativePen;
  327. mutable Status lastStatus;
  328. };
  329. #endif /* __GDIPLUS_PEN_H */