mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-02 21:19:10 +00:00
parent
8ca323492e
commit
f4d82ad2c0
@ -748,6 +748,7 @@
|
||||
<separator />
|
||||
<item command="ClearCel" text="&Clear" />
|
||||
<item command="UnlinkCel" text="&Unlink" />
|
||||
<item command="LinkCels" text="&Link Cels" />
|
||||
</menu>
|
||||
|
||||
<menu id="cel_movement_popup">
|
||||
|
@ -185,6 +185,7 @@ add_library(app-lib
|
||||
commands/cmd_layer_from_background.cpp
|
||||
commands/cmd_layer_properties.cpp
|
||||
commands/cmd_layer_visibility.cpp
|
||||
commands/cmd_link_cels.cpp
|
||||
commands/cmd_load_mask.cpp
|
||||
commands/cmd_load_palette.cpp
|
||||
commands/cmd_mask_all.cpp
|
||||
|
@ -33,11 +33,12 @@ using namespace doc;
|
||||
|
||||
CopyCel::CopyCel(
|
||||
LayerImage* srcLayer, frame_t srcFrame,
|
||||
LayerImage* dstLayer, frame_t dstFrame)
|
||||
LayerImage* dstLayer, frame_t dstFrame, bool continuous)
|
||||
: m_srcLayer(srcLayer)
|
||||
, m_dstLayer(dstLayer)
|
||||
, m_srcFrame(srcFrame)
|
||||
, m_dstFrame(dstFrame)
|
||||
, m_continuous(continuous)
|
||||
{
|
||||
}
|
||||
|
||||
@ -78,7 +79,7 @@ void CopyCel::onExecute()
|
||||
dstImage = dstCel->imageRef();
|
||||
|
||||
bool createLink =
|
||||
(srcLayer == dstLayer && dstLayer->isContinuous());
|
||||
(srcLayer == dstLayer && m_continuous);
|
||||
|
||||
// For background layer
|
||||
if (dstLayer->isBackground()) {
|
||||
|
@ -26,7 +26,7 @@ namespace cmd {
|
||||
public:
|
||||
CopyCel(
|
||||
LayerImage* srcLayer, frame_t srcFrame,
|
||||
LayerImage* dstLayer, frame_t dstFrame);
|
||||
LayerImage* dstLayer, frame_t dstFrame, bool continuous);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
@ -35,6 +35,7 @@ namespace cmd {
|
||||
private:
|
||||
WithLayer m_srcLayer, m_dstLayer;
|
||||
frame_t m_srcFrame, m_dstFrame;
|
||||
bool m_continuous;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
|
@ -46,7 +46,7 @@ void CopyFrame::onExecute()
|
||||
if (layer->isImage()) {
|
||||
executeAndAdd(new cmd::CopyCel(
|
||||
static_cast<LayerImage*>(layer), fromFrame,
|
||||
static_cast<LayerImage*>(layer), m_newFrame));
|
||||
static_cast<LayerImage*>(layer), m_newFrame, layer->isContinuous()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,11 +35,12 @@ using namespace doc;
|
||||
|
||||
MoveCel::MoveCel(
|
||||
LayerImage* srcLayer, frame_t srcFrame,
|
||||
LayerImage* dstLayer, frame_t dstFrame)
|
||||
LayerImage* dstLayer, frame_t dstFrame, bool continuous)
|
||||
: m_srcLayer(srcLayer)
|
||||
, m_dstLayer(dstLayer)
|
||||
, m_srcFrame(srcFrame)
|
||||
, m_dstFrame(dstFrame)
|
||||
, m_continuous(continuous)
|
||||
{
|
||||
}
|
||||
|
||||
@ -80,7 +81,7 @@ void MoveCel::onExecute()
|
||||
dstImage = dstCel->imageRef();
|
||||
|
||||
bool createLink =
|
||||
(srcLayer == dstLayer && dstLayer->isContinuous());
|
||||
(srcLayer == dstLayer && m_continuous);
|
||||
|
||||
// For background layer
|
||||
if (dstLayer->isBackground()) {
|
||||
|
@ -26,7 +26,7 @@ namespace cmd {
|
||||
public:
|
||||
MoveCel(
|
||||
LayerImage* srcLayer, frame_t srcFrame,
|
||||
LayerImage* dstLayer, frame_t dstFrame);
|
||||
LayerImage* dstLayer, frame_t dstFrame, bool continuous);
|
||||
|
||||
protected:
|
||||
void onExecute() override;
|
||||
@ -35,6 +35,7 @@ namespace cmd {
|
||||
private:
|
||||
WithLayer m_srcLayer, m_dstLayer;
|
||||
frame_t m_srcFrame, m_dstFrame;
|
||||
bool m_continuous;
|
||||
};
|
||||
|
||||
} // namespace cmd
|
||||
|
113
src/app/commands/cmd_link_cels.cpp
Normal file
113
src/app/commands/cmd_link_cels.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/cmd/copy_cel.h"
|
||||
#include "app/commands/command.h"
|
||||
#include "app/context_access.h"
|
||||
#include "app/modules/gui.h"
|
||||
#include "app/transaction.h"
|
||||
#include "app/ui/main_window.h"
|
||||
#include "app/ui/status_bar.h"
|
||||
#include "app/ui/timeline.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
class LinkCelsCommand : public Command {
|
||||
public:
|
||||
LinkCelsCommand();
|
||||
Command* clone() const override { return new LinkCelsCommand(*this); }
|
||||
|
||||
protected:
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
};
|
||||
|
||||
LinkCelsCommand::LinkCelsCommand()
|
||||
: Command("LinkCels",
|
||||
"Links Cels",
|
||||
CmdRecordableFlag)
|
||||
{
|
||||
}
|
||||
|
||||
bool LinkCelsCommand::onEnabled(Context* context)
|
||||
{
|
||||
if (context->checkFlags(ContextFlags::ActiveDocumentIsWritable)) {
|
||||
// TODO the range of selected frames should be in doc::Site.
|
||||
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
|
||||
return (range.enabled() && range.frames() > 1);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void LinkCelsCommand::onExecute(Context* context)
|
||||
{
|
||||
ContextWriter writer(context);
|
||||
Document* document(writer.document());
|
||||
bool nonEditableLayers = false;
|
||||
{
|
||||
// TODO the range of selected frames should be in doc::Site.
|
||||
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
|
||||
if (!range.enabled())
|
||||
return;
|
||||
|
||||
Transaction transaction(writer.context(), friendlyName());
|
||||
Sprite* sprite = writer.sprite();
|
||||
frame_t begin = range.frameBegin();
|
||||
frame_t end = range.frameEnd();
|
||||
|
||||
for (LayerIndex layerIdx = range.layerBegin(); layerIdx <= range.layerEnd(); ++layerIdx) {
|
||||
Layer* layer = sprite->indexToLayer(layerIdx);
|
||||
if (!layer->isImage())
|
||||
continue;
|
||||
|
||||
if (!layer->isEditable()) {
|
||||
nonEditableLayers = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
LayerImage* layerImage = static_cast<LayerImage*>(layer);
|
||||
for (frame_t frame=begin; frame < end+1; ++frame) {
|
||||
Cel* cel = layerImage->cel(frame);
|
||||
if (cel) {
|
||||
for (frame = cel->frame()+1;
|
||||
frame < end+1; ++frame) {
|
||||
transaction.execute(
|
||||
new cmd::CopyCel(
|
||||
layerImage, cel->frame(),
|
||||
layerImage, frame,
|
||||
true)); // true = force links
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
if (nonEditableLayers)
|
||||
StatusBar::instance()->showTip(1000,
|
||||
"There are locked layers");
|
||||
|
||||
update_screen_for_document(document);
|
||||
}
|
||||
|
||||
Command* CommandFactory::createLinkCelsCommand()
|
||||
{
|
||||
return new LinkCelsCommand;
|
||||
}
|
||||
|
||||
} // namespace app
|
@ -60,6 +60,7 @@ FOR_EACH_COMMAND(Launch)
|
||||
FOR_EACH_COMMAND(LayerFromBackground)
|
||||
FOR_EACH_COMMAND(LayerProperties)
|
||||
FOR_EACH_COMMAND(LayerVisibility)
|
||||
FOR_EACH_COMMAND(LinkCels)
|
||||
FOR_EACH_COMMAND(LoadMask)
|
||||
FOR_EACH_COMMAND(LoadPalette)
|
||||
FOR_EACH_COMMAND(MaskAll)
|
||||
|
@ -351,7 +351,7 @@ void DocumentApi::moveCel(
|
||||
ASSERT(srcLayer != dstLayer || srcFrame != dstFrame);
|
||||
m_transaction.execute(new cmd::MoveCel(
|
||||
srcLayer, srcFrame,
|
||||
dstLayer, dstFrame));
|
||||
dstLayer, dstFrame, dstLayer->isContinuous()));
|
||||
}
|
||||
|
||||
void DocumentApi::copyCel(
|
||||
@ -361,7 +361,7 @@ void DocumentApi::copyCel(
|
||||
ASSERT(srcLayer != dstLayer || srcFrame != dstFrame);
|
||||
m_transaction.execute(new cmd::CopyCel(
|
||||
srcLayer, srcFrame,
|
||||
dstLayer, dstFrame));
|
||||
dstLayer, dstFrame, dstLayer->isContinuous()));
|
||||
}
|
||||
|
||||
void DocumentApi::swapCel(
|
||||
|
Loading…
Reference in New Issue
Block a user