Adjust scroll correctly when tiled mode is changed

https://community.aseprite.org/t/tile-mode-preview-incorrect/785
This commit is contained in:
David Capello 2017-12-14 09:02:49 -03:00
parent a938fcec7f
commit 355d4b1135
2 changed files with 29 additions and 2 deletions

View File

@ -210,6 +210,7 @@ Editor::Editor(Document* document, EditorFlags flags)
setLayer(layers[layerIndex]);
}
m_tiledConnBefore = m_docPref.tiled.BeforeChange.connect(base::Bind<void>(&Editor::onTiledModeBeforeChange, this));
m_tiledConn = m_docPref.tiled.AfterChange.connect(base::Bind<void>(&Editor::onTiledModeChange, this));
m_gridConn = m_docPref.grid.AfterChange.connect(base::Bind<void>(&Editor::invalidate, this));
m_pixelGridConn = m_docPref.pixelGrid.AfterChange.connect(base::Bind<void>(&Editor::invalidate, this));
@ -1863,11 +1864,31 @@ void Editor::onContextBarBrushChange()
m_brushPreview.redraw();
}
void Editor::onTiledModeBeforeChange()
{
m_oldMainTilePos = mainTilePosition();
}
void Editor::onTiledModeChange()
{
ASSERT(m_sprite);
// Get the sprite point in the middle of the editor, so we can
// restore this with the new tiled mode in the main tile.
View* view = View::getView(this);
gfx::Rect vp = view->viewportBounds();
gfx::Point screenPos(vp.x + vp.w/2,
vp.y + vp.h/2);
gfx::Point spritePos(screenToEditor(screenPos));
spritePos -= m_oldMainTilePos;
// Update padding
m_padding = calcExtraPadding(m_proj);
updateEditor();
invalidate();
spritePos += mainTilePosition();
screenPos = editorToScreen(spritePos);
centerInSpritePoint(spritePos);
}
void Editor::onShowExtrasChange()

View File

@ -279,6 +279,7 @@ namespace app {
void onInvalidateRegion(const gfx::Region& region) override;
void onFgColorChange();
void onContextBarBrushChange();
void onTiledModeBeforeChange();
void onTiledModeChange();
void onShowExtrasChange();
@ -368,6 +369,7 @@ namespace app {
obs::scoped_connection m_showExtrasConn;
// Slots listeing document preferences.
obs::scoped_connection m_tiledConnBefore;
obs::scoped_connection m_tiledConn;
obs::scoped_connection m_gridConn;
obs::scoped_connection m_pixelGridConn;
@ -402,6 +404,10 @@ namespace app {
// focused tag band for each sprite/editor.
int m_tagFocusBand;
// Used to restore scroll when the tiled mode is changed.
// TODO could we avoid one extra field just to do this?
gfx::Point m_oldMainTilePos;
static doc::ImageBufferPtr m_renderBuffer;
// The render engine must be shared between all editors so when a