Wed, 11 Mar 2020 17:19:38 +0200
added a render style for pick scene
src/mainwindow.cpp | file | annotate | diff | comparison | revisions | |
src/mainwindow.ui | file | annotate | diff | comparison | revisions | |
src/ui/canvas.cpp | file | annotate | diff | comparison | revisions |
--- 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
--- 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 @@ <x>0</x> <y>0</y> <width>800</width> - <height>22</height> + <height>24</height> </rect> </property> <widget class="QMenu" name="menuFile"> @@ -53,6 +53,7 @@ <addaction name="actionRenderStyleNormal"/> <addaction name="actionRenderStyleBfc"/> <addaction name="actionRenderStyleRandom"/> + <addaction name="actionRenderStylePickScene"/> </widget> <addaction name="menuFile"/> <addaction name="menuView"/> @@ -108,6 +109,14 @@ <string>Random colours</string> </property> </action> + <action name="actionRenderStylePickScene"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="text"> + <string>Pick scene colours</string> + </property> + </action> </widget> <resources/> <connections/>
--- 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); + } } } }