YSTest: Main.cpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

YSTest/source/Main.cpp
浏览该文件的文档.
1 /*
2 © 2009-2016, 2018 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 "ShlExplorer.h"
29 #include YFM_Helper_Initialization
30
31 using namespace platform;
32 using std::puts;
33
34 namespace YSLib
35 {
36
37 //调试功能。
38 namespace
39 {
40
41 #ifdef YSL_USE_MEMORY_DEBUG
42
43 void
44 OnExit_DebugMemory_continue()
45 {
46 #if !YCL_Android
47 std::puts("Input to continue...");
48 platform::WaitForInput();
49 #endif
50 }
51
55 template<size_t _vN, class _tCon>
56 void
57 OnExit_DebugMemory_print(_tCon& con, const char* item_name)
58 {
59 if(!con.empty())
60 {
61 #if !YCL_Android
62 YTraceDe(Warning, "%zu %s(s) detected:\n", con.size(), item_name);
63 #else
64 // XXX: Size of %std::size is expected.
65 std::fprintf(stderr, "%zu %s(s) detected:\n", con.size(), item_name);
66 #endif
67
68 typename _tCon::size_type n(0);
69
70 for(const auto& item : con)
71 {
72 if(n++ < _vN)
73 GetDebugMemoryList().Print(item, stderr);
74 else
75 {
76 n = 0;
77 OnExit_DebugMemory_continue();
78 }
79 }
80 OnExit_DebugMemory_continue();
81 }
82 }
83
87 void
88 OnExit_DebugMemory()
89 {
90 using namespace platform;
91 #if YCL_DS
92 namespace ColorSpace = Drawing::ColorSpace;
93
94 platform_ex::DSConsoleInit({}, ColorSpace::White, ColorSpace::Blue);
95 #endif
96 std::puts("Normal exit;");
97
98 // std::FILE* fp(std::freopen("memdbg.log", "w", stderr));
99 OnExit_DebugMemory_print<4>(GetDebugMemoryList().Blocks, "memory leak");
100 OnExit_DebugMemory_print<4>(GetDebugMemoryList().DuplicateDeletedBlocks,
101 "duplicate memory deleting");
102 #if 0
103 DebugMemory.PrintAll(stderr);
104 DebugMemory.PrintAll(fp);
105 DebugMemory.PrintAllDuplicate(stderr);
106 DebugMemory.PrintAllDuplicate(fp);
107 #endif
108 // std::fclose(fp);
109 #if !YCL_Android
110 std::puts("Input to terminate...");
111 WaitForInput();
112 #endif
113 }
114
115 #endif
116
120 void
121 Repaint(Desktop& dsk)
122 {
123 SetInvalidationOf(dsk);
124 dsk.Validate();
125 dsk.Update();
126 }
127
128 } // unnamed namespace;
129
130
132
133
134
135 } // namespace YSLib;
136
138 int
139 #if YCL_Android
140 y_android_main()
141 #else
142 main()
143 #endif
144 {
145 using namespace YSLib;
146
147 const auto res(FilterExceptions([]{
148 {
149 DSApplication app;
150
151 YTraceDe(Debug, "Application initialized.");
152 {
153 using namespace YSLib::UI;
154 using YReader::Image_N;
155
156 Desktop dsk_m(app.GetScreenUp()), dsk_s(app.GetScreenDown());
157 Label lblTitle({50, 20, 100, 22}), lblStatus({60, 80, 120, 22}),
158 lblDetails({30, 20, 160, 22});
159 ProgressBar pb({8, 168, 240, 16}, Image_N);
160
161 AddWidgets(dsk_m, lblTitle, lblStatus, pb);
162 dsk_s += lblDetails;
163 yunseq(
164 dsk_m.Background = SolidBrush({240, 216, 192}),
165 dsk_s.Background = SolidBrush(
166 FetchGUIConfiguration().Colors[Styles::Desktop]),
167 //Color(240, 216, 240),
168 lblTitle.Text = G_APP_NAME,
169 lblStatus.Text = u"Now loading...",
170 lblDetails.Text = u"初始化中，请稍后……",
171 lblDetails.ForeColor = Drawing::ColorSpace::White
172 );
173 lblDetails.Background = nullptr;
174 SetInvalidationOf(dsk_m);
175 yunseq(dsk_m.Validate(), dsk_s.Validate());
176 dsk_m.Update(), dsk_s.Update();
177 YTraceDe(Debug, "Static screens updated.");
178 //初始化所有图像资源。
179 for(size_t i(0); i < Image_N; ++i)
180 {
181 pb.SetValue(i);
182 // Invalidate(pb);
183 dsk_m.Background
184 = SolidBrush(Color(255 - i * 255 / Image_N, 216, 192));
185 Repaint(dsk_m);
186 YReader::FetchImage(i);
187 }
188 pb.SetValue(Image_N);
189 Repaint(dsk_m);
190 }
191 YTraceDe(Debug, "Splash completed.");
192 Execute(app, make_shared<YReader::ShlExplorer>());
193 //释放 Shell （必要，保证释放 Shell 且避免资源泄漏）。
194 YReader::Cleanup();
195 }
196
197 #ifdef YSL_USE_MEMORY_DEBUG
198 OnExit_DebugMemory();
199 #endif
200 }, yfsig, Alert, TraceForOutermost)
201 ? EXIT_FAILURE : EXIT_SUCCESS);
202 return res;
203 }
204
YSLib::Drawing::SolidBrush
单色画刷。
Definition: YBrush.h:59
ShlExplorer.h
文件浏览器。
YSLib::Consoles::White
@ White
Definition: YConsole.h:68
yfsig
#define yfsig
展开为表示函数签名的预定义变量的宏。
Definition: ydef.h:1133
G_APP_NAME
#define G_APP_NAME
Definition: Shells.h:56
YSLib::Consoles::Blue
@ Blue
Definition: YConsole.h:62
YSLib::UI::Styles::Desktop
@ Desktop
桌面背景。
Definition: YStyle.h:310
YSLib::UI::Label
标签。
Definition: Label.h:143
YSLib::UI
Definition: ShellHelper.h:272
YReader::Cleanup
void Cleanup()
全局资源清理。
Definition: Shells.cpp:79
YSLib::Execute
void Execute(GUIApplication &app, shared_ptr< Shell > p_shl)
Definition: GUIApplication.cpp:308
platform::Descriptions::Alert
@ Alert
Definition: YCommon.h:180
YSLib::UI::AddWidgets
void AddWidgets(_tCon &con, _tWidgets &... wgts)
向部件容器添加子部件。
Definition: YUIContainer.h:446
YSLib::TraceForOutermost
YF_API void TraceForOutermost(const std::exception &, RecordLevel) ynothrow
处理最外层边界的异常，若捕获致命错误则在之后终止程序。
Definition: Initialization.cpp:619
platform::WaitForInput
YF_API void WaitForInput()
等待任意按键。
Definition: Input.cpp:46
YSLib::UI::FetchGUIConfiguration
GUIConfiguration & FetchGUIConfiguration()
Definition: YGUI.cpp:517
YSLib::i
return i
Definition: YCoreUtilities.h:177
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1535
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:407
YSLib::FilterExceptions
bool FilterExceptions(_func f, const char *desc={}, RecordLevel lv=Alert, ExceptionTracer trace=ExtractAndTrace) ynothrow
调用函数并过滤宿主异常。
Definition: YException.h:225
YReader::FetchImage
YB_ATTR_nodiscard shared_ptr< Image > & FetchImage(size_t)
Definition: Shells.cpp:87
platform::Descriptions::Warning
@ Warning
Definition: YCommon.h:183
platform
默认平台命名空间。
Definition: Container.h:56
main
int main()
Definition: YSTest/source/Main.cpp:142
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
Color
Pixel Color
Definition: CharRenderer.cpp:59
YSLib::UI::ProgressBar
进度条。
Definition: Progress.h:47
YReader::Image_N
yconstexpr const size_t Image_N(3)
fp
tidy_ptr< std::streambuf > fp
Definition: TextManager.cpp:93
YSLib::UI::SetInvalidationOf
void SetInvalidationOf(IWidget &wgt)
Definition: YWidget.cpp:63
platform::Descriptions::Debug
@ Debug
Definition: YCommon.h:186