Debian Codegraph @

include/igrid.h

raw
1 #pragma once
2
3 /* greebo: The interface of the grid system
4 *
5 * Use these methods to set/get the grid size of the xyviews
6 */
7 #include <stdexcept>
8 #include "imodule.h"
9 #include <sigc++/signal.h>
10
11 enum GridSize
12 {
13 GRID_0125 = -3,
14 GRID_025 = -2,
15 GRID_05 = -1,
16 GRID_1 = 0,
17 GRID_2 = 1,
18 GRID_4 = 2,
19 GRID_8 = 3,
20 GRID_16 = 4,
21 GRID_32 = 5,
22 GRID_64 = 6,
23 GRID_128 = 7,
24 GRID_256 = 8,
25 };
26
27 namespace grid
28 {
29
30 inline const char* getStringForSize(GridSize size)
31 {
32 switch (size)
33 {
34 case GRID_0125: return "0.125";
35 case GRID_025: return "0.25";
36 case GRID_05: return "0.5";
37 case GRID_1: return "1";
38 case GRID_2: return "2";
39 case GRID_4: return "4";
40 case GRID_8: return "8";
41 case GRID_16: return "16";
42 case GRID_32: return "32";
43 case GRID_64: return "64";
44 case GRID_128: return "128";
45 case GRID_256: return "256";
46 default:
47 throw new std::logic_error("Grid size not handled in switch!");
48 };
49 }
50
51 // The space the grid is dividing. Regular map editing is using the
52 // World grid, while the Texture Tool is working in UV space.
53 enum class Space
54 {
55 World,
56 Texture,
57 };
58
59 }
60
61 // grid renderings
62 enum GridLook
63 {
64 GRIDLOOK_LINES,
65 GRIDLOOK_DOTLINES,
66 GRIDLOOK_MOREDOTLINES,
67 GRIDLOOK_CROSSES,
68 GRIDLOOK_DOTS,
69 GRIDLOOK_BIGDOTS,
70 GRIDLOOK_SQUARES,
71 };
72
73 constexpr const char* const MODULE_GRID("Grid");
74
75 class IGridManager :
76 public RegisterableModule
77 {
78 public:
79 virtual ~IGridManager() {}
80
81 virtual void setGridSize(GridSize gridSize) = 0;
82
83 // Returns the grid spacing in units of the given space
84 virtual float getGridSize(grid::Space = grid::Space::World) const = 0;
85
86 // Returns the grid power of the currently active grid size
87 virtual int getGridPower(grid::Space = grid::Space::World) const = 0;
88
89 // Returns the base number the exponent is applied to (e.g. 2)
90 virtual int getGridBase(grid::Space = grid::Space::World) const = 0;
91
92 virtual void gridDown() = 0;
93 virtual void gridUp() = 0;
94
95 virtual GridLook getMajorLook() const = 0;
96 virtual GridLook getMinorLook() const = 0;
97
98 /// Signal emitted when the grid is changed
99 virtual sigc::signal<void> signal_gridChanged() const = 0;
100 };
101
102 // This is the accessor for the grid module
103 inline IGridManager& GlobalGrid()
104 {
105 static module::InstanceReference<IGridManager> _reference(MODULE_GRID);
106 return _reference;
107 }