YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
yrender.cpp
浏览该文件的文档.
1 /*
2  © 2011-2014 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
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 BufferedRenderer::BufferedRenderer(bool b, unique_ptr<Drawing::IImage> p)
50  : Renderer(),
51  rInvalidated(), pImageBuffer(p ? std::move(p)
52  : make_unique<CompactPixmap>()), IgnoreBackground(b)
53 {}
55  : Renderer(r),
56  rInvalidated(r.rInvalidated), pImageBuffer(ClonePolymorphic(
57  r.pImageBuffer)), IgnoreBackground(r.IgnoreBackground)
58 {}
59 
60 bool
61 BufferedRenderer::RequiresRefresh() const
62 {
63  return bool(rInvalidated);
64 }
65 
66 void
67 BufferedRenderer::SetImageBuffer(unique_ptr<Drawing::IImage> p)
68 {
69  pImageBuffer = p ? std::move(p) : make_unique<Drawing::CompactPixmap>();
70 }
71 
72 void
74 {
75  GetImageBuffer().SetSize(s);
76  rInvalidated = {{}, s};
77 }
78 
79 Rect
80 BufferedRenderer::CommitInvalidation(const Rect& r)
81 {
82  return rInvalidated |= r;
83 }
84 
85 Rect
87 {
88  YAssert(&e.GetSender().GetRenderer() == this, "Invalid widget found.");
89 
90  const Rect& r(Validate(wgt, e.GetSender(), e));
91 
92  UpdateTo(e);
93  return r;
94 }
95 
96 void
97 BufferedRenderer::UpdateTo(const PaintContext& pc) const
98 {
99  const auto& g(pc.Target);
100  const Rect& r(pc.ClipArea);
101 
102  CopyTo(g.GetBufferPtr(), GetContext(), g.GetSize(), r.GetPoint(),
103  r.GetPoint() - pc.Location, r.GetSize());
104 }
105 
106 Rect
107 BufferedRenderer::Validate(IWidget& wgt, IWidget& sender,
108  const PaintContext& pc)
109 {
110  if(RequiresRefresh())
111  {
112  const auto& l(GetLocationOf(sender));
113 
114  if(!IgnoreBackground && FetchContainerPtr(sender))
115  Invalidate(sender);
116 
117  const Rect& clip(pc.ClipArea & (rInvalidated + l));
118 
119  if(!clip.IsUnstrictlyEmpty())
120  {
121  if(!IgnoreBackground && FetchContainerPtr(sender))
122  {
123  const auto& g(GetContext());
124 
125  CopyTo(g.GetBufferPtr(), pc.Target, g.GetSize(), clip.GetPoint()
126  - pc.Location, clip.GetPoint(), clip.GetSize());
127  }
128 
129  PaintEventArgs e(sender, {GetContext(), Point(), clip - l});
130 
131  CallEvent<UI::Paint>(wgt, e);
132  //清除无效区域:只设置一个分量为零可能会使 CommitInvalidation 结果错误。
133  rInvalidated.GetSizeRef() = {};
134  return e.ClipArea;
135  }
136  }
137  return {};
138 }
139 
140 } // namespace UI;
141 
142 } // namespace YSLib;
143 
h void SetSize(const Size &) override
重新设置缓冲区大小。
Definition: ygdi.cpp:123
pt pt Y const IWidget &wgt GetLocationOf
Definition: ywidget.h:148
标准矩形像素图缓冲区。
Definition: ygdi.h:201
auto ClonePolymorphic(const _type &p) -> decltype(&*p)
使用 clone 成员函数复制指定指针指向的多态类类型对象。
Definition: ycutil.h:479
YF_API void Invalidate(IWidget &, const Rect &)
无效化:使相对于部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.cpp:111
部件渲染器。
Definition: yrender.h:46
部件绘制参数。
Definition: ywgtevt.h:276
bool IgnoreBackground
指定验证时忽略上层缓冲区背景。
Definition: yrender.h:110
void UpdateTo(const PaintContext &) const
更新至指定图形设备上下文的指定点。
Definition: yrender.cpp:97
sizeof(AlphaType)*GetAreaOf(GetSize())) using CompactPixmap void SetSize(const Size &) override
重新设置缓冲区大小。
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
Definition: ygdibase.h:235
_tWidget & wgt
Definition: ywgtevt.h:596
Rect rInvalidated
无效区域:包含所有新绘制请求的区域(不一定是最小的)。
Definition: yrender.h:97
Rect Validate(IWidget &wgt, IWidget &sender, const PaintContext &)
验证并按需绘制。
Definition: yrender.cpp:107
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
BufferedRenderer(bool={}, unique_ptr< Drawing::IImage >={})
构造:指定是否忽略上层缓冲区背景。
Definition: yrender.cpp:49
unique_ptr< Drawing::IImage > pImageBuffer
显示图像缓冲区指针。
Definition: yrender.h:103
virtual Rect Paint(IWidget &wgt, PaintEventArgs &&)
按参数绘制。
Definition: yrender.cpp:40
void SetImageBuffer(unique_ptr< Drawing::IImage >)
Definition: yrender.cpp:67
YF_API bool CopyTo(BitmapPtr, const CompactPixmapEx &, const Size &, const Point &, const Point &, const Size &, Rotation=RDeg0)
位图缓冲区向指针指定的缓冲区复制。
Definition: ygdi.cpp:234
bounds & r
Definition: ydraw.h:220
Rect Paint(IWidget &wgt, PaintEventArgs &&) override
按参数绘制。
Definition: yrender.cpp:86
c yconstfn g
Definition: ystyle.h:104
带缓冲的部件渲染器。
Definition: yrender.h:94
#define YB_LIKELY(expr)
Definition: ydef.h:297
屏幕区域大小。
Definition: ygdibase.h:249
enable_if_t<!is_array< _type >::value, std::unique_ptr< _type > > make_unique(_tParams &&...args)
使用 new 和指定参数构造指定类型的 std::unique_ptr 实例。
Definition: memory.hpp:213
#define YAssert(_expr, _msg)
Definition: cassert.h:73