Debian Codegraph @

include/ui/imainframe.h

raw
1 #pragma once
2
3 #include "imodule.h"
4 #include <sigc++/signal.h>
5
6 constexpr const char* const MODULE_MAINFRAME("MainFrame");
7
8 class wxFrame;
9 class wxToolBar;
10 class wxBoxSizer;
11
12 /**
13 * Scoped object to block screen updates and display a modal message,
14 * used while reloading shaders, for instance.
15 */
16 class IScopedScreenUpdateBlocker
17 {
18 public:
19 virtual ~IScopedScreenUpdateBlocker() {}
20
21 // For operations without calculatable duration, call pulse() regularly to
22 // provide some visual feedback
23 virtual void pulse() = 0;
24
25 // Update the progress fraction [0..1]
26 virtual void setProgress(float progress) = 0;
27
28 // Set the status message that might be displayed to the user
29 virtual void setMessage(const std::string& message) = 0;
30 };
31 typedef std::shared_ptr<IScopedScreenUpdateBlocker> IScopedScreenUpdateBlockerPtr;
32
33 /**
34 * The MainFrame represents the top-level application window.
35 */
36 class IMainFrame :
37 public RegisterableModule
38 {
39 public:
40 // Returns TRUE if screen updates are enabled
41 virtual bool screenUpdatesEnabled() = 0;
42
43 // Use this to (re-)enable camera and xyview draw updates
44 virtual void enableScreenUpdates() = 0;
45
46 // Use this to disable camera and xyview draw updates until enableScreenUpdates is called.
47 virtual void disableScreenUpdates() = 0;
48
49 /**
50 * Returns the main application window widget. Returns NULL if no window
51 * has been constructed yet.
52 */
53 virtual wxFrame* getWxTopLevelWindow() = 0;
54
55 /**
56 * Returns TRUE if DarkRadiant is currently "in focus", i.e. the app in the foreground.
57 */
58 virtual bool isActiveApp() = 0;
59
60 /**
61 * greebo: Returns the main container widget (a box sizer), where layouts
62 * can start packing widgets into. This resembles the large grey area
63 * in the main window.
64 * May return NULL if mainframe is not constructed yet.
65 */
66 virtual wxBoxSizer* getWxMainContainer() = 0;
67
68 /// Identifiers for application toolbars
69 enum class Toolbar
70 {
71 /// Top horizontal toolbar, containing mostly view-related options
72 TOP,
73
74 /// Left vertical toolbar, containing various edit options
75 LEFT,
76
77 /// Toolbar above the 3D camera view
78 CAMERA
79 };
80
81 /// Obtain a pointer to an application toolbar
82 virtual wxToolBar* getToolbar(Toolbar toolbarID) = 0;
83
84 /**
85 * Updates all viewports which are child of the toplevel window.
86 * Set the force flag to true to redraw immediately insteaf of queueing.
87 */
88 virtual void updateAllWindows(bool force = false) = 0;
89
90 /**
91 * Acquire a screen update blocker object that displays a modal message.
92 * As soon as the object is destroyed screen updates are allowed again.
93 *
94 * Pass the title and the message to display in the small modal window.
95 */
96 virtual IScopedScreenUpdateBlockerPtr getScopedScreenUpdateBlocker(const std::string& title,
97 const std::string& message, bool forceDisplay = false) = 0;
98
99 // Specifies the location controls are added to the main frame
100 enum class Location
101 {
102 PropertyPanel, // a tab in the property notebook
103 FloatingWindow, // a floating window
104 };
105
106 struct ControlSettings
107 {
108 // The location this control is added to
109 Location location;
110
111 // Whether this control is visible
112 bool visible;
113
114 // Default control width when packed in a floating window
115 int defaultFloatingWidth = 128;
116
117 // Default control height when packed in a floating window
118 int defaultFloatingHeight = 128;
119 };
120
121 /**
122 * Add a named control to the main frame. The given setting specifies
123 * where the control is added to and whether it's visible by default.
124 * Persisted user settings might still overrule these default values.
125 *
126 * The suitable point in time to call this method is when
127 * signal_MainFrameConstructed is invoked. This gives the mainframe
128 * time to restore the layout as customised by the user.
129 *
130 * The control has to be registered with the IUserInterfaceModule before it can
131 * be acquired by the mainframe, so make sure this is done beforehand.
132 */
133 virtual void addControl(const std::string& controlName, const ControlSettings& defaultSettings) = 0;
134
135 /**
136 * \brief
137 * A signal emitted when the MainFrame window has been set up.
138 *
139 * Modules can subscribe to this to register any UI parts that require a
140 * valid main window or sub component like the group dialog to be
141 * constructed. This is a one-time signal, after emission the subscribers
142 * will be automatically removed by this class.
143 */
144 virtual sigc::signal<void>& signal_MainFrameConstructed() = 0;
145
146 /**
147 * Signal fired after the MainFrame window is shown the first time
148 * during application start up.
149 * This is a one-time signal, after emission the subscribers will be
150 * automatically removed by this class.
151 */
152 virtual sigc::signal<void>& signal_MainFrameReady() = 0;
153
154 /**
155 * Signal fired when the UI is shutting down, right before the MainFrame
156 * window will be destroyed. Dependant UI modules can listen to this
157 * event to get a chance to clean up and save their state.
158 * This is a one-time signal, after emission the subscribers will be
159 * automatically removed by this class.
160 */
161 virtual sigc::signal<void>& signal_MainFrameShuttingDown() = 0;
162 };
163
164 // This is the accessor for the mainframe module
165 inline IMainFrame& GlobalMainFrame()
166 {
167 static module::InstanceReference<IMainFrame> _reference(MODULE_MAINFRAME);
168 return _reference;
169 }