diff options
Diffstat (limited to 'src/win/graphics')
-rw-r--r-- | src/win/graphics/direct/Painter.cpp | 40 | ||||
-rw-r--r-- | src/win/graphics/direct/TextLayout.cpp | 39 |
2 files changed, 79 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; diff --git a/src/win/graphics/direct/TextLayout.cpp b/src/win/graphics/direct/TextLayout.cpp index 6ece8ed1..bec4a972 100644 --- a/src/win/graphics/direct/TextLayout.cpp +++ b/src/win/graphics/direct/TextLayout.cpp @@ -1,4 +1,5 @@ #include "cru/win/graphics/direct/TextLayout.hpp" +#include <dwrite.h> #include "cru/common/Logger.hpp" #include "cru/platform/Check.hpp" @@ -55,6 +56,44 @@ void DWriteTextLayout::SetMaxHeight(float max_height) { ThrowIfFailed(text_layout_->SetMaxHeight(max_height_)); } +bool DWriteTextLayout::IsEditMode() { return edit_mode_; } + +void DWriteTextLayout::SetEditMode(bool enable) { + edit_mode_ = enable; + // TODO: Implement this. +} + +Index DWriteTextLayout::GetLineIndexFromCharIndex(Index char_index) { + if (char_index < 0 || char_index >= text_.size()) { + return -1; + } + + auto line_index = 0; + for (Index i = 0; i < char_index; ++i) { + if (text_[i] == u'\n') { + line_index++; + } + } + + return line_index; +} + +float DWriteTextLayout::GetLineHeight(Index line_index) { + Index count = GetLineCount(); + std::vector<DWRITE_LINE_METRICS> line_metrics(count); + + UINT32 actual_line_count = 0; + text_layout_->GetLineMetrics(line_metrics.data(), static_cast<UINT32>(count), + &actual_line_count); + return line_metrics[line_index].height; +} + +Index DWriteTextLayout::GetLineCount() { + UINT32 line_count = 0; + text_layout_->GetLineMetrics(nullptr, 0, &line_count); + return line_count; +} + Rect DWriteTextLayout::GetTextBounds(bool includingTrailingSpace) { DWRITE_TEXT_METRICS metrics; ThrowIfFailed(text_layout_->GetMetrics(&metrics)); |