YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
yuicont.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_YDesktop
30 
31 using namespace ystdex;
32 
33 namespace YSLib
34 {
35 
36 namespace UI
37 {
38 
39 IWidget&
40 FetchTopLevel(IWidget& wgt)
41 {
42  auto p_wgt(&wgt);
43 
44  while(const auto p = FetchContainerPtr(*p_wgt))
45  p_wgt = p;
46  return *p_wgt;
47 }
48 IWidget&
49 FetchTopLevel(IWidget& wgt, Point& pt)
50 {
51  auto p_wgt(&wgt);
52 
53  while(const auto p = FetchContainerPtr(*p_wgt))
54  {
55  pt += GetLocationOf(*p_wgt);
56  p_wgt = p;
57  }
58  return *p_wgt;
59 }
60 
61 
62 Point
63 LocateOffset(const IWidget* p_end, Point pt, const IWidget* p_wgt)
64 {
65  while(p_wgt && p_wgt != p_end)
66  {
67  pt += GetLocationOf(*p_wgt);
68  p_wgt = FetchContainerPtr(*p_wgt);
69  }
70  return pt;
71 }
72 
73 Point
74 LocateForWidget(const IWidget& a, const IWidget& b)
75 {
76  list<pair<const IWidget*, Point>> lst;
77 
78  Point pt;
79  const IWidget* pCon(&a);
80 
81  while(pCon)
82  {
83  lst.push_back(make_pair(pCon, pt));
84  pt += GetLocationOf(*pCon);
85  pCon = FetchContainerPtr(*pCon);
86  }
87  pCon = &b;
88  pt = {};
89  while(pCon)
90  {
91  {
92  auto i(std::find(lst.begin() | get_key, lst.end() | get_key, pCon));
93 
94  if(i != lst.cend())
95  return pt - i.get()->second;
96  }
97  pt += GetLocationOf(*pCon);
98  pCon = FetchContainerPtr(*pCon);
99  }
100  return Point::Invalid;
101 }
102 
103 Point
105 {
106  return FetchContainerPtr(wgt)
107  ? LocateContainerOffset(*FetchContainerPtr(wgt), GetLocationOf(wgt))
108  : Point::Invalid;
109 }
110 
111 
112 void
113 MoveToLeft(IWidget& wgt)
114 {
115  YAssertNonnull(FetchContainerPtr(wgt));
116  SetLocationOf(wgt, Point(0, GetLocationOf(wgt).Y));
117 }
118 
119 void
120 MoveToRight(IWidget& wgt)
121 {
122  YAssertNonnull(FetchContainerPtr(wgt));
123  SetLocationOf(wgt, Point(GetSizeOf(*FetchContainerPtr(wgt)).Width
124  - GetSizeOf(wgt).Width, GetLocationOf(wgt).Y));
125 }
126 
127 void
128 MoveToTop(IWidget& wgt)
129 {
130  YAssertNonnull(FetchContainerPtr(wgt));
131  SetLocationOf(wgt, Point(GetLocationOf(wgt).X, 0));
132 }
133 
134 void
135 MoveToBottom(IWidget& wgt)
136 {
137  YAssertNonnull(FetchContainerPtr(wgt));
139  GetSizeOf(*FetchContainerPtr(wgt)).Height - GetSizeOf(wgt).Height));
140 }
141 
142 
143 bool
144 RemoveFrom(IWidget& wgt, IWidget& con)
145 {
146  if(FetchContainerPtr(wgt) == &con)
147  {
148  SetContainerPtrOf(wgt);
149  if(FetchFocusingPtr(con) == &wgt)
150  con.GetView().FocusingPtr = {};
151  return true;
152  }
153  return {};
154 }
155 
156 
157 void
158 MLinearUIContainer::operator+=(IWidget& wgt)
159 {
160  if(!Contains(wgt))
161  vWidgets.push_back(&wgt);
162 }
163 
164 bool
165 MLinearUIContainer::operator-=(IWidget& wgt)
166 {
167  auto t(vWidgets.size());
168 
169  erase_all(vWidgets, &wgt);
170  t -= vWidgets.size();
171  YAssert(t <= 1, "Duplicate widget pointer found.");
172  return t != 0;
173 }
174 
175 bool
176 MLinearUIContainer::Contains(IWidget& wgt) const
177 {
178  return
179  std::find(vWidgets.cbegin(), vWidgets.cend(), &wgt) != vWidgets.end();
180 }
181 
182 size_t
183 MLinearUIContainer::Find(IWidget& wgt) const
184 {
185  return
186  std::find(vWidgets.cbegin(), vWidgets.cend(), &wgt)- vWidgets.cbegin();
187 }
188 
190 MLinearUIContainer::begin()
191 {
192  return vWidgets.begin() | get_indirect;
193 }
194 
195 MLinearUIContainer::iterator
196 MLinearUIContainer::end()
197 {
198  return vWidgets.end() | get_indirect;
199 }
200 
201 
202 bool
203 MUIContainer::operator-=(IWidget& wgt)
204 {
205  auto t(mWidgets.size());
206 
207  erase_all(mWidgets, mWidgets.begin() | get_value, mWidgets.end()
208  | get_value, &wgt);
209  t -= mWidgets.size();
210  YAssert(t <= 1, "Duplicate widget pointer found.");
211  return t != 0;
212 }
213 
214 void
215 MUIContainer::Add(IWidget& wgt, ZOrderType z)
216 {
217  if(!Contains(wgt))
218  mWidgets.insert(make_pair(z, ItemType(&wgt)));
219 }
220 
221 bool
223 {
224  return std::find(mWidgets.cbegin() | get_value, mWidgets.cend() | get_value,
225  &wgt) != mWidgets.end();
226 }
227 
228 void
229 MUIContainer::PaintVisibleChildren(PaintEventArgs& e)
230 {
231  std::for_each(mWidgets.begin() | get_value, mWidgets.end() | get_value,
232  [&](IWidget* const& p_wgt){
233  YAssertNonnull(p_wgt);
234 
235  auto& wgt(*p_wgt);
236 
237  PaintVisibleChild(wgt, e);
238  });
239 }
240 
242 MUIContainer::QueryZ(IWidget& wgt) const
243 {
244  for(auto& pr : mWidgets)
245  if((YAssertNonnull(pr.second), pr.second) == &wgt)
246  return pr.first;
247  throw std::out_of_range("Widget not found.");
248 }
249 
251 MUIContainer::begin()
252 {
253  return mWidgets.rbegin() | get_value | get_indirect;
254 }
255 
257 MUIContainer::end()
258 {
259  return mWidgets.rend() | get_value | get_indirect;
260 }
261 
262 } // namespace UI;
263 
264 } // namespace YSLib;
265 
Point LocateContainerOffset(const IWidget &wgt, const Point &pt)
取相对部件 wgt 的点 pt 相对于 wgt 的容器的偏移坐标。
Definition: yuicont.h:70
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化:使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.h:156
pt pt Y const IWidget &wgt GetLocationOf
Definition: ywidget.h:148
YF_API Point LocateOffset(const IWidget *, Point, const IWidget *)
取相对于第三参数指向的部件的点相对于第一参数指向的容器的偏移坐标。
Definition: yuicont.cpp:63
YF_API void SetLocationOf(IWidget &, const Point &)
设置部件左上角所在位置(相对于容器的偏移坐标)。
Definition: ywidget.cpp:73
部件绘制参数。
Definition: ywgtevt.h:276
GIHEvent< UIEventArgs && > ItemType
Definition: ywgtevt.h:424
const struct ystdex::indirect_tag get_indirect
YF_API void MoveToBottom(IWidget &wgt)
移动部件 wgt 至容器下端。
Definition: yuicont.cpp:135
YF_API bool RemoveFrom(IWidget &, IWidget &)
从容器中移除部件。
Definition: yuicont.cpp:144
YF_API void MoveToRight(IWidget &wgt)
移动部件 wgt 至容器右端。
Definition: yuicont.cpp:120
YF_API void PaintVisibleChild(IWidget &, PaintEventArgs &)
调用 PaintChild 指定子部件并合并参数的重绘区域。
Definition: ywidget.cpp:192
const second_tag get_value
Definition: iterator.hpp:785
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
Definition: ygdibase.h:235
YF_API void MoveToTop(IWidget &wgt)
移动部件 wgt 至容器上端。
Definition: yuicont.cpp:128
_tWidget & wgt
Definition: ywgtevt.h:596
YF_API IWidget & FetchTopLevel(IWidget &)
取指定部件的顶层部件。
Definition: yuicont.cpp:40
屏幕二元组。
Definition: ygdibase.h:54
u8 ZOrderType
Definition: yuicont.h:146
#define YAssertNonnull(_expr)
Definition: cassert.h:81
YF_API Point LocateForParentContainer(const IWidget &)
取指定部件相对于容器的父容器的偏移坐标。
Definition: yuicont.cpp:104
YF_API Point LocateForWidget(const IWidget &, const IWidget &)
取第二参数指定的部件相对于第一参数指定的部件的偏移坐标。
Definition: yuicont.cpp:74
动态泛型输入迭代器。
p1 p1 Y
Definition: ydraw.h:188
Selected const shared_ptr< ListType > const pair< Color, Color > viewer Contains
Definition: textlist.h:124
if(YB_UNLIKELY(r >=sGraphics.Height)) throw std return pBuffer r *sGraphics Width
Definition: ygdibase.cpp:155
const first_tag get_key
Definition: iterator.hpp:784
pt pt Y FetchFocusingPtr
Definition: ywidget.h:140
YF_API void MoveToLeft(IWidget &wgt)
移动部件 wgt 至容器左端。
Definition: yuicont.cpp:113
#define YAssert(_expr, _msg)
Definition: cassert.h:73
void erase_all(_tRange &c, const typename _tRange::value_type &val)
删除指定序列范围中和指定值的相等的元素。
Definition: container.hpp:387