YSTest: Main.cpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

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