2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2024-03-06 05:50:24 +08:00
|
|
|
// Copyright (C) 2018-2024 Igara Studio S.A.
|
2018-08-21 03:00:59 +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
|
|
|
|
2024-03-12 04:15:13 +08:00
|
|
|
#include "app/cmd/add_tileset.h"
|
2018-10-19 02:29:16 +08:00
|
|
|
#include "app/cmd/assign_color_profile.h"
|
|
|
|
#include "app/cmd/convert_color_profile.h"
|
2023-06-24 04:39:20 +08:00
|
|
|
#include "app/cmd/remove_tileset.h"
|
2016-05-24 23:25:11 +08:00
|
|
|
#include "app/cmd/set_pixel_ratio.h"
|
2020-12-16 01:00:44 +08:00
|
|
|
#include "app/cmd/set_user_data.h"
|
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"
|
2024-03-12 04:15:13 +08:00
|
|
|
#include "app/console.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/context_access.h"
|
2018-07-07 14:07:16 +08:00
|
|
|
#include "app/doc_api.h"
|
2018-12-14 02:25:31 +08:00
|
|
|
#include "app/i18n/strings.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/gui.h"
|
2018-10-19 02:29:16 +08:00
|
|
|
#include "app/pref/preferences.h"
|
2018-08-21 03:00:59 +08:00
|
|
|
#include "app/tx.h"
|
2016-05-24 23:25:11 +08:00
|
|
|
#include "app/ui/color_button.h"
|
2023-06-24 04:39:20 +08:00
|
|
|
#include "app/ui/skin/skin_theme.h"
|
2024-03-12 04:15:13 +08:00
|
|
|
#include "app/ui/user_data_view.h"
|
2016-05-24 23:25:11 +08:00
|
|
|
#include "app/util/pixel_ratio.h"
|
2024-03-12 04:15:13 +08:00
|
|
|
#include "app/util/tileset_utils.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "base/mem_utils.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/palette.h"
|
|
|
|
#include "doc/sprite.h"
|
2023-06-24 04:39:20 +08:00
|
|
|
#include "doc/tilesets.h"
|
2024-03-12 04:15:13 +08:00
|
|
|
#include "doc/user_data.h"
|
2018-10-19 02:29:16 +08:00
|
|
|
#include "os/color_space.h"
|
|
|
|
#include "os/system.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-09-23 03:33:49 +08:00
|
|
|
#include "sprite_properties.xml.h"
|
2015-06-22 22:20:10 +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
|
|
|
|
2023-06-24 04:39:20 +08:00
|
|
|
class TilesetListItem : public ui::ListItem {
|
|
|
|
public:
|
|
|
|
TilesetListItem(const doc::Tileset* tileset, doc::tileset_index tsi)
|
|
|
|
: ListItem(app::tileset_label(tileset, tsi))
|
|
|
|
{
|
|
|
|
m_buttons.setTransparent(true);
|
|
|
|
m_buttons.setExpansive(true);
|
|
|
|
m_buttons.setVisible(false);
|
|
|
|
|
|
|
|
auto filler = new BoxFiller();
|
|
|
|
filler->setTransparent(true);
|
|
|
|
m_buttons.addChild(filler);
|
|
|
|
|
|
|
|
auto theme = skin::SkinTheme::get(this);
|
|
|
|
auto duplicateBtn = new Button(Strings::sprite_properties_duplicate_tileset());
|
|
|
|
duplicateBtn->setStyle(theme->styles.miniButton());
|
|
|
|
duplicateBtn->setTransparent(true);
|
|
|
|
duplicateBtn->Click.connect([this, tileset] { onDuplicate(tileset); });
|
|
|
|
m_buttons.addChild(duplicateBtn);
|
|
|
|
|
|
|
|
auto deleteBtn = new Button(Strings::sprite_properties_delete_tileset());
|
|
|
|
deleteBtn->setStyle(theme->styles.miniButton());
|
|
|
|
deleteBtn->setTransparent(true);
|
|
|
|
deleteBtn->Click.connect([this, tileset] { onDelete(tileset); });
|
|
|
|
m_buttons.addChild(deleteBtn);
|
|
|
|
|
|
|
|
addChild(&m_buttons);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onProcessMessage(Message* msg) override
|
|
|
|
{
|
|
|
|
switch (msg->type()) {
|
|
|
|
case kMouseLeaveMessage:
|
|
|
|
m_buttons.setVisible(false);
|
|
|
|
invalidate();
|
|
|
|
break;
|
|
|
|
case kMouseEnterMessage:
|
|
|
|
m_buttons.setVisible(true);
|
|
|
|
invalidate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ui::ListItem::onProcessMessage(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
obs::signal<void(TilesetListItem*)> TilesetDeleted;
|
|
|
|
obs::signal<void(const Tileset*)> TilesetDuplicated;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onDuplicate(const doc::Tileset* tileset)
|
|
|
|
{
|
2023-12-13 08:34:30 +08:00
|
|
|
auto sprite = tileset->sprite();
|
2023-06-24 04:39:20 +08:00
|
|
|
auto tilesetClone = Tileset::MakeCopyCopyingImages(tileset);
|
|
|
|
|
2024-06-21 07:14:29 +08:00
|
|
|
Tx tx(sprite, Strings::commands_TilesetDuplicate());
|
2023-12-13 08:34:30 +08:00
|
|
|
tx(new cmd::AddTileset(sprite, tilesetClone));
|
2023-06-24 04:39:20 +08:00
|
|
|
tx.commit();
|
|
|
|
|
|
|
|
TilesetDuplicated(tilesetClone);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDelete(const doc::Tileset* tileset)
|
|
|
|
{
|
|
|
|
doc::tileset_index tsi = tileset->sprite()->tilesets()->getIndex(tileset);
|
|
|
|
std::string tilemapsNames;
|
|
|
|
for (auto layer : tileset->sprite()->allTilemaps()) {
|
|
|
|
auto tilemap = static_cast<doc::LayerTilemap*>(layer);
|
|
|
|
if (tilemap->tilesetIndex() == tsi) {
|
|
|
|
tilemapsNames += tilemap->name() + ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!tilemapsNames.empty()) {
|
|
|
|
tilemapsNames = tilemapsNames.substr(0, tilemapsNames.size() - 2);
|
2024-06-21 07:14:29 +08:00
|
|
|
ui::Alert::show(Strings::alerts_cannot_delete_used_tileset(tilemapsNames));
|
2023-06-24 04:39:20 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-13 08:34:30 +08:00
|
|
|
auto sprite = tileset->sprite();
|
2024-06-21 07:14:29 +08:00
|
|
|
Tx tx(sprite, Strings::commands_TilesetDelete());
|
2023-12-13 08:34:30 +08:00
|
|
|
tx(new cmd::RemoveTileset(sprite, tsi));
|
2023-06-24 04:39:20 +08:00
|
|
|
tx.commit();
|
|
|
|
|
|
|
|
TilesetDeleted(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui::HBox m_buttons;
|
|
|
|
};
|
|
|
|
|
2020-12-16 01:00:44 +08:00
|
|
|
class SpritePropertiesWindow : public app::gen::SpriteProperties {
|
|
|
|
public:
|
|
|
|
SpritePropertiesWindow(Sprite* sprite)
|
|
|
|
: SpriteProperties()
|
|
|
|
, m_sprite(sprite)
|
2022-05-20 05:56:21 +08:00
|
|
|
, m_userDataView(Preferences::instance().sprite.userDataVisibility)
|
2020-12-16 01:00:44 +08:00
|
|
|
{
|
|
|
|
userData()->Click.connect([this] { onToggleUserData(); });
|
|
|
|
|
2025-04-22 21:51:21 +08:00
|
|
|
useUuidForLayers()->setSelected(sprite->useLayerUuids());
|
2025-01-18 04:53:21 +08:00
|
|
|
|
2022-10-13 20:40:54 +08:00
|
|
|
m_userDataView.configureAndSet(m_sprite->userData(), propertiesGrid());
|
2020-12-16 01:00:44 +08:00
|
|
|
|
2023-06-24 04:39:20 +08:00
|
|
|
if (sprite->tilesets()->size() == 0) {
|
|
|
|
tilesetsPlaceholder()->parent()->removeChild(tilesetsPlaceholder());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (int i = 0; i < sprite->tilesets()->size(); ++i) {
|
|
|
|
auto tileset = (*sprite->tilesets()).get(i);
|
|
|
|
addTilesetListItem(tileset, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
Open.connect([this] { adjustSize(); });
|
|
|
|
}
|
2020-12-16 01:00:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const UserData& getUserData() const { return m_userDataView.userData(); }
|
|
|
|
|
2023-06-24 04:39:20 +08:00
|
|
|
protected:
|
|
|
|
virtual void onSizeHint(SizeHintEvent& ev) override
|
|
|
|
{
|
|
|
|
app::gen::SpriteProperties::onSizeHint(ev);
|
|
|
|
auto sz = ev.sizeHint();
|
|
|
|
sz.h += getTilesetsViewHeight();
|
|
|
|
ev.setSizeHint(sz);
|
|
|
|
}
|
|
|
|
|
2020-12-16 01:00:44 +08:00
|
|
|
private:
|
2023-06-24 04:39:20 +08:00
|
|
|
int getTilesetsViewHeight()
|
|
|
|
{
|
|
|
|
auto sz = tilesetsView()->viewport()->calculateNeededSize();
|
|
|
|
return std::min(72, sz.h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addTilesetListItem(const doc::Tileset* tileset, doc::tileset_index tsi)
|
|
|
|
{
|
|
|
|
auto item = new TilesetListItem(tileset, tsi);
|
|
|
|
item->TilesetDeleted.connect(&SpritePropertiesWindow::onTilesetDeleted, this);
|
|
|
|
item->TilesetDuplicated.connect(&SpritePropertiesWindow::onTilesedDuplicated, this);
|
|
|
|
tilesets()->addChild(item);
|
|
|
|
}
|
|
|
|
|
2020-12-16 01:00:44 +08:00
|
|
|
void onToggleUserData()
|
|
|
|
{
|
|
|
|
m_userDataView.toggleVisibility();
|
|
|
|
remapWindow();
|
|
|
|
manager()->invalidate();
|
|
|
|
}
|
|
|
|
|
2023-06-24 04:39:20 +08:00
|
|
|
void onTilesedDuplicated(const Tileset* tilesetClone)
|
|
|
|
{
|
|
|
|
addTilesetListItem(tilesetClone, tilesets()->children().size());
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void onTilesetDeleted(TilesetListItem* item)
|
|
|
|
{
|
|
|
|
int i = tilesets()->getChildIndex(item);
|
|
|
|
tilesets()->removeChild(item);
|
|
|
|
// Update text for items below the removed one, because tileset indexes
|
|
|
|
// have changed.
|
|
|
|
for (; i < tilesets()->children().size(); ++i) {
|
|
|
|
auto it = tilesets()->children()[i];
|
|
|
|
it->setText(app::tileset_label(m_sprite->tilesets()->get(i), i));
|
|
|
|
}
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void adjustSize()
|
|
|
|
{
|
|
|
|
// If the tilesets view is too small, lets inflate the windows height a bit.
|
|
|
|
if (tilesetsView()->childrenBounds().h < 36) {
|
|
|
|
auto bounds = this->bounds();
|
|
|
|
bounds.inflate(0, getTilesetsViewHeight() - tilesetsView()->clientBounds().h);
|
|
|
|
setBounds(bounds);
|
|
|
|
remapWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 01:00:44 +08:00
|
|
|
Sprite* m_sprite;
|
|
|
|
UserDataView m_userDataView;
|
|
|
|
};
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class SpritePropertiesCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
SpritePropertiesCommand();
|
|
|
|
|
|
|
|
protected:
|
2015-10-01 03:34:43 +08:00
|
|
|
bool onEnabled(Context* context) override;
|
|
|
|
void onExecute(Context* context) override;
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
2025-07-24 07:00:12 +08:00
|
|
|
SpritePropertiesCommand::SpritePropertiesCommand() : Command(CommandId::SpriteProperties())
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SpritePropertiesCommand::onEnabled(Context* context)
|
|
|
|
{
|
2025-07-24 07:00:12 +08:00
|
|
|
return context->isUIAvailable() && context->checkFlags(ContextFlags::ActiveDocumentIsWritable |
|
|
|
|
ContextFlags::HasActiveSprite);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpritePropertiesCommand::onExecute(Context* context)
|
|
|
|
{
|
2014-04-21 06:53:27 +08:00
|
|
|
std::string imgtype_text;
|
2018-10-19 02:29:16 +08:00
|
|
|
ColorButton* color_button = nullptr;
|
|
|
|
|
|
|
|
// List of available color profiles
|
2024-03-06 05:50:24 +08:00
|
|
|
const os::SystemRef system = os::System::instance();
|
2020-07-08 06:06:48 +08:00
|
|
|
std::vector<os::ColorSpaceRef> colorSpaces;
|
2024-03-06 05:50:24 +08:00
|
|
|
system->listColorSpaces(colorSpaces);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Load the window widget
|
2020-12-16 01:00:44 +08:00
|
|
|
SpritePropertiesWindow window(context->activeDocument()->sprite());
|
|
|
|
|
2018-10-19 02:29:16 +08:00
|
|
|
int selectedColorProfile = -1;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2019-04-02 01:11:42 +08:00
|
|
|
auto updateButtons = [&] {
|
|
|
|
bool enabled = (selectedColorProfile != window.colorProfile()->getSelectedItemIndex());
|
|
|
|
window.assignColorProfile()->setEnabled(enabled);
|
|
|
|
window.convertColorProfile()->setEnabled(enabled);
|
|
|
|
window.ok()->setEnabled(!enabled);
|
|
|
|
};
|
|
|
|
|
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);
|
2018-07-07 22:54:44 +08:00
|
|
|
const Doc* document(reader.document());
|
2013-03-12 07:29:45 +08:00
|
|
|
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()) {
|
2022-01-03 22:35:09 +08:00
|
|
|
case IMAGE_RGB: imgtype_text = Strings::sprite_properties_rgb(); break;
|
|
|
|
case IMAGE_GRAYSCALE: imgtype_text = Strings::sprite_properties_grayscale(); break;
|
2012-01-06 06:45:03 +08:00
|
|
|
case IMAGE_INDEXED:
|
2024-06-21 07:14:29 +08:00
|
|
|
imgtype_text = Strings::sprite_properties_indexed_color(sprite->palette(0)->size());
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ASSERT(false);
|
2022-01-10 15:13:19 +08:00
|
|
|
imgtype_text = Strings::general_unknown();
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filename
|
2015-06-22 22:20:10 +08:00
|
|
|
window.name()->setText(document->filename());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Color mode
|
2015-06-22 22:20:10 +08:00
|
|
|
window.type()->setText(imgtype_text.c_str());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Sprite size (width and height)
|
2015-06-22 22:20:10 +08:00
|
|
|
window.size()->setTextf("%dx%d (%s)",
|
2014-09-21 22:59:39 +08:00
|
|
|
sprite->width(),
|
|
|
|
sprite->height(),
|
|
|
|
base::get_pretty_memory_size(sprite->getMemSize()).c_str());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// How many frames
|
2015-06-22 22:20:10 +08:00
|
|
|
window.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()),
|
2016-09-13 04:53:01 +08:00
|
|
|
IMAGE_INDEXED,
|
2017-06-23 05:39:28 +08:00
|
|
|
ColorButtonOptions());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-06-22 22:20:10 +08:00
|
|
|
window.transparentColorPlaceholder()->addChild(color_button);
|
2018-12-14 02:25:31 +08:00
|
|
|
|
|
|
|
// TODO add a way to get or create an existent TooltipManager
|
|
|
|
TooltipManager* tooltipManager = new TooltipManager;
|
|
|
|
window.addChild(tooltipManager);
|
|
|
|
tooltipManager->addTooltipFor(color_button,
|
|
|
|
Strings::sprite_properties_transparent_color_tooltip(),
|
|
|
|
LEFT);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
else {
|
2022-01-03 22:35:09 +08:00
|
|
|
window.transparentColorPlaceholder()->addChild(
|
|
|
|
new Label(Strings::sprite_properties_indexed_image_only()));
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2016-05-24 23:25:11 +08:00
|
|
|
|
|
|
|
// Pixel ratio
|
|
|
|
window.pixelRatio()->setValue(base::convert_to<std::string>(sprite->pixelRatio()));
|
2018-10-19 02:29:16 +08:00
|
|
|
|
|
|
|
// Color profile
|
|
|
|
selectedColorProfile = -1;
|
|
|
|
int i = 0;
|
|
|
|
for (auto& cs : colorSpaces) {
|
|
|
|
if (cs->gfxColorSpace()->nearlyEqual(*sprite->colorSpace())) {
|
|
|
|
selectedColorProfile = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (selectedColorProfile < 0) {
|
2024-03-06 05:50:24 +08:00
|
|
|
colorSpaces.push_back(system->makeColorSpace(sprite->colorSpace()));
|
2018-10-19 02:29:16 +08:00
|
|
|
selectedColorProfile = colorSpaces.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& cs : colorSpaces)
|
|
|
|
window.colorProfile()->addItem(cs->gfxColorSpace()->name());
|
|
|
|
window.colorProfile()->setSelectedItemIndex(selectedColorProfile);
|
|
|
|
|
|
|
|
window.assignColorProfile()->setEnabled(false);
|
|
|
|
window.convertColorProfile()->setEnabled(false);
|
|
|
|
window.colorProfile()->Change.connect(updateButtons);
|
|
|
|
|
|
|
|
window.assignColorProfile()->Click.connect([&]() {
|
|
|
|
selectedColorProfile = window.colorProfile()->getSelectedItemIndex();
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2024-03-12 04:15:13 +08:00
|
|
|
try {
|
|
|
|
ContextWriter writer(context);
|
|
|
|
Sprite* sprite(writer.sprite());
|
|
|
|
Tx tx(writer, Strings::sprite_properties_assign_color_profile());
|
|
|
|
tx(new cmd::AssignColorProfile(sprite, colorSpaces[selectedColorProfile]->gfxColorSpace()));
|
|
|
|
tx.commit();
|
|
|
|
}
|
|
|
|
catch (const base::Exception& e) {
|
|
|
|
Console::showException(e);
|
|
|
|
}
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2018-10-19 02:29:16 +08:00
|
|
|
updateButtons();
|
|
|
|
});
|
|
|
|
window.convertColorProfile()->Click.connect([&]() {
|
|
|
|
selectedColorProfile = window.colorProfile()->getSelectedItemIndex();
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2024-03-12 04:15:13 +08:00
|
|
|
try {
|
|
|
|
ContextWriter writer(context);
|
|
|
|
Sprite* sprite(writer.sprite());
|
|
|
|
Tx tx(writer, Strings::sprite_properties_convert_color_profile());
|
|
|
|
tx(
|
|
|
|
new cmd::ConvertColorProfile(sprite, colorSpaces[selectedColorProfile]->gfxColorSpace()));
|
|
|
|
tx.commit();
|
|
|
|
}
|
|
|
|
catch (const base::Exception& e) {
|
|
|
|
Console::showException(e);
|
|
|
|
}
|
2024-12-17 01:52:19 +08:00
|
|
|
|
2018-10-19 02:29:16 +08:00
|
|
|
updateButtons();
|
|
|
|
});
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2015-06-22 22:20:10 +08:00
|
|
|
window.remapWindow();
|
|
|
|
window.centerWindow();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-06-22 22:20:10 +08:00
|
|
|
load_window_pos(&window, "SpriteProperties");
|
|
|
|
window.setVisible(true);
|
|
|
|
window.openWindowInForeground();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-12-05 01:54:15 +08:00
|
|
|
if (window.closer() == window.ok()) {
|
2016-05-24 23:25:11 +08:00
|
|
|
ContextWriter writer(context);
|
|
|
|
Sprite* sprite(writer.sprite());
|
|
|
|
|
|
|
|
color_t index = (color_button ? color_button->getColor().getIndex() :
|
|
|
|
sprite->transparentColor());
|
|
|
|
PixelRatio pixelRatio = base::convert_to<PixelRatio>(window.pixelRatio()->getValue());
|
|
|
|
|
2020-12-16 01:00:44 +08:00
|
|
|
const UserData newUserData = window.getUserData();
|
|
|
|
|
2025-04-22 21:51:21 +08:00
|
|
|
sprite->useLayerUuids(window.useUuidForLayers()->isSelected());
|
2025-01-18 04:53:21 +08:00
|
|
|
|
2016-05-24 23:25:11 +08:00
|
|
|
if (index != sprite->transparentColor() || pixelRatio != sprite->pixelRatio() ||
|
2020-12-16 01:00:44 +08:00
|
|
|
newUserData != sprite->userData()) {
|
2023-12-13 08:34:30 +08:00
|
|
|
Tx tx(writer, Strings::sprite_properties_change_sprite_props());
|
2018-08-21 03:00:59 +08:00
|
|
|
DocApi api = writer.document()->getApi(tx);
|
2016-05-24 23:25:11 +08:00
|
|
|
|
|
|
|
if (index != sprite->transparentColor())
|
2014-05-03 07:00:26 +08:00
|
|
|
api.setSpriteTransparentColor(sprite, index);
|
|
|
|
|
2016-05-24 23:25:11 +08:00
|
|
|
if (pixelRatio != sprite->pixelRatio())
|
2018-08-21 03:00:59 +08:00
|
|
|
tx(new cmd::SetPixelRatio(sprite, pixelRatio));
|
2016-05-24 23:25:11 +08:00
|
|
|
|
2020-12-16 01:00:44 +08:00
|
|
|
if (newUserData != sprite->userData())
|
|
|
|
tx(new cmd::SetUserData(sprite, newUserData, static_cast<Doc*>(sprite->document())));
|
|
|
|
|
2018-08-21 03:00:59 +08:00
|
|
|
tx.commit();
|
2016-05-24 23:25:11 +08:00
|
|
|
|
|
|
|
update_screen_for_document(writer.document());
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-22 22:20:10 +08:00
|
|
|
save_window_pos(&window, "SpriteProperties");
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createSpritePropertiesCommand()
|
|
|
|
{
|
|
|
|
return new SpritePropertiesCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|