mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-01 01:20:25 +00:00
Add "Edit > New Sprite from Selection" command
This commit is contained in:
parent
383fd3f1ae
commit
e35f85bff7
@ -350,6 +350,7 @@
|
||||
</key>
|
||||
|
||||
<key command="NewBrush" shortcut="Ctrl+B" mac="Cmd+B" />
|
||||
<key command="NewSpriteFromSelection" shortcut="Ctrl+Alt+N" mac="Cmd+Alt+N" />
|
||||
</commands>
|
||||
|
||||
<!-- Keyboard shortcuts to select tools -->
|
||||
@ -479,8 +480,7 @@
|
||||
<param name="orientation" value="vertical" />
|
||||
</item>
|
||||
<item command="MaskContent" text="Transfor&m" />
|
||||
<item command="NewBrush" text="New &Brush" />
|
||||
<menu text="Shift">
|
||||
<menu text="&Shift">
|
||||
<item command="MoveMask" text="&Left">
|
||||
<param name="target" value="content" />
|
||||
<param name="direction" value="left" />
|
||||
@ -511,6 +511,9 @@
|
||||
</item>
|
||||
</menu>
|
||||
<separator />
|
||||
<item command="NewBrush" text="New &Brush" />
|
||||
<item command="NewSpriteFromSelection" text="&New Sprite from Selection" />
|
||||
<separator />
|
||||
<item command="ReplaceColor" text="R&eplace Color..." />
|
||||
<item command="InvertColor" text="&Invert" />
|
||||
<menu text="F&X" id="fx_popup">
|
||||
|
@ -200,6 +200,7 @@ add_library(app-lib
|
||||
commands/cmd_new_frame_tag.cpp
|
||||
commands/cmd_new_layer.cpp
|
||||
commands/cmd_new_layer_set.cpp
|
||||
commands/cmd_new_sprite_from_selection.cpp
|
||||
commands/cmd_onionskin.cpp
|
||||
commands/cmd_open_file.cpp
|
||||
commands/cmd_open_in_folder.cpp
|
||||
|
98
src/app/commands/cmd_new_sprite_from_selection.cpp
Normal file
98
src/app/commands/cmd_new_sprite_from_selection.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
// 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/commands/command.h"
|
||||
#include "app/context.h"
|
||||
#include "app/document.h"
|
||||
#include "app/util/new_image_from_mask.h"
|
||||
#include "base/path.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/mask.h"
|
||||
#include "doc/palette.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/site.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "doc/document.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace app {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
class NewSpriteFromSelectionCommand : public Command {
|
||||
public:
|
||||
NewSpriteFromSelectionCommand();
|
||||
Command* clone() const override { return new NewSpriteFromSelectionCommand(*this); }
|
||||
|
||||
protected:
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
};
|
||||
|
||||
NewSpriteFromSelectionCommand::NewSpriteFromSelectionCommand()
|
||||
: Command("NewSpriteFromSelection",
|
||||
"New Sprite From Selection",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
|
||||
bool NewSpriteFromSelectionCommand::onEnabled(Context* context)
|
||||
{
|
||||
return context->checkFlags(ContextFlags::ActiveDocumentIsReadable |
|
||||
ContextFlags::HasVisibleMask);
|
||||
}
|
||||
|
||||
void NewSpriteFromSelectionCommand::onExecute(Context* context)
|
||||
{
|
||||
const Site site = context->activeSite();
|
||||
const app::Document* doc = static_cast<const app::Document*>(site.document());
|
||||
const Sprite* sprite = site.sprite();
|
||||
const Mask* mask = doc->mask();
|
||||
ImageRef image(
|
||||
new_image_from_mask(site, mask));
|
||||
if (!image)
|
||||
return;
|
||||
|
||||
Palette* palette = sprite->palette(site.frame());
|
||||
|
||||
base::UniquePtr<Sprite> dstSprite(
|
||||
Sprite::createBasicSprite(image->pixelFormat(),
|
||||
image->width(),
|
||||
image->height(),
|
||||
palette->size()));
|
||||
|
||||
palette->copyColorsTo(dstSprite->palette(frame_t(0)));
|
||||
|
||||
LayerImage* dstLayer = static_cast<LayerImage*>(dstSprite->folder()->getFirstLayer());
|
||||
dstLayer->setFlags(site.layer()->flags()); // Copy all flags
|
||||
if (site.layer()->isBackground())
|
||||
dstLayer->configureAsBackground(); // Configure layer name as background
|
||||
copy_image(dstLayer->cel(frame_t(0))->image(), image.get());
|
||||
|
||||
base::UniquePtr<Document> dstDoc(new Document(dstSprite));
|
||||
dstSprite.release();
|
||||
char buf[1024];
|
||||
std::sprintf(buf, "%s-%dx%d-%dx%d",
|
||||
base::get_file_title(doc->filename()).c_str(),
|
||||
mask->bounds().x, mask->bounds().y,
|
||||
mask->bounds().w, mask->bounds().h);
|
||||
dstDoc->setFilename(buf);
|
||||
dstDoc->setContext(context);
|
||||
dstDoc.release();
|
||||
}
|
||||
|
||||
Command* CommandFactory::createNewSpriteFromSelectionCommand()
|
||||
{
|
||||
return new NewSpriteFromSelectionCommand();
|
||||
}
|
||||
|
||||
} // namespace app
|
@ -75,6 +75,7 @@ FOR_EACH_COMMAND(NewFrame)
|
||||
FOR_EACH_COMMAND(NewFrameTag)
|
||||
FOR_EACH_COMMAND(NewLayer)
|
||||
FOR_EACH_COMMAND(NewLayerSet)
|
||||
FOR_EACH_COMMAND(NewSpriteFromSelection)
|
||||
FOR_EACH_COMMAND(OpenFile)
|
||||
FOR_EACH_COMMAND(OpenInFolder)
|
||||
FOR_EACH_COMMAND(OpenWithApp)
|
||||
|
Loading…
x
Reference in New Issue
Block a user