diff options
author | crupest <crupest@outlook.com> | 2020-05-23 23:50:00 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-05-23 23:50:00 +0800 |
commit | f3a8fd608a9776ef0a5f547da918a32cf6074060 (patch) | |
tree | 85b320479296ae12339ee1e28bab66ab001cb44b /src/win | |
parent | 75ff8a6a05afd02aaadf7e3049b0a0e305241182 (diff) | |
download | cru-f3a8fd608a9776ef0a5f547da918a32cf6074060.tar.gz cru-f3a8fd608a9776ef0a5f547da918a32cf6074060.tar.bz2 cru-f3a8fd608a9776ef0a5f547da918a32cf6074060.zip |
...
Diffstat (limited to 'src/win')
-rw-r--r-- | src/win/exception.cpp | 28 | ||||
-rw-r--r-- | src/win/graph/direct/painter.cpp | 17 | ||||
-rw-r--r-- | src/win/native/window.cpp | 1 |
3 files changed, 29 insertions, 17 deletions
diff --git a/src/win/exception.cpp b/src/win/exception.cpp index e0f114b5..fde3ec6f 100644 --- a/src/win/exception.cpp +++ b/src/win/exception.cpp @@ -1,36 +1,32 @@ #include "cru/win/exception.hpp" -#include "cru/common/format.hpp" +#include <fmt/format.h> +#include <optional> namespace cru::platform::win { -using util::Format; inline std::string HResultMakeMessage(HRESULT h_result, - const std::string_view* message) { - char buffer[20]; - sprintf_s(buffer, "%#08x", h_result); - - if (message) - return Format("HRESULT: {}.\nMessage: {}\n", buffer, *message); + std::optional<std::string_view> message) { + if (message.has_value()) + return fmt::format(FMT_STRING("HRESULT: {:#08x}. Message: {}"), h_result, + *message); else - return Format("HRESULT: {}.\n", buffer); + return fmt::format(FMT_STRING("HRESULT: {:#08x}."), h_result); } HResultError::HResultError(HRESULT h_result) - : PlatformException(HResultMakeMessage(h_result, nullptr)), + : PlatformException(HResultMakeMessage(h_result, std::nullopt)), h_result_(h_result) {} HResultError::HResultError(HRESULT h_result, const std::string_view& additional_message) - : PlatformException(HResultMakeMessage(h_result, &additional_message)), + : PlatformException(HResultMakeMessage(h_result, additional_message)), h_result_(h_result) {} inline std::string Win32MakeMessage(DWORD error_code, - const std::string_view& message) { - char buffer[20]; - sprintf_s(buffer, "%#04x", error_code); - - return Format("Last error code: {}.\nMessage: {}\n", buffer, message); + std::string_view message) { + return fmt::format("Last error code: {:#04x}.\nMessage: {}\n", error_code, + message); } Win32Error::Win32Error(const std::string_view& message) diff --git a/src/win/graph/direct/painter.cpp b/src/win/graph/direct/painter.cpp index c5150ad4..df0075e0 100644 --- a/src/win/graph/direct/painter.cpp +++ b/src/win/graph/direct/painter.cpp @@ -71,6 +71,23 @@ void D2DPainter::DrawText(const Point& offset, ITextLayout* text_layout, b->GetD2DBrushInterface()); } +void D2DPainter::PushLayer(const Rect& bounds) { + CheckValidation(); + + Microsoft::WRL::ComPtr<ID2D1Layer> layer; + ThrowIfFailed(render_target_->CreateLayer(&layer)); + + render_target_->PushLayer(D2D1::LayerParameters(Convert(bounds)), + layer.Get()); + + layers_.push_back(std::move(layer)); +} + +void D2DPainter::PopLayer() { + render_target_->PopLayer(); + layers_.pop_back(); +} + void D2DPainter::EndDraw() { if (is_drawing_) { is_drawing_ = false; diff --git a/src/win/native/window.cpp b/src/win/native/window.cpp index bda8e764..bed9a264 100644 --- a/src/win/native/window.cpp +++ b/src/win/native/window.cpp @@ -1,6 +1,5 @@ #include "cru/win/native/window.hpp" -#include "cru/common/format.hpp" #include "cru/common/logger.hpp" #include "cru/platform/check.hpp" #include "cru/win/native/cursor.hpp" |