Merged mfeemster/fractorium into master

This commit is contained in:
Michel Mastriani 2019-05-21 20:50:24 -03:00
commit 6f42938bd7
5 changed files with 50 additions and 53 deletions

View File

@ -360,7 +360,7 @@ public slots:
void OnPaletteEditorColorChanged();
void OnPaletteEditorFileChanged();
void OnPaletteEditorColorIndexChanged(size_t index, float value);
void OnPaletteEditorFinished(int result);
void OnPaletteEditorFinished(int result);
//Info.
void OnSummaryTableHeaderResized(int logicalIndex, int oldSize, int newSize);

View File

@ -249,7 +249,7 @@ public:
virtual void SetBasePaletteAndAdjust(const Palette<float>& palette) { }
virtual void PaletteEditorButtonClicked() { }
virtual void PaletteEditorColorChanged() { }
virtual void SyncPalette(bool accepted) { }
virtual void SyncPalette(bool accepted) { }
QImage& FinalPaletteImage() { return m_FinalPaletteImage; }
//Info.
@ -311,7 +311,7 @@ protected:
unique_ptr<EmberNs::RendererBase> m_Renderer;
QTIsaac<ISAAC_SIZE, ISAAC_INT> m_Rand;
Fractorium* m_Fractorium;
Palette<float> m_TempPalette, m_PreviosTempPalette;
Palette<float> m_TempPalette, m_PreviousTempPalette;
std::unique_ptr<QTimer> m_RenderTimer;
std::unique_ptr<QTimer> m_RenderRestartTimer;
shared_ptr<PaletteList<float>> m_PaletteList;
@ -538,7 +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;
virtual void SyncPalette(bool accepted) override;
//Info.
virtual void FillSummary() override;

View File

@ -385,23 +385,20 @@ void FractoriumEmberController<T>::PaletteEditorButtonClicked()
size_t i = 0;
auto ed = m_Fractorium->m_PaletteEditor;
map<size_t, float> colorIndices;
bool forceFinal = m_Fractorium->HaveFinal();
m_PreviosTempPalette = m_TempPalette; // it's necessary because m_TempPalette is changed when the user make changes in palette editor
ed->SetPalette(m_TempPalette);
bool forceFinal = m_Fractorium->HaveFinal();
m_PreviousTempPalette = m_TempPalette; // it's necessary because m_TempPalette is changed when the user make changes in palette editor
ed->SetPalette(m_TempPalette);
while (auto xform = m_Ember.GetTotalXform(i, forceFinal))
colorIndices[i++] = xform->m_ColorX;
ed->SetColorIndices(colorIndices);
ed->SetPreviousColorIndices(colorIndices); // also necessary because the colors are changed in palette editor
ed->SetPreviousColorIndices(colorIndices); // also necessary because the colors are changed in palette editor
ed->SetPaletteFile(m_CurrentPaletteFilePath);
#ifdef __linux__
ed->show();
ed->show();
#else
SyncPalette(ed->exec() == QDialog::Accepted);
SyncPalette(ed->exec() == QDialog::Accepted);
#endif
}
@ -423,12 +420,12 @@ void Fractorium::OnPaletteEditorButtonClicked(bool checked)
{
if (!m_PaletteEditor)
{
m_PaletteEditor = new PaletteEditor(this);
m_PaletteEditor = new PaletteEditor(this);
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);
#ifdef __linux__
connect(m_PaletteEditor, SIGNAL(finished(int)), this, SLOT(OnPaletteEditorFinished(int)), Qt::QueuedConnection);
connect(m_PaletteEditor, SIGNAL(finished(int)), this, SLOT(OnPaletteEditorFinished(int)), Qt::QueuedConnection);
#endif
}
@ -443,42 +440,42 @@ void Fractorium::OnPaletteEditorButtonClicked(bool checked)
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();
size_t i = 0;
auto ed = m_Fractorium->m_PaletteEditor;
Palette<float> edPal;
Palette<float> prevPal = m_PreviousTempPalette;
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();
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;
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.
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();
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;
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.
}
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));
//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>
@ -528,7 +525,7 @@ void Fractorium::OnPaletteEditorColorIndexChanged(size_t index, float value)
/// <param name="result">Cancel/OK action</param>
void Fractorium::OnPaletteEditorFinished(int result)
{
m_Controller->SyncPalette(result == QDialog::Accepted);
m_Controller->SyncPalette(result == QDialog::Accepted);
}
/// <summary>

View File

@ -124,7 +124,7 @@ map<size_t, float> PaletteEditor::GetColorIndices() const
/// <returns>The color indices</returns>
map<size_t, float> PaletteEditor::GetPreviousColorIndices() const
{
return m_PreviousColorIndices;
return m_PreviousColorIndices;
}
/// <summary>
@ -143,7 +143,7 @@ void PaletteEditor::SetColorIndices(const map<size_t, float>& indices)
/// <param name="indices">The color indices to backup</param>
void PaletteEditor::SetPreviousColorIndices(const map<size_t, float>& indices)
{
m_PreviousColorIndices = indices;
m_PreviousColorIndices = indices;
}
/// <summary>

View File

@ -27,16 +27,16 @@ class PaletteEditor : public QDialog
Q_OBJECT
public:
explicit PaletteEditor(QWidget* p = nullptr);
explicit PaletteEditor(QWidget* p = nullptr);
public:
bool Sync();
Palette<float>& GetPalette(int size);
void SetPalette(const Palette<float>& palette);
map<size_t, float> GetColorIndices() const;
map<size_t, float> GetPreviousColorIndices() const;
map<size_t, float> GetPreviousColorIndices() const;
void SetColorIndices(const map<size_t, float>& indices);
void SetPreviousColorIndices(const map<size_t, float>& indices);
void SetPreviousColorIndices(const map<size_t, float>& indices);
string GetPaletteFile() const;
void SetPaletteFile(const string& filename);
@ -80,7 +80,7 @@ private:
bool IsCurrentPaletteAndFileEditable();
bool m_PaletteFileChanged = false;
int m_PaletteIndex = 0;
map<size_t, float> m_PreviousColorIndices;
map<size_t, float> m_PreviousColorIndices;
QString m_Filename;
string m_CurrentPaletteFilePath;
ColorPickerWidget* m_ColorPicker = nullptr;