1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:57:45 +00:00

Start working on a simple graphical font editor.

Editing fonts by editing text files is really slow and boring.
A simple font editor seems like a good way to take LibGUI for a spin.
This commit is contained in:
Andreas Kling 2019-02-02 08:05:14 +01:00
parent 5e0b7f1a56
commit 6fc3c38324
18 changed files with 390 additions and 19 deletions

77
FontEditor/FontEditor.h Normal file
View file

@ -0,0 +1,77 @@
#pragma once
#include <LibGUI/GWidget.h>
#include <AK/Function.h>
class GlyphEditorWidget;
class GlyphMapWidget;
class FontEditorWidget final : public GWidget {
public:
FontEditorWidget(GWidget* parent = nullptr);
virtual ~FontEditorWidget() override;
private:
GlyphMapWidget* m_glyph_map_widget { nullptr };
GlyphEditorWidget* m_glyph_editor_widget { nullptr };
};
class GlyphMapWidget final : public GWidget {
public:
GlyphMapWidget(Font&, GWidget* parent);
virtual ~GlyphMapWidget() override;
byte selected_glyph() const { return m_selected_glyph; }
void set_selected_glyph(byte);
int rows() const { return m_rows; }
int columns() const { return 256 / m_rows; }
int preferred_width() const;
int preferred_height() const;
Font& font() { return *m_font; }
const Font& font() const { return *m_font; }
Function<void(byte)> on_glyph_selected;
private:
virtual void paint_event(GPaintEvent&) override;
virtual void mousedown_event(GMouseEvent&) override;
Rect get_outer_rect(byte glyph) const;
RetainPtr<Font> m_font;
int m_rows { 8 };
int m_horizontal_spacing { 2 };
int m_vertical_spacing { 2 };
byte m_selected_glyph { 0 };
};
class GlyphEditorWidget final : public GWidget {
public:
GlyphEditorWidget(Font&, GWidget* parent);
virtual ~GlyphEditorWidget() override;
byte glyph() const { return m_glyph; }
void set_glyph(byte);
int preferred_width() const;
int preferred_height() const;
Font& font() { return *m_font; }
const Font& font() const { return *m_font; }
Function<void()> on_glyph_altered;
private:
virtual void paint_event(GPaintEvent&) override;
virtual void mousedown_event(GMouseEvent&) override;
virtual void mousemove_event(GMouseEvent&) override;
void draw_at_mouse(const GMouseEvent&);
RetainPtr<Font> m_font;
byte m_glyph { 0 };
int m_scale { 10 };
};