YSTest: GUIApplication.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

GUIApplication.h
浏览该文件的文档.
1 /*
2 © 2012-2016, 2019-2020 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_GUIApplication_h_
29 #define INC_Helper_GUIApplication_h_ 1
30
31 #include "YModules.h"
32 #include YFM_Helper_YGlobal // for Environment;
33 #include YFM_Helper_HostWindow // for Host::Window;
34 #include YFM_YCLib_NativeAPI
35 #include YFM_YSLib_Core_YApplication // for Application;
36 #include <ystdex/cast.hpp> // for ystdex::polymorphic_downcast;
37 #include YFM_Helper_GUIShell
38 #include YFM_YCLib_HostedGUI
39 #include YFM_YCLib_Mutex // for once_flag;
40 #include <ystdex/utility.hpp> // for ystdex::call_once_init;
41 #if YCL_Win32
42 # include YFM_YSLib_UI_YPanel
43 #elif YCL_Android
44 # include YFM_YSLib_UI_YDesktop
45 #endif
46
47 namespace YSLib
48 {
49
54 class YF_API GUIHost
55 {
56 private:
57 #if YF_Hosted
58
65 map<Host::NativeWindowHandle, observer_ptr<Host::Window>> wnd_map;
67 mutable mutex wmap_mtx;
73 atomic<size_t> wnd_thrd_count{0};
74
75 public:
81 atomic<bool> ExitOnAllWindowThreadCompleted{true};
82
83 # if YCL_Win32
84
89 function<pair<observer_ptr<Host::Window>, Drawing::Point>(
90 const Drawing::Point&)> MapPoint{};
92 UI::Panel Desktop{};
93
94 private:
95 Host::WindowClass window_class;
96 # elif YCL_Android
97
101 ystdex::id_func_clr_t<Drawing::Point>* MapPoint = {};
106 UI::Desktop Desktop;
107 # endif
108 #endif
109
110 public:
111 GUIHost();
112 ~GUIHost();
113
114 #if YF_Hosted
115
120 observer_ptr<Host::Window>
121 GetForegroundWindow() const ynothrow;
122 #endif
123
124 #if YF_Hosted
125
129 void
130 AddMappedItem(Host::NativeWindowHandle, observer_ptr<Host::Window>);
131
132 # if YF_Multithread == 1
133
138 void
139 EnterWindowThread();
140 # endif
141
146 observer_ptr<Host::Window>
147 FindWindow(Host::NativeWindowHandle) const ynothrow;
148
149 # if YF_Multithread == 1
150
155 void
156 LeaveWindowThread();
157 # endif
158
167 pair<observer_ptr<Host::Window>, Drawing::Point>
168 MapCursor() const;
169
170 # if YCL_Win32
171
177 pair<observer_ptr<Host::Window>, Drawing::Point>
178 MapTopLevelWindowPoint(const Drawing::Point&) const;
179 # endif
180
184 void
185 RemoveMappedItem(Host::NativeWindowHandle) ynothrow;
186
188 void
189 UpdateRenderWindows();
190 #endif
191 };
192
193
199 class YF_API GUIApplication : public Application
200 {
201 private:
203 struct InitBlock final
204 {
206 unique_ptr<Environment> p_env;
208 mutable GUIHost host{};
209
211 InitBlock(Application&);
212 };
213
215 ystdex::call_once_init<InitBlock, once_flag> init;
216
217 public:
224 Messaging::Priority UIResponseLimit = 0x40;
225
230 GUIApplication();
234 ~GUIApplication() override;
235
237 YB_ATTR_nodiscard YB_PURE Environment&
238 GetEnvironmentRef() const ynothrow;
240 YB_ATTR_nodiscard yimpl(YB_STATELESS) GUIHost&
241 GetGUIHostRef() const ynothrow;
242
255 bool
256 DealMessage();
257 };
258
259
267 YF_API yimpl(GUIApplication&)
268 FetchGlobalInstance();
269 template<class _tApp>
270 inline _tApp&
271 FetchGlobalInstance()
272 {
273 return ystdex::polymorphic_downcast<_tApp&>(FetchGlobalInstance());
274 }
276
282 YF_API locked_ptr<yimpl(GUIApplication), recursive_mutex>
283 LockInstance();
284
285
290 inline PDefH(Environment&, FetchEnvironment, )
291 ImplRet(FetchGlobalInstance().GetEnvironmentRef())
292
297 inline PDefH(GUIHost&, FetchGUIHost, )
298 ImplRet(FetchGlobalInstance().GetGUIHostRef())
299
300
307 YF_API void
308 Execute(GUIApplication&, shared_ptr<Shell> = make_shared<Shells::GUIShell>());
309
310 } // namespace YSLib;
311
312 #endif
313
YSLib::Environment
应用程序环境。
Definition: Environment.h:63
cast.hpp
C++ 转换模板。
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
ystdex::single_thread::mutex
Definition: pseudo_mutex.h:747
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
YSLib::UI::Panel
面板。
Definition: YPanel.h:46
YSLib::GUIApplication
平台相关的应用程序类。
Definition: GUIApplication.h:200
ystdex::make_shared
std::shared_ptr< _type > make_shared(std::initializer_list< _tValue > il)
使用指定类型的初始化列表构造指定类型的 std::shared_ptr 对象。
Definition: memory.hpp:855
YSLib::UI::Styles::Desktop
@ Desktop
桌面背景。
Definition: YStyle.h:310
YSLib::GUIApplication::init
ystdex::call_once_init< InitBlock, once_flag > init
Definition: GUIApplication.h:215
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::GUIApplication::InitBlock::p_env
unique_ptr< Environment > p_env
环境状态。
Definition: GUIApplication.h:206
platform::Concurrency::atomic
ystdex::cond_or_t< ystdex::or_< std::is_integral< _type >, std::is_pointer< _type > >, void, ystdex::identity_t, _type > atomic
支持的原子性的整数或指针类型。
Definition: Mutex.h:64
YSLib::Messaging::Priority
std::uint8_t Priority
消息优先级。
Definition: YMessage.h:52
ystdex::map
映射容器。
Definition: map.hpp:79
YSLib::locked_ptr
unique_ptr< _type, unlock_delete< _tMutex, _tLock > > locked_ptr
独占所有权的锁定指针：使用线程模型对应的互斥量和锁以及 unique_ptr 。
Definition: YShellDefinition.h:108
YSLib::FetchGlobalInstance
_tApp & FetchGlobalInstance()
Definition: GUIApplication.h:271
YSLib::Execute
void Execute(GUIApplication &app, shared_ptr< Shell > p_shl)
Definition: GUIApplication.cpp:308
YSLib::Application
程序实例。
Definition: YApplication.h:47
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:941
YSLib::LockInstance
YF_API locked_ptr< yimpl(GUIApplication), recursive_mutex > LockInstance()
锁定实例。
Definition: GUIApplication.cpp:301
YSLib::yimpl
YF_API yimpl(GUIApplication &) FetchGlobalInstance()
取全局应用程序实例。
YSLib::Drawing::GBinaryGroup< SPos >
YSLib::GUIHost
GUI 宿主。
Definition: GUIApplication.h:55
YSLib::Shells::Shell
外壳程序：实现运行期控制流映像语义。
Definition: YShell.h:42
utility.hpp
实用设施。
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YSLib::GUIApplication::InitBlock
Definition: GUIApplication.h:204
YModules.h
YSLib 用户界面模块配置文件。
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:169
YSLib::UI::Desktop
桌面。
Definition: YDesktop.h:47
YSLib::ImplRet
ImplRet(FetchGlobalInstance().GetGUIHostRef()) YF_API void Execute(GUIApplication &
执行程序主消息循环。
ystdex::call_once_init
使用 call_once 的静态初始化管理器。
Definition: utility.hpp:395
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
YSLib::FetchGUIHost
FetchGUIHost
Definition: GUIApplication.h:297
YSLib::PDefH
PDefH(Environment &, FetchEnvironment,) ImplRet(FetchGlobalInstance().GetEnvironmentRef()) inline PDefH(GUIHost &
取单一环境对象引用。
ystdex::id_func_clr_t
id_func_t< _type, _vN, const _type & > id_func_clr_t
取指定维数和 const 左值引用参数类型的多元映射扩展恒等函数类型。
Definition: function.hpp:440