From c970cc687615f904e66004b6795636fbabb843cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 6 Aug 2022 22:35:40 +0200 Subject: Ensure correct mouse position for double click. --- c/layout.cpp | 8 ++++---- c/layout.h | 37 ++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/c/layout.cpp b/c/layout.cpp index 24ad11f..09c0958 100644 --- a/c/layout.cpp +++ b/c/layout.cpp @@ -39,7 +39,7 @@ void UpdateLayout(int w, int h) RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN); } -bool DlvDragger::InDragArea(const int x, const int y) +bool DlvDragger::InDragArea(const int x, const int y) const { RECT rrDlv; Require(GetRelativeRect(g_dlv->hWnd, &rrDlv)); @@ -51,7 +51,7 @@ bool DlvDragger::InDragArea(const int x, const int y) return true; } -void DlvDragger::Drag(const int, const int y) +void DlvDragger::Drag(const int, const int y) const { RECT rrDlv; Require(GetRelativeRect(g_dlv->hWnd, &rrDlv)); @@ -66,14 +66,14 @@ void DlvDragger::Drag(const int, const int y) RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_UPDATENOW); } -void DlvDragger::Reset() +void DlvDragger::Reset() const { g_dlv->SetHeight(0); Pl("cfg","set_dlv_height",0); UpdateLayout(); } -void DlvDragger::Done() +void DlvDragger::Done() const { Pl("cfg","set_dlv_height",g_dlv->Height()); } diff --git a/c/layout.h b/c/layout.h index 3d9cc3b..29647e2 100644 --- a/c/layout.h +++ b/c/layout.h @@ -21,18 +21,19 @@ struct Dragger bool HandleLButtonDown(); bool HandleSetCursor(); protected: - bool IsDown(); - bool IsDouble(); - virtual bool InDragArea(int x, int y); + bool IsDown() const; + bool IsDouble(const long time, const POINT& pt); + virtual bool InDragArea(int x, int y) const; /* Perform drag, resizing relevant windows. */ - virtual void Drag(int x, int y); + virtual void Drag(int x, int y) const; /* Reset dragger to automatic position. */ - virtual void Reset(); + virtual void Reset() const; /* Called after drag, when mouse button is released. */ - virtual void Done(); + virtual void Done() const; private: bool m_bActive = false; - long m_time = 0; + long m_time0 = 0; + POINT m_pt0 = {0, 0}; }; /* DlvDragger implements the draggable split between the data list @@ -41,24 +42,26 @@ private: struct DlvDragger : public Dragger { private: - bool InDragArea(int x, int y) override; - void Drag(int x, int y) override; - void Reset() override; - void Done() override; + bool InDragArea(int x, int y) const override; + void Drag(int x, int y) const override; + void Reset() const override; + void Done() const override; }; /* Below follows the implementation of the non-virtual member * functions of Dragger, on which derived objects rely. */ -inline bool Dragger::IsDouble() +inline bool Dragger::IsDouble(const long time, const POINT& pt) { - const long time = GetMessageTime(); - const bool dbl = time-m_time <= static_cast(GetDoubleClickTime()); - m_time = time; + const bool dbl = time-m_time0 <= static_cast(GetDoubleClickTime()) + && abs(pt.x-m_pt0.x) <= Metric + && abs(pt.y-m_pt0.y) <= Metric; + m_time0 = time; + m_pt0 = std::move(pt); return dbl; } -inline bool Dragger::IsDown() +inline bool Dragger::IsDown() const { return GetKeyState(VK_LBUTTON) & 0x8000; } @@ -70,7 +73,7 @@ inline bool Dragger::HandleLButtonDown() Require(GetRelativeCursorPos(g_hWnd, &pt)); if (!InDragArea(pt.x, pt.y)) return false; - if (IsDouble()) { + if (IsDouble(GetMessageTime(), pt)) { m_bActive = false; Reset(); } else -- cgit v1.2.3