aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/native
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-06-27 17:02:58 +0800
committercrupest <crupest@outlook.com>2019-06-27 17:02:58 +0800
commitb53527fbe50a953ad0e3225cc812eb76b8a1f82d (patch)
treeeb81cd14d0a165c47f841ad94835f8987109de7e /include/cru/platform/native
parent8c5b05bcfce96495b4ffc4209ab8feda12597729 (diff)
downloadcru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.gz
cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.bz2
cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.zip
...
Diffstat (limited to 'include/cru/platform/native')
-rw-r--r--include/cru/platform/native/native_event.hpp5
-rw-r--r--include/cru/platform/native/native_window.hpp37
-rw-r--r--include/cru/platform/native/ui_applicaition.hpp32
3 files changed, 49 insertions, 25 deletions
diff --git a/include/cru/platform/native/native_event.hpp b/include/cru/platform/native/native_event.hpp
index 21db5f90..54bab00c 100644
--- a/include/cru/platform/native/native_event.hpp
+++ b/include/cru/platform/native/native_event.hpp
@@ -1,12 +1,11 @@
#pragma once
-#include "cru/common/base.hpp"
+#include "../graphic_base.hpp"
#include "basic_types.hpp"
-#include "cru/common/ui_base.hpp"
namespace cru::platform::native {
struct NativeMouseButtonEventArgs {
MouseButton button;
- ui::Point point;
+ Point point;
};
} // namespace cru::platform::native
diff --git a/include/cru/platform/native/native_window.hpp b/include/cru/platform/native/native_window.hpp
index bb97ef21..22a2dce0 100644
--- a/include/cru/platform/native/native_window.hpp
+++ b/include/cru/platform/native/native_window.hpp
@@ -1,13 +1,13 @@
#pragma once
-#include "cru/common/base.hpp"
+#include "../native_resource.hpp"
+#include "../graphic_base.hpp"
#include "basic_types.hpp"
#include "cru/common/event.hpp"
-#include "cru/common/ui_base.hpp"
#include "native_event.hpp"
namespace cru::platform::graph {
-struct IPainter;
+class Painter;
}
namespace cru::platform::native {
@@ -19,7 +19,20 @@ 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.
-struct INativeWindow : public virtual Interface {
+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:
// Return if the window is still valid, that is, hasn't been closed or
// destroyed.
virtual bool IsValid() = 0;
@@ -27,30 +40,30 @@ struct INativeWindow : public virtual Interface {
virtual void Close() = 0;
- virtual INativeWindow* GetParent() = 0;
+ virtual NativeWindow* GetParent() = 0;
virtual bool IsVisible() = 0;
virtual void SetVisible(bool is_visible) = 0;
- virtual ui::Size GetClientSize() = 0;
- virtual void SetClientSize(const ui::Size& size) = 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 ui::Rect GetWindowRect() = 0;
+ 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 ui::Rect& rect) = 0;
+ virtual void SetWindowRect(const Rect& rect) = 0;
- virtual graph::IPainter* BeginPaint() = 0;
+ virtual graph::Painter* BeginPaint() = 0;
virtual IEvent<std::nullptr_t>* DestroyEvent() = 0;
virtual IEvent<std::nullptr_t>* PaintEvent() = 0;
- virtual IEvent<ui::Size>* ResizeEvent() = 0;
+ virtual IEvent<Size>* ResizeEvent() = 0;
virtual IEvent<bool>* FocusEvent() = 0;
virtual IEvent<bool>* MouseEnterLeaveEvent() = 0;
- virtual IEvent<ui::Point>* MouseMoveEvent() = 0;
+ virtual IEvent<Point>* MouseMoveEvent() = 0;
virtual IEvent<NativeMouseButtonEventArgs>* MouseDownEvent() = 0;
virtual IEvent<NativeMouseButtonEventArgs>* MouseUpEvent() = 0;
virtual IEvent<int>* KeyDownEvent() = 0;
diff --git a/include/cru/platform/native/ui_applicaition.hpp b/include/cru/platform/native/ui_applicaition.hpp
index 655b8ea0..aa8d98da 100644
--- a/include/cru/platform/native/ui_applicaition.hpp
+++ b/include/cru/platform/native/ui_applicaition.hpp
@@ -1,29 +1,41 @@
#pragma once
-#include "cru/common/base.hpp"
-
-#include "cru/common/auto_delete.hpp"
+#include "../native_resource.hpp"
#include <chrono>
#include <functional>
#include <vector>
namespace cru::platform::native {
-struct INativeWindow;
+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.
-struct IUiApplication : virtual Interface, virtual IAutoDelete {
+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 IUiApplication* CreateInstance();
+ static UiApplication* CreateInstance();
// Get the global instance. If it is not created, then return nullptr.
- static IUiApplication* GetInstance();
+ 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;
@@ -36,7 +48,7 @@ struct IUiApplication : virtual Interface, virtual IAutoDelete {
const std::function<void()>& action) = 0;
virtual void CancelTimer(unsigned long id) = 0;
- virtual std::vector<INativeWindow*> GetAllWindow() = 0;
- virtual INativeWindow* CreateWindow(INativeWindow* parent) = 0;
+ virtual std::vector<NativeWindow*> GetAllWindow() = 0;
+ virtual NativeWindow* CreateWindow(NativeWindow* parent) = 0;
};
-} // namespace cru::platform::ui
+} // namespace cru::platform::native