From 73f13dd60f51ff05e31a64fba89fe31ab3ab185d Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Sun, 15 Sep 2019 00:03:11 +0800 Subject: ... --- include/cru/common/base.hpp | 6 +++ include/cru/platform/native/cursor.hpp | 2 + include/cru/platform/native/ui_applicaition.hpp | 58 ------------------------- include/cru/platform/native/ui_application.hpp | 58 +++++++++++++++++++++++++ include/cru/ui/click_detector.hpp | 2 +- include/cru/ui/controls/button.hpp | 8 +++- include/cru/win/native/ui_application.hpp | 2 +- 7 files changed, 74 insertions(+), 62 deletions(-) delete mode 100644 include/cru/platform/native/ui_applicaition.hpp create mode 100644 include/cru/platform/native/ui_application.hpp (limited to 'include') diff --git a/include/cru/common/base.hpp b/include/cru/common/base.hpp index 920fe569..55f43e5c 100644 --- a/include/cru/common/base.hpp +++ b/include/cru/common/base.hpp @@ -1,6 +1,8 @@ #pragma once #include "pre_config.hpp" +#include + #define CRU_DEFAULT_COPY(classname) \ classname(const classname&) = default; \ classname& operator=(const classname&) = default; @@ -36,4 +38,8 @@ struct Interface { Interface& operator=(Interface&& other) = delete; virtual ~Interface() = default; }; + +[[noreturn]] inline void UnreachableCode() { + throw std::runtime_error("Unreachable code."); +} } // namespace cru diff --git a/include/cru/platform/native/cursor.hpp b/include/cru/platform/native/cursor.hpp index b0ff4494..b8604ecb 100644 --- a/include/cru/platform/native/cursor.hpp +++ b/include/cru/platform/native/cursor.hpp @@ -34,4 +34,6 @@ class CursorManager : public NativeResource { //TODO: Add method to create cursor. }; + +std::shared_ptr GetSystemCursor(SystemCursor type); } // namespace cru::platform::native diff --git a/include/cru/platform/native/ui_applicaition.hpp b/include/cru/platform/native/ui_applicaition.hpp deleted file mode 100644 index 923fbaf7..00000000 --- a/include/cru/platform/native/ui_applicaition.hpp +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once -#include "../native_resource.hpp" - -#include "cursor.hpp" - -#include -#include -#include - -namespace cru::platform::native { -class NativeWindow; - -// The entry point of a ui application. -// It will call IGraphFactory::CreateInstance during its creation -// and set graph factory to be auto deleted. If you want to keep -// the graph factory then you should manually set it to false after -// creating the ui application. -class UiApplication : public NativeResource { - public: - // Create a platform-specific instance and save it as the global instance. - // Do not create the instance twice. Implements should assert for that. - // After creating, get the instance by GetInstance. - static UiApplication* CreateInstance(); - - // Get the global instance. If it is not created, then return nullptr. - static UiApplication* GetInstance(); - - protected: - UiApplication() = default; - - public: - UiApplication(const UiApplication& other) = delete; - UiApplication& operator=(const UiApplication& other) = delete; - - UiApplication(UiApplication&& other) = delete; - UiApplication& operator=(UiApplication&& other) = delete; - - ~UiApplication() override = default; - - public: - virtual int Run() = 0; - virtual void Quit(int quite_code) = 0; - - virtual void AddOnQuitHandler(const std::function& handler) = 0; - - virtual void InvokeLater(const std::function& action) = 0; - virtual unsigned long SetTimeout(std::chrono::milliseconds milliseconds, - const std::function& action) = 0; - virtual unsigned long SetInterval(std::chrono::milliseconds milliseconds, - const std::function& action) = 0; - virtual void CancelTimer(unsigned long id) = 0; - - virtual std::vector GetAllWindow() = 0; - virtual NativeWindow* CreateWindow(NativeWindow* parent) = 0; - - virtual CursorManager* GetCursorManager() = 0; -}; -} // namespace cru::platform::native diff --git a/include/cru/platform/native/ui_application.hpp b/include/cru/platform/native/ui_application.hpp new file mode 100644 index 00000000..923fbaf7 --- /dev/null +++ b/include/cru/platform/native/ui_application.hpp @@ -0,0 +1,58 @@ +#pragma once +#include "../native_resource.hpp" + +#include "cursor.hpp" + +#include +#include +#include + +namespace cru::platform::native { +class NativeWindow; + +// The entry point of a ui application. +// It will call IGraphFactory::CreateInstance during its creation +// and set graph factory to be auto deleted. If you want to keep +// the graph factory then you should manually set it to false after +// creating the ui application. +class UiApplication : public NativeResource { + public: + // Create a platform-specific instance and save it as the global instance. + // Do not create the instance twice. Implements should assert for that. + // After creating, get the instance by GetInstance. + static UiApplication* CreateInstance(); + + // Get the global instance. If it is not created, then return nullptr. + static UiApplication* GetInstance(); + + protected: + UiApplication() = default; + + public: + UiApplication(const UiApplication& other) = delete; + UiApplication& operator=(const UiApplication& other) = delete; + + UiApplication(UiApplication&& other) = delete; + UiApplication& operator=(UiApplication&& other) = delete; + + ~UiApplication() override = default; + + public: + virtual int Run() = 0; + virtual void Quit(int quite_code) = 0; + + virtual void AddOnQuitHandler(const std::function& handler) = 0; + + virtual void InvokeLater(const std::function& action) = 0; + virtual unsigned long SetTimeout(std::chrono::milliseconds milliseconds, + const std::function& action) = 0; + virtual unsigned long SetInterval(std::chrono::milliseconds milliseconds, + const std::function& action) = 0; + virtual void CancelTimer(unsigned long id) = 0; + + virtual std::vector GetAllWindow() = 0; + virtual NativeWindow* CreateWindow(NativeWindow* parent) = 0; + + virtual CursorManager* GetCursorManager() = 0; +}; +} // namespace cru::platform::native diff --git a/include/cru/ui/click_detector.hpp b/include/cru/ui/click_detector.hpp index 3806dd82..1a88b8a6 100644 --- a/include/cru/ui/click_detector.hpp +++ b/include/cru/ui/click_detector.hpp @@ -70,7 +70,7 @@ class ClickDetector : public Object { case MouseButton::Right: return click_map_.right; default: - std::abort(); + UnreachableCode(); } } diff --git a/include/cru/ui/controls/button.hpp b/include/cru/ui/controls/button.hpp index ca3dcae9..b5cca7dc 100644 --- a/include/cru/ui/controls/button.hpp +++ b/include/cru/ui/controls/button.hpp @@ -20,6 +20,8 @@ struct ButtonBorderStyle { render::BorderStyle hover; // corresponds to ButtonState::Press render::BorderStyle press; + // corresponds to ButtonState::PressCancel + render::BorderStyle press_cancel; }; enum class ButtonState { @@ -27,8 +29,10 @@ enum class ButtonState { Normal, // mouse is in it and not pressed Hover, - // mouse is pressed in it (click begins) - Press + // mouse is pressed in it + Press, + // mouse is pressed outside button + PressCancel, }; class Button : public ContentControl { diff --git a/include/cru/win/native/ui_application.hpp b/include/cru/win/native/ui_application.hpp index d7da4409..addf2c93 100644 --- a/include/cru/win/native/ui_application.hpp +++ b/include/cru/win/native/ui_application.hpp @@ -1,7 +1,7 @@ #pragma once #include "../win_pre_config.hpp" -#include "cru/platform/native/ui_applicaition.hpp" +#include "cru/platform/native/ui_application.hpp" #include "platform_id.hpp" #include "cursor.hpp" -- cgit v1.2.3