YSTest: YGraphics.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

YGraphics.h
浏览该文件的文档.
1 /*
2 © 2015-2016 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
115 DefBoolNeg(explicit,
116 bool(pBuffer) && sGraphics.Width != 0 && sGraphics.Height != 0)
117
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
176 DeclIEntry(IImage* clone() const ImplI(ystdex::cloneable))
177 EndDecl
178
179
180 /*
181 \brief 绘制上下文。
182 \warning 非虚析构。
183 \since build 255
184 */
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::Height
const SizeType sGraphics Height
Definition: YGraphics.h:136
YSLib::Drawing::GGraphics< unique_ptr< Pixel[]> >::PixelType
ystdex::decay_t< decltype(PointerType()[0])> PixelType
Definition: YGraphics.h:72
platform::Nonnull
_type && Nonnull(_type &&p) ynothrow
断言并返回非空指针。
Definition: Debug.h:411
YSLib::Drawing::GGraphics::GGraphics
const SizeType class _tSize2 explicit yconstfn GGraphics(_tPointer2 p_buf, const _tSize2 &s={}) ynothrow
Definition: YGraphics.h:94
YSLib::Drawing::GGraphics::DefDeCtor
DefDeCtor(GGraphics) explicit yconstfn GGraphics(PointerType p_buf
默认构造：使用空指针和大小。
YModules.h
YSLib::Drawing::ImplExpr
tr TextRegion &tr ImplExpr(tr.Margin.Bottom=SPos(FetchResizedBottomMargin(tr))) YF_API SDst FetchCharWidth(const Font &
取指定的字符使用指定字体的显示宽度。
YSLib::GeneralEvent
std::runtime_error GeneralEvent
一般运行时异常事件类。
Definition: YException.h:45
YSLib::Drawing::GGraphics::pBuffer
PointerType pBuffer
显示缓冲区指针。
Definition: YGraphics.h:79
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
ImplI
#define ImplI(...)
Definition: YBaseMacro.h:386
ystdex::any_ops::clone
Definition: any.h:253
DefDeCopyAssignment
#define DefDeCopyAssignment(_t)
Definition: YBaseMacro.h:185
YSLib::Drawing::PDefH
yconstfn PDefH(Size, Transpose, const Size &s) ynothrow ImplRet(
转置。
Definition: YGDIBase.h:516
YSLib::Drawing::GGraphics::s
const SizeType & s
Definition: YGraphics.h:88
YSLib::Drawing::GGraphics< unique_ptr< Pixel[]> >::PointerType
unique_ptr< Pixel[]> PointerType
Definition: YGraphics.h:70
YSLib::Drawing::GGraphics::GGraphics
yconstfn GGraphics(const GGraphics< _tPointer2, _tSize2 > &g) ynothrow
构造：使用其它类型的指定位图指针和大小类型的二维图形接口上下文。
Definition: YGraphics.h:101
YSLib::Drawing::GGraphics::sGraphics
SizeType sGraphics
图形区域大小。
Definition: YGraphics.h:81
YSLib::Drawing::ConstBitmapPtr
const Pixel * ConstBitmapPtr
Definition: YGraphics.h:44
YSLib::DeclDerivedI
DeclDerivedI(YF_API, IValueHolder, ystdex::any_ops::holder) DeclIEntry(bool operator
带等于接口的动态泛型持有者接口。
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::Drawing::GGraphics::DefDeCopyCtor
DefDeCopyCtor(GGraphics) DefDeMoveCtor(GGraphics) DefDeCopyAssignment(GGraphics) DefDeMoveAssignment(GGraphics) DefBoolNeg(explicit
复制构造：浅复制。
YB_UNLIKELY
#define YB_UNLIKELY(_expr)
分支预测提示。
Definition: ydef.h:438
base.h
基类实用设施。
EndDecl
#define EndDecl
Definition: YBaseMacro.h:396
DefDeMoveAssignment
#define DefDeMoveAssignment(_t)
Definition: YBaseMacro.h:190
DeclIEntry
#define DeclIEntry(_sig)
Definition: YBaseMacro.h:394
YSLib::YAssert
YAssert(!(v< Deref(a)),"Value less than lower bound found.")
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
ystdex
特性测试宏。
Definition: ydef.h:796
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:166
YSLib::Drawing::GGraphics::DefGetter
DefGetter(const ynothrow, const PointerType &, BufferPtr, pBuffer) DefGetter(const ynothrow
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
YSLib::Drawing::BitmapPtr
Pixel * BitmapPtr
Definition: YGraphics.h:42
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
Drawing
YSLib::Drawing::CopyBitmapBuffer
void CopyBitmapBuffer(_tOut p_dst, _tIn p_src, const Size &s)
Definition: YGraphics.h:50
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:654
DefBoolNeg
#define DefBoolNeg(_spec,...)
定义表示显式转换 bool 操作符及其否定的 operator! 。
Definition: YBaseMacro.h:227
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::Drawing::GGraphics
二维图形接口上下文模板。
Definition: YGraphics.h:62
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
ystdex::cloneable
可动态复制的抽象基类。
Definition: base.h:117
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:43
YSLib::Drawing::GBinaryGroup< SPos >