Clear background layer too in "New Empty Frame"

This commit is contained in:
David Capello 2014-08-24 20:18:32 -03:00
parent 6b2c5cc386
commit da1b7097c6
3 changed files with 20 additions and 4 deletions

View File

@ -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();

View File

@ -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<LayerImage*>(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> 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)
{

View File

@ -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);