/
GridUserInterface.cpp
88 lines (66 loc) · 2.28 KB
/
GridUserInterface.cpp
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
#include "GridUserInterface.h"
#include <functional>
#include "iuimanager.h"
#include "imainframe.h"
#include "module/StaticModule.h"
namespace ui
{
const std::string& GridUserInterface::getName() const
{
static std::string _name("GridUserInterface");
return _name;
}
const StringSet& GridUserInterface::getDependencies() const
{
static StringSet _dependencies;
if (_dependencies.empty())
{
_dependencies.insert(MODULE_GRID);
_dependencies.insert(MODULE_EVENTMANAGER);
_dependencies.insert(MODULE_UIMANAGER);
}
return _dependencies;
}
void GridUserInterface::initialiseModule(const ApplicationContext& ctx)
{
rMessage() << getName() << "::initialiseModule called." << std::endl;
// Add the grid status bar element
GlobalUIManager().getStatusBarManager().addTextElement("GridStatus", "grid_up.png",
IStatusBarManager::POS_GRID, _("Current Grid Size"));
GlobalUIManager().getStatusBarManager().setText("GridStatus", "-");
_gridChangedConn = GlobalGrid().signal_gridChanged().connect(
std::bind(&GridUserInterface::onGridChanged, this)
);
// Add a Toggle element for each grid size, such that the Menu items can bind to it
for (int size = GRID_0125; size <= GRID_256; size++)
{
GridSize gridSize = static_cast<GridSize>(size);
std::string toggleName = std::string("SetGrid") + grid::getStringForSize(gridSize);
auto toggle = GlobalEventManager().addToggle(toggleName,
std::bind(&GridUserInterface::toggleGrid, this, gridSize, std::placeholders::_1));
_toggleItemNames.emplace(gridSize, toggleName);
GlobalEventManager().setToggled(toggleName, GlobalGrid().getGridPower() == size);
}
GlobalEventManager().addCommand("GridDown", "GridDown");
GlobalEventManager().addCommand("GridUp", "GridUp");
}
void GridUserInterface::shutdownModule()
{
_gridChangedConn.disconnect();
}
void GridUserInterface::onGridChanged()
{
for (const auto& item : _toggleItemNames)
{
GlobalEventManager().setToggled(item.second, GlobalGrid().getGridPower() == item.first);
}
GlobalUIManager().getStatusBarManager().setText("GridStatus",
fmt::format("{0:g}", GlobalGrid().getGridSize()));
GlobalMainFrame().updateAllWindows();
}
void GridUserInterface::toggleGrid(GridSize size, bool newState)
{
GlobalGrid().setGridSize(size);
}
module::StaticModule<GridUserInterface> gridUiModule;
}