diff -r c7241f504117 -r 6d95c1a41e6e src/gl/partrenderer.cpp --- a/src/gl/partrenderer.cpp Mon Jun 13 02:18:25 2022 +0300 +++ b/src/gl/partrenderer.cpp Tue Jun 14 17:55:50 2022 +0300 @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -132,6 +133,10 @@ for (RenderLayer* layer : this->activeRenderLayers) { layer->paintGL(); } + QPainter painter{this}; + for (RenderLayer* layer : this->activeRenderLayers) { + layer->overpaint(&painter); + } } void PartRenderer::renderScene() @@ -292,6 +297,7 @@ { const bool left = event->buttons() & Qt::LeftButton; const QPoint move = event->pos() - this->lastMousePosition; + this->totalMouseMove += move.manhattanLength(); if (left and not move.isNull()) { // q_x is the rotation of the brick along the vertical y-axis, because turning the @@ -306,6 +312,27 @@ this->updateModelMatrix(); } this->lastMousePosition = event->pos(); + for (RenderLayer* layer : this->activeRenderLayers) { + layer->mouseMoved(event); + } + this->update(); +} + +void PartRenderer::mousePressEvent(QMouseEvent* event) +{ + this->totalMouseMove = 0; + this->lastMousePosition = event->pos(); +} + +void PartRenderer::mouseReleaseEvent(QMouseEvent* event) +{ + if (this->totalMouseMove < (2.0 / sqrt(2)) * 5.0) + { + for (RenderLayer* layer : this->activeRenderLayers) { + layer->mouseClick(event); + } + this->update(); + } } void PartRenderer::wheelEvent(QWheelEvent* event) @@ -320,6 +347,7 @@ void PartRenderer::addRenderLayer(RenderLayer* layer) { this->activeRenderLayers.push_back(layer); + layer->setRendererPointer(this); this->update(); } @@ -364,12 +392,17 @@ { const glm::vec3 projected = glm::project( point, - this->viewMatrix * glm::mat4_cast(this->modelQuaternion), + this->viewMatrix * this->modelMatrix, this->projectionMatrix, this->viewportVector); return toQPointF(glm::vec2{projected.x, this->height() - projected.y}); } +bool PartRenderer::isDark() const +{ + return luma(this->renderPreferences.backgroundColor) < 0.25; +} + Line<3> PartRenderer::cameraLine(const QPointF& point) const { const glm::vec3 p1 = this->unproject({point.x(), point.y(), 0}); @@ -386,7 +419,7 @@ { return glm::unProject( glm::vec3{win.x, this->height() - win.y, win.z}, - this->viewMatrix * glm::mat4_cast(this->modelQuaternion), + this->viewMatrix * this->modelMatrix, this->projectionMatrix, viewportVector); } @@ -445,3 +478,10 @@ { return this->highlighted; } + +void PartRenderer::setSelection(const QSet& selection) +{ + Q_ASSERT(not selection.contains({0})); + gl::setModelShaderSelectedObjects(&this->shaders, selection); + this->update(); +}