From d867871bda6cc955a28b213ee324087b70a90b60 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Sun, 14 Aug 2022 13:03:38 -0400 Subject: [PATCH] FontEditor: Standardize Gfx::RotationDirections for rotate_90() --- Userland/Applications/FontEditor/GlyphEditorWidget.cpp | 9 +++++---- Userland/Applications/FontEditor/GlyphEditorWidget.h | 7 +------ Userland/Applications/FontEditor/MainWidget.cpp | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp index feb50f5e20..6042867db5 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp @@ -189,21 +189,22 @@ static Vector> glyph_as_matrix(Gfx::GlyphBitmap const& bitmap) return result; } -void GlyphEditorWidget::rotate_90(Direction direction) +void GlyphEditorWidget::rotate_90(Gfx::RotationDirection direction) { if (on_undo_event) on_undo_event(); auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap(); auto matrix = glyph_as_matrix(bitmap); + auto clockwise = direction == Gfx::RotationDirection::Clockwise; for (int y = 0; y < bitmap.height(); y++) { for (int x = 0; x < bitmap.width(); x++) { - int source_x = (direction == Counterclockwise) ? max(bitmap.width() - 1 - y, 0) : y; - int source_y = (direction == Counterclockwise) ? x : bitmap.width() - 1 - x; + int source_x = clockwise ? y : max(bitmap.width() - 1 - y, 0); + int source_y = clockwise ? bitmap.width() - 1 - x : x; bool value = false; if (source_x < bitmap.width() && source_y < bitmap.height()) { - value = (direction == Counterclockwise && y >= bitmap.width()) ? false : matrix[source_y][source_x]; + value = (!clockwise && y >= bitmap.width()) ? false : matrix[source_y][source_x]; } bitmap.set_bit_at(x, y, value); } diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.h b/Userland/Applications/FontEditor/GlyphEditorWidget.h index 90da616e2b..3abc344fef 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.h +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.h @@ -21,18 +21,13 @@ public: Move }; - enum Direction { - Clockwise, - Counterclockwise - }; - virtual ~GlyphEditorWidget() override = default; int glyph() const { return m_glyph; } void set_glyph(int); bool is_glyph_empty(); - void rotate_90(Direction); + void rotate_90(Gfx::RotationDirection); void flip_vertically(); void flip_horizontally(); diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp index f0b85fc5ac..6374aa582a 100644 --- a/Userland/Applications/FontEditor/MainWidget.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -275,11 +275,11 @@ ErrorOr MainWidget::create_actions() m_glyph_tool_actions.set_exclusive(true); m_rotate_counterclockwise_action = GUI::CommonActions::make_rotate_counterclockwise_action([&](auto&) { - m_glyph_editor_widget->rotate_90(GlyphEditorWidget::Counterclockwise); + m_glyph_editor_widget->rotate_90(Gfx::RotationDirection::CounterClockwise); }); m_rotate_clockwise_action = GUI::CommonActions::make_rotate_clockwise_action([&](auto&) { - m_glyph_editor_widget->rotate_90(GlyphEditorWidget::Clockwise); + m_glyph_editor_widget->rotate_90(Gfx::RotationDirection::Clockwise); }); m_flip_horizontal_action = GUI::Action::create("Flip Horizontally", { Mod_Ctrl | Mod_Shift, Key_Q }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-flip-horizontal.png"sv)), [&](auto&) {