mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:08:13 +00:00
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.
This commit is contained in:
parent
e68a08ad7c
commit
3874664752
9 changed files with 243 additions and 88 deletions
|
@ -25,11 +25,14 @@
|
|||
*/
|
||||
|
||||
#include "FontEditor.h"
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibGUI/AboutDialog.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/Application.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/Font.h>
|
||||
|
@ -49,30 +52,32 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Font> 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<Gfx::Font> 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<FontEditorWidget>(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<FontEditorWidget>(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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue