aboutsummaryrefslogtreecommitdiff
path: root/src/win
diff options
context:
space:
mode:
Diffstat (limited to 'src/win')
-rw-r--r--src/win/exception.cpp28
-rw-r--r--src/win/graph/direct/painter.cpp17
-rw-r--r--src/win/native/window.cpp1
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"