YSTest: yrender.cpp 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
yrender.cpp
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2009 - 2013.
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/yrender.h"
29 #include "YSLib/UI/ycontrol.h"
30 #include "YSLib/Service/ydraw.h"
31
32 YSL_BEGIN
33
34 YSL_BEGIN_NAMESPACE(UI)
35
36 Rect
37 Renderer::Paint(IWidget& wgt, PaintEventArgs&& e)
38 {
39 YAssert(&e.GetSender().GetRenderer() == this, "Invalid widget found.");
40
41 CallEvent<UI::Paint>(wgt, e);
42 return e.ClipArea;
43 }
44
45
46 bool
47 BufferedRenderer::RequiresRefresh() const
48 {
49 return bool(rInvalidated);
50 }
51
52 void
53 BufferedRenderer::SetSize(const Size& s)
54 {
55 Buffer.SetSize(s.Width, s.Height);
56 rInvalidated.GetSizeRef() = s;
57 }
58
59 Rect
60 BufferedRenderer::CommitInvalidation(const Rect& r)
61 {
62 return rInvalidated |= r;
63 }
64
65 Rect
66 BufferedRenderer::Paint(IWidget& wgt, PaintEventArgs&& e)
67 {
68 YAssert(&e.GetSender().GetRenderer() == this, "Invalid widget found.");
69
70 const Rect& r(Validate(wgt, e.GetSender(), e));
71
72 UpdateTo(e);
73 return r;
74 }
75
76 void
77 BufferedRenderer::UpdateTo(const PaintContext& pc) const
78 {
79 const auto& g(pc.Target);
80 const Rect& r(pc.ClipArea);
81
82 CopyTo(g.GetBufferPtr(), GetContext(), g.GetSize(), r.GetPoint(),
83 r.GetPoint() - pc.Location, r.GetSize());
84 }
85
86 Rect
87 BufferedRenderer::Validate(IWidget& wgt, IWidget& sender,
88 const PaintContext& pc)
89 {
90 if(RequiresRefresh())
91 {
92 const auto& l(GetLocationOf(sender));
93
94 if(!IgnoreBackground && FetchContainerPtr(sender))
95 Invalidate(sender);
96
97 const Rect& clip(pc.ClipArea & (rInvalidated + l));
98
99 if(!IgnoreBackground && FetchContainerPtr(sender))
100 {
101 const auto& g(GetContext());
102
103 CopyTo(g.GetBufferPtr(), pc.Target, g.GetSize(),
104 clip.GetPoint() - pc.Location, clip.GetPoint(), clip.GetSize());
105 }
106
107 PaintEventArgs e(sender, {GetContext(), Point(), clip - l});
108
109 CallEvent<UI::Paint>(wgt, e);
110 //清除无效区域：只设置一个分量为零可能会使 CommitInvalidation 结果错误。
111 rInvalidated.GetSizeRef() = Size();
112 return e.ClipArea;
113 }
114 return {};
115 }
116
117 YSL_END_NAMESPACE(UI)
118
119 YSL_END
120