diff options
author | MacDue <macdue@dueutil.tech> | 2022-03-21 01:52:19 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-05-07 22:59:02 +0200 |
commit | cf5b6c5c8d2925b552a2f3efb6ec6395de05b5e3 (patch) | |
tree | 7da991c637ea84d6acb3fcb85baaa07feef9ec51 /Userland/Demos | |
parent | 89445b967db7b17916d0ab3d32f1fe290baf4f93 (diff) | |
download | serenity-cf5b6c5c8d2925b552a2f3efb6ec6395de05b5e3.zip |
Demos/Eyes: Render eyes antialiased
This looks good, and is a good way to test ellipse rendering is
working properly.
Diffstat (limited to 'Userland/Demos')
-rw-r--r-- | Userland/Demos/Eyes/EyesWidget.cpp | 13 | ||||
-rw-r--r-- | Userland/Demos/Eyes/EyesWidget.h | 3 |
2 files changed, 9 insertions, 7 deletions
diff --git a/Userland/Demos/Eyes/EyesWidget.cpp b/Userland/Demos/Eyes/EyesWidget.cpp index 902187386f..37ec28b331 100644 --- a/Userland/Demos/Eyes/EyesWidget.cpp +++ b/Userland/Demos/Eyes/EyesWidget.cpp @@ -20,18 +20,19 @@ void EyesWidget::track_mouse_move(Gfx::IntPoint const& point) void EyesWidget::paint_event(GUI::PaintEvent& event) { GUI::Painter painter(*this); + Gfx::AntiAliasingPainter aa_painter { painter }; painter.clear_rect(event.rect(), Gfx::Color()); for (int i = 0; i < m_full_rows; i++) { for (int j = 0; j < m_eyes_in_row; j++) - render_eyeball(i, j, painter); + render_eyeball(i, j, aa_painter); } for (int i = 0; i < m_extra_columns; ++i) - render_eyeball(m_full_rows, i, painter); + render_eyeball(m_full_rows, i, aa_painter); } -void EyesWidget::render_eyeball(int row, int column, GUI::Painter& painter) const +void EyesWidget::render_eyeball(int row, int column, Gfx::AntiAliasingPainter& painter) const { auto eye_width = width() / m_eyes_in_row; auto eye_height = height() / m_num_rows; @@ -40,9 +41,9 @@ void EyesWidget::render_eyeball(int row, int column, GUI::Painter& painter) cons auto height_thickness = max(int(eye_height / 5.5), 1); bounds.shrink(int(eye_width / 12.5), 0); - painter.fill_ellipse(bounds, palette().base_text()); + painter.draw_ellipse(bounds, palette().base_text()); bounds.shrink(width_thickness, height_thickness); - painter.fill_ellipse(bounds, palette().base()); + painter.draw_ellipse(bounds, palette().base()); Gfx::IntPoint pupil_center = this->pupil_center(bounds); Gfx::IntSize pupil_size { @@ -56,7 +57,7 @@ void EyesWidget::render_eyeball(int row, int column, GUI::Painter& painter) cons pupil_size.height() }; - painter.fill_ellipse(pupil, palette().base_text()); + painter.draw_ellipse(pupil, palette().base_text()); } Gfx::IntPoint EyesWidget::pupil_center(Gfx::IntRect& eyeball_bounds) const diff --git a/Userland/Demos/Eyes/EyesWidget.h b/Userland/Demos/Eyes/EyesWidget.h index 3fb6d26f43..6f64c2fa12 100644 --- a/Userland/Demos/Eyes/EyesWidget.h +++ b/Userland/Demos/Eyes/EyesWidget.h @@ -9,6 +9,7 @@ #include <LibGUI/MouseTracker.h> #include <LibGUI/Widget.h> +#include <LibGfx/AntiAliasingPainter.h> class EyesWidget final : public GUI::Widget , GUI::MouseTracker { @@ -29,7 +30,7 @@ private: virtual void paint_event(GUI::PaintEvent&) override; virtual void track_mouse_move(Gfx::IntPoint const&) override; - void render_eyeball(int row, int column, GUI::Painter&) const; + void render_eyeball(int row, int column, Gfx::AntiAliasingPainter& aa_painter) const; Gfx::IntPoint pupil_center(Gfx::IntRect& eyeball_bounds) const; Gfx::IntPoint m_mouse_position; |