aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cru/osx/graphics/quartz/TextLayout.hpp10
-rw-r--r--include/cru/platform/GraphicsBase.hpp13
-rw-r--r--include/cru/platform/Matrix.hpp9
-rw-r--r--include/cru/platform/graphics/TextLayout.hpp3
-rw-r--r--include/cru/ui/render/TextRenderObject.hpp2
5 files changed, 34 insertions, 3 deletions
diff --git a/include/cru/osx/graphics/quartz/TextLayout.hpp b/include/cru/osx/graphics/quartz/TextLayout.hpp
index 95e3d1be..35bcc32d 100644
--- a/include/cru/osx/graphics/quartz/TextLayout.hpp
+++ b/include/cru/osx/graphics/quartz/TextLayout.hpp
@@ -30,19 +30,25 @@ class OsxCTTextLayout : public OsxQuartzResource, public virtual ITextLayout {
Rect GetTextBounds(bool includingTrailingSpace = false) override;
std::vector<Rect> TextRangeRect(const TextRange& text_range) override;
- Point TextSinglePoint(Index position, bool trailing) override;
+ Rect TextSinglePoint(Index position, bool trailing) override;
TextHitTestResult HitTest(const Point& point) override;
CTFrameRef GetCTFrameRef() const { return ct_frame_; }
CTFrameRef CreateFrameWithColor(const Color& color);
+ Matrix GetTransform() { return transform_; }
+
String GetDebugString() override;
private:
void ReleaseResource();
void RecreateFrame();
+ Rect DoGetTextBounds(bool includingTrailingSpace = false);
+ std::vector<Rect> DoTextRangeRect(const TextRange& text_range);
+ Rect DoTextSinglePoint(Index position, bool trailing);
+
private:
float max_width_;
float max_height_;
@@ -58,5 +64,7 @@ class OsxCTTextLayout : public OsxQuartzResource, public virtual ITextLayout {
int line_count_;
std::vector<CGPoint> line_origins_;
std::vector<CTLineRef> lines_;
+
+ Matrix transform_;
};
} // namespace cru::platform::graphics::osx::quartz
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
diff --git a/include/cru/ui/render/TextRenderObject.hpp b/include/cru/ui/render/TextRenderObject.hpp
index ef39b7a6..68d2d0ce 100644
--- a/include/cru/ui/render/TextRenderObject.hpp
+++ b/include/cru/ui/render/TextRenderObject.hpp
@@ -43,7 +43,7 @@ class TextRenderObject : public RenderObject {
void SetFont(std::shared_ptr<platform::graphics::IFont> font);
std::vector<Rect> TextRangeRect(const TextRange& text_range);
- Point TextSinglePoint(gsl::index position, bool trailing);
+ Rect TextSinglePoint(gsl::index position, bool trailing);
platform::graphics::TextHitTestResult TextHitTest(const Point& point);
std::optional<TextRange> GetSelectionRange() const {