From ccf563c4dd8ceb9214be1c739155bbf6f1a7c7fb Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 8 Nov 2014 17:03:29 -0300 Subject: [PATCH] Fix mini editor animation playback when we're drawing (inside a ToolLoop) We've to show the document's extra cel only if we are in the current layer and frame. --- src/app/commands/filters/filter_manager_impl.h | 1 + src/app/commands/filters/filter_preview.cpp | 3 ++- src/app/tools/tool_loop.h | 4 ++++ src/app/tools/tool_loop_manager.cpp | 3 ++- src/app/ui/editor/editor.cpp | 2 ++ src/app/ui/editor/tool_loop_impl.cpp | 1 + src/app/util/render.cpp | 13 ++++++++----- src/app/util/render.h | 2 +- 8 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/app/commands/filters/filter_manager_impl.h b/src/app/commands/filters/filter_manager_impl.h index cc689d807..587744996 100644 --- a/src/app/commands/filters/filter_manager_impl.h +++ b/src/app/commands/filters/filter_manager_impl.h @@ -95,6 +95,7 @@ namespace app { Document* document() { return m_location.document(); } Sprite* sprite() { return m_location.sprite(); } Layer* layer() { return m_location.layer(); } + FrameNumber frame() { return m_location.frame(); } Image* destinationImage() const { return m_dst; } // Updates the current editor to show the progress of the preview. diff --git a/src/app/commands/filters/filter_preview.cpp b/src/app/commands/filters/filter_preview.cpp index 40a767c81..154d79f9b 100644 --- a/src/app/commands/filters/filter_preview.cpp +++ b/src/app/commands/filters/filter_preview.cpp @@ -77,11 +77,12 @@ bool FilterPreview::onProcessMessage(Message* msg) case kOpenMessage: RenderEngine::setPreviewImage( m_filterMgr->layer(), + m_filterMgr->frame(), m_filterMgr->destinationImage()); break; case kCloseMessage: - RenderEngine::setPreviewImage(NULL, NULL); + RenderEngine::setPreviewImage(NULL, FrameNumber(0), NULL); // Stop the preview timer. m_timer.stop(); diff --git a/src/app/tools/tool_loop.h b/src/app/tools/tool_loop.h index 64501792c..823a071ac 100644 --- a/src/app/tools/tool_loop.h +++ b/src/app/tools/tool_loop.h @@ -24,6 +24,7 @@ #include "app/tools/trace_policy.h" #include "filters/tiled_mode.h" #include "gfx/point.h" +#include "raster/frame_number.h" namespace gfx { class Region; @@ -82,6 +83,9 @@ namespace app { // Returns the layer that will be modified if the tool paints virtual Layer* getLayer() = 0; + // Returns the frame where we're paiting + virtual FrameNumber getFrame() = 0; + // Should return an image where we can read pixels (readonly image) virtual Image* getSrcImage() = 0; diff --git a/src/app/tools/tool_loop_manager.cpp b/src/app/tools/tool_loop_manager.cpp index e572eb775..2d21f6b10 100644 --- a/src/app/tools/tool_loop_manager.cpp +++ b/src/app/tools/tool_loop_manager.cpp @@ -74,13 +74,14 @@ void ToolLoopManager::prepareLoop(const Pointer& pointer) // in the tool-loop time, so we can see what we are drawing) RenderEngine::setPreviewImage( m_toolLoop->getLayer(), + m_toolLoop->getFrame(), m_toolLoop->getDstImage()); } void ToolLoopManager::releaseLoop(const Pointer& pointer) { // No more preview image - RenderEngine::setPreviewImage(NULL, NULL); + RenderEngine::setPreviewImage(NULL, FrameNumber(0), NULL); } void ToolLoopManager::pressKey(ui::KeyScancode key) diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index f1be12a63..f074af76a 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -684,6 +684,8 @@ void Editor::flashCurrentLayer() int x, y; const Image* src_image = loc.image(&x, &y); if (src_image) { + RenderEngine::setPreviewImage(NULL, FrameNumber(0), NULL); + m_document->prepareExtraCel(0, 0, m_sprite->width(), m_sprite->height(), 255); Image* flash_image = m_document->getExtraCelImage(); diff --git a/src/app/ui/editor/tool_loop_impl.cpp b/src/app/ui/editor/tool_loop_impl.cpp index 18f78ebec..daab39302 100644 --- a/src/app/ui/editor/tool_loop_impl.cpp +++ b/src/app/ui/editor/tool_loop_impl.cpp @@ -216,6 +216,7 @@ public: Document* getDocument() override { return m_document; } Sprite* sprite() override { return m_sprite; } Layer* getLayer() override { return m_layer; } + FrameNumber getFrame() override { return m_frame; } Image* getSrcImage() override { return m_expandCelCanvas.getSourceCanvas(); } Image* getDstImage() override { return m_expandCelCanvas.getDestCanvas(); } RgbMap* getRgbMap() override { return m_sprite->getRgbMap(m_frame); } diff --git a/src/app/util/render.cpp b/src/app/util/render.cpp index 4ee2633cb..b46b7cba0 100644 --- a/src/app/util/render.cpp +++ b/src/app/util/render.cpp @@ -289,6 +289,7 @@ static app::Color checked_bg_color2; static int global_opacity = 255; static const Layer* selected_layer = NULL; +static FrameNumber selected_frame(0); static Image* preview_image = NULL; // static @@ -367,9 +368,10 @@ RenderEngine::RenderEngine(const Document* document, } // static -void RenderEngine::setPreviewImage(const Layer* layer, Image* image) +void RenderEngine::setPreviewImage(const Layer* layer, FrameNumber frame, Image* image) { selected_layer = layer; + selected_frame = frame; preview_image = image; } @@ -586,8 +588,8 @@ void RenderEngine::renderLayer( Image* src_image; // Is the 'preview_image' set to be used with this layer? - if ((frame == m_currentFrame) && - (selected_layer == layer) && + if ((selected_layer == layer) && + (selected_frame == frame) && (preview_image != NULL)) { src_image = preview_image; } @@ -635,8 +637,9 @@ void RenderEngine::renderLayer( } // Draw extras - if (layer == m_currentLayer && - m_document->getExtraCel() != NULL) { + if (m_document->getExtraCel() && + layer == m_currentLayer && + frame == m_currentFrame) { Cel* extraCel = m_document->getExtraCel(); if (extraCel->opacity() > 0) { Image* extraImage = m_document->getExtraCelImage(); diff --git a/src/app/util/render.h b/src/app/util/render.h index 7e62807be..f946cc574 100644 --- a/src/app/util/render.h +++ b/src/app/util/render.h @@ -63,7 +63,7 @@ namespace app { ////////////////////////////////////////////////////////////////////// // Preview image - static void setPreviewImage(const Layer* layer, Image* drawable); + static void setPreviewImage(const Layer* layer, FrameNumber frame, Image* drawable); ////////////////////////////////////////////////////////////////////// // Main function used by sprite-editors to render the sprite