diff options
author | John Ankarström <john@ankarstrom.se> | 2022-09-02 02:11:49 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-09-02 02:14:11 +0200 |
commit | 90c7bc237c9cf964c16f0cb48c308a92a8193a5c (patch) | |
tree | 53f165056dffa061a9dfe39b76913edab87056f4 /c/layout.h | |
parent | bb9280267bfb78a8d69adea02f5ed7894833b19d (diff) | |
download | EpisodeBrowser-90c7bc237c9cf964c16f0cb48c308a92a8193a5c.tar.gz |
Use global Window object.
This makes it easier to control initialization and maintain RAII.
Diffstat (limited to 'c/layout.h')
-rw-r--r-- | c/layout.h | 61 |
1 files changed, 5 insertions, 56 deletions
@@ -14,10 +14,14 @@ void UpdateLayout(int w = 0, int h = 0); * HandleSetCursor are called by relevant window procedures upon * WM_(NC)LBUTTONDOWN and WM_SETCURSOR. */ +struct Window; + struct Dragger { + Window& parent; bool HandleLButtonDown(); bool HandleSetCursor(); + inline Dragger(Window& parent) : parent(parent) {} protected: bool IsDown() const; bool IsDouble(const long time, const POINT& pt); @@ -39,6 +43,7 @@ private: struct DlvDragger : public Dragger { + inline DlvDragger(Window& parent) : Dragger(parent) {} private: bool InDragArea(int x, int y) const override; void Drag(int x, int y) const override; @@ -46,60 +51,4 @@ private: 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(const long time, const POINT& pt) -{ - 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() const -{ - return GetKeyState(VK_LBUTTON) & 0x8000; -} - -inline bool Dragger::HandleLButtonDown() -{ - extern HWND g_hWnd; - POINT pt; - Require(GetRelativeCursorPos(g_hWnd, &pt)); - if (!InDragArea(pt.x, pt.y)) return false; - - if (IsDouble(GetMessageTime(), pt)) { - m_bActive = false; - Reset(); - } else - m_bActive = true; - - return m_bActive; -} - -inline bool Dragger::HandleSetCursor() -{ - extern HWND g_hWnd; - POINT pt; - Require(GetRelativeCursorPos(g_hWnd, &pt)); - - extern HCURSOR g_hcSizeNs; - bool r = true; - if (InDragArea(pt.x, pt.y)) - SetCursor(g_hcSizeNs); - else - r = false; - if (!m_bActive) - return r; - Drag(pt.x, pt.y); - if (!IsDown()) { - m_bActive = false; - Done(); - } - return r; -} - #endif |