# HG changeset patch # User Teemu Piippo # Date 1583939978 -7200 # Node ID 5fe2dd4e161a621254eaa099a26fabbd579c5ed9 # Parent 97c3ce5aa498ec41a6e88fbcceec8a0acbd5ecbc added a render style for pick scene diff -r 97c3ce5aa498 -r 5fe2dd4e161a src/mainwindow.cpp --- a/src/mainwindow.cpp Wed Mar 11 17:19:28 2020 +0200 +++ b/src/mainwindow.cpp Wed Mar 11 17:19:38 2020 +0200 @@ -43,6 +43,7 @@ { offsetof(Ui_MainWindow, actionRenderStyleNormal), gl::RenderStyle::Normal }, { offsetof(Ui_MainWindow, actionRenderStyleBfc), gl::RenderStyle::BfcRedGreen }, { offsetof(Ui_MainWindow, actionRenderStyleRandom), gl::RenderStyle::RandomColors }, + { offsetof(Ui_MainWindow, actionRenderStylePickScene), gl::RenderStyle::PickScene }, }; class A : public QSettings diff -r 97c3ce5aa498 -r 5fe2dd4e161a src/mainwindow.ui --- a/src/mainwindow.ui Wed Mar 11 17:19:28 2020 +0200 +++ b/src/mainwindow.ui Wed Mar 11 17:19:38 2020 +0200 @@ -26,7 +26,7 @@ 0 0 800 - 22 + 24 @@ -53,6 +53,7 @@ + @@ -108,6 +109,14 @@ Random colours + + + true + + + Pick scene colours + + diff -r 97c3ce5aa498 -r 5fe2dd4e161a src/ui/canvas.cpp --- 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(fontMetrics.ascent())}; - break; - case geom::RectangleSide::Left: - break; - case geom::RectangleSide::Bottom: - position += QPointF{0, static_cast(-fontMetrics.descent())}; - break; - case geom::RectangleSide::Right: - position += QPointF{static_cast(-fontMetrics.width(text)), 0}; - break; - } - painter.drawText(position, text); - }; - const QRectF box { - QPointF{0, 0}, - QPointF{static_cast(this->width()), static_cast(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(fontMetrics.ascent())}; + break; + case geom::RectangleSide::Left: + break; + case geom::RectangleSide::Bottom: + position += QPointF{0, static_cast(-fontMetrics.descent())}; + break; + case geom::RectangleSide::Right: + position += QPointF{static_cast(-fontMetrics.width(text)), 0}; + break; + } + painter.drawText(position, text); + }; + const QRectF box { + QPointF{0, 0}, + QPointF{static_cast(this->width()), static_cast(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); + } } } }