From 2785e12b767c8021e9dbf3383cfab2e2b5a5a30f Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Thu, 22 Apr 2021 14:04:19 -0400 Subject: [PATCH] FontEditor: Add adjustable scaling to GlyphEditorWidget The editor can now be adjusted under the View->Scale menu --- .../Applications/FontEditor/FontEditor.cpp | 32 +++++++++++++++++++ Userland/Applications/FontEditor/FontEditor.h | 5 +++ .../FontEditor/GlyphEditorWidget.cpp | 8 +++++ .../FontEditor/GlyphEditorWidget.h | 3 ++ 4 files changed, 48 insertions(+) diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp index c4b4419149..7c02daeb89 100644 --- a/Userland/Applications/FontEditor/FontEditor.cpp +++ b/Userland/Applications/FontEditor/FontEditor.cpp @@ -261,6 +261,33 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& toolbar.add_separator(); toolbar.add_action(*m_open_preview_action); + m_scale_five_action = GUI::Action::create_checkable("500%", { Mod_Ctrl, Key_1 }, [&](auto&) { + m_glyph_editor_widget->set_scale(5); + m_glyph_editor_container->set_fixed_size(m_glyph_editor_widget->preferred_width(), m_glyph_editor_widget->preferred_height()); + m_left_column_container->set_fixed_width(m_glyph_editor_widget->preferred_width()); + }); + m_scale_five_action->set_checked(false); + m_scale_five_action->set_status_tip("Scale the editor in proportion to the current font"); + m_scale_ten_action = GUI::Action::create_checkable("1000%", { Mod_Ctrl, Key_2 }, [&](auto&) { + m_glyph_editor_widget->set_scale(10); + m_glyph_editor_container->set_fixed_size(m_glyph_editor_widget->preferred_width(), m_glyph_editor_widget->preferred_height()); + m_left_column_container->set_fixed_width(m_glyph_editor_widget->preferred_width()); + }); + m_scale_ten_action->set_checked(true); + m_scale_ten_action->set_status_tip("Scale the editor in proportion to the current font"); + m_scale_fifteen_action = GUI::Action::create_checkable("1500%", { Mod_Ctrl, Key_3 }, [&](auto&) { + m_glyph_editor_widget->set_scale(15); + m_glyph_editor_container->set_fixed_size(m_glyph_editor_widget->preferred_width(), m_glyph_editor_widget->preferred_height()); + m_left_column_container->set_fixed_width(m_glyph_editor_widget->preferred_width()); + }); + m_scale_fifteen_action->set_checked(false); + m_scale_fifteen_action->set_status_tip("Scale the editor in proportion to the current font"); + + m_glyph_editor_scale_actions.add_action(*m_scale_five_action); + m_glyph_editor_scale_actions.add_action(*m_scale_ten_action); + m_glyph_editor_scale_actions.add_action(*m_scale_fifteen_action); + m_glyph_editor_scale_actions.set_exclusive(true); + GUI::Clipboard::the().on_change = [&](const String& data_type) { m_paste_action->set_enabled(data_type == "glyph/x-fonteditor"); }; @@ -446,6 +473,11 @@ void FontEditorWidget::initialize_menubar(GUI::Menubar& menubar) view_menu.add_action(*m_open_preview_action); view_menu.add_separator(); view_menu.add_action(*m_show_metadata_action); + view_menu.add_separator(); + auto& scale_menu = view_menu.add_submenu("&Scale"); + scale_menu.add_action(*m_scale_five_action); + scale_menu.add_action(*m_scale_ten_action); + scale_menu.add_action(*m_scale_fifteen_action); auto& help_menu = menubar.add_menu("&Help"); help_menu.add_action(GUI::CommonActions::make_help_action([](auto&) { diff --git a/Userland/Applications/FontEditor/FontEditor.h b/Userland/Applications/FontEditor/FontEditor.h index 03a56b5648..faabc62151 100644 --- a/Userland/Applications/FontEditor/FontEditor.h +++ b/Userland/Applications/FontEditor/FontEditor.h @@ -49,6 +49,11 @@ private: RefPtr m_open_preview_action; RefPtr m_show_metadata_action; + GUI::ActionGroup m_glyph_editor_scale_actions; + RefPtr m_scale_five_action; + RefPtr m_scale_ten_action; + RefPtr m_scale_fifteen_action; + RefPtr m_font_preview_window; RefPtr m_left_column_container; RefPtr m_glyph_editor_container; diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp index bffee79ff7..6a86f4a491 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp @@ -183,3 +183,11 @@ int GlyphEditorWidget::preferred_height() const { return frame_thickness() * 2 + font().glyph_height() * m_scale - 1; } + +void GlyphEditorWidget::set_scale(int scale) +{ + if (m_scale == scale) + return; + m_scale = clamp(scale, 1, 15); + update(); +} diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.h b/Userland/Applications/FontEditor/GlyphEditorWidget.h index 2b654a1b8b..0fa62b9ac7 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.h +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.h @@ -31,6 +31,9 @@ public: Gfx::BitmapFont& font() { return *m_font; } const Gfx::BitmapFont& font() const { return *m_font; } + int scale() const { return m_scale; } + void set_scale(int scale); + Function on_glyph_altered; private: