From 18db7513a8f1368c9f171b68086bb9a38eb2a35f Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 23 Jan 2011 21:15:00 -0300 Subject: [PATCH] Open new sprites in the center of the current sprite. --- TODO.txt | 1 - src/raster/sprite.cpp | 1 + src/raster/sprite.h | 1 + src/widgets/editor/editor.cpp | 14 ++++++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/TODO.txt b/TODO.txt index ef6988e5d..cafd28906 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,7 +1,6 @@ For next release ---------------- -+ After creating or opening a sprite, it should be shown centered in the editor. + Mini-look for sliders in palette editor (add ISliderBackground to draw RGB/HSV sliders with a customized background). + Fix palette editor to avoid generating a lot of consecutive Undo actions. diff --git a/src/raster/sprite.cpp b/src/raster/sprite.cpp index 772b3ade2..4ea6bca39 100644 --- a/src/raster/sprite.cpp +++ b/src/raster/sprite.cpp @@ -425,6 +425,7 @@ SpriteImpl::SpriteImpl(Sprite* sprite, int imgtype, int width, int height, int n m_preferred.scroll_x = 0; m_preferred.scroll_y = 0; m_preferred.zoom = 0; + m_preferred.virgin = true; // Generate palette Palette pal(0, ncolors); diff --git a/src/raster/sprite.h b/src/raster/sprite.h index be620ab99..dae2dad2c 100644 --- a/src/raster/sprite.h +++ b/src/raster/sprite.h @@ -41,6 +41,7 @@ struct PreferredEditorSettings int scroll_x; int scroll_y; int zoom; + bool virgin; }; typedef std::vector PalettesList; diff --git a/src/widgets/editor/editor.cpp b/src/widgets/editor/editor.cpp index 83481b604..394d7e7d5 100644 --- a/src/widgets/editor/editor.cpp +++ b/src/widgets/editor/editor.cpp @@ -159,6 +159,20 @@ void Editor::editor_set_sprite(Sprite* sprite) m_zoom = preferred.zoom; editor_update(); + + if (preferred.virgin) { + JWidget view = jwidget_get_view(this); + JRect vp = jview_get_viewport_position(view); + + preferred.virgin = false; + preferred.scroll_x = -jrect_w(vp)/2 + (sprite->getWidth()/2); + preferred.scroll_y = -jrect_h(vp)/2 + (sprite->getHeight()/2); + + m_sprite->setPreferredEditorSettings(preferred); + + jrect_free(vp); + } + editor_set_scroll(m_offset_x + preferred.scroll_x, m_offset_y + preferred.scroll_y, false);