From 4c0f03a52a72b3f06f678d2e175b5c0ee0fd9a24 Mon Sep 17 00:00:00 2001 From: Person Date: Wed, 8 May 2024 07:31:55 -0600 Subject: [PATCH] --User changes -Add Ctrl+g shortcut for generating a sequence. --Bug fixes -Fix indendation for variations because of type icon. -Fix bug when duplicating flame where the new flame wasn't being properly selected. -Fix bug where clearing a flame was changing size and quality when it shouldn't have. -Fix bug where reading an Xml palette was failing on linux. --Code changes -No longer pad string with null terminator in ReadFile() because std::string already does it. --- Source/Ember/Ember.h | 2 +- Source/Ember/PaletteList.cpp | 1 + Source/Ember/Utils.h | 9 ++------ Source/Fractorium/Fractorium.cpp | 22 ++++++++++++++----- Source/Fractorium/FractoriumEmberController.h | 2 +- Source/Fractorium/FractoriumInfo.cpp | 3 ++- Source/Fractorium/FractoriumLibrary.cpp | 13 ++++++----- Source/Fractorium/FractoriumMenus.cpp | 11 +++++++--- Source/Fractorium/FractoriumParams.cpp | 8 +++---- .../Fractorium/FractoriumXformsVariations.cpp | 20 ++++++++++++----- 10 files changed, 58 insertions(+), 33 deletions(-) diff --git a/Source/Ember/Ember.h b/Source/Ember/Ember.h index d72793e..d16e7f9 100644 --- a/Source/Ember/Ember.h +++ b/Source/Ember/Ember.h @@ -1479,7 +1479,7 @@ public: m_BlurCurve = 0; m_BlurCoef = 0; m_CamMat = m3T(0); - m_Quality = 1; + m_Quality = 30; m_SubBatchSize = 10240; m_RandPointRange = 1; m_FuseCount = 15; diff --git a/Source/Ember/PaletteList.cpp b/Source/Ember/PaletteList.cpp index 71ae477..804248a 100644 --- a/Source/Ember/PaletteList.cpp +++ b/Source/Ember/PaletteList.cpp @@ -208,6 +208,7 @@ bool PaletteList::Add(const string& filename, bool force) if (EndsWith(lower, ".xml")) { + //Subtract 1 to make reading with nullterminate set to true work on linux. const auto doc = xmlReadMemory(static_cast(buf.data()), static_cast(buf.size()), filename.c_str(), nullptr, XML_PARSE_NONET); if (doc) diff --git a/Source/Ember/Utils.h b/Source/Ember/Utils.h index 37728a7..86a8828 100644 --- a/Source/Ember/Utils.h +++ b/Source/Ember/Utils.h @@ -320,9 +320,8 @@ public: /// /// The full path to the file to read /// The string which will be populated with the file's contents -/// Whether to append a NULL character as the last element of the vector. Needed when reading text files. Default: true. /// True if successfully read and populated, else false -static bool ReadFile(const char* filename, string& buf, bool nullTerminate = true) +static bool ReadFile(const char* filename, string& buf) { try { @@ -332,13 +331,9 @@ static bool ReadFile(const char* filename, string& buf, bool nullTerminate = tru if (const auto pos = ifs.tellg())//Ensure it exists and wasn't empty. { - buf.resize(pos);// +streampos(nullTerminate ? 1 : 0)); + buf.resize(pos); ifs.seekg(0, ios::beg); ifs.read(&buf[0], pos); - - if (nullTerminate && (buf[buf.size() - 1] != 0))//Optionally NULL terminate if they want to treat it as a string, and it's not terminated arleady. - buf.push_back(0); - return true; } } diff --git a/Source/Fractorium/Fractorium.cpp b/Source/Fractorium/Fractorium.cpp index 76c8f18..56b7bad 100644 --- a/Source/Fractorium/Fractorium.cpp +++ b/Source/Fractorium/Fractorium.cpp @@ -392,6 +392,7 @@ bool Fractorium::eventFilter(QObject* o, QEvent* e) static int commacount = 0; static int periodcount = 0; static int lcount = 0; + static int ctrlgcount = 0; const bool shift = QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier); const bool ctrl = QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier); @@ -448,11 +449,22 @@ bool Fractorium::eventFilter(QObject* o, QEvent* e) const auto focusedctrlDblSpin = dynamic_cast(this->focusWidget()); const auto focusedctrlCombo = dynamic_cast(this->focusWidget()); - if (!focusedctrlEdit && - !focusedctrlSpin && - !focusedctrlDblSpin && - !focusedctrlCombo && - !QGuiApplication::keyboardModifiers().testFlag(Qt::AltModifier))//Must exclude these because otherwise, typing a minus key in any of the spinners will switch the xform. Also exclude alt. + if (ctrl && (ke->key() == Qt::Key_G)) + { + ctrlgcount++; + + if (ctrlgcount >= ftimes) + { + OnSequenceGenerateButtonClicked(true); + ctrlgcount = 0; + return true; + } + } + else if (!focusedctrlEdit && + !focusedctrlSpin && + !focusedctrlDblSpin && + !focusedctrlCombo && + !QGuiApplication::keyboardModifiers().testFlag(Qt::AltModifier))//Must exclude these because otherwise, typing a minus key in any of the spinners will switch the xform. Also exclude alt. { size_t index = 0; double vdist = 0.01; diff --git a/Source/Fractorium/FractoriumEmberController.h b/Source/Fractorium/FractoriumEmberController.h index dc68af0..3ab0d4c 100644 --- a/Source/Fractorium/FractoriumEmberController.h +++ b/Source/Fractorium/FractoriumEmberController.h @@ -567,7 +567,7 @@ public: void FilteredVariations() override; void FillVariationTreeWithCurrentXform() override; void FillVariationTreeWithXform(Xform* xform); - QIcon MakeVariationIcon(const Variation* var); + QIcon MakeVariationIcon(const Variation* var, int iconSize); //Xforms Xaos. void FillXaos() override; diff --git a/Source/Fractorium/FractoriumInfo.cpp b/Source/Fractorium/FractoriumInfo.cpp index d6041b5..3b6d0f3 100644 --- a/Source/Fractorium/FractoriumInfo.cpp +++ b/Source/Fractorium/FractoriumInfo.cpp @@ -71,6 +71,7 @@ void FractoriumEmberController::FillSummary() const auto vp = 4; const auto vlen = 7; const auto pc = 'f'; + const auto iconSize = 20; const auto forceFinal = m_Fractorium->HaveFinal(); const auto total = m_Ember.TotalXformCount(forceFinal); const auto table = m_Fractorium->ui.SummaryTable; @@ -163,7 +164,7 @@ void FractoriumEmberController::FillSummary() vitem->setText(0, QString::fromStdString(var->Name())); vitem->setText(1, QLocale::system().toString(var->m_Weight, pc, vp).rightJustified(vlen, ' ')); vitem->setFlags(draggable); - auto qi = MakeVariationIcon(var); + auto qi = MakeVariationIcon(var, iconSize); vitem->setIcon(0, qi); if (const auto parVar = dynamic_cast*>(var)) diff --git a/Source/Fractorium/FractoriumLibrary.cpp b/Source/Fractorium/FractoriumLibrary.cpp index 0e0cedc..2982f28 100644 --- a/Source/Fractorium/FractoriumLibrary.cpp +++ b/Source/Fractorium/FractoriumLibrary.cpp @@ -47,7 +47,7 @@ void Fractorium::SelectLibraryItem(size_t index) item = emberItem; emberItem->setSelected(b); - emberItem->setCheckState(NAME_COL, i == index ? Qt::Checked : Qt::Unchecked); + emberItem->setCheckState(NAME_COL, b ? Qt::Checked : Qt::Unchecked); } } @@ -164,6 +164,7 @@ void FractoriumEmberController::FillLibraryTree(int selectIndex) for (auto& it : m_EmberFile.m_Embers) { + it.m_Index = i; auto emberItem = new EmberTreeWidgetItem(&it, fileItem); auto istr = ToString(i++); emberItem->setText(INDEX_COL, istr); @@ -175,8 +176,11 @@ void FractoriumEmberController::FillLibraryTree(int selectIndex) emberItem->setToolTip(NAME_COL, emberItem->text(NAME_COL)); emberItem->SetImage(empy_preview, size, size); + emberItem->SetEmberPointer(&it); } + //tree->update(); + if (selectIndex != -1) m_Fractorium->SelectLibraryItem(selectIndex); @@ -345,8 +349,7 @@ void FractoriumEmberController::MoveLibraryItems(const QModelIndexList& items return false; }); tree->update(); - SyncLibrary(eLibraryUpdate(static_cast(eLibraryUpdate::INDEX) | static_cast(eLibraryUpdate::POINTER))); - //SyncLibrary(eLibraryUpdate(eLibraryUpdate::INDEX | eLibraryUpdate::POINTER | eLibraryUpdate::NAME)); + SyncLibrary(eLibraryUpdate(static_cast(eLibraryUpdate::INDEX) | static_cast(eLibraryUpdate::NAME) | static_cast(eLibraryUpdate::POINTER))); } /// @@ -367,7 +370,7 @@ void FractoriumEmberController::Delete(const vector(eLibraryUpdate::INDEX) | static_cast(eLibraryUpdate::NAME) | static_cast(eLibraryUpdate::POINTER))); m_Fractorium->SyncFileCountToSequenceCount(); } @@ -669,7 +672,7 @@ void FractoriumEmberController::SequenceGenerateButtonClicked() const auto rotsPerBlend = it->m_RotationsPerBlend; const auto linear = it->m_Linear; tools.SetSpinParams(!linear, - stagger,//Will be set again below if random is used. + stagger, 0, 0, s->Nick().toStdString(), diff --git a/Source/Fractorium/FractoriumMenus.cpp b/Source/Fractorium/FractoriumMenus.cpp index b58096c..bb5873f 100644 --- a/Source/Fractorium/FractoriumMenus.cpp +++ b/Source/Fractorium/FractoriumMenus.cpp @@ -164,10 +164,12 @@ void FractoriumEmberController::CopyFlameInCurrentFile() { StopAllPreviewRenderers(); auto ember = m_Ember; - auto insertEmberIndex = m_Fractorium->ui.LibraryTree->currentIndex().row() + 1; + auto model = m_Fractorium->ui.LibraryTree->selectionModel(); + auto sel = model->selectedIndexes(); + auto insertEmberIndex = sel.size() > 0 ? sel[0].row() + 1 : 0; ember.m_Name = EmberFile::DefaultEmberName(m_EmberFile.Size() + 1).toStdString(); - ember.m_Index = insertEmberIndex;//Will be overwritten below in UpdateLibraryTree(). - m_EmberFile.m_Embers.insert(Advance(m_EmberFile.m_Embers.begin(), insertEmberIndex), ember);//Will invalidate the pointers contained in the EmberTreeWidgetItems, UpdateLibraryTree() will resync. + ember.m_Index = insertEmberIndex;//Will be overwritten below in FillLibraryTree(). + m_EmberFile.m_Embers.insert(Advance(m_EmberFile.m_Embers.begin(), insertEmberIndex), ember);//Will invalidate the pointers contained in the EmberTreeWidgetItems, FillLibraryTree() has the effect of resyncing because index, name and pointer are assigned. m_EmberFile.MakeNamesUnique(); FillLibraryTree(insertEmberIndex); SetEmber(insertEmberIndex, false); @@ -1013,6 +1015,9 @@ void FractoriumEmberController::ClearFlame() newXform.m_ColorX = m_Rand.Frand01(); newXform.AddVariation(m_VariationList->GetVariationCopy(eVariationId::VAR_LINEAR)); m_Ember.Clear(); + m_Ember.m_FinalRasW = m_Fractorium->m_WidthSpin->value(); + m_Ember.m_FinalRasH = m_Fractorium->m_HeightSpin->value(); + m_Ember.m_Quality = m_Fractorium->m_QualitySpin->value(); m_Ember.AddXform(newXform); FillXforms();//Must do this first because the palette setup in FillParamTablesAndPalette() uses the xforms combo. FillParamTablesAndPalette(); diff --git a/Source/Fractorium/FractoriumParams.cpp b/Source/Fractorium/FractoriumParams.cpp index a199944..47b1a19 100644 --- a/Source/Fractorium/FractoriumParams.cpp +++ b/Source/Fractorium/FractoriumParams.cpp @@ -122,8 +122,8 @@ void Fractorium::InitParamsUI() llComboVals = comboVals; SetupCombo(table, this, row, 1, m_AffineInterpTypeCombo, comboVals, SIGNAL(currentIndexChanged(int)), SLOT(OnAffineInterpTypeComboCurrentIndexChanged(int))); m_AffineInterpTypeCombo->SetCurrentIndexStealth(static_cast(eAffineInterp::AFFINE_INTERP_LOG)); - SetupSpinner(table, this, row, 1, m_RotationsSpin, spinHeight, 0, dmax, 1, SIGNAL(valueChanged(double)), SLOT(OnRotationsChanged(double)), true, 1.0, 1.0, 0); - SetupSpinner(table, this, row, 1, m_SecondsPerRotationSpin, spinHeight, 0, dmax, 1, SIGNAL(valueChanged(double)), SLOT(OnSecondsPerRotationChanged(double)), true, 1.0, 1.0, 0); + SetupSpinner(table, this, row, 1, m_RotationsSpin, spinHeight, 0, dmax, 1, SIGNAL(valueChanged(double)), SLOT(OnRotationsChanged(double)), true, 1.0, 1.0, 0); + SetupSpinner(table, this, row, 1, m_SecondsPerRotationSpin, spinHeight, 0, dmax, 1, SIGNAL(valueChanged(double)), SLOT(OnSecondsPerRotationChanged(double)), true, 1.0, 1.0, 0); comboVals.clear(); comboVals.push_back("Cw"); comboVals.push_back("Ccw"); @@ -135,8 +135,8 @@ void Fractorium::InitParamsUI() m_BlendXformsRotateDirCombo->SetCurrentIndexStealth(0); SetupCombo(table, this, row, 1, m_BlendInterpTypeCombo, llComboVals, SIGNAL(currentIndexChanged(int)), SLOT(OnBlendInterpTypeComboCurrentIndexChanged(int))); m_BlendInterpTypeCombo->SetCurrentIndexStealth(1); - SetupSpinner(table, this, row, 1, m_StaggerSpin, spinHeight, 0, 1, 0.1, SIGNAL(valueChanged(double)), SLOT(OnStaggerChanged(double)), true, 0, 1.0, 0); - SetupSpinner(table, this, row, 1, m_TemporalFilterWidthSpin, spinHeight, 1, 10, 1, SIGNAL(valueChanged(double)), SLOT(OnTemporalFilterWidthChanged(double)), true, 1, 1, 1); + SetupSpinner(table, this, row, 1, m_StaggerSpin, spinHeight, 0, 1, 0.1, SIGNAL(valueChanged(double)), SLOT(OnStaggerChanged(double)), true, 0, 1.0, 0); + SetupSpinner(table, this, row, 1, m_TemporalFilterWidthSpin, spinHeight, 1, 10, 1, SIGNAL(valueChanged(double)), SLOT(OnTemporalFilterWidthChanged(double)), true, 1, 1, 1); comboVals = TemporalFilterCreator::FilterTypes(); SetupCombo(table, this, row, 1, m_TemporalFilterTypeCombo, comboVals, SIGNAL(currentTextChanged(const QString&)), SLOT(OnTemporalFilterTypeComboCurrentIndexChanged(const QString&))); m_TemporalFilterTypeCombo->SetCurrentIndexStealth(static_cast(eTemporalFilterType::BOX_TEMPORAL_FILTER)); diff --git a/Source/Fractorium/FractoriumXformsVariations.cpp b/Source/Fractorium/FractoriumXformsVariations.cpp index 5902ae7..c34f581 100644 --- a/Source/Fractorium/FractoriumXformsVariations.cpp +++ b/Source/Fractorium/FractoriumXformsVariations.cpp @@ -16,7 +16,7 @@ void Fractorium::InitXformsVariationsUI() //Setting dimensions in the designer with a layout is futile, so must hard code here. tree->setColumnWidth(0, 170); tree->setColumnWidth(1, 80); - tree->setColumnWidth(2, 20); + //tree->setColumnWidth(2, 20); //Set Default variation tree text and background colors for zero and non zero cases. m_VariationTreeColorNonZero = Qt::black; m_VariationTreeColorZero = Qt::black; @@ -107,12 +107,19 @@ void FractoriumEmberController::SetupVariationsTree() { T fMin = TLOW; T fMax = TMAX; + const int iconSize = 20; const QSize hint0(170, 16); const QSize hint1(80, 16); - const QSize hint2(20, 16); + //const QSize hint2(20, 16); + QPixmap pixmap(iconSize * 3, iconSize); + auto mask = pixmap.createMaskFromColor(QColor("transparent"), Qt::MaskOutColor); auto tree = m_Fractorium->ui.VariationsTree; tree->clear(); tree->blockSignals(true); + pixmap.setMask(mask); + QPainter paint(&pixmap); + paint.fillRect(QRect(0, 0, iconSize * 3, iconSize), QColor(0, 0, 0, 0)); + QIcon defIcon(pixmap); for (size_t i = 0; i < m_VariationList->Size(); i++) { @@ -124,8 +131,8 @@ void FractoriumEmberController::SetupVariationsTree() item->setText(0, QString::fromStdString(var->Name())); item->setSizeHint(0, hint0); item->setSizeHint(1, hint1); - item->setSizeHint(2, hint2); - auto qi = MakeVariationIcon(var); + //item->setSizeHint(2, hint2); + auto qi = MakeVariationIcon(var, iconSize); item->setIcon(0, qi); spinBox->setRange(fMin, fMax); spinBox->DoubleClick(true); @@ -150,6 +157,7 @@ void FractoriumEmberController::SetupVariationsTree() paramWidget->setText(0, params[j].Name().c_str()); paramWidget->setSizeHint(0, hint0); paramWidget->setSizeHint(1, hint1); + paramWidget->setIcon(0, defIcon); varSpinBox->setRange(params[j].Min(), params[j].Max()); varSpinBox->setValue(params[j].ParamVal()); varSpinBox->DoubleClick(true); @@ -367,11 +375,11 @@ void FractoriumEmberController::FillVariationTreeWithXform(Xform* xform) /// Blue: maintains internal state, mostly of engineering interest. /// /// The variation to create the icon for +/// The size of the icon in pixels /// The newly created icon template -QIcon FractoriumEmberController::MakeVariationIcon(const Variation* var) +QIcon FractoriumEmberController::MakeVariationIcon(const Variation* var, int iconSize) { - const int iconSize = 20; static vector dc{ "m_ColorX" }; static vector assign{ "outPoint->m_X =", "outPoint->m_Y =", "outPoint->m_Z =", "outPoint->m_X=", "outPoint->m_Y=", "outPoint->m_Z=" };