Add SetGridBounds::setGrid() to avoid some duplicated code

This commit is contained in:
David Capello 2021-08-30 10:52:40 -03:00
parent f85f24e847
commit 1f6c6951af
2 changed files with 12 additions and 8 deletions

View File

@ -30,21 +30,23 @@ SetGridBounds::SetGridBounds(Sprite* sprite, const gfx::Rect& bounds)
void SetGridBounds::onExecute()
{
Sprite* spr = sprite();
spr->setGridBounds(m_newBounds);
Doc* doc = static_cast<Doc*>(spr->document());
auto& docPref = Preferences::instance().document(doc);
docPref.grid.bounds(m_newBounds);
spr->incrementVersion();
setGrid(m_newBounds);
}
void SetGridBounds::onUndo()
{
setGrid(m_oldBounds);
}
void SetGridBounds::setGrid(const gfx::Rect& grid)
{
Sprite* spr = sprite();
spr->setGridBounds(m_oldBounds);
spr->setGridBounds(grid);
Doc* doc = static_cast<Doc*>(spr->document());
auto& docPref = Preferences::instance().document(doc);
docPref.grid.bounds(m_oldBounds);
docPref.grid.bounds(grid);
spr->incrementVersion();
}

View File

@ -33,6 +33,8 @@ namespace cmd {
}
private:
void setGrid(const gfx::Rect& grid);
gfx::Rect m_oldBounds;
gfx::Rect m_newBounds;
};