YSTest: Shells.cpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

Shells.cpp
浏览该文件的文档.
1 /*
2 © 2010-2016 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
33 using namespace ystdex;
34
35 namespace YReader
36 {
37
39 using Timers::HighResolutionClock;
40
41 namespace
42 {
43
44 ResourceMap GlobalResourceMap;
46 HighResolutionClock::duration gfx_init_time;
47
48 } // unnamed namespace;
49
50 DeclResource(GR_BGs)
51
52 namespace
53 {
54
55 using namespace YReader;
56
57 template<typename _tTarget>
58 _tTarget&
59 FetchGlobalResource(ResourceIndex idx)
60 {
61 if(!GlobalResourceMap[idx])
62 GlobalResourceMap[idx] = ValueObject(new _tTarget(), PointerTag());
63 return GlobalResourceMap[GR_BGs].GetObject<_tTarget>();
64 }
65
66 shared_ptr<Image>&
67 FetchGlobalImage(size_t idx)
68 {
69 auto& spi(FetchGlobalResource<array<shared_ptr<Image>, 10>>(GR_BGs));
70
71 YAssert(IsInInterval(idx, size_t(10)), "Index is out of range.");
72 return spi[idx];
73 }
74
75 } // unnamed namespace;
76
77 using namespace Shells;
78 using namespace Drawing::ColorSpace;
79
80 void
81 Cleanup()
82 {
83 for(size_t i(0); i != Image_N; ++i)
84 FetchGlobalImage(i).reset();
85 GlobalResourceMap.clear();
86 }
87
88 shared_ptr<Image>&
89 FetchImage(size_t i)
90 {
91 static Color(*const p_bg[Image_N])(SDst, SDst){
92 [](SDst x, SDst y) ynothrow -> Color{
93 return {~(x * y) >> 2, x | y | 128, 240 - ((x & y) >> 1)};
94 },
95 [](SDst x, SDst y) ynothrow -> Color{
96 return {(x << 4) / (y | 1), (x | y << 1) % (y + 2),
97 (~y | x << 1) % 27 + 3};
98 },
99 [](SDst x, SDst y) ynothrow -> Color{
100 return {~(x * y) >> 2, x | y | 128, 240 - ((x & y) >> 1)};
101 }
102 };
103
104 auto& h(FetchGlobalImage(i));
105
106 if(!h && p_bg[i])
107 {
108 h = make_shared<Image>(nullptr, MainScreenWidth, MainScreenHeight);
109 gfx_init_time += ytest::timing::once(HighResolutionClock::now,
110 [](BitmapPtr buf, decltype(*p_bg) f){
111 for(SDst y(0); y < MainScreenHeight; ++y)
112 for(SDst x(0); x < MainScreenWidth; yunseq(++x, ++buf))
113 *buf = f(x, y);
114 }, h->GetBufferPtr(), p_bg[i]);
115 }
116 return h;
117 }
118
119 double
120 FetchImageLoadTime()
121 {
122 return gfx_init_time.count() / 1e9;
123 }
124
125
126 WidgetLoader&
127 FetchWidgetLoader()
128 {
129 static WidgetLoader wgt_ldr;
130 static struct Init
131 {
132 Init()
133 {
134 #define YSL_RegWidget Widget, Control, Panel, Window, Label, \
135 Button, CheckButton, RadioButton, DropDownList, FileBox, \
136 TextBox, TabBar, TabControl, TreeList, TreeView
137 #define YSL_RegWidget_Str {"Widget", "Control", "Panel", "Window", "Label", \
138 "Button", "CheckButton", "RadioButton", "DropDownList", "FileBox", \
139 "TextBox", "TabBar", "TabControl", "TreeList", "TreeView"}
140
141 wgt_ldr.Default.Register<YSL_RegWidget>(YSL_RegWidget_Str),
142 wgt_ldr.Bounds.Register<YSL_RegWidget>(YSL_RegWidget_Str),
143 wgt_ldr.Insert.Register<Panel, TabBar, TabControl>({"Panel",
144 "TabBar", "TabControl"}),
145 wgt_ldr.InsertZOrdered.Register<Panel>({"Panel"});
146 #undef YSL_RegWidget_Str
147 #undef YSL_RegWidget
148 }
149 } obj;
150
151 yunused(obj);
152 return wgt_ldr;
153 }
154
155 void
156 AddButtonToTabBar(TabControl& tc, ValueNode& node, const string& name,
157 const String& text, SDst w)
158 {
159 auto& tb(tc.GetTabBarRef());
160 auto p_tab(make_shared<Button>(Rect({}, w, tc.BarHeight)));
161
162 p_tab->Text = text,
163 tb += *p_tab,
164 tc.Attach(*p_tab);
165 node += AsNode(name, std::move(p_tab));
166 }
167
168 } // namespace YReader;
169
YSL_RegWidget
#define YSL_RegWidget
YSLib::Drawing::x
The boundary is out of the const Rect SDst SPos x
Definition: YDraw.h:127
YSLib::Drawing::w
The boundary is out of the const Rect SDst w
Definition: YDraw.h:127
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
YSLib::Text::buf
const char * buf
Definition: TextFile.h:77
YSLib::UI::WidgetLoader::Bounds
GWidgetRegister< const Rect & > Bounds
Definition: Loader.h:240
YSLib::IsInInterval
YB_STATELESS bool IsInInterval(_type i, _type b) ynothrow
判断 i 是否在左闭右开区间 [_type(0), b) 中。
Definition: YCoreUtilities.h:84
Shells
YSLib::ResourceMap
map< ResourceIndex, ValueObject > ResourceMap
Definition: Shells.h:45
YReader::Image_N
yconstexpr const size_t Image_N(3)
NPL::A1::name
ctx const string & name
Definition: NPLA1.h:248
YSLib::UI::WidgetLoader::InsertZOrdered
GWidgetInserterRegister< IWidget &, const ZOrder & > InsertZOrdered
Definition: Loader.h:244
platform::Color
颜色。
Definition: Video.h:451
YReader::FetchImage
shared_ptr< Image > & FetchImage(size_t)
Definition: Shells.cpp:89
YSLib::ResourceIndex
decltype(__LINE__) ResourceIndex
Definition: Shells.h:44
YReader
Definition: About.h:33
YAssert
#define YAssert(_expr, _msg)
Definition: cassert.h:105
yunused
#define yunused(...)
标记未使用的表达式。
Definition: ydef.h:942
YReader::AddButtonToTabBar
void AddButtonToTabBar(TabControl &, ValueNode &, const string &, const String &, SDst=64)
向标签栏和节点添加按钮。
Definition: Shells.cpp:156
Color
Pixel Color
Definition: CharRenderer.cpp:58
ytest::timing::once
auto once(_fNow now, _func &&f, _tParams &&...args) -> decltype(now()-now())
测试指定函数执行一次的时间。
Definition: timing.hpp:59
ystdex::path_category::node
YSLib::UI::WidgetLoader
部件加载器。
Definition: Loader.h:236
ShlReader.h
Shell 阅读器框架。
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:996
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
ystdex
特性测试宏。
Definition: ydef.h:796
YReader::Cleanup
void Cleanup()
全局资源清理。
Definition: Shells.cpp:81
YSLib::UI::WidgetLoader::Insert
GWidgetInserterRegister< IWidget & > Insert
Definition: Loader.h:242
YSLib::Drawing::BitmapPtr
Pixel * BitmapPtr
Definition: YGraphics.h:42
DeclResource
#define DeclResource(_name)
Definition: Shells.h:47
YSLib::UI::WidgetLoader::Default
GWidgetRegister Default
Definition: Loader.h:239
ShlExplorer.h
文件浏览器。
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
YReader::FetchWidgetLoader
WidgetLoader & FetchWidgetLoader()
Definition: Shells.cpp:127
YSLib::i
return i
Definition: YCoreUtilities.h:176
YSLib::UI::Panel
面板。
Definition: ypanel.h:45
Shells.h
Shell 框架逻辑。
YSLib::PointerTag
指示指针的标记。
Definition: YObject.h:66
ColorSpace
YSLib::UI::TabBar
标签栏控件。
Definition: TabControl.h:45
YSLib::ValueNode
值类型节点。
Definition: ValueNode.h:57
timing.hpp
运行计时测试工具。
YSLib::GHandlerRegisterBase::Register
void Register(const _tKey &key)
Definition: YFunc.hpp:104
YSL_RegWidget_Str
#define YSL_RegWidget_Str
YSLib::IO::f
const string &path const String &path _func f
Definition: YSLib/Service/FileSystem.h:430
YReader::FetchImageLoadTime
double FetchImageLoadTime()
Definition: Shells.cpp:120
YSLib::ValueObject
值类型对象类。
Definition: YObject.h:272
YSLib::UI::Styles::Panel
面板背景。
Definition: YStyle.h:312
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:43