From e8f4c61fa7d776d39e1727c6da7e8d5eeb3a1f66 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 9 Aug 2011 21:45:22 -0300 Subject: [PATCH] Palette editor now is redrawn when the palette changes externally (e.g. by undo/redo actions). --- src/commands/cmd_palette_editor.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/commands/cmd_palette_editor.cpp b/src/commands/cmd_palette_editor.cpp index a2f71127d..53e101356 100644 --- a/src/commands/cmd_palette_editor.cpp +++ b/src/commands/cmd_palette_editor.cpp @@ -90,6 +90,7 @@ private: void setNewPalette(Palette* palette, const char* operationName); void updateCurrentSpritePalette(const char* operationName); void updateColorBar(); + void onPalChange(); Box m_vbox; Box m_topBox; @@ -114,6 +115,8 @@ private: int m_redrawTimerId; bool m_redrawAll; + + Signal0::SlotType* m_palChangeSlot; }; ////////////////////////////////////////////////////////////////////// @@ -128,8 +131,8 @@ public: Command* clone() { return new PaletteEditorCommand(*this); } protected: - void onLoadParams(Params* params); - void onExecute(Context* context); + void onLoadParams(Params* params) OVERRIDE; + void onExecute(Context* context) OVERRIDE; private: bool m_open; @@ -304,6 +307,10 @@ PaletteEntryEditor::PaletteEntryEditor() // We hook App::Exit signal to destroy the g_frame singleton at exit. App::instance()->Exit.connect(&PaletteEntryEditor::onExit, this); + // Hook for palette change to redraw the palette editor frame + m_palChangeSlot = + App::instance()->PaletteChange.connect(&PaletteEntryEditor::onPalChange, this); + initTheme(); } @@ -311,6 +318,8 @@ PaletteEntryEditor::~PaletteEntryEditor() { jmanager_remove_timer(m_redrawTimerId); m_redrawTimerId = -1; + + App::instance()->PaletteChange.disconnect(m_palChangeSlot); } void PaletteEntryEditor::setColor(const Color& color) @@ -725,6 +734,15 @@ void PaletteEntryEditor::updateColorBar() app_get_colorbar()->invalidate(); } +void PaletteEntryEditor::onPalChange() +{ + PaletteView* palette_editor = app_get_colorbar()->getPaletteView(); + setColor(Color::fromIndex(palette_editor->getSelectedEntry())); + + // Redraw the window + invalidate(); +} + ////////////////////////////////////////////////////////////////////// // CommandFactory