diff options
author | crupest <crupest@outlook.com> | 2021-10-31 22:53:11 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-10-31 22:53:11 +0800 |
commit | 1dca2841da6f024f613d6dc16de456d5035f8fce (patch) | |
tree | 37ca6290afbe5900df2eb4a09e30024257d55316 /include/cru/platform | |
parent | e68e0d9a5130e8bc0b634572b7fd44b9bfc0f8ef (diff) | |
download | cru-1dca2841da6f024f613d6dc16de456d5035f8fce.tar.gz cru-1dca2841da6f024f613d6dc16de456d5035f8fce.tar.bz2 cru-1dca2841da6f024f613d6dc16de456d5035f8fce.zip |
...
Diffstat (limited to 'include/cru/platform')
-rw-r--r-- | include/cru/platform/GraphicsBase.hpp | 13 | ||||
-rw-r--r-- | include/cru/platform/Matrix.hpp | 9 | ||||
-rw-r--r-- | include/cru/platform/graphics/TextLayout.hpp | 3 |
3 files changed, 24 insertions, 1 deletions
diff --git a/include/cru/platform/GraphicsBase.hpp b/include/cru/platform/GraphicsBase.hpp index aee718a1..73b41bb5 100644 --- a/include/cru/platform/GraphicsBase.hpp +++ b/include/cru/platform/GraphicsBase.hpp @@ -206,6 +206,19 @@ struct Rect final { point.y < GetBottom(); } + constexpr Rect Normalize() const { + Rect result = *this; + if (result.width < 0) { + result.left += result.width; + result.width = -result.width; + } + if (result.height < 0) { + result.top += result.height; + result.height = -result.height; + } + return result; + } + float left = 0.0f; float top = 0.0f; float width = 0.0f; diff --git a/include/cru/platform/Matrix.hpp b/include/cru/platform/Matrix.hpp index 72459b79..47917d47 100644 --- a/include/cru/platform/Matrix.hpp +++ b/include/cru/platform/Matrix.hpp @@ -43,6 +43,15 @@ struct Matrix { point.x * m12 + point.y * m22 + m32}; } + Rect TransformRect(const Rect& rect, bool normalize = true) const { + Point lefttop = TransformPoint(rect.GetLeftTop()), + rightbottom = TransformPoint(rect.GetRightBottom()); + auto result = + Rect::FromVertices(lefttop.x, lefttop.y, rightbottom.x, rightbottom.y); + if (normalize) result = result.Normalize(); + return result; + } + static Matrix Identity() { return Matrix{1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f}; } diff --git a/include/cru/platform/graphics/TextLayout.hpp b/include/cru/platform/graphics/TextLayout.hpp index ec3c2d96..5f98696d 100644 --- a/include/cru/platform/graphics/TextLayout.hpp +++ b/include/cru/platform/graphics/TextLayout.hpp @@ -17,7 +17,8 @@ struct ITextLayout : virtual IGraphicsResource { virtual Rect GetTextBounds(bool includingTrailingSpace = false) = 0; virtual std::vector<Rect> TextRangeRect(const TextRange& text_range) = 0; - virtual Point TextSinglePoint(Index position, bool trailing) = 0; + // Width is always 0, height is line height. + virtual Rect TextSinglePoint(Index position, bool trailing) = 0; virtual TextHitTestResult HitTest(const Point& point) = 0; }; } // namespace cru::platform::graphics |