2014-07-08 03:11:14 -04:00
|
|
|
#include "FractoriumPch.h"
|
|
|
|
#include "Fractorium.h"
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initialize the xforms xaos UI.
|
|
|
|
/// </summary>
|
2015-04-27 01:11:56 -04:00
|
|
|
void Fractorium::InitXaosUI()
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2015-05-03 20:13:14 -04:00
|
|
|
ui.XaosTable->verticalHeader()->setVisible(true);
|
|
|
|
ui.XaosTable->horizontalHeader()->setVisible(true);
|
|
|
|
ui.XaosTable->verticalHeader()->setSectionsClickable(true);
|
|
|
|
ui.XaosTable->horizontalHeader()->setSectionsClickable(true);
|
|
|
|
|
2014-07-08 03:11:14 -04:00
|
|
|
connect(ui.ClearXaosButton, SIGNAL(clicked(bool)), this, SLOT(OnClearXaosButtonClicked(bool)), Qt::QueuedConnection);
|
2014-10-15 23:09:44 -04:00
|
|
|
connect(ui.RandomXaosButton, SIGNAL(clicked(bool)), this, SLOT(OnRandomXaosButtonClicked(bool)), Qt::QueuedConnection);
|
2015-05-03 20:13:14 -04:00
|
|
|
connect(ui.XaosTable->verticalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(OnXaosRowDoubleClicked(int)), Qt::QueuedConnection);
|
|
|
|
connect(ui.XaosTable->horizontalHeader(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(OnXaosColDoubleClicked(int)), Qt::QueuedConnection);
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2015-04-08 21:23:29 -04:00
|
|
|
/// Fill the xaos table with the values from the ember.
|
2014-07-08 03:11:14 -04:00
|
|
|
/// </summary>
|
|
|
|
template <typename T>
|
2015-04-08 21:23:29 -04:00
|
|
|
void FractoriumEmberController<T>::FillXaos()
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
for (int i = 0, count = int(XformCount()); i < count; i++)
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
auto* xform = m_Ember.GetXform(i);
|
2014-07-08 03:11:14 -04:00
|
|
|
|
2015-04-08 21:23:29 -04:00
|
|
|
for (int j = 0; j < count; j++)
|
|
|
|
if (auto* spinBox = dynamic_cast<DoubleSpinBox*>(m_Fractorium->ui.XaosTable->cellWidget(i, j)))
|
|
|
|
spinBox->SetValueStealth(xform->Xaos(j));
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Create and return a xaos name string.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="i">The index of the xform whose xaos will be used</param>
|
|
|
|
/// <returns>The xaos name string</returns>
|
|
|
|
template <typename T>
|
2014-12-06 00:05:09 -05:00
|
|
|
QString FractoriumEmberController<T>::MakeXaosNameString(uint i)
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
|
|
|
Xform<T>* xform = m_Ember.GetXform(i);
|
|
|
|
QString name;
|
|
|
|
|
2015-04-08 21:23:29 -04:00
|
|
|
//if (xform)
|
|
|
|
//{
|
|
|
|
// int indexPlus1 = m_Ember.GetXformIndex(xform) + 1;//GUI is 1 indexed to avoid confusing the user.
|
|
|
|
// int curr = m_Fractorium->ui.CurrentXformCombo->currentIndex() + 1;
|
|
|
|
//
|
|
|
|
// if (indexPlus1 != -1)
|
|
|
|
// {
|
|
|
|
// if (m_Fractorium->ui.XaosToRadio->isChecked())
|
|
|
|
// name = QString("From ") + ToString(curr) + QString(" To ") + ToString(indexPlus1);
|
|
|
|
// else
|
|
|
|
// name = QString("From ") + ToString(indexPlus1) + QString(" To ") + ToString(curr);
|
|
|
|
//
|
|
|
|
// //if (xform->m_Name != "")
|
|
|
|
// // name = name + " (" + QString::fromStdString(xform->m_Name) + ")";
|
|
|
|
// }
|
|
|
|
//}
|
2014-07-08 03:11:14 -04:00
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set the xaos value.
|
|
|
|
/// Called when any xaos spinner is changed.
|
|
|
|
/// Resets the rendering process.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sender">The DoubleSpinBox that triggered this event</param>
|
|
|
|
template <typename T>
|
|
|
|
void FractoriumEmberController<T>::XaosChanged(DoubleSpinBox* sender)
|
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
auto p = sender->property("tableindex").toPoint();
|
2014-07-08 03:11:14 -04:00
|
|
|
|
2015-04-08 21:23:29 -04:00
|
|
|
if (auto* xform = m_Ember.GetXform(p.x()))
|
|
|
|
Update([&] { xform->SetXaos(p.y(), sender->value()); });
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Fractorium::OnXaosChanged(double d)
|
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
if (auto* senderSpinBox = dynamic_cast<DoubleSpinBox*>(this->sender()))
|
2014-07-08 03:11:14 -04:00
|
|
|
m_Controller->XaosChanged(senderSpinBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2015-04-08 21:23:29 -04:00
|
|
|
/// Clear xaos table, recreate all spinners based on the xaos used in the current ember.
|
2014-07-08 03:11:14 -04:00
|
|
|
/// </summary>
|
|
|
|
void Fractorium::FillXaosTable()
|
|
|
|
{
|
|
|
|
int spinHeight = 20;
|
2015-04-08 21:23:29 -04:00
|
|
|
int count = int(m_Controller->XformCount());
|
2014-12-11 00:50:15 -05:00
|
|
|
QWidget* w = nullptr;
|
2015-04-08 21:23:29 -04:00
|
|
|
QString lbl("lbl");
|
|
|
|
|
2015-04-27 01:11:56 -04:00
|
|
|
ui.XaosTable->blockSignals(true);
|
2015-04-08 21:23:29 -04:00
|
|
|
ui.XaosTable->setRowCount(count);//This will grow or shrink the number of rows and call the destructor for previous DoubleSpinBoxes.
|
|
|
|
ui.XaosTable->setColumnCount(count);
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
2014-07-08 03:11:14 -04:00
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
for (int j = 0; j < count; j++)
|
|
|
|
{
|
|
|
|
QPoint p(i, j);
|
|
|
|
DoubleSpinBox* spinBox = new DoubleSpinBox(ui.XaosTable, spinHeight, 0.1);
|
|
|
|
|
|
|
|
spinBox->setFixedWidth(35);
|
|
|
|
spinBox->DoubleClick(true);
|
|
|
|
spinBox->DoubleClickZero(1);
|
|
|
|
spinBox->DoubleClickNonZero(0);
|
|
|
|
spinBox->setProperty("tableindex", p);
|
|
|
|
ui.XaosTable->setCellWidget(i, j, spinBox);
|
|
|
|
|
|
|
|
auto wp = ui.XaosTable->item(i, j);
|
|
|
|
|
|
|
|
if (wp)
|
|
|
|
wp->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
|
|
|
connect(spinBox, SIGNAL(valueChanged(double)), this, SLOT(OnXaosChanged(double)), Qt::QueuedConnection);
|
|
|
|
|
|
|
|
if (i == 0 && j == 0)
|
|
|
|
w = spinBox;
|
|
|
|
else
|
|
|
|
w = SetTabOrder(this, w, spinBox);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
ui.XaosTable->setHorizontalHeaderItem(i, new QTableWidgetItem("F" + QString::number(i + 1)));
|
|
|
|
ui.XaosTable->setVerticalHeaderItem(i, new QTableWidgetItem("T" + QString::number(i + 1)));
|
|
|
|
ui.XaosTable->horizontalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
|
|
|
ui.XaosTable->verticalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
2014-07-28 01:25:38 -04:00
|
|
|
|
2015-04-08 21:23:29 -04:00
|
|
|
ui.XaosTable->resizeRowsToContents();
|
|
|
|
ui.XaosTable->resizeColumnsToContents();
|
|
|
|
|
2014-07-28 01:25:38 -04:00
|
|
|
w = SetTabOrder(this, w, ui.ClearXaosButton);
|
2014-10-15 23:09:44 -04:00
|
|
|
w = SetTabOrder(this, w, ui.RandomXaosButton);
|
2015-04-27 01:11:56 -04:00
|
|
|
ui.XaosTable->blockSignals(false);
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Clear all xaos from the current ember.
|
|
|
|
/// </summary>
|
|
|
|
template <typename T>
|
|
|
|
void FractoriumEmberController<T>::ClearXaos()
|
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
Update([&] { m_Ember.ClearXaos(); });
|
|
|
|
FillXaos();
|
2014-07-08 03:11:14 -04:00
|
|
|
}
|
|
|
|
|
2014-10-15 23:09:44 -04:00
|
|
|
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.
|
2014-10-27 17:21:06 -04:00
|
|
|
/// Resets the rendering process.
|
2014-10-15 23:09:44 -04:00
|
|
|
/// </summary>
|
|
|
|
template <typename T>
|
|
|
|
void FractoriumEmberController<T>::RandomXaos()
|
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
Update([&]
|
2014-10-15 23:09:44 -04:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < m_Ember.XformCount(); i++)
|
|
|
|
{
|
2015-04-08 21:23:29 -04:00
|
|
|
if (auto* xform = m_Ember.GetXform(i))
|
2014-10-15 23:09:44 -04:00
|
|
|
{
|
|
|
|
for (size_t j = 0; j < m_Ember.XformCount(); j++)
|
|
|
|
{
|
|
|
|
if (m_Rand.RandBit())
|
2015-04-08 21:23:29 -04:00
|
|
|
xform->SetXaos(j, T(m_Rand.RandBit()));
|
2014-10-15 23:09:44 -04:00
|
|
|
else
|
2015-04-08 21:23:29 -04:00
|
|
|
xform->SetXaos(j, m_Rand.Frand<T>(0, 3));
|
2014-10-15 23:09:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-04-08 21:23:29 -04:00
|
|
|
|
|
|
|
FillXaos();
|
2014-10-15 23:09:44 -04:00
|
|
|
}
|
|
|
|
|
2014-12-11 00:50:15 -05:00
|
|
|
void Fractorium::OnRandomXaosButtonClicked(bool checked) { m_Controller->RandomXaos(); }
|
|
|
|
|
2015-05-03 20:13:14 -04:00
|
|
|
/// <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)
|
|
|
|
{
|
2015-05-15 21:45:15 -04:00
|
|
|
ToggleTableRow(ui.XaosTable, logicalIndex);
|
2015-05-03 20:13:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
{
|
2015-05-15 21:45:15 -04:00
|
|
|
ToggleTableCol(ui.XaosTable, logicalIndex);
|
2015-05-03 20:13:14 -04:00
|
|
|
}
|
|
|
|
|
2014-12-11 00:50:15 -05:00
|
|
|
template class FractoriumEmberController<float>;
|
|
|
|
|
|
|
|
#ifdef DO_DOUBLE
|
|
|
|
template class FractoriumEmberController<double>;
|
|
|
|
#endif
|