From 73af9f1c3a2dcbb37179af1c49f1194684bfdf99 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 7 Jul 2012 14:20:43 -0300 Subject: [PATCH] Fix issue #130 - converting to grayscale wasn't adding an undoer to revert the new grayscale palette. --- src/undo_transaction.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/undo_transaction.cpp b/src/undo_transaction.cpp index 12552fecb..30583b376 100644 --- a/src/undo_transaction.cpp +++ b/src/undo_transaction.cpp @@ -37,6 +37,7 @@ #include "undoers/add_cel.h" #include "undoers/add_image.h" #include "undoers/add_layer.h" +#include "undoers/add_palette.h" #include "undoers/close_group.h" #include "undoers/dirty_area.h" #include "undoers/flip_image.h" @@ -270,18 +271,24 @@ void UndoTransaction::setPixelFormat(PixelFormat newFormat, DitheringMethod dith // Regenerate extras m_document->destroyExtraCel(); - // change "sprite.palette" + // When we are converting to grayscale color mode, we've to destroy + // all palettes and put only one grayscaled-palette at the first + // frame. if (newFormat == IMAGE_GRAYSCALE) { + // Add undoers to revert all palette changes. if (isEnabled()) { - // Save all palettes PalettesList palettes = m_sprite->getPalettes(); for (PalettesList::iterator it = palettes.begin(); it != palettes.end(); ++it) { Palette* palette = *it; m_undoHistory->pushUndoer(new undoers::RemovePalette( m_undoHistory->getObjects(), m_sprite, palette->getFrame())); } + + m_undoHistory->pushUndoer(new undoers::AddPalette( + m_undoHistory->getObjects(), m_sprite, 0)); } + // It's a UniquePtr because setPalette'll create a copy of "graypal". UniquePtr graypal(Palette::createGrayscale()); m_sprite->resetPalettes();