diff options
Diffstat (limited to 'include/cru/platform/native')
-rw-r--r-- | include/cru/platform/native/basic_types.hpp | 2 | ||||
-rw-r--r-- | include/cru/platform/native/cursor.hpp | 29 | ||||
-rw-r--r-- | include/cru/platform/native/native_event.hpp | 5 | ||||
-rw-r--r-- | include/cru/platform/native/native_window.hpp | 34 | ||||
-rw-r--r-- | include/cru/platform/native/ui_application.hpp | 35 |
5 files changed, 37 insertions, 68 deletions
diff --git a/include/cru/platform/native/basic_types.hpp b/include/cru/platform/native/basic_types.hpp index 5a7155ee..a53fa671 100644 --- a/include/cru/platform/native/basic_types.hpp +++ b/include/cru/platform/native/basic_types.hpp @@ -7,5 +7,5 @@ struct Dpi { float y; }; -enum MouseButton : unsigned { Left = 1, Right = 2, Middle = 4 }; +enum MouseButton : unsigned { Left = 0b1, Right = 0b10, Middle = 0b100 }; } // namespace cru::platform::native diff --git a/include/cru/platform/native/cursor.hpp b/include/cru/platform/native/cursor.hpp index b8604ecb..961dff34 100644 --- a/include/cru/platform/native/cursor.hpp +++ b/include/cru/platform/native/cursor.hpp @@ -5,35 +5,16 @@ #include <memory> namespace cru::platform::native { -class Cursor : public NativeResource { - public: - Cursor() = default; +struct ICursor : public virtual INativeResource {}; - CRU_DELETE_COPY(Cursor) - CRU_DELETE_MOVE(Cursor) - - ~Cursor() override = default; -}; - -enum class SystemCursor { +enum class SystemCursorType { Arrow, Hand, }; -class CursorManager : public NativeResource { - public: - CursorManager() = default; - - CRU_DELETE_COPY(CursorManager) - CRU_DELETE_MOVE(CursorManager) +struct ICursorManager : public virtual INativeResource { + virtual std::shared_ptr<ICursor> GetSystemCursor(SystemCursorType type) = 0; - ~CursorManager() override = default; - - public: - virtual std::shared_ptr<Cursor> GetSystemCursor(SystemCursor type) = 0; - - //TODO: Add method to create cursor. + // TODO: Add method to create cursor. }; - -std::shared_ptr<Cursor> GetSystemCursor(SystemCursor type); } // namespace cru::platform::native diff --git a/include/cru/platform/native/native_event.hpp b/include/cru/platform/native/native_event.hpp index 54bab00c..dcd7a336 100644 --- a/include/cru/platform/native/native_event.hpp +++ b/include/cru/platform/native/native_event.hpp @@ -8,4 +8,9 @@ struct NativeMouseButtonEventArgs { MouseButton button; Point point; }; + +enum class FocusChangeType { Gain, Lost }; + +enum class MouseEnterLeaveType { Enter, Leave }; + } // namespace cru::platform::native diff --git a/include/cru/platform/native/native_window.hpp b/include/cru/platform/native/native_window.hpp index 8a067a4c..cd2459e0 100644 --- a/include/cru/platform/native/native_window.hpp +++ b/include/cru/platform/native/native_window.hpp @@ -9,7 +9,7 @@ #include "native_event.hpp" namespace cru::platform::graph { -class Painter; +struct IPainter; } namespace cru::platform::native { @@ -21,28 +21,18 @@ namespace cru::platform::native { // Close or closed by the user, which leads to an invalid instance. You can // check the validity by IsValid. When you call perform native operations on the // invalid instance, there is no effect. -class NativeWindow : public NativeResource { - protected: - NativeWindow() = default; - - public: - NativeWindow(const NativeWindow& other) = delete; - NativeWindow& operator=(const NativeWindow& other) = delete; - - NativeWindow(NativeWindow&& other) = delete; - NativeWindow& operator=(NativeWindow&& other) = delete; - - ~NativeWindow() override = default; - - public: +struct INativeWindow : public virtual INativeResource { // Return if the window is still valid, that is, hasn't been closed or // destroyed. virtual bool IsValid() = 0; + + // Set if the instance is deleted automatically when the window is destroyed + // by other ways. Default is true. virtual void SetDeleteThisOnDestroy(bool value) = 0; virtual void Close() = 0; - virtual NativeWindow* GetParent() = 0; + virtual INativeWindow* GetParent() = 0; virtual bool IsVisible() = 0; virtual void SetVisible(bool is_visible) = 0; @@ -64,16 +54,18 @@ class NativeWindow : public NativeResource { virtual bool CaptureMouse() = 0; virtual bool ReleaseMouse() = 0; - virtual void SetCursor(std::shared_ptr<Cursor> cursor) = 0; + virtual void SetCursor(std::shared_ptr<ICursor> cursor) = 0; + + virtual void RequestRepaint() = 0; - virtual void Repaint() = 0; - virtual graph::Painter* BeginPaint() = 0; + // Remember to call EndDraw on return value and destroy it. + virtual std::unique_ptr<graph::IPainter> BeginPaint() = 0; virtual IEvent<std::nullptr_t>* DestroyEvent() = 0; virtual IEvent<std::nullptr_t>* PaintEvent() = 0; virtual IEvent<Size>* ResizeEvent() = 0; - virtual IEvent<bool>* FocusEvent() = 0; - virtual IEvent<bool>* MouseEnterLeaveEvent() = 0; + virtual IEvent<FocusChangeType>* FocusEvent() = 0; + virtual IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() = 0; virtual IEvent<Point>* MouseMoveEvent() = 0; virtual IEvent<NativeMouseButtonEventArgs>* MouseDownEvent() = 0; virtual IEvent<NativeMouseButtonEventArgs>* MouseUpEvent() = 0; diff --git a/include/cru/platform/native/ui_application.hpp b/include/cru/platform/native/ui_application.hpp index 923fbaf7..6d2ab659 100644 --- a/include/cru/platform/native/ui_application.hpp +++ b/include/cru/platform/native/ui_application.hpp @@ -1,45 +1,36 @@ #pragma once #include "../native_resource.hpp" -#include "cursor.hpp" - #include <chrono> #include <functional> #include <vector> namespace cru::platform::native { -class NativeWindow; +struct INativeWindow; +struct ICursorManager; // 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 { +struct IUiApplication : public virtual INativeResource { 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(); + static IUiApplication* 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; + static IUiApplication* GetInstance(); public: + // Block current thread and run the message loop. Return the exit code when + // message loop gets a quit message (possibly posted by method RequestQuit). virtual int Run() = 0; - virtual void Quit(int quite_code) = 0; + + // Post a quit message with given quit code. + virtual void RequestQuit(int quit_code) = 0; virtual void AddOnQuitHandler(const std::function<void()>& handler) = 0; @@ -50,9 +41,9 @@ class UiApplication : public NativeResource { const std::function<void()>& action) = 0; virtual void CancelTimer(unsigned long id) = 0; - virtual std::vector<NativeWindow*> GetAllWindow() = 0; - virtual NativeWindow* CreateWindow(NativeWindow* parent) = 0; + virtual std::vector<INativeWindow*> GetAllWindow() = 0; + virtual INativeWindow* CreateWindow(INativeWindow* parent) = 0; - virtual CursorManager* GetCursorManager() = 0; + virtual ICursorManager* GetCursorManager() = 0; }; } // namespace cru::platform::native |