From 48a6111bf90a69dd1901af58216c431003f2dfc6 Mon Sep 17 00:00:00 2001 From: Person Date: Thu, 17 Aug 2017 22:40:03 -0700 Subject: [PATCH] Bug fixes: --Typing in the xform color index spinner produced strange results. --Returning from palette editor did not always update xform color indices. --- Source/Fractorium/Fractorium.h | 2 +- Source/Fractorium/FractoriumEmberController.h | 6 +- Source/Fractorium/FractoriumPalette.cpp | 39 ++++++++----- Source/Fractorium/FractoriumXformsColor.cpp | 56 ++++++++++--------- 4 files changed, 58 insertions(+), 45 deletions(-) diff --git a/Source/Fractorium/Fractorium.h b/Source/Fractorium/Fractorium.h index 3d50b8f..c0d5370 100644 --- a/Source/Fractorium/Fractorium.h +++ b/Source/Fractorium/Fractorium.h @@ -281,7 +281,7 @@ public slots: //Xforms Color. void OnXformColorIndexChanged(double d); - void OnXformColorIndexChanged(double d, bool updateRender, eXformUpdate update = eXformUpdate::UPDATE_SELECTED, size_t index = 0); + void OnXformColorIndexChanged(double d, bool updateRender, bool updateSpinner, bool updateScroll, eXformUpdate update = eXformUpdate::UPDATE_SELECTED, size_t index = 0); void OnXformScrollColorIndexChanged(int d); void OnRandomColorIndicesButtonClicked(bool b); void OnToggleColorIndicesButtonClicked(bool b); diff --git a/Source/Fractorium/FractoriumEmberController.h b/Source/Fractorium/FractoriumEmberController.h index 6fc7349..456dbd6 100644 --- a/Source/Fractorium/FractoriumEmberController.h +++ b/Source/Fractorium/FractoriumEmberController.h @@ -199,8 +199,7 @@ public: virtual void InitLockedScale() { } //Xforms Color. - virtual void XformColorIndexChanged(double d, bool updateRender, eXformUpdate update = eXformUpdate::UPDATE_SELECTED, size_t index = 0) { } - virtual void XformScrollColorIndexChanged(int d) { } + virtual void XformColorIndexChanged(double d, bool updateRender, bool updateSpinner, bool updateScroll, eXformUpdate update = eXformUpdate::UPDATE_SELECTED, size_t index = 0) { } virtual void RandomColorIndicesButtonClicked() { } virtual void ToggleColorIndicesButtonClicked() { } virtual void RandomColorSpeedButtonClicked() { } @@ -466,8 +465,7 @@ public: T AffineScaleLockedToCurrent(); //Xforms Color. - virtual void XformColorIndexChanged(double d, bool updateRender, eXformUpdate update = eXformUpdate::UPDATE_SELECTED, size_t index = 0) override; - virtual void XformScrollColorIndexChanged(int d) override; + virtual void XformColorIndexChanged(double d, bool updateRender, bool updateSpinner, bool updateScroll, eXformUpdate update = eXformUpdate::UPDATE_SELECTED, size_t index = 0) override; virtual void RandomColorIndicesButtonClicked() override; virtual void ToggleColorIndicesButtonClicked() override; virtual void RandomColorSpeedButtonClicked() override; diff --git a/Source/Fractorium/FractoriumPalette.cpp b/Source/Fractorium/FractoriumPalette.cpp index f816537..d937ce7 100644 --- a/Source/Fractorium/FractoriumPalette.cpp +++ b/Source/Fractorium/FractoriumPalette.cpp @@ -172,8 +172,9 @@ void FractoriumEmberController::UpdateAdjustedPaletteGUI(Palette& pale } //Update the current xform's color and reset the rendering process. + //Update all controls to be safe. if (xform) - XformColorIndexChanged(xform->m_ColorX, true); + XformColorIndexChanged(xform->m_ColorX, true, true, true); } /// @@ -321,9 +322,9 @@ void FractoriumEmberController::PaletteEditorButtonClicked() auto ed = m_Fractorium->m_PaletteEditor; Palette edPal; Palette prevPal = m_TempPalette; - ed->SetPalette(m_TempPalette); map colorIndices; bool forceFinal = m_Fractorium->HaveFinal(); + ed->SetPalette(m_TempPalette); while (auto xform = m_Ember.GetTotalXform(i, forceFinal)) colorIndices[i++] = xform->m_ColorX; @@ -333,21 +334,29 @@ void FractoriumEmberController::PaletteEditorButtonClicked() if (ed->exec() == QDialog::Accepted) { - if (!m_Fractorium->PaletteChanged())//If the clicked ok, but never synced, set the palette now. - { - edPal = ed->GetPalette(int(256)); - SetBasePaletteAndAdjust(edPal); + //Copy all just to be safe, because they may or may not have synced. + colorIndices = ed->GetColorIndices(); - if (edPal.m_Filename.get() && !edPal.m_Filename->empty()) - m_Fractorium->SetPaletteFileComboIndex(*edPal.m_Filename); - } + for (auto& index : colorIndices) + if (auto xform = m_Ember.GetTotalXform(index.first, forceFinal)) + xform->m_ColorX = index.second; + + edPal = ed->GetPalette(int(256)); + 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. { - SetBasePaletteAndAdjust(prevPal); + 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. + //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)); } @@ -406,15 +415,15 @@ void Fractorium::OnPaletteEditorFileChanged() /// The value of the color index void Fractorium::OnPaletteEditorColorIndexChanged(size_t index, float value) { - if (index == std::numeric_limits::max()) + if (index == std::numeric_limits::max())//Update all in this case. { auto indices = m_PaletteEditor->GetColorIndices(); for (auto& it : indices) - OnXformColorIndexChanged(it.second, true, eXformUpdate::UPDATE_SPECIFIC, it.first); + OnXformColorIndexChanged(it.second, true, true, true, eXformUpdate::UPDATE_SPECIFIC, it.first); } - else - OnXformColorIndexChanged(value, true, eXformUpdate::UPDATE_SPECIFIC, index); + else//Only update the xform index that was selected and dragged inside of the palette editor. + OnXformColorIndexChanged(value, true, true, true, eXformUpdate::UPDATE_SPECIFIC, index); } /// diff --git a/Source/Fractorium/FractoriumXformsColor.cpp b/Source/Fractorium/FractoriumXformsColor.cpp index 3ce3208..73e6fe8 100644 --- a/Source/Fractorium/FractoriumXformsColor.cpp +++ b/Source/Fractorium/FractoriumXformsColor.cpp @@ -40,35 +40,44 @@ void Fractorium::InitXformsColorUI() /// /// The color index, 0-1/ /// True to reset the rendering process, else don't. +/// True to update the color index spinner with the new value, else don't. +/// True to update the color index scroll bar with the new value, else don't. /// The type of updating to do, default: eXformUpdate::UPDATE_SELECTED. /// The index of the xform to update. Ignored unless update is eXformUpdate::UPDATE_SPECIFIC. Default: 0. template -void FractoriumEmberController::XformColorIndexChanged(double d, bool updateRender, eXformUpdate update, size_t index) +void FractoriumEmberController::XformColorIndexChanged(double d, bool updateRender, bool updateSpinner, bool updateScroll, eXformUpdate update, size_t index) { bool updateGUI = update != eXformUpdate::UPDATE_SPECIFIC || index == m_Fractorium->ui.CurrentXformCombo->currentIndex(); - if (updateGUI) - { - auto scroll = m_Fractorium->ui.XformColorScroll; - int scrollVal = d * scroll->maximum(); - scroll->blockSignals(true); - scroll->setValue(scrollVal); - scroll->blockSignals(false); - m_Fractorium->m_XformColorIndexSpin->SetValueStealth(CurrentXform()->m_ColorX); - m_Fractorium->ui.XformColorIndexTable->item(0, 0)->setBackgroundColor(ColorIndexToQColor(d));//Grab the current color from the index and assign it to the first cell of the first table. - } - - if (updateRender)//False when just updating GUI, true when in response to a GUI change so update values and reset renderer. + if (updateRender)//False when just updating GUI in response to a change elsewhere, true when in response to a GUI change so update values and reset renderer. { UpdateXform([&](Xform* xform) { xform->m_ColorX = Clamp(d, 0, 1); }, update, updateRender, eProcessAction::FULL_RENDER, index); } + + //Only do this is coming from elsewhere, like the palette editor. Otherwise, normal events will handle updating the spinner. + if (updateSpinner && updateGUI) + { + m_Fractorium->m_XformColorIndexSpin->SetValueStealth(CurrentXform()->m_ColorX); + } + + if (updateScroll && updateGUI) + { + auto scroll = m_Fractorium->ui.XformColorScroll; + int scrollVal = d * scroll->maximum(); + scroll->blockSignals(true); + scroll->setValue(scrollVal); + scroll->blockSignals(false); + } + + if (updateGUI) + m_Fractorium->ui.XformColorIndexTable->item(0, 0)->setBackgroundColor(ColorIndexToQColor(d));//Grab the current color from the index and assign it to the first cell of the first table. } -void Fractorium::OnXformColorIndexChanged(double d) { OnXformColorIndexChanged(d, true, eXformUpdate::UPDATE_SELECTED, 0); } -void Fractorium::OnXformColorIndexChanged(double d, bool updateRender, eXformUpdate update, size_t index) { m_Controller->XformColorIndexChanged(d, updateRender, update, index); } +void Fractorium::OnXformColorIndexChanged(double d) { OnXformColorIndexChanged(d, true, false, true, eXformUpdate::UPDATE_SELECTED, std::numeric_limits::max()); } +void Fractorium::OnXformColorIndexChanged(double d, bool updateRender, bool updateSpinner, bool updateScroll, eXformUpdate update, size_t index) { m_Controller->XformColorIndexChanged(d, updateRender, updateSpinner, updateScroll, update, index); } /// /// Set the color index of the current xform. @@ -77,14 +86,11 @@ void Fractorium::OnXformColorIndexChanged(double d, bool updateRender, eXformUpd /// Resets the rendering process. /// /// The color index, 0-1. -template -void FractoriumEmberController::XformScrollColorIndexChanged(int d) +void Fractorium::OnXformScrollColorIndexChanged(int d) { - m_Fractorium->m_XformColorIndexSpin->setValue(d / double(m_Fractorium->ui.XformColorScroll->maximum()));//Will trigger an update. + OnXformColorIndexChanged(d / double(ui.XformColorScroll->maximum()), true, true, false);//Update spinner, but not scrollbar. Trigger render update. } -void Fractorium::OnXformScrollColorIndexChanged(int d) { m_Controller->XformScrollColorIndexChanged(d); } - /// /// Set all xform color indices to a random value between 0 and 1, inclusive. /// Called when the Random Indices button is clicked. @@ -93,8 +99,8 @@ void Fractorium::OnXformScrollColorIndexChanged(int d) { m_Controller->XformScro template void FractoriumEmberController::RandomColorIndicesButtonClicked() { - UpdateXform([&](Xform* xform) { xform->m_ColorX = m_Rand.Frand01(); }, eXformUpdate::UPDATE_ALL); - m_Fractorium->OnXformColorIndexChanged(CurrentXform()->m_ColorX, false);//Update GUI, no need to update renderer because UpdateXform() did it. + UpdateXform([&](Xform* xform) { xform->m_ColorX = m_Rand.Frand01(); }, eXformUpdate::UPDATE_ALL, false);//Don't update renderer here... + m_Fractorium->m_XformColorIndexSpin->setValue(CurrentXform()->m_ColorX);//...do it via GUI. This will set scrollbar value as well. } void Fractorium::OnRandomColorIndicesButtonClicked(bool b) { m_Controller->RandomColorIndicesButtonClicked(); } @@ -107,8 +113,8 @@ template void FractoriumEmberController::ToggleColorIndicesButtonClicked() { char ch = 1; - UpdateXform([&](Xform* xform) { xform->m_ColorX = T(ch ^= 1); }, eXformUpdate::UPDATE_ALL); - m_Fractorium->OnXformColorIndexChanged(CurrentXform()->m_ColorX, false);//Update GUI, no need to update renderer because UpdateXform() did it. + UpdateXform([&](Xform* xform) { xform->m_ColorX = T(ch ^= 1); }, eXformUpdate::UPDATE_ALL, false);//Don't update renderer here... + m_Fractorium->m_XformColorIndexSpin->setValue(CurrentXform()->m_ColorX);//...do it via GUI. This will set scrollbar value as well. } void Fractorium::OnToggleColorIndicesButtonClicked(bool b) { m_Controller->ToggleColorIndicesButtonClicked(); } @@ -239,7 +245,7 @@ void FractoriumEmberController::FillColorWithXform(Xform* xform) m_Fractorium->m_XformColorSpeedSpin->SetValueStealth(xform->m_ColorSpeed); m_Fractorium->m_XformOpacitySpin->SetValueStealth(xform->m_Opacity); m_Fractorium->m_XformDirectColorSpin->SetValueStealth(xform->m_DirectColor); - m_Fractorium->OnXformColorIndexChanged(xform->m_ColorX, false);//Had to call stealth before to avoid doing an update, now manually update related controls, still without doing an update. + m_Fractorium->OnXformColorIndexChanged(xform->m_ColorX, false, false, true);//Had to call stealth before to avoid doing an update, now manually update related controls, still without doing an update. } ///