diff options
-rw-r--r-- | FontEditor/FontEditor.cpp | 20 | ||||
-rw-r--r-- | FontEditor/FontEditor.h | 4 | ||||
-rw-r--r-- | FontEditor/main.cpp | 20 |
3 files changed, 34 insertions, 10 deletions
diff --git a/FontEditor/FontEditor.cpp b/FontEditor/FontEditor.cpp index 879fabb56b..ebf01b140b 100644 --- a/FontEditor/FontEditor.cpp +++ b/FontEditor/FontEditor.cpp @@ -4,14 +4,14 @@ #include <LibGUI/GLabel.h> #include <LibGUI/GTextBox.h> -FontEditorWidget::FontEditorWidget(GWidget* parent) +FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_font, GWidget* parent) : GWidget(parent) + , m_edited_font(move(edited_font)) { - m_edited_font = Font::load_from_file("/saved.font"); - if (m_edited_font) - m_edited_font = m_edited_font->clone(); + if (path.is_empty()) + m_path = "/saved.font"; else - m_edited_font = Font::default_font().clone(); + m_path = path; m_glyph_map_widget = new GlyphMapWidget(*m_edited_font, this); m_glyph_map_widget->move_to({ 90, 5 }); @@ -30,7 +30,15 @@ FontEditorWidget::FontEditorWidget(GWidget* parent) save_button->set_caption("Save"); save_button->set_relative_rect({ 5, 170, 100, 20 }); save_button->on_click = [this] (GButton&) { - m_edited_font->write_to_file("/saved.font"); + dbgprintf("write to file: '%s'\n", m_path.characters()); + m_edited_font->write_to_file(m_path); + }; + + auto* quit_button = new GButton(this); + quit_button->set_caption("Quit"); + quit_button->set_relative_rect({ 110, 170, 100, 20 }); + quit_button->on_click = [] (GButton&) { + exit(0); }; auto* info_label = new GLabel(this); diff --git a/FontEditor/FontEditor.h b/FontEditor/FontEditor.h index aa2408d5c6..d44c7e698c 100644 --- a/FontEditor/FontEditor.h +++ b/FontEditor/FontEditor.h @@ -9,7 +9,7 @@ class GTextBox; class FontEditorWidget final : public GWidget { public: - FontEditorWidget(GWidget* parent = nullptr); + FontEditorWidget(const String& path, RetainPtr<Font>&&, GWidget* parent = nullptr); virtual ~FontEditorWidget() override; private: @@ -18,6 +18,8 @@ private: GlyphMapWidget* m_glyph_map_widget { nullptr }; GlyphEditorWidget* m_glyph_editor_widget { nullptr }; GTextBox* m_name_textbox { nullptr }; + + String m_path; }; class GlyphMapWidget final : public GWidget { diff --git a/FontEditor/main.cpp b/FontEditor/main.cpp index e66bd80eec..84fc36977c 100644 --- a/FontEditor/main.cpp +++ b/FontEditor/main.cpp @@ -5,14 +5,28 @@ int main(int argc, char** argv) { - (void) argc; - (void) argv; + RetainPtr<Font> edited_font; + String path; + + if (argc == 2) { + path = argv[1]; + edited_font = Font::load_from_file(path); + if (!edited_font) { + fprintf(stderr, "Couldn't load font: %s\n", path.characters()); + return 1; + } + } + + if (edited_font) + edited_font = edited_font->clone(); + else + edited_font = Font::default_font().clone(); GEventLoop loop; auto* window = new GWindow; window->set_title("FontEditor"); window->set_rect({ 50, 50, 420, 200 }); - auto* font_editor = new FontEditorWidget; + auto* font_editor = new FontEditorWidget(path, move(edited_font)); font_editor->set_relative_rect({ 0, 0, 420, 200 }); window->set_main_widget(font_editor); window->show(); |