YSTest: ShellHelper.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

ShellHelper.h
浏览该文件的文档.
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 #ifndef INC_Helper_ShellHelper_h_
29 #define INC_Helper_ShellHelper_h_ 1
30
31 #include <Helper/YModules.h>
32 #include <YCLib/YModules.h>
33 #include YFM_YCLib_Debug
34 #include YFM_YSLib_UI_YDesktop // for UI::Desktop;
35 #include YFM_YSLib_Core_YApplication // for Shell, FetchAppInstance;
36 #include YFM_YSLib_Service_YTimer // for Timers::HighResolutionClock;
37 #include <ystdex/cast.hpp> // for ystdex::polymorphic_downcast;
38 #include YFM_YSLib_UI_ListControl // for UI::TextList::ListType;
39
40 namespace YSLib
41 {
42
43 #ifndef NDEBUG
44
50 class YF_API DebugTimer
51 {
52 protected:
54 string event_info;
55 Timers::HighResolutionClock::time_point base_tick;
56
57 public:
62 DebugTimer(string_view = "");
63 ~DebugTimer();
64 };
65 # define YSL_DEBUG_DECL_TIMER(_name, ...) DebugTimer _name(__VA_ARGS__);
66 #else
67 # define YSL_DEBUG_DECL_TIMER(...)
68 #endif
69
70
75 template<class _tShell, typename _tConnection = lref<_tShell>>
76 class GShellSession
77 {
78 public:
79 using Shell = _tShell;
80 using Connection = _tConnection;
81
82 private:
83 Connection conn;
84
85 public:
86 template<typename... _tParam>
87 GShellSession(_tParam&&... args)
88 : conn(yforward(args)...)
89 {}
90
91 virtual DefDeDtor(GShellSession)
92
93 DefGetter(const ynothrow, _tShell&, Shell, conn)
94 };
95
96
97 namespace Text
98 {
99
104 using EncodingInfoItem = pair<Encoding, const char16_t*>;
105
110 yconstexpr const EncodingInfoItem Encodings[]{{CharSet::UTF_8, u"UTF-8"},
111 {CharSet::GBK, u"GBK"}, {CharSet::UTF_16BE, u"UTF-16 Big Endian"},
112 {CharSet::UTF_16LE, u"UTF-16 Little Endian"},
113 {CharSet::UTF_32BE, u"UTF-32 Big Endian"},
114 {CharSet::UTF_32LE, u"UTF-32 Little Endian"}};
115
116 } // namespace Text;
117
118
120
121
125 template<class _tShell>
126 inline _tShell&
127 FetchShell()
128 {
129 return ystdex::polymorphic_downcast<_tShell&>(Deref(FetchShellHandle()));
130 }
131
132
137 inline PDefH(bool, IsNowShell, const shared_ptr<Shell>& hShl)
138 ImplRet(FetchAppInstance().GetShellHandle() == hShl)
139
140
144 inline PDefH(void, NowShellTo, const shared_ptr<Shell>& hShl)
145 ImplExpr(Activate(hShl))
146
151 inline PDefH(void, SetShellTo, const shared_ptr<Shell>& hShl,
152 Messaging::Priority prior = Messaging::NormalPriority)
153 // NOTE: It would make the message loop in dead lock when called more
154 // than once specifying on same destination shell.
155 ImplRet(PostMessage<SM_Set>(prior, hShl))
156
157
164 inline PDefH(void, ResetDesktop, UI::Desktop& dsk, Devices::Screen& scr)
165 ImplExpr(dsk.~Desktop(), new(&dsk) UI::Desktop(scr))
166
167
168 namespace Drawing
169 {
170
172 inline PDefH(Color, GenerateRandomColor, )
173 //使用 std::time(0) 初始化随机数种子在 DeSmuME 上无效。
174 // std::srand(std::time(0));
175 ImplRet(Color(std::rand(), std::rand(), std::rand(), 1))
176
177 } // namespace Drawing;
178
183 YF_API void
184 RemoveGlobalTasks();
185
186
191 yconstexpr const char* const DefaultTimeFormat("%04u-%02u-%02u %02u:%02u:%02u");
192
199 YF_API YB_ATTR_returns_nonnull const char*
200 TranslateTime(const std::tm&, const char* = DefaultTimeFormat);
202 YF_API YB_ATTR_returns_nonnull const char*
203 TranslateTime(const std::time_t&, const char* = DefaultTimeFormat);
205
206
212 YF_API shared_ptr<UI::TextList::ListType>
213 FetchFontFamilyNames();
214
215
220 class YF_API FPSCounter
221 {
222 private:
227 std::chrono::nanoseconds last_tick, now_tick;
232 size_t refresh_count;
233
234 public:
239 std::chrono::nanoseconds MinimalInterval;
240
245 FPSCounter(std::chrono::nanoseconds = {});
246
252 DefGetter(const ynothrow, std::chrono::nanoseconds, LastTick, last_tick)
253 DefGetter(const ynothrow, std::chrono::nanoseconds, NowTick, now_tick)
255
261 size_t
262 Refresh();
263 };
264
266
267 namespace UI
268 {
269
274 YF_API void
275 SwitchVisible(IWidget&);
276
281 YF_API void
282 SwitchVisibleToFront(IWidget&);
283
284
289 template<class _tWidget>
290 inline void
291 SetBufferRendererAndText(_tWidget& wgt, const String& s)
292 {
293 wgt.SetRenderer(make_unique<BufferedRenderer>()),
294 wgt.Text = s;
295 }
296
297
304 YF_API shared_ptr<TextList::ListType>
305 FetchVisualStyleNames(String = u"<Default>");
306
307 } // namespace UI;
308
309 } // namespace YSLib;
310
311 #endif
312
CHRLib::CharSet::UTF_16LE
yconstexpr const Encoding UTF_16LE(csUTF16LE)
YSLib::Messaging::NormalPriority
yconstexpr const Priority NormalPriority(0x80)
默认消息优先级。
YSLib::FPSCounter::MinimalInterval
std::chrono::nanoseconds MinimalInterval
计时间隔下界。
Definition: ShellHelper.h:239
YSLib::UI::FetchVisualStyleNames
YF_API shared_ptr< TextList::ListType > FetchVisualStyleNames(String=u"<Default>")
取视觉样式名称。
Definition: ShellHelper.cpp:160
CHRLib::CharSet::GBK
yconstexpr const Encoding GBK(csGBK)
YSLib::Messaging::Priority
std::uint8_t Priority
消息优先级。
Definition: YMessage.h:51
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Timers::HighResolutionClock::time_point
std::chrono::time_point< HighResolutionClock, std::chrono::nanoseconds > time_point
Definition: YClock.h:53
YSLib::FPSCounter::refresh_count
size_t refresh_count
刷新计数。
Definition: ShellHelper.h:232
cast.hpp
C++ 转换模板。
UI
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:451
YSLib::TranslateTime
YF_API YB_ATTR_returns_nonnull const char * TranslateTime(const std::tm &, const char *=DefaultTimeFormat)
格式化时间字符串。
Definition: ShellHelper.cpp:84
YSLib::UI::SwitchVisible
YF_API void SwitchVisible(IWidget &)
切换部件显示状态并无效化。
Definition: ShellHelper.cpp:145
Text
YSLib::UI::wgt
IWidget & wgt
Definition: YControl.h:112
Color
Pixel Color
Definition: CharRenderer.cpp:58
YSLib::shared_ptr< Shell >
shared_ptr< Shell >
Definition: GUIApplication.h:307
CHRLib::args
_tParams && args
Definition: CharacterProcessing.h:538
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:679
YSLib::DebugTimer::base_tick
Timers::HighResolutionClock::time_point base_tick
Definition: ShellHelper.h:55
YSLib::UI::SwitchVisibleToFront
YF_API void SwitchVisibleToFront(IWidget &)
切换部件显示状态并请求提升至前端。
Definition: ShellHelper.cpp:152
YSLib::DebugTimer::event_info
string event_info
Definition: ShellHelper.h:54
YSLib::GShellSession< ShlTextReader >::Shell
ShlTextReader Shell
Definition: ShellHelper.h:79
ystdex::lref
左值引用包装。
Definition: ref.hpp:74
YSLib::GShellSession::DefDeDtor
virtual DefDeDtor(GShellSession) DefGetter(const ynothrow
CHRLib::CharSet::UTF_16BE
yconstexpr const Encoding UTF_16BE(csUTF16BE)
YB_ATTR_returns_nonnull
#define YB_ATTR_returns_nonnull
指示返回非空属性。
Definition: ydef.h:413
CHRLib::CharSet::UTF_32LE
yconstexpr const Encoding UTF_32LE(csUTF32LE)
YSLib::PDefH
PDefH(Environment &, FetchEnvironment,) ImplRet(FetchGlobalInstance().GetEnvironmentRef()) inline PDefH(GUIHost &
取单一环境对象引用。
YSLib::GShellSession::conn
Connection conn
Definition: ShellHelper.h:83
YSLib::FetchFontFamilyNames
YF_API shared_ptr< UI::TextList::ListType > FetchFontFamilyNames()
取字型家族名称。
Definition: ShellHelper.cpp:106
CHRLib::CharSet::UTF_32BE
yconstexpr const Encoding UTF_32BE(csUTF32BE)
YSLib::Text::Encodings
yconstexpr const EncodingInfoItem Encodings[]
编码信息。
Definition: ShellHelper.h:110
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
YSLib::Activate
Activate
Definition: YApplication.h:210
CHRLib::CharSet::UTF_8
yconstexpr const Encoding UTF_8(csUTF8)
SM_Set
#define SM_Set
Definition: ymsgdef.h:60
YF_API
#define YF_API
Definition: Platform.h:56
Drawing
YModules.h
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::DebugTimer
调试计时器。
Definition: ShellHelper.h:50
YSLib::FPSCounter::now_tick
std::chrono::nanoseconds now_tick
Definition: ShellHelper.h:227
YModules.h
std
Definition: memory.hpp:1183
YSLib::ImplRet
ImplRet(FetchGlobalInstance().GetGUIHostRef()) YF_API void Execute(GUIApplication &
执行程序主消息循环。
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::UI::SetBufferRendererAndText
void SetBufferRendererAndText(_tWidget &wgt, const String &s)
设置部件渲染器为 BufferedRenderer 及部件的 Text 成员。
Definition: ShellHelper.h:291
YSLib::GShellSession::GShellSession
GShellSession(_tParam &&...args)
Definition: ShellHelper.h:87
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:995
YSLib::PostMessage
const shared_ptr< Shell > &hShl ImplRet(FetchAppInstance().Switch(shared_ptr< Shell >(hShl))) yconstexpr const Messaging YF_API void PostMessage(const Message &, Messaging::Priority)
默认退出消息优先级。
Definition: YApplication.cpp:78
YSLib::UI::Styles::Desktop
桌面背景。
Definition: YStyle.h:310
YSLib::Text::EncodingInfoItem
pair< Encoding, const char16_t * > EncodingInfoItem
编码信息项目。
Definition: ShellHelper.h:104
YSLib::GShellSession
Shell 连接会话。
Definition: ShellHelper.h:76
YSLib::FetchAppInstance
YF_API Application & FetchAppInstance()
取应用程序实例。
Definition: GUIApplication.cpp:295
ystdex::string_view
basic_string_view< char > string_view
Definition: string_view.hpp:415
YSLib::DefaultTimeFormat
yconstexpr const char *const DefaultTimeFormat("%04u-%02u-%02u %02u:%02u:%02u")
默认时间格式字符串。
YSLib::RemoveGlobalTasks
void RemoveGlobalTasks()
Definition: ShellHelper.cpp:57
YSLib::FPSCounter
帧速率计数器。
Definition: ShellHelper.h:220
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: YString.h:46
YSLib::FetchShell
_tShell & FetchShell()
取指定 Shell 句柄对应的 Shell 引用 。
Definition: ShellHelper.h:127