File: terraintexturemode.hpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (149 lines) | stat: -rw-r--r-- 4,410 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef CSV_RENDER_TERRAINTEXTUREMODE_H
#define CSV_RENDER_TERRAINTEXTUREMODE_H

#include "editmode.hpp"

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include <QWidget>

#ifndef Q_MOC_RUN
#include "../../model/world/columnimp.hpp"
#include "../widget/brushshapes.hpp"
#include "brushdraw.hpp"
#endif

#include <components/esm3/loadland.hpp>

class QDragMoveEvent;
class QDropEvent;
class QMouseEvent;
class QObject;
class QPoint;
class QWidget;

namespace osg
{
    class Group;
}

namespace CSMDoc
{
    class Document;
}

namespace CSMWorld
{
    class IdTable;
}

namespace CSVWidget
{
    class SceneToolTextureBrush;
    class SceneToolbar;
}

namespace CSVRender
{
    class TerrainSelection;
    class WorldspaceWidget;
    struct WorldspaceHitResult;

    class TerrainTextureMode : public EditMode
    {
        Q_OBJECT

    public:
        enum InteractionType
        {
            InteractionType_PrimaryEdit,
            InteractionType_PrimarySelect,
            InteractionType_SecondaryEdit,
            InteractionType_SecondarySelect,
            InteractionType_None
        };

        /// \brief Editmode for terrain texture grid
        TerrainTextureMode(WorldspaceWidget*, osg::Group* parentNode, QWidget* parent = nullptr);

        void primaryOpenPressed(const WorldspaceHitResult& hit) override;

        /// \brief Create single command for one-click texture editing
        void primaryEditPressed(const WorldspaceHitResult& hit) override;

        /// \brief Open brush settings window
        void primarySelectPressed(const WorldspaceHitResult&) override;

        void secondarySelectPressed(const WorldspaceHitResult&) override;

        void activate(CSVWidget::SceneToolbar*) override;
        void deactivate(CSVWidget::SceneToolbar*) override;

        /// \brief Start texture editing command macro
        bool primaryEditStartDrag(const QPoint& pos) override;

        bool secondaryEditStartDrag(const QPoint& pos) override;
        bool primarySelectStartDrag(const QPoint& pos) override;
        bool secondarySelectStartDrag(const QPoint& pos) override;

        /// \brief Handle texture edit behavior during dragging
        void drag(const QPoint& pos, int diffX, int diffY, double speedFactor) override;

        /// \brief End texture editing command macro
        void dragCompleted(const QPoint& pos) override;

        void dragAborted() override;
        void dragWheel(int diff, double speedFactor) override;
        void dragMoveEvent(QDragMoveEvent* event) override;

        void mouseMoveEvent(QMouseEvent* event) override;

        std::shared_ptr<TerrainSelection> getTerrainSelection();

    private:
        /// \brief Handle brush mechanics, maths regarding worldspace hit etc.
        void editTerrainTextureGrid(const WorldspaceHitResult& hit);

        /// \brief Check if global selection coordinate belongs to cell in view
        bool isInCellSelection(int globalSelectionX, int globalSelectionY);

        /// \brief Handle brush mechanics for texture selection
        void selectTerrainTextures(const std::pair<int, int>& texCoords, unsigned char selectMode);

        /// \brief Push texture edits to command macro
        void pushEditToCommand(CSMWorld::LandTexturesColumn::DataType& newLandGrid, CSMDoc::Document& document,
            CSMWorld::IdTable& landTable, std::string cellId);

        /// \brief Create new cell and land if needed
        bool allowLandTextureEditing(const std::string& textureFileName);

        std::string mCellId;
        ESM::RefId mBrushTexture;
        int mBrushSize;
        CSVWidget::BrushShape mBrushShape;
        std::unique_ptr<BrushDraw> mBrushDraw;
        std::vector<std::pair<int, int>> mCustomBrushShape;
        CSVWidget::SceneToolTextureBrush* mTextureBrushScenetool;
        int mDragMode;
        osg::Group* mParentNode;
        bool mIsEditing;
        std::shared_ptr<TerrainSelection> mTerrainTextureSelection;

        const int cellSize{ ESM::Land::REAL_SIZE };
        const int landTextureSize{ ESM::Land::LAND_TEXTURE_SIZE };

    signals:
        void passBrushTexture(ESM::RefId brushTexture);

    public slots:
        void handleDropEvent(QDropEvent* event);
        void setBrushSize(int brushSize);
        void setBrushShape(CSVWidget::BrushShape brushShape);
        void setBrushTexture(ESM::RefId brushShape);
    };
}

#endif