File: SelectionMouseTools.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (169 lines) | stat: -rw-r--r-- 3,955 bytes parent folder | download | duplicates (3)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#pragma once

#include "imousetool.h"
#include "render/View.h"
#include "Rectangle.h"

class SelectionVolume;

namespace ui
{

/**
 * \brief
 * Abstract base class for all for classes handling the selection-related mouse
 * operations, like Alt-Shift-Click, Selection toggles and drag selections.
*/
class SelectMouseTool: public MouseTool
{
protected:
    // Base epsilon value as read from the registry
    float _selectEpsilon;

    // Epsilon vector (scaled by device dimensions)
    Vector2 _epsilon;

    render::View _view;

public:
    SelectMouseTool();

    virtual Result onMouseDown(Event& ev) override;
    virtual Result onMouseUp(Event& ev) override;

    virtual bool allowChaseMouse() override
    {
        return false;
    }

    virtual unsigned int getPointerMode() override
    {
        return PointerMode::Capture;
    }

protected:
    // Test select method to be implemented by subclasses
    // testSelect will be called onMouseUp()
    virtual void testSelect(Event& ev) = 0;
};

/**
 * \brief
 * Basic mouse selection tool handling left click and left drag selection.
 *
 * Renders an overlay rectangle on the device during an active drag operation.
 */
class BasicSelectionTool: public SelectMouseTool
{
protected:
    Vector2 _start;		// Position at mouseDown
    Vector2 _current;	// Position during mouseMove

    selection::Rectangle _dragSelectionRect;

    enum class SelectionType
    {
        Point,
        Area,
    };

public:
    virtual const std::string& getName() override;
    virtual const std::string& getDisplayName() override;

    Result onMouseDown(Event& ev) override;
    Result onMouseMove(Event& ev) override;

    void onMouseCaptureLost(IInteractiveView& view) override;
    Result onCancel(IInteractiveView& view) override;

    virtual void renderOverlay() override;

protected:
    virtual bool selectFacesOnly()
    {
        return false;
    }

    // Performs a drag- or point-selection test
    virtual void testSelect(Event& ev) override;

    // Recalculates the rectangle used to draw the GUI overlay
    void updateDragSelectionRectangle(Event& ev);

    virtual void performSelectionTest(SelectionVolume& volume, SelectionType type, MouseTool::Event& ev);
};

/**
 * Face-only variant of the BasicSelectionTool.
 */
class DragSelectionMouseToolFaceOnly :
    public BasicSelectionTool
{
public:
    const std::string& getName() override;
    const std::string& getDisplayName() override;

protected:
    bool selectFacesOnly() override
    {
        return true;
    }
};

/**
 * Used to cycle between single selectables while holding a special modifier.
 * The selection candidates are traverse from front to back, moving
 * "deeper" into the scene. Works both in Camera and XY views.
 */
class CycleSelectionMouseTool :
    public SelectMouseTool
{
private:
    // Flag used by the selection logic
    bool _mouseMovedSinceLastSelect;

    // Position of the last testSelect call
    Vector2 _lastSelectPos;

public:
    CycleSelectionMouseTool();

    virtual const std::string& getName() override;
    virtual const std::string& getDisplayName() override;

    Result onMouseMove(Event& ev) override;

    void onMouseCaptureLost(IInteractiveView& view) override;
    Result onCancel(IInteractiveView& view) override;

protected:
    virtual bool selectFacesOnly() 
    {
        return false;
    }

    void testSelect(Event& ev) override;

    // Call the selection system to perform the point selection using the given modifier flag
    virtual void performPointSelection(SelectionVolume& volume, selection::SelectionSystem::EModifier modifier);
};

/**
* Face-only variant of the CycleSelectionMouseTool.
*/
class CycleSelectionMouseToolFaceOnly :
    public CycleSelectionMouseTool
{
public:
    const std::string& getName() override;
    const std::string& getDisplayName() override;

protected:
    bool selectFacesOnly() override
    {
        return true;
    }
};

}