From 084623519e95f0ab0cf4bc328b5fa736d679c5bd Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 31 Jul 2019 21:35:12 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E5=90=8D=E7=A7=B0=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/modules/asura-core/window/window.h | 244 +++++++++++++++--------------- 1 file changed, 121 insertions(+), 123 deletions(-) (limited to 'source/modules/asura-core/window/window.h') diff --git a/source/modules/asura-core/window/window.h b/source/modules/asura-core/window/window.h index deffc10..872c40f 100644 --- a/source/modules/asura-core/window/window.h +++ b/source/modules/asura-core/window/window.h @@ -9,131 +9,129 @@ #include "../graphics/render_state.h" #include "../graphics/render_target.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Window) + +class WindowImpl; + +/// +/// 从SDL拷贝过来的,留下一些有用的。 +/// +enum WindowFlag +{ + WINDOW_FULLSCREEN = 1 << 1, ///< fullscreen window + WINDOW_OPENGL = 1 << 2, ///< window usable with OpenGL context + WINDOW_SHOWN = 1 << 3, ///< window is visible + WINDOW_HIDDEN = 1 << 4, ///< window is not visible + WINDOW_BORDERLESS = 1 << 5, ///< no window decoration + WINDOW_RESIZABLE = 1 << 6, ///< window can be resized + WINDOW_MINIMIZED = 1 << 7, ///< window is minimized + WINDOW_MAXIMIZED = 1 << 8, ///< window is maximized + WINDOW_INPUT_GRABBED = 1 << 9, ///< window has grabbed input focus + WINDOW_INPUT_FOCUS = 1 << 10, ///< window has input focus + WINDOW_MOUSE_FOCUS = 1 << 11, ///< window has mouse focus + WINDOW_ALLOW_HIGHDPI = 1 << 12, ///< window should be created in high-DPI mode if supported. + ///< On macOS NSHighResolutionCapable must be set true in the + ///< application's Info.plist for this to have any effect. + WINDOW_MOUSE_CAPTURE = 1 << 13, ///< window has mouse captured (unrelated to INPUT_GRABBED) + WINDOW_ALWAYS_ON_TOP = 1 << 14, ///< window should always be above others +}; + +/// Window初始化配置项 +struct WindowConfig +{ + uint width, height; ///< 尺寸 + int x, y; ///< 窗口初始坐标 + std::string title; ///< 标题名 + bool vsync; ///< 垂直同步 + AEImage::ImageData* icon; ///< 图标 + bool show; ///< 是否显示 + int flag; ///< 窗口标记 +}; + +/// +/// 游戏的单窗口,runner只需要一个窗口。不同的客户端实现此接口并手动注册到lua。编辑器不 +/// 会导入此类,将会嫁接到编辑器的虚拟窗口上。 +/// +class Window ASURA_FINAL + : public AEScripting::Portable + , public Singleton { - namespace Window - { - - class WindowImpl; - - /// - /// 从SDL拷贝过来的,留下一些有用的。 - /// - enum WindowFlag - { - WINDOW_FULLSCREEN = 1 << 1, ///< fullscreen window - WINDOW_OPENGL = 1 << 2, ///< window usable with OpenGL context - WINDOW_SHOWN = 1 << 3, ///< window is visible - WINDOW_HIDDEN = 1 << 4, ///< window is not visible - WINDOW_BORDERLESS = 1 << 5, ///< no window decoration - WINDOW_RESIZABLE = 1 << 6, ///< window can be resized - WINDOW_MINIMIZED = 1 << 7, ///< window is minimized - WINDOW_MAXIMIZED = 1 << 8, ///< window is maximized - WINDOW_INPUT_GRABBED = 1 << 9, ///< window has grabbed input focus - WINDOW_INPUT_FOCUS = 1 << 10, ///< window has input focus - WINDOW_MOUSE_FOCUS = 1 << 11, ///< window has mouse focus - WINDOW_ALLOW_HIGHDPI = 1 << 12, ///< window should be created in high-DPI mode if supported. - ///< On macOS NSHighResolutionCapable must be set true in the - ///< application's Info.plist for this to have any effect. - WINDOW_MOUSE_CAPTURE = 1 << 13, ///< window has mouse captured (unrelated to INPUT_GRABBED) - WINDOW_ALWAYS_ON_TOP = 1 << 14, ///< window should always be above others - }; - - /// Window初始化配置项 - struct WindowConfig - { - uint width, height; ///< 尺寸 - int x, y; ///< 窗口初始坐标 - std::string title; ///< 标题名 - bool vsync; ///< 垂直同步 - AEImage::ImageData* icon; ///< 图标 - bool show; ///< 是否显示 - int flag; ///< 窗口标记 - }; - - /// - /// 游戏的单窗口,runner只需要一个窗口。不同的客户端实现此接口并手动注册到lua。编辑器不 - /// 会导入此类,将会嫁接到编辑器的虚拟窗口上。 - /// - class Window ASURA_FINAL - : public AEScripting::Portable - , public Singleton - { - public: - - /// 游戏运行时的窗口是唯一的,编辑器不会用到此类。 - LUAX_DECL_SINGLETON(Window); - - Window(); - ~Window(); - - /// 在这里真正创建窗口。 - bool Init(const WindowConfig& config); - void Exit(); - - void SetSize(uint width, uint height); - void SetPosition(int x, int y); - void SetTitle(const std::string& title); - void SetIcon(AEImage::ImageData* imgData); - - void Show(); - void Hide(); - - /// 如果是开启双缓冲的窗口,需要交换缓冲区来展示到前台 - void SwapRenderBuffer(); - - void Clear(const AEGraphics::Color& col = AEGraphics::Color::Black) override; - void Clear(const Math::Recti& quad, const AEGraphics::Color& col = AEGraphics::Color::Black) override; - - void Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) override; - void Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) override; - - private: - - WindowImpl* m_Impl; - - luaxport: - - LUAX_DECL_ENUM(WindowFlag, 0); - - LUAX_DECL_METHOD(_Init); - LUAX_DECL_METHOD(_Exit); - LUAX_DECL_METHOD(_Show); - LUAX_DECL_METHOD(_Hide); - LUAX_DECL_METHOD(_SetSize); - LUAX_DECL_METHOD(_SetPosition); - LUAX_DECL_METHOD(_SetTitle); - LUAX_DECL_METHOD(_SetIcon); - LUAX_DECL_METHOD(_SwapRenderBuffer); - LUAX_DECL_METHOD(_Clear); - LUAX_DECL_METHOD(_Draw); - - }; - - using RenderWindow = Window; - - ASURA_ABSTRACT class WindowImpl - { - public: - - WindowImpl() {}; - virtual ~WindowImpl() {}; - - virtual bool Init(const WindowConfig& config); - - virtual void SetSize(uint width, uint height) = 0; - virtual void SetPosition(int x, int y) = 0; - virtual void SetTitils(const std::string& title) = 0; - - virtual void Show() = 0; - virtual void Hide() = 0; - - virtual void SwapRenderBuffer() = 0; - - }; +public: + + /// 游戏运行时的窗口是唯一的,编辑器不会用到此类。 + LUAX_DECL_SINGLETON(Window); + + Window(); + ~Window(); + + /// 在这里真正创建窗口。 + bool Init(const WindowConfig& config); + void Exit(); + + void SetSize(uint width, uint height); + void SetPosition(int x, int y); + void SetTitle(const std::string& title); + void SetIcon(AEImage::ImageData* imgData); + + void Show(); + void Hide(); + + /// 如果是开启双缓冲的窗口,需要交换缓冲区来展示到前台 + void SwapRenderBuffer(); + + void Clear(const AEGraphics::Color& col = AEGraphics::Color::Black) override; + void Clear(const Math::Recti& quad, const AEGraphics::Color& col = AEGraphics::Color::Black) override; + + void Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) override; + void Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) override; + +private: + + WindowImpl* m_Impl; + +luaxport: + + LUAX_DECL_ENUM(WindowFlag, 0); + + LUAX_DECL_METHOD(_Init); + LUAX_DECL_METHOD(_Exit); + LUAX_DECL_METHOD(_Show); + LUAX_DECL_METHOD(_Hide); + LUAX_DECL_METHOD(_SetSize); + LUAX_DECL_METHOD(_SetPosition); + LUAX_DECL_METHOD(_SetTitle); + LUAX_DECL_METHOD(_SetIcon); + LUAX_DECL_METHOD(_SwapRenderBuffer); + LUAX_DECL_METHOD(_Clear); + LUAX_DECL_METHOD(_Draw); + +}; + +using RenderWindow = Window; + +ASURA_ABSTRACT class WindowImpl +{ +public: + + WindowImpl() {}; + virtual ~WindowImpl() {}; + + virtual bool Init(const WindowConfig& config); + + virtual void SetSize(uint width, uint height) = 0; + virtual void SetPosition(int x, int y) = 0; + virtual void SetTitils(const std::string& title) = 0; + + virtual void Show() = 0; + virtual void Hide() = 0; + + virtual void SwapRenderBuffer() = 0; + +}; - } -} +namespace_end +namespace_end namespace AEWindow = AsuraEngine::Window; -- cgit v1.1-26-g67d0