aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform
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
parent8c5b05bcfce96495b4ffc4209ab8feda12597729 (diff)
downloadcru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.gz
cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.tar.bz2
cru-b53527fbe50a953ad0e3225cc812eb76b8a1f82d.zip
...
Diffstat (limited to 'include/cru/platform')
-rw-r--r--include/cru/platform/graph/graph_factory.hpp3
-rw-r--r--include/cru/platform/graph/util/painter_util.hpp4
-rw-r--r--include/cru/platform/matrix.hpp4
-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
-rw-r--r--include/cru/platform/native_resource.hpp5
7 files changed, 59 insertions, 31 deletions
diff --git a/include/cru/platform/graph/graph_factory.hpp b/include/cru/platform/graph/graph_factory.hpp
index 69afc7b3..0b1034cc 100644
--- a/include/cru/platform/graph/graph_factory.hpp
+++ b/include/cru/platform/graph/graph_factory.hpp
@@ -55,5 +55,8 @@ class GraphFactory : public NativeResource {
virtual TextLayout* CreateTextLayout(std::shared_ptr<Font> font,
std::wstring text) = 0;
+
+ virtual bool IsAutoDelete() const = 0;
+ virtual void SetAutoDelete(bool value) = 0;
};
} // namespace cru::platform::graph
diff --git a/include/cru/platform/graph/util/painter_util.hpp b/include/cru/platform/graph/util/painter_util.hpp
index 71e125c3..7a655a34 100644
--- a/include/cru/platform/graph/util/painter_util.hpp
+++ b/include/cru/platform/graph/util/painter_util.hpp
@@ -6,9 +6,9 @@
namespace cru::platform::graph::util {
template <typename Fn>
-inline void WithTransform(IPainter* painter, const Matrix& matrix,
+inline void WithTransform(Painter* painter, const Matrix& matrix,
const Fn& action) {
- static_assert(std::is_invocable_v<decltype(action), IPainter*>,
+ static_assert(std::is_invocable_v<decltype(action), Painter*>,
"Action must can be be invoked with painter.");
const auto old = painter->GetTransform();
painter->SetTransform(old * matrix);
diff --git a/include/cru/platform/matrix.hpp b/include/cru/platform/matrix.hpp
index b0165a88..cbb55c78 100644
--- a/include/cru/platform/matrix.hpp
+++ b/include/cru/platform/matrix.hpp
@@ -37,8 +37,8 @@ struct Matrix {
return Product(*this, matrix);
}
- ui::Point TransformPoint(const ui::Point& point) const {
- return ui::Point{point.x * m11 + point.y * m21 + m31,
+ Point TransformPoint(const Point& point) const {
+ return Point{point.x * m11 + point.y * m21 + m31,
point.x * m12 + point.y * m22 + m32};
}
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
diff --git a/include/cru/platform/native_resource.hpp b/include/cru/platform/native_resource.hpp
index 787c46a5..ec7f01b6 100644
--- a/include/cru/platform/native_resource.hpp
+++ b/include/cru/platform/native_resource.hpp
@@ -9,8 +9,9 @@ class NativeResource : public Object {
NativeResource() = default;
public:
- NativeResource(NativeResource&& other) = delete;
- NativeResource& operator=(NativeResource&& other) = delete;
+ NativeResource(const NativeResource& other) = delete;
+ NativeResource& operator=(const NativeResource& other) = delete;
+
NativeResource(NativeResource&& other) = delete;
NativeResource& operator=(NativeResource&& other) = delete;