YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
yuicont.cpp
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2011 - 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/ydesktop.h"
29 
31 
33 
34 IWidget&
35 FetchTopLevel(IWidget& wgt)
36 {
37  auto pWgt(&wgt);
38 
39  while(const auto p = FetchContainerPtr(*pWgt))
40  pWgt = p;
41  return *pWgt;
42 }
43 IWidget&
44 FetchTopLevel(IWidget& wgt, Point& pt)
45 {
46  auto pWgt(&wgt);
47 
48  while(const auto p = FetchContainerPtr(*pWgt))
49  {
50  pt += GetLocationOf(*pWgt);
51  pWgt = p;
52  }
53  return *pWgt;
54 }
55 
56 
57 Point
58 LocateOffset(const IWidget* pEnd, Point pt, const IWidget* pWgt)
59 {
60  while(pWgt && pWgt != pEnd)
61  {
62  pt += GetLocationOf(*pWgt);
63  pWgt = FetchContainerPtr(*pWgt);
64  }
65  return pt;
66 }
67 
68 Point
69 LocateForWidget(IWidget& a, IWidget& b)
70 {
71  list<pair<IWidget*, Point>> lst;
72 
73  Point pt;
74  IWidget* pCon(&a);
75 
76  while(pCon)
77  {
78  lst.push_back(make_pair(pCon, pt));
79  pt += GetLocationOf(*pCon);
80  pCon = FetchContainerPtr(*pCon);
81  }
82  pCon = &b;
83  pt = Point();
84  while(pCon)
85  {
86  {
87  using ystdex::get_key;
88 
89  auto i(std::find(lst.begin() | get_key, lst.end() | get_key, pCon));
90 
91  if(i != lst.cend())
92  return pt - i.get()->second;
93  }
94  pt += GetLocationOf(*pCon);
95  pCon = FetchContainerPtr(*pCon);
96  }
97  return Point::Invalid;
98 }
99 
100 Point
101 LocateForParentContainer(const IWidget& wgt)
102 {
103  return FetchContainerPtr(wgt)
105  : Point::Invalid;
106 }
107 
108 
109 void
110 MoveToLeft(IWidget& wgt)
111 {
112  YAssert(FetchContainerPtr(wgt), "Null pointer found.");
113 
114  SetLocationOf(wgt, Point(0, GetLocationOf(wgt).Y));
115 }
116 
117 void
118 MoveToRight(IWidget& wgt)
119 {
120  YAssert(FetchContainerPtr(wgt), "Null pointer found.");
121 
123  - GetSizeOf(wgt).Width, GetLocationOf(wgt).Y));
124 }
125 
126 void
127 MoveToTop(IWidget& wgt)
128 {
129  YAssert(FetchContainerPtr(wgt), "Null pointer found.");
130 
131  SetLocationOf(wgt, Point(GetLocationOf(wgt).X, 0));
132 }
133 
134 void
135 MoveToBottom(IWidget& wgt)
136 {
137  YAssert(FetchContainerPtr(wgt), "Null pointer found.");
138 
140  GetSizeOf(*FetchContainerPtr(wgt)).Height - GetSizeOf(wgt).Height));
141 }
142 
143 
144 bool
145 MUIContainer::operator-=(IWidget& wgt)
146 {
147  using namespace ystdex;
148 
149  auto t(mWidgets.size());
150 
151  erase_all(mWidgets, mWidgets.begin() | get_value, mWidgets.end()
152  | get_value, &wgt);
153  t -= mWidgets.size();
154 
155  YAssert(t <= 1, "Duplicate desktop object pointer found.");
156 
157  return t != 0;
158 }
159 
161 MUIContainer::GetBegin()
162 {
163  using namespace ystdex;
164 
165  return mWidgets.rbegin() | get_value | get_indirect;
166 }
168 MUIContainer::GetEnd()
169 {
170  using namespace ystdex;
171 
172  return mWidgets.rend() | get_value | get_indirect;
173 }
174 
175 void
176 MUIContainer::Add(IWidget& wgt, ZOrderType z)
177 {
178  if(!Contains(wgt))
179  mWidgets.insert(make_pair(z, ItemType(&wgt)));
180 }
181 
182 bool
184 {
185  using ystdex::get_value;
186 
187  return std::find(mWidgets.cbegin() | get_value, mWidgets.cend() | get_value,
188  &wgt) != mWidgets.end();
189 }
190 
191 void
192 MUIContainer::PaintVisibleChildren(PaintEventArgs& e)
193 {
194  using ystdex::get_value;
195 
196  std::for_each(mWidgets.begin() | get_value, mWidgets.end() | get_value,
197  [&](IWidget* const& pWgt){
198  YAssert(pWgt, "Null pointer found.");
199 
200  auto& wgt(*pWgt);
201 
202  if(UI::IsVisible(wgt))
203  e.ClipArea |= PaintChild(wgt, e);
204  });
205 }
206 
208 
209 YSL_END
210