mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 08:58:11 +00:00
FontEditor: Allow specifying which font to edit on the command line.
Also add a quit button. The quit button has a tendency to freeze the kernel. That doesn't seem entirely right.
This commit is contained in:
parent
d459525725
commit
af21a45b1a
3 changed files with 34 additions and 10 deletions
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue