YSTest: YGDIBase.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

YGDIBase.h
浏览该文件的文档.
1 /*
2 © 2011-2016, 2018-2020 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YSL_INC_Core_YGDIBase_h_
29 #define YSL_INC_Core_YGDIBase_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YCoreUtilities // for octet, size_t, Pixel,
33 // ystdex::min, ystdex::max, YSLib::HalfDifference;
34 #include <limits>
35 #include <ystdex/operators.hpp> // for ystdex::equality_comparable;
36 #include <ystdex/string.hpp> // for ystdex::quote;
37
38 namespace YSLib
39 {
40
41 namespace Drawing
42 {
43
45
46 using MonoType = octet;
49 using AlphaType = octet;
51
58 template<size_t>
59 struct ComponentTraits;
60
61 template<>
62 struct ComponentTraits<8>
63 {
64 template<typename _type>
65 YB_ATTR_nodiscard YB_STATELESS static yconstfn _type
66 Saturate(_type v) ynothrow
67 {
68 return v;
69 }
70 };
71
72 template<>
73 struct ComponentTraits<1>
74 {
75 template<typename _type>
76 YB_ATTR_nodiscard YB_STATELESS static yconstfn _type
77 Saturate(_type v) ynothrow
78 {
79 return bool(v) ? 0xFF : 0x00;
80 }
81 };
83
84
86
87
91 YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(Pixel, FetchOpaque, Pixel px)
92 ynothrow
93 ImplRet(px.Integer | Pixel::traits_type::mask<Pixel::CMap::A>::value)
94
95
100 YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(AlphaType, PixelToAlpha, Pixel px)
101 ynothrow
102 ImplRet(ComponentTraits<Pixel::AWidth::value>::Saturate(px))
103
104 // TODO: RGB componenets are not saturated as A components for non 8-bit
105 // components. Consider make them consistent?
106 YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(MonoType, PixelToBlue, Pixel px)
107 ynothrow
108 ImplRet(px.GetB() << (8 - Pixel::BWidth::value))
109
110 YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(MonoType, PixelToGreen, Pixel px)
111 ynothrow
112 ImplRet(px.GetG() << (8 - Pixel::GWidth::value))
113
114 YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(MonoType, PixelToRed, Pixel px)
115 ynothrow
116 ImplRet(px.GetR() << (8 - Pixel::RWidth::value))
118
125 template<size_t _vCMapIndex>
126 YB_ATTR_nodiscard YB_STATELESS yconstfn Pixel::IntegerType
127 CompositePixelByCMapIndex(Pixel::IntegerType v) ynothrow
128 {
129 using PixelTratis = Pixel::traits_type;
130
131 // XXX: Only alpha is saturated.
132 return v >> (_vCMapIndex == Pixel::CMap::A ? 0 : 8 - PixelTratis
133 ::component_width<_vCMapIndex>::value)
134 << PixelTratis::shift<_vCMapIndex>::value;
135 }
137
138
143 class YF_API Color
144 {
145 private:
147 template<size_t _vCMapIndex>
148 using PixelShift = Pixel::traits_type::shift<_vCMapIndex>;
149
154 MonoType r = 0, g = 0, b = 0;
159 AlphaType a = 0;
160
161 public:
166 yconstfn
167 Color() = default;
172 yconstfn
173 Color(Pixel px) ynothrow
174 : r(PixelToRed(px)), g(PixelToGreen(px)), b(PixelToBlue(px)),
175 a(PixelToAlpha(px))
176 {}
181 template<typename _type, typename = yimpl(
182 ystdex::enable_if_t<ystdex::and_<std::is_enum<_type>, std::is_same<
183 ystdex::underlying_cond_type_t<_type>, Pixel::IntegerType>>::value>)>
184 yconstfn
185 Color(_type cs) ynothrow
186 : Color(Pixel(cs))
187 {}
192 yconstfn
193 Color(MonoType r_, MonoType g_, MonoType b_, AlphaType a_ = 0xFF) ynothrow
194 : r(r_), g(g_), b(b_), a(a_)
195 {}
201 template<typename _tScalar>
202 yconstfn
203 Color(_tScalar r_, _tScalar g_, _tScalar b_, AlphaType a_ = 0xFF) ynothrow
204 : Color(MonoType(r_), MonoType(g_), MonoType(b_), a_)
205 {}
206
211 yconstfn DefCvt(const ynothrow, Pixel,
212 CompositePixelByCMapIndex<Pixel::CMap::A>(a)
213 | CompositePixelByCMapIndex<Pixel::CMap::B>(b)
214 | CompositePixelByCMapIndex<Pixel::CMap::G>(g)
215 | CompositePixelByCMapIndex<Pixel::CMap::R>(r))
216
217
221 yconstfn DefGetter(const ynothrow, MonoType, A, a)
226 yconstfn DefGetter(const ynothrow, MonoType, B, b)
231 yconstfn DefGetter(const ynothrow, MonoType, G, g)
236 yconstfn DefGetter(const ynothrow, MonoType, R, r)
237 };
238
239
244 namespace ColorSpace
245 {
246
247 #define YSL_Impl_YSL_Impl_DefColorH_(hex, name) \
248 name = Pixel::IntegerType(Pixel(Color(MonoType(((hex) >> 16) & 0xFF), \
249 MonoType(((hex) >> 8) & 0xFF), MonoType((hex) & 0xFF))))
250 #define YSL_Impl_0x(hex) 0x##hex
251 #define YSL_Impl_DefColorH(hex_, name) \
252 YSL_Impl_YSL_Impl_DefColorH_(YSL_Impl_0x(hex_), name)
253
259 enum ColorSet : Pixel::IntegerType
260 {
261 YSL_Impl_DefColorH(00FFFF, Aqua),
262 YSL_Impl_DefColorH(000000, Black),
263 YSL_Impl_DefColorH(0000FF, Blue),
264 YSL_Impl_DefColorH(FF00FF, Fuchsia),
265 YSL_Impl_DefColorH(808080, Gray),
266 YSL_Impl_DefColorH(008000, Green),
267 YSL_Impl_DefColorH(00FF00, Lime),
268 YSL_Impl_DefColorH(800000, Maroon),
269 YSL_Impl_DefColorH(000080, Navy),
270 YSL_Impl_DefColorH(808000, Olive),
271 YSL_Impl_DefColorH(800080, Purple),
272 YSL_Impl_DefColorH(FF0000, Red),
273 YSL_Impl_DefColorH(C0C0C0, Silver),
274 YSL_Impl_DefColorH(008080, Teal),
275 YSL_Impl_DefColorH(FFFFFF, White),
276 YSL_Impl_DefColorH(FFFF00, Yellow)
277 };
278
279 #undef YSL_Impl_DefColorH
280 #undef YSL_Impl_YSL_Impl_DefColorH_
281 #undef YSL_Impl_0x
282 } // namespace ColorSpace;
283
284 class Size;
285 class Rect;
286
287
293 template<typename _type>
294 class GBinaryGroup : private ystdex::equality_comparable<GBinaryGroup<_type>>
295 {
297 static_assert(ystdex::is_nothrow_copyable<_type>(),
298 "Invalid type found.");
299
300 public:
302 static const GBinaryGroup Invalid;
303
305 _type X = 0, Y = 0;
306
312 yconstfn DefDeCtor(GBinaryGroup)
316 yconstfn DefDeCopyCtor(GBinaryGroup)
321 explicit yconstfn
322 GBinaryGroup(const Size&) ynothrow;
327 explicit yconstfn
328 GBinaryGroup(const Rect&) ynothrow;
336 template<typename _tScalar1, typename _tScalar2>
337 yconstfn
338 GBinaryGroup(_tScalar1 x, _tScalar2 y) ynothrow
339 : X(_type(x)), Y(_type(y))
340 {}
346 template<typename _tPair>
347 yconstfn
348 GBinaryGroup(const _tPair& pr) ynothrow
349 : X(std::get<0>(pr)), Y(std::get<1>(pr))
350 {}
351
353 DefDeCopyAssignment(GBinaryGroup)
354
355
359 YB_ATTR_nodiscard YB_PURE yconstfn PDefHOp(GBinaryGroup, -, ) const ynothrow
360 ImplRet(GBinaryGroup(-X, -Y))
361
365 PDefHOp(GBinaryGroup&, +=, const GBinaryGroup& val) ynothrow
366 ImplRet(yunseq(X += val.X, Y += val.Y), *this)
370 PDefHOp(GBinaryGroup&, -=, const GBinaryGroup& val) ynothrow
371 ImplRet(yunseq(X -= val.X, Y -= val.Y), *this)
372
373 yconstfn DefGetter(const ynothrow, _type, X, X)
374 yconstfn DefGetter(const ynothrow, _type, Y, Y)
375
376 DefSetter(, _type, X, X)
377 DefSetter(, _type, Y, Y)
378
382 yconstfn DefPred(const ynothrow, Zero, X == 0 && Y == 0)
383
390 YB_ATTR_nodiscard YB_PURE PDefH(_type&, GetRef, bool b = true) ynothrow
391 ImplRet(b ? X : Y)
392 YB_ATTR_nodiscard YB_PURE PDefH(const _type&, GetRef, bool b = true) const ynothrow
393 ImplRet(b ? X : Y)
395 };
396
398
399 template<typename _type>
400 const GBinaryGroup<_type> GBinaryGroup<_type>::Invalid{
401 std::numeric_limits<_type>::lowest(), std::numeric_limits<_type>::lowest()};
402
407 template<typename _type>
408 YB_ATTR_nodiscard YB_PURE yconstfn bool
409 operator==(const GBinaryGroup<_type>& x, const GBinaryGroup<_type>& y) ynothrow
410 {
411 return x.X == y.X && x.Y == y.Y;
412 }
413
418 template<typename _type>
419 YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup<_type>
420 operator+(const GBinaryGroup<_type>& x, const GBinaryGroup<_type>& y) ynothrow
421 {
422 return GBinaryGroup<_type>(x.X + y.X, x.Y + y.Y);
423 }
424
429 template<typename _type>
430 YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup<_type>
431 operator-(const GBinaryGroup<_type>& x, const GBinaryGroup<_type>& y) ynothrow
432 {
433 return GBinaryGroup<_type>(x.X - y.X, x.Y - y.Y);
434 }
435
440 template<typename _type, typename _tScalar>
441 YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup<_type>
442 operator*(const GBinaryGroup<_type>& val, _tScalar l) ynothrow
443 {
444 return GBinaryGroup<_type>(val.X * l, val.Y * l);
445 }
446
451 template<class _tBinary>
452 YB_ATTR_nodiscard YB_PURE yconstfn _tBinary
453 Transpose(const _tBinary& obj) ynothrow
454 {
455 return _tBinary(obj.Y, obj.X);
456 }
457
459
460 template<typename _type>
462 YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup<_type>
463 TransposeCCW(const GBinaryGroup<_type>& val) ynothrow
464 {
465 return GBinaryGroup<_type>(val.Y, -val.X);
466 }
467
469 template<typename _type>
470 YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup<_type>
471 TransposeCW(const GBinaryGroup<_type>& val) ynothrow
472 {
473 return GBinaryGroup<_type>(-val.Y, val.X);
474 }
476
482 template<size_t _vIdx, typename _type>
483 YB_ATTR_nodiscard YB_PURE yconstfn _type&
484 get(GBinaryGroup<_type>& val)
485 {
486 static_assert(_vIdx < 2, "Invalid index found.");
487
488 return _vIdx == 0 ? val.X : val.Y;
489 }
490 template<size_t _vIdx, typename _type>
491 YB_ATTR_nodiscard YB_PURE yconstfn const _type&
492 get(const GBinaryGroup<_type>& val)
493 {
494 static_assert(_vIdx < 2, "Invalid index found.");
495
496 return _vIdx == 0 ? val.X : val.Y;
497 }
499
505 template<typename _type>
506 YB_ATTR_nodiscard YB_PURE std::string
507 to_string(const GBinaryGroup<_type>& val)
508 {
509 using YSLib::to_string;
510
511 return ystdex::quote(to_string(val.X) + ", " + to_string(val.Y), '(', ')');
512 }
514
515
520 using Point = GBinaryGroup<SPos>;
521
522
527 using Vec = GBinaryGroup<SPos>;
528
529
535 class YF_API Size : private ystdex::equality_comparable<Size>
536 {
537 public:
542 static const Size Invalid;
543
545 SDst Width, Height;
546
552 yconstfn
553 Size() ynothrow
554 : Width(0), Height(0)
555 {}
560 yconstfn
561 Size(const Size& s) ynothrow
562 : Width(s.Width), Height(s.Height)
563 {}
568 explicit yconstfn
569 Size(const Rect&) ynothrow;
574 template<typename _type>
575 explicit yconstfn
576 Size(const GBinaryGroup<_type>& val) ynothrow
577 : Width(static_cast< SDst>(val.X)), Height(static_cast< SDst>(val.Y))
578 {}
583 template<typename _tScalar1, typename _tScalar2>
584 yconstfn
585 Size(_tScalar1 w, _tScalar2 h) ynothrow
586 : Width(static_cast< SDst>(w)), Height(static_cast< SDst>(h))
587 {}
588
590 DefDeCopyAssignment(Size)
591
592
596 yconstfn DefBoolNeg(explicit yconstfn, Width != 0 || Height != 0)
597
598
603 PDefHOp(Size&, &=, const Size& s) ynothrow
604 ImplRet(yunseq(Width = ystdex::min(Width, s.Width),
605 Height = ystdex::min(Height, s.Height)), *this)
606
612 PDefHOp(Size&, |=, const Size& s) ynothrow
613 ImplRet(yunseq(Width = ystdex::max(Width, s.Width),
614 Height = ystdex::max(Height, s.Height)), *this)
615
620 yconstfn DefCvt(const ynothrow, Vec, Vec(Width, Height))
621
626 yconstfn DefPred(const ynothrow, LineSegment,
627 !((Width == 0) ^ (Height == 0)))
632 yconstfn DefPred(const ynothrow, UnstrictlyEmpty, Width == 0 || Height == 0)
633
640 PDefH(SDst&, GetRef, bool b = true) ynothrow
641 ImplRet(b ? Width : Height)
642 PDefH(const SDst&, GetRef, bool b = true) const ynothrow
643 ImplRet(b ? Width : Height)
645 };
646
652 YB_ATTR_nodiscard YB_PURE yconstfn PDefHOp(bool, ==, const Size& x, const Size& y)
654 ynothrow
655 ImplRet(x.Width == y.Width && x.Height == y.Height)
656
662 YB_ATTR_nodiscard YB_PURE yconstfn
663 PDefHOp(Size, &, const Size& x, const Size& y) ynothrow
664 ImplRet({ystdex::min(x.Width, y.Width), ystdex::min(x.Height, y.Height)})
665
671 YB_ATTR_nodiscard YB_PURE yconstfn
672 PDefHOp(Size, |, const Size& x, const Size& y) ynothrow
673 ImplRet({ystdex::max(x.Width, y.Width), ystdex::max(x.Height, y.Height)})
674
679 YB_ATTR_nodiscard YB_PURE yconstfn PDefH(size_t, GetAreaOf, const Size& s) ynothrow
680 ImplRet(size_t(s.Width * s.Height))
681
682
686 YB_ATTR_nodiscard YB_PURE yconstfn
687 PDefH(Point, LocateCenter, const Size& x, const Size& y)
688 // XXX: Conversion to 'SPos' might be implementation-defined.
689 ImplRet({HalfDifference(SPos(x.Width), SPos(y.Width)),
690 HalfDifference(SPos(x.Height), SPos(y.Height))})
691
696 YB_ATTR_nodiscard YB_PURE yconstfn PDefH(Point, RotateCenter, const Size& s)
697 // XXX: Conversion to 'SPos' might be implementation-defined.
698 ImplRet({HalfDifference(SPos(s.Width), SPos(s.Height)),
699 HalfDifference(SPos(s.Height), SPos(s.Width))})
700
706 template<size_t _vIdx>
707 YB_ATTR_nodiscard YB_PURE yconstfn SDst&
708 get(Size& s)
709 {
710 static_assert(_vIdx < 2, "Invalid index found.");
711
712 return _vIdx == 0 ? s.Width : s.Height;
713 }
714 template<size_t _vIdx>
715 YB_ATTR_nodiscard YB_PURE yconstfn const SDst&
716 get(const Size& s)
717 {
718 static_assert(_vIdx < 2, "Invalid index found.");
719
720 return _vIdx == 0 ? s.Width : s.Height;
721 }
723
729 YB_ATTR_nodiscard YF_API YB_PURE std::string
730 to_string(const Size&);
732
733
738 template<typename _type>
739 YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup<_type>
740 operator+(GBinaryGroup<_type> val, const Size& s) ynothrow
741 {
742 // XXX: Conversion to '_type' might be implementation-defined.
743 return {val.X + _type(s.Width), val.Y + _type(s.Height)};
744 }
745
750 template<typename _type>
751 YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup<_type>
752 operator-(GBinaryGroup<_type> val, const Size& s) ynothrow
753 {
754 // XXX: Conversion to '_type' might be implementation-defined.
755 return {val.X - _type(s.Width), val.Y - _type(s.Height)};
756 }
757
758
763 YB_ATTR_nodiscard YB_PURE yconstfn PDefH(Size, Transpose, const Size& s) ynothrow
764 ImplRet({s.Height, s.Width})
765
766
771 template<typename _tScalar = float>
772 YB_ATTR_nodiscard YB_PURE yconstfn _tScalar
773 ScaleMin(const Size& x, const Size& y, _tScalar threshold = 1.F)
774 {
775 return ystdex::min({threshold, _tScalar(_tScalar(x.Width) / _tScalar(
776 y.Width)), _tScalar(_tScalar(x.Height) / _tScalar(y.Height))});
777 }
778
779
786 class YF_API Rect : private Point, private Size,
787 private ystdex::equality_comparable<Rect>
788 {
789 public:
794 static const Rect Invalid;
795
801 using Point::X;
807 using Point::Y;
813 using Size::Width;
819 using Size::Height;
820
821
826 DefDeCtor(Rect)
831 explicit yconstfn
832 Rect(const Point& pt) ynothrow
833 : Point(pt), Size()
834 {}
839 yconstfn
840 Rect(const Size& s) ynothrow
841 : Point(), Size(s)
842 {}
847 yconstfn
848 Rect(const Point& pt, const Size& s) ynothrow
849 : Point(pt), Size(s)
850 {}
855 yconstfn
856 Rect(const Point& pt, SDst w, SDst h) ynothrow
857 : Point(pt.X, pt.Y), Size(w, h)
858 {}
863 yconstfn
864 Rect(SPos x, SPos y, const Size& s) ynothrow
865 : Point(x, y), Size(s.Width, s.Height)
866 {}
871 yconstfn
872 Rect(SPos x, SPos y, SDst w, SDst h) ynothrow
873 : Point(x, y), Size(w, h)
874 {}
878 yconstfn DefDeCopyCtor(Rect)
879
880 DefDeCopyAssignment(Rect)
882
883 Rect&
884 operator=(const Point& pt) ynothrow
885 {
886 yunseq(X = pt.X, Y = pt.Y);
887 return *this;
888 }
889 Rect&
890 operator=(const Size& s) ynothrow
891 {
892 yunseq(Width = s.Width, Height = s.Height);
893 return *this;
894 }
896
902 Rect&
903 operator&=(const Rect&) ynothrow;
904
910 Rect&
911 operator|=(const Rect&) ynothrow;
912
918 using Size::operator!;
919
925 using Size::operator bool;
926
931 YB_ATTR_nodiscard YB_PURE bool
932 Contains(SPos px, SPos py) const ynothrow;
937 YB_ATTR_nodiscard YB_PURE PDefH(bool, Contains, const Point& pt) const ynothrow
938 ImplRet(Contains(pt.X, pt.Y))
944 YB_ATTR_nodiscard YB_PURE bool
945 Contains(const Rect&) const ynothrow;
950 YB_ATTR_nodiscard YB_PURE bool
951 ContainsStrict(SPos px, SPos py) const ynothrow;
956 YB_ATTR_nodiscard YB_PURE
957 PDefH(bool, ContainsStrict, const Point& pt) const ynothrow
958 ImplRet(ContainsStrict(pt.X, pt.Y))
964 YB_ATTR_nodiscard YB_PURE bool
965 ContainsStrict(const Rect&) const ynothrow;
971 using Size::IsLineSegment;
977 using Size::IsUnstrictlyEmpty;
978
980 // XXX: Conversion to 'SPos' might be implementation-defined.
981 yconstfn DefGetter(const ynothrow, SPos, Bottom, Y + SPos(Height))
985 yconstfn DefGetter(const ynothrow, const Point&, Point,
986 static_cast<const Point&>(*this))
991 DefGetter(ynothrow, Point&, PointRef, static_cast<Point&>(*this))
993 // XXX: Conversion to 'SPos' might be implementation-defined.
994 yconstfn DefGetter(const ynothrow, SPos, Right, X + SPos(Width))
998 yconstfn DefGetter(const ynothrow, const Size&, Size,
999 static_cast<const Size&>(*this))
1004 DefGetter(ynothrow, Size&, SizeRef, static_cast<Size&>(*this))
1006
1007 using Point::GetX;
1008 using Point::GetY;
1009
1010 using Point::SetX;
1011 using Point::SetY;
1013 };
1014
1016
1017
1021 YB_ATTR_nodiscard YB_PURE yconstfn PDefHOp(bool, ==, const Rect& x, const Rect& y)
1022 ynothrow
1023 ImplRet(x.GetPoint() == y.GetPoint() && x.GetSize() == y.GetSize())
1024
1029 YB_ATTR_nodiscard YB_PURE yconstfn PDefHOp(Rect, +, const Rect& r, const Vec& v)
1030 ynothrow
1031 ImplRet({r.GetPoint() + v, r.GetSize()})
1032
1037 YB_ATTR_nodiscard YB_PURE yconstfn PDefHOp(Rect, -, const Rect& r, const Vec& v)
1038 ynothrow
1039 ImplRet({r.GetPoint() - v, r.GetSize()})
1040
1046 YB_ATTR_nodiscard YB_PURE inline PDefHOp(Rect, &, const Rect& x, const Rect& y)
1047 ynothrow
1048 ImplRet(Rect(x) &= y)
1049
1050
1055 YB_ATTR_nodiscard YB_PURE inline PDefHOp(Rect, |, const Rect& x, const Rect& y) ynothrow
1056 ImplRet(Rect(x) |= y)
1057
1058
1063 inline PDefH(void, Diminish, Rect& r, SDst off1 = 1, SDst off2 = 2)
1064 // XXX: Conversion to 'SPos' might be implementation-defined.
1065 ImplExpr(YAssert(r.Width > off2 && r.Height > off2,
1066 "Boundary is too small."), yunseq(r.X += SPos(off1), r.Y += SPos(off1),
1067 r.Width -= off2, r.Height -= off2))
1068
1070
1071
1079 YB_ATTR_nodiscard YB_PURE yconstfn
1080 PDefH(Rect, MakeRect, const Point& pt1, const Point& pt2) ynothrow
1081 ImplRet(Rect(ystdex::min(pt1.X, pt2.X), ystdex::min(pt1.Y, pt2.Y),
1082 SDst(pt1.X < pt2.X ? pt2.X - pt1.X : pt1.X - pt2.X),
1083 SDst(pt1.Y < pt2.Y ? pt2.Y - pt1.Y : pt1.Y - pt2.Y)))
1084
1086 YB_ATTR_nodiscard YB_PURE yconstfn PDefH(Rect, TransposeCCW, const Rect& r) ynothrow
1087 ImplRet(MakeRect(TransposeCCW(Point(r.GetRight(), r.Y)),
1088 TransposeCCW(Point(r.X, r.GetBottom()))))
1089
1091 YB_ATTR_nodiscard YB_PURE yconstfn PDefH(Rect, TransposeCW, const Rect& r) ynothrow
1092 ImplRet(MakeRect(TransposeCW(Point(r.GetRight(), r.Y)),
1093 TransposeCW(Point(r.X, r.GetBottom()))))
1095
1101 template<size_t _vIdx>
1102 YB_ATTR_nodiscard YB_PURE yconstfn ystdex::conditional_t<_vIdx < 2, SPos, SDst>&
1103 get(Rect& r)
1104 {
1105 return get<_vIdx>(
1106 tuple<SPos&, SPos&, SDst&, SDst&>(r.X, r.Y, r.Width, r.Height));
1107 }
1108 template<size_t _vIdx>
1109 YB_ATTR_nodiscard YB_PURE yconstfn const ystdex::conditional_t<_vIdx < 2, SPos, SDst>&
1110 get(const Rect& r)
1111 {
1112 return get<_vIdx>(tuple<const SPos&, const SPos&, const SDst&, const SDst&>(
1113 r.X, r.Y, r.Width, r.Height));
1114 }
1116
1122 YB_ATTR_nodiscard YF_API YB_PURE std::string
1123 to_string(const Rect&);
1125
1126
1127 template<typename _type>
1128 yconstfn
1129 GBinaryGroup<_type>::GBinaryGroup(const Rect& r) ynothrow
1130 : X(r.X), Y(r.Y)
1131 {}
1132
1133 yconstfn
1134 Size::Size(const Rect& r) ynothrow
1135 : Width(r.Width), Height(r.Height)
1136 {}
1137
1138
1144 enum Rotation : yimpl(size_t)
1145 {
1146 RDeg0 = 0,
1147 RDeg90 = 1,
1148 RDeg180 = 2,
1149 RDeg270 = 3
1150 };
1151
1153
1154 YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(Rotation, Flip, Rotation rot)
1156 ImplRet(Rotation((size_t(rot) + 2) % 4))
1157
1158 YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(Rotation, RotateCCW, Rotation rot)
1160 ImplRet(Rotation((size_t(rot) + 1) % 4))
1161
1163 YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(Rotation, RotateCW, Rotation rot)
1164 ImplRet(Rotation((size_t(rot) - 1) % 4))
1166
1167
1172 enum Orientation
1173 {
1174 Horizontal = 0,
1175 Vertical = 1
1176 };
1177
1178 } // namespace Drawing;
1179
1180 } // namespace YSLib;
1181
1182 #endif
1183
YSLib::Drawing::operator*
YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup< _type > operator*(const GBinaryGroup< _type > &val, _tScalar l) ynothrow
数乘：屏幕二元组。
Definition: YGDIBase.h:442
YSLib::Drawing::ComponentTraits< 1 >::Saturate
YB_ATTR_nodiscard static YB_STATELESS yconstfn _type Saturate(_type v) ynothrow
Definition: YGDIBase.h:77
YSLib::Drawing::GBinaryGroup::ImplRet
const ynothrow ImplRet(GBinaryGroup(-X, -Y)) PDefHOp(GBinaryGroup &
加法赋值。
YSLib::Drawing::RDeg270
@ RDeg270
Definition: YGDIBase.h:1149
YSLib::Drawing::SPos
YB_ATTR_nodiscard yconstfn YB_PURE x x x Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE SPos(x.Right *ptrdiff_t(n))
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
DefPred
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:232
YSLib::Drawing::Color
The boundary is out of the const Rect SDst SPos SPos SPos Color
Definition: YDraw.h:128
YSLib::Drawing::Size::Width
SDst Width
宽和高。
Definition: YGDIBase.h:545
YSLib::Drawing::Rect::Rect
yconstfn Rect(SPos x, SPos y, SDst w, SDst h) ynothrow
构造：使用表示位置的两个 SPos 值和表示大小的两个 SDst 值。
Definition: YGDIBase.h:872
string.hpp
ISO C++ 标准字符串扩展。
ystdex::cpp2014::conditional_t
typename conditional< _bCond, _type, _type2 >::type conditional_t
Definition: meta.hpp:202
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:536
YSLib::Drawing::GBinaryGroup::GBinaryGroup
yconstfn GBinaryGroup(const Rect &) ynothrow
构造：使用 Rect 对象。
Definition: YGDIBase.h:1129
YSLib::Drawing::Rect::Invalid
static const Rect Invalid
无效对象。
Definition: YGDIBase.h:794
YSLib::Drawing::ImplRet
YB_ATTR_nodiscard YB_STATELESS yconstfn Rotation rot ImplRet(Rotation((size_t(rot)+1) % 4)) YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(Rotation
ystdex::quote
decay_t< _tString > quote(_tString &&str, typename string_traits< decay_t< _tString >>::value_type c=typename string_traits< decay_t< _tString >>::value_type('"'))
取添加前缀和后缀的字符串。
Definition: string.hpp:1579
YSLib::Drawing::Size::Height
SDst Height
Definition: YGDIBase.h:545
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
YSLib::Drawing::RotateCCW
YB_ATTR_nodiscard YB_STATELESS yconstfn RotateCCW
Definition: YGDIBase.h:1159
ystdex::cpp2014::min
const _type & min(const _type &a, const _type &b, _fComp comp=less< _type >())
取较小的元素。
Definition: algorithm.hpp:614
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
YSLib::Drawing::Rect::PDefH
YB_ATTR_nodiscard YB_PURE PDefH(bool, Contains, const Point &pt) const ynothrow ImplRet(Contains(pt.X
判断点 pt 是否在矩形内或边上。
YSLib::Drawing::Size::Size
yconstfn Size() ynothrow
无参数构造。
Definition: YGDIBase.h:553
YSLib::Drawing::x
const TextState &ts const TextState &ts const TextState &ts TextState SPos x
Definition: TextBase.h:190
YSLib::Drawing::GGraphics::Height
const SizeType sGraphics Height
Definition: YGraphics.h:136
YSLib::Drawing::TransposeCW
YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup< _type > TransposeCW(const GBinaryGroup< _type > &val) ynothrow
转置变换：顺时针旋转直角。
Definition: YGDIBase.h:471
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: meta.hpp:199
ystdex::dep_ops::equality_comparable
_t< details::ops_seq< _type, _type2, _tOpt, cond_t< is_same< _type, _type2 >, index_sequence< 7 >, index_sequence< 6, 7, 8 > >> > equality_comparable
Definition: operators.hpp:265
YSLib::Drawing::GBinaryGroup::Zero
const ynothrow const GBinaryGroup &val ynothrow const GBinaryGroup &val ynothrow X yconstfn X Zero
Definition: YGDIBase.h:382
YSLib::Drawing::ColorSpace::Blue
@ Blue
Definition: YGDIBase.h:263
YSLib::Drawing::Rect::Rect
yconstfn Rect(SPos x, SPos y, const Size &s) ynothrow
构造：使用表示位置的两个 SPos 值和 Size 对象。
Definition: YGDIBase.h:864
YSLib::Drawing::ColorSpace::Gray
@ Gray
Definition: YGDIBase.h:265
YSLib::Drawing::GBinaryGroup::Invalid
static const GBinaryGroup Invalid
无效（不在屏幕坐标系中）对象。
Definition: YGDIBase.h:298
YSLib::Drawing::Right
YB_ATTR_nodiscard yconstfn YB_PURE x Right
Definition: YGDI.h:108
YSLib::Drawing::GBinaryGroup::GBinaryGroup
yconstfn GBinaryGroup(const _tPair &pr) ynothrow
构造：使用纯量对。
Definition: YGDIBase.h:348
ystdex::cpp2014::max
const _type & max(const _type &a, const _type &b, _fComp comp=less< _type >())
取较大的元素。
Definition: algorithm.hpp:635
YF_API
#define YF_API
Definition: Platform.h:56
platform::KeyCodes::DS::B
@ B
Definition: Keys.h:217
YSLib::Drawing::ColorSpace::Yellow
@ Yellow
Definition: YGDIBase.h:276
YSLib::Drawing::GBinaryGroup::DefSetter
const ynothrow const GBinaryGroup &val ynothrow const GBinaryGroup &val ynothrow X yconstfn X DefSetter(, _type, Y, Y) yconstfn DefPred(const ynothrow
判断是否是零元素。
YSLib::Drawing::GBinaryGroup::GBinaryGroup
yconstfn GBinaryGroup(_tScalar1 x, _tScalar2 y) ynothrow
构造：使用两个纯量。
Definition: YGDIBase.h:338
platform::IndexSpace::AXYZMapping::G
@ G
Definition: Video.h:89
YSLib::Drawing::RDeg180
@ RDeg180
Definition: YGDIBase.h:1148
YSLib::Drawing::Size::Size
yconstfn Size(const GBinaryGroup< _type > &val) ynothrow
构造：使用屏幕二元组。
Definition: YGDIBase.h:576
YSLib::Drawing::operator+
YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup< _type > operator+(const GBinaryGroup< _type > &x, const GBinaryGroup< _type > &y) ynothrow
加法：屏幕二元组。
Definition: YGDIBase.h:420
YSLib::Drawing::ColorSpace::Red
@ Red
Definition: YGDIBase.h:272
YSLib::Drawing::Size::Invalid
static const Size Invalid
无效对象。
Definition: YGDIBase.h:542
YSLib::Drawing::ColorSpace::Purple
@ Purple
Definition: YGDIBase.h:271
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
ystdex::is_nothrow_copyable
Definition: meta.hpp:628
YSLib::Drawing::PDefH
YB_ATTR_nodiscard YB_PURE yconstfn PDefH(Size, Transpose, const Size &s) ynothrow ImplRet(
转置。
Definition: YGDIBase.h:763
YSLib::Drawing::RotateCW
YB_ATTR_nodiscard YB_STATELESS yconstfn Rotation rot RotateCW
Definition: YGDIBase.h:1163
YSLib::Drawing::GBinaryGroup::DefDeCtor
yconstfn DefDeCtor(GBinaryGroup) yconstfn DefDeCopyCtor(GBinaryGroup) explicit yconstfn GBinaryGroup(const Size &) ynothrow
无参数构造。
YSLib::Drawing::MonoType
octet MonoType
单色分量类型。
Definition: YGDIBase.h:47
platform::KeyCodes::DS::A
@ A
Definition: Keys.h:216
YSLib::Drawing::Rect::DefDeCtor
DefDeCtor(Rect) explicit yconstfn Rect(const Point &pt) ynothrow
无参数构造：默认实现。
Definition: YGDIBase.h:826
DefBoolNeg
#define DefBoolNeg(_spec,...)
定义表示显式转换 bool 操作符及其否定的 operator! 。
Definition: YBaseMacro.h:228
YSLib::Drawing::get
YB_ATTR_nodiscard YB_PURE yconstfn _type & get(GBinaryGroup< _type > &val)
取分量。
Definition: YGDIBase.h:484
YSLib::Drawing::ScaleMin
YB_ATTR_nodiscard YB_PURE yconstfn _tScalar ScaleMin(const Size &x, const Size &y, _tScalar threshold=1.F)
计算两个大小和阈值限定的最小缩放值。
Definition: YGDIBase.h:773
YSLib::Drawing::operator==
YB_ATTR_nodiscard YB_PURE yconstfn bool operator==(const GBinaryGroup< _type > &x, const GBinaryGroup< _type > &y) ynothrow
比较：屏幕二元组相等关系。
Definition: YGDIBase.h:409
YSLib::YAssert
YAssert(!(v< Deref(a)), "Value less than lower bound found.")
YSL_Impl_DefColorH
#define YSL_Impl_DefColorH(hex_, name)
Definition: YGDIBase.h:251
ImageBrowser::Flip
@ Flip
Definition: ImageControl.cpp:39
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: YGDIBase.h:520
YSLib::Drawing::IsUnstrictlyEmpty
YB_ATTR_nodiscard !x IsUnstrictlyEmpty()) YB_ATTR_nodiscard YF_API Point ClipBounds(Rect &
根据指定源的边界优化绘制上下文的剪切区域。
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:941
YSLib::Drawing::Size::Size
yconstfn Size(const Size &s) ynothrow
复制构造。
Definition: YGDIBase.h:561
YSLib::Drawing::Rect::Rect
yconstfn Rect(const Size &s) ynothrow
构造：使用 Size 对象。
Definition: YGDIBase.h:840
YSLib::Drawing::Rotation
Rotation
逆时针旋转角度指示输出指向。
Definition: YGDIBase.h:1145
YSLib::Drawing::ColorSpace::ColorSet
ColorSet
默认颜色集。
Definition: YGDIBase.h:260
YSLib::Drawing::ColorSpace::Green
@ Green
Definition: YGDIBase.h:266
YSLib::Drawing::GBinaryGroup::_type
const ynothrow const GBinaryGroup &val ynothrow const GBinaryGroup &val ynothrow _type
Definition: YGDIBase.h:373
YSLib::yimpl
YF_API yimpl(GUIApplication &) FetchGlobalInstance()
取全局应用程序实例。
YSLib::Drawing::Size::DefDeCopyAssignment
DefDeCopyAssignment(Size) yconstfn DefBoolNeg(explicit yconstfn
判断是否为空或非空。
YSLib::Drawing::GBinaryGroup
屏幕二元组。
Definition: YGDIBase.h:295
YSLib::Drawing::ColorSpace::Fuchsia
@ Fuchsia
Definition: YGDIBase.h:264
operators.hpp
重载操作符。
YSLib::Drawing::ColorSpace::Teal
@ Teal
Definition: YGDIBase.h:274
YSLib::Drawing::ColorSpace::Lime
@ Lime
Definition: YGDIBase.h:267
YSLib::Drawing::GetSize
dst GetSize()
YSLib::Drawing::ColorSpace::Olive
@ Olive
Definition: YGDIBase.h:270
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1535
YSLib::Drawing::ColorSpace::Black
@ Black
Definition: YGDIBase.h:262
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
ystdex::underlying_cond_type_t
_t< cond_t< is_enum< _type >, vdefer< underlying_type_t, _type >, identity< _type > >> underlying_cond_type_t
取底层类型。
Definition: type_op.hpp:250
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
YSLib::Drawing::GBinaryGroup::X
_type X
分量。
Definition: YGDIBase.h:305
YSLib::Drawing::ComponentTraits
分量特征。
Definition: YGDIBase.h:59
YSLib::Drawing::AlphaType
octet AlphaType
Alpha 分量类型。
Definition: YGDIBase.h:49
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
YSLib::HalfDifference
YB_STATELESS yconstfn _type HalfDifference(_type x, _type y)
计算指定类型的差值的一半。
Definition: YCoreUtilities.h:73
YSLib::Drawing::operator-
YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup< _type > operator-(const GBinaryGroup< _type > &x, const GBinaryGroup< _type > &y) ynothrow
减法：屏幕二元组。
Definition: YGDIBase.h:431
YSLib::Drawing::Rect::DefDeCopyCtor
yconstfn DefDeCopyCtor(Rect) DefDeCopyAssignment(Rect) Rect &operator
复制构造：默认实现。
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
YSLib::Drawing::Transpose
YB_ATTR_nodiscard YB_PURE yconstfn _tBinary Transpose(const _tBinary &obj) ynothrow
转置。
Definition: YGDIBase.h:453
YSLib::Drawing::PDefHOp
YB_ATTR_nodiscard yconstfn YB_PURE x x x Bottom YB_ATTR_nodiscard yconstfn YB_PURE PDefHOp(Padding,+, const Padding &x, const Padding &y) ynothrow ImplRet(Padding(x.Left+y.Left
加法：对应分量调用 operator+ 。
YModules.h
YSLib 用户界面模块配置文件。
YSLib::Drawing::ynothrow
YB_ATTR_nodiscard yconstfn YB_PURE x x x Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE x Right y x Top y x Bottom y Bottom YB_ATTR_nodiscard yconstfn YB_PURE const Padding & ynothrow
Definition: YGDI.h:132
YSLib::Drawing::ImplExpr
const TextState &ts const TextState &ts const TextState &ts TextState SPos SPos y ImplExpr(ts.Pen=Point(x, y)) YF_API void SetCurrentTextLineNOf(TextState &
设置笔的行位置。
YSLib::Drawing::RDeg0
@ RDeg0
Definition: YGDIBase.h:1146
YSLib::Drawing::ComponentTraits< 8 >::Saturate
YB_ATTR_nodiscard static YB_STATELESS yconstfn _type Saturate(_type v) ynothrow
Definition: YGDIBase.h:66
v
byte v
Definition: CharRenderer.cpp:76
YSLib::Drawing::ColorSpace::Navy
@ Navy
Definition: YGDIBase.h:269
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
YSLib::Drawing::GBinaryGroup::DefDeCopyAssignment
DefDeCopyAssignment(GBinaryGroup) YB_ATTR_nodiscard YB_PURE yconstfn PDefHOp(GBinaryGroup
负运算：取加法逆元。
YSLib::Drawing::ColorSpace::Aqua
@ Aqua
Definition: YGDIBase.h:261
YSLib::Drawing::w
The boundary is out of the const Rect SDst w
Definition: YDraw.h:127
YSLib::Drawing::Rect::Rect
yconstfn Rect(const Point &pt, const Size &s) ynothrow
构造：使用屏幕二维点和 Size 对象。
Definition: YGDIBase.h:848
DefDeCopyCtor
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:162
YSLib::Drawing::Rect::Rect
yconstfn Rect(const Point &pt, SDst w, SDst h) ynothrow
构造：使用屏幕二维点和表示长宽的两个 SDst 值。
Definition: YGDIBase.h:856
ystdex::octet
void octet
Definition: ydef.h:1294
DefCvt
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:206
YSLib::Drawing::TransposeCCW
YB_ATTR_nodiscard YB_PURE yconstfn GBinaryGroup< _type > TransposeCCW(const GBinaryGroup< _type > &val) ynothrow
转置变换：逆时针旋转直角。
Definition: YGDIBase.h:463
YSLib::Drawing::GBinaryGroup::Y
_type Y
Definition: YGDIBase.h:305
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
platform::KeyCodes::DS::R
@ R
Definition: Keys.h:227
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
YSLib::Drawing::RDeg90
@ RDeg90
Definition: YGDIBase.h:1147
platform::bool
YB_ATTR_nodiscard std::FILE *fp bool
Definition: FileIO.h:1271
ystdex::cpp2017::string
basic_string< char > string
Definition: string.hpp:772
YSLib::Drawing::ColorSpace::White
@ White
Definition: YGDIBase.h:275
YSLib::Drawing::ColorSpace::Silver
@ Silver
Definition: YGDIBase.h:273
YSLib::Drawing::GBinaryGroup::DefGetter
const ynothrow const GBinaryGroup &val ynothrow const GBinaryGroup &val ynothrow X yconstfn DefGetter(const ynothrow, _type, Y, Y) DefSetter(
YSLib::Drawing::to_string
YB_ATTR_nodiscard YB_PURE std::string to_string(const GBinaryGroup< _type > &val)
转换为字符串。
Definition: YGDIBase.h:507
YSLib::Drawing::ColorSpace::Maroon
@ Maroon
Definition: YGDIBase.h:268
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
YSLib::Drawing::Size::Size
yconstfn Size(_tScalar1 w, _tScalar2 h) ynothrow
构造：使用两个纯量。
Definition: YGDIBase.h:585
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:168
platform::l
return l
Definition: YCLib/FileSystem.h:402
ystdex::and_
逻辑操作元函数。
Definition: integral_constant.hpp:151