From f2aa96fba0b72eeeadf5160ea5df2c8143ec8aa0 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 12 Dec 2019 23:26:04 +0800 Subject: ... --- include/cru/platform/native/cursor.hpp | 6 +-- include/cru/platform/native/event.hpp | 15 ++++++ include/cru/platform/native/native_event.hpp | 16 ------ include/cru/platform/native/native_window.hpp | 75 -------------------------- include/cru/platform/native/ui_application.hpp | 21 +++----- include/cru/platform/native/window.hpp | 74 +++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 108 deletions(-) create mode 100644 include/cru/platform/native/event.hpp delete mode 100644 include/cru/platform/native/native_event.hpp delete mode 100644 include/cru/platform/native/native_window.hpp create mode 100644 include/cru/platform/native/window.hpp (limited to 'include/cru/platform') diff --git a/include/cru/platform/native/cursor.hpp b/include/cru/platform/native/cursor.hpp index 961dff34..cb8b7ed2 100644 --- a/include/cru/platform/native/cursor.hpp +++ b/include/cru/platform/native/cursor.hpp @@ -1,18 +1,18 @@ #pragma once -#include "../native_resource.hpp" +#include "../resource.hpp" #include namespace cru::platform::native { -struct ICursor : public virtual INativeResource {}; +struct ICursor : virtual INativeResource {}; enum class SystemCursorType { Arrow, Hand, }; -struct ICursorManager : public virtual INativeResource { +struct ICursorManager : virtual INativeResource { virtual std::shared_ptr GetSystemCursor(SystemCursorType type) = 0; // TODO: Add method to create cursor. diff --git a/include/cru/platform/native/event.hpp b/include/cru/platform/native/event.hpp new file mode 100644 index 00000000..48e9cfca --- /dev/null +++ b/include/cru/platform/native/event.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "../graph_base.hpp" +#include "basic_types.hpp" + +namespace cru::platform::native { +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_event.hpp b/include/cru/platform/native/native_event.hpp deleted file mode 100644 index dcd7a336..00000000 --- a/include/cru/platform/native/native_event.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "../graphic_base.hpp" -#include "basic_types.hpp" - -namespace cru::platform::native { -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 deleted file mode 100644 index cd2459e0..00000000 --- a/include/cru/platform/native/native_window.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once -#include "../native_resource.hpp" - -#include "cru/common/event.hpp" - -#include "../graphic_base.hpp" -#include "basic_types.hpp" -#include "cursor.hpp" -#include "native_event.hpp" - -namespace cru::platform::graph { -struct IPainter; -} - -namespace cru::platform::native { -// Represents a native window, which exposes some low-level events and -// operations. -// -// Although you can always retain an instance of this class, the real window -// associated with it might be have already been destroyed by explicitly calling -// 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. -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 INativeWindow* GetParent() = 0; - - virtual bool IsVisible() = 0; - virtual void SetVisible(bool is_visible) = 0; - - virtual Size GetClientSize() = 0; - virtual void SetClientSize(const Size& size) = 0; - - // Get the rect of the window containing frame. - // The lefttop of the rect is relative to screen lefttop. - virtual Rect GetWindowRect() = 0; - - // Set the rect of the window containing frame. - // The lefttop of the rect is relative to screen lefttop. - virtual void SetWindowRect(const Rect& rect) = 0; - - // Relative to client lefttop. - virtual Point GetMousePosition() = 0; - - virtual bool CaptureMouse() = 0; - virtual bool ReleaseMouse() = 0; - - virtual void SetCursor(std::shared_ptr cursor) = 0; - - virtual void RequestRepaint() = 0; - - // Remember to call EndDraw on return value and destroy it. - virtual std::unique_ptr BeginPaint() = 0; - - virtual IEvent* DestroyEvent() = 0; - virtual IEvent* PaintEvent() = 0; - virtual IEvent* ResizeEvent() = 0; - virtual IEvent* FocusEvent() = 0; - virtual IEvent* MouseEnterLeaveEvent() = 0; - virtual IEvent* MouseMoveEvent() = 0; - virtual IEvent* MouseDownEvent() = 0; - virtual IEvent* MouseUpEvent() = 0; - virtual IEvent* KeyDownEvent() = 0; - virtual IEvent* KeyUpEvent() = 0; -}; -} // namespace cru::platform::native diff --git a/include/cru/platform/native/ui_application.hpp b/include/cru/platform/native/ui_application.hpp index 6d2ab659..c1f10d15 100644 --- a/include/cru/platform/native/ui_application.hpp +++ b/include/cru/platform/native/ui_application.hpp @@ -1,29 +1,20 @@ #pragma once -#include "../native_resource.hpp" +#include "../resource.hpp" #include #include #include +namespace cru::platform::graph { +struct IGraphFactory; +} + namespace cru::platform::native { 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. 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 IUiApplication* CreateInstance(); - - // Get the global instance. If it is not created, then return nullptr. - 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). @@ -44,6 +35,8 @@ struct IUiApplication : public virtual INativeResource { virtual std::vector GetAllWindow() = 0; virtual INativeWindow* CreateWindow(INativeWindow* parent) = 0; + virtual cru::platform::graph::IGraphFactory* GetGraphFactory() = 0; + virtual ICursorManager* GetCursorManager() = 0; }; } // namespace cru::platform::native diff --git a/include/cru/platform/native/window.hpp b/include/cru/platform/native/window.hpp new file mode 100644 index 00000000..bfaf170b --- /dev/null +++ b/include/cru/platform/native/window.hpp @@ -0,0 +1,74 @@ +#pragma once +#include "../resource.hpp" + +#include "../graph_base.hpp" +#include "basic_types.hpp" +#include "cru/common/event.hpp" +#include "cursor.hpp" +#include "event.hpp" + +namespace cru::platform::graph { +struct IPainter; +} + +namespace cru::platform::native { +// Represents a native window, which exposes some low-level events and +// operations. +// +// Although you can always retain an instance of this class, the real window +// associated with it might be have already been destroyed by explicitly calling +// 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. +struct INativeWindow : 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 INativeWindow* GetParent() = 0; + + virtual bool IsVisible() = 0; + virtual void SetVisible(bool is_visible) = 0; + + virtual Size GetClientSize() = 0; + virtual void SetClientSize(const Size& size) = 0; + + // Get the rect of the window containing frame. + // The lefttop of the rect is relative to screen lefttop. + virtual Rect GetWindowRect() = 0; + + // Set the rect of the window containing frame. + // The lefttop of the rect is relative to screen lefttop. + virtual void SetWindowRect(const Rect& rect) = 0; + + // Relative to client lefttop. + virtual Point GetMousePosition() = 0; + + virtual bool CaptureMouse() = 0; + virtual bool ReleaseMouse() = 0; + + virtual void SetCursor(std::shared_ptr cursor) = 0; + + virtual void RequestRepaint() = 0; + + // Remember to call EndDraw on return value and destroy it. + virtual std::unique_ptr BeginPaint() = 0; + + virtual IEvent* DestroyEvent() = 0; + virtual IEvent* PaintEvent() = 0; + virtual IEvent* ResizeEvent() = 0; + virtual IEvent* FocusEvent() = 0; + virtual IEvent* MouseEnterLeaveEvent() = 0; + virtual IEvent* MouseMoveEvent() = 0; + virtual IEvent* MouseDownEvent() = 0; + virtual IEvent* MouseUpEvent() = 0; + virtual IEvent* KeyDownEvent() = 0; + virtual IEvent* KeyUpEvent() = 0; +}; +} // namespace cru::platform::native -- cgit v1.2.3