--- a/src/ui/canvas.cpp Wed Feb 26 22:26:05 2020 +0200 +++ b/src/ui/canvas.cpp Thu Feb 27 11:56:41 2020 +0200 @@ -1,4 +1,5 @@ #include <QMouseEvent> +#include <QPainter> #include "canvas.h" Canvas::Canvas( @@ -22,24 +23,26 @@ void Canvas::mouseMoveEvent(QMouseEvent* event) { -#if 0 - std::optional<glm::vec3> p = this->cameraToGrid(event->pos()); - if (p.has_value()) + const ldraw::Id id = this->pick(event->pos()); + this->highlighted = id; + this->totalMouseMove += (event->pos() - this->lastMousePosition).manhattanLength(); + this->lastMousePosition = event->pos(); + this->worldPosition = this->screenToModelCoordinates(this->lastMousePosition); + if (this->worldPosition.has_value()) { - this->newStatusText("Position: (%1, %2, %3)"_q.arg(p->x).arg(p->y).arg(p->z)); + this->worldPosition = glm::round(*this->worldPosition); + } + if (this->worldPosition.has_value()) + { + this->newStatusText("Position: (%1, %2, %3)"_q + .arg(this->worldPosition->x) + .arg(this->worldPosition->y) + .arg(this->worldPosition->z)); } else { this->newStatusText("Position: <none>"_q); } -#else - const QPointF originAtCamera = this->modelToScreenCoordinates({1, 1, 1}); - this->newStatusText("{1,1,1} is at (%1, %2), cursor at (%3, %4)"_q.arg(originAtCamera.x()).arg(originAtCamera.y()).arg(event->pos().x()).arg(event->pos().y())); -#endif - const ldraw::Id id = this->pick(event->pos()); - this->highlighted = id; - this->totalMouseMove += (event->pos() - this->lastMousePosition).manhattanLength(); - this->lastMousePosition = event->pos(); PartRenderer::mouseMoveEvent(event); } @@ -68,3 +71,16 @@ } PartRenderer::mouseReleaseEvent(event); } + +void Canvas::paintGL() +{ + PartRenderer::paintGL(); + if (this->worldPosition.has_value()) + { + QPainter painter{this}; + painter.setRenderHint(QPainter::Antialiasing); + painter.setPen(Qt::black); + painter.setBrush(Qt::green); + painter.drawEllipse(this->modelToScreenCoordinates(*this->worldPosition), 10, 10); + } +}