aboutsummaryrefslogtreecommitdiff
path: root/src/win/graphics/direct/Painter.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-12 21:35:08 +0800
committercrupest <crupest@outlook.com>2022-01-12 21:35:08 +0800
commit7a42d92c10a4bc686244668dd0e3f903f30f2fae (patch)
treee48fc4a47afa5eadbdf54cec6d2b73110f500680 /src/win/graphics/direct/Painter.cpp
parent882d843083895f4905571dc273e801ee18fd5984 (diff)
downloadcru-7a42d92c10a4bc686244668dd0e3f903f30f2fae.tar.gz
cru-7a42d92c10a4bc686244668dd0e3f903f30f2fae.tar.bz2
cru-7a42d92c10a4bc686244668dd0e3f903f30f2fae.zip
...
Diffstat (limited to 'src/win/graphics/direct/Painter.cpp')
-rw-r--r--src/win/graphics/direct/Painter.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/win/graphics/direct/Painter.cpp b/src/win/graphics/direct/Painter.cpp
index 26ef92ec..5db60fd1 100644
--- a/src/win/graphics/direct/Painter.cpp
+++ b/src/win/graphics/direct/Painter.cpp
@@ -27,6 +27,10 @@ void D2DPainter::SetTransform(const platform::Matrix& matrix) {
render_target_->SetTransform(Convert(matrix));
}
+void D2DPainter::ConcatTransform(const Matrix& matrix) {
+ SetTransform(GetTransform() * matrix);
+}
+
void D2DPainter::Clear(const Color& color) {
CheckValidation();
render_target_->Clear(Convert(color));
@@ -54,6 +58,24 @@ void D2DPainter::FillRectangle(const Rect& rectangle, IBrush* brush) {
render_target_->FillRectangle(Convert(rectangle), b->GetD2DBrushInterface());
}
+void D2DPainter::StrokeEllipse(const Rect& outline_rect, IBrush* brush,
+ float width) {
+ CheckValidation();
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
+ render_target_->DrawEllipse(
+ D2D1::Ellipse(Convert(outline_rect.GetCenter()),
+ outline_rect.width / 2.0f, outline_rect.height / 2.0f),
+ b->GetD2DBrushInterface(), width);
+}
+void D2DPainter::FillEllipse(const Rect& outline_rect, IBrush* brush) {
+ CheckValidation();
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
+ render_target_->FillEllipse(
+ D2D1::Ellipse(Convert(outline_rect.GetCenter()),
+ outline_rect.width / 2.0f, outline_rect.height / 2.0f),
+ b->GetD2DBrushInterface());
+}
+
void D2DPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
float width) {
CheckValidation();
@@ -96,6 +118,24 @@ void D2DPainter::PopLayer() {
layers_.pop_back();
}
+void D2DPainter::PushState() {
+ Microsoft::WRL::ComPtr<ID2D1Factory> factory = nullptr;
+ render_target_->GetFactory(&factory);
+
+ Microsoft::WRL::ComPtr<ID2D1DrawingStateBlock> state_block;
+ factory->CreateDrawingStateBlock(&state_block);
+ render_target_->SaveDrawingState(state_block.Get());
+
+ drawing_state_stack_.push_back(std::move(state_block));
+}
+
+void D2DPainter::PopState() {
+ Expects(!drawing_state_stack_.empty());
+ auto drawing_state = drawing_state_stack_.back();
+ drawing_state_stack_.pop_back();
+ render_target_->RestoreDrawingState(drawing_state.Get());
+}
+
void D2DPainter::EndDraw() {
if (is_drawing_) {
is_drawing_ = false;