summaryrefslogtreecommitdiff
path: root/src/layout/supplementary/DragController.hpp
blob: 3a0d8071fa2ec3a458cacd699d5cdffa27bc8186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once

#include "../target/Target.hpp"
#include "../../managers/input/InputManager.hpp"

namespace Layout {
    enum eRectCorner : uint8_t;
}

namespace Layout::Supplementary {

    // DragStateController contains logic to begin and end a drag, which shouldn't be part of the layout's job. It's stuff like
    // toggling float when dragging tiled, remembering sizes, checking deltas, etc.
    class CDragStateController {
      public:
        CDragStateController()  = default;
        ~CDragStateController() = default;

        void           dragBegin(SP<ITarget> target, eMouseBindMode mode);
        void           dragEnd();

        void           mouseMove(const Vector2D& mousePos);
        eMouseBindMode mode() const;
        bool           wasDraggingWindow() const;
        bool           dragThresholdReached() const;
        void           resetDragThresholdReached();
        bool           draggingTiled() const;

        /*
            Called to try to pick up window for dragging.
            Updates drag related variables and floats window if threshold reached.
            Return true to reject
        */
        bool        updateDragWindow();

        SP<ITarget> target() const;

      private:
        WP<ITarget>         m_target;

        eMouseBindMode      m_dragMode             = MBIND_INVALID;
        bool                m_wasDraggingWindow    = false;
        bool                m_dragThresholdReached = false;
        bool                m_draggingTiled        = false;

        int                 m_mouseMoveEventCount = 0;
        Vector2D            m_beginDragXY;
        Vector2D            m_lastDragXY;
        Vector2D            m_beginDragPositionXY;
        Vector2D            m_beginDragSizeXY;
        Vector2D            m_draggingWindowOriginalFloatSize;
        Layout::eRectCorner m_grabbedCorner = sc<Layout::eRectCorner>(0) /* CORNER_NONE */;
    };
};