mirror of
https://bitbucket.org/mfeemster/fractorium.git
synced 2025-02-01 10:30:08 -05:00
Solving Gnome Palette Editor problem
This commit is contained in:
parent
4550f9dc87
commit
2d2d561e29
@ -21,6 +21,7 @@
|
||||
|
||||
class GLWidget;
|
||||
class QssDialog;
|
||||
class PaletteEditor; // michel
|
||||
class FractoriumOptionsDialog;
|
||||
class FractoriumVariationsDialog;
|
||||
class FractoriumFinalRenderDialog;
|
||||
@ -359,6 +360,7 @@ public slots:
|
||||
void OnPaletteEditorColorChanged();
|
||||
void OnPaletteEditorFileChanged();
|
||||
void OnPaletteEditorColorIndexChanged(size_t index, float value);
|
||||
void OnPaletteEditorFinished(int result); // michel
|
||||
|
||||
//Info.
|
||||
void OnSummaryTableHeaderResized(int logicalIndex, int oldSize, int newSize);
|
||||
|
@ -249,6 +249,7 @@ public:
|
||||
virtual void SetBasePaletteAndAdjust(const Palette<float>& palette) { }
|
||||
virtual void PaletteEditorButtonClicked() { }
|
||||
virtual void PaletteEditorColorChanged() { }
|
||||
virtual void SyncPalette(bool accepted) { } // michel
|
||||
QImage& FinalPaletteImage() { return m_FinalPaletteImage; }
|
||||
|
||||
//Info.
|
||||
@ -310,7 +311,7 @@ protected:
|
||||
unique_ptr<EmberNs::RendererBase> m_Renderer;
|
||||
QTIsaac<ISAAC_SIZE, ISAAC_INT> m_Rand;
|
||||
Fractorium* m_Fractorium;
|
||||
Palette<float> m_TempPalette;
|
||||
Palette<float> m_TempPalette, m_PreviosTempPalette; // michel
|
||||
std::unique_ptr<QTimer> m_RenderTimer;
|
||||
std::unique_ptr<QTimer> m_RenderRestartTimer;
|
||||
shared_ptr<PaletteList<float>> m_PaletteList;
|
||||
@ -537,6 +538,7 @@ public:
|
||||
virtual void SetBasePaletteAndAdjust(const Palette<float>& palette) override;
|
||||
virtual void PaletteEditorButtonClicked() override;
|
||||
virtual void PaletteEditorColorChanged() override;
|
||||
virtual void SyncPalette(bool accepted) override; // michel
|
||||
|
||||
//Info.
|
||||
virtual void FillSummary() override;
|
||||
|
@ -396,6 +396,12 @@ void FractoriumEmberController<T>::PaletteEditorButtonClicked()
|
||||
ed->SetColorIndices(colorIndices);
|
||||
ed->SetPaletteFile(m_CurrentPaletteFilePath);
|
||||
|
||||
// michel - waiting to be approved - may be used with IFDEF LINUX
|
||||
m_PreviosTempPalette = m_TempPalette;
|
||||
ed->SetPreviousColorIndices(colorIndices);
|
||||
ed->show();
|
||||
return;
|
||||
|
||||
//ed->setpal
|
||||
if (ed->exec() == QDialog::Accepted)
|
||||
{
|
||||
@ -448,6 +454,7 @@ void Fractorium::OnPaletteEditorButtonClicked(bool checked)
|
||||
connect(m_PaletteEditor, SIGNAL(PaletteChanged()), this, SLOT(OnPaletteEditorColorChanged()), Qt::QueuedConnection);
|
||||
connect(m_PaletteEditor, SIGNAL(PaletteFileChanged()), this, SLOT(OnPaletteEditorFileChanged()), Qt::QueuedConnection);
|
||||
connect(m_PaletteEditor, SIGNAL(ColorIndexChanged(size_t, float)), this, SLOT(OnPaletteEditorColorIndexChanged(size_t, float)), Qt::QueuedConnection);
|
||||
connect(m_PaletteEditor, SIGNAL(finished(int)), this, SLOT(OnPaletteEditorFinished(int)), Qt::QueuedConnection); // michel
|
||||
}
|
||||
|
||||
m_PaletteChanged = false;
|
||||
@ -455,6 +462,51 @@ void Fractorium::OnPaletteEditorButtonClicked(bool checked)
|
||||
m_Controller->PaletteEditorButtonClicked();
|
||||
}
|
||||
|
||||
// michel
|
||||
/// <summary>
|
||||
/// Slot called when palette editor window is closed.
|
||||
/// </summary>
|
||||
template <typename T>
|
||||
void FractoriumEmberController<T>::SyncPalette(bool accepted)
|
||||
{
|
||||
size_t i = 0;
|
||||
auto ed = m_Fractorium->m_PaletteEditor;
|
||||
Palette<float> edPal;
|
||||
Palette<float> prevPal = m_PreviosTempPalette;
|
||||
map<size_t, float> colorIndices;
|
||||
bool forceFinal = m_Fractorium->HaveFinal();
|
||||
|
||||
if (accepted)
|
||||
{
|
||||
//Copy all just to be safe, because they may or may not have synced.
|
||||
colorIndices = ed->GetColorIndices();
|
||||
|
||||
for (auto& index : colorIndices)
|
||||
if (auto xform = m_Ember.GetTotalXform(index.first, forceFinal))
|
||||
xform->m_ColorX = index.second;
|
||||
|
||||
edPal = ed->GetPalette(int(prevPal.Size()));
|
||||
SetBasePaletteAndAdjust(edPal);//This will take care of updating the color index controls.
|
||||
|
||||
if (edPal.m_Filename.get() && !edPal.m_Filename->empty())
|
||||
m_Fractorium->SetPaletteFileComboIndex(*edPal.m_Filename);
|
||||
}
|
||||
else if (m_Fractorium->PaletteChanged())//They clicked cancel, but synced at least once, restore the previous palette.
|
||||
{
|
||||
colorIndices = ed->GetPreviousColorIndices();
|
||||
|
||||
for (auto& index : colorIndices)
|
||||
if (auto xform = m_Ember.GetTotalXform(index.first, forceFinal))
|
||||
xform->m_ColorX = index.second;
|
||||
|
||||
SetBasePaletteAndAdjust(prevPal);//This will take care of updating the color index controls.
|
||||
}
|
||||
|
||||
//Whether the current palette file was changed or not, if it's modifiable then reload it just to be safe (even though it might be overkill).
|
||||
if (m_PaletteList->IsModifiable(m_CurrentPaletteFilePath))
|
||||
m_Fractorium->OnPaletteFilenameComboChanged(QString::fromStdString(m_CurrentPaletteFilePath));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Slot called every time a color is changed in the palette editor.
|
||||
/// </summary>
|
||||
@ -497,6 +549,15 @@ void Fractorium::OnPaletteEditorColorIndexChanged(size_t index, float value)
|
||||
OnXformColorIndexChanged(value, true, true, true, eXformUpdate::UPDATE_SPECIFIC, index);
|
||||
}
|
||||
|
||||
// michel
|
||||
/// Slot called after EditPallete is closed.
|
||||
/// </summary>
|
||||
/// <param name="result">Cancel/OK action</param>
|
||||
void Fractorium::OnPaletteEditorFinished(int result)
|
||||
{
|
||||
m_Controller->SyncPalette(result == QDialog::Accepted);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply the text in the palette filter text box to only show palettes whose names
|
||||
/// contain the substring.
|
||||
|
@ -117,6 +117,17 @@ map<size_t, float> PaletteEditor::GetColorIndices() const
|
||||
return m_GradientColorView->GetColorIndices();
|
||||
}
|
||||
|
||||
// michel
|
||||
/// <summary>
|
||||
/// Return the previous xform color indices as a map.
|
||||
/// The keys are the xform indices, and the values are the color indices.
|
||||
/// </summary>
|
||||
/// <returns>The color indices</returns>
|
||||
map<size_t, float> PaletteEditor::GetPreviousColorIndices() const
|
||||
{
|
||||
return m_PreviousColorIndices;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Assign the values of the xform color indices to the arrows.
|
||||
/// This will clear out any existing values first.
|
||||
@ -127,6 +138,16 @@ void PaletteEditor::SetColorIndices(const map<size_t, float>& indices)
|
||||
m_GradientColorView->SetColorIndices(indices);
|
||||
}
|
||||
|
||||
// michel
|
||||
/// <summary>
|
||||
/// Backup xform color
|
||||
/// </summary>
|
||||
/// <param name="indices">The color indices to backup</param>
|
||||
void PaletteEditor::SetPreviousColorIndices(const map<size_t, float>& indices)
|
||||
{
|
||||
m_PreviousColorIndices = indices;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the filename of the currently selected palette.
|
||||
/// Note this will only be filled in if the user has clicked in the palette
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "FractoriumPch.h"
|
||||
#include "Fractorium.h" // michel
|
||||
#include "ColorPickerWidget.h"
|
||||
#include "GradientColorsView.h"
|
||||
#include "EmberFile.h"
|
||||
@ -33,7 +34,9 @@ public:
|
||||
Palette<float>& GetPalette(int size);
|
||||
void SetPalette(const Palette<float>& palette);
|
||||
map<size_t, float> GetColorIndices() const;
|
||||
map<size_t, float> GetPreviousColorIndices() const; // michel
|
||||
void SetColorIndices(const map<size_t, float>& indices);
|
||||
void SetPreviousColorIndices(const map<size_t, float>& indices); // michel
|
||||
string GetPaletteFile() const;
|
||||
void SetPaletteFile(const string& filename);
|
||||
|
||||
@ -77,6 +80,7 @@ private:
|
||||
bool IsCurrentPaletteAndFileEditable();
|
||||
bool m_PaletteFileChanged = false;
|
||||
int m_PaletteIndex = 0;
|
||||
map<size_t, float> m_PreviousColorIndices; // michel
|
||||
QString m_Filename;
|
||||
string m_CurrentPaletteFilePath;
|
||||
ColorPickerWidget* m_ColorPicker = nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user