aboutsummaryrefslogtreecommitdiff
path: root/c/layout.h
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 /c/layout.h
parente0bc29e318c3e5c7918703a3f5ae91033e28b388 (diff)
downloadEpisodeBrowser-c970cc687615f904e66004b6795636fbabb843cb.tar.gz
Ensure correct mouse position for double click.
Diffstat (limited to 'c/layout.h')
-rw-r--r--c/layout.h37
1 files changed, 20 insertions, 17 deletions
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