From bc4cef92d8efbf97a9215122abc2d7247c287f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 2 Sep 2022 20:16:04 +0200 Subject: Improve Window object. --- c/drag.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 c/drag.cpp (limited to 'c/drag.cpp') diff --git a/c/drag.cpp b/c/drag.cpp new file mode 100644 index 0000000..b92429a --- /dev/null +++ b/c/drag.cpp @@ -0,0 +1,97 @@ +#include + +#include "datalistview.h" +#include "drag.h" +#include "episodelistview.h" +#include "win32.h" +#include "window.h" + +bool Dragger::IsDouble(const long time, const POINT& pt) +{ + 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; +} + +bool Dragger::IsDown() const +{ + return GetKeyState(VK_LBUTTON) & 0x8000; +} + +bool Dragger::HandleLButtonDown() +{ + POINT pt; + Require(GetRelativeCursorPos(parent.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; +} + +bool Dragger::HandleSetCursor() +{ + POINT pt; + Require(GetRelativeCursorPos(parent.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; +} + +bool DlvDragger::InDragArea(const int x, const int y) const +{ + RECT rrDlv; + Require(GetRelativeRect(parent.dlv.hWnd, &rrDlv)); + + const int pad = EBIsThemeActive()? Dpi(6): 0; + const int extra = EBIsThemeActive()? 0: Dpi(2); + if (x < rrDlv.left || x > rrDlv.right) return false; + if (y < rrDlv.top-pad*2-extra*3 || y > rrDlv.top+extra) return false; + return true; +} + +void DlvDragger::Drag(const int, const int y) const +{ + RECT rrDlv; + Require(GetRelativeRect(parent.dlv.hWnd, &rrDlv)); + + if (y < Dpi(50) || y > rrDlv.bottom-Dpi(20)) return; + + int h; + h = rrDlv.bottom-y; + parent.dlv.SetHeight(h); + parent.UpdateLayout(); + RedrawWindow(parent.hWnd, nullptr, nullptr, + RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_UPDATENOW); +} + +void DlvDragger::Reset() const +{ + parent.dlv.SetHeight(0); + parent.cfg.heightDlv = 0; + parent.UpdateLayout(); +} + +void DlvDragger::Done() const +{ + parent.cfg.heightDlv = parent.dlv.Height(); +} -- cgit v1.2.3