2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2014-08-10 05:04:53 +08:00
|
|
|
* Copyright (C) 2001-2014 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
|
|
|
|
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"
|
|
|
|
#include "app/undo_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
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
|
|
|
|
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
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
base::UniquePtr<Window> window(app::load_widget<Window>("cel_properties.xml", "cel_properties"));
|
2012-06-16 10:37:59 +08:00
|
|
|
Widget* label_frame = app::find_widget<Widget>(window, "frame");
|
|
|
|
Widget* label_pos = app::find_widget<Widget>(window, "pos");
|
|
|
|
Widget* label_size = app::find_widget<Widget>(window, "size");
|
|
|
|
Slider* slider_opacity = app::find_widget<Slider>(window, "opacity");
|
|
|
|
Widget* button_ok = app::find_widget<Widget>(window, "ok");
|
2012-06-18 09:02:54 +08:00
|
|
|
ui::TooltipManager* tooltipManager = window->findFirstChildByType<ui::TooltipManager>();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Mini look for the opacity slider
|
|
|
|
setup_mini_look(slider_opacity);
|
|
|
|
|
2014-11-17 10:03:30 +08:00
|
|
|
// If the layer isn't writable
|
|
|
|
if (!layer->isEditable()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
button_ok->setText("Locked");
|
|
|
|
button_ok->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2012-07-10 04:36:02 +08:00
|
|
|
label_frame->setTextf("%d/%d",
|
2013-03-12 07:29:45 +08:00
|
|
|
(int)reader.frame()+1,
|
2014-07-30 12:28:15 +08:00
|
|
|
(int)sprite->totalFrames());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
if (cel != NULL) {
|
|
|
|
// Position
|
2014-07-30 12:28:15 +08:00
|
|
|
label_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
|
|
|
|
|
|
|
label_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
|
2014-07-30 12:28:15 +08:00
|
|
|
slider_opacity->setValue(cel->opacity());
|
2013-01-11 23:43:25 +08:00
|
|
|
if (layer->isBackground()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
slider_opacity->setEnabled(false);
|
2012-06-16 10:37:59 +08:00
|
|
|
tooltipManager->addTooltipFor(slider_opacity,
|
2014-08-10 05:04:53 +08:00
|
|
|
"The `Background' layer is opaque,\n"
|
|
|
|
"its opacity can't be changed.",
|
|
|
|
JI_LEFT);
|
|
|
|
}
|
|
|
|
else if (sprite->pixelFormat() == IMAGE_INDEXED) {
|
|
|
|
slider_opacity->setEnabled(false);
|
|
|
|
tooltipManager->addTooltipFor(slider_opacity,
|
|
|
|
"Cel opacity of Indexed images\n"
|
|
|
|
"cannot be changed.",
|
|
|
|
JI_LEFT);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
label_pos->setText("None");
|
|
|
|
label_size->setText("Empty (0 bytes)");
|
|
|
|
slider_opacity->setValue(0);
|
|
|
|
slider_opacity->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
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() == button_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
|
|
|
|
2014-05-02 23:10:29 +08:00
|
|
|
int newOpacity = slider_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
|
|
|
DocumentApi api = document_writer->getApi();
|
|
|
|
{
|
|
|
|
UndoTransaction undo(writer.context(), "Cel Opacity Change", undo::ModifyDocument);
|
|
|
|
api.setCelOpacity(sprite_writer, cel_writer, newOpacity);
|
2012-07-08 12:25:26 +08:00
|
|
|
undo.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
|