1 /* 2 * GdiPlusPen.h 3 * 4 * Windows GDI+ 5 * 6 * This file is part of the w32api package. 7 * 8 * THIS SOFTWARE IS NOT COPYRIGHTED 9 * 10 * This source code is offered for use in the public domain. You may 11 * use, modify or distribute it freely. 12 * 13 * This code is distributed in the hope that it will be useful but 14 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY 15 * DISCLAIMED. This includes but is not limited to warranties of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 */ 18 19 #ifndef _GDIPLUSPEN_H 20 #define _GDIPLUSPEN_H 21 22 class Pen : public GdiplusBase 23 { 24 public: 25 friend class Graphics; 26 friend class GraphicsPath; 27 nativePen(NULL)28 Pen(const Brush *brush, REAL width = 1.0f) : nativePen(NULL) 29 { 30 lastStatus = DllExports::GdipCreatePen2(getNat(brush), width, UnitWorld, &nativePen); 31 } 32 nativePen(NULL)33 Pen(const Color &color, REAL width = 1.0f) : nativePen(NULL) 34 { 35 lastStatus = DllExports::GdipCreatePen1(color.GetValue(), width, UnitWorld, &nativePen); 36 } 37 ~Pen()38 ~Pen() 39 { 40 DllExports::GdipDeletePen(nativePen); 41 } 42 43 Pen * Clone()44 Clone() 45 { 46 GpPen *clonePen = NULL; 47 SetStatus(DllExports::GdipClonePen(nativePen, &clonePen)); 48 if (lastStatus != Ok) 49 return NULL; 50 Pen *newPen = new Pen(clonePen, lastStatus); 51 if (!newPen) 52 DllExports::GdipDeletePen(clonePen); 53 return newPen; 54 } 55 56 PenAlignment GetAlignment()57 GetAlignment() 58 { 59 PenAlignment penAlignment; 60 SetStatus(DllExports::GdipGetPenMode(nativePen, &penAlignment)); 61 return penAlignment; 62 } 63 64 Brush * GetBrush()65 GetBrush() 66 { 67 // FIXME 68 return NULL; 69 } 70 71 Status GetColor(Color * color)72 GetColor(Color *color) 73 { 74 if (!color) 75 return SetStatus(InvalidParameter); 76 77 ARGB argb; 78 SetStatus(DllExports::GdipGetPenColor(nativePen, &argb)); 79 color->SetValue(argb); 80 return lastStatus; 81 } 82 83 Status GetCompoundArray(REAL * compoundArray,INT count)84 GetCompoundArray(REAL *compoundArray, INT count) 85 { 86 if (!compoundArray || count <= 0) 87 return SetStatus(InvalidParameter); 88 #if 1 89 return SetStatus(NotImplemented); 90 #else 91 return SetStatus(DllExports::GdipGetPenCompoundArray(nativePen, compoundArray, count)); 92 #endif 93 } 94 95 INT GetCompoundArrayCount()96 GetCompoundArrayCount() 97 { 98 INT count = 0; 99 SetStatus(DllExports::GdipGetPenCompoundCount(nativePen, &count)); 100 return count; 101 } 102 103 Status GetCustomEndCap(CustomLineCap * customCap)104 GetCustomEndCap(CustomLineCap *customCap) 105 { 106 if (!customCap) 107 return SetStatus(InvalidParameter); 108 109 return SetStatus(DllExports::GdipGetPenCustomEndCap(nativePen, &getNat(customCap))); 110 } 111 112 Status GetCustomStartCap(CustomLineCap * customCap)113 GetCustomStartCap(CustomLineCap *customCap) 114 { 115 if (!customCap) 116 return SetStatus(InvalidParameter); 117 118 return SetStatus(DllExports::GdipGetPenCustomStartCap(nativePen, &getNat(customCap))); 119 } 120 121 DashCap GetDashCap()122 GetDashCap() 123 { 124 DashCap dashCap; 125 SetStatus(DllExports::GdipGetPenDashCap197819(nativePen, &dashCap)); 126 return dashCap; 127 } 128 129 REAL GetDashOffset()130 GetDashOffset() 131 { 132 REAL offset; 133 SetStatus(DllExports::GdipGetPenDashOffset(nativePen, &offset)); 134 return offset; 135 } 136 137 Status GetDashPattern(REAL * dashArray,INT count)138 GetDashPattern(REAL *dashArray, INT count) 139 { 140 if (dashArray == NULL || count <= 0) 141 return SetStatus(InvalidParameter); 142 143 return SetStatus(DllExports::GdipGetPenDashArray(nativePen, dashArray, count)); 144 } 145 146 INT GetDashPatternCount()147 GetDashPatternCount() 148 { 149 INT count = 0; 150 SetStatus(DllExports::GdipGetPenDashCount(nativePen, &count)); 151 return count; 152 } 153 154 DashStyle GetDashStyle()155 GetDashStyle() 156 { 157 DashStyle dashStyle; 158 SetStatus(DllExports::GdipGetPenDashStyle(nativePen, &dashStyle)); 159 return dashStyle; 160 } 161 162 LineCap GetEndCap()163 GetEndCap() 164 { 165 LineCap endCap; 166 SetStatus(DllExports::GdipGetPenEndCap(nativePen, &endCap)); 167 return endCap; 168 } 169 170 Status GetLastStatus()171 GetLastStatus() const 172 { 173 return lastStatus; 174 } 175 176 LineJoin GetLineJoin()177 GetLineJoin() 178 { 179 LineJoin lineJoin; 180 SetStatus(DllExports::GdipGetPenLineJoin(nativePen, &lineJoin)); 181 return lineJoin; 182 } 183 184 REAL GetMiterLimit()185 GetMiterLimit() 186 { 187 REAL miterLimit; 188 SetStatus(DllExports::GdipGetPenMiterLimit(nativePen, &miterLimit)); 189 return miterLimit; 190 } 191 192 PenType GetPenType()193 GetPenType() 194 { 195 PenType type; 196 SetStatus(DllExports::GdipGetPenFillType(nativePen, &type)); 197 return type; 198 } 199 200 LineCap GetStartCap()201 GetStartCap() 202 { 203 LineCap startCap; 204 SetStatus(DllExports::GdipGetPenStartCap(nativePen, &startCap)); 205 return startCap; 206 } 207 208 Status GetTransform(Matrix * matrix)209 GetTransform(Matrix *matrix) 210 { 211 return SetStatus(DllExports::GdipGetPenTransform(nativePen, getNat(matrix))); 212 } 213 214 REAL GetWidth()215 GetWidth() 216 { 217 REAL width; 218 SetStatus(DllExports::GdipGetPenWidth(nativePen, &width)); 219 return width; 220 } 221 222 Status 223 MultiplyTransform(Matrix *matrix, MatrixOrder order = MatrixOrderPrepend) 224 { 225 return SetStatus(DllExports::GdipMultiplyPenTransform(nativePen, getNat(matrix), order)); 226 } 227 228 Status ResetTransform()229 ResetTransform() 230 { 231 return SetStatus(DllExports::GdipResetPenTransform(nativePen)); 232 } 233 234 Status 235 RotateTransform(REAL angle, MatrixOrder order = MatrixOrderPrepend) 236 { 237 return SetStatus(DllExports::GdipRotatePenTransform(nativePen, angle, order)); 238 } 239 240 Status 241 ScaleTransform(REAL sx, REAL sy, MatrixOrder order = MatrixOrderPrepend) 242 { 243 return SetStatus(DllExports::GdipScalePenTransform(nativePen, sx, sy, order)); 244 } 245 246 Status SetAlignment(PenAlignment penAlignment)247 SetAlignment(PenAlignment penAlignment) 248 { 249 return SetStatus(DllExports::GdipSetPenMode(nativePen, penAlignment)); 250 } 251 252 Status SetBrush(const Brush * brush)253 SetBrush(const Brush *brush) 254 { 255 GpBrush *theBrush = brush ? getNat(brush) : NULL; 256 return SetStatus(DllExports::GdipSetPenBrushFill(nativePen, theBrush)); 257 } 258 259 Status SetColor(const Color & color)260 SetColor(const Color &color) 261 { 262 return SetStatus(DllExports::GdipSetPenColor(nativePen, color.GetValue())); 263 } 264 265 Status SetCompoundArray(const REAL * compoundArray,INT count)266 SetCompoundArray(const REAL *compoundArray, INT count) 267 { 268 return SetStatus(DllExports::GdipSetPenCompoundArray(nativePen, compoundArray, count)); 269 } 270 271 Status SetCustomEndCap(const CustomLineCap * customCap)272 SetCustomEndCap(const CustomLineCap *customCap) 273 { 274 GpCustomLineCap *cap = customCap ? getNat(customCap) : NULL; 275 return SetStatus(DllExports::GdipSetPenCustomEndCap(nativePen, cap)); 276 } 277 278 Status SetCustomStartCap(const CustomLineCap * customCap)279 SetCustomStartCap(const CustomLineCap *customCap) 280 { 281 GpCustomLineCap *cap = customCap ? getNat(customCap) : NULL; 282 return SetStatus(DllExports::GdipSetPenCustomStartCap(nativePen, cap)); 283 } 284 285 Status SetDashCap(DashCap dashCap)286 SetDashCap(DashCap dashCap) 287 { 288 return SetStatus(DllExports::GdipSetPenDashCap197819(nativePen, dashCap)); 289 } 290 291 Status SetDashOffset(REAL dashOffset)292 SetDashOffset(REAL dashOffset) 293 { 294 return SetStatus(DllExports::GdipSetPenDashOffset(nativePen, dashOffset)); 295 } 296 297 Status SetDashPattern(const REAL * dashArray,INT count)298 SetDashPattern(const REAL *dashArray, INT count) 299 { 300 return SetStatus(DllExports::GdipSetPenDashArray(nativePen, dashArray, count)); 301 } 302 303 Status SetDashStyle(DashStyle dashStyle)304 SetDashStyle(DashStyle dashStyle) 305 { 306 return SetStatus(DllExports::GdipSetPenDashStyle(nativePen, dashStyle)); 307 } 308 309 Status SetEndCap(LineCap endCap)310 SetEndCap(LineCap endCap) 311 { 312 return SetStatus(DllExports::GdipSetPenEndCap(nativePen, endCap)); 313 } 314 315 Status SetLineCap(LineCap startCap,LineCap endCap,DashCap dashCap)316 SetLineCap(LineCap startCap, LineCap endCap, DashCap dashCap) 317 { 318 return SetStatus(DllExports::GdipSetPenLineCap197819(nativePen, startCap, endCap, dashCap)); 319 } 320 321 Status SetLineJoin(LineJoin lineJoin)322 SetLineJoin(LineJoin lineJoin) 323 { 324 return SetStatus(DllExports::GdipSetPenLineJoin(nativePen, lineJoin)); 325 } 326 327 Status SetMiterLimit(REAL miterLimit)328 SetMiterLimit(REAL miterLimit) 329 { 330 return SetStatus(DllExports::GdipSetPenMiterLimit(nativePen, miterLimit)); 331 } 332 333 Status SetStartCap(LineCap startCap)334 SetStartCap(LineCap startCap) 335 { 336 return SetStatus(DllExports::GdipSetPenStartCap(nativePen, startCap)); 337 } 338 339 Status SetTransform(const Matrix * matrix)340 SetTransform(const Matrix *matrix) 341 { 342 GpMatrix *mat = matrix ? getNat(matrix) : NULL; 343 return SetStatus(DllExports::GdipSetPenTransform(nativePen, mat)); 344 } 345 346 Status SetWidth(REAL width)347 SetWidth(REAL width) 348 { 349 return SetStatus(DllExports::GdipSetPenWidth(nativePen, width)); 350 } 351 352 Status 353 TranslateTransform(REAL dx, REAL dy, MatrixOrder order = MatrixOrderPrepend) 354 { 355 return SetStatus(DllExports::GdipTranslatePenTransform(nativePen, dx, dy, order)); 356 } 357 358 protected: 359 GpPen *nativePen; 360 mutable Status lastStatus; 361 362 Status SetStatus(Status status)363 SetStatus(Status status) const 364 { 365 if (status != Ok) 366 lastStatus = status; 367 return status; 368 } 369 Pen(GpPen * pen,Status status)370 Pen(GpPen *pen, Status status) : nativePen(pen), lastStatus(status) 371 { 372 } 373 374 VOID SetNativePen(GpPen * pen)375 SetNativePen(GpPen *pen) 376 { 377 nativePen = pen; 378 } 379 380 private: 381 // Pen is not copyable 382 Pen(const Pen &); 383 Pen & 384 operator=(const Pen &); 385 386 // get native 387 friend inline GpPen *& getNat(const Pen * pen)388 getNat(const Pen *pen) 389 { 390 return const_cast<Pen *>(pen)->nativePen; 391 } 392 }; 393 394 #endif /* _GDIPLUSPEN_H */ 395