/
SelectionModeToggle.h
105 lines (80 loc) · 3.53 KB
/
SelectionModeToggle.h
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
#pragma once
#include "iselection.h"
#include <sigc++/connection.h>
namespace ui
{
// Adaptor class connecting the EventSystem toggles of the various
// selection modes to the actual state of the backend RadiantSelectionSystem.
class SelectionModeToggle
{
private:
sigc::connection _selectionModeChanged;
sigc::connection _componentModeChanged;
public:
SelectionModeToggle()
{
_selectionModeChanged = GlobalSelectionSystem().signal_selectionModeChanged()
.connect(sigc::mem_fun(*this, &SelectionModeToggle::onSelectionModeChanged));
_componentModeChanged = GlobalSelectionSystem().signal_componentModeChanged()
.connect(sigc::mem_fun(*this, &SelectionModeToggle::onComponentModeChanged));
GlobalEventManager().addToggle("DragVertices", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleComponentSelectionMode", { "Vertex" });
});
GlobalEventManager().addToggle("DragEdges", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleComponentSelectionMode", { "Edge" });
});
GlobalEventManager().addToggle("DragFaces", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleComponentSelectionMode", { "Face" });
});
GlobalEventManager().addToggle("DragEntities", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleEntitySelectionMode");
});
GlobalEventManager().addToggle("SelectionModeGroupPart", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleGroupPartSelectionMode");
});
GlobalEventManager().addAdvancedToggle("SelectionModeMergeActions", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleMergeActionSelectionMode");
return GlobalSelectionSystem().getSelectionMode() == selection::SelectionMode::MergeAction;
});
onSelectionModeChanged(GlobalSelectionSystem().getSelectionMode());
onComponentModeChanged(GlobalSelectionSystem().ComponentMode());
}
~SelectionModeToggle()
{
_selectionModeChanged.disconnect();
_componentModeChanged.disconnect();
}
private:
void onSelectionModeChanged(selection::SelectionMode selectionMode)
{
auto componentMode = GlobalSelectionSystem().ComponentMode();
updateToggleState(selectionMode, componentMode);
}
void onComponentModeChanged(selection::ComponentSelectionMode componentMode)
{
auto selectionMode = GlobalSelectionSystem().getSelectionMode();
updateToggleState(selectionMode, componentMode);
}
void updateToggleState(selection::SelectionMode selectionMode, selection::ComponentSelectionMode componentMode)
{
GlobalEventManager().setToggled("DragVertices",
selectionMode == selection::SelectionMode::Component && componentMode == selection::ComponentSelectionMode::Vertex);
GlobalEventManager().setToggled("DragEdges",
selectionMode == selection::SelectionMode::Component && componentMode == selection::ComponentSelectionMode::Edge);
GlobalEventManager().setToggled("DragFaces",
selectionMode == selection::SelectionMode::Component && componentMode == selection::ComponentSelectionMode::Face);
GlobalEventManager().setToggled("DragEntities",
selectionMode == selection::SelectionMode::Entity && componentMode == selection::ComponentSelectionMode::Default);
GlobalEventManager().setToggled("SelectionModeGroupPart",
selectionMode == selection::SelectionMode::GroupPart && componentMode == selection::ComponentSelectionMode::Default);
GlobalEventManager().setToggled("SelectionModeMergeActions",
selectionMode == selection::SelectionMode::MergeAction && componentMode == selection::ComponentSelectionMode::Default);
}
};
}