summaryrefslogtreecommitdiff
path: root/Userland/Applications/FontEditor/main.cpp
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2021-04-10 13:40:59 -0400
committerAndreas Kling <kling@serenityos.org>2021-04-11 01:16:34 +0200
commitcdfa2614b958b4e70987cbb3e4c51136f60f70d9 (patch)
tree4f611324036dc4715dc099f52c338dc98159a175 /Userland/Applications/FontEditor/main.cpp
parentc283429196502ba011c4bb9c469146666ff65f81 (diff)
downloadserenity-cdfa2614b958b4e70987cbb3e4c51136f60f70d9.zip
FontEditor: Move menu bar into editor and tweak several widgets
Actions are now shared between menu bar and toolbar. Adds an edit menu to complement toolbar actions. Glyphs are now passed as ints instead of u8s; fixes Latin Extended+ glyphs failing to update in real time on map. Converts weight and type to more human-readable combo box lists. Selected glyph now scrolls into view on load.
Diffstat (limited to 'Userland/Applications/FontEditor/main.cpp')
-rw-r--r--Userland/Applications/FontEditor/main.cpp77
1 files changed, 3 insertions, 74 deletions
diff --git a/Userland/Applications/FontEditor/main.cpp b/Userland/Applications/FontEditor/main.cpp
index 6f3e8a0973..0f1dde82f7 100644
--- a/Userland/Applications/FontEditor/main.cpp
+++ b/Userland/Applications/FontEditor/main.cpp
@@ -28,18 +28,13 @@
#include <AK/URL.h>
#include <LibCore/ArgsParser.h>
#include <LibDesktop/Launcher.h>
-#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
-#include <LibGUI/FilePicker.h>
#include <LibGUI/Icon.h>
-#include <LibGUI/Menu.h>
#include <LibGUI/MenuBar.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Window.h>
-#include <LibGfx/Bitmap.h>
#include <LibGfx/BitmapFont.h>
#include <LibGfx/FontDatabase.h>
-#include <LibGfx/Point.h>
#include <stdio.h>
#include <unistd.h>
@@ -99,80 +94,14 @@ int main(int argc, char** argv)
auto window = GUI::Window::construct();
window->set_icon(app_icon.bitmap_for_size(16));
window->resize(440, 470);
- window->set_main_widget<FontEditorWidget>(path, move(edited_font));
window->set_title(String::formatted("{} - Font Editor", path));
- auto set_edited_font = [&](const String& path, RefPtr<Gfx::BitmapFont>&& font) {
- // Convert 256 char font to 384 char font.
- if (font->type() == Gfx::FontTypes::Default)
- font->set_type(Gfx::FontTypes::LatinExtendedA);
-
- // Convert 384 char font to 1280 char font.
- // Dirty hack. Should be refactored.
- if (font->type() == Gfx::FontTypes::LatinExtendedA)
- font->set_type(Gfx::FontTypes::Cyrillic);
-
- window->set_title(String::formatted("{} - Font Editor", path));
- static_cast<FontEditorWidget*>(window->main_widget())->initialize(path, move(font));
- };
+ auto& font_editor = window->set_main_widget<FontEditorWidget>(path, move(edited_font));
auto menubar = GUI::MenuBar::construct();
-
- auto& app_menu = menubar->add_menu("&File");
- app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
- Optional<String> open_path = GUI::FilePicker::get_open_filepath(window, {}, "/res/fonts/");
- if (!open_path.has_value())
- return;
-
- auto bitmap_font = Gfx::BitmapFont::load_from_file(open_path.value());
- if (!bitmap_font) {
- String message = String::formatted("Couldn't load font: {}\n", open_path.value());
- GUI::MessageBox::show(window, message, "Font Editor", GUI::MessageBox::Type::Error);
- return;
- }
- RefPtr<Gfx::BitmapFont> new_font = static_ptr_cast<Gfx::BitmapFont>(bitmap_font->clone());
- if (!new_font) {
- String message = String::formatted("Couldn't load font: {}\n", open_path.value());
- GUI::MessageBox::show(window, message, "Font Editor", GUI::MessageBox::Type::Error);
- return;
- }
-
- set_edited_font(open_path.value(), move(new_font));
- }));
- app_menu.add_action(GUI::CommonActions::make_save_action([&](auto&) {
- FontEditorWidget* editor = static_cast<FontEditorWidget*>(window->main_widget());
- editor->save_as(editor->path());
- }));
- app_menu.add_action(GUI::CommonActions::make_save_as_action([&](auto&) {
- FontEditorWidget* editor = static_cast<FontEditorWidget*>(window->main_widget());
- LexicalPath lexical_path(editor->path());
- Optional<String> save_path = GUI::FilePicker::get_save_filepath(window, lexical_path.title(), lexical_path.extension());
- if (!save_path.has_value())
- return;
-
- if (editor->save_as(save_path.value()))
- window->set_title(String::formatted("{} - Font Editor", save_path.value()));
- }));
- app_menu.add_separator();
- app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
- app->quit();
- }));
-
- auto& view_menu = menubar->add_menu("&View");
- auto set_font_metadata = GUI::Action::create_checkable("Font &Metadata", { Mod_Ctrl, Key_M }, [&](auto& action) {
- static_cast<FontEditorWidget*>(window->main_widget())->set_show_font_metadata(action.is_checked());
- });
- set_font_metadata->set_checked(true);
- view_menu.add_action(*set_font_metadata);
-
- auto& help_menu = menubar->add_menu("&Help");
- help_menu.add_action(GUI::CommonActions::make_help_action([](auto&) {
- Desktop::Launcher::open(URL::create_with_file_protocol("/usr/share/man/man1/FontEditor.md"), "/bin/Help");
- }));
-
- help_menu.add_action(GUI::CommonActions::make_about_action("Font Editor", app_icon, window));
-
+ font_editor.initialize_menubar(menubar);
window->set_menubar(move(menubar));
+
window->show();
return app->exec();