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 "app/color.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/context_access.h"
|
2014-05-03 07:00:26 +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"
|
|
|
|
#include "app/ui/color_button.h"
|
2015-01-19 09:05:33 +08:00
|
|
|
#include "app/transaction.h"
|
2012-06-16 10:37:59 +08:00
|
|
|
#include "base/bind.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "base/mem_utils.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/palette.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
|
|
|
|
2012-07-10 04:36:45 +08:00
|
|
|
#include <cstdio>
|
2012-06-16 10:37:59 +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 SpritePropertiesCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
SpritePropertiesCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new SpritePropertiesCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool onEnabled(Context* context);
|
|
|
|
void onExecute(Context* context);
|
|
|
|
};
|
|
|
|
|
|
|
|
SpritePropertiesCommand::SpritePropertiesCommand()
|
|
|
|
: Command("SpriteProperties",
|
|
|
|
"Sprite Properties",
|
|
|
|
CmdUIOnlyFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SpritePropertiesCommand::onEnabled(Context* context)
|
|
|
|
{
|
|
|
|
return context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
ContextFlags::HasActiveSprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpritePropertiesCommand::onExecute(Context* context)
|
|
|
|
{
|
2012-06-16 11:05:01 +08:00
|
|
|
Widget* name, *type, *size, *frames, *ok, *box_transparent;
|
2014-04-21 06:53:27 +08:00
|
|
|
std::string imgtype_text;
|
2012-01-06 06:45:03 +08:00
|
|
|
char buf[256];
|
|
|
|
ColorButton* color_button = NULL;
|
|
|
|
|
|
|
|
// Load the window widget
|
2013-08-06 08:20:19 +08:00
|
|
|
base::UniquePtr<Window> window(app::load_widget<Window>("sprite_properties.xml", "sprite_properties"));
|
2012-06-16 10:37:59 +08:00
|
|
|
name = app::find_widget<Widget>(window, "name");
|
|
|
|
type = app::find_widget<Widget>(window, "type");
|
|
|
|
size = app::find_widget<Widget>(window, "size");
|
|
|
|
frames = app::find_widget<Widget>(window, "frames");
|
|
|
|
ok = app::find_widget<Widget>(window, "ok");
|
|
|
|
box_transparent = app::find_widget<Widget>(window, "box_transparent");
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Get sprite properties and fill frame fields
|
|
|
|
{
|
2013-03-12 07:29:45 +08:00
|
|
|
const ContextReader reader(context);
|
|
|
|
const Document* document(reader.document());
|
|
|
|
const Sprite* sprite(reader.sprite());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Update widgets values
|
2014-07-30 12:28:15 +08:00
|
|
|
switch (sprite->pixelFormat()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
case IMAGE_RGB:
|
|
|
|
imgtype_text = "RGB";
|
|
|
|
break;
|
|
|
|
case IMAGE_GRAYSCALE:
|
|
|
|
imgtype_text = "Grayscale";
|
|
|
|
break;
|
|
|
|
case IMAGE_INDEXED:
|
2014-12-29 07:39:11 +08:00
|
|
|
std::sprintf(buf, "Indexed (%d colors)", sprite->palette(0)->size());
|
2012-01-06 06:45:03 +08:00
|
|
|
imgtype_text = buf;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ASSERT(false);
|
|
|
|
imgtype_text = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filename
|
2014-07-29 11:53:24 +08:00
|
|
|
name->setText(document->filename());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Color mode
|
|
|
|
type->setText(imgtype_text.c_str());
|
|
|
|
|
|
|
|
// Sprite size (width and height)
|
2014-09-21 22:59:39 +08:00
|
|
|
sprintf(buf, "%dx%d (%s)",
|
|
|
|
sprite->width(),
|
|
|
|
sprite->height(),
|
|
|
|
base::get_pretty_memory_size(sprite->getMemSize()).c_str());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
size->setText(buf);
|
|
|
|
|
|
|
|
// How many frames
|
2014-07-30 12:28:15 +08:00
|
|
|
frames->setTextf("%d", (int)sprite->totalFrames());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-07-30 12:28:15 +08:00
|
|
|
if (sprite->pixelFormat() == IMAGE_INDEXED) {
|
|
|
|
color_button = new ColorButton(app::Color::fromIndex(sprite->transparentColor()),
|
2012-01-06 06:45:03 +08:00
|
|
|
IMAGE_INDEXED);
|
|
|
|
|
|
|
|
box_transparent->addChild(color_button);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
box_transparent->addChild(new Label("(only for indexed images)"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:43:25 +08:00
|
|
|
window->remapWindow();
|
|
|
|
window->centerWindow();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
load_window_pos(window, "SpriteProperties");
|
|
|
|
window->setVisible(true);
|
2012-07-09 10:24:42 +08:00
|
|
|
window->openWindowInForeground();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-01-11 23:43:25 +08:00
|
|
|
if (window->getKiller() == ok) {
|
2012-01-06 06:45:03 +08:00
|
|
|
if (color_button) {
|
2013-03-12 07:29:45 +08:00
|
|
|
ContextWriter writer(context);
|
|
|
|
Sprite* sprite(writer.sprite());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// If the transparent color index has changed, we update the
|
|
|
|
// property in the sprite.
|
|
|
|
int index = color_button->getColor().getIndex();
|
2015-03-06 02:19:00 +08:00
|
|
|
if (color_t(index) != sprite->transparentColor()) {
|
2015-01-19 09:05:33 +08:00
|
|
|
Transaction transaction(writer.context(), "Set Transparent Color");
|
|
|
|
DocumentApi api = writer.document()->getApi(transaction);
|
2014-05-03 07:00:26 +08:00
|
|
|
api.setSpriteTransparentColor(sprite, index);
|
2015-01-19 09:05:33 +08:00
|
|
|
transaction.commit();
|
2014-05-03 07:00:26 +08:00
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
update_screen_for_document(writer.document());
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
save_window_pos(window, "SpriteProperties");
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createSpritePropertiesCommand()
|
|
|
|
{
|
|
|
|
return new SpritePropertiesCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|