aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-06 22:35:40 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-06 22:35:40 +0200
commitc970cc687615f904e66004b6795636fbabb843cb (patch)
tree321f7f109c237e2337e1ccb38811fcd88a534c4f
parente0bc29e318c3e5c7918703a3f5ae91033e28b388 (diff)
downloadEpisodeBrowser-c970cc687615f904e66004b6795636fbabb843cb.tar.gz
Ensure correct mouse position for double click.
-rw-r--r--c/layout.cpp8
-rw-r--r--c/layout.h37
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<long>(GetDoubleClickTime());
- m_time = time;
+ const bool dbl = time-m_time0 <= static_cast<long>(GetDoubleClickTime())
+ && abs(pt.x-m_pt0.x) <= Metric<SM_CXDOUBLECLK>
+ && abs(pt.y-m_pt0.y) <= Metric<SM_CYDOUBLECLK>;
+ 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