mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:17:44 +00:00
FontEditor: Add move glyph tool
When toggled on, glyphs can now be repositioned within the glyph editor by dragging the mouse
This commit is contained in:
parent
44cd121e30
commit
bada590b91
5 changed files with 101 additions and 8 deletions
|
@ -11,6 +11,9 @@
|
|||
#include <LibGfx/BitmapFont.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
|
||||
static int x_offset;
|
||||
static int y_offset;
|
||||
|
||||
GlyphEditorWidget::~GlyphEditorWidget()
|
||||
{
|
||||
}
|
||||
|
@ -153,13 +156,49 @@ void GlyphEditorWidget::paint_event(GUI::PaintEvent& event)
|
|||
|
||||
void GlyphEditorWidget::mousedown_event(GUI::MouseEvent& event)
|
||||
{
|
||||
draw_at_mouse(event);
|
||||
if (!(font().raw_glyph_width(m_glyph) > 0))
|
||||
return;
|
||||
|
||||
if (on_undo_event)
|
||||
on_undo_event(false);
|
||||
if (mode() == Paint) {
|
||||
draw_at_mouse(event);
|
||||
} else {
|
||||
memset(m_movable_bits, 0, sizeof(m_movable_bits));
|
||||
auto bitmap = font().glyph(m_glyph).glyph_bitmap();
|
||||
for (int x = s_max_width; x < s_max_width + bitmap.width(); x++)
|
||||
for (int y = s_max_height; y < s_max_height + bitmap.height(); y++)
|
||||
m_movable_bits[x][y] = bitmap.bit_at(x - s_max_width, y - s_max_height);
|
||||
x_offset = (event.x() - 1) / m_scale;
|
||||
y_offset = (event.y() - 1) / m_scale;
|
||||
move_at_mouse(event);
|
||||
}
|
||||
}
|
||||
|
||||
void GlyphEditorWidget::mouseup_event(GUI::MouseEvent&)
|
||||
{
|
||||
if (on_undo_event)
|
||||
on_undo_event(true);
|
||||
}
|
||||
|
||||
void GlyphEditorWidget::mousemove_event(GUI::MouseEvent& event)
|
||||
{
|
||||
if (event.buttons() & (GUI::MouseButton::Left | GUI::MouseButton::Right))
|
||||
if (!(font().raw_glyph_width(m_glyph) > 0))
|
||||
return;
|
||||
if (!(event.buttons() & (GUI::MouseButton::Left | GUI::MouseButton::Right)))
|
||||
return;
|
||||
if (mode() == Paint)
|
||||
draw_at_mouse(event);
|
||||
else
|
||||
move_at_mouse(event);
|
||||
}
|
||||
|
||||
void GlyphEditorWidget::enter_event(Core::Event&)
|
||||
{
|
||||
if (mode() == Move)
|
||||
set_override_cursor(Gfx::StandardCursor::Move);
|
||||
else
|
||||
set_override_cursor(Gfx::StandardCursor::None);
|
||||
}
|
||||
|
||||
void GlyphEditorWidget::draw_at_mouse(const GUI::MouseEvent& event)
|
||||
|
@ -183,6 +222,23 @@ void GlyphEditorWidget::draw_at_mouse(const GUI::MouseEvent& event)
|
|||
update();
|
||||
}
|
||||
|
||||
void GlyphEditorWidget::move_at_mouse(const GUI::MouseEvent& event)
|
||||
{
|
||||
int x_delta = ((event.x() - 1) / m_scale) - x_offset;
|
||||
int y_delta = ((event.y() - 1) / m_scale) - y_offset;
|
||||
auto bitmap = font().glyph(m_glyph).glyph_bitmap();
|
||||
if (abs(x_delta) > bitmap.width() || abs(y_delta) > bitmap.height())
|
||||
return;
|
||||
for (int x = 0; x < bitmap.width(); x++) {
|
||||
for (int y = 0; y < bitmap.height(); y++) {
|
||||
bitmap.set_bit_at(x, y, m_movable_bits[s_max_width + x - x_delta][s_max_height + y - y_delta]);
|
||||
}
|
||||
}
|
||||
if (on_glyph_altered)
|
||||
on_glyph_altered(m_glyph);
|
||||
update();
|
||||
}
|
||||
|
||||
int GlyphEditorWidget::preferred_width() const
|
||||
{
|
||||
return frame_thickness() * 2 + font().max_glyph_width() * m_scale - 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue