mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-02 13:09:27 +00:00
Add Alt+B shortcut to create new empty frames
This commit is contained in:
parent
eed23803a8
commit
6c571adbd4
@ -59,6 +59,9 @@
|
||||
<key command="GotoNextLayer" shortcut="Up" />
|
||||
<!-- Frame -->
|
||||
<key command="NewFrame" shortcut="Alt+N" />
|
||||
<key command="NewFrame" shortcut="Alt+B">
|
||||
<param name="content" value="empty" />
|
||||
</key>
|
||||
<key command="FrameProperties" shortcut="P">
|
||||
<param name="frame" value="current" />
|
||||
</key>
|
||||
@ -378,6 +381,9 @@
|
||||
<item command="CelProperties" text="&Cel Properties..." />
|
||||
<separator />
|
||||
<item command="NewFrame" text="&New Frame" />
|
||||
<item command="NewFrame" text="&New Empty Frame">
|
||||
<param name="content" value="empty" />
|
||||
</item>
|
||||
<item command="RemoveFrame" text="&Remove Frame" />
|
||||
<separator />
|
||||
<menu text="&Jump to">
|
||||
@ -493,6 +499,9 @@
|
||||
</item>
|
||||
<separator />
|
||||
<item command="NewFrame" text="&New" />
|
||||
<item command="NewFrame" text="&New Empty Frame">
|
||||
<param name="content" value="empty" />
|
||||
</item>
|
||||
<item command="RemoveFrame" text="&Remove" />
|
||||
</menu>
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "app/app.h"
|
||||
#include "app/color.h"
|
||||
#include "app/commands/command.h"
|
||||
#include "app/commands/params.h"
|
||||
#include "app/console.h"
|
||||
#include "app/context_access.h"
|
||||
#include "app/document_api.h"
|
||||
@ -42,12 +43,18 @@ namespace app {
|
||||
|
||||
class NewFrameCommand : public Command {
|
||||
public:
|
||||
enum class Content { CurrentFrame, EmptyFrame };
|
||||
|
||||
NewFrameCommand();
|
||||
Command* clone() const override { return new NewFrameCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params);
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
|
||||
private:
|
||||
Content m_content;
|
||||
};
|
||||
|
||||
NewFrameCommand::NewFrameCommand()
|
||||
@ -57,6 +64,15 @@ NewFrameCommand::NewFrameCommand()
|
||||
{
|
||||
}
|
||||
|
||||
void NewFrameCommand::onLoadParams(Params* params)
|
||||
{
|
||||
m_content = Content::CurrentFrame;
|
||||
|
||||
std::string content = params->get("content");
|
||||
if (content == "current") m_content = Content::CurrentFrame;
|
||||
else if (content == "empty") m_content = Content::EmptyFrame;
|
||||
}
|
||||
|
||||
bool NewFrameCommand::onEnabled(Context* context)
|
||||
{
|
||||
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
||||
@ -70,7 +86,14 @@ void NewFrameCommand::onExecute(Context* context)
|
||||
Sprite* sprite(writer.sprite());
|
||||
{
|
||||
UndoTransaction undoTransaction(writer.context(), "New Frame");
|
||||
document->getApi().addFrame(sprite, writer.frame().next());
|
||||
switch (m_content) {
|
||||
case Content::CurrentFrame:
|
||||
document->getApi().addFrame(sprite, writer.frame().next());
|
||||
break;
|
||||
case Content::EmptyFrame:
|
||||
document->getApi().addEmptyFrame(sprite, writer.frame().next());
|
||||
break;
|
||||
}
|
||||
undoTransaction.commit();
|
||||
}
|
||||
update_screen_for_document(document);
|
||||
|
@ -245,6 +245,32 @@ void DocumentApi::addFrame(Sprite* sprite, FrameNumber newFrame)
|
||||
copyFrame(sprite, newFrame.previous(), newFrame);
|
||||
}
|
||||
|
||||
void DocumentApi::addEmptyFrame(Sprite* sprite, FrameNumber newFrame)
|
||||
{
|
||||
// Add the frame in the sprite structure, it adjusts the total
|
||||
// number of frames in the sprite.
|
||||
if (undoEnabled())
|
||||
m_undoers->pushUndoer(new undoers::AddFrame(getObjects(), m_document, sprite, newFrame));
|
||||
|
||||
sprite->addFrame(newFrame);
|
||||
|
||||
// Move cels.
|
||||
displaceFrames(sprite->folder(), newFrame);
|
||||
|
||||
// Add background cel
|
||||
Layer* bgLayer = sprite->backgroundLayer();
|
||||
if (bgLayer) {
|
||||
LayerImage* imglayer = static_cast<LayerImage*>(bgLayer);
|
||||
copyCel(imglayer, FrameNumber(0), imglayer, newFrame, 0);
|
||||
}
|
||||
|
||||
// Notify observers about the new frame.
|
||||
doc::DocumentEvent ev(m_document);
|
||||
ev.sprite(sprite);
|
||||
ev.frame(newFrame);
|
||||
m_document->notifyObservers<doc::DocumentEvent&>(&doc::DocumentObserver::onAddFrame, ev);
|
||||
}
|
||||
|
||||
void DocumentApi::copyFrame(Sprite* sprite, FrameNumber fromFrame, FrameNumber newFrame)
|
||||
{
|
||||
// Add the frame in the sprite structure, it adjusts the total
|
||||
@ -264,7 +290,7 @@ void DocumentApi::copyFrame(Sprite* sprite, FrameNumber fromFrame, FrameNumber n
|
||||
m_document->notifyObservers<doc::DocumentEvent&>(&doc::DocumentObserver::onAddFrame, ev);
|
||||
}
|
||||
|
||||
void DocumentApi::copyFrameForLayer(Layer* layer, FrameNumber fromFrame, FrameNumber frame)
|
||||
void DocumentApi::displaceFrames(Layer* layer, FrameNumber frame)
|
||||
{
|
||||
ASSERT(layer);
|
||||
ASSERT(frame >= 0);
|
||||
@ -282,6 +308,34 @@ void DocumentApi::copyFrameForLayer(Layer* layer, FrameNumber fromFrame, FrameNu
|
||||
if (cel)
|
||||
setCelFramePosition(imglayer, cel, cel->frame().next());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case OBJECT_LAYER_FOLDER: {
|
||||
LayerIterator it = static_cast<LayerFolder*>(layer)->getLayerBegin();
|
||||
LayerIterator end = static_cast<LayerFolder*>(layer)->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it)
|
||||
displaceFrames(*it, frame);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentApi::copyFrameForLayer(Layer* layer, FrameNumber fromFrame, FrameNumber frame)
|
||||
{
|
||||
ASSERT(layer);
|
||||
ASSERT(frame >= 0);
|
||||
|
||||
Sprite* sprite = layer->sprite();
|
||||
|
||||
switch (layer->type()) {
|
||||
|
||||
case OBJECT_LAYER_IMAGE: {
|
||||
LayerImage* imglayer = static_cast<LayerImage*>(layer);
|
||||
|
||||
displaceFrames(imglayer, frame);
|
||||
|
||||
if (fromFrame >= frame)
|
||||
fromFrame = fromFrame.next();
|
||||
|
@ -69,6 +69,7 @@ namespace app {
|
||||
|
||||
// Frames API
|
||||
void addFrame(Sprite* sprite, FrameNumber newFrame);
|
||||
void addEmptyFrame(Sprite* sprite, FrameNumber newFrame);
|
||||
void copyFrame(Sprite* sprite, FrameNumber fromFrame, FrameNumber newFrame);
|
||||
void removeFrame(Sprite* sprite, FrameNumber frame);
|
||||
void setTotalFrames(Sprite* sprite, FrameNumber frames);
|
||||
@ -126,6 +127,7 @@ namespace app {
|
||||
private:
|
||||
undo::ObjectsContainer* getObjects() const;
|
||||
void setCelFramePosition(LayerImage* layer, Cel* cel, FrameNumber frame);
|
||||
void displaceFrames(Layer* layer, FrameNumber frame);
|
||||
void copyFrameForLayer(Layer* layer, FrameNumber fromFrame, FrameNumber frame);
|
||||
void removeFrameOfLayer(Layer* layer, FrameNumber frame);
|
||||
void moveFrameLayer(Layer* layer, FrameNumber frame, FrameNumber beforeFrame);
|
||||
|
Loading…
Reference in New Issue
Block a user