--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.
This commit is contained in:
Person 2024-05-08 07:31:55 -06:00
parent 45d936b60c
commit 4c0f03a52a
10 changed files with 58 additions and 33 deletions

View File

@ -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;

View File

@ -208,6 +208,7 @@ bool PaletteList<T>::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<const char*>(buf.data()), static_cast<int>(buf.size()), filename.c_str(), nullptr, XML_PARSE_NONET);
if (doc)

View File

@ -320,9 +320,8 @@ public:
/// </summary>
/// <param name="filename">The full path to the file to read</param>
/// <param name="buf">The string which will be populated with the file's contents</param>
/// <param name="nullTerminate">Whether to append a NULL character as the last element of the vector. Needed when reading text files. Default: true.</param>
/// <returns>True if successfully read and populated, else false</returns>
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;
}
}

View File

@ -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,7 +449,18 @@ bool Fractorium::eventFilter(QObject* o, QEvent* e)
const auto focusedctrlDblSpin = dynamic_cast<QDoubleSpinBox*>(this->focusWidget());
const auto focusedctrlCombo = dynamic_cast<QComboBox*>(this->focusWidget());
if (!focusedctrlEdit &&
if (ctrl && (ke->key() == Qt::Key_G))
{
ctrlgcount++;
if (ctrlgcount >= ftimes)
{
OnSequenceGenerateButtonClicked(true);
ctrlgcount = 0;
return true;
}
}
else if (!focusedctrlEdit &&
!focusedctrlSpin &&
!focusedctrlDblSpin &&
!focusedctrlCombo &&

View File

@ -567,7 +567,7 @@ public:
void FilteredVariations() override;
void FillVariationTreeWithCurrentXform() override;
void FillVariationTreeWithXform(Xform<T>* xform);
QIcon MakeVariationIcon(const Variation<T>* var);
QIcon MakeVariationIcon(const Variation<T>* var, int iconSize);
//Xforms Xaos.
void FillXaos() override;

View File

@ -71,6 +71,7 @@ void FractoriumEmberController<T>::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<T>::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<ParametricVariation<T>*>(var))

View File

@ -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<T>::FillLibraryTree(int selectIndex)
for (auto& it : m_EmberFile.m_Embers)
{
it.m_Index = i;
auto emberItem = new EmberTreeWidgetItem<T>(&it, fileItem);
auto istr = ToString(i++);
emberItem->setText(INDEX_COL, istr);
@ -175,8 +176,11 @@ void FractoriumEmberController<T>::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<T>::MoveLibraryItems(const QModelIndexList& items
return false;
});
tree->update();
SyncLibrary(eLibraryUpdate(static_cast<uint>(eLibraryUpdate::INDEX) | static_cast<uint>(eLibraryUpdate::POINTER)));
//SyncLibrary(eLibraryUpdate(eLibraryUpdate::INDEX | eLibraryUpdate::POINTER | eLibraryUpdate::NAME));
SyncLibrary(eLibraryUpdate(static_cast<uint>(eLibraryUpdate::INDEX) | static_cast<uint>(eLibraryUpdate::NAME) | static_cast<uint>(eLibraryUpdate::POINTER)));
}
/// <summary>
@ -367,7 +370,7 @@ void FractoriumEmberController<T>::Delete(const vector<pair<size_t, QTreeWidgetI
{
last = uint(p.first - offset);
delete p.second;
SyncLibrary(eLibraryUpdate::INDEX);
SyncLibrary(eLibraryUpdate(static_cast<uint>(eLibraryUpdate::INDEX) | static_cast<uint>(eLibraryUpdate::NAME) | static_cast<uint>(eLibraryUpdate::POINTER)));
m_Fractorium->SyncFileCountToSequenceCount();
}
@ -669,7 +672,7 @@ void FractoriumEmberController<T>::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(),

View File

@ -164,10 +164,12 @@ void FractoriumEmberController<T>::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<T>::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<T>::ClearFlame()
newXform.m_ColorX = m_Rand.Frand01<T>();
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();

View File

@ -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<T>::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<T>::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<T>::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<T>::FillVariationTreeWithXform(Xform<T>* xform)
/// Blue: maintains internal state, mostly of engineering interest.
/// </summary>
/// <param name="text">The variation to create the icon for</param>
/// <param name="size">The size of the icon in pixels</param>
/// <returns>The newly created icon</returns>
template <typename T>
QIcon FractoriumEmberController<T>::MakeVariationIcon(const Variation<T>* var)
QIcon FractoriumEmberController<T>::MakeVariationIcon(const Variation<T>* var, int iconSize)
{
const int iconSize = 20;
static vector<string> dc{ "m_ColorX" };
static vector<string> assign{ "outPoint->m_X =", "outPoint->m_Y =", "outPoint->m_Z =",
"outPoint->m_X=", "outPoint->m_Y=", "outPoint->m_Z=" };