summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTorstennator <engelTorsten@gmx.de>2023-01-22 19:15:50 +0100
committerSam Atkins <atkinssj@gmail.com>2023-01-26 10:37:26 +0000
commite7ceaf8a6dd4d84bc4f26e768394ed18e893517c (patch)
tree35023c3cf63107cbf0d5aa63ad45272c0d074081 /Userland
parent95c469ca4c34d6bea2c546f722352852d5887cb1 (diff)
downloadserenity-e7ceaf8a6dd4d84bc4f26e768394ed18e893517c.zip
LibGfx: Add small convenience functions for Lines and AA Painter
This patch adds the following some convenience functions: - Lines do now support rotated(), scaled() and translated() - AntiAliasingPainter has now a draw_line function that takes a FloatLine as argument
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGfx/AntiAliasingPainter.h4
-rw-r--r--Userland/Libraries/LibGfx/Line.h27
2 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/AntiAliasingPainter.h b/Userland/Libraries/LibGfx/AntiAliasingPainter.h
index f12988f8b6..ca33f0397c 100644
--- a/Userland/Libraries/LibGfx/AntiAliasingPainter.h
+++ b/Userland/Libraries/LibGfx/AntiAliasingPainter.h
@@ -28,6 +28,10 @@ public:
void draw_line(IntPoint, IntPoint, Color, float thickness = 1, Painter::LineStyle style = Painter::LineStyle::Solid, Color alternate_color = Color::Transparent, LineLengthMode line_length_mode = LineLengthMode::PointToPoint);
void draw_line(FloatPoint, FloatPoint, Color, float thickness = 1, Painter::LineStyle style = Painter::LineStyle::Solid, Color alternate_color = Color::Transparent, LineLengthMode line_length_mode = LineLengthMode::PointToPoint);
+ void draw_line(FloatLine line, Color color, float thickness = 1, Painter::LineStyle style = Painter::LineStyle::Solid, Color alternate_color = Color::Transparent, LineLengthMode line_length_mode = LineLengthMode::PointToPoint)
+ {
+ draw_line(line.a(), line.b(), color, thickness, style, alternate_color, line_length_mode);
+ }
void draw_line_for_path(FloatPoint, FloatPoint, Color, float thickness = 1, Painter::LineStyle style = Painter::LineStyle::Solid, Color alternate_color = Color::Transparent, LineLengthMode line_length_mode = LineLengthMode::PointToPoint);
void fill_path(Path const&, Color, Painter::WindingRule rule = Painter::WindingRule::Nonzero);
diff --git a/Userland/Libraries/LibGfx/Line.h b/Userland/Libraries/LibGfx/Line.h
index 867428317f..d660bde19b 100644
--- a/Userland/Libraries/LibGfx/Line.h
+++ b/Userland/Libraries/LibGfx/Line.h
@@ -129,9 +129,36 @@ public:
Point<T> const& a() const { return m_a; }
Point<T> const& b() const { return m_b; }
+ Line<T> rotated(float radians)
+ {
+ Gfx::AffineTransform rotation_transform;
+ rotation_transform.rotate_radians(radians);
+
+ Line<T> line = *this;
+ line.set_a(line.a().transformed(rotation_transform));
+ line.set_b(line.b().transformed(rotation_transform));
+ return line;
+ }
+
void set_a(Point<T> const& a) { m_a = a; }
void set_b(Point<T> const& b) { m_b = b; }
+ Line<T> scaled(T sx, T sy) const
+ {
+ Line<T> line = *this;
+ line.set_a(line.a().scaled(sx, sy));
+ line.set_b(line.b().scaled(sx, sy));
+ return line;
+ }
+
+ Line<T> translated(Point<T> const& delta) const
+ {
+ Line<T> line = *this;
+ line.set_a(line.a().translated(delta));
+ line.set_b(line.b().translated(delta));
+ return line;
+ }
+
template<typename U>
requires(!IsSame<T, U>)
[[nodiscard]] ALWAYS_INLINE constexpr Line<U> to_type() const