Fri, 01 Jul 2022 23:48:27 +0300
Improve click handling
src/basics.h | file | annotate | diff | comparison | revisions | |
src/gl/partrenderer.cpp | file | annotate | diff | comparison | revisions | |
src/gl/partrenderer.h | file | annotate | diff | comparison | revisions |
--- a/src/basics.h Fri Jul 01 16:46:43 2022 +0300 +++ b/src/basics.h Fri Jul 01 23:48:27 2022 +0300 @@ -43,6 +43,7 @@ template<typename T> using opt = std::optional<T>; +using std::chrono::steady_clock; //! \brief Return type of qHash. unsigned int on Qt5, unsigned long on Qt6. using hash_t = decltype(qHash(0));
--- a/src/gl/partrenderer.cpp Fri Jul 01 16:46:43 2022 +0300 +++ b/src/gl/partrenderer.cpp Fri Jul 01 23:48:27 2022 +0300 @@ -319,13 +319,18 @@ if (not this->frozen) { this->totalMouseMove = 0; this->lastMousePosition = event->pos(); + this->lastClickTime = steady_clock::now(); } } void PartRenderer::mouseReleaseEvent(QMouseEvent* event) { - if (not frozen and this->totalMouseMove < (2.0 / sqrt(2)) * 5.0) - { + using namespace std::chrono_literals; + if (true + and not frozen + and this->totalMouseMove < 50.0 / sqrt(2) + and (steady_clock::now() - this->lastClickTime) < 0.5s + ) { for (RenderLayer* layer : this->activeRenderLayers) { layer->mouseClick(event); } @@ -494,3 +499,10 @@ gl::setModelShaderSelectedObjects(&this->shaders, selection); this->update(); } + +glm::vec3 PartRenderer::cameraVector(const QPointF& point) const +{ + const glm::vec3 p1 = this->unproject({point.x(), point.y(), 0}); + const glm::vec3 p2 = this->unproject({point.x(), point.y(), 1}); + return p2 - p1; +}
--- a/src/gl/partrenderer.h Fri Jul 01 16:46:43 2022 +0300 +++ b/src/gl/partrenderer.h Fri Jul 01 23:48:27 2022 +0300 @@ -28,6 +28,7 @@ bool needBuild = true; std::vector<RenderLayer*> activeRenderLayers; std::vector<RenderLayer*> inactiveRenderLayers; + std::chrono::time_point<std::chrono::steady_clock> lastClickTime; bool frozen = false; public: PartRenderer( @@ -45,6 +46,8 @@ bool isDark() const; ElementId pick(QPoint where); void setSelection(const QSet<ElementId>& selectedIds); + glm::vec3 cameraVector(const QPointF& point) const; + Line<3> cameraLine(const QPointF& point) const; Q_SIGNALS: void projectionMatrixChanged(const glm::mat4& newMatrix); void modelMatrixChanged(const glm::mat4& newMatrix); @@ -60,7 +63,6 @@ void mouseReleaseEvent(QMouseEvent* event) override; void keyReleaseEvent(QKeyEvent* event) override; void wheelEvent(QWheelEvent* event) override; - Line<3> cameraLine(const QPointF& point) const; glm::vec3 unproject(const glm::vec3& win) const; void setFragmentStyle(gl::FragmentStyle fragStyle); void renderScene();