mirror of
https://bitbucket.org/mfeemster/fractorium.git
synced 2026-05-17 13:20:22 -04:00
-Give tabs a height of 4px in the qss files. Looks a little large on 4k screens, but just right on HD screens which are much more common. -Allow for styling of zero and non-zero variation tree nodes via qss. -Allow for toggling whether to interpolate between colors in the palette editor, or to do hard cuts between colors. -Allow for adjusting spinner values with the + = or up arrow keys to increase, and - _ or down arrow keys to decrease. -Allow for responding to global presses of + = and - _ to cycle up or down to specify which xform is set as the current one. -Allow for adding "layers" via xaos which will add a user-specified number of xforms, and set certain xaos values to 0 or 1. -Add a new menu item under the Edit menu to copy the OpenCL iteration kernel source to the clipboard. -Show text on the status bar which indicates that an OpenCL kernel compilation is taking place. -Show xform name on xform combo box when expanded. Adjust size to fit all names. -Draw post affine circles using dashed lines. -Prevent QSS dialog from styling its editor, which makes it easier to see text when creating styles which have custom colors for text boxes. --Bug fixes -Fix up some table layouts which seemed to have regressed/decayed over time for reasons unknown. -Using undo/redo would create a new flame in the library every time. -Solo was not being preserved when using undo/redo. --Code changes -Make the solo flag be a part of the flame data now. -Fix some tabification in the OpenCL code for EllipticVariation. -Fix tabification in the varState code for OpenCL. -Add an event called m_CompileBegun to RendererCL that is called right before an OpenCL compile is begun. --This required making RendererCLBase not a pure virtual base class. Member functions just return defaults. -Filter key presses on main window to only process the third one. This is due to Qt triggering three events for every key press. -The palette preview table was installing an event filter for seemingly no reason. Remove it. -Mark certain virtual functions as override in SpinBox and DoubleSpinBox.
241 lines
7.7 KiB
C++
241 lines
7.7 KiB
C++
#include "FractoriumPch.h"
|
|
#include "Fractorium.h"
|
|
|
|
#define XAOS_PREC 6
|
|
|
|
/// <summary>
|
|
/// Initialize the xforms xaos UI.
|
|
/// </summary>
|
|
void Fractorium::InitXaosUI()
|
|
{
|
|
int spinHeight = 20;
|
|
ui.XaosTableView->verticalHeader()->setSectionsClickable(true);
|
|
ui.XaosTableView->horizontalHeader()->setSectionsClickable(true);
|
|
m_XaosSpinBox = new DoubleSpinBox(nullptr, spinHeight, 0.1);
|
|
m_XaosSpinBox->DoubleClick(true);
|
|
m_XaosSpinBox->DoubleClickZero(1);
|
|
m_XaosSpinBox->DoubleClickNonZero(0);
|
|
m_XaosSpinBox->setDecimals(XAOS_PREC);
|
|
m_XaosSpinBox->setObjectName("XaosSpinBox");
|
|
m_XaosTableModel = nullptr;
|
|
m_XaosTableItemDelegate = new DoubleSpinBoxTableItemDelegate(m_XaosSpinBox, this);
|
|
connect(m_XaosSpinBox, SIGNAL(valueChanged(double)), this, SLOT(OnXaosChanged(double)), Qt::QueuedConnection);
|
|
connect(ui.ClearXaosButton, SIGNAL(clicked(bool)), this, SLOT(OnClearXaosButtonClicked(bool)), Qt::QueuedConnection);
|
|
connect(ui.RandomXaosButton, SIGNAL(clicked(bool)), this, SLOT(OnRandomXaosButtonClicked(bool)), Qt::QueuedConnection);
|
|
connect(ui.AddLayerButton, SIGNAL(clicked(bool)), this, SLOT(OnAddLayerButtonClicked(bool)), Qt::QueuedConnection);
|
|
connect(ui.XaosTableView->verticalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(OnXaosRowDoubleClicked(int)), Qt::QueuedConnection);
|
|
connect(ui.XaosTableView->horizontalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(OnXaosColDoubleClicked(int)), Qt::QueuedConnection);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fill the xaos table with the values from the ember.
|
|
/// </summary>
|
|
template <typename T>
|
|
void FractoriumEmberController<T>::FillXaos()
|
|
{
|
|
for (int i = 0, count = int(XformCount()); i < count; i++)//Column.
|
|
{
|
|
if (auto xform = m_Ember.GetXform(i))
|
|
{
|
|
for (int j = 0; j < count; j++)//Row.
|
|
{
|
|
QModelIndex index = m_Fractorium->m_XaosTableModel->index(j, i, QModelIndex());//j and i are intentionally swapped here.
|
|
m_Fractorium->m_XaosTableModel->setData(index, xform->Xaos(j));
|
|
}
|
|
}
|
|
}
|
|
|
|
m_Fractorium->ui.XaosTableView->resizeRowsToContents();
|
|
m_Fractorium->ui.XaosTableView->resizeColumnsToContents();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the xaos value.
|
|
/// Called when any xaos spinner is changed.
|
|
/// It actually gets called multiple times as the user clicks around the
|
|
/// xaos table due to how QTableView passes events to and from its model.
|
|
/// To filter out spurrious events, the value is checked against the existing
|
|
/// xaos value.
|
|
/// Resets the rendering process.
|
|
/// </summary>
|
|
/// <param name="x">The index of the xform whose xaos value was changed (column)</param>
|
|
/// <param name="y">The index of the to value that was changed for the xform (row)</param>
|
|
/// <param name="val">The changed value of the xaos element</param>
|
|
template <typename T>
|
|
void FractoriumEmberController<T>::XaosChanged(int x, int y, double val)
|
|
{
|
|
auto newVal = TruncPrecision(val, XAOS_PREC);//Sometimes 0 comes in as a very small number, so round.
|
|
|
|
if (auto xform = m_Ember.GetXform(x))
|
|
if (!IsClose<T>(newVal, xform->Xaos(y), T(1e-7)))
|
|
Update([&] { xform->SetXaos(y, newVal); });
|
|
}
|
|
|
|
void Fractorium::OnXaosChanged(double d)
|
|
{
|
|
if (auto senderSpinBox = qobject_cast<DoubleSpinBox*>(sender()))
|
|
{
|
|
auto p = senderSpinBox->property("tableindex").toPoint();
|
|
m_Controller->XaosChanged(p.y(), p.x(), d);//Intentionally switched, column is the from xform, row is the to xform.
|
|
}
|
|
}
|
|
|
|
void Fractorium::OnXaosTableModelDataChanged(const QModelIndex& indexA, const QModelIndex& indexB)
|
|
{
|
|
m_Controller->XaosChanged(indexA.column(), indexA.row(), indexA.data().toDouble());//Intentionally switched, column is the from xform, row is the to xform.
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clear xaos table, recreate all spinners based on the xaos used in the current ember.
|
|
/// </summary>
|
|
void Fractorium::FillXaosTable()
|
|
{
|
|
int count = int(m_Controller->XformCount());
|
|
QStringList hl, vl;
|
|
auto oldModel = m_XaosTableModel;
|
|
hl.reserve(count);
|
|
vl.reserve(count);
|
|
m_XaosTableModel = new QStandardItemModel(count, count, this);
|
|
connect(m_XaosTableModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(OnXaosTableModelDataChanged(QModelIndex, QModelIndex)));
|
|
ui.XaosTableView->blockSignals(true);
|
|
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
auto s = QString::number(i + 1);
|
|
hl.push_back("F" + s);
|
|
vl.push_back("T" + s);
|
|
}
|
|
|
|
m_XaosTableModel->setHorizontalHeaderLabels(hl);
|
|
m_XaosTableModel->setVerticalHeaderLabels(vl);
|
|
ui.XaosTableView->setModel(m_XaosTableModel);
|
|
ui.XaosTableView->setItemDelegate(m_XaosTableItemDelegate);
|
|
SetTabOrder(this, ui.ClearXaosButton, ui.RandomXaosButton);
|
|
m_Controller->FillXaos();
|
|
ui.XaosTableView->blockSignals(false);
|
|
|
|
if (oldModel)
|
|
delete oldModel;
|
|
|
|
//Needed to get the dark stylesheet to correctly color the top left corner button.
|
|
auto widgetList = ui.XaosTableView->findChildren<QAbstractButton*>();
|
|
|
|
for (auto& it : widgetList)
|
|
it->setEnabled(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clear all xaos from the current ember.
|
|
/// </summary>
|
|
template <typename T>
|
|
void FractoriumEmberController<T>::ClearXaos()
|
|
{
|
|
Update([&] { m_Ember.ClearXaos(); });
|
|
FillXaos();
|
|
}
|
|
|
|
void Fractorium::OnClearXaosButtonClicked(bool checked) { m_Controller->ClearXaos(); }
|
|
|
|
/// <summary>
|
|
/// Set all xaos values to random numbers.
|
|
/// There is a 50% chance they're set to 0 or 1, and
|
|
/// 50% that they're 0-3.
|
|
/// Resets the rendering process.
|
|
/// </summary>
|
|
template <typename T>
|
|
void FractoriumEmberController<T>::RandomXaos()
|
|
{
|
|
Update([&]
|
|
{
|
|
for (size_t i = 0; i < m_Ember.XformCount(); i++)
|
|
{
|
|
if (auto xform = m_Ember.GetXform(i))
|
|
{
|
|
for (size_t j = 0; j < m_Ember.XformCount(); j++)
|
|
{
|
|
if (m_Rand.RandBit())
|
|
xform->SetXaos(j, T(m_Rand.RandBit()));
|
|
else
|
|
xform->SetXaos(j, m_Rand.Frand<T>(0, 3));
|
|
}
|
|
}
|
|
}
|
|
});
|
|
FillXaos();
|
|
}
|
|
|
|
void Fractorium::OnRandomXaosButtonClicked(bool checked) { m_Controller->RandomXaos(); }
|
|
|
|
/// <summary>
|
|
/// Add a layer using the specified number of xforms.
|
|
/// A layer is defined as a new set of xforms whose xaos values are the following:
|
|
/// From existing to existing: unchanged.
|
|
/// From existing to new: 0.
|
|
/// From new to existing: 0.
|
|
/// From new to new: 1.
|
|
/// </summary>
|
|
/// <param name="xforms">The number of new xforms to add to create the layer</param>
|
|
template <typename T>
|
|
void FractoriumEmberController<T>::AddLayer(int xforms)
|
|
{
|
|
Update([&]
|
|
{
|
|
auto origXformCount = m_Ember.XformCount();
|
|
m_Ember.AddXforms(xforms);
|
|
|
|
for (auto i = 0; i < m_Ember.XformCount(); i++)
|
|
{
|
|
auto xf = m_Ember.GetXform(i);
|
|
|
|
if (i < origXformCount)
|
|
{
|
|
for (auto j = 0; j < m_Ember.XformCount(); j++)
|
|
if (j >= origXformCount)
|
|
xf->SetXaos(j, 0);
|
|
}
|
|
else
|
|
{
|
|
for (auto j = 0; j < m_Ember.XformCount(); j++)
|
|
if (j < origXformCount)
|
|
xf->SetXaos(j, 0);
|
|
else
|
|
xf->SetXaos(j, 1);
|
|
}
|
|
}
|
|
});
|
|
FillXforms();
|
|
FillSummary();
|
|
}
|
|
|
|
void Fractorium::OnAddLayerButtonClicked(bool checked) { m_Controller->AddLayer(ui.AddLayerSpinBox->value()); }
|
|
|
|
/// <summary>
|
|
/// Toggle all xaos values in one row.
|
|
/// Resets the rendering process.
|
|
/// </summary>
|
|
/// <param name="logicalIndex">The index of the row that was double clicked</param>
|
|
void Fractorium::OnXaosRowDoubleClicked(int logicalIndex)
|
|
{
|
|
ToggleTableRow(ui.XaosTableView, logicalIndex);
|
|
ui.XaosTableView->resizeRowsToContents();
|
|
ui.XaosTableView->resizeColumnsToContents();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Toggle all xaos values in one column.
|
|
/// Resets the rendering process.
|
|
/// </summary>
|
|
/// <param name="logicalIndex">The index of the column that was double clicked</param>
|
|
void Fractorium::OnXaosColDoubleClicked(int logicalIndex)
|
|
{
|
|
ToggleTableCol(ui.XaosTableView, logicalIndex);
|
|
ui.XaosTableView->resizeRowsToContents();
|
|
ui.XaosTableView->resizeColumnsToContents();
|
|
}
|
|
|
|
template class FractoriumEmberController<float>;
|
|
|
|
#ifdef DO_DOUBLE
|
|
template class FractoriumEmberController<double>;
|
|
#endif
|