YSTest: YGraphics.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

YGraphics.h
浏览该文件的文档.
1 /*
2 © 2011-2016, 2018-2019 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_YGraphics_h_
29 #define YSL_INC_Core_YGraphics_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YGDIBase
33 #include <ystdex/base.h> // for ystdex::cloneable;
34
35 namespace YSLib
36 {
37
38 namespace Drawing
39 {
40
42 using BitmapPtr = Pixel*;
44 using ConstBitmapPtr = const Pixel*;
45
46
48 template<typename _tOut, typename _tIn>
49 void
50 CopyBitmapBuffer(_tOut p_dst, _tIn p_src, const Size& s)
51 {
52 std::copy_n(Nonnull(p_src), GetAreaOf(s), Nonnull(p_dst));
53 }
54
55
61 template<typename _tPointer, class _tSize = Size>
62 class GGraphics
63 {
64 static_assert(std::is_nothrow_move_constructible<_tPointer>(),
65 "Invalid pointer type found.");
66 static_assert(std::is_nothrow_copy_constructible<_tSize>(),
67 "Invalid size type found.");
68
69 public:
70 using PointerType = _tPointer;
71 using SizeType = _tSize;
72 using PixelType = ystdex::decay_t<decltype(PointerType()[0])>;
73
74 protected:
79 PointerType pBuffer{};
81 SizeType sGraphics{};
82
83 public:
85 DefDeCtor(GGraphics)
87 explicit yconstfn
88 GGraphics(PointerType p_buf, const SizeType& s = {}) ynothrow
89 : pBuffer(std::move(p_buf)), sGraphics(s)
90 {}
92 template<typename _tPointer2, class _tSize2>
93 explicit yconstfn
94 GGraphics(_tPointer2 p_buf, const _tSize2& s = {}) ynothrow
95 : GGraphics(static_cast< PointerType>(std::move(p_buf)),
96 static_cast< SizeType>(s))
97 {}
99 template<typename _tPointer2, class _tSize2>
100 yconstfn
101 GGraphics(const GGraphics<_tPointer2, _tSize2>& g) ynothrow
102 : GGraphics(std::move(g.GetBufferPtr()), g.GetSize())
103 {}
105 DefDeCopyCtor(GGraphics)
106 DefDeMoveCtor(GGraphics)
107
108 DefDeCopyAssignment(GGraphics)
109 DefDeMoveAssignment(GGraphics)
110
111
115 DefBoolNeg(explicit,
116 bool(pBuffer) && sGraphics.Width != 0 && sGraphics.Height != 0)
117
118
123 PointerType
124 operator[](size_t r) const ynothrow
125 {
126 YAssert(r < sGraphics.Height, "Access out of range.");
127 return Nonnull(pBuffer) + r * sGraphics.Width;
128 }
129
131 DefGetter(const ynothrow, const PointerType&, BufferPtr, pBuffer)
132 DefGetter(const ynothrow, const SizeType&, Size, sGraphics)
134 DefGetter(const ynothrow, SDst, Width, sGraphics.Width)
136 DefGetter(const ynothrow, SDst, Height, sGraphics.Height)
138 DefGetter(const ynothrow, size_t, SizeOfBuffer,
139 sizeof(PixelType) * size_t(GetAreaOf(sGraphics)))
140
147 PointerType
148 at(size_t r) const
149 {
150 if(YB_UNLIKELY(!pBuffer))
151 throw GeneralEvent("Null pointer found.");
152 if(YB_UNLIKELY(r >= sGraphics.Height))
153 throw std::out_of_range("Access out of range.");
154 return pBuffer + r * sGraphics.Width;
155 }
156 };
157
158
160 using ConstGraphics = GGraphics<ConstBitmapPtr>;
161
163 using Graphics = GGraphics<BitmapPtr>;
164
165
170 DeclDerivedI(YF_API, IImage, ystdex::cloneable)
172 DeclIEntry(Graphics GetContext() const ynothrow)
173 DeclIEntry(void SetSize(const Size&))
174
175
176 DeclIEntry(IImage* clone() const ImplI(ystdex::cloneable))
177 EndDecl
178
179
185 struct YF_API PaintContext
186 {
187 Graphics Target;
188
194 Point Location;
201 Rect ClipArea;
202 };
203
210 inline PDefH(void, UpdateClipArea, PaintContext& pc, const Rect& r)
211 ImplExpr(pc.ClipArea = r & Rect(pc.Target.GetSize()))
212
213 inline PDefH(void, UpdateClipSize, PaintContext& pc, const Size& s)
214 ImplExpr(UpdateClipArea(pc, {pc.Location, s}))
216
217 } // namespace Drawing;
218
219 } // namespace YSLib;
220
221 #endif
222
YSLib::Drawing::GGraphics::GGraphics
yconstfn GGraphics(const GGraphics< _tPointer2, _tSize2 > &g) ynothrow
构造：使用其它类型的指定位图指针和大小类型的二维图形接口上下文。
Definition: YGraphics.h:101
EndDecl
#define EndDecl
Definition: YBaseMacro.h:406
platform::Nonnull
YB_PURE _type && Nonnull(_type &&p) ynothrowv
断言并返回非空参数。
Definition: Debug.h:518
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:536
base.h
基类实用设施。
YSLib::Drawing::GGraphics::pBuffer
PointerType pBuffer
显示缓冲区指针。
Definition: YGraphics.h:79
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::GGraphics::Height
const SizeType sGraphics Height
Definition: YGraphics.h:136
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:167
YSLib::Drawing::GGraphics::s
const SizeType & s
Definition: YGraphics.h:88
YSLib::DeclDerivedI
DeclDerivedI(YF_API, IValueHolder, any_ops::holder) enum Creation
带等于接口的动态泛型持有者接口。
Definition: YObject.h:126
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::GeneralEvent
std::runtime_error GeneralEvent
一般运行时异常事件类。
Definition: YException.h:46
YSLib::Drawing::GGraphics< unique_ptr< Pixel[]> >::PixelType
ystdex::decay_t< decltype(PointerType()[0])> PixelType
Definition: YGraphics.h:72
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
YSLib::Drawing::GGraphics::GGraphics
const SizeType class _tSize2 explicit yconstfn GGraphics(_tPointer2 p_buf, const _tSize2 &s={}) ynothrow
Definition: YGraphics.h:94
YSLib::Drawing::PDefH
YB_ATTR_nodiscard YB_PURE yconstfn PDefH(Size, Transpose, const Size &s) ynothrow ImplRet(
转置。
Definition: YGDIBase.h:763
ystdex::cpp2014::decay_t
typename decay< _type >::type decay_t
Definition: meta.hpp:196
DefBoolNeg
#define DefBoolNeg(_spec,...)
定义表示显式转换 bool 操作符及其否定的 operator! 。
Definition: YBaseMacro.h:228
ImplI
#define ImplI(...)
Definition: YBaseMacro.h:396
YSLib::YAssert
YAssert(!(v< Deref(a)), "Value less than lower bound found.")
YSLib::Drawing::GGraphics
二维图形接口上下文模板。
Definition: YGraphics.h:63
YSLib::Drawing::GGraphics< unique_ptr< Pixel[]> >::PointerType
unique_ptr< Pixel[]> PointerType
Definition: YGraphics.h:70
YSLib::Drawing::GGraphics::SizeType
_tSize SizeType
Definition: YGraphics.h:71
YSLib::Drawing::GGraphics::DefGetter
DefGetter(const ynothrow, const PointerType &, BufferPtr, pBuffer) DefGetter(const ynothrow
YSLib::Drawing::GBinaryGroup< SPos >
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::Drawing::GGraphics::DefDeCopyCtor
DefDeCopyCtor(GGraphics) DefDeMoveCtor(GGraphics) DefDeCopyAssignment(GGraphics) DefDeMoveAssignment(GGraphics) DefBoolNeg(explicit
复制构造：浅复制。
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
DefDeCopyAssignment
#define DefDeCopyAssignment(_t)
Definition: YBaseMacro.h:186
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
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::CopyBitmapBuffer
void CopyBitmapBuffer(_tOut p_dst, _tIn p_src, const Size &s)
Definition: YGraphics.h:50
YSLib::Drawing::GGraphics::sGraphics
SizeType sGraphics
图形区域大小。
Definition: YGraphics.h:81
YSLib::Drawing::ConstBitmapPtr
const Pixel * ConstBitmapPtr
Definition: YGraphics.h:44
YB_UNLIKELY
#define YB_UNLIKELY(_expr)
分支预测提示。
Definition: ydef.h:828
YSLib::DeclIEntry
YB_ATTR_nodiscard DeclIEntry(any Create(Creation, const any &) const) YB_ATTR_nodiscard YB_PURE DeclIEntry(bool Equals(const void *) const) YB_ATTR_nodiscard YB_PURE DeclIEntry(size_t OwnsCount() const ynothrow) YB_ATTR_nodiscard YB_PURE DeclIEntry(any Query(uintmax_t) const) template< typename _type > YB_ATTR_nodiscard static any CreateHolder(Creation
创建新的持有者。
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
DefDeMoveAssignment
#define DefDeMoveAssignment(_t)
Definition: YBaseMacro.h:191
YSLib::Drawing::BitmapPtr
Pixel * BitmapPtr
Definition: YGraphics.h:42
YSLib::Drawing::GGraphics::DefDeCtor
DefDeCtor(GGraphics) explicit yconstfn GGraphics(PointerType p_buf
无参数构造：使用空指针和大小。
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
ystdex::any_ops::clone
@ clone
复制被管理的对象的处理器。
Definition: any.h:285
ystdex::bases::cloneable
可动态复制的抽象基类。
Definition: base.h:126