From 3c0e17f29f9cff870f4cb609f3177ad580f8d4ee Mon Sep 17 00:00:00 2001 From: MacDue Date: Sat, 19 Mar 2022 00:29:22 +0000 Subject: [PATCH] LibGfx: Support scaling in AntiAliasingPainter::draw_circle() Previously the painter would crash if scaling was enabled. --- Userland/Libraries/LibGfx/AntiAliasingPainter.cpp | 7 +++++-- Userland/Libraries/LibGfx/Painter.cpp | 6 +++--- Userland/Libraries/LibGfx/Painter.h | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp b/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp index 31c51edf60..8d6cbe1010 100644 --- a/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp +++ b/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp @@ -193,6 +193,9 @@ void Gfx::AntiAliasingPainter::draw_circle(IntPoint center, int radius, Color co Inline comments are from the paper. */ + center *= m_underlying_painter.scale(); + radius *= m_underlying_painter.scale(); + // TODO: Generalize to ellipses (see paper) // These happen to be the same here, but are treated separately in the paper: @@ -352,11 +355,11 @@ void Gfx::AntiAliasingPainter::fill_rect_with_rounded_corners(IntRect const& a_r a_rect.x() + a_rect.width() - top_right_radius, a_rect.y() + top_right_radius, }; - IntPoint bottom_right_corner { + IntPoint bottom_left_corner { a_rect.x() + bottom_left_radius, a_rect.y() + a_rect.height() - bottom_right_radius }; - IntPoint bottom_left_corner { + IntPoint bottom_right_corner { a_rect.x() + a_rect.width() - bottom_left_radius, a_rect.y() + a_rect.height() - bottom_left_radius }; diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 91e12bd240..1f148e647b 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1713,11 +1713,11 @@ void Painter::draw_text(Function d void Painter::set_pixel(IntPoint const& p, Color color, bool blend) { - VERIFY(scale() == 1); // FIXME: Add scaling support. - auto point = p; point.translate_by(state().translation); - if (!clip_rect().contains(point)) + // Use the scale only to avoid clipping pixels set in drawing functions that handle + // scaling and call set_pixel() -- do not scale the pixel. + if (!clip_rect().contains(point / scale())) return; auto& dst = m_target->scanline(point.y())[point.x()]; if (!blend) { diff --git a/Userland/Libraries/LibGfx/Painter.h b/Userland/Libraries/LibGfx/Painter.h index 445ddf8677..fedb6433ca 100644 --- a/Userland/Libraries/LibGfx/Painter.h +++ b/Userland/Libraries/LibGfx/Painter.h @@ -145,11 +145,12 @@ public: IntRect clip_rect() const { return state().clip_rect; } + int scale() const { return state().scale; } + protected: IntPoint translation() const { return state().translation; } IntRect to_physical(IntRect const& r) const { return r.translated(translation()) * scale(); } IntPoint to_physical(IntPoint const& p) const { return p.translated(translation()) * scale(); } - int scale() const { return state().scale; } void set_physical_pixel_with_draw_op(u32& pixel, Color const&); void fill_physical_scanline_with_draw_op(int y, int x, int width, Color const& color); void fill_rect_with_draw_op(IntRect const&, Color);