From 894b41ef4d4bc73df87c9914c3a8c7258e2e97c9 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Tue, 25 Oct 2022 07:11:58 -0400 Subject: [PATCH] FontEditor: Consolidate GlyphEditor's flip_{horizontally,vertically} --- .../FontEditor/GlyphEditorWidget.cpp | 29 +++---------------- .../FontEditor/GlyphEditorWidget.h | 3 +- .../Applications/FontEditor/MainWidget.cpp | 4 +-- 3 files changed, 7 insertions(+), 29 deletions(-) diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp index 6042867db5..be0e375716 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp @@ -215,40 +215,19 @@ void GlyphEditorWidget::rotate_90(Gfx::RotationDirection direction) update(); } -void GlyphEditorWidget::flip_vertically() +void GlyphEditorWidget::flip(Gfx::Orientation orientation) { if (on_undo_event) on_undo_event(); auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap(); auto matrix = glyph_as_matrix(bitmap); + auto vertical = orientation == Gfx::Orientation::Vertical; for (int y = 0; y < bitmap.height(); y++) { for (int x = 0; x < bitmap.width(); x++) { - int source_x = x; - int source_y = bitmap.height() - 1 - y; - bool value = matrix[source_y][source_x]; - bitmap.set_bit_at(x, y, value); - } - } - - if (on_glyph_altered) - on_glyph_altered(m_glyph); - update(); -} - -void GlyphEditorWidget::flip_horizontally() -{ - if (on_undo_event) - on_undo_event(); - - auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap(); - auto matrix = glyph_as_matrix(bitmap); - - for (int y = 0; y < bitmap.height(); y++) { - for (int x = 0; x < bitmap.width(); x++) { - int source_x = bitmap.width() - 1 - x; - int source_y = y; + int source_x = vertical ? x : bitmap.width() - 1 - x; + int source_y = vertical ? bitmap.height() - 1 - y : y; bool value = 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 3abc344fef..05f18ece74 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.h +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.h @@ -28,8 +28,7 @@ public: bool is_glyph_empty(); void rotate_90(Gfx::RotationDirection); - void flip_vertically(); - void flip_horizontally(); + void flip(Gfx::Orientation); int preferred_width() const; int preferred_height() const; diff --git a/Userland/Applications/FontEditor/MainWidget.cpp b/Userland/Applications/FontEditor/MainWidget.cpp index 6374aa582a..d99fa037d7 100644 --- a/Userland/Applications/FontEditor/MainWidget.cpp +++ b/Userland/Applications/FontEditor/MainWidget.cpp @@ -283,11 +283,11 @@ ErrorOr MainWidget::create_actions() }); 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&) { - m_glyph_editor_widget->flip_horizontally(); + m_glyph_editor_widget->flip(Gfx::Orientation::Horizontal); }); m_flip_vertical_action = GUI::Action::create("Flip Vertically", { Mod_Ctrl | Mod_Shift, Key_W }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-flip-vertical.png"sv)), [&](auto&) { - m_glyph_editor_widget->flip_vertically(); + m_glyph_editor_widget->flip(Gfx::Orientation::Vertical); }); m_copy_text_action = GUI::Action::create("Copy as Te&xt", { Mod_Ctrl, Key_T }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png"sv)), [&](auto&) {