1
2
3
4
5
6 using System;
7 using System.Collections;
8 using System.Windows.API;
9
10 namespace System.Windows
11 {
12 public enum GraphicsStatus : int
13 {
14 ok = 0,
15 genericError = 1,
16 invalidParameter = 2,
17 outOfMemory = 3,
18 objectBusy = 4,
19 insufficientBuffer = 5,
20 notImplemented = 6,
21 win32Error = 7,
22 wrongState = 8,
23 aborted = 9,
24 fileNotFound = 10,
25 valueOverflow = 11,
26 accessDenied = 12,
27 unknownImageFormat = 13,
28 fontFamilyNotFound = 14,
29 fontStyleNotFound = 15,
30 notTrueTypeFont = 16,
31 unsupportedGdiplusVersion = 17,
32 gdiplusNotInitialized = 18,
33 propertyNotFound = 19,
34 propertyNotSupported = 20,
35 profileNotFound = 21
36 }
37
38 public string GraphicsStatusStr(GraphicsStatus status)
39 {
40 switch (status)
41 {
42 case GraphicsStatus.ok: return "ok";
43 case GraphicsStatus.genericError: return "generic error";
44 case GraphicsStatus.invalidParameter: return "invalid parameter";
45 case GraphicsStatus.outOfMemory: return "out of memory";
46 case GraphicsStatus.objectBusy: return "object busy";
47 case GraphicsStatus.insufficientBuffer: return "insufficient buffer";
48 case GraphicsStatus.notImplemented: return "not implemented";
49 case GraphicsStatus.win32Error: return "WIN32 error";
50 case GraphicsStatus.wrongState: return "wrong state";
51 case GraphicsStatus.aborted: return "aborted";
52 case GraphicsStatus.fileNotFound: return "file not found";
53 case GraphicsStatus.valueOverflow: return "value overflow";
54 case GraphicsStatus.accessDenied: return "access denied";
55 case GraphicsStatus.unknownImageFormat: return "unknown image format";
56 case GraphicsStatus.fontFamilyNotFound: return "font family not found";
57 case GraphicsStatus.fontStyleNotFound: return "font style not found";
58 case GraphicsStatus.notTrueTypeFont: return "not True Type font";
59 case GraphicsStatus.unsupportedGdiplusVersion: return "unsupported GDI+ version";
60 case GraphicsStatus.gdiplusNotInitialized: return "GDI+ not initialized";
61 case GraphicsStatus.propertyNotFound: return "property not found";
62 case GraphicsStatus.propertyNotSupported: return "property not supported";
63 case GraphicsStatus.profileNotFound: return "profile not found";
64 }
65 return "graphics error";
66 }
67
68 public void CheckGraphicsStatus(GraphicsStatus status)
69 {
70 if (status != GraphicsStatus.ok)
71 {
72 throw Exception("GDI+ error: " + GraphicsStatusStr(status));
73 }
74 }
75
76 public class Point
77 {
78 public nothrow Point() : x(0), y(0)
79 {
80 }
81 public nothrow Point(int x_, int y_) : x(x_), y(y_)
82 {
83 }
84 public default nothrow Point(const Point&);
85 public default nothrow void operator=(const Point&);
86 public static nothrow Point Default()
87 {
88 return Point(CW_USEDEFAULT, CW_USEDEFAULT);
89 }
90 public nothrow string ToString() const
91 {
92 return "(" + ToString(x) + ", " + ToString(y) + ")";
93 }
94 public inline nothrow void Offset(int dx, int dy)
95 {
96 x = x + dx;
97 y = y + dy;
98 }
99 public int x;
100 public int y;
101 }
102
103 public inline nothrow bool operator==(const Point& left, const Point& right)
104 {
105 return left.x == right.x && left.y == right.y;
106 }
107
108 public class Size
109 {
110 public nothrow Size() : h(0), w(0)
111 {
112 }
113 public nothrow Size(int w_, int h_) : w(w_), h(h_)
114 {
115 }
116 public default nothrow Size(const Size&);
117 public default nothrow void operator=(const Size&);
118 public static nothrow Size Default()
119 {
120 return Size(CW_USEDEFAULT, CW_USEDEFAULT);
121 }
122 public nothrow string ToString() const
123 {
124 return "(" + ToString(w) + ", " + ToString(h) + ")";
125 }
126 public int w;
127 public int h;
128 }
129
130 public inline nothrow bool operator==(const Size& left, const Size& right)
131 {
132 return left.w == right.w && left.h == right.h;
133 }
134
135 public class PointF
136 {
137 public nothrow PointF() : x(0.0f), y(0.0f)
138 {
139 }
140 public nothrow PointF(float x_, float y_) : x(x_), y(y_)
141 {
142 }
143 public nothrow string ToString() const
144 {
145 return "(" + ToString(x) + ", " + ToString(y) + ")";
146 }
147 public inline nothrow void Offset(float dx, float dy)
148 {
149 x = x + dx;
150 y = y + dy;
151 }
152 public float x;
153 public float y;
154 }
155
156 public inline nothrow bool operator==(const PointF& left, const PointF& right)
157 {
158 return left.x == right.x && left.y == right.y;
159 }
160
161 public nothrow float Distance(const PointF& start, const PointF& end)
162 {
163 float dx = Abs(start.x - end.x);
164 float dy = Abs(start.y - end.y);
165 float distance = cast<float>(Sqrt(dx * dx + dy * dy));
166 return distance;
167 }
168
169 public class Vector
170 {
171 public nothrow Vector() : x(0), y(0)
172 {
173 }
174 public nothrow Vector(float x_, float y_) : x(x_), y(y_)
175 {
176 }
177 public explicit nothrow Vector(const PointF& point) : x(point.x), y(point.y)
178 {
179 }
180 public nothrow float Length() const
181 {
182 return cast<float>(Sqrt(x * x + y * y));
183 }
184 public nothrow PointF ToPoint() const
185 {
186 return PointF(x, y);
187 }
188 public float x;
189 public float y;
190 }
191
192 public inline nothrow bool operator==(const Vector& v, const Vector& u)
193 {
194 return v.x == u.x && v.y == u.y;
195 }
196
197 public nothrow Vector operator*(const Vector& v, float a)
198 {
199 return Vector(v.x * a, v.y * a);
200 }
201
202 public nothrow Vector operator*(float a, const Vector& v)
203 {
204 return Vector(v.x * a, v.y * a);
205 }
206
207 public nothrow Vector operator+(const Vector& left, const Vector& right)
208 {
209 return Vector(left.x + right.x, left.y + right.y);
210 }
211
212 public nothrow Vector operator-(const Vector& left, const Vector& right)
213 {
214 return Vector(left.x - right.x, left.y - right.y);
215 }
216
217 public nothrow Vector UnitVector(const Vector& v)
218 {
219 float length = v.Length();
220 return v * (1 / length);
221 }
222
223
224
225 public nothrow float Dot(const Vector& u, const Vector& v)
226 {
227 return u.x * v.x + u.y * v.y;
228 }
229
230 public nothrow float ProjectionFactor(const Vector& a, const Vector& b)
231 {
232 return Dot(a, b * (1 / b.Length()));
233 }
234
235
236
237 public nothrow Vector Projection(const Vector& a, const Vector& b)
238 {
239 return UnitVector(b) * ProjectionFactor(a, b);
240 }
241
242
243
244
245
246
247
248
249 public nothrow int MainDirection(const Vector& v)
250 {
251 if (v.x >= 0)
252 {
253 if (v.y >= 0)
254 {
255 Vector u(1, -1);
256 if (Dot(v, u) >= 0)
257 {
258 return 0;
259 }
260 else
261 {
262 return 90;
263 }
264 }
265 else
266 {
267 Vector u(-1, -1);
268 if (Dot(v, u) >= 0)
269 {
270 return 270;
271 }
272 else
273 {
274 return 0;
275 }
276 }
277 }
278 else
279 {
280 if (v.y >= 0)
281 {
282 Vector u(1, 1);
283 if (Dot(v, u) >= 0)
284 {
285 return 90;
286 }
287 else
288 {
289 return 180;
290 }
291 }
292 else
293 {
294 Vector u(-1, 1);
295 if (Dot(v, u) >= 0)
296 {
297 return 180;
298 }
299 else
300 {
301 return 270;
302 }
303 }
304 }
305 }
306
307 public nothrow Vector Rotate(const Vector& v, double angleRad)
308 {
309 double cosTheta = Cos(angleRad);
310 double sinTheta = Sin(angleRad);
311 Vector r(cast<float>(v.x * cosTheta - v.y * sinTheta), cast<float>(v.x * sinTheta + v.y * cosTheta));
312 return r;
313 }
314
315 public class Line
316 {
317 public nothrow Line() : start(), end()
318 {
319 }
320 public nothrow Line(const PointF& start_, const PointF& end_) : start(start_), end(end_)
321 {
322 }
323 public nothrow Line(const PointF& start_, const Vector& v) : start(start_), end(Vector(Vector(start) + v).ToPoint())
324 {
325 }
326 public nothrow float Length() const
327 {
328 return Distance(start, end);
329 }
330 public nothrow Vector ToVector() const
331 {
332 return Vector(end.x - start.x, end.y - start.y);
333 }
334 public PointF start;
335 public PointF end;
336 }
337
338 public inline nothrow bool operator==(const Line& left, const Line& right)
339 {
340 return left.start == right.start && left.end == right.end;
341 }
342
343 public nothrow Line Rotate(const Line& line, float angleDeg)
344 {
345 double angleRad = PI() / 180.0 * angleDeg;
346 Vector v = line.ToVector();
347 Vector r = Rotate(v, angleRad);
348 Line result(line.start, r);
349 return result;
350 }
351
352 public class SizeF
353 {
354 public nothrow SizeF() : w(0.0f), h(0.0f)
355 {
356 }
357 public nothrow SizeF(float w_, float h_) : w(w_), h(h_)
358 {
359 }
360 public nothrow string ToString() const
361 {
362 return "(" + ToString(w) + ", " + ToString(h) + ")";
363 }
364 public float w;
365 public float h;
366 }
367
368 public inline nothrow bool operator==(const SizeF& left, const SizeF& right)
369 {
370 return left.w == right.w && left.h == right.h;
371 }
372
373 public class Rect
374 {
375 public nothrow Rect() : location(), size()
376 {
377 }
378 public nothrow Rect(const Point& location_, const Size& size_) : location(location_), size(size_)
379 {
380 }
381 public nothrow Rect(const WinRect& winRect) : location(winRect.left, winRect.top), size(winRect.right - winRect.left, winRect.bottom - winRect.top)
382 {
383 }
384 public nothrow WinRect ToWinRect() const
385 {
386 return WinRect(location.x, location.y, location.x + size.w, location.y + size.h);
387 }
388 public inline nothrow bool IsEmpty() const
389 {
390 return size.w == 0 && size.h == 0;
391 }
392 public inline nothrow int Left() const
393 {
394 return location.x;
395 }
396 public inline nothrow int Right() const
397 {
398 return location.x + size.w;
399 }
400 public inline nothrow int Top() const
401 {
402 return location.y;
403 }
404 public inline nothrow int Bottom() const
405 {
406 return location.y + size.h;
407 }
408 public inline nothrow bool Contains(const Point& p)
409 {
410 return p.x >= location.x && p.x < location.x + size.w && p.y >= location.y && p.y < location.y + size.h;
411 }
412 public inline nothrow void Inflate(int dx, int dy)
413 {
414 location.x = location.x - dx;
415 location.y = location.y - dy;
416 size.w = size.w + 2 * dx;
417 size.h = size.h + 2 * dy;
418 }
419 public inline nothrow void Offset(int dx, int dy)
420 {
421 location.Offset(dx, dy);
422 }
423 public nothrow bool IntersectsWith(const Rect& that) const
424 {
425 return Left() < that.Right() && Top() < that.Bottom() && Right() > that.Left() && Bottom() > that.Top();
426 }
427 public static nothrow Rect Union(const Rect& a, const Rect& b)
428 {
429 int right = Max(a.Right(), b.Right());
430 int bottom = Max(a.Bottom(), b.Bottom());
431 int left = Min(a.Left(), b.Left());
432 int top = Min(a.Top(), b.Top());
433 return Rect(Point(left, top), Size(right - left, bottom - top));
434 }
435 public nothrow string ToString() const
436 {
437 return "(" + ToString(location.x) + ", " + ToString(location.y) + ", " + ToString(size.w) + ", " + ToString(size.h) + ")";
438 }
439 public Point location;
440 public Size size;
441 }
442
443 public inline nothrow bool operator==(const Rect& left, const Rect& right)
444 {
445 return left.location == right.location && left.size == right.size;
446 }
447
448 public class RectF
449 {
450 public nothrow RectF() : location(), size()
451 {
452 }
453 public nothrow RectF(const PointF& location_, const SizeF& size_) : location(location_), size(size_)
454 {
455 }
456 public inline nothrow float Left() const
457 {
458 return location.x;
459 }
460 public inline nothrow float Right() const
461 {
462 return location.x + size.w;
463 }
464 public inline nothrow float Top() const
465 {
466 return location.y;
467 }
468 public inline nothrow float Bottom() const
469 {
470 return location.y + size.h;
471 }
472 public nothrow string ToString() const
473 {
474 return "(" + ToString(location.x) + ", " + ToString(location.y) + ", " + ToString(size.w) + ", " + ToString(size.h) + ")";
475 }
476 public inline nothrow bool IsEmpty() const
477 {
478 return size.w == 0 && size.h == 0;
479 }
480 public inline nothrow bool Contains(const PointF& p)
481 {
482 return p.x >= location.x && p.x < location.x + size.w && p.y >= location.y && p.y < location.y + size.h;
483 }
484 public inline nothrow void Inflate(float dx, float dy)
485 {
486 location.x = location.x - dx;
487 location.y = location.y - dy;
488 size.w = size.w + 2 * dx;
489 size.h = size.h + 2 * dy;
490 }
491 public inline nothrow void Offset(float dx, float dy)
492 {
493 location.Offset(dx, dy);
494 }
495 public nothrow bool IntersectsWith(const RectF& that) const
496 {
497 return Left() < that.Right() && Top() < that.Bottom() && Right() > that.Left() && Bottom() > that.Top();
498 }
499 public static nothrow RectF Union(const RectF& a, const RectF& b)
500 {
501 float right = Max(a.Right(), b.Right());
502 float bottom = Max(a.Bottom(), b.Bottom());
503 float left = Min(a.Left(), b.Left());
504 float top = Min(a.Top(), b.Top());
505 return RectF(PointF(left, top), SizeF(right - left, bottom - top));
506 }
507 public PointF location;
508 public SizeF size;
509 }
510
511 public enum LineCap : int
512 {
513 flat = 0,
514 square = 1,
515 round = 2,
516 triangle = 3,
517 noAnchor = 0x10,
518 squareAnchor = 0x11,
519 roundAnchopr = 0x12,
520 diamondAnchor = 0x13,
521 arrowAnchor = 0x14,
522 custom = 0xff,
523 anchorMask = 0xf0
524 }
525
526 public enum LineJoin : int
527 {
528 miter = 0,
529 bevel = 1,
530 round = 2,
531 miterClipped = 3
532 }
533
534 public enum DashCap : int
535 {
536 flat = 0,
537 round = 2,
538 triangle = 3
539 }
540
541 public enum DashStyle : int
542 {
543 solid = 0,
544 dash = 1,
545 dot = 2,
546 dashDot = 3,
547 dashDotDot = 4,
548 custom = 5
549 }
550
551 public nothrow string ToString(DashStyle dashStyle)
552 {
553 switch (dashStyle)
554 {
555 case DashStyle.solid: return "solid";
556 case DashStyle.dash: return "dash";
557 case DashStyle.dot: return "dot";
558 case DashStyle.dashDot: return "dashDot";
559 case DashStyle.dashDotDot: return "dashDotDot";
560 case DashStyle.custom: return "custom";
561 }
562 return string();
563 }
564
565 public class Pen
566 {
567 public enum Alignment : int
568 {
569 center = 0, inset = 1
570 }
571 public Pen(const Color& color, float width) : nativePen(WinGraphicsCreatePen(color.alpha, color.red, color.green, color.blue, width))
572 {
573 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsPenGetLastStatus(nativePen)));
574 }
575 public Pen(const Color& color) : this(color, 1.0f)
576 {
577 }
578 public Pen(const Pen& that) : nativePen(WinGraphicsClonePen(that.nativePen))
579 {
580 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsPenGetLastStatus(nativePen)));
581 }
582 public nothrow Pen(Pen&& that) : nativePen(that.nativePen)
583 {
584 that.nativePen = null;
585 }
586 public void operator=(const Pen& that)
587 {
588 if (nativePen != that.nativePen)
589 {
590 if (nativePen != null)
591 {
592 WinGraphicsDeletePen(nativePen);
593 }
594 nativePen = WinGraphicsClonePen(that.nativePen);
595 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsPenGetLastStatus(nativePen)));
596 }
597 }
598 public default nothrow void operator=(Pen&& that);
599 public ~Pen()
600 {
601 if (nativePen != null)
602 {
603 WinGraphicsDeletePen(nativePen);
604 }
605 }
606 public nothrow Alignment GetAlignment() const
607 {
608 return cast<Alignment>(WinGraphicsPenGetAlignment(nativePen));
609 }
610 public nothrow GraphicsStatus SetAlignment(Alignment alignment)
611 {
612 return cast<GraphicsStatus>(WinGraphicsPenSetAlignment(nativePen, cast<int>(alignment)));
613 }
614 public void SetAlignmentChecked(Alignment alignment)
615 {
616 CheckGraphicsStatus(SetAlignment(alignment));
617 }
618 public nothrow Brush GetBrush() const
619 {
620 Brush brush;
621 brush.SetNativeBrush(WinGraphicsPenGetBrush(nativePen));
622 return brush;
623 }
624 public nothrow GraphicsStatus SetBrush(const Brush& brush)
625 {
626 return cast<GraphicsStatus>(WinGraphicsPenSetBrush(nativePen, brush.NativeBrush()));
627 }
628 public void SetBrushChecked(const Brush& brush)
629 {
630 CheckGraphicsStatus(SetBrush(brush));
631 }
632 public nothrow GraphicsStatus GetColor(Color& color) const
633 {
634 return cast<GraphicsStatus>(WinGraphicsPenGetColor(nativePen, color.alpha, color.red, color.green, color.blue));
635 }
636 public Color GetColorChecked() const
637 {
638 Color color;
639 CheckGraphicsStatus(GetColor(color));
640 return color;
641 }
642 public nothrow GraphicsStatus SetColor(const Color& color)
643 {
644 return cast<GraphicsStatus>(WinGraphicsPenSetColor(nativePen, color.alpha, color.red, color.green, color.blue));
645 }
646 public LineCap GetStartCap() const
647 {
648 return cast<LineCap>(WinGraphicsPenGetStartCap(nativePen));
649 }
650 public nothrow GraphicsStatus SetStartCap(LineCap startCap)
651 {
652 return cast<GraphicsStatus>(WinGraphicsPenSetStartCap(nativePen, cast<int>(startCap)));
653 }
654 public void SetStartCapChecked(LineCap startCap)
655 {
656 CheckGraphicsStatus(SetStartCap(startCap));
657 }
658 public LineCap GetEndCap() const
659 {
660 return cast<LineCap>(WinGraphicsPenGetEndCap(nativePen));
661 }
662 public nothrow GraphicsStatus SetEndCap(LineCap endCap)
663 {
664 return cast<GraphicsStatus>(WinGraphicsPenSetEndCap(nativePen, cast<int>(endCap)));
665 }
666 public void SetEndCapChecked(LineCap endCap)
667 {
668 CheckGraphicsStatus(SetEndCap(endCap));
669 }
670 public DashCap GetDashCap() const
671 {
672 return cast<DashCap>(WinGraphicsPenGetDashCap(nativePen));
673 }
674 public nothrow GraphicsStatus SetDashCap(DashCap dashCap)
675 {
676 return cast<GraphicsStatus>(WinGraphicsPenSetDashCap(nativePen, cast<int>(dashCap)));
677 }
678 public void SetDashCapChecked(DashCap dashCap)
679 {
680 CheckGraphicsStatus(SetDashCap(dashCap));
681 }
682 public nothrow float GetDashOffset() const
683 {
684 return WinGraphicsPenGetDashOffset(nativePen);
685 }
686 public nothrow GraphicsStatus SetDashOffset(float dashOffset)
687 {
688 return cast<GraphicsStatus>(WinGraphicsPenSetDashOffset(nativePen, dashOffset));
689 }
690 public void SetDashOffsetChecked(float dashOffset)
691 {
692 CheckGraphicsStatus(SetDashOffset(dashOffset));
693 }
694 public nothrow DashStyle GetDashStyle() const
695 {
696 return cast<DashStyle>(WinGraphicsPenGetDashStyle(nativePen));
697 }
698 public nothrow GraphicsStatus SetDashStyle(DashStyle dashStyle)
699 {
700 return cast<GraphicsStatus>(WinGraphicsPenSetDashStyle(nativePen, cast<int>(dashStyle)));
701 }
702 public void SetDashStyleChecked(DashStyle dashStyle)
703 {
704 CheckGraphicsStatus(SetDashStyle(dashStyle));
705 }
706 public LineJoin GetLineJoin() const
707 {
708 return cast<LineJoin>(WinGraphicsPenGetLineJoin(nativePen));
709 }
710 public nothrow GraphicsStatus SetLineJoin(LineJoin lineJoin)
711 {
712 return cast<GraphicsStatus>(WinGraphicsPenSetLineJoin(nativePen, cast<int>(lineJoin)));
713 }
714 public void SetLineJoinChecked(LineJoin lineJoin)
715 {
716 CheckGraphicsStatus(SetLineJoin(lineJoin));
717 }
718 public inline nothrow void* NativePen() const
719 {
720 return nativePen;
721 }
722 private void* nativePen;
723 }
724
725 public class PenKey
726 {
727 public nothrow PenKey(const Color& color_, float width_, DashStyle dashStyle_) : color(color_), width(width_), dashStyle(dashStyle_)
728 {
729 }
730 public nothrow string ToString() const
731 {
732 return color.ToString() + ":" + System.ToString(width) + ":" + ToString(dashStyle);
733 }
734 public Color color;
735 public float width;
736 public DashStyle dashStyle;
737 }
738
739 public nothrow bool operator==(const PenKey& left, const PenKey& right)
740 {
741 return left.color == right.color && left.width == right.width && left.dashStyle == right.dashStyle;
742 }
743
744 public nothrow ulong GetHashCode(const PenKey& penKey)
745 {
746 return GetHashCode(penKey.ToString());
747 }
748
749 public abstract class Brush
750 {
751 public nothrow Brush() : nativeBrush(null)
752 {
753 }
754 public nothrow void SetNativeBrush(const void* nativeBrush_)
755 {
756 nativeBrush = nativeBrush_;
757 }
758 public virtual ~Brush()
759 {
760 }
761 public virtual nothrow const void* NativeBrush() const
762 {
763 return nativeBrush;
764 }
765 private const void* nativeBrush;
766 }
767
768 public class SolidBrush : Brush
769 {
770 public SolidBrush(const Color& color) : nativeSolidBrush(WinGraphicsCreateSolidBrush(color.alpha, color.red, color.green, color.blue))
771 {
772 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsBrushGetLastStatus(nativeSolidBrush)));
773 SetNativeBrush(nativeSolidBrush);
774 }
775 public SolidBrush(const SolidBrush& that) : nativeSolidBrush(WinGraphicsCloneSolidBrush(that.nativeSolidBrush))
776 {
777 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsBrushGetLastStatus(nativeSolidBrush)));
778 SetNativeBrush(nativeSolidBrush);
779 }
780 public nothrow SolidBrush(SolidBrush&& that) : nativeSolidBrush(that.nativeSolidBrush)
781 {
782 that.SetNativeBrush(null);
783 that.nativeSolidBrush = null;
784 }
785 public void operator=(const SolidBrush& that)
786 {
787 if (nativeSolidBrush != that.nativeSolidBrush)
788 {
789 if (nativeSolidBrush != null)
790 {
791 WinGraphicsDeleteSolidBrush(nativeSolidBrush);
792 }
793 nativeSolidBrush = WinGraphicsCloneSolidBrush(that.nativeSolidBrush);
794 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsBrushGetLastStatus(nativeSolidBrush)));
795 SetNativeBrush(nativeSolidBrush);
796 }
797 }
798 public nothrow void operator=(SolidBrush&& that)
799 {
800 const void* thatNativeBrush = that.NativeBrush();
801 const void* nativeBrush = NativeBrush();
802 Swap(thatNativeBrush, nativeBrush);
803 that.SetNativeBrush(thatNativeBrush);
804 SetNativeBrush(nativeBrush);
805 Swap(nativeSolidBrush, that.nativeSolidBrush);
806 }
807 public ~SolidBrush()
808 {
809 if (nativeSolidBrush != null)
810 {
811 WinGraphicsDeleteSolidBrush(nativeSolidBrush);
812 }
813 }
814 public override nothrow const void* NativeBrush() const
815 {
816 return nativeSolidBrush;
817 }
818 private void* nativeSolidBrush;
819 }
820
821 public class NativeHandle
822 {
823 public explicit nothrow NativeHandle(const void* handle_) : handle(handle_)
824 {
825 }
826 public void* handle;
827 }
828
829 public class FontFamily
830 {
831 public FontFamily() : nativeFontFamily(WinGraphicsCreateEmptyFontFamily()), owned(true)
832 {
833 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsFontFamilyGetLastStatus(nativeFontFamily)));
834 }
835 public FontFamily(const string& familyName) : nativeFontFamily(WinGraphicsCreateFontFamily(familyName.Chars())), owned(true)
836 {
837 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsFontFamilyGetLastStatus(nativeFontFamily)));
838 }
839 public explicit nothrow FontFamily(const NativeHandle& nativeHandle_) : nativeFontFamily(nativeHandle_.handle), owned(false)
840 {
841 }
842 public FontFamily(const FontFamily& that) : nativeFontFamily(null), owned(that.owned)
843 {
844 if (owned)
845 {
846 nativeFontFamily = WinGraphicsCloneFontFamily(that.nativeFontFamily);
847 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsFontFamilyGetLastStatus(nativeFontFamily)));
848 }
849 else
850 {
851 nativeFontFamily = that.nativeFontFamily;
852 }
853 }
854 public nothrow FontFamily(FontFamily&& that) : nativeFontFamily(that.nativeFontFamily), owned(that.owned)
855 {
856 that.nativeFontFamily = null;
857 that.owned = false;
858 }
859 public void operator=(const FontFamily& that)
860 {
861 if (nativeFontFamily != that.nativeFontFamily)
862 {
863 if (nativeFontFamily != null && owned)
864 {
865 WinGraphicsDeleteFontFamily(nativeFontFamily);
866 }
867 if (that.owned)
868 {
869 nativeFontFamily = WinGraphicsCloneFontFamily(that.nativeFontFamily);
870 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsFontFamilyGetLastStatus(nativeFontFamily)));
871 owned = true;
872 }
873 else
874 {
875 nativeFontFamily = that.nativeFontFamily;
876 owned = false;
877 }
878 }
879 }
880 public default nothrow void operator=(FontFamily&&);
881 public ~FontFamily()
882 {
883 if (nativeFontFamily != null && owned)
884 {
885 WinGraphicsDeleteFontFamily(nativeFontFamily);
886 }
887 }
888 public nothrow GraphicsStatus GetFamilyName(string& familyName) const
889 {
890 wchar* str = null;
891 GraphicsStatus status = cast<GraphicsStatus>(WinGraphicsGetFontFamilyName(nativeFontFamily, str));
892 if (status == GraphicsStatus.ok)
893 {
894 familyName = ToUtf8(str);
895 }
896 return status;
897 }
898 public string GetFamilyNameChecked() const
899 {
900 string familyName;
901 CheckGraphicsStatus(GetFamilyName(familyName));
902 return familyName;
903 }
904 public static nothrow FontFamily GenericMonospace()
905 {
906 NativeHandle nativeHandle(WinGraphicsGetGenericMonospaceFontFamily());
907 return FontFamily(nativeHandle);
908 }
909 public static nothrow FontFamily GenericSansSerif()
910 {
911 NativeHandle nativeHandle(WinGraphicsGetGenericSansSerifFontFamily());
912 return FontFamily(nativeHandle);
913 }
914 public static nothrow FontFamily GenericSerif()
915 {
916 NativeHandle nativeHandle(WinGraphicsGetGenericSerifFontFamily());
917 return FontFamily(nativeHandle);
918 }
919 public inline nothrow void* NativeFontFamily() const
920 {
921 return nativeFontFamily;
922 }
923 private void* nativeFontFamily;
924 private bool owned;
925 }
926
927 public enum FontStyle : int
928 {
929 regular = 0,
930 bold = 1 << 0,
931 italic = 1 << 1,
932 boldItalic = bold | italic,
933 underline = 1 << 2,
934 strikeOut = 1 << 3
935 }
936
937 public nothrow ulong GetHashCode(FontStyle fontStyle)
938 {
939 return cast<ulong>(cast<int>(fontStyle));
940 }
941
942 public enum Unit : int
943 {
944 world = 0,
945 display = 1,
946 pixel = 2,
947 point = 3,
948 inch = 4,
949 document = 5,
950 millimeter = 6
951 }
952
953 public class FontHandle
954 {
955 public nothrow FontHandle(void* hfont_) : hfont(hfont_)
956 {
957 }
958 suppress FontHandle(const FontHandle&);
959 suppress void operator=(const FontHandle&);
960 public nothrow FontHandle(FontHandle&& that) : hfont(that.hfont)
961 {
962 that.hfont = null;
963 }
964 public default nothrow void operator=(FontHandle&&);
965 public ~FontHandle()
966 {
967 if (hfont != null)
968 {
969 WinDeleteObject(hfont);
970 }
971 }
972 public inline nothrow bool IsNull() const
973 {
974 return hfont == null;
975 }
976 public inline nothrow void* HFont() const
977 {
978 return hfont;
979 }
980 private void* hfont;
981 }
982
983 public class Font
984 {
985 public Font(const FontFamily& family, float emSize, FontStyle style, Unit unit) : nativeFont(WinGraphicsCreateFont(family.NativeFontFamily(), emSize, style, unit))
986 {
987 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsFontGetLastStatus(nativeFont)));
988 }
989 public Font(const FontFamily& family, float emSize) : this(family, emSize, FontStyle.regular, Unit.point)
990 {
991 }
992 public nothrow Font(void* nativeFont_) : nativeFont(nativeFont_)
993 {
994 }
995 public nothrow Font() : this(null)
996 {
997 }
998 public Font(const Font& that) : nativeFont(WinGraphicsCloneFont(that.nativeFont))
999 {
1000 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsFontGetLastStatus(nativeFont)));
1001 }
1002 public nothrow Font(Font&& that) : nativeFont(that.nativeFont)
1003 {
1004 that.nativeFont = null;
1005 }
1006 public void operator=(const Font& that)
1007 {
1008 if (nativeFont != that.nativeFont)
1009 {
1010 if (nativeFont != null)
1011 {
1012 WinGraphicsDeleteFont(nativeFont);
1013 }
1014 nativeFont = WinGraphicsCloneFont(that.nativeFont);
1015 }
1016 }
1017 public default nothrow void operator=(Font&&);
1018 public ~Font()
1019 {
1020 if (nativeFont != null)
1021 {
1022 WinGraphicsDeleteFont(nativeFont);
1023 }
1024 }
1025 public nothrow bool IsNull() const
1026 {
1027 return nativeFont == null;
1028 }
1029 public nothrow float GetSize() const
1030 {
1031 return WinGraphicsGetFontSize(nativeFont);
1032 }
1033 public nothrow float GetHeight(const Graphics& graphics) const
1034 {
1035 return WinGraphicsGetFontHeight(nativeFont, graphics.NativeGraphics());
1036 }
1037 public nothrow FontStyle GetStyle() const
1038 {
1039 return cast<FontStyle>(WinGraphicsGetFontStyle(nativeFont));
1040 }
1041 public nothrow GraphicsStatus GetFamily(FontFamily& fontFamily)
1042 {
1043 return cast<GraphicsStatus>(WinGraphicsGetFontFamily(nativeFont, fontFamily.NativeFontFamily()));
1044 }
1045 public FontFamily GetFamilyChecked()
1046 {
1047 FontFamily fontFamily;
1048 CheckGraphicsStatus(GetFamily(fontFamily));
1049 return fontFamily;
1050 }
1051 public static Font FromHFont(void* hdc, void* hfont)
1052 {
1053 Font font(WinGraphicsCreateFontFromHFont(hdc, hfont));
1054 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsFontGetLastStatus(font.NativeFont())));
1055 return font;
1056 }
1057 public nothrow GraphicsStatus ToHFont(const Graphics& graphics, FontHandle& fontHandle)
1058 {
1059 void* hfont = null;
1060 GraphicsStatus status = cast<GraphicsStatus>(WinGraphicsFontToHFont(nativeFont, graphics.NativeGraphics(), hfont));
1061 if (status == GraphicsStatus.ok)
1062 {
1063 fontHandle = FontHandle(hfont);
1064 }
1065 return status;
1066 }
1067 public FontHandle ToHFontChecked(const Graphics& graphics)
1068 {
1069 FontHandle fontHandle(null);
1070 CheckGraphicsStatus(ToHFont(graphics, fontHandle));
1071 return fontHandle;
1072 }
1073 public inline nothrow void* NativeFont() const
1074 {
1075 return nativeFont;
1076 }
1077 private void* nativeFont;
1078 }
1079
1080 public nothrow string ToString(FontStyle style)
1081 {
1082 string s;
1083 if (style == FontStyle.regular)
1084 {
1085 s.Append("regular");
1086 }
1087 else
1088 {
1089 if ((style & FontStyle.bold) != 0)
1090 {
1091 if (!s.IsEmpty())
1092 {
1093 s.Append('.');
1094 }
1095 s.Append("bold");
1096 }
1097 if ((style & FontStyle.italic) != 0)
1098 {
1099 if (!s.IsEmpty())
1100 {
1101 s.Append('.');
1102 }
1103 s.Append("italic");
1104 }
1105 if ((style & FontStyle.underline) != 0)
1106 {
1107 if (!s.IsEmpty())
1108 {
1109 s.Append('.');
1110 }
1111 s.Append("underline");
1112 }
1113 if ((style & FontStyle.strikeOut) != 0)
1114 {
1115 if (!s.IsEmpty())
1116 {
1117 s.Append('.');
1118 }
1119 s.Append("strikeOut");
1120 }
1121 }
1122 return s;
1123 }
1124
1125 public FontStyle ParseFontStyle(const string& fontStyleStr)
1126 {
1127 FontStyle fontStyle = FontStyle.regular;
1128 List<string> components = fontStyleStr.Split('.');
1129 for (const string& component : components)
1130 {
1131 if (component == "bold")
1132 {
1133 fontStyle = cast<FontStyle>(fontStyle | FontStyle.bold);
1134 }
1135 else if (component == "italic")
1136 {
1137 fontStyle = cast<FontStyle>(fontStyle | FontStyle.italic);
1138 }
1139 else if (component == "underline")
1140 {
1141 fontStyle = cast<FontStyle>(fontStyle | FontStyle.underline);
1142 }
1143 else if (component == "strikeOut")
1144 {
1145 fontStyle = cast<FontStyle>(fontStyle | FontStyle.strikeOut);
1146 }
1147 }
1148 return fontStyle;
1149 }
1150
1151 public class FontKey
1152 {
1153 public nothrow FontKey(const string& family_, float size_, FontStyle style_) : family(family_), size(size_), style(style_)
1154 {
1155 }
1156 public nothrow string ToString()
1157 {
1158 string s = ToLower(family);
1159 s.Append('.').Append(System.ToString(size)).Append('.').Append(ToString(style));
1160 return s;
1161 }
1162 public string family;
1163 public float size;
1164 public FontStyle style;
1165 }
1166
1167 public nothrow bool operator==(const FontKey& left, const FontKey& right)
1168 {
1169 return ToLower(left.family) == ToLower(right.family) && left.size == right.size && left.style == right.style;
1170 }
1171
1172 public nothrow ulong GetHashCode(const FontKey& fontKey)
1173 {
1174 return GetHashCode(fontKey.ToString());
1175 }
1176
1177 public enum StringAlignment : int
1178 {
1179 near, center, far
1180 }
1181
1182 public enum HotKeyPrefix : int
1183 {
1184 none, show, hide
1185 }
1186
1187 public class StringFormat
1188 {
1189 public StringFormat() : nativeFormat(WinGraphicsCreateDefaultStringFormat()), owned(true)
1190 {
1191 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsStringFormatGetLastStatus(nativeFormat)));
1192 }
1193 public StringFormat(const NativeHandle& nativeHandle_) : nativeFormat(nativeHandle_.handle), owned(false)
1194 {
1195 }
1196 public StringFormat(const StringFormat& that) : nativeFormat(null), owned(that.owned)
1197 {
1198 if (owned)
1199 {
1200 nativeFormat = WinGraphicsCloneStringFormat(that.nativeFormat);
1201 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsStringFormatGetLastStatus(nativeFormat)));
1202 }
1203 else
1204 {
1205 nativeFormat = that.nativeFormat;
1206 }
1207 }
1208 public StringFormat(StringAlignment horizontalAlignment, StringAlignment verticalAlignment, HotKeyPrefix hotKeyPrefix) : this()
1209 {
1210 SetAlignmentChecked(horizontalAlignment);
1211 SetLineAlignmentChecked(verticalAlignment);
1212 SetHotKeyPrefixChecked(hotKeyPrefix);
1213 }
1214 public StringFormat(StringAlignment horizontalAlignment, StringAlignment verticalAlignment) : this(horizontalAlignment, verticalAlignment, HotKeyPrefix.none)
1215 {
1216 }
1217 public nothrow StringFormat(StringFormat&& that) : nativeFormat(that.nativeFormat), owned(that.owned)
1218 {
1219 that.nativeFormat = null;
1220 that.owned = false;
1221 }
1222 public void operator=(const StringFormat& that)
1223 {
1224 if (nativeFormat != that.nativeFormat)
1225 {
1226 if (nativeFormat != null && owned)
1227 {
1228 WinGraphicsDeleteStringFormat(nativeFormat);
1229 }
1230 if (that.owned)
1231 {
1232 nativeFormat = WinGraphicsCloneStringFormat(that.nativeFormat);
1233 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsStringFormatGetLastStatus(nativeFormat)));
1234 owned = true;
1235 }
1236 else
1237 {
1238 nativeFormat = that.nativeFormat;
1239 owned = false;
1240 }
1241 }
1242 }
1243 public default nothrow void operator=(StringFormat&&);
1244 public ~StringFormat()
1245 {
1246 if (nativeFormat != null && owned)
1247 {
1248 WinGraphicsDeleteStringFormat(nativeFormat);
1249 }
1250 }
1251 public nothrow GraphicsStatus SetAlignment(StringAlignment alignment)
1252 {
1253 return cast<GraphicsStatus>(WinGraphicsStringFormatSetAlignment(nativeFormat, alignment));
1254 }
1255 public void SetAlignmentChecked(StringAlignment alignment)
1256 {
1257 CheckGraphicsStatus(SetAlignment(alignment));
1258 }
1259 public nothrow GraphicsStatus SetLineAlignment(StringAlignment alignment)
1260 {
1261 return cast<GraphicsStatus>(WinGraphicsStringFormatSetLineAlignment(nativeFormat, alignment));
1262 }
1263 public void SetLineAlignmentChecked(StringAlignment alignment)
1264 {
1265 CheckGraphicsStatus(SetLineAlignment(alignment));
1266 }
1267 public nothrow GraphicsStatus SetHotKeyPrefix(HotKeyPrefix hotKeyPrefix)
1268 {
1269 return cast<GraphicsStatus>(WinGraphicsStringFormatSetHotKeyPrefix(nativeFormat, hotKeyPrefix));
1270 }
1271 public void SetHotKeyPrefixChecked(HotKeyPrefix hotKeyPrefix)
1272 {
1273 CheckGraphicsStatus(SetHotKeyPrefix(hotKeyPrefix));
1274 }
1275 public inline nothrow void* NativeFormat() const
1276 {
1277 return nativeFormat;
1278 }
1279 public static nothrow StringFormat GenericDefault()
1280 {
1281 NativeHandle nativeHandle(WinGraphicsGetGenericDefaultStringFormat());
1282 return StringFormat(nativeHandle);
1283 }
1284 public static nothrow StringFormat GenericTypographic()
1285 {
1286 NativeHandle nativeHandle(WinGraphicsGetGenericTypographicStringFormat());
1287 return StringFormat(nativeHandle);
1288 }
1289 private void* nativeFormat;
1290 private bool owned;
1291 }
1292
1293 public enum TextRenderingHint : int
1294 {
1295 systemDefault = 0,
1296 singleBitPerPixelGridFit = 1,
1297 singleBitPerPixel = 2,
1298 antiAliasGridFit = 3,
1299 antiAlias = 4,
1300 clearTypeGridFit = 5
1301 }
1302
1303 internal class PaintGuard
1304 {
1305 public nothrow PaintGuard(void* hdc_, void* paintStruct_) : hdc(hdc_), paintStruct(paintStruct_)
1306 {
1307 }
1308 public ~PaintGuard()
1309 {
1310 if (hdc != null)
1311 {
1312 EndPaint(hdc, paintStruct);
1313 }
1314 }
1315 private void* hdc;
1316 private void* paintStruct;
1317 }
1318
1319 public enum CombineMode : int
1320 {
1321 replace, intersect, union, xor, exclude, complement
1322 }
1323
1324 public class Region
1325 {
1326 public Region() : nativeRegion(WinGraphicsCreateRegion())
1327 {
1328 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsRegionGetLastStatus(nativeRegion)));
1329 }
1330 public Region(const Region& that) : nativeRegion(WinGraphicsCloneRegion(that.nativeRegion))
1331 {
1332 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsRegionGetLastStatus(nativeRegion)));
1333 }
1334 public nothrow Region(Region&& that) : nativeRegion(that.nativeRegion)
1335 {
1336 that.nativeRegion = null;
1337 }
1338 public void operator=(const Region& that)
1339 {
1340 if (nativeRegion != null)
1341 {
1342 WinGraphicsDeleteRegion(nativeRegion);
1343 }
1344 nativeRegion = WinGraphicsCloneRegion(that.nativeRegion);
1345 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsRegionGetLastStatus(nativeRegion)));
1346 }
1347 public default nothrow void operator=(Region&&);
1348 public ~Region()
1349 {
1350 if (nativeRegion != null)
1351 {
1352 WinGraphicsDeleteRegion(nativeRegion);
1353 }
1354 }
1355 public inline nothrow void* NativeRegion() const
1356 {
1357 return nativeRegion;
1358 }
1359 private void* nativeRegion;
1360 }
1361
1362
1363
1364 public enum ImageFormat : int
1365 {
1366 bmp, jpeg, gif, tiff, png
1367 }
1368
1369 public nothrow const char* GetImageFormat(ImageFormat format)
1370 {
1371 switch (format)
1372 {
1373 case ImageFormat.bmp: return "image/bmp";
1374 case ImageFormat.jpeg: return "image/jpeg";
1375 case ImageFormat.gif: return "image/gif";
1376 case ImageFormat.tiff: return "image/tiff";
1377 case ImageFormat.png: return "image/png";
1378 }
1379 return "";
1380 }
1381
1382 public nothrow GraphicsStatus GetEncoderClsId(const char* imageFormat, Uuid& clsid)
1383 {
1384 return cast<GraphicsStatus>(WinGraphicsGetEncoderClsId(imageFormat, &clsid));
1385 }
1386
1387 public Uuid GetEncoderClsIdChecked(const char* imageFormat)
1388 {
1389 Uuid clsid;
1390 CheckGraphicsStatus(GetEncoderClsId(imageFormat, clsid));
1391 return clsid;
1392 }
1393
1394 public class Image
1395 {
1396 public nothrow Image() : nativeImage(null)
1397 {
1398 }
1399 public nothrow Image(void* nativeImage_) : nativeImage(nativeImage_)
1400 {
1401 }
1402 public Image(const string& fileName, bool useEmbeddedColorManagement) : nativeImage(WinGraphicsCreateImage(fileName.Chars(), useEmbeddedColorManagement))
1403 {
1404 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsImageGetLastStatus(nativeImage)));
1405 }
1406 public Image(const Image& that) : nativeImage(WinGraphicsCloneImage(that.nativeImage))
1407 {
1408 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsImageGetLastStatus(nativeImage)));
1409 }
1410 public nothrow Image(Image&& that) : nativeImage(that.nativeImage)
1411 {
1412 that.nativeImage = null;
1413 }
1414 public void operator=(const Image& that)
1415 {
1416 if (nativeImage != null)
1417 {
1418 WinGraphicsDeleteImage(nativeImage);
1419 }
1420 nativeImage = WinGraphicsCloneImage(that.nativeImage);
1421 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsImageGetLastStatus(nativeImage)));
1422 }
1423 public default nothrow void operator=(Image&&);
1424 public virtual ~Image()
1425 {
1426 if (nativeImage != null)
1427 {
1428 WinGraphicsDeleteImage(nativeImage);
1429 }
1430 }
1431 public nothrow uint GetHeight() const
1432 {
1433 return WinGraphicsImageGetHeight(nativeImage);
1434 }
1435 public nothrow uint GetWidth() const
1436 {
1437 return WinGraphicsImageGetWidth(nativeImage);
1438 }
1439 public GraphicsStatus Save(const char* fileName, const Uuid& encoderClsId)
1440 {
1441 return cast<GraphicsStatus>(WinGraphicsImageSave(nativeImage, fileName, &encoderClsId));
1442 }
1443 public void SaveChecked(const char* fileName, const Uuid& encoderClsId)
1444 {
1445 CheckGraphicsStatus(Save(fileName, encoderClsId));
1446 }
1447 public nothrow void* NativeImage() const
1448 {
1449 return nativeImage;
1450 }
1451 private void* nativeImage;
1452 }
1453
1454 public const int pixelFormatIndexed = 0x00010000;
1455 public const int pixelFormatGDI = 0x00020000;
1456 public const int pixelFormatAlpha = 0x00040000;
1457 public const int pixelFormatPAlpha = 0x00080000;
1458 public const int pixelFormatExtended = 0x00100000;
1459 public const int pixelFormatCanonical = 0x00200000;
1460
1461 public enum PixelFormat : int
1462 {
1463 pixelFormat1bppIndexed = 1 | (1 << 8) | pixelFormatIndexed | pixelFormatGDI,
1464 pixelFormat4bppIndexed = 2 | (4 << 8) | pixelFormatIndexed | pixelFormatGDI,
1465 pixelFormat8bppIndexed = 3 | ( 8 << 8) | pixelFormatIndexed | pixelFormatGDI,
1466 pixelFormat16bppGrayScale = 4 | (16 << 8) | pixelFormatExtended,
1467 pixelFormat16bppRGB555 = 5 | (16 << 8) | pixelFormatGDI,
1468 pixelFormat16bppRGB565 = 6 | (16 << 8) | pixelFormatGDI,
1469 pixelFormat16bppARGB1555 = 7 | (16 << 8) | pixelFormatAlpha | pixelFormatGDI,
1470 pixelFormat24bppRGB = 8 | (24 << 8) | pixelFormatGDI,
1471 pixelFormat32bppRGB = 9 | (32 << 8) | pixelFormatGDI,
1472 pixelFormat32bppARGB = 10 | (32 << 8) | pixelFormatAlpha | pixelFormatGDI | pixelFormatCanonical,
1473 pixelFormat32bppPARGB = 11 | (32 << 8) | pixelFormatAlpha | pixelFormatPAlpha | pixelFormatGDI,
1474 pixelFormat48bppRGB = 12 | (48 << 8) | pixelFormatExtended,
1475 pixelFormat64bppARGB = 13 | (64 << 8) | pixelFormatAlpha | pixelFormatCanonical | pixelFormatExtended,
1476 pixelFormat64bppPARGB = 14 | (64 << 8) | pixelFormatAlpha | pixelFormatPAlpha | pixelFormatExtended,
1477 pixelFormat32bppCMYK = 15 | (32 << 8),
1478 pixelFormatMax = 16
1479 }
1480
1481 public class Bitmap : Image
1482 {
1483 public nothrow Bitmap() : base()
1484 {
1485 }
1486 public nothrow Bitmap(void* nativeHandle_) : base(nativeHandle_)
1487 {
1488 }
1489 public Bitmap(const string& fileName, bool useEmbeddedColorManagement) : base(WinGraphicsCreateBitmap(fileName.Chars(), useEmbeddedColorManagement))
1490 {
1491 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsImageGetLastStatus(NativeImage())));
1492 }
1493 public Bitmap(int width, int height, const Graphics& graphics) : base(WinGraphicsCreateBitmapWidthHeight(width, height, graphics.NativeGraphics()))
1494 {
1495 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsImageGetLastStatus(NativeImage())));
1496 }
1497 public Bitmap(const WinBitmap& winBitmap, void* palette) : base(WinGraphicsCreateBitmapWinBitmap(winBitmap.Handle(), palette))
1498 {
1499 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsImageGetLastStatus(NativeImage())));
1500 }
1501 public Bitmap(const Icon& icon) : base(WinGraphicsCreateBitmapIcon(icon.Handle()))
1502 {
1503 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsImageGetLastStatus(NativeImage())));
1504 }
1505 public static Bitmap FromResource(const string& resourceName)
1506 {
1507 Bitmap bitmap(WinGraphicsCreateBitmapResource(resourceName.Chars()));
1508 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsImageGetLastStatus(bitmap.NativeImage())));
1509 return bitmap;
1510 }
1511 public nothrow GraphicsStatus GetPixel(int x, int y, Color& color) const
1512 {
1513 return cast<GraphicsStatus>(WinGraphicsBitmapGetPixel(NativeImage(), x, y, color.alpha, color.red, color.green, color.blue));
1514 }
1515 public Color GetPixelChecked(int x, int y) const
1516 {
1517 Color color;
1518 CheckGraphicsStatus(GetPixel(x, y, color));
1519 return color;
1520 }
1521 public nothrow GraphicsStatus SetPixel(int x, int y, const Color& color)
1522 {
1523 return cast<GraphicsStatus>(WinGraphicsBitmapSetPixel(NativeImage(), x, y, color.alpha, color.red, color.green, color.blue));
1524 }
1525 public void SetPixelChecked(int x, int y, const Color& color)
1526 {
1527 CheckGraphicsStatus(SetPixel(x, y, color));
1528 }
1529 public Bitmap ToGrayBitmap(PixelFormat pixelFormat, const Color& bitmapTransparentColor)
1530 {
1531 int w = cast<int>(GetWidth());
1532 int h = cast<int>(GetHeight());
1533 Bitmap grayBitmap(WinGraphicsCloneBitmap(NativeImage(), 0, 0, w, h, pixelFormat));
1534 for (int y = 0; y < h; ++y;)
1535 {
1536 for(int x = 0; x < w; ++x;)
1537 {
1538 Color color = grayBitmap.GetPixelChecked(x, y);
1539 Color gray = color.ToGray(bitmapTransparentColor);
1540 grayBitmap.SetPixelChecked(x, y, gray);
1541 }
1542 }
1543 return grayBitmap;
1544 }
1545 public Bitmap ToGrayBitmap()
1546 {
1547 return ToGrayBitmap(PixelFormat.pixelFormat24bppRGB, Color.DefaultBitmapTransparent());
1548 }
1549 public ~Bitmap()
1550 {
1551 }
1552 }
1553
1554 public enum MatrixOrder
1555 {
1556 prepend, append
1557 }
1558
1559 public class Matrix
1560 {
1561 public Matrix() : nativeMatrix(WinGraphicsCreateMatrix())
1562 {
1563 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsMatrixGetLastStatus(nativeMatrix)));
1564 }
1565 public Matrix(const Rect& rect, const Point& pt) : nativeMatrix(WinGraphicsCreateMatrixRectPoint(rect.location.x, rect.location.y, rect.size.w, rect.size.h, pt.x, pt.y))
1566 {
1567 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsMatrixGetLastStatus(nativeMatrix)));
1568 }
1569 public Matrix(const RectF& rect, const PointF& pt) : nativeMatrix(WinGraphicsCreateMatrixRectFPointF(rect.location.x, rect.location.y, rect.size.w, rect.size.h, pt.x, pt.y))
1570 {
1571 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsMatrixGetLastStatus(nativeMatrix)));
1572 }
1573 public Matrix(const Matrix& that) : nativeMatrix(WinGraphicsCloneMatrix(that.nativeMatrix))
1574 {
1575 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsMatrixGetLastStatus(nativeMatrix)));
1576 }
1577 public nothrow Matrix(Matrix&& that) : nativeMatrix(that.nativeMatrix)
1578 {
1579 that.nativeMatrix = null;
1580 }
1581 public void operator=(const Matrix& that)
1582 {
1583 if (nativeMatrix != null)
1584 {
1585 WinGraphicsDeleteMatrix(nativeMatrix);
1586 }
1587 nativeMatrix = WinGraphicsCloneMatrix(that.nativeMatrix);
1588 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsMatrixGetLastStatus(nativeMatrix)));
1589 }
1590 public default nothrow void operator=(Matrix&&);
1591 public ~Matrix()
1592 {
1593 if (nativeMatrix != null)
1594 {
1595 WinGraphicsDeleteMatrix(nativeMatrix);
1596 }
1597 }
1598 public GraphicsStatus Multiply(const Matrix& that, MatrixOrder order)
1599 {
1600 return cast<GraphicsStatus>(WinGraphicsMultiplyMatrix(nativeMatrix, that.nativeMatrix, cast<int>(order)));
1601 }
1602 public GraphicsStatus Multiply(const Matrix& that)
1603 {
1604 return cast<GraphicsStatus>(WinGraphicsMultiplyMatrix(nativeMatrix, that.nativeMatrix, cast<int>(MatrixOrder.prepend)));
1605 }
1606 public void MultiplyChecked(const Matrix& that, MatrixOrder order)
1607 {
1608 CheckGraphicsStatus(Multiply(that, order));
1609 }
1610 public void MultiplyChecked(const Matrix& that)
1611 {
1612 CheckGraphicsStatus(Multiply(that, MatrixOrder.prepend));
1613 }
1614 public nothrow GraphicsStatus Reset()
1615 {
1616 return cast<GraphicsStatus>(WinGraphicsResetMatrix(nativeMatrix));
1617 }
1618 public void ResetChecked()
1619 {
1620 CheckGraphicsStatus(Reset());
1621 }
1622 public nothrow GraphicsStatus Invert()
1623 {
1624 return cast<GraphicsStatus>(WinGraphicsInvertMatrix(nativeMatrix));
1625 }
1626 public void InvertChecked()
1627 {
1628 CheckGraphicsStatus(Invert());
1629 }
1630 public nothrow float OffsetX() const
1631 {
1632 return WinGraphicsMatrixOffsetX(nativeMatrix);
1633 }
1634 public nothrow float OffsetY() const
1635 {
1636 return WinGraphicsMatrixOffsetY(nativeMatrix);
1637 }
1638 public nothrow GraphicsStatus Rotate(float angle, MatrixOrder order)
1639 {
1640 return cast<GraphicsStatus>(WinGraphicsMatrixRotate(nativeMatrix, angle, cast<int>(order)));
1641 }
1642 public nothrow GraphicsStatus Rotate(float angle)
1643 {
1644 return cast<GraphicsStatus>(WinGraphicsMatrixRotate(nativeMatrix, angle, cast<int>(MatrixOrder.prepend)));
1645 }
1646 public void RotateChecked(float angle, MatrixOrder order)
1647 {
1648 CheckGraphicsStatus(Rotate(angle));
1649 }
1650 public void RotateChecked(float angle)
1651 {
1652 CheckGraphicsStatus(Rotate(angle, MatrixOrder.prepend));
1653 }
1654 public nothrow GraphicsStatus RotateAt(float angle, const PointF& center, MatrixOrder order)
1655 {
1656 return cast<GraphicsStatus>(WinGraphicsMatrixRotateAt(nativeMatrix, angle, center.x, center.y, cast<int>(order)));
1657 }
1658 public void RotateAtChecked(float angle, const PointF& center, MatrixOrder order)
1659 {
1660 CheckGraphicsStatus(RotateAt(angle, center, order));
1661 }
1662 public nothrow GraphicsStatus RotateAt(float angle, const PointF& center)
1663 {
1664 return RotateAt(angle, center, MatrixOrder.prepend);
1665 }
1666 public void RotateAtChecked(float angle, const PointF& center)
1667 {
1668 CheckGraphicsStatus(RotateAt(angle, center, MatrixOrder.prepend));
1669 }
1670 public nothrow GraphicsStatus Scale(float scaleX, float scaleY, MatrixOrder order)
1671 {
1672 return cast<GraphicsStatus>(WinGraphicsMatrixScale(nativeMatrix, scaleX, scaleY, cast<int>(order)));
1673 }
1674 public void ScaleChecked(float scaleX, float scaleY, MatrixOrder order)
1675 {
1676 CheckGraphicsStatus(Scale(scaleX, scaleY, order));
1677 }
1678 public nothrow GraphicsStatus Scale(float scaleX, float scaleY)
1679 {
1680 return Scale(scaleX, scaleY, MatrixOrder.prepend);
1681 }
1682 public void ScaleChecked(float scaleX, float scaleY)
1683 {
1684 CheckGraphicsStatus(Scale(scaleX, scaleY, MatrixOrder.prepend));
1685 }
1686 public nothrow GraphicsStatus Shear(float shearX, float shearY, MatrixOrder order)
1687 {
1688 return cast<GraphicsStatus>(WinGraphicsMatrixShear(nativeMatrix, shearX, shearY, cast<int>(order)));
1689 }
1690 public void ShearChecked(float shearX, float shearY, MatrixOrder order)
1691 {
1692 CheckGraphicsStatus(Shear(shearX, shearY, order));
1693 }
1694 public nothrow GraphicsStatus Shear(float shearX, float shearY)
1695 {
1696 return Shear(shearX, shearY, MatrixOrder.prepend);
1697 }
1698 public void ShearChecked(float shearX, float shearY)
1699 {
1700 ShearChecked(shearX, shearY, MatrixOrder.prepend);
1701 }
1702 public nothrow GraphicsStatus Translate(float offsetX, float offsetY, MatrixOrder order)
1703 {
1704 return cast<GraphicsStatus>(WinGraphicsMatrixTranslate(nativeMatrix, offsetX, offsetY, cast<int>(order)));
1705 }
1706 public void TranslateChecked(float offsetX, float offsetY, MatrixOrder order)
1707 {
1708 CheckGraphicsStatus(Translate(offsetX, offsetY, order));
1709 }
1710 public nothrow GraphicsStatus Translate(float offsetX, float offsetY)
1711 {
1712 return Translate(offsetX, offsetY, MatrixOrder.prepend);
1713 }
1714 public void TranslateChecked(float offsetX, float offsetY)
1715 {
1716 TranslateChecked(offsetX, offsetY, MatrixOrder.prepend);
1717 }
1718 public nothrow GraphicsStatus SetElements(float m11, float m12, float m21, float m22, float dx, float dy)
1719 {
1720 return cast<GraphicsStatus>(WinGraphicsMatrixSetElements(nativeMatrix, m11, m12, m21, m22, dx, dy));
1721 }
1722 public void SetElementsChecked(float m11, float m12, float m21, float m22, float dx, float dy)
1723 {
1724 CheckGraphicsStatus(SetElements(m11, m12, m21, m22, dx, dy));
1725 }
1726 public nothrow GraphicsStatus TransformPoints(List<Point>& points)
1727 {
1728 return cast<GraphicsStatus>(WinGraphicsMatrixTransformPoints(nativeMatrix, points.Begin().Ptr(), cast<int>(points.Count())));
1729 }
1730 public void TransformPointsChecked(List<Point>& points)
1731 {
1732 CheckGraphicsStatus(TransformPoints(points));
1733 }
1734 public nothrow GraphicsStatus TransformPoints(List<PointF>& points)
1735 {
1736 return cast<GraphicsStatus>(WinGraphicsMatrixTransformPointsF(nativeMatrix, points.Begin().Ptr(), cast<int>(points.Count())));
1737 }
1738 public void TransformPointsChecked(List<PointF>& points)
1739 {
1740 CheckGraphicsStatus(TransformPoints(points));
1741 }
1742 public inline nothrow void* NativeMatrix() const
1743 {
1744 return nativeMatrix;
1745 }
1746 private void* nativeMatrix;
1747 }
1748
1749 public Matrix operator*(const Matrix& left, const Matrix& right)
1750 {
1751 Matrix product(right);
1752 product.MultiplyChecked(left);
1753 return product;
1754 }
1755
1756 public Matrix Rotate(const Matrix& m, float angle)
1757 {
1758 Matrix rm(m);
1759 rm.RotateChecked(angle);
1760 return rm;
1761 }
1762
1763 public Matrix RotateAt(const Matrix& m, float angle, const PointF& center)
1764 {
1765 Matrix rm(m);
1766 rm.RotateAtChecked(angle, center);
1767 return rm;
1768 }
1769
1770 public Matrix Scale(const Matrix& m, float scaleX, float scaleY)
1771 {
1772 Matrix sm(m);
1773 sm.ScaleChecked(scaleX, scaleY);
1774 return sm;
1775 }
1776
1777 public Matrix Shear(const Matrix& m, float shearX, float shearY)
1778 {
1779 Matrix sm(m);
1780 sm.ShearChecked(shearX, shearY);
1781 return sm;
1782 }
1783
1784 public Matrix Translate(const Matrix& m, float offsetX, float offsetY)
1785 {
1786 Matrix tm(m);
1787 tm.TranslateChecked(offsetX, offsetY);
1788 return tm;
1789 }
1790
1791 public Matrix Invert(const Matrix& m)
1792 {
1793 Matrix im(m);
1794 im.InvertChecked();
1795 return im;
1796 }
1797
1798 public enum GraphicsState : uint
1799 {
1800 state = 0u
1801 }
1802
1803 public enum SmoothingMode : int
1804 {
1805 invalid = -1,
1806 default_ = 0,
1807 highSpeed = 1,
1808 highQuality = 2,
1809 none = 3,
1810 antiAlias = 4
1811 }
1812
1813 public enum ColorAdjustType : int
1814 {
1815 default_ = 0,
1816 bitmap = 1,
1817 brush = 2,
1818 pen = 3,
1819 text = 4,
1820 count = 5,
1821 any = 6
1822 }
1823
1824 public class ImageAttributes
1825 {
1826 public ImageAttributes() : nativeImageAttributes(WinGraphicsCreateDefaultImageAttributes())
1827 {
1828 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsImageAttributesGetLastStatus(nativeImageAttributes)));
1829 }
1830 public ImageAttributes(const ImageAttributes& that) : nativeImageAttributes(WinGraphicsCloneImageAttributes(that.nativeImageAttributes))
1831 {
1832 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsImageAttributesGetLastStatus(nativeImageAttributes)));
1833 }
1834 public nothrow ImageAttributes(ImageAttributes&& that) : nativeImageAttributes(that.nativeImageAttributes)
1835 {
1836 that.nativeImageAttributes = null;
1837 }
1838 public void operator=(const ImageAttributes& that)
1839 {
1840 if (nativeImageAttributes != that.nativeImageAttributes)
1841 {
1842 if (that.nativeImageAttributes != null)
1843 {
1844 WinGraphicsDeleteImageAttributes(that.nativeImageAttributes);
1845 }
1846 nativeImageAttributes = WinGraphicsCloneImageAttributes(that.nativeImageAttributes);
1847 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsImageAttributesGetLastStatus(nativeImageAttributes)));
1848 }
1849 }
1850 public default nothrow void operator=(ImageAttributes&&);
1851 public ~ImageAttributes()
1852 {
1853 if (nativeImageAttributes != null)
1854 {
1855 WinGraphicsDeleteImageAttributes(nativeImageAttributes);
1856 }
1857 }
1858 public nothrow GraphicsStatus SetColorKey(const Color& colorLow, const Color& colorHigh, ColorAdjustType type)
1859 {
1860 return cast<GraphicsStatus>(WinGraphicsImageAttributesSetColorKey(nativeImageAttributes, colorLow.alpha, colorLow.red, colorLow.green, colorLow.blue,
1861 colorHigh.alpha, colorHigh.red, colorHigh.green, colorHigh.blue, cast<int>(type)));
1862 }
1863 public void SetColorKeyChecked(const Color& colorLow, const Color& colorHigh, ColorAdjustType type)
1864 {
1865 CheckGraphicsStatus(cast<GraphicsStatus>(SetColorKey(colorLow, colorHigh, type)));
1866 }
1867 public nothrow void* NativeImageAttributes() const
1868 {
1869 return nativeImageAttributes;
1870 }
1871 private void* nativeImageAttributes;
1872 }
1873
1874 public class Graphics
1875 {
1876 public nothrow Graphics() : nativeGraphics(null)
1877 {
1878 }
1879 public Graphics(void* hdc) : nativeGraphics(WinCreateGraphics(hdc))
1880 {
1881 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsGetLastStatus(nativeGraphics)));
1882 }
1883 public Graphics(const NativeHandle& nativeHandle) : nativeGraphics(nativeHandle.handle)
1884 {
1885 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsGetLastStatus(nativeGraphics)));
1886 }
1887 public static Graphics FromWindowHandle(void* windowHandle)
1888 {
1889 NativeHandle nativeHandle = WinCreateGraphicsFromWindowHandle(windowHandle);
1890 return Graphics(nativeHandle);
1891 }
1892 public static Graphics FromImage(const Image& image)
1893 {
1894 NativeHandle nativeHandle = WinCreateGraphicsFromImage(image.NativeImage());
1895 return Graphics(nativeHandle);
1896 }
1897 suppress Graphics(const Graphics&);
1898 public nothrow Graphics(Graphics&& that) : nativeGraphics(that.nativeGraphics)
1899 {
1900 that.nativeGraphics = null;
1901 }
1902 suppress void operator=(const Graphics&);
1903 public default nothrow void operator=(Graphics&&);
1904 public ~Graphics()
1905 {
1906 if (nativeGraphics != null)
1907 {
1908 WinDeleteGraphics(nativeGraphics);
1909 }
1910 }
1911 public nothrow void* GetHDC() const
1912 {
1913 return WinGraphicsGetHDC(nativeGraphics);
1914 }
1915 public nothrow GraphicsStatus DrawLine(const Pen& pen, const Point& start, const Point& end)
1916 {
1917 return cast<GraphicsStatus>(WinGraphicsDrawLine(nativeGraphics, pen.NativePen(), start.x, start.y, end.x, end.y));
1918 }
1919 public void DrawLineChecked(const Pen& pen, const Point& start, const Point& end)
1920 {
1921 CheckGraphicsStatus(DrawLine(pen, start, end));
1922 }
1923 public nothrow GraphicsStatus DrawLine(const Pen& pen, const PointF& start, const PointF& end)
1924 {
1925 return cast<GraphicsStatus>(WinGraphicsDrawLineF(nativeGraphics, pen.NativePen(), start.x, start.y, end.x, end.y));
1926 }
1927 public void DrawLineChecked(const Pen& pen, const PointF& start, const PointF& end)
1928 {
1929 CheckGraphicsStatus(DrawLine(pen, start, end));
1930 }
1931 public nothrow GraphicsStatus DrawLines(const Pen& pen, int numPoints, const Point* points)
1932 {
1933 return cast<GraphicsStatus>(WinGraphicsDrawLines(nativeGraphics, pen.NativePen(), numPoints, points));
1934 }
1935 public void DrawLinesChecked(const Pen& pen, int numPoints, const Point* points)
1936 {
1937 CheckGraphicsStatus(DrawLines(pen, numPoints, points));
1938 }
1939 public nothrow GraphicsStatus DrawLines(const Pen& pen, int numPoints, const PointF* points)
1940 {
1941 return cast<GraphicsStatus>(WinGraphicsDrawLinesF(nativeGraphics, pen.NativePen(), numPoints, points));
1942 }
1943 public void DrawLinesChecked(const Pen& pen, int numPoints, const PointF* points)
1944 {
1945 CheckGraphicsStatus(DrawLines(pen, numPoints, points));
1946 }
1947 public nothrow GraphicsStatus DrawString(const string& str, const Font& font, const PointF& origin, const Brush& brush)
1948 {
1949 return cast<GraphicsStatus>(WinGraphicsDrawString(nativeGraphics, str.Chars(), font.NativeFont(), origin.x, origin.y, brush.NativeBrush()));
1950 }
1951 public void DrawStringChecked(const string& str, const Font& font, const PointF& origin, const Brush& brush)
1952 {
1953 CheckGraphicsStatus(DrawString(str, font, origin, brush));
1954 }
1955 public nothrow GraphicsStatus DrawString(const string& str, const Font& font, const PointF& origin, const StringFormat& format, const Brush& brush)
1956 {
1957 return cast<GraphicsStatus>(WinGraphicsDrawStringFormatPoint(nativeGraphics, str.Chars(), font.NativeFont(),
1958 origin.x, origin.y, format.NativeFormat(), brush.NativeBrush()));
1959 }
1960 public void DrawStringChecked(const string& str, const Font& font, const PointF& origin, const StringFormat& format, const Brush& brush)
1961 {
1962 CheckGraphicsStatus(DrawString(str, font, origin, format, brush));
1963 }
1964 public nothrow GraphicsStatus DrawString(const string& str, const Font& font, const RectF& rect, const StringFormat& format, const Brush& brush)
1965 {
1966 return cast<GraphicsStatus>(WinGraphicsDrawStringFormatRect(nativeGraphics, str.Chars(), font.NativeFont(),
1967 rect.location.x, rect.location.y, rect.size.w, rect.size.h,
1968 format.NativeFormat(), brush.NativeBrush()));
1969 }
1970 public void DrawStringChecked(const string& str, const Font& font, const RectF& rect, const StringFormat& format, const Brush& brush)
1971 {
1972 CheckGraphicsStatus(DrawString(str, font, rect, format, brush));
1973 }
1974 public nothrow GraphicsStatus MeasureString(const string& str, const Font& font, const SizeF& layoutRectSize, const StringFormat& format,
1975 SizeF& size, int* codePointsFitted, int* linesFilled)
1976 {
1977 return cast<GraphicsStatus>(WinGraphicsMeasureStringFormatSize(nativeGraphics, str.Chars(), font.NativeFont(),
1978 layoutRectSize.w, layoutRectSize.h, format.NativeFormat(),
1979 size.w, size.h, codePointsFitted, linesFilled));
1980 }
1981 public SizeF MeasureStringChecked(const string& str, const Font& font, const SizeF& layoutRectSize, const StringFormat& format, int* codePointsFitted, int* linesFilled)
1982 {
1983 SizeF size;
1984 CheckGraphicsStatus(MeasureString(str, font, layoutRectSize, format, size, codePointsFitted, linesFilled));
1985 return size;
1986 }
1987 public nothrow GraphicsStatus MeasureString(const string& str, const Font& font, const SizeF& layoutRectSize, const StringFormat& format, SizeF& size)
1988 {
1989 return cast<GraphicsStatus>(WinGraphicsMeasureStringFormatSize(nativeGraphics, str.Chars(), font.NativeFont(),
1990 layoutRectSize.w, layoutRectSize.h, format.NativeFormat(),
1991 size.w, size.h, null, null));
1992 }
1993 public SizeF MeasureStringChecked(const string& str, const Font& font, const SizeF& layoutRectSize, const StringFormat& format)
1994 {
1995 SizeF size;
1996 CheckGraphicsStatus(MeasureString(str, font, layoutRectSize, format, size));
1997 return size;
1998 }
1999 public nothrow GraphicsStatus MeasureString(const string& str, const Font& font, const RectF& layoutRect, const StringFormat& format,
2000 RectF& boundingBox, int* codePointsFitted, int* linesFilled)
2001 {
2002 return cast<GraphicsStatus>(WinGraphicsMeasureStringFormatRect(nativeGraphics, str.Chars(), font.NativeFont(),
2003 layoutRect.location.x, layoutRect.location.y, layoutRect.size.w, layoutRect.size.h, format.NativeFormat(),
2004 boundingBox.location.x, boundingBox.location.y, boundingBox.size.w, boundingBox.size.h,
2005 codePointsFitted, linesFilled));
2006 }
2007 public RectF MeasureStringChecked(const string& str, const Font& font, const RectF& layoutRect, const StringFormat& format, int* codePointsFitted, int* linesFilled)
2008 {
2009 RectF boundingBox;
2010 CheckGraphicsStatus(MeasureString(str, font, layoutRect, format, boundingBox, codePointsFitted, linesFilled));
2011 return boundingBox;
2012 }
2013 public nothrow GraphicsStatus MeasureString(const string& str, const Font& font, const RectF& layoutRect, const StringFormat& format, RectF& boundingBox)
2014 {
2015 return cast<GraphicsStatus>(WinGraphicsMeasureStringFormatRect(nativeGraphics, str.Chars(), font.NativeFont(),
2016 layoutRect.location.x, layoutRect.location.y, layoutRect.size.w, layoutRect.size.h, format.NativeFormat(),
2017 boundingBox.location.x, boundingBox.location.y, boundingBox.size.w, boundingBox.size.h,
2018 null, null));
2019 }
2020 public RectF MeasureStringChecked(const string& str, const Font& font, const RectF& layoutRect, const StringFormat& format)
2021 {
2022 RectF boundingBox;
2023 CheckGraphicsStatus(MeasureString(str, font, layoutRect, format, boundingBox));
2024 return boundingBox;
2025 }
2026 public nothrow GraphicsStatus MeasureString(const string& str, const Font& font, const PointF& origin, const StringFormat& format, RectF& boundingBox)
2027 {
2028 return cast<GraphicsStatus>(WinGraphicsMeasureStringFormatPoint(nativeGraphics, str.Chars(), font.NativeFont(), origin.x, origin.y, format.NativeFormat(),
2029 boundingBox.location.x, boundingBox.location.y, boundingBox.size.w, boundingBox.size.h));
2030 }
2031 public RectF MeasureStringChecked(const string& str, const Font& font, const PointF& origin, const StringFormat& format)
2032 {
2033 RectF boundingBox;
2034 CheckGraphicsStatus(MeasureString(str, font, origin, format, boundingBox));
2035 return boundingBox;
2036 }
2037 public nothrow TextRenderingHint GetTextRenderingHint()
2038 {
2039 return cast<TextRenderingHint>(WinGraphicsGetTextRenderingHint(nativeGraphics));
2040 }
2041 public nothrow GraphicsStatus SetTextRenderingHint(TextRenderingHint textRenderingHint)
2042 {
2043 return cast<GraphicsStatus>(WinGraphicsSetTextRenderingHint(nativeGraphics, cast<int>(textRenderingHint)));
2044 }
2045 public void SetTextRenderingHintChecked(TextRenderingHint textRenderingHint)
2046 {
2047 CheckGraphicsStatus(SetTextRenderingHint(textRenderingHint));
2048 }
2049 public nothrow GraphicsStatus Clear(const Color& color)
2050 {
2051 return cast<GraphicsStatus>(WinGraphicsClear(nativeGraphics, color.alpha, color.red, color.green, color.blue));
2052 }
2053 public void ClearChecked(const Color& color)
2054 {
2055 CheckGraphicsStatus(Clear(color));
2056 }
2057 public nothrow GraphicsStatus DrawRectangle(const Pen& pen, const Rect& rect)
2058 {
2059 return cast<GraphicsStatus>(WinGraphicsDrawRectangle(nativeGraphics, pen.NativePen(), rect.location.x, rect.location.y, rect.size.w, rect.size.h));
2060 }
2061 public void DrawRectangleChecked(const Pen& pen, const Rect& rect)
2062 {
2063 CheckGraphicsStatus(DrawRectangle(pen, rect));
2064 }
2065 public nothrow GraphicsStatus DrawRectangle(const Pen& pen, const RectF& rect)
2066 {
2067 return cast<GraphicsStatus>(WinGraphicsDrawRectangleF(nativeGraphics, pen.NativePen(), rect.location.x, rect.location.y, rect.size.w, rect.size.h));
2068 }
2069 public void DrawRectangleChecked(const Pen& pen, const RectF& rect)
2070 {
2071 CheckGraphicsStatus(DrawRectangle(pen, rect));
2072 }
2073 public nothrow GraphicsStatus FillRectangle(const Brush& brush, const Rect& rect)
2074 {
2075 return cast<GraphicsStatus>(WinGraphicsFillRectangle(nativeGraphics, brush.NativeBrush(), rect.location.x, rect.location.y, rect.size.w, rect.size.h));
2076 }
2077 public void FillRectangleChecked(const Brush& brush, const Rect& rect)
2078 {
2079 CheckGraphicsStatus(FillRectangle(brush, rect));
2080 }
2081 public nothrow GraphicsStatus FillRectangle(const Brush& brush, const RectF& rect)
2082 {
2083 return cast<GraphicsStatus>(WinGraphicsFillRectangleF(nativeGraphics, brush.NativeBrush(), rect.location.x, rect.location.y, rect.size.w, rect.size.h));
2084 }
2085 public void FillRectangleChecked(const Brush& brush, const RectF& rect)
2086 {
2087 CheckGraphicsStatus(FillRectangle(brush, rect));
2088 }
2089 public nothrow GraphicsStatus FillPolygon(const Brush& brush, int numPoints, const Point* points)
2090 {
2091 return cast<GraphicsStatus>(WinGraphicsFillPolygon(nativeGraphics, brush.NativeBrush(), numPoints, points));
2092 }
2093 public void FillPolygonChecked(const Brush& brush, int numPoints, const Point* points)
2094 {
2095 CheckGraphicsStatus(FillPolygon(brush, numPoints, points));
2096 }
2097 public nothrow GraphicsStatus FillPolygon(const Brush& brush, int numPoints, const PointF* points)
2098 {
2099 return cast<GraphicsStatus>(WinGraphicsFillPolygonF(nativeGraphics, brush.NativeBrush(), numPoints, points));
2100 }
2101 public void FillPolygonChecked(const Brush& brush, int numPoints, const PointF* points)
2102 {
2103 CheckGraphicsStatus(FillPolygon(brush, numPoints, points));
2104 }
2105 public nothrow GraphicsStatus DrawArc(const Pen& pen, const RectF& rect, float startAngle, float sweepAngle)
2106 {
2107 return cast<GraphicsStatus>(WinGraphicsDrawArc(nativeGraphics, pen.NativePen(), rect.location.x, rect.location.y, rect.size.w, rect.size.h, startAngle, sweepAngle));
2108 }
2109 public void DrawArcChecked(const Pen& pen, const RectF& rect, float startAngle, float sweepAngle)
2110 {
2111 CheckGraphicsStatus(DrawArc(pen, rect, startAngle, sweepAngle));
2112 }
2113 public nothrow GraphicsStatus DrawEllipse(const Pen& pen, const RectF& rect)
2114 {
2115 return cast<GraphicsStatus>(WinGraphicsDrawEllipse(nativeGraphics, pen.NativePen(), rect.location.x, rect.location.y, rect.size.w, rect.size.h));
2116 }
2117 public void DrawEllipseChecked(const Pen& pen, const RectF& rect)
2118 {
2119 CheckGraphicsStatus(DrawEllipse(pen, rect));
2120 }
2121 public nothrow GraphicsStatus FillEllipse(const Brush& brush, const RectF& rect)
2122 {
2123 return cast<GraphicsStatus>(WinGraphicsFillEllipse(nativeGraphics, brush.NativeBrush(), rect.location.x, rect.location.y, rect.size.w, rect.size.h));
2124 }
2125 public void FillEllipseChecked(const Brush& brush, const RectF& rect)
2126 {
2127 CheckGraphicsStatus(FillEllipse(brush, rect));
2128 }
2129 public nothrow GraphicsStatus DrawImage(const Image& image, const PointF& point)
2130 {
2131 return cast<GraphicsStatus>(WinGraphicsDrawImagePoint(nativeGraphics, image.NativeImage(), point.x, point.y));
2132 }
2133 public void DrawImageChecked(const Image& image, const PointF& point)
2134 {
2135 CheckGraphicsStatus(DrawImage(image, point));
2136 }
2137 public nothrow GraphicsStatus DrawImage(const Image& image, const RectF& rect)
2138 {
2139 return cast<GraphicsStatus>(WinGraphicsDrawImageRect(nativeGraphics, image.NativeImage(), rect.location.x, rect.location.y, rect.size.w, rect.size.h));
2140 }
2141 public void DrawImageChecked(const Image& image, const RectF& rect)
2142 {
2143 CheckGraphicsStatus(DrawImage(image, rect));
2144 }
2145 public nothrow GraphicsStatus DrawImage(const Image& image, const Rect& destRect, int srcX, int srcY, int srcW, int srcH, Unit srcUnit, const ImageAttributes& attributes)
2146 {
2147 return cast<GraphicsStatus>(WinGraphicsDrawImageWithAttributes(nativeGraphics, image.NativeImage(), destRect.location.x, destRect.location.y, destRect.size.w, destRect.size.h,
2148 srcX, srcY, srcW, srcH, srcUnit, attributes.NativeImageAttributes()));
2149 }
2150 public void DrawImageChecked(const Image& image, const Rect& destRect, int srcX, int srcY, int srcW, int srcH, Unit srcUnit, const ImageAttributes& attributes)
2151 {
2152 CheckGraphicsStatus(DrawImage(image, destRect, srcX, srcY, srcW, srcH, srcUnit, attributes));
2153 }
2154 public nothrow GraphicsStatus DrawImage(const Image& image, const RectF& destRect, const RectF& sourceRect, Unit srcUnit, const ImageAttributes& attributes)
2155 {
2156 return cast<GraphicsStatus>(WinGraphicsDrawImageWithAttributesF(nativeGraphics, image.NativeImage(), destRect.location.x, destRect.location.y, destRect.size.w, destRect.size.h,
2157 sourceRect.location.x, sourceRect.location.y, sourceRect.size.w, sourceRect.size.h, srcUnit, attributes.NativeImageAttributes()));
2158 }
2159 public void DrawImageChecked(const Image& image, const RectF& destRect, const RectF& sourceRect, Unit srcUnit, const ImageAttributes& attributes)
2160 {
2161 CheckGraphicsStatus(DrawImage(image, destRect, sourceRect, srcUnit, attributes));
2162 }
2163 public nothrow GraphicsStatus GetClip(Region& region)
2164 {
2165 return cast<GraphicsStatus>(WinGraphicsGetClip(nativeGraphics, region.NativeRegion()));
2166 }
2167 public Region GetClipChecked()
2168 {
2169 Region region;
2170 CheckGraphicsStatus(GetClip(region));
2171 return region;
2172 }
2173 public nothrow GraphicsStatus SetClip(const Rect& rect, CombineMode combineMode)
2174 {
2175 return cast<GraphicsStatus>(WinGraphicsSetClipRect(nativeGraphics, rect.location.x, rect.location.y, rect.size.w, rect.size.h, combineMode));
2176 }
2177 public nothrow GraphicsStatus SetClip(const Rect& rect)
2178 {
2179 return cast<GraphicsStatus>(WinGraphicsSetClipRect(nativeGraphics, rect.location.x, rect.location.y, rect.size.w, rect.size.h, CombineMode.replace));
2180 }
2181 public void SetClipChecked(const Rect& rect, CombineMode combineMode)
2182 {
2183 CheckGraphicsStatus(SetClip(rect, combineMode));
2184 }
2185 public void SetClipChecked(const Rect& rect)
2186 {
2187 CheckGraphicsStatus(SetClip(rect, CombineMode.replace));
2188 }
2189 public nothrow GraphicsStatus SetClip(const Region& region)
2190 {
2191 return cast<GraphicsStatus>(WinGraphicsSetClipRegion(nativeGraphics, region.NativeRegion()));
2192 }
2193 public void SetClipChecked(const Region& region)
2194 {
2195 CheckGraphicsStatus(SetClip(region));
2196 }
2197 public nothrow GraphicsState Save()
2198 {
2199 return cast<GraphicsState>(WinGraphicsSave(nativeGraphics));
2200 }
2201 public GraphicsState SaveChecked()
2202 {
2203 GraphicsState state = Save();
2204 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsGetLastStatus(nativeGraphics)));
2205 return state;
2206 }
2207 public nothrow GraphicsStatus Restore(GraphicsState graphicsState)
2208 {
2209 return cast<GraphicsStatus>(WinGraphicsRestore(nativeGraphics, cast<uint>(graphicsState)));
2210 }
2211 public void RestoreChecked(GraphicsState graphicsState)
2212 {
2213 CheckGraphicsStatus(Restore(graphicsState));
2214 }
2215 public nothrow GraphicsStatus GetTransform(Matrix& m)
2216 {
2217 return cast<GraphicsStatus>(WinGraphicsGetTransform(nativeGraphics, m.NativeMatrix()));
2218 }
2219 public void GetTransformChecked(Matrix& m)
2220 {
2221 CheckGraphicsStatus(GetTransform(m));
2222 }
2223 public nothrow GraphicsStatus SetTransform(Matrix& m)
2224 {
2225 return cast<GraphicsStatus>(WinGraphicsSetTransform(nativeGraphics, m.NativeMatrix()));
2226 }
2227 public void SetTransformChecked(Matrix& m)
2228 {
2229 CheckGraphicsStatus(SetTransform(m));
2230 }
2231 public nothrow GraphicsStatus MultiplyTransform(const Matrix& matrix, MatrixOrder order)
2232 {
2233 return cast<GraphicsStatus>(WinGraphicsMultiplyTransform(nativeGraphics, matrix.NativeMatrix(), cast<int>(order)));
2234 }
2235 public void MultiplyTransformChecked(const Matrix& matrix, MatrixOrder order)
2236 {
2237 CheckGraphicsStatus(MultiplyTransform(matrix, order));
2238 }
2239 public nothrow GraphicsStatus MultiplyTransform(const Matrix& matrix)
2240 {
2241 return MultiplyTransform(matrix, MatrixOrder.prepend);
2242 }
2243 public void MultiplyTransformChecked(const Matrix& matrix)
2244 {
2245 CheckGraphicsStatus(MultiplyTransform(matrix));
2246 }
2247 public nothrow GraphicsStatus ResetTransform()
2248 {
2249 return cast<GraphicsStatus>(WinGraphicsResetTransform(nativeGraphics));
2250 }
2251 public void ResetTransformChecked()
2252 {
2253 CheckGraphicsStatus(ResetTransform());
2254 }
2255 public nothrow GraphicsStatus RotateTransform(float angle, MatrixOrder order)
2256 {
2257 return cast<GraphicsStatus>(WinGraphicsRotateTransform(nativeGraphics, angle, cast<int>(order)));
2258 }
2259 public void RotateTransformChecked(float angle, MatrixOrder order)
2260 {
2261 CheckGraphicsStatus(RotateTransform(angle, order));
2262 }
2263 public nothrow GraphicsStatus RotateTransform(float angle)
2264 {
2265 return RotateTransform(angle, MatrixOrder.prepend);
2266 }
2267 public void RotateTransformChecked(float angle)
2268 {
2269 RotateTransformChecked(angle, MatrixOrder.prepend);
2270 }
2271 public nothrow GraphicsStatus ScaleTransform(float scaleX, float scaleY, MatrixOrder order)
2272 {
2273 return cast<GraphicsStatus>(WinGraphicsScaleTransform(nativeGraphics, scaleX, scaleY, cast<int>(order)));
2274 }
2275 public void ScaleTransformChecked(float scaleX, float scaleY, MatrixOrder order)
2276 {
2277 CheckGraphicsStatus(ScaleTransform(scaleX, scaleY, order));
2278 }
2279 public nothrow GraphicsStatus ScaleTransform(float scaleX, float scaleY)
2280 {
2281 return ScaleTransform(scaleX, scaleY, MatrixOrder.prepend);
2282 }
2283 public void ScaleTransformChecked(float scaleX, float scaleY)
2284 {
2285 ScaleTransformChecked(scaleX, scaleY, MatrixOrder.prepend);
2286 }
2287 public nothrow GraphicsStatus TranslateTransform(float offsetX, float offsetY, MatrixOrder order)
2288 {
2289 return cast<GraphicsStatus>(WinGraphicsTranslateTransform(nativeGraphics, offsetX, offsetY, cast<int>(order)));
2290 }
2291 public void TranslateTransformChecked(float offsetX, float offsetY, MatrixOrder order)
2292 {
2293 CheckGraphicsStatus(TranslateTransform(offsetX, offsetY, order));
2294 }
2295 public nothrow GraphicsStatus TranslateTransform(float offsetX, float offsetY)
2296 {
2297 return TranslateTransform(offsetX, offsetY, MatrixOrder.prepend);
2298 }
2299 public void TranslateTransformChecked(float offsetX, float offsetY)
2300 {
2301 TranslateTransformChecked(offsetX, offsetY, MatrixOrder.prepend);
2302 }
2303 public nothrow Unit GetPageUnit()
2304 {
2305 return cast<Unit>(WinGraphicsGetPageUnit(nativeGraphics));
2306 }
2307 public Unit GetPageUnitChecked()
2308 {
2309 Unit unit = GetPageUnit();
2310 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsGetLastStatus(nativeGraphics)));
2311 return unit;
2312 }
2313 public nothrow GraphicsStatus SetPageUnit(Unit unit)
2314 {
2315 return cast<GraphicsStatus>(WinGraphicsSetPageUnit(nativeGraphics, cast<int>(unit)));
2316 }
2317 public void SetPageUnitChecked(Unit unit)
2318 {
2319 CheckGraphicsStatus(SetPageUnit(unit));
2320 }
2321 public nothrow float GetPageScale()
2322 {
2323 return WinGraphicsGetPageScale(nativeGraphics);
2324 }
2325 public float GetPageScaleChecked()
2326 {
2327 float scale = GetPageScale();
2328 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsGetLastStatus(nativeGraphics)));
2329 return scale;
2330 }
2331 public nothrow GraphicsStatus SetPageScale(float scale)
2332 {
2333 return cast<GraphicsStatus>(WinGraphicsSetPageScale(nativeGraphics, scale));
2334 }
2335 public void SetPageScaleChecked(float scale)
2336 {
2337 CheckGraphicsStatus(SetPageScale(scale));
2338 }
2339 public nothrow float GetDpiX()
2340 {
2341 return WinGraphicsGetDpiX(nativeGraphics);
2342 }
2343 public nothrow float GetDpiY()
2344 {
2345 return WinGraphicsGetDpiY(nativeGraphics);
2346 }
2347 public nothrow SmoothingMode GetSmoothingMode()
2348 {
2349 return cast<SmoothingMode>(WinGraphicsGetSmoothingMode(nativeGraphics));
2350 }
2351 public SmoothingMode GetSmoothingModeChecked()
2352 {
2353 SmoothingMode smoothingMode = GetSmoothingMode();
2354 CheckGraphicsStatus(cast<GraphicsStatus>(WinGraphicsGetLastStatus(nativeGraphics)));
2355 return smoothingMode;
2356 }
2357 public nothrow GraphicsStatus SetSmoothingMode(SmoothingMode smoothingMode)
2358 {
2359 return cast<GraphicsStatus>(WinGraphicsSetSmoothingMode(nativeGraphics, smoothingMode));
2360 }
2361 public void SetSmoothingModeChecked(SmoothingMode smoothingMode)
2362 {
2363 CheckGraphicsStatus(SetSmoothingMode(smoothingMode));
2364 }
2365 public inline nothrow const void* NativeGraphics() const
2366 {
2367 return nativeGraphics;
2368 }
2369 private void* nativeGraphics;
2370 }
2371 }
2372