本文整理汇总了C++中DocumentApi::setSpriteTransparentColor方法的典型用法代码示例。如果您正苦于以下问题:C++ DocumentApi::setSpriteTransparentColor方法的具体用法?C++ DocumentApi::setSpriteTransparentColor怎么用?C++ DocumentApi::setSpriteTransparentColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentApi
的用法示例。
在下文中一共展示了DocumentApi::setSpriteTransparentColor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onExecute
void SpritePropertiesCommand::onExecute(Context* context)
{
std::string imgtype_text;
char buf[256];
ColorButton* color_button = NULL;
// Load the window widget
app::gen::SpriteProperties window;
// Get sprite properties and fill frame fields
{
const ContextReader reader(context);
const Document* document(reader.document());
const Sprite* sprite(reader.sprite());
// Update widgets values
switch (sprite->pixelFormat()) {
case IMAGE_RGB:
imgtype_text = "RGB";
break;
case IMAGE_GRAYSCALE:
imgtype_text = "Grayscale";
break;
case IMAGE_INDEXED:
std::sprintf(buf, "Indexed (%d colors)", sprite->palette(0)->size());
imgtype_text = buf;
break;
default:
ASSERT(false);
imgtype_text = "Unknown";
break;
}
// Filename
window.name()->setText(document->filename());
// Color mode
window.type()->setText(imgtype_text.c_str());
// Sprite size (width and height)
window.size()->setTextf(
"%dx%d (%s)",
sprite->width(),
sprite->height(),
base::get_pretty_memory_size(sprite->getMemSize()).c_str());
// How many frames
window.frames()->setTextf("%d", (int)sprite->totalFrames());
if (sprite->pixelFormat() == IMAGE_INDEXED) {
color_button = new ColorButton(app::Color::fromIndex(sprite->transparentColor()),
IMAGE_INDEXED);
window.transparentColorPlaceholder()->addChild(color_button);
}
else {
window.transparentColorPlaceholder()->addChild(new Label("(only for indexed images)"));
}
}
window.remapWindow();
window.centerWindow();
load_window_pos(&window, "SpriteProperties");
window.setVisible(true);
window.openWindowInForeground();
if (window.closer() == window.ok()) {
if (color_button) {
ContextWriter writer(context);
Sprite* sprite(writer.sprite());
// If the transparent color index has changed, we update the
// property in the sprite.
int index = color_button->getColor().getIndex();
if (color_t(index) != sprite->transparentColor()) {
Transaction transaction(writer.context(), "Set Transparent Color");
DocumentApi api = writer.document()->getApi(transaction);
api.setSpriteTransparentColor(sprite, index);
transaction.commit();
update_screen_for_document(writer.document());
}
}
}
save_window_pos(&window, "SpriteProperties");
}