aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-03-18 21:16:25 +0800
committercrupest <crupest@outlook.com>2020-03-18 21:16:25 +0800
commitb129c5a144dfb116082689ffaaa9ac78e2403656 (patch)
tree08c3540569260c4231996f769040beb3737e5b4b
parentabf604f8c6ec89c8d7df7062fe10fd17c60d5719 (diff)
downloadcru-b129c5a144dfb116082689ffaaa9ac78e2403656.tar.gz
cru-b129c5a144dfb116082689ffaaa9ac78e2403656.tar.bz2
cru-b129c5a144dfb116082689ffaaa9ac78e2403656.zip
...
-rw-r--r--.vscode/settings.json3
-rw-r--r--include/cru/platform/graph/base.hpp12
-rw-r--r--include/cru/platform/graph/factory.hpp4
-rw-r--r--include/cru/platform/graph/fwd.hpp12
-rw-r--r--include/cru/platform/graph/geometry.hpp2
-rw-r--r--include/cru/platform/graph/painter.hpp5
-rw-r--r--include/cru/platform/graph/text_layout.hpp9
-rw-r--r--include/cru/platform/native/ui_application.hpp15
-rw-r--r--include/cru/ui/render/border_render_object.hpp5
-rw-r--r--include/cru/ui/render/render_object.hpp5
-rw-r--r--include/cru/ui/render/text_render_object.hpp8
-rw-r--r--include/cru/win/native/ui_application.hpp11
-rw-r--r--src/platform/native/ui_application.cpp10
-rw-r--r--src/win/native/timer.cpp4
-rw-r--r--src/win/native/timer.hpp2
-rw-r--r--src/win/native/ui_application.cpp29
16 files changed, 67 insertions, 69 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 7dd396d8..1f97dbb1 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -63,6 +63,7 @@
"set": "cpp",
"sstream": "cpp",
"xlocmon": "cpp",
- "xloctime": "cpp"
+ "xloctime": "cpp",
+ "string_view": "cpp"
}
}
diff --git a/include/cru/platform/graph/base.hpp b/include/cru/platform/graph/base.hpp
index 8c2a2d2f..0b011262 100644
--- a/include/cru/platform/graph/base.hpp
+++ b/include/cru/platform/graph/base.hpp
@@ -2,3 +2,15 @@
#include "../graph_base.hpp"
#include "../matrix.hpp"
#include "../resource.hpp"
+
+#include "fwd.hpp"
+
+#include <memory>
+
+namespace cru::platform::graph {
+struct TextHitTestResult {
+ int position;
+ bool trailing;
+ bool insideText;
+};
+} // namespace cru::platform::graph
diff --git a/include/cru/platform/graph/factory.hpp b/include/cru/platform/graph/factory.hpp
index 2c52cbb8..0ed45161 100644
--- a/include/cru/platform/graph/factory.hpp
+++ b/include/cru/platform/graph/factory.hpp
@@ -1,15 +1,13 @@
#pragma once
-#include "base.hpp"
+#include "resource.hpp"
#include "brush.hpp"
#include "font.hpp"
#include "geometry.hpp"
#include "text_layout.hpp"
-#include <memory>
#include <string>
#include <string_view>
-#include <utility>
namespace cru::platform::graph {
// Entry point of the graph module.
diff --git a/include/cru/platform/graph/fwd.hpp b/include/cru/platform/graph/fwd.hpp
new file mode 100644
index 00000000..508a49fa
--- /dev/null
+++ b/include/cru/platform/graph/fwd.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+namespace cru::platform::graph {
+struct IGraphFactory;
+struct IBrush;
+struct ISolidColorBrush;
+struct IFont;
+struct IGeometry;
+struct IGeometryBuilder;
+struct IPainter;
+struct ITextLayout;
+} // namespace cru::platform::graph
diff --git a/include/cru/platform/graph/geometry.hpp b/include/cru/platform/graph/geometry.hpp
index a49453dd..85ffd3f6 100644
--- a/include/cru/platform/graph/geometry.hpp
+++ b/include/cru/platform/graph/geometry.hpp
@@ -1,8 +1,6 @@
#pragma once
#include "resource.hpp"
-#include <memory>
-
namespace cru::platform::graph {
struct IGeometry : virtual IGraphResource {
virtual bool FillContains(const Point& point) = 0;
diff --git a/include/cru/platform/graph/painter.hpp b/include/cru/platform/graph/painter.hpp
index 3ae9cf1c..1f4ab7cb 100644
--- a/include/cru/platform/graph/painter.hpp
+++ b/include/cru/platform/graph/painter.hpp
@@ -1,10 +1,7 @@
#pragma once
-#include "base.hpp"
+#include "resource.hpp"
namespace cru::platform::graph {
-struct IBrush;
-struct IGeometry;
-struct ITextLayout;
struct IPainter : virtual INativeResource {
virtual Matrix GetTransform() = 0;
diff --git a/include/cru/platform/graph/text_layout.hpp b/include/cru/platform/graph/text_layout.hpp
index d1cfb44b..20009c0d 100644
--- a/include/cru/platform/graph/text_layout.hpp
+++ b/include/cru/platform/graph/text_layout.hpp
@@ -1,19 +1,10 @@
#pragma once
#include "resource.hpp"
-#include <memory>
#include <string>
#include <vector>
namespace cru::platform::graph {
-struct IFont;
-
-struct TextHitTestResult {
- int position;
- bool trailing;
- bool insideText;
-};
-
struct ITextLayout : virtual IGraphResource {
virtual std::string GetText() = 0;
virtual void SetText(std::string new_text) = 0;
diff --git a/include/cru/platform/native/ui_application.hpp b/include/cru/platform/native/ui_application.hpp
index edbcc578..e02904bb 100644
--- a/include/cru/platform/native/ui_application.hpp
+++ b/include/cru/platform/native/ui_application.hpp
@@ -20,10 +20,15 @@ struct IUiApplication : public virtual INativeResource {
public:
static IUiApplication* GetInstance() { return instance; }
- protected:
+ private:
static IUiApplication* instance;
+ protected:
+ IUiApplication();
+
public:
+ ~IUiApplication() override;
+
// 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;
@@ -31,13 +36,13 @@ struct IUiApplication : public virtual INativeResource {
// Post a quit message with given quit code.
virtual void RequestQuit(int quit_code) = 0;
- virtual void AddOnQuitHandler(const std::function<void()>& handler) = 0;
+ virtual void AddOnQuitHandler(std::function<void()> handler) = 0;
- virtual void InvokeLater(const std::function<void()>& action) = 0;
+ virtual void InvokeLater(std::function<void()> action) = 0;
virtual unsigned long SetTimeout(std::chrono::milliseconds milliseconds,
- const std::function<void()>& action) = 0;
+ std::function<void()> action) = 0;
virtual unsigned long SetInterval(std::chrono::milliseconds milliseconds,
- const std::function<void()>& action) = 0;
+ std::function<void()> action) = 0;
virtual void CancelTimer(unsigned long id) = 0;
virtual std::vector<INativeWindow*> GetAllWindow() = 0;
diff --git a/include/cru/ui/render/border_render_object.hpp b/include/cru/ui/render/border_render_object.hpp
index 726510a8..b9af71c0 100644
--- a/include/cru/ui/render/border_render_object.hpp
+++ b/include/cru/ui/render/border_render_object.hpp
@@ -3,11 +3,6 @@
#include <memory>
-namespace cru::platform::graph {
-struct IBrush;
-struct IGeometry;
-} // namespace cru::platform::graph
-
namespace cru::ui::render {
struct CornerRadius {
constexpr CornerRadius()
diff --git a/include/cru/ui/render/render_object.hpp b/include/cru/ui/render/render_object.hpp
index d9851757..8db1a20f 100644
--- a/include/cru/ui/render/render_object.hpp
+++ b/include/cru/ui/render/render_object.hpp
@@ -2,6 +2,7 @@
#include "../base.hpp"
#include "cru/common/event.hpp"
+#include "cru/platform/graph/base.hpp"
#include <vector>
@@ -10,10 +11,6 @@ namespace cru::ui {
class Control;
}
-namespace cru::platform::graph {
-struct IPainter;
-}
-
namespace cru::ui::render {
struct AfterLayoutEventArgs {};
diff --git a/include/cru/ui/render/text_render_object.hpp b/include/cru/ui/render/text_render_object.hpp
index 33d34f78..62313cd3 100644
--- a/include/cru/ui/render/text_render_object.hpp
+++ b/include/cru/ui/render/text_render_object.hpp
@@ -1,17 +1,9 @@
#pragma once
#include "render_object.hpp"
-#include "cru/platform/graph/text_layout.hpp"
-
#include <memory>
#include <string>
-// forward declarations
-namespace cru::platform::graph {
-struct IBrush;
-struct IFont;
-} // namespace cru::platform::graph
-
namespace cru::ui::render {
class TextRenderObject : public RenderObject {
public:
diff --git a/include/cru/win/native/ui_application.hpp b/include/cru/win/native/ui_application.hpp
index 73f67abe..8de9d1b5 100644
--- a/include/cru/win/native/ui_application.hpp
+++ b/include/cru/win/native/ui_application.hpp
@@ -35,17 +35,18 @@ class WinUiApplication : public WinNativeResource,
int Run() override;
void RequestQuit(int quit_code) override;
- void AddOnQuitHandler(const std::function<void()>& handler) override;
+ void AddOnQuitHandler(std::function<void()> handler) override;
- void InvokeLater(const std::function<void()>& action) override;
+ void InvokeLater(std::function<void()> action) override;
unsigned long SetTimeout(std::chrono::milliseconds milliseconds,
- const std::function<void()>& action) override;
+ std::function<void()> action) override;
unsigned long SetInterval(std::chrono::milliseconds milliseconds,
- const std::function<void()>& action) override;
+ std::function<void()> action) override;
void CancelTimer(unsigned long id) override;
std::vector<INativeWindow*> GetAllWindow() override;
- std::shared_ptr<INativeWindowResolver> CreateWindow(INativeWindow* parent) override;
+ std::shared_ptr<INativeWindowResolver> CreateWindow(
+ INativeWindow* parent) override;
cru::platform::graph::IGraphFactory* GetGraphFactory() override;
diff --git a/src/platform/native/ui_application.cpp b/src/platform/native/ui_application.cpp
index b4794182..212d9104 100644
--- a/src/platform/native/ui_application.cpp
+++ b/src/platform/native/ui_application.cpp
@@ -2,4 +2,14 @@
namespace cru::platform::native {
IUiApplication* IUiApplication::instance = nullptr;
+
+IUiApplication::IUiApplication() {
+ if (instance) {
+ throw std::runtime_error("An ui application has already been created.");
+ }
+
+ instance = this;
}
+
+IUiApplication::~IUiApplication() { instance = nullptr; }
+} // namespace cru::platform::native
diff --git a/src/win/native/timer.cpp b/src/win/native/timer.cpp
index ed2ae069..66743963 100644
--- a/src/win/native/timer.cpp
+++ b/src/win/native/timer.cpp
@@ -4,10 +4,10 @@ namespace cru::platform::native::win {
TimerManager::TimerManager(GodWindow* god_window) { god_window_ = god_window; }
UINT_PTR TimerManager::CreateTimer(const UINT milliseconds, const bool loop,
- const TimerAction& action) {
+ TimerAction action) {
const auto id = current_count_++;
::SetTimer(god_window_->GetHandle(), id, milliseconds, nullptr);
- map_.emplace(id, std::make_pair(loop, action));
+ map_.emplace(id, std::make_pair(loop, std::move(action)));
return id;
}
diff --git a/src/win/native/timer.hpp b/src/win/native/timer.hpp
index 10658cf1..6c4871dd 100644
--- a/src/win/native/timer.hpp
+++ b/src/win/native/timer.hpp
@@ -21,7 +21,7 @@ class TimerManager : public Object {
~TimerManager() override = default;
- UINT_PTR CreateTimer(UINT milliseconds, bool loop, const TimerAction& action);
+ UINT_PTR CreateTimer(UINT milliseconds, bool loop, TimerAction action);
void KillTimer(UINT_PTR id);
std::optional<std::pair<bool, TimerAction>> GetAction(UINT_PTR id);
diff --git a/src/win/native/ui_application.cpp b/src/win/native/ui_application.cpp
index 9ab61551..892acd50 100644
--- a/src/win/native/ui_application.cpp
+++ b/src/win/native/ui_application.cpp
@@ -18,13 +18,7 @@ namespace cru::platform::native::win {
WinUiApplication* WinUiApplication::instance = nullptr;
WinUiApplication::WinUiApplication() {
- if (instance) {
- throw new std::runtime_error(
- "Already created an instance of WinUiApplication");
- }
-
instance = this;
- IUiApplication::instance = this;
instance_handle_ = ::GetModuleHandleW(nullptr);
if (!instance_handle_)
@@ -42,10 +36,7 @@ WinUiApplication::WinUiApplication() {
cursor_manager_ = std::make_unique<WinCursorManager>();
}
-WinUiApplication::~WinUiApplication() {
- IUiApplication::instance = nullptr;
- instance = nullptr;
-}
+WinUiApplication::~WinUiApplication() { instance = nullptr; }
int WinUiApplication::Run() {
MSG msg;
@@ -63,13 +54,13 @@ void WinUiApplication::RequestQuit(const int quit_code) {
::PostQuitMessage(quit_code);
}
-void WinUiApplication::AddOnQuitHandler(const std::function<void()>& handler) {
- quit_handlers_.push_back(handler);
+void WinUiApplication::AddOnQuitHandler(std::function<void()> handler) {
+ quit_handlers_.push_back(std::move(handler));
}
-void WinUiApplication::InvokeLater(const std::function<void()>& action) {
+void WinUiApplication::InvokeLater(std::function<void()> action) {
// copy the action to a safe place
- auto p_action_copy = new std::function<void()>(action);
+ auto p_action_copy = new std::function<void()>(std::move(action));
if (::PostMessageW(GetGodWindow()->GetHandle(), invoke_later_message_id,
reinterpret_cast<WPARAM>(p_action_copy), 0) == 0)
@@ -77,17 +68,15 @@ void WinUiApplication::InvokeLater(const std::function<void()>& action) {
}
unsigned long WinUiApplication::SetTimeout(
- std::chrono::milliseconds milliseconds,
- const std::function<void()>& action) {
+ std::chrono::milliseconds milliseconds, std::function<void()> action) {
return static_cast<unsigned long>(timer_manager_->CreateTimer(
- static_cast<UINT>(milliseconds.count()), false, action));
+ static_cast<UINT>(milliseconds.count()), false, std::move(action)));
}
unsigned long WinUiApplication::SetInterval(
- std::chrono::milliseconds milliseconds,
- const std::function<void()>& action) {
+ std::chrono::milliseconds milliseconds, std::function<void()> action) {
return static_cast<unsigned long>(timer_manager_->CreateTimer(
- static_cast<UINT>(milliseconds.count()), true, action));
+ static_cast<UINT>(milliseconds.count()), true, std::move(action)));
}
void WinUiApplication::CancelTimer(unsigned long id) {