mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-10 01:13:49 +00:00
Merge NewGroup command into NewLayer command
This commit is contained in:
parent
33d7f6509f
commit
f6fa39ba52
@ -664,7 +664,9 @@
|
||||
<item command="LayerVisibility" text="&Visible" />
|
||||
<separator />
|
||||
<item command="NewLayer" text="&New Layer" />
|
||||
<item command="NewGroup" text="New &Group" />
|
||||
<item command="NewLayer" text="New &Group">
|
||||
<param name="group" value="true" />
|
||||
</item>
|
||||
<item command="RemoveLayer" text="&Remove Layer" />
|
||||
<item command="BackgroundFromLayer" text="&Background from Layer" />
|
||||
<item command="LayerFromBackground" text="&Layer from Background" />
|
||||
|
@ -17,16 +17,4 @@
|
||||
</box>
|
||||
</box>
|
||||
</window>
|
||||
<window text="New Group" id="new_layer_set">
|
||||
<box vertical="true">
|
||||
<box horizontal="true">
|
||||
<label text="Name:" />
|
||||
<entry maxsize="256" text="New Group" id="name" expansive="true" />
|
||||
</box>
|
||||
<box horizontal="true" homogeneous="true">
|
||||
<button text="&OK" closewindow="true" id="ok" magnet="true" width="60" />
|
||||
<button text="&Cancel" closewindow="true" />
|
||||
</box>
|
||||
</box>
|
||||
</window>
|
||||
</gui>
|
||||
|
@ -228,7 +228,6 @@ add_library(app-lib
|
||||
commands/cmd_new_file.cpp
|
||||
commands/cmd_new_frame.cpp
|
||||
commands/cmd_new_frame_tag.cpp
|
||||
commands/cmd_new_group.cpp
|
||||
commands/cmd_new_layer.cpp
|
||||
commands/cmd_new_sprite_from_selection.cpp
|
||||
commands/cmd_onionskin.cpp
|
||||
|
@ -1,87 +0,0 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2016 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/commands/command.h"
|
||||
#include "app/context_access.h"
|
||||
#include "app/document_api.h"
|
||||
#include "app/document_api.h"
|
||||
#include "app/find_widget.h"
|
||||
#include "app/load_widget.h"
|
||||
#include "app/modules/gui.h"
|
||||
#include "app/ui/status_bar.h"
|
||||
#include "app/transaction.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
using namespace ui;
|
||||
|
||||
class NewGroupCommand : public Command {
|
||||
public:
|
||||
NewGroupCommand();
|
||||
Command* clone() const override { return new NewGroupCommand(*this); }
|
||||
|
||||
protected:
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
};
|
||||
|
||||
NewGroupCommand::NewGroupCommand()
|
||||
: Command("NewGroup",
|
||||
"New Layer Group",
|
||||
CmdRecordableFlag)
|
||||
{
|
||||
}
|
||||
|
||||
bool NewGroupCommand::onEnabled(Context* context)
|
||||
{
|
||||
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
||||
ContextFlags::HasActiveSprite);
|
||||
}
|
||||
|
||||
void NewGroupCommand::onExecute(Context* context)
|
||||
{
|
||||
ContextWriter writer(context);
|
||||
Document* document(writer.document());
|
||||
Sprite* sprite(writer.sprite());
|
||||
|
||||
// load the window widget
|
||||
base::UniquePtr<Window> window(app::load_widget<Window>("new_layer.xml", "new_layer_set"));
|
||||
|
||||
window->openWindowInForeground();
|
||||
|
||||
if (window->closer() != window->findChild("ok"))
|
||||
return;
|
||||
|
||||
std::string name = window->findChild("name")->text();
|
||||
Layer* layer;
|
||||
{
|
||||
Transaction transaction(writer.context(), "New Group");
|
||||
layer = document->getApi(transaction).newLayerGroup(sprite);
|
||||
transaction.commit();
|
||||
}
|
||||
layer->setName(name);
|
||||
|
||||
update_screen_for_document(document);
|
||||
|
||||
StatusBar::instance()->invalidate();
|
||||
StatusBar::instance()->showTip(1000, "Group `%s' created", name.c_str());
|
||||
}
|
||||
|
||||
Command* CommandFactory::createNewGroupCommand()
|
||||
{
|
||||
return new NewGroupCommand;
|
||||
}
|
||||
|
||||
} // namespace app
|
@ -24,6 +24,8 @@
|
||||
#include "doc/sprite.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
#include "new_layer.xml.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
@ -42,14 +44,16 @@ protected:
|
||||
void onExecute(Context* context) override;
|
||||
|
||||
private:
|
||||
std::string getUniqueLayerName(const Sprite* sprite) const;
|
||||
int getMaxLayerNum(const Layer* layer) const;
|
||||
const char* layerPrefix() const;
|
||||
|
||||
bool m_ask;
|
||||
bool m_top;
|
||||
bool m_group;
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
static std::string get_unique_layer_name(Sprite* sprite);
|
||||
static int get_max_layer_num(Layer* layer);
|
||||
|
||||
NewLayerCommand::NewLayerCommand()
|
||||
: Command("NewLayer",
|
||||
"New Layer",
|
||||
@ -57,6 +61,7 @@ NewLayerCommand::NewLayerCommand()
|
||||
{
|
||||
m_ask = false;
|
||||
m_top = false;
|
||||
m_group = false;
|
||||
m_name = "";
|
||||
}
|
||||
|
||||
@ -64,6 +69,7 @@ void NewLayerCommand::onLoadParams(const Params& params)
|
||||
{
|
||||
m_ask = (params.get("ask") == "true");
|
||||
m_top = (params.get("top") == "true");
|
||||
m_group = (params.get("group") == "true");
|
||||
m_name = params.get("name");
|
||||
}
|
||||
|
||||
@ -84,29 +90,32 @@ void NewLayerCommand::onExecute(Context* context)
|
||||
if (!m_name.empty())
|
||||
name = m_name;
|
||||
else
|
||||
name = get_unique_layer_name(sprite);
|
||||
name = getUniqueLayerName(sprite);
|
||||
|
||||
// If params specify to ask the user about the name...
|
||||
if (m_ask) {
|
||||
// We open the window to ask the name
|
||||
base::UniquePtr<Window> window(app::load_widget<Window>("new_layer.xml", "new_layer"));
|
||||
Widget* name_widget = app::find_widget<Widget>(window, "name");
|
||||
name_widget->setText(name.c_str());
|
||||
name_widget->setMinSize(gfx::Size(128, 0));
|
||||
|
||||
window->openWindowInForeground();
|
||||
|
||||
if (window->closer() != window->findChild("ok"))
|
||||
app::gen::NewLayer window;
|
||||
window.name()->setText(name.c_str());
|
||||
window.name()->setMinSize(gfx::Size(128, 0));
|
||||
window.openWindowInForeground();
|
||||
if (window.closer() != window.ok())
|
||||
return;
|
||||
|
||||
name = window->findChild("name")->text();
|
||||
name = window.name()->text();
|
||||
}
|
||||
|
||||
Layer* activeLayer = writer.layer();
|
||||
Layer* layer;
|
||||
{
|
||||
Transaction transaction(writer.context(), "New Layer");
|
||||
Transaction transaction(
|
||||
writer.context(),
|
||||
std::string("New ") + layerPrefix());
|
||||
DocumentApi api = document->getApi(transaction);
|
||||
|
||||
if (m_group)
|
||||
layer = api.newGroup(sprite, name);
|
||||
else
|
||||
layer = api.newLayer(sprite, name);
|
||||
|
||||
// If "top" parameter is false, create the layer above the active
|
||||
@ -119,31 +128,38 @@ void NewLayerCommand::onExecute(Context* context)
|
||||
update_screen_for_document(document);
|
||||
|
||||
StatusBar::instance()->invalidate();
|
||||
StatusBar::instance()->showTip(1000, "Layer `%s' created", name.c_str());
|
||||
StatusBar::instance()->showTip(
|
||||
1000, "%s '%s' created",
|
||||
layerPrefix(),
|
||||
name.c_str());
|
||||
|
||||
App::instance()->mainWindow()->popTimeline();
|
||||
}
|
||||
|
||||
static std::string get_unique_layer_name(Sprite* sprite)
|
||||
std::string NewLayerCommand::getUniqueLayerName(const Sprite* sprite) const
|
||||
{
|
||||
char buf[1024];
|
||||
std::sprintf(buf, "Layer %d", get_max_layer_num(sprite->root())+1);
|
||||
std::sprintf(buf, "%s %d",
|
||||
layerPrefix(),
|
||||
getMaxLayerNum(sprite->root())+1);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static int get_max_layer_num(Layer* layer)
|
||||
int NewLayerCommand::getMaxLayerNum(const Layer* layer) const
|
||||
{
|
||||
int max = 0;
|
||||
std::string prefix = layerPrefix();
|
||||
prefix += " ";
|
||||
|
||||
if (std::strncmp(layer->name().c_str(), "Layer ", 6) == 0)
|
||||
max = std::strtol(layer->name().c_str()+6, NULL, 10);
|
||||
int max = 0;
|
||||
if (std::strncmp(layer->name().c_str(), prefix.c_str(), prefix.size()) == 0)
|
||||
max = std::strtol(layer->name().c_str()+prefix.size(), NULL, 10);
|
||||
|
||||
if (layer->isGroup()) {
|
||||
LayerIterator it = static_cast<LayerGroup*>(layer)->getLayerBegin();
|
||||
LayerIterator end = static_cast<LayerGroup*>(layer)->getLayerEnd();
|
||||
auto it = static_cast<const LayerGroup*>(layer)->getLayerBegin();
|
||||
auto end = static_cast<const LayerGroup*>(layer)->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
int tmp = get_max_layer_num(*it);
|
||||
int tmp = getMaxLayerNum(*it);
|
||||
max = MAX(tmp, max);
|
||||
}
|
||||
}
|
||||
@ -151,6 +167,11 @@ static int get_max_layer_num(Layer* layer)
|
||||
return max;
|
||||
}
|
||||
|
||||
const char* NewLayerCommand::layerPrefix() const
|
||||
{
|
||||
return (m_group ? "Group": "Layer");
|
||||
}
|
||||
|
||||
Command* CommandFactory::createNewLayerCommand()
|
||||
{
|
||||
return new NewLayerCommand;
|
||||
|
@ -78,7 +78,6 @@ FOR_EACH_COMMAND(NewBrush)
|
||||
FOR_EACH_COMMAND(NewFile)
|
||||
FOR_EACH_COMMAND(NewFrame)
|
||||
FOR_EACH_COMMAND(NewFrameTag)
|
||||
FOR_EACH_COMMAND(NewGroup)
|
||||
FOR_EACH_COMMAND(NewLayer)
|
||||
FOR_EACH_COMMAND(NewSpriteFromSelection)
|
||||
FOR_EACH_COMMAND(OpenFile)
|
||||
|
@ -407,9 +407,10 @@ LayerImage* DocumentApi::newLayer(Sprite* sprite, const std::string& name)
|
||||
return layer;
|
||||
}
|
||||
|
||||
LayerGroup* DocumentApi::newLayerGroup(Sprite* sprite)
|
||||
LayerGroup* DocumentApi::newGroup(Sprite* sprite, const std::string& name)
|
||||
{
|
||||
LayerGroup* layer = new LayerGroup(sprite);
|
||||
layer->setName(name);
|
||||
|
||||
addLayer(sprite->root(), layer,
|
||||
sprite->root()->lastLayer());
|
||||
|
@ -81,7 +81,7 @@ namespace app {
|
||||
|
||||
// Layers API
|
||||
LayerImage* newLayer(Sprite* sprite, const std::string& name);
|
||||
LayerGroup* newLayerGroup(Sprite* sprite);
|
||||
LayerGroup* newGroup(Sprite* sprite, const std::string& name);
|
||||
void addLayer(LayerGroup* folder, Layer* newLayer, Layer* afterThis);
|
||||
void removeLayer(Layer* layer);
|
||||
void restackLayerAfter(Layer* layer, Layer* afterThis);
|
||||
|
Loading…
x
Reference in New Issue
Block a user