mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:07:44 +00:00
FontEditor: Don't put invalid clicks on the undo stack
This commit is contained in:
parent
8febfb169d
commit
ed634a4582
2 changed files with 20 additions and 3 deletions
|
@ -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;
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue