aboutsummaryrefslogtreecommitdiff
path: root/src/win/graph
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-06-27 00:18:48 +0800
committercrupest <crupest@outlook.com>2019-06-27 00:18:48 +0800
commitbaa7cf141b8121473edceae16c1a20a6d47bd202 (patch)
tree9349633a9d0bc286fe29f480bd70e4c2ad1f3075 /src/win/graph
parentf404a3b2eb7bb9865d0c6f938538899996a53d8c (diff)
downloadcru-baa7cf141b8121473edceae16c1a20a6d47bd202.tar.gz
cru-baa7cf141b8121473edceae16c1a20a6d47bd202.tar.bz2
cru-baa7cf141b8121473edceae16c1a20a6d47bd202.zip
......
Diffstat (limited to 'src/win/graph')
-rw-r--r--src/win/graph/CMakeLists.txt21
-rw-r--r--src/win/graph/direct/CMakeLists.txt24
-rw-r--r--src/win/graph/direct/brush.cpp19
-rw-r--r--src/win/graph/direct/exception.cpp29
-rw-r--r--src/win/graph/direct/font.cpp (renamed from src/win/graph/win_font.cpp)0
-rw-r--r--src/win/graph/direct/geometry.cpp (renamed from src/win/graph/win_geometry.cpp)0
-rw-r--r--src/win/graph/direct/graph_factory.cpp (renamed from src/win/graph/win_graph_factory.cpp)48
-rw-r--r--src/win/graph/direct/painter.cpp (renamed from src/win/graph/win_painter.cpp)0
-rw-r--r--src/win/graph/direct/text_layout.cpp (renamed from src/win/graph/win_text_layout.cpp)0
-rw-r--r--src/win/graph/win_brush.cpp23
10 files changed, 98 insertions, 66 deletions
diff --git a/src/win/graph/CMakeLists.txt b/src/win/graph/CMakeLists.txt
index 03cd4566..c90537ac 100644
--- a/src/win/graph/CMakeLists.txt
+++ b/src/win/graph/CMakeLists.txt
@@ -1,20 +1 @@
-set(CRU_WIN_GRAPH_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/win/graph)
-
-add_library(cru_win_graph STATIC
- win_brush.cpp
- win_font.cpp
- win_geometry.cpp
- win_graph_factory.cpp
- win_painter.cpp
- win_text_layout.cpp
-)
-target_sources(cru_win_graph PUBLIC
- ${CRU_WIN_GRAPH_INCLUDE_DIR}/win_brush.hpp
- ${CRU_WIN_GRAPH_INCLUDE_DIR}/win_font.hpp
- ${CRU_WIN_GRAPH_INCLUDE_DIR}/win_geometry.hpp
- ${CRU_WIN_GRAPH_INCLUDE_DIR}/win_graph_factory.hpp
- ${CRU_WIN_GRAPH_INCLUDE_DIR}/win_native_factory.hpp
- ${CRU_WIN_GRAPH_INCLUDE_DIR}/win_painter.hpp
- ${CRU_WIN_GRAPH_INCLUDE_DIR}/win_text_layout.hpp
-)
-target_link_libraries(cru_win_graph PUBLIC D3D11 D2d1 DWrite cru_win_base)
+add_subdirectory(direct)
diff --git a/src/win/graph/direct/CMakeLists.txt b/src/win/graph/direct/CMakeLists.txt
new file mode 100644
index 00000000..7a04a778
--- /dev/null
+++ b/src/win/graph/direct/CMakeLists.txt
@@ -0,0 +1,24 @@
+set(CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/win/graph/direct)
+
+add_library(cru_win_graph_direct STATIC
+ brush.cpp
+ exception.cpp
+ font.cpp
+ geometry.cpp
+ graph_factory.cpp
+ painter.cpp
+ text_layout.cpp
+)
+target_sources(cru_win_graph_direct PUBLIC
+ ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/brush.hpp
+ ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/com_resource.hpp
+ ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/convert_util.hpp
+ ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/direct_factory.hpp
+ ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/exception.hpp
+ ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/font.hpp
+ ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/geometry.hpp
+ ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/graph_factory.hpp
+ ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/painter.hpp
+ ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/text_layout.hpp
+)
+target_link_libraries(cru_win_graph_direct PUBLIC D3D11 D2d1 DWrite cru_win_base)
diff --git a/src/win/graph/direct/brush.cpp b/src/win/graph/direct/brush.cpp
new file mode 100644
index 00000000..7ddd14b4
--- /dev/null
+++ b/src/win/graph/direct/brush.cpp
@@ -0,0 +1,19 @@
+#include "cru/win/graph/direct/brush.hpp"
+
+#include "cru/win/graph/direct/convert_util.hpp"
+#include "cru/win/graph/direct/direct_factory.hpp"
+#include "cru/win/graph/direct/exception.hpp"
+
+#include <cassert>
+
+namespace cru::platform::graph::win::direct {
+D2DSolidColorBrush::D2DSolidColorBrush(IDirectFactory* factory) {
+ assert(factory);
+ ThrowIfFailed(factory->GetD2D1DeviceContext()->CreateSolidColorBrush(
+ Convert(color_), &brush_));
+}
+
+void D2DSolidColorBrush::OnSetColor(const Color& color) {
+ brush_->SetColor(Convert(color));
+}
+} // namespace cru::platform::graph::win::direct
diff --git a/src/win/graph/direct/exception.cpp b/src/win/graph/direct/exception.cpp
new file mode 100644
index 00000000..23c267c1
--- /dev/null
+++ b/src/win/graph/direct/exception.cpp
@@ -0,0 +1,29 @@
+#include "cru/win/graph/direct/exception.hpp"
+
+#include "cru/common/format.hpp"
+
+namespace cru::platform::graph::win::direct {
+using util::Format;
+
+inline std::string HResultMakeMessage(HRESULT h_result,
+ const std::string_view* message) {
+ char buffer[10];
+ sprintf_s(buffer, "%#08x", h_result);
+
+ if (message)
+ return Format(
+ "An HResultError is thrown. HRESULT: {}.\nAdditional message: {}\n",
+ buffer, *message);
+ else
+ return Format("An HResultError is thrown. HRESULT: {}.\n", buffer);
+}
+
+HResultError::HResultError(HRESULT h_result)
+ : PlatformException(HResultMakeMessage(h_result, nullptr)),
+ h_result_(h_result) {}
+
+HResultError::HResultError(HRESULT h_result,
+ const std::string_view& additional_message)
+ : PlatformException(HResultMakeMessage(h_result, &additional_message)),
+ h_result_(h_result) {}
+} // namespace cru::platform::graph::win::direct
diff --git a/src/win/graph/win_font.cpp b/src/win/graph/direct/font.cpp
index a359d73e..a359d73e 100644
--- a/src/win/graph/win_font.cpp
+++ b/src/win/graph/direct/font.cpp
diff --git a/src/win/graph/win_geometry.cpp b/src/win/graph/direct/geometry.cpp
index a725eff6..a725eff6 100644
--- a/src/win/graph/win_geometry.cpp
+++ b/src/win/graph/direct/geometry.cpp
diff --git a/src/win/graph/win_graph_factory.cpp b/src/win/graph/direct/graph_factory.cpp
index de1d28f9..2f2bb7a5 100644
--- a/src/win/graph/win_graph_factory.cpp
+++ b/src/win/graph/direct/graph_factory.cpp
@@ -1,45 +1,48 @@
-#include "cru/win/graph/win_graph_factory.hpp"
+#include "cru/win/graph/direct/graph_factory.hpp"
-#include "cru/win/exception.hpp"
-#include "cru/win/graph/win_brush.hpp"
-#include "cru/win/graph/win_font.hpp"
-#include "cru/win/graph/win_geometry.hpp"
-#include "cru/win/graph/win_text_layout.hpp"
+#include "cru/win/graph/direct/brush.hpp"
+#include "cru/win/graph/direct/exception.hpp"
+#include "cru/win/graph/direct/font.hpp"
+#include "cru/win/graph/direct/geometry.hpp"
+#include "cru/win/graph/direct/text_layout.hpp"
#include <cassert>
#include <cstdlib>
#include <utility>
-namespace cru::win::graph {
+namespace cru::platform::graph::win::direct {
namespace {
-WinGraphFactory* instance = nullptr;
+DirectGraphFactory* instance = nullptr;
}
-} // namespace cru::win::graph
+} // namespace cru::platform::graph::win::direct
namespace cru::platform::graph {
void GraphFactoryAutoDeleteExitHandler() {
- const auto i = ::cru::win::graph::instance; // avoid long namespace prefix
+ const auto i =
+ ::cru::platform::graph::win::direct::instance; // avoid long namespace
+ // prefix
if (i == nullptr) return;
if (i->IsAutoDelete()) delete i;
}
-IGraphFactory* IGraphFactory::CreateInstance() {
- auto& i = ::cru::win::graph::instance; // avoid long namespace prefix
+GraphFactory* GraphFactory::CreateInstance() {
+ auto& i = ::cru::platform::graph::win::direct::instance; // avoid long
+ // namespace prefix
assert(i == nullptr);
- i = new cru::win::graph::WinGraphFactory();
+ i = new ::cru::platform::graph::win::direct::DirectGraphFactory();
std::atexit(&GraphFactoryAutoDeleteExitHandler);
return i;
}
-IGraphFactory* IGraphFactory::GetInstance() {
- return ::cru::win::graph::instance;
+GraphFactory* GraphFactory::GetInstance() {
+ return ::cru::platform::graph::win::direct::instance;
}
} // namespace cru::platform::graph
-namespace cru::win::graph {
-WinGraphFactory* WinGraphFactory::GetInstance() { return instance; }
+namespace cru::platform::graph::win::direct {
+DirectGraphFactory* DirectGraphFactory::GetInstance() { return instance; }
-WinGraphFactory::WinGraphFactory() {
+DirectGraphFactory::DirectGraphFactory() {
UINT creation_flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#ifdef CRU_DEBUG
@@ -86,11 +89,10 @@ WinGraphFactory::WinGraphFactory() {
&dwrite_system_font_collection_));
}
-WinGraphFactory::~WinGraphFactory() { instance = nullptr; }
+DirectGraphFactory::~DirectGraphFactory() { instance = nullptr; }
-platform::graph::ISolidColorBrush* WinGraphFactory::CreateSolidColorBrush(
- const ui::Color& color) {
- return new WinSolidColorBrush(this, color);
+D2DSolidColorBrush* DirectGraphFactory::CreateSolidColorBrush() {
+ return new D2DSolidColorBrush(this);
}
platform::graph::IGeometryBuilder* WinGraphFactory::CreateGeometryBuilder() {
@@ -108,4 +110,4 @@ platform::graph::ITextLayout* WinGraphFactory::CreateTextLayout(
assert(f);
return new WinTextLayout(this, std::move(f), std::move(text));
}
-} // namespace cru::win::graph
+} // namespace cru::platform::graph::win::direct
diff --git a/src/win/graph/win_painter.cpp b/src/win/graph/direct/painter.cpp
index f75cf4e0..f75cf4e0 100644
--- a/src/win/graph/win_painter.cpp
+++ b/src/win/graph/direct/painter.cpp
diff --git a/src/win/graph/win_text_layout.cpp b/src/win/graph/direct/text_layout.cpp
index 997309ad..997309ad 100644
--- a/src/win/graph/win_text_layout.cpp
+++ b/src/win/graph/direct/text_layout.cpp
diff --git a/src/win/graph/win_brush.cpp b/src/win/graph/win_brush.cpp
deleted file mode 100644
index 0c783366..00000000
--- a/src/win/graph/win_brush.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "cru/win/graph/win_brush.hpp"
-
-#include "cru/win/exception.hpp"
-#include "cru/win/graph/win_native_factory.hpp"
-#include "cru/win/graph/util/convert_util.hpp"
-
-#include <cassert>
-
-namespace cru::win::graph {
-WinSolidColorBrush::WinSolidColorBrush(IWinNativeFactory* factory,
- const ui::Color& color) {
- assert(factory);
- ThrowIfFailed(factory->GetD2D1DeviceContext()->CreateSolidColorBrush(
- util::Convert(color), &brush_));
-}
-
-ui::Color WinSolidColorBrush::GetColor() {
- return util::Convert(brush_->GetColor());
-}
-void WinSolidColorBrush::SetColor(const ui::Color& color) {
- brush_->SetColor(util::Convert(color));
-}
-} // namespace cru::win::graph