2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2018-07-07 13:47:42 +08:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
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
|
|
|
|
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"
|
2015-12-11 05:34:25 +08:00
|
|
|
#include "app/cmd/set_user_data.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/command.h"
|
2015-08-21 11:44:28 +08:00
|
|
|
#include "app/console.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/context_access.h"
|
2018-07-07 13:47:42 +08:00
|
|
|
#include "app/doc_event.h"
|
|
|
|
#include "app/document.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/gui.h"
|
2015-06-14 08:29:16 +08:00
|
|
|
#include "app/transaction.h"
|
2017-07-25 02:13:32 +08:00
|
|
|
#include "app/ui/separator_in_view.h"
|
2017-03-27 00:33:12 +08:00
|
|
|
#include "app/ui/timeline/timeline.h"
|
2015-12-11 05:34:25 +08:00
|
|
|
#include "app/ui/user_data_popup.h"
|
2015-08-21 11:44:28 +08:00
|
|
|
#include "app/ui_context.h"
|
|
|
|
#include "base/bind.h"
|
|
|
|
#include "base/scoped_value.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"
|
2015-12-11 05:34:25 +08:00
|
|
|
#include "doc/user_data.h"
|
2015-08-21 11:44:28 +08:00
|
|
|
#include "ui/ui.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-09-23 03:33:49 +08:00
|
|
|
#include "layer_properties.xml.h"
|
2014-08-11 17:57:22 +08:00
|
|
|
|
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:
|
2015-08-21 11:44:28 +08:00
|
|
|
bool onEnabled(Context* context) override;
|
|
|
|
void onExecute(Context* context) override;
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
2015-08-21 11:44:28 +08:00
|
|
|
class LayerPropertiesWindow;
|
|
|
|
static LayerPropertiesWindow* g_window = nullptr;
|
2015-06-15 06:07:06 +08:00
|
|
|
|
2018-07-07 13:47:42 +08:00
|
|
|
class LayerPropertiesWindow : public app::gen::LayerProperties,
|
|
|
|
public ContextObserver,
|
|
|
|
public DocObserver {
|
2015-08-21 11:44:28 +08:00
|
|
|
public:
|
2017-07-25 02:13:32 +08:00
|
|
|
class BlendModeItem : public ListItem {
|
|
|
|
public:
|
|
|
|
BlendModeItem(const std::string& name,
|
|
|
|
const doc::BlendMode mode)
|
|
|
|
: ListItem(name)
|
|
|
|
, m_mode(mode) {
|
|
|
|
}
|
|
|
|
doc::BlendMode mode() const { return m_mode; }
|
|
|
|
private:
|
|
|
|
doc::BlendMode m_mode;
|
|
|
|
};
|
|
|
|
|
2015-08-21 11:44:28 +08:00
|
|
|
LayerPropertiesWindow()
|
|
|
|
: m_timer(250, this)
|
2017-04-06 03:01:18 +08:00
|
|
|
, m_document(nullptr)
|
2015-08-21 11:44:28 +08:00
|
|
|
, m_layer(nullptr)
|
|
|
|
, m_selfUpdate(false) {
|
2015-06-15 06:07:06 +08:00
|
|
|
name()->setMinSize(gfx::Size(128, 0));
|
|
|
|
name()->setExpansive(true);
|
|
|
|
|
2017-07-25 02:13:32 +08:00
|
|
|
mode()->addItem(new BlendModeItem("Normal", doc::BlendMode::NORMAL));
|
|
|
|
mode()->addItem(new SeparatorInView);
|
|
|
|
mode()->addItem(new BlendModeItem("Darken", doc::BlendMode::DARKEN));
|
|
|
|
mode()->addItem(new BlendModeItem("Multiply", doc::BlendMode::MULTIPLY));
|
|
|
|
mode()->addItem(new BlendModeItem("Color Burn", doc::BlendMode::COLOR_BURN));
|
|
|
|
mode()->addItem(new SeparatorInView);
|
|
|
|
mode()->addItem(new BlendModeItem("Lighten", doc::BlendMode::LIGHTEN));
|
|
|
|
mode()->addItem(new BlendModeItem("Screen", doc::BlendMode::SCREEN));
|
|
|
|
mode()->addItem(new BlendModeItem("Color Dodge", doc::BlendMode::COLOR_DODGE));
|
|
|
|
mode()->addItem(new BlendModeItem("Addition", doc::BlendMode::ADDITION));
|
|
|
|
mode()->addItem(new SeparatorInView);
|
|
|
|
mode()->addItem(new BlendModeItem("Overlay", doc::BlendMode::OVERLAY));
|
|
|
|
mode()->addItem(new BlendModeItem("Soft Light", doc::BlendMode::SOFT_LIGHT));
|
|
|
|
mode()->addItem(new BlendModeItem("Hard Light", doc::BlendMode::HARD_LIGHT));
|
|
|
|
mode()->addItem(new SeparatorInView);
|
|
|
|
mode()->addItem(new BlendModeItem("Difference", doc::BlendMode::DIFFERENCE));
|
|
|
|
mode()->addItem(new BlendModeItem("Exclusion", doc::BlendMode::EXCLUSION));
|
|
|
|
mode()->addItem(new BlendModeItem("Subtract", doc::BlendMode::SUBTRACT));
|
|
|
|
mode()->addItem(new BlendModeItem("Divide", doc::BlendMode::DIVIDE));
|
|
|
|
mode()->addItem(new SeparatorInView);
|
|
|
|
mode()->addItem(new BlendModeItem("Hue", doc::BlendMode::HSL_HUE));
|
|
|
|
mode()->addItem(new BlendModeItem("Saturation", doc::BlendMode::HSL_SATURATION));
|
|
|
|
mode()->addItem(new BlendModeItem("Color", doc::BlendMode::HSL_COLOR));
|
|
|
|
mode()->addItem(new BlendModeItem("Luminosity", doc::BlendMode::HSL_LUMINOSITY));
|
2015-06-15 07:23:49 +08:00
|
|
|
|
2015-12-05 02:17:42 +08:00
|
|
|
name()->Change.connect(base::Bind<void>(&LayerPropertiesWindow::onStartTimer, this));
|
|
|
|
mode()->Change.connect(base::Bind<void>(&LayerPropertiesWindow::onStartTimer, this));
|
|
|
|
opacity()->Change.connect(base::Bind<void>(&LayerPropertiesWindow::onStartTimer, this));
|
|
|
|
m_timer.Tick.connect(base::Bind<void>(&LayerPropertiesWindow::onCommitChange, this));
|
2015-12-11 05:34:25 +08:00
|
|
|
userData()->Click.connect(base::Bind<void>(&LayerPropertiesWindow::onPopupUserData, this));
|
2015-06-15 06:07:06 +08:00
|
|
|
|
|
|
|
remapWindow();
|
|
|
|
centerWindow();
|
|
|
|
load_window_pos(this, "LayerProperties");
|
2015-08-21 11:44:28 +08:00
|
|
|
|
2016-09-14 02:02:00 +08:00
|
|
|
UIContext::instance()->add_observer(this);
|
2015-08-21 11:44:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~LayerPropertiesWindow() {
|
2016-09-14 02:02:00 +08:00
|
|
|
UIContext::instance()->remove_observer(this);
|
2015-08-21 11:44:28 +08:00
|
|
|
}
|
|
|
|
|
2017-04-06 03:01:18 +08:00
|
|
|
void setLayer(Document* doc, Layer* layer) {
|
2015-08-21 11:44:28 +08:00
|
|
|
if (m_layer) {
|
2017-04-06 03:01:18 +08:00
|
|
|
m_document->remove_observer(this);
|
2015-08-21 11:44:28 +08:00
|
|
|
m_layer = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_timer.stop();
|
2017-04-06 03:01:18 +08:00
|
|
|
m_document = doc;
|
2016-06-16 03:13:12 +08:00
|
|
|
m_layer = layer;
|
2017-04-06 03:01:18 +08:00
|
|
|
m_range = App::instance()->timeline()->range();
|
2015-08-21 11:44:28 +08:00
|
|
|
|
2017-04-06 03:01:18 +08:00
|
|
|
if (m_document)
|
|
|
|
m_document->add_observer(this);
|
2015-08-21 11:44:28 +08:00
|
|
|
|
2015-08-21 22:03:59 +08:00
|
|
|
updateFromLayer();
|
2015-08-21 11:44:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2015-06-15 06:07:06 +08:00
|
|
|
std::string nameValue() const {
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
return name()->text();
|
2015-06-15 06:07:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
BlendMode blendModeValue() const {
|
2017-07-25 02:13:32 +08:00
|
|
|
BlendModeItem* item = dynamic_cast<BlendModeItem*>(mode()->getSelectedItem());
|
|
|
|
if (item)
|
|
|
|
return item->mode();
|
|
|
|
else
|
|
|
|
return doc::BlendMode::NORMAL;
|
2015-06-15 06:07:06 +08:00
|
|
|
}
|
|
|
|
|
2015-06-15 07:23:49 +08:00
|
|
|
int opacityValue() const {
|
|
|
|
return opacity()->getValue();
|
|
|
|
}
|
|
|
|
|
2017-04-06 03:01:18 +08:00
|
|
|
int countLayers() const {
|
|
|
|
if (!m_document)
|
|
|
|
return 0;
|
|
|
|
else if (m_layer && !m_range.enabled())
|
|
|
|
return 1;
|
|
|
|
else if (m_range.enabled())
|
|
|
|
return m_range.layers();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-15 06:07:06 +08:00
|
|
|
bool onProcessMessage(ui::Message* msg) override {
|
|
|
|
switch (msg->type()) {
|
2015-08-21 11:44:28 +08:00
|
|
|
|
2015-08-22 01:53:31 +08:00
|
|
|
case kKeyDownMessage:
|
|
|
|
if (name()->hasFocus() ||
|
|
|
|
opacity()->hasFocus() ||
|
|
|
|
mode()->hasFocus()) {
|
2016-10-24 05:48:16 +08:00
|
|
|
KeyScancode scancode = static_cast<KeyMessage*>(msg)->scancode();
|
|
|
|
if (scancode == kKeyEnter ||
|
|
|
|
scancode == kKeyEsc) {
|
2015-08-22 01:53:31 +08:00
|
|
|
onCommitChange();
|
|
|
|
closeWindow(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-06-15 06:07:06 +08:00
|
|
|
case kCloseMessage:
|
2015-08-21 11:44:28 +08:00
|
|
|
// Save changes before we close the window
|
2017-04-06 03:01:18 +08:00
|
|
|
setLayer(nullptr, nullptr);
|
2015-06-15 06:07:06 +08:00
|
|
|
save_window_pos(this, "LayerProperties");
|
2015-08-21 11:44:28 +08:00
|
|
|
|
|
|
|
deferDelete();
|
|
|
|
g_window = nullptr;
|
2015-06-15 06:07:06 +08:00
|
|
|
break;
|
2015-08-21 11:44:28 +08:00
|
|
|
|
2015-06-15 06:07:06 +08:00
|
|
|
}
|
|
|
|
return Window::onProcessMessage(msg);
|
|
|
|
}
|
|
|
|
|
2015-08-21 22:03:59 +08:00
|
|
|
void onStartTimer() {
|
2015-08-21 11:44:28 +08:00
|
|
|
if (m_selfUpdate)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_timer.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void onCommitChange() {
|
2016-09-13 04:53:01 +08:00
|
|
|
// Nothing to do here, as there is no layer selected.
|
|
|
|
if (!m_layer)
|
|
|
|
return;
|
|
|
|
|
2015-08-21 11:44:28 +08:00
|
|
|
base::ScopedValue<bool> switchSelf(m_selfUpdate, true, false);
|
|
|
|
|
|
|
|
m_timer.stop();
|
|
|
|
|
2017-04-06 03:01:18 +08:00
|
|
|
const int count = countLayers();
|
|
|
|
|
2015-08-21 11:44:28 +08:00
|
|
|
std::string newName = nameValue();
|
|
|
|
int newOpacity = opacityValue();
|
|
|
|
BlendMode newBlendMode = blendModeValue();
|
|
|
|
|
2017-04-06 03:01:18 +08:00
|
|
|
if ((count > 1) ||
|
|
|
|
(count == 1 && m_layer && (newName != m_layer->name() ||
|
|
|
|
m_userData != m_layer->userData() ||
|
|
|
|
(m_layer->isImage() &&
|
|
|
|
(newOpacity != static_cast<LayerImage*>(m_layer)->opacity() ||
|
|
|
|
newBlendMode != static_cast<LayerImage*>(m_layer)->blendMode()))))) {
|
2015-08-21 11:44:28 +08:00
|
|
|
try {
|
|
|
|
ContextWriter writer(UIContext::instance());
|
|
|
|
Transaction transaction(writer.context(), "Set Layer Properties");
|
|
|
|
|
2018-07-07 21:07:21 +08:00
|
|
|
DocRange range;
|
2017-04-06 03:01:18 +08:00
|
|
|
if (m_range.enabled())
|
|
|
|
range = m_range;
|
|
|
|
else {
|
2018-07-07 21:07:21 +08:00
|
|
|
range.startRange(m_layer, -1, DocRange::kLayers);
|
2017-04-06 03:01:18 +08:00
|
|
|
range.endRange(m_layer, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool nameChanged = (newName != m_layer->name());
|
|
|
|
const bool userDataChanged = (m_userData != m_layer->userData());
|
|
|
|
const bool opacityChanged = (m_layer->isImage() && newOpacity != static_cast<LayerImage*>(m_layer)->opacity());
|
|
|
|
const bool blendModeChanged = (m_layer->isImage() && newBlendMode != static_cast<LayerImage*>(m_layer)->blendMode());
|
2015-08-21 11:44:28 +08:00
|
|
|
|
2017-04-06 03:01:18 +08:00
|
|
|
for (Layer* layer : range.selectedLayers()) {
|
|
|
|
if (nameChanged && newName != layer->name())
|
|
|
|
transaction.execute(new cmd::SetLayerName(layer, newName));
|
2015-12-11 05:34:25 +08:00
|
|
|
|
2017-04-06 03:01:18 +08:00
|
|
|
if (userDataChanged && m_userData != layer->userData())
|
|
|
|
transaction.execute(new cmd::SetUserData(layer, m_userData));
|
2016-06-16 03:13:12 +08:00
|
|
|
|
2017-04-06 03:01:18 +08:00
|
|
|
if (layer->isImage()) {
|
|
|
|
if (opacityChanged && newOpacity != static_cast<LayerImage*>(layer)->opacity())
|
|
|
|
transaction.execute(new cmd::SetLayerOpacity(static_cast<LayerImage*>(layer), newOpacity));
|
|
|
|
|
|
|
|
if (blendModeChanged && newBlendMode != static_cast<LayerImage*>(layer)->blendMode())
|
|
|
|
transaction.execute(new cmd::SetLayerBlendMode(static_cast<LayerImage*>(layer), newBlendMode));
|
|
|
|
}
|
2016-06-16 03:13:12 +08:00
|
|
|
}
|
|
|
|
|
2016-08-26 04:57:03 +08:00
|
|
|
// Redraw timeline because the layer's name/user data/color
|
|
|
|
// might have changed.
|
|
|
|
App::instance()->timeline()->invalidate();
|
2015-12-23 00:18:08 +08:00
|
|
|
|
2015-08-21 11:44:28 +08:00
|
|
|
transaction.commit();
|
|
|
|
}
|
|
|
|
catch (const std::exception& e) {
|
|
|
|
Console::showException(e);
|
|
|
|
}
|
|
|
|
|
2017-04-06 03:01:18 +08:00
|
|
|
update_screen_for_document(m_document);
|
2015-08-21 11:44:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContextObserver impl
|
|
|
|
void onActiveSiteChange(const Site& site) override {
|
|
|
|
if (isVisible())
|
2017-04-06 03:01:18 +08:00
|
|
|
setLayer(const_cast<Document*>(static_cast<const Document*>(site.document())),
|
|
|
|
const_cast<Layer*>(site.layer()));
|
2015-08-21 11:44:28 +08:00
|
|
|
else if (m_layer)
|
2017-04-06 03:01:18 +08:00
|
|
|
setLayer(nullptr, nullptr);
|
2015-08-21 11:44:28 +08:00
|
|
|
}
|
|
|
|
|
2018-07-07 08:06:03 +08:00
|
|
|
// DocObserver impl
|
|
|
|
void onLayerNameChange(DocEvent& ev) override {
|
2015-08-21 22:03:59 +08:00
|
|
|
if (m_layer == ev.layer())
|
|
|
|
updateFromLayer();
|
2015-08-21 11:44:28 +08:00
|
|
|
}
|
|
|
|
|
2018-07-07 08:06:03 +08:00
|
|
|
void onLayerOpacityChange(DocEvent& ev) override {
|
2015-08-21 22:03:59 +08:00
|
|
|
if (m_layer == ev.layer())
|
|
|
|
updateFromLayer();
|
2015-08-21 11:44:28 +08:00
|
|
|
}
|
2015-06-15 07:23:49 +08:00
|
|
|
|
2018-07-07 08:06:03 +08:00
|
|
|
void onLayerBlendModeChange(DocEvent& ev) override {
|
2015-08-21 22:03:59 +08:00
|
|
|
if (m_layer == ev.layer())
|
|
|
|
updateFromLayer();
|
2015-06-15 06:07:06 +08:00
|
|
|
}
|
|
|
|
|
2015-12-11 05:34:25 +08:00
|
|
|
void onPopupUserData() {
|
|
|
|
if (m_layer) {
|
2015-12-12 00:58:32 +08:00
|
|
|
m_userData = m_layer->userData();
|
2015-12-11 05:34:25 +08:00
|
|
|
if (show_user_data_popup(userData()->bounds(), m_userData)) {
|
2015-12-12 00:58:32 +08:00
|
|
|
onCommitChange();
|
2015-12-11 05:34:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-21 22:03:59 +08:00
|
|
|
void updateFromLayer() {
|
2015-08-21 11:44:28 +08:00
|
|
|
if (m_selfUpdate)
|
|
|
|
return;
|
|
|
|
|
2015-08-21 22:03:59 +08:00
|
|
|
m_timer.stop(); // Cancel current editions (just in case)
|
|
|
|
|
|
|
|
base::ScopedValue<bool> switchSelf(m_selfUpdate, true, false);
|
|
|
|
|
|
|
|
if (m_layer) {
|
|
|
|
name()->setText(m_layer->name().c_str());
|
|
|
|
name()->setEnabled(true);
|
2016-06-16 03:13:12 +08:00
|
|
|
|
|
|
|
if (m_layer->isImage()) {
|
2017-07-25 02:13:32 +08:00
|
|
|
mode()->setSelectedItem(nullptr);
|
|
|
|
for (auto item : *mode()) {
|
|
|
|
if (auto blendModeItem = dynamic_cast<BlendModeItem*>(item)) {
|
|
|
|
if (blendModeItem->mode() == static_cast<LayerImage*>(m_layer)->blendMode()) {
|
|
|
|
mode()->setSelectedItem(item);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-16 03:13:12 +08:00
|
|
|
mode()->setEnabled(!m_layer->isBackground());
|
|
|
|
opacity()->setValue(static_cast<LayerImage*>(m_layer)->opacity());
|
|
|
|
opacity()->setEnabled(!m_layer->isBackground());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mode()->setEnabled(false);
|
|
|
|
opacity()->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2015-12-11 05:34:25 +08:00
|
|
|
m_userData = m_layer->userData();
|
2015-08-21 22:03:59 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
name()->setText("No Layer");
|
|
|
|
name()->setEnabled(false);
|
|
|
|
mode()->setEnabled(false);
|
|
|
|
opacity()->setEnabled(false);
|
2015-12-11 05:34:25 +08:00
|
|
|
m_userData = UserData();
|
2015-08-21 22:03:59 +08:00
|
|
|
}
|
2015-08-21 11:44:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Timer m_timer;
|
2017-04-06 03:01:18 +08:00
|
|
|
Document* m_document;
|
2016-06-16 03:13:12 +08:00
|
|
|
Layer* m_layer;
|
2018-07-07 21:07:21 +08:00
|
|
|
DocRange m_range;
|
2015-08-21 11:44:28 +08:00
|
|
|
bool m_selfUpdate;
|
2015-12-11 05:34:25 +08:00
|
|
|
UserData m_userData;
|
2015-06-15 06:07:06 +08:00
|
|
|
};
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
LayerPropertiesCommand::LayerPropertiesCommand()
|
2017-12-02 02:10:21 +08:00
|
|
|
: Command(CommandId::LayerProperties(), CmdRecordableFlag)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LayerPropertiesCommand::onEnabled(Context* context)
|
|
|
|
{
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
ContextFlags::HasActiveLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LayerPropertiesCommand::onExecute(Context* context)
|
|
|
|
{
|
2015-08-21 11:44:28 +08:00
|
|
|
ContextReader reader(context);
|
2017-04-06 03:01:18 +08:00
|
|
|
Document* doc = static_cast<Document*>(reader.document());
|
2015-08-21 11:44:28 +08:00
|
|
|
LayerImage* layer = static_cast<LayerImage*>(reader.layer());
|
2015-06-14 08:29:16 +08:00
|
|
|
|
2015-08-21 11:44:28 +08:00
|
|
|
if (!g_window)
|
|
|
|
g_window = new LayerPropertiesWindow;
|
2015-06-15 06:07:06 +08:00
|
|
|
|
2017-04-06 03:01:18 +08:00
|
|
|
g_window->setLayer(doc, layer);
|
2015-08-21 11:44:28 +08:00
|
|
|
g_window->openWindow();
|
2015-08-21 19:27:13 +08:00
|
|
|
|
|
|
|
// Focus layer name
|
|
|
|
g_window->name()->requestFocus();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createLayerPropertiesCommand()
|
|
|
|
{
|
|
|
|
return new LayerPropertiesCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|