1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 11:07:45 +00:00

FontEditor: Add adjustable scaling to GlyphEditorWidget

The editor can now be adjusted under the View->Scale menu
This commit is contained in:
thankyouverycool 2021-04-22 14:04:19 -04:00 committed by Andreas Kling
parent cc781e3d94
commit 2785e12b76
4 changed files with 48 additions and 0 deletions

View file

@ -261,6 +261,33 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr<Gfx::BitmapFont>&&
toolbar.add_separator(); toolbar.add_separator();
toolbar.add_action(*m_open_preview_action); 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) { GUI::Clipboard::the().on_change = [&](const String& data_type) {
m_paste_action->set_enabled(data_type == "glyph/x-fonteditor"); 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_action(*m_open_preview_action);
view_menu.add_separator(); view_menu.add_separator();
view_menu.add_action(*m_show_metadata_action); 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"); auto& help_menu = menubar.add_menu("&Help");
help_menu.add_action(GUI::CommonActions::make_help_action([](auto&) { help_menu.add_action(GUI::CommonActions::make_help_action([](auto&) {

View file

@ -49,6 +49,11 @@ private:
RefPtr<GUI::Action> m_open_preview_action; RefPtr<GUI::Action> m_open_preview_action;
RefPtr<GUI::Action> m_show_metadata_action; RefPtr<GUI::Action> m_show_metadata_action;
GUI::ActionGroup m_glyph_editor_scale_actions;
RefPtr<GUI::Action> m_scale_five_action;
RefPtr<GUI::Action> m_scale_ten_action;
RefPtr<GUI::Action> m_scale_fifteen_action;
RefPtr<GUI::Window> m_font_preview_window; RefPtr<GUI::Window> m_font_preview_window;
RefPtr<GUI::Widget> m_left_column_container; RefPtr<GUI::Widget> m_left_column_container;
RefPtr<GUI::Widget> m_glyph_editor_container; RefPtr<GUI::Widget> m_glyph_editor_container;

View file

@ -183,3 +183,11 @@ int GlyphEditorWidget::preferred_height() const
{ {
return frame_thickness() * 2 + font().glyph_height() * m_scale - 1; 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();
}

View file

@ -31,6 +31,9 @@ public:
Gfx::BitmapFont& font() { return *m_font; } Gfx::BitmapFont& font() { return *m_font; }
const Gfx::BitmapFont& font() const { return *m_font; } const Gfx::BitmapFont& font() const { return *m_font; }
int scale() const { return m_scale; }
void set_scale(int scale);
Function<void(int)> on_glyph_altered; Function<void(int)> on_glyph_altered;
private: private: