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
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/context_access.h"
|
2014-05-02 23:10:29 +08:00
|
|
|
#include "app/document_api.h"
|
2012-06-16 10:37:59 +08:00
|
|
|
#include "app/find_widget.h"
|
|
|
|
#include "app/load_widget.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/gui.h"
|
2015-01-19 09:05:33 +08:00
|
|
|
#include "app/transaction.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "base/mem_utils.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/cel.h"
|
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/layer.h"
|
|
|
|
#include "doc/sprite.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-08-21 10:42:05 +08:00
|
|
|
#include "generated_cel_properties.h"
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
|
|
|
|
2015-08-21 10:42:05 +08:00
|
|
|
class CelPropertiesWindow : public app::gen::CelProperties {
|
|
|
|
public:
|
|
|
|
CelPropertiesWindow() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class CelPropertiesCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
CelPropertiesCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new CelPropertiesCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
|
|
|
};
|
|
|
|
|
|
|
|
CelPropertiesCommand::CelPropertiesCommand()
|
|
|
|
: Command("CelProperties",
|
|
|
|
"Cel Properties",
|
|
|
|
CmdUIOnlyFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CelPropertiesCommand::onEnabled(Context* context)
|
|
|
|
{
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
ContextFlags::ActiveLayerIsImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CelPropertiesCommand::onExecute(Context* context)
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
const ContextReader reader(context);
|
|
|
|
const Sprite* sprite = reader.sprite();
|
|
|
|
const Layer* layer = reader.layer();
|
|
|
|
const Cel* cel = reader.cel(); // Get current cel (can be NULL)
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-08-21 10:42:05 +08:00
|
|
|
CelPropertiesWindow window;
|
|
|
|
ui::TooltipManager* tooltipManager = window.findFirstChildByType<ui::TooltipManager>();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-11-17 10:03:30 +08:00
|
|
|
// If the layer isn't writable
|
|
|
|
if (!layer->isEditable()) {
|
2015-08-21 10:42:05 +08:00
|
|
|
window.ok()->setText("Locked");
|
|
|
|
window.ok()->setEnabled(false);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2015-08-21 10:42:05 +08:00
|
|
|
window.frame()->setTextf("%d/%d",
|
|
|
|
(int)reader.frame()+1,
|
|
|
|
(int)sprite->totalFrames());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
if (cel != NULL) {
|
|
|
|
// Position
|
2015-08-21 10:42:05 +08:00
|
|
|
window.pos()->setTextf("%d, %d", cel->x(), cel->y());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Dimension (and memory size)
|
2014-07-30 12:28:15 +08:00
|
|
|
Image* image = cel->image();
|
|
|
|
int memsize = image->getRowStrideSize() * image->height();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-08-21 10:42:05 +08:00
|
|
|
window.size()->setTextf("%dx%d (%s)",
|
2014-07-30 12:28:15 +08:00
|
|
|
image->width(),
|
|
|
|
image->height(),
|
|
|
|
base::get_pretty_memory_size(memsize).c_str());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Opacity
|
2015-08-21 10:42:05 +08:00
|
|
|
window.opacity()->setValue(cel->opacity());
|
2013-01-11 23:43:25 +08:00
|
|
|
if (layer->isBackground()) {
|
2015-08-21 10:42:05 +08:00
|
|
|
window.opacity()->setEnabled(false);
|
|
|
|
tooltipManager->addTooltipFor(window.opacity(),
|
2014-08-10 05:04:53 +08:00
|
|
|
"The `Background' layer is opaque,\n"
|
|
|
|
"its opacity can't be changed.",
|
2015-06-24 01:00:00 +08:00
|
|
|
LEFT);
|
2014-08-10 05:04:53 +08:00
|
|
|
}
|
|
|
|
else if (sprite->pixelFormat() == IMAGE_INDEXED) {
|
2015-08-21 10:42:05 +08:00
|
|
|
window.opacity()->setEnabled(false);
|
|
|
|
tooltipManager->addTooltipFor(window.opacity(),
|
2014-08-10 05:04:53 +08:00
|
|
|
"Cel opacity of Indexed images\n"
|
|
|
|
"cannot be changed.",
|
2015-06-24 01:00:00 +08:00
|
|
|
LEFT);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-08-21 10:42:05 +08:00
|
|
|
window.pos()->setText("None");
|
|
|
|
window.size()->setText("Empty (0 bytes)");
|
|
|
|
window.opacity()->setValue(0);
|
|
|
|
window.opacity()->setEnabled(false);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2015-08-21 10:42:05 +08:00
|
|
|
window.openWindowInForeground();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-08-21 10:42:05 +08:00
|
|
|
if (window.getKiller() == window.ok()) {
|
2013-03-12 07:29:45 +08:00
|
|
|
ContextWriter writer(reader);
|
|
|
|
Document* document_writer = writer.document();
|
2014-05-02 23:10:29 +08:00
|
|
|
Sprite* sprite_writer = writer.sprite();
|
2013-03-12 07:29:45 +08:00
|
|
|
Cel* cel_writer = writer.cel();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-08-21 10:42:05 +08:00
|
|
|
int newOpacity = window.opacity()->getValue();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// The opacity was changed?
|
|
|
|
if (cel_writer != NULL &&
|
2014-07-30 12:28:15 +08:00
|
|
|
cel_writer->opacity() != newOpacity) {
|
2014-05-02 23:10:29 +08:00
|
|
|
{
|
2015-01-19 09:05:33 +08:00
|
|
|
Transaction transaction(writer.context(), "Cel Opacity Change", ModifyDocument);
|
|
|
|
document_writer->getApi(transaction)
|
|
|
|
.setCelOpacity(sprite_writer, cel_writer, newOpacity);
|
|
|
|
transaction.commit();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2013-01-21 05:40:37 +08:00
|
|
|
update_screen_for_document(document_writer);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createCelPropertiesCommand()
|
|
|
|
{
|
|
|
|
return new CelPropertiesCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|