YSTest: ShellHelper.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

ShellHelper.h
浏览该文件的文档.
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 #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 #if __cplusplus > 201103L
111 // XXX: The constructor of %std::pair used here has 'constexpr' since ISO C++14.
112 yconstexpr
113 #endif
114 const EncodingInfoItem Encodings[]{{CharSet::UTF_8, u"UTF-8"},
115 {CharSet::GBK, u"GBK"}, {CharSet::UTF_16BE, u"UTF-16 Big Endian"},
116 {CharSet::UTF_16LE, u"UTF-16 Little Endian"},
117 {CharSet::UTF_32BE, u"UTF-32 Big Endian"},
118 {CharSet::UTF_32LE, u"UTF-32 Little Endian"}};
119
120 } // namespace Text;
121
122
124
125
129 template<class _tShell>
130 inline _tShell&
131 FetchShell()
132 {
133 return ystdex::polymorphic_downcast<_tShell&>(Deref(FetchShellHandle()));
134 }
135
136
141 inline PDefH(bool, IsNowShell, const shared_ptr<Shell>& hShl)
142 ImplRet(FetchAppInstance().GetShellHandle() == hShl)
143
144
148 inline PDefH(void, NowShellTo, const shared_ptr<Shell>& hShl)
149 ImplExpr(Activate(hShl))
150
151
155 inline PDefH(void, SetShellTo, const shared_ptr<Shell>& hShl,
156 Messaging::Priority prior = Messaging::NormalPriority)
157 // NOTE: It would make the message loop in dead lock when called more
158 // than once specifying on same destination shell.
159 ImplRet(PostMessage<SM_Set>(prior, hShl))
160
161
162
168 inline PDefH(void, ResetDesktop, UI::Desktop& dsk, Devices::Screen& scr)
169 ImplExpr(dsk.~Desktop(), new(&dsk) UI::Desktop(scr))
170
171
172 namespace Drawing
173 {
174
176 inline PDefH(Color, GenerateRandomColor, )
177 //使用 std::time(0) 初始化随机数种子在 DeSmuME 上无效。
178 // std::srand(std::time(0));
179 ImplRet(Color(std::rand(), std::rand(), std::rand(), 1))
180
181 } // namespace Drawing;
182
187 YF_API void
188 RemoveGlobalTasks();
189
190
195 yconstexpr const char* const DefaultTimeFormat("%04u-%02u-%02u %02u:%02u:%02u");
196
203 YF_API YB_ATTR_returns_nonnull const char*
204 TranslateTime(const std::tm&, const char* = DefaultTimeFormat);
206 YF_API YB_ATTR_returns_nonnull const char*
207 TranslateTime(const std::time_t&, const char* = DefaultTimeFormat);
209
210
216 YF_API shared_ptr<UI::TextList::ListType>
217 FetchFontFamilyNames();
218
219
224 class YF_API FPSCounter
225 {
226 private:
231 std::chrono::nanoseconds last_tick, now_tick;
236 size_t refresh_count;
237
238 public:
243 std::chrono::nanoseconds MinimalInterval;
244
249 FPSCounter(std::chrono::nanoseconds = {});
250
256 DefGetter(const ynothrow, std::chrono::nanoseconds, LastTick, last_tick)
257 DefGetter(const ynothrow, std::chrono::nanoseconds, NowTick, now_tick)
259
265 size_t
266 Refresh();
267 };
268
270
271 namespace UI
272 {
273
278 YF_API void
279 SwitchVisible(IWidget&);
280
285 YF_API void
286 SwitchVisibleToFront(IWidget&);
287
288
293 template<class _tWidget>
294 inline void
295 SetBufferRendererAndText(_tWidget& wgt, const String& s)
296 {
297 wgt.SetRenderer(make_unique<BufferedRenderer>()),
298 wgt.Text = s;
299 }
300
301
308 YF_API shared_ptr<TextList::ListType>
309 FetchVisualStyleNames(String = u"<Default>");
310
311 } // namespace UI;
312
313 } // namespace YSLib;
314
315 #endif
316
cast.hpp
C++ 转换模板。
YSLib::Text::EncodingInfoItem
pair< Encoding, const char16_t * > EncodingInfoItem
编码信息项目。
Definition: ShellHelper.h:104
ystdex::lref
左值引用包装。
Definition: ref.hpp:61
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
YSLib::GShellSession
Shell 连接会话。
Definition: ShellHelper.h:77
YSLib::DefaultTimeFormat
yconstexpr const char *const DefaultTimeFormat("%04u-%02u-%02u %02u:%02u:%02u")
默认时间格式字符串。
YSLib::UI::FetchVisualStyleNames
YF_API shared_ptr< TextList::ListType > FetchVisualStyleNames(String=u"<Default>")
取视觉样式名称。
Definition: ShellHelper.cpp:161
YSLib::shared_ptr< Shell >
shared_ptr< Shell >
Definition: GUIApplication.h:308
YSLib::FetchAppInstance
YF_API Application & FetchAppInstance()
取应用程序实例。
Definition: GUIApplication.cpp:295
CHRLib::CharSet::UTF_8
yconstexpr const Encoding UTF_8(csUTF8)
ystdex::cpp2017::string_view
basic_string_view< char > string_view
Definition: string_view.hpp:437
YSLib::Messaging::NormalPriority
yconstexpr const Priority NormalPriority(0x80)
默认消息优先级。
YSLib::FPSCounter::now_tick
std::chrono::nanoseconds now_tick
Definition: ShellHelper.h:231
YSLib::FetchFontFamilyNames
YF_API shared_ptr< UI::TextList::ListType > FetchFontFamilyNames()
取字型家族名称。
Definition: ShellHelper.cpp:107
YSLib::UI::SetBufferRendererAndText
void SetBufferRendererAndText(_tWidget &wgt, const String &s)
设置部件渲染器为 BufferedRenderer 及部件的 Text 成员。
Definition: ShellHelper.h:295
YF_API
#define YF_API
Definition: Platform.h:56
YModules.h
Helper 库模块配置文件。
CHRLib::CharSet::UTF_32LE
yconstexpr const Encoding UTF_32LE(csUTF32LE)
YSLib::GShellSession::GShellSession
GShellSession(_tParam &&... args)
Definition: ShellHelper.h:87
YSLib::Messaging::Priority
std::uint8_t Priority
消息优先级。
Definition: YMessage.h:52
NPL::tm
tm
Definition: NPLA.h:1941
CHRLib::CharSet::UTF_16BE
yconstexpr const Encoding UTF_16BE(csUTF16BE)
CHRLib::CharSet::GBK
yconstexpr const Encoding GBK(csGBK)
YSLib::FPSCounter::refresh_count
size_t refresh_count
刷新计数。
Definition: ShellHelper.h:236
YB_ATTR_returns_nonnull
#define YB_ATTR_returns_nonnull
指示返回非空属性。
Definition: ydef.h:761
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: YString.h:47
std
Definition: optional.h:982
YSLib::RemoveGlobalTasks
void RemoveGlobalTasks()
Definition: ShellHelper.cpp:57
YSLib::Timers::HighResolutionClock::time_point
std::chrono::time_point< HighResolutionClock, std::chrono::nanoseconds > time_point
Definition: YClock.h:53
YSLib::DebugTimer
调试计时器。
Definition: ShellHelper.h:51
YSLib::FetchShell
_tShell & FetchShell()
取指定 Shell 句柄对应的 Shell 引用 。
Definition: ShellHelper.h:131
YSLib::Text::Encodings
const EncodingInfoItem Encodings[]
编码信息。
Definition: ShellHelper.h:114
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:153
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
Color
Pixel Color
Definition: CharRenderer.cpp:59
YSLib::Activate
Activate
Definition: YApplication.h:210
YSLib::TranslateTime
YF_API YB_ATTR_returns_nonnull const char * TranslateTime(const std::tm &, const char *=DefaultTimeFormat)
格式化时间字符串。
Definition: ShellHelper.cpp:84
YSLib::FPSCounter
帧速率计数器。
Definition: ShellHelper.h:225
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:169
YSLib::GShellSession::DefDeDtor
virtual DefDeDtor(GShellSession) DefGetter(const ynothrow
YSLib::UI::Desktop
桌面。
Definition: YDesktop.h:47
platform::Deref
YB_PURE yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:547
CHRLib::CharSet::UTF_32BE
yconstexpr const Encoding UTF_32BE(csUTF32BE)
YSLib::ImplRet
ImplRet(FetchGlobalInstance().GetGUIHostRef()) YF_API void Execute(GUIApplication &
执行程序主消息循环。
YSLib::UI::wgt
IWidget & wgt
Definition: YControl.h:113
YSLib::UI::SwitchVisible
YF_API void SwitchVisible(IWidget &)
切换部件显示状态并无效化。
Definition: ShellHelper.cpp:146
YSLib::DebugTimer::event_info
string event_info
Definition: ShellHelper.h:54
YModules.h
YCLib 库模块配置文件。
YSLib::FPSCounter::DefGetter
DefGetter(const ynothrow, std::chrono::nanoseconds, LastTick, last_tick) DefGetter(const ynothrow
取内部计数。
ImplExpr
#define ImplExpr(...)
简单通用函数实现。
Definition: YBaseMacro.h:96
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
YSLib::GShellSession::conn
Connection conn
Definition: ShellHelper.h:83
YSLib::FPSCounter::MinimalInterval
std::chrono::nanoseconds MinimalInterval
计时间隔下界。
Definition: ShellHelper.h:243
YSLib::GShellSession< ShlTextReader >::Shell
ShlTextReader Shell
Definition: ShellHelper.h:79
YSLib::args
YB_ATTR_nodiscard YB_PURE typename _tParams && args
Definition: ValueNode.h:1299
CHRLib::CharSet::UTF_16LE
yconstexpr const Encoding UTF_16LE(csUTF16LE)
YSLib::Devices::Screen
屏幕。
Definition: YDevice.h:133
YSLib::PDefH
PDefH(Environment &, FetchEnvironment,) ImplRet(FetchGlobalInstance().GetEnvironmentRef()) inline PDefH(GUIHost &
取单一环境对象引用。
NPL::_tParam
_tParam
Definition: NPLA.h:2367