diff --git a/data/gui.xml b/data/gui.xml index 68d9257f8..6bf250194 100644 --- a/data/gui.xml +++ b/data/gui.xml @@ -630,7 +630,7 @@ - + diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index a3d772f83..5c8c21966 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -21,6 +21,7 @@ add_library(app-lib commands/cmd_change_color.cpp commands/cmd_change_pixel_format.cpp commands/cmd_clear.cpp + commands/cmd_clear_cel.cpp commands/cmd_close_file.cpp commands/cmd_configure_tools.cpp commands/cmd_copy.cpp @@ -67,7 +68,6 @@ add_library(app-lib commands/cmd_play_animation.cpp commands/cmd_preview.cpp commands/cmd_refresh.cpp - commands/cmd_remove_cel.cpp commands/cmd_remove_frame.cpp commands/cmd_remove_layer.cpp commands/cmd_repeat_last_export.cpp diff --git a/src/app/commands/cmd_canvas_size.cpp b/src/app/commands/cmd_canvas_size.cpp index 4c8efddca..8be382179 100644 --- a/src/app/commands/cmd_canvas_size.cpp +++ b/src/app/commands/cmd_canvas_size.cpp @@ -20,7 +20,6 @@ #include "config.h" #endif -#include "app/color_utils.h" #include "app/commands/command.h" #include "app/context_access.h" #include "app/document_api.h" @@ -345,14 +344,8 @@ void CanvasSizeCommand::onExecute(Context* context) Sprite* sprite = writer.sprite(); UndoTransaction undoTransaction(writer.context(), "Canvas Size"); DocumentApi api = document->getApi(); - raster::color_t bgcolor = color_utils::color_for_target( - context->settings()->getBgColor(), - ColorTarget( - ColorTarget::BackgroundLayer, - sprite->pixelFormat(), - sprite->transparentColor())); - api.cropSprite(sprite, gfx::Rect(x1, y1, x2-x1, y2-y1), bgcolor); + api.cropSprite(sprite, gfx::Rect(x1, y1, x2-x1, y2-y1)); undoTransaction.commit(); document->generateMaskBoundaries(); diff --git a/src/app/commands/cmd_clear.cpp b/src/app/commands/cmd_clear.cpp index b5ad918b5..2eb05fccb 100644 --- a/src/app/commands/cmd_clear.cpp +++ b/src/app/commands/cmd_clear.cpp @@ -64,14 +64,14 @@ bool ClearCommand::onEnabled(Context* context) void ClearCommand::onExecute(Context* context) { - // Clear of several frames is handled with RemoveCel command. + // Clear of several frames is handled with ClearCel command. DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range(); if (range.enabled()) { Command* subCommand = NULL; switch (range.type()) { case DocumentRange::kCels: - subCommand = CommandsModule::instance()->getCommandByName(CommandId::RemoveCel); + subCommand = CommandsModule::instance()->getCommandByName(CommandId::ClearCel); break; case DocumentRange::kFrames: subCommand = CommandsModule::instance()->getCommandByName(CommandId::RemoveFrame); diff --git a/src/app/commands/cmd_remove_cel.cpp b/src/app/commands/cmd_clear_cel.cpp similarity index 78% rename from src/app/commands/cmd_remove_cel.cpp rename to src/app/commands/cmd_clear_cel.cpp index 7373554a4..ec9222c06 100644 --- a/src/app/commands/cmd_remove_cel.cpp +++ b/src/app/commands/cmd_clear_cel.cpp @@ -34,24 +34,24 @@ namespace app { -class RemoveCelCommand : public Command { +class ClearCelCommand : public Command { public: - RemoveCelCommand(); - Command* clone() const override { return new RemoveCelCommand(*this); } + ClearCelCommand(); + Command* clone() const override { return new ClearCelCommand(*this); } protected: bool onEnabled(Context* context); void onExecute(Context* context); }; -RemoveCelCommand::RemoveCelCommand() - : Command("RemoveCel", - "Remove Cel", +ClearCelCommand::ClearCelCommand() + : Command("ClearCel", + "Clear Cel", CmdRecordableFlag) { } -bool RemoveCelCommand::onEnabled(Context* context) +bool ClearCelCommand::onEnabled(Context* context) { return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | ContextFlags::ActiveLayerIsReadable | @@ -60,12 +60,12 @@ bool RemoveCelCommand::onEnabled(Context* context) ContextFlags::HasActiveCel); } -void RemoveCelCommand::onExecute(Context* context) +void ClearCelCommand::onExecute(Context* context) { ContextWriter writer(context); Document* document(writer.document()); { - UndoTransaction undoTransaction(writer.context(), "Remove Cel"); + UndoTransaction undoTransaction(writer.context(), "Clear Cel"); // TODO the range of selected frames should be in the DocumentLocation. Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range(); @@ -83,14 +83,12 @@ void RemoveCelCommand::onExecute(Context* context) begin = range.frameBegin().previous(); frame != begin; frame = frame.previous()) { - Cel* cel = layerImage->getCel(frame); - if (cel) - document->getApi().removeCel(layerImage, cel); + document->getApi().clearCel(layerImage, frame); } } } else { - document->getApi().removeCel(static_cast(writer.layer()), writer.cel()); + document->getApi().clearCel(writer.cel()); } undoTransaction.commit(); @@ -98,9 +96,9 @@ void RemoveCelCommand::onExecute(Context* context) update_screen_for_document(document); } -Command* CommandFactory::createRemoveCelCommand() +Command* CommandFactory::createClearCelCommand() { - return new RemoveCelCommand; + return new ClearCelCommand; } } // namespace app diff --git a/src/app/commands/cmd_crop.cpp b/src/app/commands/cmd_crop.cpp index 19584d3a2..41d2f588e 100644 --- a/src/app/commands/cmd_crop.cpp +++ b/src/app/commands/cmd_crop.cpp @@ -20,8 +20,6 @@ #include "config.h" #endif -#include "app/app.h" -#include "app/color_utils.h" #include "app/commands/command.h" #include "app/context_access.h" #include "app/document_api.h" @@ -68,10 +66,7 @@ void CropSpriteCommand::onExecute(Context* context) Mask* mask(document->mask()); { UndoTransaction undoTransaction(writer.context(), "Sprite Crop"); - int bgcolor = color_utils::color_for_image(ColorBar::instance()->getBgColor(), - sprite->pixelFormat()); - - document->getApi().cropSprite(sprite, mask->bounds(), bgcolor); + document->getApi().cropSprite(sprite, mask->bounds()); undoTransaction.commit(); } document->generateMaskBoundaries(); @@ -107,11 +102,8 @@ void AutocropSpriteCommand::onExecute(Context* context) Document* document(writer.document()); Sprite* sprite(writer.sprite()); { - int bgcolor = color_utils::color_for_image(ColorBar::instance()->getBgColor(), - sprite->pixelFormat()); - UndoTransaction undoTransaction(writer.context(), "Trim Sprite"); - document->getApi().trimSprite(sprite, bgcolor); + document->getApi().trimSprite(sprite); undoTransaction.commit(); } document->generateMaskBoundaries(); diff --git a/src/app/commands/cmd_flatten_layers.cpp b/src/app/commands/cmd_flatten_layers.cpp index 2d53c57d8..060975b9d 100644 --- a/src/app/commands/cmd_flatten_layers.cpp +++ b/src/app/commands/cmd_flatten_layers.cpp @@ -20,8 +20,6 @@ #include "config.h" #endif -#include "app/app.h" -#include "app/color_utils.h" #include "app/commands/command.h" #include "app/context_access.h" #include "app/document_api.h" @@ -59,11 +57,9 @@ void FlattenLayersCommand::onExecute(Context* context) ContextWriter writer(context); Document* document = writer.document(); Sprite* sprite = writer.sprite(); - int bgcolor = color_utils::color_for_image(ColorBar::instance()->getBgColor(), - sprite->pixelFormat()); { UndoTransaction undoTransaction(writer.context(), "Flatten Layers"); - document->getApi().flattenLayers(sprite, bgcolor); + document->getApi().flattenLayers(sprite); undoTransaction.commit(); } update_screen_for_document(writer.document()); diff --git a/src/app/commands/cmd_flip.cpp b/src/app/commands/cmd_flip.cpp index 71ab740b6..53cf1699d 100644 --- a/src/app/commands/cmd_flip.cpp +++ b/src/app/commands/cmd_flip.cpp @@ -120,11 +120,9 @@ void FlipCommand::onExecute(Context* context) // If the mask isn't a rectangular area, we've to flip the mask too. if (mask->bitmap() && !mask->isRectangular()) { - raster::color_t bgcolor = app_get_color_to_clear_layer(writer.layer()); - // Flip the portion of image specified by the mask. mask->offsetOrigin(-x, -y); - api.flipImageWithMask(image, mask, m_flipType, bgcolor); + api.flipImageWithMask(writer.layer(), image, mask, m_flipType); mask->offsetOrigin(x, y); alreadyFlipped = true; } diff --git a/src/app/commands/cmd_new_frame.cpp b/src/app/commands/cmd_new_frame.cpp index b116d0644..4e9f5ae5d 100644 --- a/src/app/commands/cmd_new_frame.cpp +++ b/src/app/commands/cmd_new_frame.cpp @@ -91,9 +91,7 @@ void NewFrameCommand::onExecute(Context* context) document->getApi().addFrame(sprite, writer.frame().next()); break; case Content::EmptyFrame: - document->getApi().addEmptyFrame(sprite, - writer.frame().next(), - app_get_color_to_clear_layer(writer.layer())); + document->getApi().addEmptyFrame(sprite, writer.frame().next()); break; } undoTransaction.commit(); diff --git a/src/app/commands/commands_list.h b/src/app/commands/commands_list.h index 5ad0f2893..2b037be5e 100644 --- a/src/app/commands/commands_list.h +++ b/src/app/commands/commands_list.h @@ -27,6 +27,7 @@ FOR_EACH_COMMAND(ChangeBrush) FOR_EACH_COMMAND(ChangeColor) FOR_EACH_COMMAND(ChangePixelFormat) FOR_EACH_COMMAND(Clear) +FOR_EACH_COMMAND(ClearCel) FOR_EACH_COMMAND(CloseAllFiles) FOR_EACH_COMMAND(CloseFile) FOR_EACH_COMMAND(ColorCurve) @@ -85,7 +86,6 @@ FOR_EACH_COMMAND(PlayAnimation) FOR_EACH_COMMAND(Preview) FOR_EACH_COMMAND(Redo) FOR_EACH_COMMAND(Refresh) -FOR_EACH_COMMAND(RemoveCel) FOR_EACH_COMMAND(RemoveFrame) FOR_EACH_COMMAND(RemoveLayer) FOR_EACH_COMMAND(RepeatLastExport) diff --git a/src/app/document_api.cpp b/src/app/document_api.cpp index 578607b73..3378e8cf4 100644 --- a/src/app/document_api.cpp +++ b/src/app/document_api.cpp @@ -116,21 +116,21 @@ void DocumentApi::setSpriteTransparentColor(Sprite* sprite, color_t maskColor) m_document->notifyObservers(&doc::DocumentObserver::onSpriteTransparentColorChanged, ev); } -void DocumentApi::cropSprite(Sprite* sprite, const gfx::Rect& bounds, color_t bgcolor) +void DocumentApi::cropSprite(Sprite* sprite, const gfx::Rect& bounds) { setSpriteSize(sprite, bounds.w, bounds.h); displaceLayers(sprite->folder(), -bounds.x, -bounds.y); Layer *background_layer = sprite->backgroundLayer(); if (background_layer) - cropLayer(background_layer, 0, 0, sprite->width(), sprite->height(), bgcolor); + cropLayer(background_layer, 0, 0, sprite->width(), sprite->height()); if (!m_document->mask()->isEmpty()) setMaskPosition(m_document->mask()->bounds().x-bounds.x, m_document->mask()->bounds().y-bounds.y); } -void DocumentApi::trimSprite(Sprite* sprite, color_t bgcolor) +void DocumentApi::trimSprite(Sprite* sprite) { gfx::Rect bounds; @@ -152,7 +152,7 @@ void DocumentApi::trimSprite(Sprite* sprite, color_t bgcolor) } if (!bounds.isEmpty()) - cropSprite(sprite, bounds, bgcolor); + cropSprite(sprite, bounds); } void DocumentApi::setPixelFormat(Sprite* sprite, PixelFormat newFormat, DitheringMethod dithering_method) @@ -248,7 +248,7 @@ void DocumentApi::addFrame(Sprite* sprite, FrameNumber newFrame) copyFrame(sprite, newFrame.previous(), newFrame); } -void DocumentApi::addEmptyFrame(Sprite* sprite, FrameNumber newFrame, color_t bgcolor) +void DocumentApi::addEmptyFrame(Sprite* sprite, FrameNumber newFrame) { // Add the frame in the sprite structure, it adjusts the total // number of frames in the sprite. @@ -260,15 +260,6 @@ void DocumentApi::addEmptyFrame(Sprite* sprite, FrameNumber newFrame, color_t bg // Move cels. displaceFrames(sprite->folder(), newFrame); - // Add background cel - Layer* bgLayer = sprite->backgroundLayer(); - if (bgLayer) { - LayerImage* imglayer = static_cast(bgLayer); - Image* bgimage = Image::create(sprite->pixelFormat(), sprite->width(), sprite->height()); - clear_image(bgimage, bgcolor); - addImage(imglayer, newFrame, bgimage); - } - // Notify observers about the new frame. doc::DocumentEvent ev(m_document); ev.sprite(sprite); @@ -276,10 +267,10 @@ void DocumentApi::addEmptyFrame(Sprite* sprite, FrameNumber newFrame, color_t bg m_document->notifyObservers(&doc::DocumentObserver::onAddFrame, ev); } -void DocumentApi::addEmptyFramesTo(Sprite* sprite, FrameNumber newFrame, color_t bgcolor) +void DocumentApi::addEmptyFramesTo(Sprite* sprite, FrameNumber newFrame) { while (sprite->totalFrames() <= newFrame) - addEmptyFrame(sprite, sprite->totalFrames(), bgcolor); + addEmptyFrame(sprite, sprite->totalFrames()); } void DocumentApi::copyFrame(Sprite* sprite, FrameNumber fromFrame, FrameNumber newFrame) @@ -319,6 +310,13 @@ void DocumentApi::displaceFrames(Layer* layer, FrameNumber frame) if (cel) setCelFramePosition(imglayer, cel, cel->frame().next()); } + + // Add background cel + if (imglayer->isBackground()) { + Image* bgimage = Image::create(sprite->pixelFormat(), sprite->width(), sprite->height()); + clear_image(bgimage, bgColor(layer)); + addImage(imglayer, frame, bgimage); + } break; } @@ -349,7 +347,7 @@ void DocumentApi::copyFrameForLayer(Layer* layer, FrameNumber fromFrame, FrameNu if (fromFrame >= frame) fromFrame = fromFrame.next(); - copyCel(imglayer, fromFrame, imglayer, frame, 0); + copyCel(imglayer, fromFrame, imglayer, frame); break; } @@ -403,7 +401,7 @@ void DocumentApi::removeFrameOfLayer(Layer* layer, FrameNumber frame) case OBJECT_LAYER_IMAGE: { LayerImage* imglayer = static_cast(layer); if (Cel* cel = imglayer->getCel(frame)) - removeCel(imglayer, cel); + removeCel(cel); for (++frame; frametotalFrames(); ++frame) if (Cel* cel = imglayer->getCel(frame)) @@ -581,11 +579,11 @@ void DocumentApi::addCel(LayerImage* layer, Cel* cel) m_document->notifyObservers(&doc::DocumentObserver::onAddCel, ev); } -void DocumentApi::removeCel(LayerImage* layer, Cel* cel) +void DocumentApi::removeCel(Cel* cel) { - ASSERT(layer); ASSERT(cel); + LayerImage* layer = cel->layer(); Sprite* sprite = layer->sprite(); doc::DocumentEvent ev(m_document); @@ -663,13 +661,14 @@ void DocumentApi::setCelOpacity(Sprite* sprite, Cel* cel, int newOpacity) m_document->notifyObservers(&doc::DocumentObserver::onCelOpacityChanged, ev); } -void DocumentApi::cropCel(Sprite* sprite, Cel* cel, int x, int y, int w, int h, color_t bgcolor) +void DocumentApi::cropCel(Sprite* sprite, Cel* cel, int x, int y, int w, int h) { Image* cel_image = cel->image(); ASSERT(cel_image); // create the new image through a crop - Image* new_image = crop_image(cel_image, x-cel->x(), y-cel->y(), w, h, bgcolor); + Image* new_image = crop_image(cel_image, + x-cel->x(), y-cel->y(), w, h, bgColor(cel->layer())); // replace the image in the stock that is pointed by the cel replaceStockImage(sprite, cel->imageIndex(), new_image); @@ -678,27 +677,35 @@ void DocumentApi::cropCel(Sprite* sprite, Cel* cel, int x, int y, int w, int h, setCelPosition(sprite, cel, x, y); } -void DocumentApi::clearCel(LayerImage* layer, FrameNumber frame, color_t bgcolor) +void DocumentApi::clearCel(LayerImage* layer, FrameNumber frame) { Cel* cel = layer->getCel(frame); - Image* image = (cel ? cel->image(): NULL); + if (cel) + clearCel(cel); +} + +void DocumentApi::clearCel(Cel* cel) +{ + ASSERT(cel); + + Image* image = cel->image(); + ASSERT(image); if (!image) return; - if (layer->isBackground()) { + if (cel->layer()->isBackground()) { ASSERT(image); if (image) - clearImage(image, bgcolor); + clearImage(image, bgColor(cel->layer())); } else { - removeCel(layer, cel); + removeCel(cel); } } void DocumentApi::moveCel( LayerImage* srcLayer, FrameNumber srcFrame, - LayerImage* dstLayer, FrameNumber dstFrame, - color_t bgcolor) + LayerImage* dstLayer, FrameNumber dstFrame) { ASSERT(srcLayer != NULL); ASSERT(dstLayer != NULL); @@ -710,8 +717,8 @@ void DocumentApi::moveCel( ASSERT(srcFrame >= 0 && srcFrame < srcSprite->totalFrames()); ASSERT(dstFrame >= 0); - clearCel(dstLayer, dstFrame, bgcolor); - addEmptyFramesTo(dstSprite, dstFrame, bgcolor); + clearCel(dstLayer, dstFrame); + addEmptyFramesTo(dstSprite, dstFrame); Cel* srcCel = srcLayer->getCel(srcFrame); Cel* dstCel = dstLayer->getCel(dstFrame); @@ -726,7 +733,7 @@ void DocumentApi::moveCel( composite_image(dstImage, srcImage, srcCel->x(), srcCel->y(), 255, BLEND_MODE_NORMAL); - clearImage(srcImage, bgcolor); + clearImage(srcImage, bgColor(srcLayer)); } // Move the cel in the same layer. else { @@ -754,10 +761,7 @@ void DocumentApi::moveCel( addCel(dstLayer, dstCel); } - if (srcLayer->isBackground()) - clearImage(srcImage, bgcolor); - else - removeCel(srcLayer, srcCel); + clearCel(srcCel); } } @@ -766,7 +770,7 @@ void DocumentApi::moveCel( void DocumentApi::copyCel( LayerImage* srcLayer, FrameNumber srcFrame, - LayerImage* dstLayer, FrameNumber dstFrame, color_t bgcolor) + LayerImage* dstLayer, FrameNumber dstFrame) { ASSERT(srcLayer != NULL); ASSERT(dstLayer != NULL); @@ -778,8 +782,8 @@ void DocumentApi::copyCel( ASSERT(srcFrame >= 0 && srcFrame < srcSprite->totalFrames()); ASSERT(dstFrame >= 0); - clearCel(dstLayer, dstFrame, bgcolor); - addEmptyFramesTo(dstSprite, dstFrame, bgcolor); + clearCel(dstLayer, dstFrame); + addEmptyFramesTo(dstSprite, dstFrame); Cel* srcCel = srcLayer->getCel(srcFrame); Cel* dstCel = dstLayer->getCel(dstFrame); @@ -796,7 +800,7 @@ void DocumentApi::copyCel( } else { if (dstCel) - removeCel(dstLayer, dstCel); + removeCel(dstCel); if (srcCel) { // Add the image in the stock @@ -909,19 +913,17 @@ void DocumentApi::restackLayerBefore(Layer* layer, Layer* beforeThis) restackLayerAfter(layer, layer->sprite()->indexToLayer(afterThisIdx)); } -void DocumentApi::cropLayer(Layer* layer, int x, int y, int w, int h, color_t bgcolor) +void DocumentApi::cropLayer(Layer* layer, int x, int y, int w, int h) { if (!layer->isImage()) return; - if (!layer->isBackground()) - bgcolor = 0; // TODO use proper mask color - + color_t bgcolor = bgColor(layer); Sprite* sprite = layer->sprite(); CelIterator it = ((LayerImage*)layer)->getCelBegin(); CelIterator end = ((LayerImage*)layer)->getCelEnd(); for (; it != end; ++it) - cropCel(sprite, *it, x, y, w, h, bgcolor); + cropCel(sprite, *it, x, y, w, h); } // Moves every frame in @a layer with the offset (@a dx, @a dy). @@ -1041,7 +1043,7 @@ void DocumentApi::layerFromBackground(Layer* layer) layer->setName("Layer 0"); } -void DocumentApi::flattenLayers(Sprite* sprite, color_t bgcolor) +void DocumentApi::flattenLayers(Sprite* sprite) { Image* cel_image; Cel* cel; @@ -1062,6 +1064,8 @@ void DocumentApi::flattenLayers(Sprite* sprite, color_t bgcolor) configureLayerAsBackground(background); } + color_t bgcolor = bgColor(background); + // Copy all frames to the background. for (FrameNumber frame(0); frametotalFrames(); ++frame) { // Clear the image and render this frame. @@ -1150,6 +1154,9 @@ int DocumentApi::addImageInStock(Sprite* sprite, Image* image) Cel* DocumentApi::addImage(LayerImage* layer, FrameNumber frameNumber, Image* image) { int imageIndex = addImageInStock(layer->sprite(), image); + + ASSERT(layer->getCel(frameNumber) == NULL); + base::UniquePtr cel(new Cel(frameNumber, imageIndex)); addCel(layer, cel); @@ -1204,62 +1211,51 @@ void DocumentApi::clearMask(Cel* cel) { ASSERT(cel); + // If the mask is empty or is not visible then we have to clear the + // entire image in the cel. + if (!m_document->isMaskVisible()) { + clearCel(cel); + return; + } + Image* image = (cel ? cel->image(): NULL); if (!image) return; - LayerImage* layer = cel->layer(); Mask* mask = m_document->mask(); - color_t bgcolor = bgColor(layer); + color_t bgcolor = bgColor(cel->layer()); + int offset_x = mask->bounds().x-cel->x(); + int offset_y = mask->bounds().y-cel->y(); + int u, v, putx, puty; + int x1 = MAX(0, offset_x); + int y1 = MAX(0, offset_y); + int x2 = MIN(image->width()-1, offset_x+mask->bounds().w-1); + int y2 = MIN(image->height()-1, offset_y+mask->bounds().h-1); - // If the mask is empty or is not visible then we have to clear the - // entire image in the cel. - if (!m_document->isMaskVisible()) { - // If the layer is the background then we clear the image. - if (layer->isBackground()) { - clearImage(image, bgcolor); - } - // If the layer is transparent we can remove the cel (and its - // associated image). - else { - ASSERT(layer->isImage()); - removeCel(layer, cel); - } - } - else { - int offset_x = mask->bounds().x-cel->x(); - int offset_y = mask->bounds().y-cel->y(); - int u, v, putx, puty; - int x1 = MAX(0, offset_x); - int y1 = MAX(0, offset_y); - int x2 = MIN(image->width()-1, offset_x+mask->bounds().w-1); - int y2 = MIN(image->height()-1, offset_y+mask->bounds().h-1); + // Do nothing + if (x1 > x2 || y1 > y2) + return; - // Do nothing - if (x1 > x2 || y1 > y2) - return; + if (undoEnabled()) + m_undoers->pushUndoer(new undoers::ImageArea(getObjects(), + image, x1, y1, x2-x1+1, y2-y1+1)); - if (undoEnabled()) - m_undoers->pushUndoer(new undoers::ImageArea(getObjects(), - image, x1, y1, x2-x1+1, y2-y1+1)); + const LockImageBits maskBits(mask->bitmap()); + LockImageBits::const_iterator it = maskBits.begin(); - const LockImageBits maskBits(mask->bitmap()); - LockImageBits::const_iterator it = maskBits.begin(); - - // Clear the masked zones - for (v=0; vbounds().h; ++v) { - for (u=0; ubounds().w; ++u, ++it) { - ASSERT(it != maskBits.end()); - if (*it) { - putx = u + offset_x; - puty = v + offset_y; - put_pixel(image, putx, puty, bgcolor); - } + // Clear the masked zones + for (v=0; vbounds().h; ++v) { + for (u=0; ubounds().w; ++u, ++it) { + ASSERT(it != maskBits.end()); + if (*it) { + putx = u + offset_x; + puty = v + offset_y; + put_pixel(image, putx, puty, bgcolor); } } - - ASSERT(it == maskBits.end()); } + + ASSERT(it == maskBits.end()); } void DocumentApi::flipImage(Image* image, const gfx::Rect& bounds, @@ -1276,9 +1272,10 @@ void DocumentApi::flipImage(Image* image, const gfx::Rect& bounds, raster::algorithm::flip_image(image, bounds, flipType); } -void DocumentApi::flipImageWithMask(Image* image, const Mask* mask, raster::algorithm::FlipType flipType, color_t bgcolor) +void DocumentApi::flipImageWithMask(Layer* layer, Image* image, const Mask* mask, raster::algorithm::FlipType flipType) { base::UniquePtr flippedImage((Image::createCopy(image))); + color_t bgcolor = bgColor(layer); // Flip the portion of the bitmap. raster::algorithm::flip_image_with_mask(flippedImage, mask, flipType, bgcolor); diff --git a/src/app/document_api.h b/src/app/document_api.h index 817e6c932..876683a34 100644 --- a/src/app/document_api.h +++ b/src/app/document_api.h @@ -63,14 +63,14 @@ namespace app { // Sprite API void setSpriteSize(Sprite* sprite, int w, int h); void setSpriteTransparentColor(Sprite* sprite, color_t maskColor); - void cropSprite(Sprite* sprite, const gfx::Rect& bounds, color_t bgcolor); - void trimSprite(Sprite* sprite, color_t bgcolor); + void cropSprite(Sprite* sprite, const gfx::Rect& bounds); + void trimSprite(Sprite* sprite); void setPixelFormat(Sprite* sprite, PixelFormat newFormat, DitheringMethod dithering_method); // Frames API void addFrame(Sprite* sprite, FrameNumber newFrame); - void addEmptyFrame(Sprite* sprite, FrameNumber newFrame, color_t bgcolor); - void addEmptyFramesTo(Sprite* sprite, FrameNumber newFrame, color_t bgcolor); + void addEmptyFrame(Sprite* sprite, FrameNumber newFrame); + void addEmptyFramesTo(Sprite* sprite, FrameNumber newFrame); void copyFrame(Sprite* sprite, FrameNumber fromFrame, FrameNumber newFrame); void removeFrame(Sprite* sprite, FrameNumber frame); void setTotalFrames(Sprite* sprite, FrameNumber frames); @@ -80,17 +80,17 @@ namespace app { // Cels API void addCel(LayerImage* layer, Cel* cel); - void removeCel(LayerImage* layer, Cel* cel); + void clearCel(LayerImage* layer, FrameNumber frame); + void clearCel(Cel* cel); void setCelPosition(Sprite* sprite, Cel* cel, int x, int y); void setCelOpacity(Sprite* sprite, Cel* cel, int newOpacity); - void cropCel(Sprite* sprite, Cel* cel, int x, int y, int w, int h, color_t bgcolor); - void clearCel(LayerImage* layer, FrameNumber frame, color_t bgcolor); + void cropCel(Sprite* sprite, Cel* cel, int x, int y, int w, int h); void moveCel( LayerImage* srcLayer, FrameNumber srcFrame, - LayerImage* dstLayer, FrameNumber dstFrame, color_t bgcolor); + LayerImage* dstLayer, FrameNumber dstFrame); void copyCel( LayerImage* srcLayer, FrameNumber srcFrame, - LayerImage* dstLayer, FrameNumber dstFrame, color_t bgcolor); + LayerImage* dstLayer, FrameNumber dstFrame); // Layers API LayerImage* newLayer(Sprite* sprite); @@ -99,11 +99,11 @@ namespace app { void removeLayer(Layer* layer); void restackLayerAfter(Layer* layer, Layer* afterThis); void restackLayerBefore(Layer* layer, Layer* beforeThis); - void cropLayer(Layer* layer, int x, int y, int w, int h, color_t bgcolor); + void cropLayer(Layer* layer, int x, int y, int w, int h); void displaceLayers(Layer* layer, int dx, int dy); void backgroundFromLayer(LayerImage* layer); void layerFromBackground(Layer* layer); - void flattenLayers(Sprite* sprite, color_t bgcolor); + void flattenLayers(Sprite* sprite); void duplicateLayerAfter(Layer* sourceLayer, Layer* afterLayer); void duplicateLayerBefore(Layer* sourceLayer, Layer* beforeLayer); @@ -117,7 +117,7 @@ namespace app { void clearImage(Image* image, color_t bgcolor); void clearMask(Cel* cel); void flipImage(Image* image, const gfx::Rect& bounds, raster::algorithm::FlipType flipType); - void flipImageWithMask(Image* image, const Mask* mask, raster::algorithm::FlipType flipType, color_t bgcolor); + void flipImageWithMask(Layer* layer, Image* image, const Mask* mask, raster::algorithm::FlipType flipType); void pasteImage(Sprite* sprite, Cel* cel, const Image* src_image, int x, int y, int opacity); // Mask API @@ -130,6 +130,7 @@ namespace app { private: undo::ObjectsContainer* getObjects() const; + void removeCel(Cel* cel); void setCelFramePosition(LayerImage* layer, Cel* cel, FrameNumber frame); void displaceFrames(Layer* layer, FrameNumber frame); void copyFrameForLayer(Layer* layer, FrameNumber fromFrame, FrameNumber frame); diff --git a/src/app/document_range_ops.cpp b/src/app/document_range_ops.cpp index 6a4ad4358..c270248ca 100644 --- a/src/app/document_range_ops.cpp +++ b/src/app/document_range_ops.cpp @@ -148,8 +148,8 @@ static DocumentRange drop_range_op( color_t bgcolor = app_get_color_to_clear_layer(dstLayer); switch (op) { - case Move: api.moveCel(srcLayer, srcFrame, dstLayer, dstFrame, bgcolor); break; - case Copy: api.copyCel(srcLayer, srcFrame, dstLayer, dstFrame, bgcolor); break; + case Move: api.moveCel(srcLayer, srcFrame, dstLayer, dstFrame); break; + case Copy: api.copyCel(srcLayer, srcFrame, dstLayer, dstFrame); break; } srcFrame += srcFrameStep; diff --git a/src/app/util/clipboard.cpp b/src/app/util/clipboard.cpp index 0db92e65a..2ec7a5530 100644 --- a/src/app/util/clipboard.cpp +++ b/src/app/util/clipboard.cpp @@ -326,16 +326,14 @@ void clipboard::paste() Cel* cel = static_cast(srcLayers[i])->getCel(frame); if (cel && cel->image()) { - bgcolor = app_get_color_to_clear_layer(dstLayers[j]); - api.copyCel( static_cast(srcLayers[i]), frame, - static_cast(dstLayers[j]), dstFrame, bgcolor); + static_cast(dstLayers[j]), dstFrame); } else { Cel* dstCel = static_cast(dstLayers[j])->getCel(dstFrame); if (dstCel) - api.removeCel(static_cast(dstLayers[j]), dstCel); + api.clearCel(dstCel); } } @@ -361,11 +359,9 @@ void clipboard::paste() j >= LayerIndex(0); --i, --j) { Cel* cel = static_cast(srcLayers[i])->getCel(frame); if (cel && cel->image()) { - bgcolor = app_get_color_to_clear_layer(dstLayers[j]); - api.copyCel( static_cast(srcLayers[i]), frame, - static_cast(dstLayers[j]), dstFrame, bgcolor); + static_cast(dstLayers[j]), dstFrame); } }