diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp index 44f61dd5c8..7419cad052 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.cpp +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.cpp @@ -157,11 +157,23 @@ void GlyphEditorWidget::paint_event(GUI::PaintEvent& event) } } +bool GlyphEditorWidget::is_glyph_empty() +{ + auto bitmap = font().glyph(m_glyph).glyph_bitmap(); + for (int x = 0; x < bitmap.width(); x++) + for (int y = 0; y < bitmap.height(); y++) + if (bitmap.bit_at(x, y)) + return false; + return true; +} + void GlyphEditorWidget::mousedown_event(GUI::MouseEvent& event) { - if (!(font().raw_glyph_width(m_glyph) > 0)) + if ((event.x() - 1) / m_scale + 1 > font().raw_glyph_width(m_glyph)) return; - + if (mode() == Move && is_glyph_empty()) + return; + m_is_clicking_valid_cell = true; if (on_undo_event) on_undo_event(false); if (mode() == Paint) { @@ -180,13 +192,16 @@ void GlyphEditorWidget::mousedown_event(GUI::MouseEvent& event) void GlyphEditorWidget::mouseup_event(GUI::MouseEvent&) { + if (!m_is_clicking_valid_cell) + return; + m_is_clicking_valid_cell = false; if (on_undo_event) on_undo_event(true); } void GlyphEditorWidget::mousemove_event(GUI::MouseEvent& event) { - if (!(font().raw_glyph_width(m_glyph) > 0)) + if (!m_is_clicking_valid_cell) return; if (!(event.buttons() & (GUI::MouseButton::Left | GUI::MouseButton::Right))) return; diff --git a/Userland/Applications/FontEditor/GlyphEditorWidget.h b/Userland/Applications/FontEditor/GlyphEditorWidget.h index 2d74f45097..b98e77aefd 100644 --- a/Userland/Applications/FontEditor/GlyphEditorWidget.h +++ b/Userland/Applications/FontEditor/GlyphEditorWidget.h @@ -32,6 +32,7 @@ public: void copy_glyph(); void paste_glyph(); void delete_glyph(); + bool is_glyph_empty(); int preferred_width() const; int preferred_height() const; @@ -64,4 +65,5 @@ private: int m_scale { 10 }; u8 m_movable_bits[s_max_width * 3][s_max_height * 3] = {}; Mode m_mode { Paint }; + bool m_is_clicking_valid_cell { false }; };