From da1b7097c68717b4c44aefe80d70e42f24932f28 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 24 Aug 2014 20:18:32 -0300 Subject: [PATCH] Clear background layer too in "New Empty Frame" --- src/app/commands/cmd_new_frame.cpp | 4 +++- src/app/document_api.cpp | 17 +++++++++++++++-- src/app/document_api.h | 3 ++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/app/commands/cmd_new_frame.cpp b/src/app/commands/cmd_new_frame.cpp index 4e9f5ae5d..b116d0644 100644 --- a/src/app/commands/cmd_new_frame.cpp +++ b/src/app/commands/cmd_new_frame.cpp @@ -91,7 +91,9 @@ void NewFrameCommand::onExecute(Context* context) document->getApi().addFrame(sprite, writer.frame().next()); break; case Content::EmptyFrame: - document->getApi().addEmptyFrame(sprite, writer.frame().next()); + document->getApi().addEmptyFrame(sprite, + writer.frame().next(), + app_get_color_to_clear_layer(writer.layer())); break; } undoTransaction.commit(); diff --git a/src/app/document_api.cpp b/src/app/document_api.cpp index ced0e681c..bae8f932c 100644 --- a/src/app/document_api.cpp +++ b/src/app/document_api.cpp @@ -245,7 +245,7 @@ void DocumentApi::addFrame(Sprite* sprite, FrameNumber newFrame) copyFrame(sprite, newFrame.previous(), newFrame); } -void DocumentApi::addEmptyFrame(Sprite* sprite, FrameNumber newFrame) +void DocumentApi::addEmptyFrame(Sprite* sprite, FrameNumber newFrame, color_t bgcolor) { // Add the frame in the sprite structure, it adjusts the total // number of frames in the sprite. @@ -261,7 +261,9 @@ void DocumentApi::addEmptyFrame(Sprite* sprite, FrameNumber newFrame) Layer* bgLayer = sprite->backgroundLayer(); if (bgLayer) { LayerImage* imglayer = static_cast(bgLayer); - copyCel(imglayer, FrameNumber(0), imglayer, newFrame, 0); + Image* bgimage = Image::create(sprite->pixelFormat(), sprite->width(), sprite->height()); + clear_image(bgimage, bgcolor); + addImage(imglayer, newFrame, bgimage); } // Notify observers about the new frame. @@ -1140,6 +1142,17 @@ int DocumentApi::addImageInStock(Sprite* sprite, Image* image) return imageIndex; } +Cel* DocumentApi::addImage(LayerImage* layer, FrameNumber frameNumber, Image* image) +{ + int imageIndex = addImageInStock(layer->sprite(), image); + base::UniquePtr cel(new Cel(frameNumber, imageIndex)); + + addCel(layer, cel); + cel.release(); + + return cel; +} + // Removes and destroys the specified image in the stock. void DocumentApi::removeImageFromStock(Sprite* sprite, int imageIndex) { diff --git a/src/app/document_api.h b/src/app/document_api.h index 1a93d8a6d..5e8774194 100644 --- a/src/app/document_api.h +++ b/src/app/document_api.h @@ -69,7 +69,7 @@ namespace app { // Frames API void addFrame(Sprite* sprite, FrameNumber newFrame); - void addEmptyFrame(Sprite* sprite, FrameNumber newFrame); + void addEmptyFrame(Sprite* sprite, FrameNumber newFrame, color_t bgcolor); void copyFrame(Sprite* sprite, FrameNumber fromFrame, FrameNumber newFrame); void removeFrame(Sprite* sprite, FrameNumber frame); void setTotalFrames(Sprite* sprite, FrameNumber frames); @@ -106,6 +106,7 @@ namespace app { void duplicateLayerBefore(Layer* sourceLayer, Layer* beforeLayer); // Images stock API + Cel* addImage(LayerImage* layer, FrameNumber frameNumber, Image* image); int addImageInStock(Sprite* sprite, Image* image); void removeImageFromStock(Sprite* sprite, int imageIndex); void replaceStockImage(Sprite* sprite, int imageIndex, Image* newImage);