src/ui/canvas.cpp

changeset 79
5fe2dd4e161a
parent 73
97df974b5ed5
child 96
165777a20dc7
--- a/src/ui/canvas.cpp	Wed Mar 11 17:19:28 2020 +0200
+++ b/src/ui/canvas.cpp	Wed Mar 11 17:19:38 2020 +0200
@@ -154,84 +154,87 @@
 void Canvas::paintGL()
 {
 	PartRenderer::paintGL();
-	// Render axes
-	{
-		glLineWidth(5);
-		glEnable(GL_LINE_SMOOTH);
-		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
-		this->axesProgram->draw();
-		glDisable(GL_LINE_SMOOTH);
-	}
-	// Render grid
-	{
-		glEnable(GL_BLEND);
-		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-		this->gridProgram->draw();
-		glDisable(GL_BLEND);
-	}
-	if (this->worldPosition.has_value())
+	if (this->renderPreferences.style != gl::RenderStyle::PickScene)
 	{
-		QPainter painter{this};
-		painter.setRenderHint(QPainter::Antialiasing);
-		painter.setPen(Qt::black);
-		painter.setBrush(Qt::green);
-		const QPointF pos = this->modelToScreenCoordinates(*this->worldPosition);
-		painter.drawEllipse(pos, 5, 5);
-		painter.setPen(Qt::white);
-		painter.drawText(pos + QPointF{5, 5}, vectorToString(*this->worldPosition));
-	}
-	{
-		QPainter painter{this};
-		QFont font;
-		//font.setStyle(QFont::StyleItalic);
-		painter.setFont(font);
-		QFontMetrics fontMetrics{font};
-		const auto renderText = [&](const QString& text, const geom::PointOnRectagle& intersection)
+		// Render axes
+		{
+			glLineWidth(5);
+			glEnable(GL_LINE_SMOOTH);
+			glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
+			this->axesProgram->draw();
+			glDisable(GL_LINE_SMOOTH);
+		}
+		// Render grid
+		{
+			glEnable(GL_BLEND);
+			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+			this->gridProgram->draw();
+			glDisable(GL_BLEND);
+		}
+		if (this->worldPosition.has_value())
 		{
-			QPointF position = toQPointF(intersection.position);
-			const geom::RectangleSide side = intersection.side;
-			switch (side)
+			QPainter painter{this};
+			painter.setRenderHint(QPainter::Antialiasing);
+			painter.setPen(Qt::black);
+			painter.setBrush(Qt::green);
+			const QPointF pos = this->modelToScreenCoordinates(*this->worldPosition);
+			painter.drawEllipse(pos, 5, 5);
+			painter.setPen(Qt::white);
+			painter.drawText(pos + QPointF{5, 5}, vectorToString(*this->worldPosition));
+		}
+		{
+			QPainter painter{this};
+			QFont font;
+			//font.setStyle(QFont::StyleItalic);
+			painter.setFont(font);
+			QFontMetrics fontMetrics{font};
+			const auto renderText = [&](const QString& text, const geom::PointOnRectagle& intersection)
 			{
-			case geom::RectangleSide::Top:
-				position += QPointF{0, static_cast<qreal>(fontMetrics.ascent())};
-				break;
-			case geom::RectangleSide::Left:
-				break;
-			case geom::RectangleSide::Bottom:
-				position += QPointF{0, static_cast<qreal>(-fontMetrics.descent())};
-				break;
-			case geom::RectangleSide::Right:
-				position += QPointF{static_cast<qreal>(-fontMetrics.width(text)), 0};
-				break;
-			}
-			painter.drawText(position, text);
-		};
-		const QRectF box {
-			QPointF{0, 0},
-			QPointF{static_cast<qreal>(this->width()), static_cast<qreal>(this->height())}
-		};
-		const QPointF p1 = this->modelToScreenCoordinates(glm::vec3{0, 0, 0});
+				QPointF position = toQPointF(intersection.position);
+				const geom::RectangleSide side = intersection.side;
+				switch (side)
+				{
+				case geom::RectangleSide::Top:
+					position += QPointF{0, static_cast<qreal>(fontMetrics.ascent())};
+					break;
+				case geom::RectangleSide::Left:
+					break;
+				case geom::RectangleSide::Bottom:
+					position += QPointF{0, static_cast<qreal>(-fontMetrics.descent())};
+					break;
+				case geom::RectangleSide::Right:
+					position += QPointF{static_cast<qreal>(-fontMetrics.width(text)), 0};
+					break;
+				}
+				painter.drawText(position, text);
+			};
+			const QRectF box {
+				QPointF{0, 0},
+				QPointF{static_cast<qreal>(this->width()), static_cast<qreal>(this->height())}
+			};
+			const QPointF p1 = this->modelToScreenCoordinates(glm::vec3{0, 0, 0});
 
-		static const struct
-		{
-			QString text;
-			glm::vec3 direction;
-		} directions[] =
-		{
-			{"+𝑥", {1, 0, 0}},
-			{"-𝑥", {-1, 0, 0}},
-			{"+𝑦", {0, 1, 0}},
-			{"-𝑦", {0, -1, 0}},
-			{"+𝑧", {0, 0, 1}},
-			{"-𝑧", {0, 0, -1}},
-		};
-		for (const auto& axis : directions)
-		{
-			const QPointF x_p = this->modelToScreenCoordinates(axis.direction);
-			const auto intersection = geom::rayRectangleIntersection(geom::rayFromPoints(toVec2(p1), toVec2(x_p)), box);
-			if (intersection.has_value())
+			static const struct
+			{
+				QString text;
+				glm::vec3 direction;
+			} directions[] =
 			{
-				renderText(axis.text, *intersection);
+				{"+𝑥", {1, 0, 0}},
+				{"-𝑥", {-1, 0, 0}},
+				{"+𝑦", {0, 1, 0}},
+				{"-𝑦", {0, -1, 0}},
+				{"+𝑧", {0, 0, 1}},
+				{"-𝑧", {0, 0, -1}},
+			};
+			for (const auto& axis : directions)
+			{
+				const QPointF x_p = this->modelToScreenCoordinates(axis.direction);
+				const auto intersection = geom::rayRectangleIntersection(geom::rayFromPoints(toVec2(p1), toVec2(x_p)), box);
+				if (intersection.has_value())
+				{
+					renderText(axis.text, *intersection);
+				}
 			}
 		}
 	}

mercurial