YSTest: Shells.cpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

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