fixed the grid not being black on startup if settings has bright background color

Sat, 05 Mar 2022 13:55:12 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 05 Mar 2022 13:55:12 +0200
changeset 165
f6eab2bd46c2
parent 164
8305e2f968fb
child 166
8857351912d0

fixed the grid not being black on startup if settings has bright background color

src/ui/canvas.cpp file | annotate | diff | comparison | revisions
src/ui/canvas.h file | annotate | diff | comparison | revisions
--- a/src/ui/canvas.cpp	Sat Mar 05 13:38:22 2022 +0200
+++ b/src/ui/canvas.cpp	Sat Mar 05 13:55:12 2022 +0200
@@ -107,17 +107,11 @@
 		connect(this, &PartRenderer::viewMatrixChanged,
 			program, &AbstractBasicShaderProgram::setViewMatrix);
 	}
-	connect(this, &PartRenderer::renderPreferencesChanged, [&]()
-	{
-		if (this->gridProgram.has_value())
-		{
-			const bool isDark = luma(this->renderPreferences.backgroundColor) < 0.25;
-			this->gridProgram->setGridColor(isDark ? Qt::white : Qt::black);
-		}
-	});
+	connect(this, &PartRenderer::renderPreferencesChanged, this, &Canvas::updateCanvasRenderPreferences);
 	PartRenderer::initializeGL();
 	// Set up XZ grid matrix
 	this->setGridMatrix({{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}});
+	this->updateCanvasRenderPreferences();
 }
 
 void Canvas::paintGL()
@@ -344,6 +338,15 @@
 	return points2d;
 }
 
+void Canvas::updateCanvasRenderPreferences()
+{
+	if (this->gridProgram.has_value())
+	{
+		const bool isDark = luma(this->renderPreferences.backgroundColor) < 0.25;
+		this->gridProgram->setGridColor(isDark ? Qt::white : Qt::black);
+	}
+}
+
 /**
  * @brief Clears the selection.
  */
--- a/src/ui/canvas.h	Sat Mar 05 13:38:22 2022 +0200
+++ b/src/ui/canvas.h	Sat Mar 05 13:55:12 2022 +0200
@@ -44,6 +44,7 @@
 	glm::vec3 cameraVector() const;
 	bool isGridPerpendicularToScreen(float threshold) const;
 	QVector<QPointF> convertWorldPointsToScreenPoints(const std::vector<glm::vec3>& worldPoints);
+	Q_SLOT void updateCanvasRenderPreferences();
 	std::optional<GridProgram> gridProgram;
 	std::optional<AxesProgram> axesProgram;
 	std::optional<VertexProgram> vertexProgram;

mercurial