2015-02-12 23:16:25 +08:00
|
|
|
// 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.
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
#include "base/bind.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
2015-06-14 08:29:16 +08:00
|
|
|
#include "app/cmd/set_layer_blend_mode.h"
|
|
|
|
#include "app/cmd/set_layer_name.h"
|
2015-06-15 07:23:49 +08:00
|
|
|
#include "app/cmd/set_layer_opacity.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/context_access.h"
|
|
|
|
#include "app/modules/gui.h"
|
2015-06-14 08:29:16 +08:00
|
|
|
#include "app/transaction.h"
|
2015-06-15 06:07:06 +08:00
|
|
|
#include "doc/document.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/layer.h"
|
2015-06-15 06:07:06 +08:00
|
|
|
#include "doc/sprite.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-08-11 17:57:22 +08:00
|
|
|
#include "generated_layer_properties.h"
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2012-06-18 09:02:54 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
using namespace ui;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class LayerPropertiesCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
LayerPropertiesCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new LayerPropertiesCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
|
|
|
};
|
|
|
|
|
2015-06-15 06:07:06 +08:00
|
|
|
class LayerPropertiesWindow : public app::gen::LayerProperties {
|
|
|
|
public:
|
|
|
|
|
|
|
|
LayerPropertiesWindow(const LayerImage* layer)
|
|
|
|
: m_layer(const_cast<LayerImage*>(layer))
|
2015-06-15 07:23:49 +08:00
|
|
|
, m_oldBlendMode(layer->blendMode())
|
|
|
|
, m_oldOpacity(layer->opacity()) {
|
2015-06-15 06:07:06 +08:00
|
|
|
name()->setText(layer->name().c_str());
|
|
|
|
name()->setMinSize(gfx::Size(128, 0));
|
|
|
|
name()->setExpansive(true);
|
|
|
|
|
|
|
|
mode()->addItem("Normal");
|
|
|
|
mode()->addItem("Multiply");
|
|
|
|
mode()->addItem("Screen");
|
|
|
|
mode()->addItem("Overlay");
|
|
|
|
mode()->addItem("Darken");
|
|
|
|
mode()->addItem("Lighten");
|
|
|
|
mode()->addItem("Color Dodge");
|
|
|
|
mode()->addItem("Color Burn");
|
|
|
|
mode()->addItem("Hard Light");
|
|
|
|
mode()->addItem("Soft Light");
|
|
|
|
mode()->addItem("Difference");
|
|
|
|
mode()->addItem("Exclusion");
|
|
|
|
mode()->addItem("Hue");
|
|
|
|
mode()->addItem("Saturation");
|
|
|
|
mode()->addItem("Color");
|
|
|
|
mode()->addItem("Luminosity");
|
|
|
|
mode()->setSelectedItemIndex((int)layer->blendMode());
|
2015-06-15 07:23:49 +08:00
|
|
|
opacity()->setValue(layer->opacity());
|
|
|
|
|
2015-06-15 06:07:06 +08:00
|
|
|
mode()->setEnabled(!layer->isBackground());
|
2015-06-15 07:23:49 +08:00
|
|
|
opacity()->setEnabled(!layer->isBackground());
|
|
|
|
|
|
|
|
mode()->Change.connect(Bind<void>(&LayerPropertiesWindow::onLayerPropsChange, this));
|
|
|
|
opacity()->Change.connect(Bind<void>(&LayerPropertiesWindow::onLayerPropsChange, this));
|
2015-06-15 06:07:06 +08:00
|
|
|
|
|
|
|
remapWindow();
|
|
|
|
centerWindow();
|
|
|
|
load_window_pos(this, "LayerProperties");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string nameValue() const {
|
|
|
|
return name()->getText();
|
|
|
|
}
|
|
|
|
|
|
|
|
BlendMode blendModeValue() const {
|
|
|
|
return (BlendMode)mode()->getSelectedItemIndex();
|
|
|
|
}
|
|
|
|
|
2015-06-15 07:23:49 +08:00
|
|
|
int opacityValue() const {
|
|
|
|
return opacity()->getValue();
|
|
|
|
}
|
|
|
|
|
2015-06-15 06:07:06 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
bool onProcessMessage(ui::Message* msg) override {
|
|
|
|
switch (msg->type()) {
|
|
|
|
case kCloseMessage:
|
|
|
|
m_layer->setBlendMode(m_oldBlendMode);
|
2015-06-15 07:23:49 +08:00
|
|
|
m_layer->setOpacity(m_oldOpacity);
|
2015-06-15 06:07:06 +08:00
|
|
|
save_window_pos(this, "LayerProperties");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return Window::onProcessMessage(msg);
|
|
|
|
}
|
|
|
|
|
2015-06-15 07:23:49 +08:00
|
|
|
void onLayerPropsChange() {
|
2015-06-15 06:07:06 +08:00
|
|
|
m_layer->setBlendMode(blendModeValue());
|
2015-06-15 07:23:49 +08:00
|
|
|
m_layer->setOpacity(opacityValue());
|
|
|
|
|
2015-06-15 06:07:06 +08:00
|
|
|
update_screen_for_document(
|
|
|
|
static_cast<app::Document*>(m_layer->sprite()->document()));
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerImage* m_layer;
|
|
|
|
BlendMode m_oldBlendMode;
|
2015-06-15 07:23:49 +08:00
|
|
|
int m_oldOpacity;
|
2015-06-15 06:07:06 +08:00
|
|
|
};
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
LayerPropertiesCommand::LayerPropertiesCommand()
|
|
|
|
: Command("LayerProperties",
|
|
|
|
"Layer Properties",
|
|
|
|
CmdRecordableFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LayerPropertiesCommand::onEnabled(Context* context)
|
|
|
|
{
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
ContextFlags::HasActiveLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerPropertiesCommand::onExecute(Context* context)
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
const ContextReader reader(context);
|
2015-06-14 08:29:16 +08:00
|
|
|
const LayerImage* layer = static_cast<const LayerImage*>(reader.layer());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-06-15 06:07:06 +08:00
|
|
|
LayerPropertiesWindow window(layer);
|
2015-06-14 08:29:16 +08:00
|
|
|
|
2014-08-11 17:57:22 +08:00
|
|
|
window.openWindowInForeground();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-08-11 17:57:22 +08:00
|
|
|
if (window.getKiller() == window.ok()) {
|
2015-06-15 06:07:06 +08:00
|
|
|
std::string newName = window.nameValue();
|
2015-06-15 07:23:49 +08:00
|
|
|
int newOpacity = window.opacityValue();
|
2015-06-15 06:07:06 +08:00
|
|
|
BlendMode newBlendMode = window.blendModeValue();
|
2015-06-14 08:29:16 +08:00
|
|
|
|
|
|
|
if (newName != layer->name() ||
|
2015-06-15 07:23:49 +08:00
|
|
|
newOpacity != layer->opacity() ||
|
2015-06-14 08:29:16 +08:00
|
|
|
newBlendMode != layer->blendMode()) {
|
|
|
|
ContextWriter writer(reader);
|
|
|
|
{
|
|
|
|
Transaction transaction(writer.context(), "Set Layer Properties");
|
|
|
|
|
|
|
|
if (newName != layer->name())
|
|
|
|
transaction.execute(new cmd::SetLayerName(writer.layer(), newName));
|
|
|
|
|
2015-06-15 07:23:49 +08:00
|
|
|
if (newOpacity != layer->opacity())
|
|
|
|
transaction.execute(new cmd::SetLayerOpacity(static_cast<LayerImage*>(writer.layer()), newOpacity));
|
|
|
|
|
2015-06-14 08:29:16 +08:00
|
|
|
if (newBlendMode != layer->blendMode())
|
|
|
|
transaction.execute(new cmd::SetLayerBlendMode(static_cast<LayerImage*>(writer.layer()), newBlendMode));
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
}
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2015-06-15 06:07:06 +08:00
|
|
|
|
|
|
|
update_screen_for_document(reader.document());
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createLayerPropertiesCommand()
|
|
|
|
{
|
|
|
|
return new LayerPropertiesCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|