Fix problems clearing background cels

- The background color to clear is calculated in one place: DocumentApi
- Rename RemoveCel command to ClearCel
This commit is contained in:
David Capello 2014-09-17 09:53:25 -03:00
parent 79320943d7
commit 546d3af5e8
14 changed files with 130 additions and 161 deletions

View File

@ -630,7 +630,7 @@
<menu id="cel_popup">
<item command="CelProperties" text="&amp;Properties..." />
<separator />
<item command="RemoveCel" text="&amp;Clear" />
<item command="ClearCel" text="&amp;Clear" />
</menu>
<menu id="cel_movement_popup">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -116,21 +116,21 @@ void DocumentApi::setSpriteTransparentColor(Sprite* sprite, color_t maskColor)
m_document->notifyObservers<doc::DocumentEvent&>(&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<LayerImage*>(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::DocumentEvent&>(&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<LayerImage*>(layer);
if (Cel* cel = imglayer->getCel(frame))
removeCel(imglayer, cel);
removeCel(cel);
for (++frame; frame<sprite->totalFrames(); ++frame)
if (Cel* cel = imglayer->getCel(frame))
@ -581,11 +579,11 @@ void DocumentApi::addCel(LayerImage* layer, Cel* cel)
m_document->notifyObservers<doc::DocumentEvent&>(&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::DocumentEvent&>(&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); frame<sprite->totalFrames(); ++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> 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<BitmapTraits> maskBits(mask->bitmap());
LockImageBits<BitmapTraits>::const_iterator it = maskBits.begin();
const LockImageBits<BitmapTraits> maskBits(mask->bitmap());
LockImageBits<BitmapTraits>::const_iterator it = maskBits.begin();
// Clear the masked zones
for (v=0; v<mask->bounds().h; ++v) {
for (u=0; u<mask->bounds().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; v<mask->bounds().h; ++v) {
for (u=0; u<mask->bounds().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<Image> 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);

View File

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

View File

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

View File

@ -326,16 +326,14 @@ void clipboard::paste()
Cel* cel = static_cast<LayerImage*>(srcLayers[i])->getCel(frame);
if (cel && cel->image()) {
bgcolor = app_get_color_to_clear_layer(dstLayers[j]);
api.copyCel(
static_cast<LayerImage*>(srcLayers[i]), frame,
static_cast<LayerImage*>(dstLayers[j]), dstFrame, bgcolor);
static_cast<LayerImage*>(dstLayers[j]), dstFrame);
}
else {
Cel* dstCel = static_cast<LayerImage*>(dstLayers[j])->getCel(dstFrame);
if (dstCel)
api.removeCel(static_cast<LayerImage*>(dstLayers[j]), dstCel);
api.clearCel(dstCel);
}
}
@ -361,11 +359,9 @@ void clipboard::paste()
j >= LayerIndex(0); --i, --j) {
Cel* cel = static_cast<LayerImage*>(srcLayers[i])->getCel(frame);
if (cel && cel->image()) {
bgcolor = app_get_color_to_clear_layer(dstLayers[j]);
api.copyCel(
static_cast<LayerImage*>(srcLayers[i]), frame,
static_cast<LayerImage*>(dstLayers[j]), dstFrame, bgcolor);
static_cast<LayerImage*>(dstLayers[j]), dstFrame);
}
}