YSTest: YRenderer.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

YRenderer.cpp
浏览该文件的文档.
1 /*
2 © 2011-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 #include "YSLib/UI/YModules.h"
29 #include YFM_YSLib_UI_YRenderer
30 #include YFM_YSLib_UI_YControl
31 #include YFM_YSLib_Service_YGDI
32
33 namespace YSLib
34 {
35
36 namespace UI
37 {
38
39 Rect
40 Renderer::Paint(IWidget& wgt, PaintEventArgs&& e)
41 {
42 YAssert(&e.GetSender().GetRenderer() == this, "Invalid widget found.");
43 if(YB_LIKELY(!e.ClipArea.IsUnstrictlyEmpty()))
44 CallEvent<UI::Paint>(wgt, e);
45 return e.ClipArea;
46 }
47
48
49 ImplDeDtor(PseudoRenderer)
50
51
52 BufferedRenderer::BufferedRenderer(bool b, unique_ptr<Drawing::IImage> p)
53 : Renderer(),
54 rInvalidated(), pImageBuffer(p ? std::move(p)
55 : make_unique<CompactPixmap>()), IgnoreBackground(b)
56 {}
57 BufferedRenderer::BufferedRenderer(const BufferedRenderer& rd)
58 : Renderer(rd),
59 rInvalidated(rd.rInvalidated), pImageBuffer(ystdex::clone_polymorphic(
60 Deref(rd.pImageBuffer))), IgnoreBackground(rd.IgnoreBackground)
61 {}
62
63 bool
64 BufferedRenderer::RequiresRefresh() const
65 {
66 return bool(rInvalidated);
67 }
68
69 void
70 BufferedRenderer::SetImageBuffer(unique_ptr<Drawing::IImage> p)
71 {
72 pImageBuffer = p ? std::move(p) : make_unique<Drawing::CompactPixmap>();
73 }
74
75 void
76 BufferedRenderer::SetSize(const Size& s)
77 {
78 GetImageBuffer().SetSize(s);
79 rInvalidated = {{}, s};
80 }
81
82 Rect
83 BufferedRenderer::CommitInvalidation(const Rect& r)
84 {
85 return rInvalidated |= r;
86 }
87
88 Rect
89 BufferedRenderer::Paint(IWidget& wgt, PaintEventArgs&& e)
90 {
91 const Rect& r(Validate(wgt, e.GetSender(), e));
92
93 UpdateTo(e);
94 return r;
95 }
96
97 void
98 BufferedRenderer::UpdateTo(const PaintContext& pc) const
99 {
100 const auto& g(pc.Target);
101 const Rect& bounds(pc.ClipArea);
102
103 CopyTo(g.GetBufferPtr(), GetContext(), g.GetSize(), bounds.GetPoint(),
104 bounds.GetPoint() - pc.Location, bounds.GetSize());
105 }
106
107 Rect
108 BufferedRenderer::Validate(IWidget& wgt, IWidget& sender,
109 const PaintContext& pc)
110 {
111 YAssert(&sender.GetRenderer() == this, "Invalid widget found.");
112 if(RequiresRefresh())
113 {
114 if(!IgnoreBackground && FetchContainerPtr(sender))
115 Invalidate(sender);
116
117 const Rect& clip(pc.ClipArea & (rInvalidated + pc.Location));
118
119 if(!clip.IsUnstrictlyEmpty())
120 {
121 const auto& g(GetContext());
122
123 if(!IgnoreBackground && FetchContainerPtr(sender))
124 {
125 const auto dst(g.GetBufferPtr());
126 const auto& src(pc.Target);
127
128 if(dst != src.GetBufferPtr())
129 CopyTo(g.GetBufferPtr(), src, g.GetSize(), clip.GetPoint()
130 - pc.Location, clip.GetPoint(), clip.GetSize());
131 }
132
133 PaintEventArgs e(sender,
134 {g, Point(), (clip - pc.Location) & Rect(g.GetSize())});
135
136 CallEvent<UI::Paint>(wgt, e);
137 // NOTE: To keep %CommitInvalidation result correct, both
138 // components of the size shall be reset.
139 rInvalidated.GetSizeRef() = {};
140 return e.ClipArea;
141 }
142 }
143 return {};
144 }
145
146 } // namespace UI;
147
148 } // namespace YSLib;
149
NPL::dst
YF_API const char src const string const char * dst
Definition: Dependency.h:95
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
UI
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:451
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
ystdex::clone_polymorphic
auto clone_polymorphic(const _type &v) -> decltype(v.clone())
使用 clone 成员函数复制多态类类型对象。
Definition: memory.hpp:1115
YSLib::UI::PseudoRenderer
伪渲染器：静态类型的所有实际操作不产生可观察的副作用。
Definition: YRenderer.h:86
YSLib::Drawing::CompactPixmap
标准矩形像素图缓冲区。
Definition: YGDI.h:243
YSLib::UI::wgt
IWidget & wgt
Definition: YControl.h:112
ystdex::cpp2014::make_unique
enable_if_t<!is_array< _type >::value, std::unique_ptr< _type > > make_unique(_tParams &&...args)
使用 new 和指定参数构造指定类型的 std::unique_ptr 对象。
Definition: memory.hpp:852
YSLib::UI::BufferedRenderer::SetImageBuffer
void SetImageBuffer(unique_ptr< Drawing::IImage >)
Definition: YRenderer.cpp:70
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: YGDIBase.h:278
YSLib::YAssert
YAssert(!(v< Deref(a)),"Value less than lower bound found.")
YSLib::UI::BufferedRenderer::pImageBuffer
unique_ptr< Drawing::IImage > pImageBuffer
显示图像缓冲区指针。
Definition: YRenderer.h:120
YSLib::UI::Invalidate
YF_API void Invalidate(IWidget &, const Rect &)
无效化：使相对部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.cpp:108
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
特性测试宏。
Definition: ydef.h:822
Drawing
YSLib::UI::BufferedRenderer
带缓冲的部件渲染器。
Definition: YRenderer.h:111
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:323
YSLib::UI::BufferedRenderer::Validate
Rect Validate(IWidget &wgt, IWidget &sender, const PaintContext &)
验证并按需绘制。
Definition: YRenderer.cpp:108
YSLib::UI::Renderer::CommitInvalidation
CommitInvalidation
Definition: YRenderer.h:66
YSLib::Drawing::CopyTo
bool CopyTo(BitmapPtr dst, const ConstGraphics &g, const Size &ds, const Point &dp, const Point &sp, const Size &sc, Rotation rot)
Definition: YGDI.cpp:203
YSLib::UI::e
void e
Definition: YWidget.h:352
YSLib::UI::BufferedRenderer::IgnoreBackground
bool IgnoreBackground
指定验证时忽略上层缓冲区背景。
Definition: YRenderer.h:127
YModules.h
YSLib::UI::Renderer
部件渲染器。
Definition: YRenderer.h:46
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
YSLib::UI::BufferedRenderer::UpdateTo
void UpdateTo(const PaintContext &) const
更新至指定图形设备上下文的指定点。
Definition: YRenderer.cpp:98
YSLib::UI::Paint
界面绘制。
Definition: YWidgetEvent.h:416
std
Definition: memory.hpp:1183
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
YSLib::UI::BufferedRenderer::rInvalidated
Rect rInvalidated
无效区域：包含所有新绘制请求的区域（不一定是最小的）。
Definition: YRenderer.h:114
YSLib::UI::BufferedRenderer::BufferedRenderer
BufferedRenderer(bool={}, unique_ptr< Drawing::IImage >={})
构造：指定是否忽略上层缓冲区背景。
YSLib::Drawing::bounds
The boundary is out of the const Rect & bounds
Definition: YDraw.h:127
YSLib::UI::bool
IWidget bool b bool
Definition: YControl.h:121
YB_LIKELY
#define YB_LIKELY(_expr)
Definition: ydef.h:463
YSLib::UI::BufferedRenderer::Paint
Rect Paint(IWidget &wgt, PaintEventArgs &&e) override
按参数绘制。
Definition: YRenderer.cpp:89
CHRLib::p
const auto p(d)
YSLib::UI::ImplDeDtor
ImplDeDtor(Thumb) void DecorateAsCloseButton(Thumb &tmb)
Definition: Button.cpp:125