Skip to content

Commit

Permalink
Timeline: add support to move/copy ranges (multiple cels/frames/layers)
Browse files Browse the repository at this point in the history
- Merge Timeline::STATE_MOVING_LAYER/CEL/FRAME to STATE_MOVING_RANGE.
- Remove celmove.h/cpp and move_cel/copy_cel functions. Now they are
  in the Timeline as dropRange/Cels/Frames/Layers member functions.
- Add DocumentApi::copyFrame/moveCel/copyCel member functions.
- Add timeline_drop_layer_deco and timeline_drop_frame_deco skin parts.
- Move code from DuplicateLayerCommand::onExecute() to new member
  function DocumentApi::duplicateLayer().
- Fix a bug changing Cel's frame number: we weren't updating the Cel
  position properly inside the LayerImage::m_cels collection. Now we use
  LayerImage::moveCel() to change the Cel frame number.
- Other fixes to DocumentApi: Change bgcolor from int to color_t.
  • Loading branch information
dacap committed Apr 10, 2014
1 parent cb2c094 commit 942dba3
Show file tree
Hide file tree
Showing 19 changed files with 717 additions and 646 deletions.
Binary file modified data/skins/default/sheet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions data/skins/default/skin.xml
Expand Up @@ -310,6 +310,8 @@
<part id="timeline_padding_tr" x="288" y="12" w1="1" w2="10" w3="1" h1="1" h2="10" h3="1" />
<part id="timeline_padding_bl" x="276" y="24" w1="1" w2="10" w3="1" h1="1" h2="10" h3="1" />
<part id="timeline_padding_br" x="288" y="24" w1="1" w2="10" w3="1" h1="1" h2="10" h3="1" />
<part id="timeline_drop_layer_deco" x="252" y="127" w1="3" w2="1" w3="3" h1="2" h2="1" h3="2" />
<part id="timeline_drop_frame_deco" x="252" y="120" w1="2" w2="1" w3="2" h1="3" h2="1" h3="3" />
</parts>

<stylesheet>
Expand Down Expand Up @@ -502,6 +504,16 @@
<background part="colorbar_border_fg" />
</style>

<!-- timeline_drop_layer_deco -->
<style id="timeline_drop_layer_deco">
<background part="timeline_drop_layer_deco" />
</style>

<!-- timeline_drop_frame_deco -->
<style id="timeline_drop_frame_deco">
<background part="timeline_drop_frame_deco" />
</style>

</stylesheet>

</skin>
1 change: 0 additions & 1 deletion src/app/CMakeLists.txt
Expand Up @@ -227,7 +227,6 @@ add_library(app-lib
undoers/set_total_frames.cpp
util/autocrop.cpp
util/boundary.cpp
util/celmove.cpp
util/clipboard.cpp
util/expand_cel_canvas.cpp
util/filetoks.cpp
Expand Down
4 changes: 1 addition & 3 deletions src/app/commands/cmd_copy_cel.cpp
Expand Up @@ -25,7 +25,6 @@
#include "app/context_access.h"
#include "app/ui/timeline.h"
#include "app/ui/main_window.h"
#include "app/util/celmove.h"
#include "ui/base.h"

namespace app {
Expand Down Expand Up @@ -54,8 +53,7 @@ bool CopyCelCommand::onEnabled(Context* context)

void CopyCelCommand::onExecute(Context* context)
{
ContextWriter writer(context);
copy_cel(writer);
App::instance()->getMainWindow()->getTimeline()->dropRange(Timeline::kCopy);
}

Command* CommandFactory::createCopyCelCommand()
Expand Down
35 changes: 8 additions & 27 deletions src/app/commands/cmd_duplicate_layer.cpp
Expand Up @@ -66,33 +66,14 @@ void DuplicateLayerCommand::onExecute(Context* context)
{
ContextWriter writer(context);
Document* document = writer.document();
Sprite* sprite = writer.sprite();
UndoTransaction undo(writer.context(), "Layer Duplication");
LayerImage* sourceLayer = static_cast<LayerImage*>(writer.layer());

// Create a new layer
base::UniquePtr<LayerImage> newLayerPtr(new LayerImage(sprite));

// Disable undo because the layer content is added as a whole with
// AddLayer() undoer.
document->getUndo()->setEnabled(false);

// Copy the layer content (cels + images)
document->copyLayerContent(sourceLayer, document, newLayerPtr);

// Restore enabled status.
document->getUndo()->setEnabled(undo.isEnabled());

// Copy the layer name
newLayerPtr->setName(newLayerPtr->getName() + " Copy");

// Add the new layer in the sprite.
document->getApi().addLayer(sourceLayer->getParent(), newLayerPtr, sourceLayer);

// Release the pointer as it is owned by the sprite now
Layer* newLayer = newLayerPtr.release();

undo.commit();
DocumentApi api = document->getApi();

{
UndoTransaction undo(writer.context(), "Layer Duplication");
LayerImage* sourceLayer = static_cast<LayerImage*>(writer.layer());
api.duplicateLayer(sourceLayer, sourceLayer);
undo.commit();
}

update_screen_for_document(document);
}
Expand Down
4 changes: 1 addition & 3 deletions src/app/commands/cmd_move_cel.cpp
Expand Up @@ -25,7 +25,6 @@
#include "app/context_access.h"
#include "app/ui/main_window.h"
#include "app/ui/timeline.h"
#include "app/util/celmove.h"
#include "ui/base.h"

namespace app {
Expand Down Expand Up @@ -54,8 +53,7 @@ bool MoveCelCommand::onEnabled(Context* context)

void MoveCelCommand::onExecute(Context* context)
{
ContextWriter writer(context);
move_cel(writer);
App::instance()->getMainWindow()->getTimeline()->dropRange(Timeline::kMove);
}

Command* CommandFactory::createMoveCelCommand()
Expand Down
25 changes: 8 additions & 17 deletions src/app/document.cpp
Expand Up @@ -360,8 +360,6 @@ void Document::resetTransformation()

void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, Layer* destLayer0) const
{
DocumentUndo* undo = destDoc->getUndo();

// Copy the layer name
destLayer0->setName(sourceLayer0->getName());

Expand All @@ -386,12 +384,6 @@ void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, La
Image* newImage = Image::createCopy(sourceImage);
newCel->setImage(destLayer->getSprite()->getStock()->addImage(newImage));

if (undo->isEnabled()) {
undo->pushUndoer(new undoers::AddImage(undo->getObjects(),
destLayer->getSprite()->getStock(),
newCel->getImage()));
}

destLayer->addCel(newCel);
newCel.release();
}
Expand Down Expand Up @@ -422,9 +414,14 @@ void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, La
ASSERT(destChild != NULL);

// Add the new layer in the sprite.
destDoc->getApi().addLayer(destLayer,
destChild.release(),
destLayer->getLastLayer());

Layer* newLayer = destChild.release();
Layer* afterThis = destLayer->getLastLayer();

destLayer->addLayer(newLayer);
destChild.release();

destLayer->stackLayer(newLayer, afterThis);
}
}
else {
Expand Down Expand Up @@ -461,14 +458,8 @@ Document* Document::duplicate(DuplicateType type) const
switch (type) {

case DuplicateExactCopy:
// Disable the undo
documentCopy->getUndo()->setEnabled(false);

// Copy the layer folder
copyLayerContent(getSprite()->getFolder(), documentCopy, spriteCopy->getFolder());

// Re-enable the undo
documentCopy->getUndo()->setEnabled(true);
break;

case DuplicateWithFlattenLayers:
Expand Down

0 comments on commit 942dba3

Please sign in to comment.