From 387466475252999e40cecce822a457419057dfa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20ASLIT=C3=9CRK?= Date: Sat, 9 May 2020 01:06:56 +0300 Subject: [PATCH] Applications: FontEditor, relocate form items by fonts size FontEditor widget rewritten for respect to the font size and added fixed width and height header values. --- Applications/FontEditor/FontEditor.cpp | 243 ++++++++++++++---- Applications/FontEditor/FontEditor.h | 9 +- Applications/FontEditor/FontEditorBottom.frm | 1 - Applications/FontEditor/GlyphEditorWidget.cpp | 2 +- Applications/FontEditor/GlyphEditorWidget.h | 6 +- Applications/FontEditor/GlyphMapWidget.cpp | 10 +- Applications/FontEditor/GlyphMapWidget.h | 14 +- Applications/FontEditor/Makefile | 7 - Applications/FontEditor/main.cpp | 39 +-- 9 files changed, 243 insertions(+), 88 deletions(-) delete mode 100644 Applications/FontEditor/FontEditorBottom.frm diff --git a/Applications/FontEditor/FontEditor.cpp b/Applications/FontEditor/FontEditor.cpp index 4540151deb..0cb59fb7b9 100644 --- a/Applications/FontEditor/FontEditor.cpp +++ b/Applications/FontEditor/FontEditor.cpp @@ -27,75 +27,225 @@ #include "FontEditor.h" #include "GlyphEditorWidget.h" #include "GlyphMapWidget.h" -#include "UI_FontEditorBottom.h" #include +#include #include #include #include #include +#include #include #include #include +#include #include +#include #include FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& edited_font) : m_edited_font(move(edited_font)) + , m_path(path) { set_fill_with_background_color(true); + set_layout(); - if (path.is_empty()) - m_path = "/tmp/saved.font"; - else - m_path = path; + // Top + auto& main_container = add(); + main_container.set_layout(); + main_container.layout()->set_margins({ 4, 4, 4, 4 }); + main_container.set_background_role(Gfx::ColorRole::SyntaxKeyword); + main_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); - m_glyph_map_widget = add(*m_edited_font); - m_glyph_map_widget->move_to({ 90, 5 }); + // Top-Left Glyph Ediyor and info + auto& editor_container = main_container.add(); + editor_container.set_layout(); + editor_container.layout()->set_margins({ 4, 4, 4, 4 }); + editor_container.set_background_role(Gfx::ColorRole::SyntaxKeyword); + editor_container.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); - m_glyph_editor_widget = add(*m_edited_font); - m_glyph_editor_widget->move_to({ 5, 5 }); + m_glyph_editor_widget = editor_container.add(*m_edited_font); + m_glyph_editor_widget->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); + m_glyph_editor_widget->set_preferred_size(m_glyph_editor_widget->preferred_width(), m_glyph_editor_widget->preferred_height()); - m_ui = make(); - add_child(*m_ui->main_widget); - m_ui->main_widget->set_relative_rect(5, 110, 380, 240); + editor_container.set_preferred_size(m_glyph_editor_widget->preferred_width(), 0); - m_ui->name_textbox->set_text(m_edited_font->name()); - m_ui->name_textbox->on_change = [this] { - m_edited_font->set_name(m_ui->name_textbox->text()); + auto& glyph_width_label = editor_container.add(); + glyph_width_label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + glyph_width_label.set_preferred_size(0, 22); + glyph_width_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); + glyph_width_label.set_text("Glyph width:"); + + auto& glyph_width_spinbox = editor_container.add(); + glyph_width_spinbox.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + glyph_width_spinbox.set_preferred_size(0, 22); + glyph_width_spinbox.set_min(0); + glyph_width_spinbox.set_max(32); + glyph_width_spinbox.set_value(0); + glyph_width_spinbox.set_enabled(!m_edited_font->is_fixed_width()); + + auto& info_label = editor_container.add(); + info_label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + info_label.set_preferred_size(0, 22); + info_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); + info_label.set_text("info_label"); + + /// Top-Right glyph map and font meta data + + auto& map_and_test_container = main_container.add(); + map_and_test_container.set_layout(); + map_and_test_container.layout()->set_margins({ 4, 4, 4, 4 }); + map_and_test_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); + + m_glyph_map_widget = map_and_test_container.add(*m_edited_font); + m_glyph_map_widget->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); + m_glyph_map_widget->set_preferred_size(m_glyph_map_widget->preferred_width(), m_glyph_map_widget->preferred_height()); + + auto& font_mtest_group_box = map_and_test_container.add(); + font_mtest_group_box.set_layout(); + font_mtest_group_box.layout()->set_margins({ 5, 15, 5, 5 }); + font_mtest_group_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + font_mtest_group_box.set_preferred_size(0, 2 * m_edited_font->glyph_height() + 50); + font_mtest_group_box.set_title("Test"); + + auto& demo_label_1 = font_mtest_group_box.add(); + demo_label_1.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); + demo_label_1.set_font(m_edited_font); + demo_label_1.set_text("quick fox jumps nightly above wizard."); + + auto& demo_label_2 = font_mtest_group_box.add(); + demo_label_2.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); + demo_label_2.set_font(m_edited_font); + demo_label_2.set_text("QUICK FOX JUMPS NIGHTLY ABOVE WIZARD!"); + + auto& font_metadata_group_box = map_and_test_container.add(); + font_metadata_group_box.set_layout(); + font_metadata_group_box.layout()->set_margins({ 5, 15, 5, 5 }); + font_metadata_group_box.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + font_metadata_group_box.set_preferred_size(0, 145); + font_metadata_group_box.set_title("Font metadata"); + + //// Name Row + auto& namecontainer = font_metadata_group_box.add(); + namecontainer.set_layout(); + namecontainer.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + namecontainer.set_preferred_size(0, 22); + + auto& name_label = namecontainer.add(); + name_label.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); + name_label.set_preferred_size(100, 0); + name_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); + name_label.set_text("Name:"); + + auto& name_textbox = namecontainer.add(); + name_textbox.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); + name_textbox.set_text(m_edited_font->name()); + name_textbox.on_change = [&] { + m_edited_font->set_name(name_textbox.text()); }; - m_ui->fixed_width_checkbox->set_text("Fixed width"); - m_ui->fixed_width_checkbox->set_checked(m_edited_font->is_fixed_width()); + //// Glyph spacing Row + auto& glyph_spacing_container = font_metadata_group_box.add(); + glyph_spacing_container.set_layout(); + glyph_spacing_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + glyph_spacing_container.set_preferred_size(0, 22); - m_ui->spacing_spinbox->set_value(m_edited_font->glyph_spacing()); + auto& glyph_spacing = glyph_spacing_container.add(); + glyph_spacing.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); + glyph_spacing.set_preferred_size(100, 0); + glyph_spacing.set_text_alignment(Gfx::TextAlignment::CenterLeft); + glyph_spacing.set_text("Glyph spacing:"); - m_ui->path_textbox->set_text(m_path); - m_ui->path_textbox->on_change = [this] { - m_path = m_ui->path_textbox->text(); + auto& spacing_spinbox = glyph_spacing_container.add(); + spacing_spinbox.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); + spacing_spinbox.set_min(0); + spacing_spinbox.set_max(255); + spacing_spinbox.set_value(m_edited_font->glyph_spacing()); + + //// Glyph Height Row + auto& glyph_height_container = font_metadata_group_box.add(); + glyph_height_container.set_layout(); + glyph_height_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + glyph_height_container.set_preferred_size(0, 22); + + auto& glyph_height = glyph_height_container.add(); + glyph_height.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); + glyph_height.set_preferred_size(100, 0); + glyph_height.set_text_alignment(Gfx::TextAlignment::CenterLeft); + glyph_height.set_text("Glyph height:"); + + auto& glyph_height_spinbox = glyph_height_container.add(); + glyph_height_spinbox.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); + glyph_height_spinbox.set_min(0); + glyph_height_spinbox.set_max(255); + glyph_height_spinbox.set_value(m_edited_font->glyph_height()); + glyph_height_spinbox.set_enabled(false); + + //// Glyph width Row + auto& glyph_weight_container = font_metadata_group_box.add(); + glyph_weight_container.set_layout(); + glyph_weight_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + glyph_weight_container.set_preferred_size(0, 22); + + auto& glyph_header_width_label = glyph_weight_container.add(); + glyph_header_width_label.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); + glyph_header_width_label.set_preferred_size(100, 0); + glyph_header_width_label.set_text_alignment(Gfx::TextAlignment::CenterLeft); + glyph_header_width_label.set_text("Glyph width:"); + + auto& glyph_header_width_spinbox = glyph_weight_container.add(); + glyph_header_width_spinbox.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); + glyph_header_width_spinbox.set_min(0); + glyph_header_width_spinbox.set_max(255); + glyph_header_width_spinbox.set_value(m_edited_font->glyph_fixed_width()); + glyph_header_width_spinbox.set_enabled(false); + + //// Fixed checkbox Row + auto& fixed_width_checkbox = font_metadata_group_box.add(); + fixed_width_checkbox.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + fixed_width_checkbox.set_preferred_size(0, 22); + fixed_width_checkbox.set_text("Fixed width"); + fixed_width_checkbox.set_checked(m_edited_font->is_fixed_width()); + + // Bottom + auto& bottom_container = add(); + bottom_container.set_layout(); + bottom_container.layout()->set_margins({ 8, 0, 8, 8 }); + bottom_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed); + bottom_container.set_preferred_size(0, 32); + + bottom_container.layout()->add_spacer(); + + auto& save_button = bottom_container.add(); + save_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); + save_button.set_preferred_size(80, 0); + save_button.set_text("Save"); + save_button.on_click = [this] { + auto ret_val = m_edited_font->write_to_file(m_path); + if (!ret_val) { + GUI::MessageBox::show("The font file could not be saved.", "Save failed", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window()); + } }; - m_ui->save_button->set_text("Save"); - m_ui->save_button->on_click = [this] { - dbgprintf("write to file: '%s'\n", m_path.characters()); - m_edited_font->write_to_file(m_path); - }; - - m_ui->quit_button->set_text("Quit"); - m_ui->quit_button->on_click = [] { + auto& quit_button = bottom_container.add(); + quit_button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill); + quit_button.set_preferred_size(80, 0); + quit_button.set_text("Quit"); + quit_button.on_click = [this] { exit(0); }; - m_ui->info_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); + // Event hanglers + auto update_demo = [&] { + demo_label_1.update(); + demo_label_2.update(); + }; - m_ui->demo_label_1->set_font(m_edited_font); - m_ui->demo_label_1->set_text("quick fox jumps nightly above wizard."); + auto calculate_prefed_sizes = [&] { + int right_site_width = m_edited_font->width("QUICK FOX JUMPS NIGHTLY ABOVE WIZARD!") + 20; + right_site_width = max(right_site_width, m_glyph_map_widget->preferred_width()); - m_ui->demo_label_2->set_font(m_edited_font); - m_ui->demo_label_2->set_text("QUICK FOX JUMPS NIGHTLY ABOVE WIZARD!"); - - auto update_demo = [this] { - m_ui->demo_label_1->update(); - m_ui->demo_label_2->update(); + m_preferred_width = m_glyph_editor_widget->width() + right_site_width + 20; + m_preferred_height = m_glyph_map_widget->relative_rect().height() + 2 * m_edited_font->glyph_height() + 250; }; m_glyph_editor_widget->on_glyph_altered = [this, update_demo](u8 glyph) { @@ -103,9 +253,9 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& edite update_demo(); }; - m_glyph_map_widget->on_glyph_selected = [this](u8 glyph) { + m_glyph_map_widget->on_glyph_selected = [&](size_t glyph) { m_glyph_editor_widget->set_glyph(glyph); - m_ui->width_spinbox->set_value(m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph())); + glyph_width_spinbox.set_value(m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph())); StringBuilder builder; builder.appendf("0x%b (", glyph); if (glyph < 128) { @@ -115,28 +265,31 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& edite builder.append(128 | (glyph % 64)); } builder.append(')'); - m_ui->info_label->set_text(builder.to_string()); + info_label.set_text(builder.to_string()); }; - m_ui->fixed_width_checkbox->on_checked = [this, update_demo](bool checked) { + fixed_width_checkbox.on_checked = [&](bool checked) { m_edited_font->set_fixed_width(checked); - m_ui->width_spinbox->set_value(m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph())); + glyph_width_spinbox.set_enabled(!m_edited_font->is_fixed_width()); + glyph_width_spinbox.set_value(m_edited_font->glyph_width(m_glyph_map_widget->selected_glyph())); m_glyph_editor_widget->update(); update_demo(); }; - m_ui->width_spinbox->on_change = [this, update_demo](int value) { + glyph_width_spinbox.on_change = [this, update_demo](int value) { m_edited_font->set_glyph_width(m_glyph_map_widget->selected_glyph(), value); m_glyph_editor_widget->update(); m_glyph_map_widget->update_glyph(m_glyph_map_widget->selected_glyph()); update_demo(); }; - m_ui->spacing_spinbox->on_change = [this, update_demo](int value) { + spacing_spinbox.on_change = [this, update_demo](int value) { m_edited_font->set_glyph_spacing(value); update_demo(); }; + // init widget + calculate_prefed_sizes(); m_glyph_map_widget->set_selected_glyph('A'); } diff --git a/Applications/FontEditor/FontEditor.h b/Applications/FontEditor/FontEditor.h index 78820bb1c2..f620976e0e 100644 --- a/Applications/FontEditor/FontEditor.h +++ b/Applications/FontEditor/FontEditor.h @@ -32,13 +32,14 @@ class GlyphEditorWidget; class GlyphMapWidget; -struct UI_FontEditorBottom; - class FontEditorWidget final : public GUI::Widget { C_OBJECT(FontEditorWidget) public: virtual ~FontEditorWidget() override; + int preferred_width() { return m_preferred_width; } + int preferred_height() { return m_preferred_height; } + private: FontEditorWidget(const String& path, RefPtr&&); RefPtr m_edited_font; @@ -47,6 +48,6 @@ private: RefPtr m_glyph_editor_widget; String m_path; - - OwnPtr m_ui; + int m_preferred_width; + int m_preferred_height; }; diff --git a/Applications/FontEditor/FontEditorBottom.frm b/Applications/FontEditor/FontEditorBottom.frm deleted file mode 100644 index d690a27797..0000000000 --- a/Applications/FontEditor/FontEditorBottom.frm +++ /dev/null @@ -1 +0,0 @@ -{"name":"FontEditorBottom","widgets":[{"enabled":true,"forecolor":"#000000ff","autofill":false,"x":5,"tooltip":"[null]","name":"info_label","height":16,"width":66,"y":15,"class":"GUI::Label","text":"info_label","backcolor":"#d4d0c8ff","visible":true},{"enabled":true,"forecolor":"#00000000","autofill":false,"x":95,"tooltip":null,"name":"demo_label_1","height":16,"width":276,"y":15,"class":"GUI::Label","text":"demo_label_1","backcolor":"#00000000","visible":true},{"enabled":true,"forecolor":"#00000000","autofill":false,"x":95,"tooltip":null,"name":"demo_label_2","height":16,"width":276,"y":40,"class":"GUI::Label","text":"demo_label_2","backcolor":"#00000000","visible":true},{"enabled":true,"forecolor":"#00000000","autofill":false,"x":5,"tooltip":null,"name":"label1","height":16,"width":66,"y":40,"class":"GUI::Label","text":"Glyph width:","backcolor":"#00000000","visible":true},{"forecolor":"#00000000","name":"width_spinbox","height":21,"backcolor":"#00000000","enabled":true,"value":0,"tooltip":null,"max":32,"visible":true,"y":60,"width":71,"autofill":false,"x":5,"class":"GUI::SpinBox","min":0},{"enabled":true,"forecolor":"#00000000","autofill":false,"x":5,"tooltip":null,"name":"gb1","height":76,"width":300,"y":95,"class":"GUI::GroupBox","backcolor":"#d4d0c8ff","title":"Font metadata","visible":true},{"enabled":true,"forecolor":"#00000000","autofill":false,"x":15,"tooltip":null,"name":"label2","height":16,"width":40,"y":105,"class":"GUI::Label","text":"Name:","backcolor":"#00000000","visible":true},{"tooltip":null,"forecolor":"#00000000","name":"name_textbox","y":120,"autofill":false,"x":15,"class":"GUI::TextBox","backcolor":"#00000000","ruler_visible":false,"height":21,"enabled":true,"text":"","visible":true,"width":196},{"enabled":true,"forecolor":"#00000000","autofill":false,"x":215,"tooltip":null,"name":"label3","height":16,"width":80,"y":105,"class":"GUI::Label","text":"Glyph spacing:","backcolor":"#00000000","visible":true},{"forecolor":"#00000000","name":"spacing_spinbox","height":21,"backcolor":"#00000000","enabled":true,"value":0,"tooltip":null,"max":255,"visible":true,"y":120,"width":80,"autofill":false,"x":215,"class":"GUI::SpinBox","min":0},{"tooltip":null,"checked":false,"forecolor":"#00000000","name":"fixed_width_checkbox","y":145,"autofill":false,"x":15,"class":"GUI::CheckBox","backcolor":"#00000000","height":21,"enabled":true,"text":"Fixed width","visible":true,"width":101},{"tooltip":null,"forecolor":"#00000000","name":"path_textbox","y":175,"autofill":false,"x":5,"class":"GUI::TextBox","backcolor":"#00000000","ruler_visible":false,"height":21,"enabled":true,"text":"","visible":true,"width":216},{"enabled":true,"forecolor":"#00000000","autofill":false,"x":5,"tooltip":null,"name":"save_button","height":21,"width":106,"y":205,"class":"GUI::Button","text":"Save","backcolor":"#00000000","visible":true},{"enabled":true,"forecolor":"#00000000","autofill":false,"x":115,"tooltip":null,"name":"quit_button","height":21,"width":106,"y":205,"class":"GUI::Button","text":"Quit","backcolor":"#00000000","visible":true}]} diff --git a/Applications/FontEditor/GlyphEditorWidget.cpp b/Applications/FontEditor/GlyphEditorWidget.cpp index 66adffdda5..e3db6ba2a6 100644 --- a/Applications/FontEditor/GlyphEditorWidget.cpp +++ b/Applications/FontEditor/GlyphEditorWidget.cpp @@ -39,7 +39,7 @@ GlyphEditorWidget::~GlyphEditorWidget() { } -void GlyphEditorWidget::set_glyph(u8 glyph) +void GlyphEditorWidget::set_glyph(int glyph) { if (m_glyph == glyph) return; diff --git a/Applications/FontEditor/GlyphEditorWidget.h b/Applications/FontEditor/GlyphEditorWidget.h index df6cfbfa1a..ec8080972c 100644 --- a/Applications/FontEditor/GlyphEditorWidget.h +++ b/Applications/FontEditor/GlyphEditorWidget.h @@ -32,8 +32,8 @@ class GlyphEditorWidget final : public GUI::Frame { public: virtual ~GlyphEditorWidget() override; - u8 glyph() const { return m_glyph; } - void set_glyph(u8); + int glyph() const { return m_glyph; } + void set_glyph(int); int preferred_width() const; int preferred_height() const; @@ -52,6 +52,6 @@ private: void draw_at_mouse(const GUI::MouseEvent&); RefPtr m_font; - u8 m_glyph { 0 }; + int m_glyph { 0 }; int m_scale { 10 }; }; diff --git a/Applications/FontEditor/GlyphMapWidget.cpp b/Applications/FontEditor/GlyphMapWidget.cpp index d5f1118564..e252e617cc 100644 --- a/Applications/FontEditor/GlyphMapWidget.cpp +++ b/Applications/FontEditor/GlyphMapWidget.cpp @@ -32,6 +32,7 @@ GlyphMapWidget::GlyphMapWidget(Gfx::Font& mutable_font) : m_font(mutable_font) { + m_glyph_count = mutable_font.glyph_count(); set_relative_rect({ 0, 0, preferred_width(), preferred_height() }); } @@ -49,7 +50,7 @@ int GlyphMapWidget::preferred_height() const return rows() * (font().glyph_height() + m_vertical_spacing) + 2 + frame_thickness() * 2; } -void GlyphMapWidget::set_selected_glyph(u8 glyph) +void GlyphMapWidget::set_selected_glyph(int glyph) { if (m_selected_glyph == glyph) return; @@ -59,7 +60,7 @@ void GlyphMapWidget::set_selected_glyph(u8 glyph) update(); } -Gfx::Rect GlyphMapWidget::get_outer_rect(u8 glyph) const +Gfx::Rect GlyphMapWidget::get_outer_rect(int glyph) const { int row = glyph / columns(); int column = glyph % columns(); @@ -72,7 +73,7 @@ Gfx::Rect GlyphMapWidget::get_outer_rect(u8 glyph) const .translated(frame_thickness(), frame_thickness()); } -void GlyphMapWidget::update_glyph(u8 glyph) +void GlyphMapWidget::update_glyph(int glyph) { update(get_outer_rect(glyph)); } @@ -158,7 +159,8 @@ void GlyphMapWidget::keydown_event(GUI::KeyEvent& event) } if (!event.ctrl() && event.key() == KeyCode::Key_End) { int new_selection = selected_glyph() / m_columns * m_columns + (m_columns - 1); - new_selection = clamp(new_selection, 0, m_glyph_count - 1); + int max = m_glyph_count - 1; + new_selection = clamp(new_selection, 0, max); set_selected_glyph(new_selection); return; } diff --git a/Applications/FontEditor/GlyphMapWidget.h b/Applications/FontEditor/GlyphMapWidget.h index 55847bb74a..bf24b7612d 100644 --- a/Applications/FontEditor/GlyphMapWidget.h +++ b/Applications/FontEditor/GlyphMapWidget.h @@ -35,8 +35,8 @@ class GlyphMapWidget final : public GUI::Frame { public: virtual ~GlyphMapWidget() override; - u8 selected_glyph() const { return m_selected_glyph; } - void set_selected_glyph(u8); + int selected_glyph() const { return m_selected_glyph; } + void set_selected_glyph(int); int rows() const { return ceil_div(m_glyph_count, m_columns); } int columns() const { return m_columns; } @@ -47,9 +47,9 @@ public: Gfx::Font& font() { return *m_font; } const Gfx::Font& font() const { return *m_font; } - void update_glyph(u8); + void update_glyph(int); - Function on_glyph_selected; + Function on_glyph_selected; private: explicit GlyphMapWidget(Gfx::Font&); @@ -58,12 +58,12 @@ private: virtual void mousedown_event(GUI::MouseEvent&) override; virtual void keydown_event(GUI::KeyEvent&) override; - Gfx::Rect get_outer_rect(u8 glyph) const; + Gfx::Rect get_outer_rect(int glyph) const; RefPtr m_font; - int m_glyph_count { 256 }; + int m_glyph_count; int m_columns { 32 }; int m_horizontal_spacing { 2 }; int m_vertical_spacing { 2 }; - u8 m_selected_glyph { 0 }; + int m_selected_glyph { 0 }; }; diff --git a/Applications/FontEditor/Makefile b/Applications/FontEditor/Makefile index af40646a99..20b620b202 100644 --- a/Applications/FontEditor/Makefile +++ b/Applications/FontEditor/Makefile @@ -8,11 +8,4 @@ PROGRAM = FontEditor LIB_DEPS = GUI Gfx Core IPC -FontEditor.cpp: UI_FontEditorBottom.h - -UI_FontEditorBottom.h: FontEditorBottom.frm | FORMCOMPILER - $(QUIET) $(FORMCOMPILER) $< > $@ - -EXTRA_CLEAN = UI_FontEditorBottom.h - include ../../Makefile.common diff --git a/Applications/FontEditor/main.cpp b/Applications/FontEditor/main.cpp index 9185733d33..db0a1e138b 100644 --- a/Applications/FontEditor/main.cpp +++ b/Applications/FontEditor/main.cpp @@ -25,11 +25,14 @@ */ #include "FontEditor.h" +#include #include #include #include +#include #include #include +#include #include #include #include @@ -49,30 +52,32 @@ int main(int argc, char** argv) return 1; } - RefPtr edited_font; - String path; + const char* path = nullptr; + Core::ArgsParser args_parser; + args_parser.add_positional_argument(path, "The font file for editing.", "file", Core::ArgsParser::Required::No); + args_parser.parse(argc, argv); - if (argc == 2) { - path = argv[1]; - edited_font = Gfx::Font::load_from_file(path); + RefPtr edited_font; + if (path == nullptr) { + path = "/tmp/saved.font"; + edited_font = Gfx::Font::default_font().clone(); + } else { + edited_font = Gfx::Font::load_from_file(path)->clone(); if (!edited_font) { - fprintf(stderr, "Couldn't load font: %s\n", path.characters()); + String message = String::format("Couldn't load font: %s\n", path); + GUI::MessageBox::show(message, "Font Editor", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK); return 1; } } - if (edited_font) - edited_font = edited_font->clone(); - else - edited_font = Gfx::Font::default_font().clone(); + auto app_icon = GUI::Icon::default_icon("app-font-editor"); auto window = GUI::Window::construct(); - window->set_title("Font Editor"); - window->set_rect({ 50, 50, 390, 342 }); + window->set_title(String::format("%s - Font Editor", path)); + window->set_icon(app_icon.bitmap_for_size(16)); - window->set_main_widget(path, move(edited_font)); - window->show(); - window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png")); + auto& font_editor_widget = window->set_main_widget(path, move(edited_font)); + window->set_rect({ 50, 50, font_editor_widget.preferred_width(), font_editor_widget.preferred_height() }); auto menubar = GUI::MenuBar::construct(); @@ -84,10 +89,12 @@ int main(int argc, char** argv) auto& help_menu = menubar->add_menu("Help"); help_menu.add_action(GUI::Action::create("About", [&](const GUI::Action&) { - GUI::AboutDialog::show("Font Editor", Gfx::Bitmap::load_from_file("/res/icons/FontEditor.png"), window); + GUI::AboutDialog::show("Font Editor", app_icon.bitmap_for_size(32), window); })); app.set_menubar(move(menubar)); + window->show(); + return app.exec(); }