mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
FontEditor: Restore selections on undo/redo actions
This makes navigating undo history a lot easier to follow. Individual glyph alterations now reset selection size if necessary to save space.
This commit is contained in:
parent
df443863bd
commit
212817ea20
3 changed files with 60 additions and 19 deletions
|
@ -12,15 +12,16 @@
|
|||
|
||||
class UndoSelection : public RefCounted<UndoSelection> {
|
||||
public:
|
||||
explicit UndoSelection(int const start, int const size, Gfx::BitmapFont const& font)
|
||||
explicit UndoSelection(int const start, int const size, u32 const active_glyph, Gfx::BitmapFont const& font)
|
||||
: m_start(start)
|
||||
, m_size(size)
|
||||
, m_active_glyph(active_glyph)
|
||||
, m_font(font)
|
||||
{
|
||||
}
|
||||
NonnullRefPtr<UndoSelection> save_state()
|
||||
{
|
||||
auto state = adopt_ref(*new UndoSelection(m_start, m_size, *m_font));
|
||||
auto state = adopt_ref(*new UndoSelection(m_start, m_size, m_active_glyph, *m_font));
|
||||
size_t bytes_per_glyph = Gfx::GlyphBitmap::bytes_per_row() * font().glyph_height();
|
||||
auto* rows = font().rows() + m_start * bytes_per_glyph;
|
||||
auto* widths = font().widths() + m_start;
|
||||
|
@ -35,19 +36,27 @@ public:
|
|||
auto* widths = font().widths() + state.m_start;
|
||||
memcpy(rows, &state.m_data[0], bytes_per_glyph * state.m_size);
|
||||
memcpy(widths, &state.m_data[bytes_per_glyph * state.m_size], state.m_size);
|
||||
m_previous_active_glyph = state.m_start;
|
||||
m_restored_active_glyph = state.m_active_glyph;
|
||||
m_restored_start = state.m_start;
|
||||
m_restored_size = state.m_size;
|
||||
}
|
||||
void set_start(int start) { m_start = start; }
|
||||
void set_size(int size) { m_size = size; }
|
||||
void set_active_glyph(u32 code_point) { m_active_glyph = code_point; }
|
||||
Gfx::BitmapFont& font() { return *m_font; }
|
||||
u32 previous_active_glyph() const { return m_previous_active_glyph; }
|
||||
u32 restored_active_glyph() const { return m_restored_active_glyph; }
|
||||
int restored_start() const { return m_restored_start; }
|
||||
int restored_size() const { return m_restored_size; }
|
||||
|
||||
private:
|
||||
int m_start { 0 };
|
||||
int m_size { 0 };
|
||||
u32 m_active_glyph { 0 };
|
||||
int m_restored_start { 0 };
|
||||
int m_restored_size { 0 };
|
||||
u32 m_restored_active_glyph { 0 };
|
||||
RefPtr<Gfx::BitmapFont> m_font;
|
||||
ByteBuffer m_data;
|
||||
u32 m_previous_active_glyph { 0 };
|
||||
};
|
||||
|
||||
class SelectionUndoCommand : public GUI::Command {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue