diff options
author | crupest <crupest@outlook.com> | 2019-04-19 23:20:09 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-04-19 23:20:09 +0800 |
commit | ea87825d58ab5b58dd360c3f080518c07a865db0 (patch) | |
tree | 4b497ef3687d682368e0fde4b86293565583a63a /src/win/graph | |
parent | 7351020a582d70a1495249fba87d342c8a1fb634 (diff) | |
download | cru-ea87825d58ab5b58dd360c3f080518c07a865db0.tar.gz cru-ea87825d58ab5b58dd360c3f080518c07a865db0.tar.bz2 cru-ea87825d58ab5b58dd360c3f080518c07a865db0.zip |
...
Diffstat (limited to 'src/win/graph')
-rw-r--r-- | src/win/graph/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/win/graph/d2d_painter.cpp (renamed from src/win/graph/win_painter.cpp) | 32 | ||||
-rw-r--r-- | src/win/graph/graph_manager.cpp | 6 | ||||
-rw-r--r-- | src/win/graph/win_font.cpp | 2 |
4 files changed, 19 insertions, 23 deletions
diff --git a/src/win/graph/CMakeLists.txt b/src/win/graph/CMakeLists.txt index 7781e09a..61749a6a 100644 --- a/src/win/graph/CMakeLists.txt +++ b/src/win/graph/CMakeLists.txt @@ -1,9 +1,9 @@ add_library(cru_win_graph STATIC + d2d_painter.cpp graph_manager.cpp win_brush.cpp win_font.cpp win_geometry.cpp win_graph_factory.cpp - win_painter.cpp win_text_layout.cpp) target_link_libraries(cru_win_graph PUBLIC D3D11 D2d1 DWrite cru_win_base) diff --git a/src/win/graph/win_painter.cpp b/src/win/graph/d2d_painter.cpp index 69ce1141..26f6bef0 100644 --- a/src/win/graph/win_painter.cpp +++ b/src/win/graph/d2d_painter.cpp @@ -1,4 +1,4 @@ -#include "cru/win/graph/win_painter.hpp" +#include "cru/win/graph/d2d_painter.hpp" #include "cru/win/exception.hpp" #include "cru/win/graph/d2d_util.hpp" @@ -10,31 +10,29 @@ #include <cassert> namespace cru::win::graph { -WinPainter::WinPainter(ID2D1RenderTarget* render_target) { +D2DPainter::D2DPainter(ID2D1RenderTarget* render_target) { assert(render_target); render_target_ = render_target; } -WinPainter::~WinPainter() { EndDraw(); } - -platform::Matrix WinPainter::GetTransform() { +platform::Matrix D2DPainter::GetTransform() { assert(!IsDisposed()); D2D1_MATRIX_3X2_F m; render_target_->GetTransform(&m); return util::Convert(m); } -void WinPainter::SetTransform(const platform::Matrix& matrix) { +void D2DPainter::SetTransform(const platform::Matrix& matrix) { assert(!IsDisposed()); render_target_->SetTransform(util::Convert(matrix)); } -void WinPainter::Clear(const ui::Color& color) { +void D2DPainter::Clear(const ui::Color& color) { assert(!IsDisposed()); render_target_->Clear(util::Convert(color)); } -void WinPainter::StrokeRectangle(const ui::Rect& rectangle, +void D2DPainter::StrokeRectangle(const ui::Rect& rectangle, platform::graph::Brush* brush, float width) { assert(!IsDisposed()); const auto b = dynamic_cast<WinBrush*>(brush); @@ -43,7 +41,7 @@ void WinPainter::StrokeRectangle(const ui::Rect& rectangle, width); } -void WinPainter::FillRectangle(const ui::Rect& rectangle, +void D2DPainter::FillRectangle(const ui::Rect& rectangle, platform::graph::Brush* brush) { assert(!IsDisposed()); const auto b = dynamic_cast<WinBrush*>(brush); @@ -51,7 +49,7 @@ void WinPainter::FillRectangle(const ui::Rect& rectangle, render_target_->FillRectangle(util::Convert(rectangle), b->GetD2DBrush()); } -void WinPainter::StrokeGeometry(platform::graph::Geometry* geometry, +void D2DPainter::StrokeGeometry(platform::graph::Geometry* geometry, platform::graph::Brush* brush, float width) { assert(!IsDisposed()); const auto g = dynamic_cast<WinGeometry*>(geometry); @@ -62,7 +60,7 @@ void WinPainter::StrokeGeometry(platform::graph::Geometry* geometry, render_target_->DrawGeometry(g->GetNative(), b->GetD2DBrush(), width); } -void WinPainter::FillGeometry(platform::graph::Geometry* geometry, +void D2DPainter::FillGeometry(platform::graph::Geometry* geometry, platform::graph::Brush* brush) { assert(!IsDisposed()); const auto g = dynamic_cast<WinGeometry*>(geometry); @@ -73,7 +71,7 @@ void WinPainter::FillGeometry(platform::graph::Geometry* geometry, render_target_->FillGeometry(g->GetNative(), b->GetD2DBrush()); } -void WinPainter::DrawText(const ui::Point& offset, +void D2DPainter::DrawText(const ui::Point& offset, platform::graph::TextLayout* text_layout, platform::graph::Brush* brush) { assert(!IsDisposed()); @@ -86,14 +84,10 @@ void WinPainter::DrawText(const ui::Point& offset, t->GetDWriteTextLayout(), b->GetD2DBrush()); } -void WinPainter::EndDraw() { - if (!IsDisposed()) { +void D2DPainter::EndDraw() { + if (!is_disposed_) { + is_disposed_ = true; DoEndDraw(); } } - -void WinPainter::DoEndDraw() { - ThrowIfFailed(render_target_->EndDraw()); - is_disposed_ = true; -} } // namespace cru::win::graph diff --git a/src/win/graph/graph_manager.cpp b/src/win/graph/graph_manager.cpp index a4306b1b..30e1a14e 100644 --- a/src/win/graph/graph_manager.cpp +++ b/src/win/graph/graph_manager.cpp @@ -2,10 +2,12 @@ #include "cru/win/exception.hpp" +#include <cassert> + namespace cru::win::graph { GraphManager* GraphManager::GetInstance() { - static GraphManager instance; - return &instance; + static GraphManager* instance = new GraphManager(); + return instance; } GraphManager::GraphManager() { diff --git a/src/win/graph/win_font.cpp b/src/win/graph/win_font.cpp index 0eb5e6b2..96983d3e 100644 --- a/src/win/graph/win_font.cpp +++ b/src/win/graph/win_font.cpp @@ -13,7 +13,7 @@ WinFontDescriptor::WinFontDescriptor(GraphManager* graph_manager, float font_size) { assert(graph_manager); std::array<wchar_t, LOCALE_NAME_MAX_LENGTH> buffer; - if (!::GetUserDefaultLocaleName(buffer.data(), buffer.size())) + if (!::GetUserDefaultLocaleName(buffer.data(), static_cast<int>(buffer.size()))) throw Win32Error(::GetLastError(), "Failed to get locale."); ThrowIfFailed(graph_manager->GetDWriteFactory()->CreateTextFormat( |