YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
Shells.cpp
浏览该文件的文档.
1 /*
2  © 2010-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 "Shells.h"
29 #include "ShlExplorer.h"
30 #include "ShlReader.h"
31 #include <ytest/timing.hpp>
32 
34 //测试用声明:全局资源定义。
35 //extern char gstr[128];
36 
37 using namespace ystdex;
38 
39 namespace YReader
40 {
41 
42 namespace
43 {
44 
45 ResourceMap GlobalResourceMap;
47 double gfx_init_time;
48 
49 } // unnamed namespace;
50 
51 DeclResource(GR_BGs)
52 
53 namespace
54 {
55 
56 using namespace YReader;
57 
58 //测试函数。
59 
60 template<typename _tTarget>
61 _tTarget&
62 FetchGlobalResource(ResourceIndex idx)
63 {
64  if(!GlobalResourceMap[idx])
65  GlobalResourceMap[idx] = ValueObject(new _tTarget(), PointerTag());
66  return GlobalResourceMap[GR_BGs].GetObject<_tTarget>();
67 }
68 
69 shared_ptr<Image>&
70 FetchGlobalImage(size_t idx)
71 {
72  auto& spi(FetchGlobalResource<array<shared_ptr<Image>, 10>>(GR_BGs));
73 
74  YAssert(IsInInterval(idx, 10u), "Index is out of range.");
75  return spi[idx];
76 }
77 
78 } // unnamed namespace;
79 
80 using namespace Shells;
81 using namespace Drawing::ColorSpace;
82 
83 void
85 {
86  for(size_t i(0); i != Image_N; ++i)
87  FetchGlobalImage(i).reset();
88  GlobalResourceMap.clear();
89  ReleaseStored<ShlReader>();
90  ReleaseStored<ShlExplorer>();
91 }
92 
93 shared_ptr<Image>&
94 FetchImage(size_t i)
95 {
96  static Color(*const p_bg[Image_N])(SDst, SDst){
97  [](SDst x, SDst y)->Color{
98  return {~(x * y) >> 2, x | y | 128, 240 - ((x & y) >> 1)};
99  },
100  [](SDst x, SDst y)->Color{
101  return {(x << 4) / (y | 1), (x | y << 1) % (y + 2),
102  (~y | x << 1) % 27 + 3};
103  },
104  [](SDst x, SDst y)->Color{
105  return {~(x * y) >> 2, x | y | 128, 240 - ((x & y) >> 1)};
106  }
107  };
108 
109  if(!FetchGlobalImage(i) && p_bg[i])
110  {
111  auto& h(FetchGlobalImage(i));
112 
113  if(!h)
114  h = make_shared<Image>(nullptr, MainScreenWidth, MainScreenHeight);
115  gfx_init_time += ytest::timing::once(Timers::HighResolutionClock::now,
116  ScrDraw<BitmapPtr, decltype(*p_bg)>, h->GetBufferPtr(), p_bg[i])
117  .count() / 1e9;
118  }
119  return FetchGlobalImage(i);
120 }
121 
122 double
124 {
125  return gfx_init_time;
126 }
127 
128 
131 {
132  static WidgetLoader wgt_ldr;
133  static struct Init
134  {
135  Init()
136  {
139  TextBox, TabBar, TabControl>({"Widget", "Control", "Panel",
140  "Window", "Label", "Button", "CheckButton", "RadioButton",
141  "DropDownList", "FileBox", "TextBox", "TabBar", "TabControl"}),
142  wgt_ldr.Bounds.Register<Widget, Control, Panel, Window, Label,
143  Button, CheckButton, RadioButton, DropDownList, FileBox,
144  TextBox, TabBar, TabControl>({"Widget", "Control", "Panel",
145  "Window", "Label", "Button", "CheckButton", "RadioButton",
146  "DropDownList", "FileBox", "TextBox", "TabBar", "TabControl"}),
147  wgt_ldr.Insert.Register<Panel, TabBar, TabControl>({"Panel",
148  "TabBar", "TabControl"}),
149  wgt_ldr.InsertZOrdered.Register<Panel>({"Panel"});
150  }
151  } obj;
152 
153  yunused(obj);
154  return wgt_ldr;
155 }
156 
157 void
158 AddButtonToTabBar(TabControl& tc, const ValueNode& node, const string& name,
159  const String& text, SDst w)
160 {
161  auto& tb(tc.GetTabBarRef());
162  auto p_tab(make_shared<Button>(Rect(0, 0, w, tc.BarHeight)));
163 
164  p_tab->Text = text,
165  tb += *p_tab,
166  tc.Attach(*p_tab);
167  node += {0, name, std::move(p_tab)};
168 }
169 
170 } // namespace YReader;
171 
GWidgetInserterRegister< IWidget & > Insert
Definition: Loader.h:228
const vector< Panel * > tab_pages void Attach(Control &)
附加:添加 TouchDown 事件处理器。
Definition: TabControl.cpp:144
GWidgetInserterRegister< IWidget &, const ZOrderType & > InsertZOrdered
Definition: Loader.h:230
下拉列表。
Definition: ComboList.h:230
GetTabBarRef().GetCount()) DefGetter(const ynothrow
#define yunused(...)
标记未使用的表达式。
Definition: ydef.h:697
void Cleanup()
全局资源清理。
Definition: Shells.cpp:84
SDst BarHeight
标签栏初始高。
Definition: TabControl.h:118
单选按钮。
Definition: Selector.h:344
面板。
Definition: ypanel.h:45
按钮。
Definition: button.h:116
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
#define DeclResource(_name)
Definition: Shells.h:49
部件加载器。
Definition: Loader.h:222
控件。
Definition: ycontrol.h:275
指示指针的标记。
Definition: yobject.h:63
值类型对象类。
Definition: yobject.h:281
auto once(_fNow now, _fCallable &&f, _tParams &&...args) -> decltype(now()-now())
测试指定函数执行一次的时间。
Definition: timing.hpp:64
文件列表框。
Definition: ComboList.h:162
窗口背景。
Definition: ystyle.h:182
void Register(const _tKey &key)
Definition: yfunc.hpp:358
文本框。
Definition: TextBox.h:128
yconstfn const string & name
Definition: Loader.h:110
map< ResourceIndex, ValueObject > ResourceMap
Definition: Shells.h:47
WidgetLoader & FetchWidgetLoader()
Definition: Shells.cpp:130
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
值类型节点。
Definition: ValueNode.h:45
标签。
Definition: label.h:104
void ScrDraw(_tOut buf, _tGen &&f)
全屏幕描点。
Definition: ShellHelper.h:307
面板背景。
Definition: ystyle.h:183
GWidgetRegister< const Rect & > Bounds
Definition: Loader.h:226
shared_ptr< Image > & FetchImage(size_t)
Definition: Shells.cpp:94
Shell 框架逻辑。
GWidgetRegister Default
Definition: Loader.h:225
Color
控制台颜色枚举。
Definition: Video.h:458
标签栏控件。
Definition: TabControl.h:45
PixelType * BitmapPtr
Definition: Video.h:295
复选按钮。
Definition: Selector.h:202
void AddButtonToTabBar(TabControl &, const ValueNode &, const string &, const String &, SDst=64)
向标签栏和节点添加按钮。
Definition: Shells.cpp:158
颜色。
Definition: Video.h:339
decltype(__LINE__) ResourceIndex
Definition: Shells.h:46
部件。
Definition: ywidget.h:356
bool IsInInterval(_type i, _type b) ynothrow
判断 i 是否在左闭右开区间 [FetchZero<_type>(), b) 中。
Definition: ycutil.h:140
double FetchImageLoadTime()
Definition: Shells.cpp:123
Shell 阅读器框架。
yconstexpr size_t Image_N(3)
文件浏览器。
#define YAssert(_expr, _msg)
Definition: cassert.h:73
标签容器控件。
Definition: TabControl.h:112