From 4c53364f622520c7d12a3d67e5b19c2901c71f21 Mon Sep 17 00:00:00 2001 From: Person Date: Sun, 28 Jan 2018 17:51:19 -0800 Subject: [PATCH] --Bug fixes -Allow 7 decimal places in variations spinners. -Try to prevent infinite loop that sometimes happens when drawing grid. Unsure if this actually works since it's very hard to reproduce. --- Source/Fractorium/DoubleSpinBox.cpp | 10 ++++++++-- Source/Fractorium/DoubleSpinBox.h | 1 + Source/Fractorium/Fractorium.cpp | 2 +- Source/Fractorium/FractoriumXformsVariations.cpp | 2 -- Source/Fractorium/GLWidget.cpp | 8 ++++++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Source/Fractorium/DoubleSpinBox.cpp b/Source/Fractorium/DoubleSpinBox.cpp index 66e9393..14a0eb8 100644 --- a/Source/Fractorium/DoubleSpinBox.cpp +++ b/Source/Fractorium/DoubleSpinBox.cpp @@ -356,7 +356,7 @@ VariationTreeDoubleSpinBox::VariationTreeDoubleSpinBox(QWidget* p, VariationTree m_WidgetItem = widgetItem; m_Param = param; m_Id = id; - //setDecimals(3); + setDecimals(7); //PI auto piAction = new QAction("PI", this); connect(piAction, SIGNAL(triggered(bool)), this, SLOT(PiActionTriggered(bool)), Qt::QueuedConnection); @@ -426,7 +426,13 @@ void VariationTreeDoubleSpinBox::SqrtThreeActionTriggered(bool checked) { setVal QString VariationTreeDoubleSpinBox::textFromValue(double value) const { - return QWidget::locale().toString(value, 'g', 10); + return QWidget::locale().toString(value, 'g', decimals()); +} + + +double VariationTreeDoubleSpinBox::valueFromText(const QString& text) const +{ + return QWidget::locale().toDouble(text); } /// diff --git a/Source/Fractorium/DoubleSpinBox.h b/Source/Fractorium/DoubleSpinBox.h index 26bc4f8..5552825 100644 --- a/Source/Fractorium/DoubleSpinBox.h +++ b/Source/Fractorium/DoubleSpinBox.h @@ -99,6 +99,7 @@ public: eVariationId GetVariationId() { return m_Id; } VariationTreeWidgetItem* WidgetItem() { return m_WidgetItem; } virtual QString textFromValue(double value) const override; + virtual double valueFromText(const QString& text) const override; public slots: void PiActionTriggered(bool checked = false); diff --git a/Source/Fractorium/Fractorium.cpp b/Source/Fractorium/Fractorium.cpp index c63bd98..2f81ffd 100644 --- a/Source/Fractorium/Fractorium.cpp +++ b/Source/Fractorium/Fractorium.cpp @@ -213,7 +213,7 @@ Fractorium::Fractorium(QWidget* p) //this constructor exits, GLWidget::InitGL() will create the initial flock and start the rendering timer //which executes whenever the program is idle. Upon starting the timer, the renderer //will be initialized. - QTimer::singleShot(500, [&]() { ui.GLDisplay->InitGL(); }); + QTimer::singleShot(1000, [&]() { ui.GLDisplay->InitGL(); }); } /// diff --git a/Source/Fractorium/FractoriumXformsVariations.cpp b/Source/Fractorium/FractoriumXformsVariations.cpp index 6042a1d..cfc24eb 100644 --- a/Source/Fractorium/FractoriumXformsVariations.cpp +++ b/Source/Fractorium/FractoriumXformsVariations.cpp @@ -122,7 +122,6 @@ void FractoriumEmberController::SetupVariationsTree() spinBox->DoubleClickZero(1); spinBox->DoubleClickNonZero(0); spinBox->SmallStep(0.001); - //spinBox->setDecimals(4); tree->setItemWidget(item, 1, spinBox); m_Fractorium->connect(spinBox, SIGNAL(valueChanged(double)), SLOT(OnVariationSpinBoxValueChanged(double)), Qt::QueuedConnection); @@ -153,7 +152,6 @@ void FractoriumEmberController::SetupVariationsTree() varSpinBox->SmallStep(1); } - varSpinBox->setDecimals(4); tree->setItemWidget(paramWidget, 1, varSpinBox); m_Fractorium->connect(varSpinBox, SIGNAL(valueChanged(double)), SLOT(OnVariationSpinBoxValueChanged(double)), Qt::QueuedConnection); } diff --git a/Source/Fractorium/GLWidget.cpp b/Source/Fractorium/GLWidget.cpp index c1ad13c..8d556f4 100644 --- a/Source/Fractorium/GLWidget.cpp +++ b/Source/Fractorium/GLWidget.cpp @@ -897,13 +897,17 @@ void GLEmberController::DrawGrid() { auto renderer = m_Fractorium->m_Controller->Renderer(); double scale = m_FractoriumEmberController->AffineScaleCurrentToLocked(); + //qDebug() << renderer->UpperRightX(false) << " " << renderer->LowerLeftX(false) << " " << renderer->UpperRightY(false) << " " << renderer->LowerLeftY(false); float unitX = (std::abs(renderer->UpperRightX(false) - renderer->LowerLeftX(false)) / 2.0f) / scale; float unitY = (std::abs(renderer->UpperRightY(false) - renderer->LowerLeftY(false)) / 2.0f) / scale; + //qDebug() << unitX << " " << unitY; float xLow = std::floor(-unitX); float xHigh = std::ceil(unitX); float yLow = std::floor(-unitY); float yHigh = std::ceil(unitY); float alpha = 0.25f; + int xsteps = std::ceil(std::abs(xHigh - xLow) / GridStep);//Need these because sometimes the float value never reaches the max and it gets stuck in an infinite loop. + int ysteps = std::ceil(std::abs(yHigh - yLow) / GridStep); Affine2D temp; m4T mat = (temp * scale).ToMat4RowMajor(); m_GL->glPushMatrix(); @@ -913,13 +917,13 @@ void GLEmberController::DrawGrid() m_GL->glBegin(GL_LINES); m_GL->glColor4f(0.5f, 0.5f, 0.5f, alpha); - for (float fx = xLow; fx <= xHigh; fx += GridStep) + for (float fx = xLow, i = 0; fx <= xHigh && i < xsteps; fx += GridStep, i++) { m_GL->glVertex2f(fx, yLow); m_GL->glVertex2f(fx, yHigh); } - for (float fy = yLow; fy < yHigh; fy += GridStep) + for (float fy = yLow, i = 0; fy < yHigh && i < ysteps; fy += GridStep, i++) { m_GL->glVertex2f(xLow, fy); m_GL->glVertex2f(xHigh, fy);