2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2013-01-27 23:13:13 +08:00
|
|
|
* Copyright (C) 2001-2013 David Capello
|
2012-01-06 06:45:03 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
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"
|
2014-05-03 07:00:26 +08:00
|
|
|
#include "app/undo_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"
|
|
|
|
#include "raster/image.h"
|
|
|
|
#include "raster/palette.h"
|
|
|
|
#include "raster/sprite.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-06-16 10:37:59 +08:00
|
|
|
#include <allegro/unicode.h>
|
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:
|
2012-07-10 04:36:45 +08:00
|
|
|
std::sprintf(buf, "Indexed (%d colors)", sprite->getPalette(FrameNumber(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)
|
|
|
|
usprintf(buf, "%dx%d (%s)",
|
2014-07-30 12:28:15 +08:00
|
|
|
sprite->width(),
|
|
|
|
sprite->height(),
|
2013-08-06 08:20:19 +08:00
|
|
|
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();
|
2014-07-30 12:28:15 +08:00
|
|
|
if (index != sprite->transparentColor()) {
|
2014-05-03 07:00:26 +08:00
|
|
|
UndoTransaction undoTransaction(writer.context(), "Set Transparent Color");
|
|
|
|
DocumentApi api = writer.document()->getApi();
|
|
|
|
api.setSpriteTransparentColor(sprite, index);
|
|
|
|
undoTransaction.commit();
|
|
|
|
|
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
|