1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:18:12 +00:00

FontEditor: Convert to GML and add new edit commands to GlyphEditor

Adds cut, copy, paste and delete to GlyphEditor. Font preview has
moved to a separate resizable ToolWindow. Font metadata can now be
hidden. FontEditor and glyph widgets can now be re-initialized
instead of resetting window's main widget after loading new fonts.
This commit is contained in:
thankyouverycool 2021-04-06 12:04:21 -04:00 committed by Andreas Kling
parent d115b29a5b
commit bb9cd13a56
7 changed files with 477 additions and 241 deletions

View file

@ -29,16 +29,21 @@
#include <LibGfx/BitmapFont.h>
#include <LibGfx/Palette.h>
GlyphEditorWidget::GlyphEditorWidget(Gfx::BitmapFont& mutable_font)
: m_font(mutable_font)
{
set_relative_rect({ 0, 0, preferred_width(), preferred_height() });
}
GlyphEditorWidget::~GlyphEditorWidget()
{
}
void GlyphEditorWidget::initialize(Gfx::BitmapFont& mutable_font)
{
if (m_font == mutable_font)
return;
m_font = mutable_font;
set_relative_rect({ 0, 0, preferred_width(), preferred_height() });
m_clipboard_font = m_font->clone();
m_clipboard_glyph = m_clipboard_font->glyph(0).glyph_bitmap();
clear_clipboard_glyph();
}
void GlyphEditorWidget::set_glyph(int glyph)
{
if (m_glyph == glyph)
@ -47,6 +52,50 @@ void GlyphEditorWidget::set_glyph(int glyph)
update();
}
void GlyphEditorWidget::delete_glyph()
{
auto bitmap = font().glyph(m_glyph).glyph_bitmap();
for (int x = 0; x < bitmap.width(); x++)
for (int y = 0; y < bitmap.height(); y++)
bitmap.set_bit_at(x, y, false);
if (on_glyph_altered)
on_glyph_altered(m_glyph);
update();
}
void GlyphEditorWidget::cut_glyph()
{
copy_glyph();
delete_glyph();
}
void GlyphEditorWidget::copy_glyph()
{
clear_clipboard_glyph();
auto bitmap = font().glyph(m_glyph).glyph_bitmap();
for (int x = 0; x < bitmap.width(); x++)
for (int y = 0; y < bitmap.height(); y++)
m_clipboard_glyph.set_bit_at(x, y, bitmap.bit_at(x, y));
}
void GlyphEditorWidget::paste_glyph()
{
auto bitmap = font().glyph(m_glyph).glyph_bitmap();
for (int x = 0; x < bitmap.width(); x++)
for (int y = 0; y < bitmap.height(); y++)
bitmap.set_bit_at(x, y, m_clipboard_glyph.bit_at(x, y));
if (on_glyph_altered)
on_glyph_altered(m_glyph);
update();
}
void GlyphEditorWidget::clear_clipboard_glyph()
{
for (int x = 0; x < m_clipboard_glyph.width(); x++)
for (int y = 0; y < m_clipboard_glyph.height(); y++)
m_clipboard_glyph.set_bit_at(x, y, false);
}
void GlyphEditorWidget::paint_event(GUI::PaintEvent& event)
{
GUI::Frame::paint_event(event);