diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index 22187a022..04024ff87 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -210,6 +210,7 @@ Editor::Editor(Document* document, EditorFlags flags) setLayer(layers[layerIndex]); } + m_tiledConnBefore = m_docPref.tiled.BeforeChange.connect(base::Bind(&Editor::onTiledModeBeforeChange, this)); m_tiledConn = m_docPref.tiled.AfterChange.connect(base::Bind(&Editor::onTiledModeChange, this)); m_gridConn = m_docPref.grid.AfterChange.connect(base::Bind(&Editor::invalidate, this)); m_pixelGridConn = m_docPref.pixelGrid.AfterChange.connect(base::Bind(&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() diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h index a9b9222c6..644fce3ad 100644 --- a/src/app/ui/editor/editor.h +++ b/src/app/ui/editor/editor.h @@ -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