summaryrefslogtreecommitdiff
path: root/src/layout/algorithm/tiled/scrolling/ScrollTapeController.hpp
blob: 8006c4a59c1ac28e5e43c00ad77cfd02b78b9314 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once

#include "../../../../helpers/math/Math.hpp"
#include "../../../../helpers/memory/Memory.hpp"
#include <vector>

namespace Layout::Tiled {

    struct SColumnData;

    enum eScrollDirection : uint8_t {
        SCROLL_DIR_RIGHT = 0,
        SCROLL_DIR_LEFT,
        SCROLL_DIR_DOWN,
        SCROLL_DIR_UP,
    };

    struct SStripData {
        float              size = 1.F;  // size along primary axis
        std::vector<float> targetSizes; // sizes along secondary axis for each target in this strip
        WP<SColumnData>    userData;

        SStripData() = default;
    };

    struct STapeLayoutResult {
        CBox   box;
        size_t stripIndex  = 0;
        size_t targetIndex = 0;
    };

    class CScrollTapeController {
      public:
        CScrollTapeController(eScrollDirection direction = SCROLL_DIR_RIGHT);
        ~CScrollTapeController() = default;

        void              setDirection(eScrollDirection dir);
        eScrollDirection  getDirection() const;
        bool              isPrimaryHorizontal() const;
        bool              isReversed() const;

        size_t            addStrip(float size = 1.0F);
        void              insertStrip(ssize_t afterIndex, float size = 1.0F);
        void              removeStrip(size_t index);
        size_t            stripCount() const;
        SStripData&       getStrip(size_t index);
        const SStripData& getStrip(size_t index) const;
        void              swapStrips(size_t a, size_t b);

        void              setOffset(double offset);
        double            getOffset() const;
        void              adjustOffset(double delta);

        double            calculateMaxExtent(const CBox& usableArea, bool fullscreenOnOne = false) const;
        double            calculateStripStart(size_t stripIndex, const CBox& usableArea, bool fullscreenOnOne = false) const;
        double            calculateStripSize(size_t stripIndex, const CBox& usableArea, bool fullscreenOnOne = false) const;

        CBox              calculateStripBox(size_t stripIndex, const CBox& usableArea, const Vector2D& workspaceOffset, bool fullscreenOnOne = false);
        CBox              calculateTargetBox(size_t stripIndex, size_t targetIndex, const CBox& usableArea, const Vector2D& workspaceOffset, bool fullscreenOnOne = false);

        double            calculateCameraOffset(const CBox& usableArea, bool fullscreenOnOne = false);
        Vector2D          getCameraTranslation(const CBox& usableArea, bool fullscreenOnOne = false);

        void              centerStrip(size_t stripIndex, const CBox& usableArea, bool fullscreenOnOne = false);
        void              fitStrip(size_t stripIndex, const CBox& usableArea, bool fullscreenOnOne = false);

        bool              isStripVisible(size_t stripIndex, const CBox& usableArea, bool fullscreenOnOne = false, bool full = false) const;

        size_t            getStripAtCenter(const CBox& usableArea, bool fullscreenOnOne = false) const;

      private:
        eScrollDirection        m_direction = SCROLL_DIR_RIGHT;
        std::vector<SStripData> m_strips;
        double                  m_offset = 0.0;

        double                  getPrimary(const Vector2D& v) const;
        double                  getSecondary(const Vector2D& v) const;
        void                    setPrimary(Vector2D& v, double val) const;
        void                    setSecondary(Vector2D& v, double val) const;
        bool                    isBeingDragged() const;

        Vector2D                makeVector(double primary, double secondary) const;
    };
};