SGL
console.h
1 /*
2  * File: console.h
3  * ---------------
4  * This file contains functions related to the library's graphical console window,
5  * implemented using the Qt graphics library in native C++ instead of Java.
6  *
7  * In general if you #include this file, it will implicitly enable the graphical
8  * console. If you don't want to do that, you can include consoletext.h which
9  * exports the same functions without enabling the graphical console.
10  * Or you can #define a flag named __DONT_ENABLE_QT_GRAPHICAL_CONSOLE right
11  * before #include'ing this header.
12  *
13  * Once the graphical console has been enabled, it cannot easily be turned off
14  * again for that program. Sorry.
15  *
16  * @author Marty Stepp
17  * @version 2021/04/09
18  * - added sgl namespace
19  * @version 2018/11/22
20  * - added headless mode support
21  * @version 2018/10/18
22  * - fixed includes to avoid accidentally enabling GUI unintentionally
23  * @version 2018/09/08
24  * - added doc comments for new documentation generation
25  * @version 2018/08/27
26  * - cleaned up comments
27  * @version 2018/08/23
28  * - renamed to console.h to replace Java version
29  * - separated out gconsolewindow.h/cpp
30  * @version 2018/07/29
31  * - menu, icons, hotkeys
32  * @version 2018/07/26
33  * - refactored GConsoleWindow class
34  * @version 2018/07/15
35  * - initial version, based on io/console.h
36  */
37 
38 
39 #ifndef _console_h
40 #define _console_h
41 
42 #include <string>
43 
44 #ifndef SGL_HEADLESS_MODE
45 namespace sgl {
46 
47 class GConsoleWindow;
48 struct GDimension;
49 struct GPoint;
50 
51 } // namespace sgl
52 #endif // SGL_HEADLESS_MODE
53 
57 void clearConsole();
58 
65 bool getConsoleClearEnabled();
66 
71 /* GWindow::CloseOperation */ int getConsoleCloseOperation();
72 
79 bool getConsoleEcho();
80 
85 bool getConsoleEnabled();
86 
93 bool getConsoleEventOnClose();
94 
99 bool getConsoleExitProgramOnClose();
100 
111 string getConsoleFont();
112 
116 double getConsoleHeight();
117 
121 #ifndef SGL_HEADLESS_MODE
122 ::sgl::GPoint getConsoleLocation();
123 #endif // SGL_HEADLESS_MODE
124 
129 bool getConsoleLocationSaved();
130 
136 bool getConsolePrintExceptions();
137 
144 bool getConsoleSettingsLocked();
145 
149 #ifndef SGL_HEADLESS_MODE
150 ::sgl::GDimension getConsoleSize();
151 #endif // SGL_HEADLESS_MODE
152 
156 double getConsoleWidth();
157 
165 #ifndef SGL_HEADLESS_MODE
166 ::sgl::GConsoleWindow* getConsoleWindow();
167 #endif // SGL_HEADLESS_MODE
168 
172 string getConsoleWindowTitle();
173 
180 void initializeQtGraphicalConsole();
181 
182 // defined in gwindow.h/cpp
183 extern void pause(double milliseconds);
184 
192 void setConsoleClearEnabled(bool value);
193 
197 void setConsoleCloseOperation(/*GWindow::CloseOperation*/ int op);
198 
205 void setConsoleEcho(bool echo);
206 
212 void setConsoleErrorColor(const string& color);
213 
220 void setConsoleEventOnClose(bool eventOnClose);
221 
226 void setConsoleExitProgramOnClose(bool exitOnClose);
227 
242 void setConsoleFont(const string& font);
243 
248 void setConsoleLocation(double x, double y);
249 
254 void setConsoleLocationSaved(bool value);
255 
261 void setConsoleOutputColor(const string& color);
262 
270 void setConsoleSettingsLocked(bool value);
271 
275 void setConsoleSize(double width, double height);
276 
280 void setConsoleWindowTitle(const string& title);
281 
285 void shutdownConsole();
286 
287 #endif // _console_h
288 
289 
290 /*
291  * console.h is weird in that a student's program must be able to #include it
292  * and then magically receive the graphical console instead of the standard one;
293  * but we want other lib files to be able to include console.h to get the
294  * function prototypes without actually turning the graphical console on.
295  * To achieve this, we have the __DONT_ENABLE_QT_GRAPHICAL_CONSOLE flag that lib
296  * files can set right before #include'ing console.h. If they do so, it will
297  * declare the prototypes but not initialize the graphical console.
298  */
299 #ifndef __DONT_ENABLE_QT_GRAPHICAL_CONSOLE
300 
301 extern void setConsoleEnabled(bool);
302 
303 namespace sgl {
304 
305 #ifndef QtConsoleInitializer_created
306 #define QtConsoleInitializer_created
307 
310 class QtConsoleInitializer_private {
311 public:
312  /*
313  * Code to initialize the library.
314  * Implemented as a class constructor so that it will run during
315  * static initialization phase, which happens before the student's
316  * main function.
317  */
318  QtConsoleInitializer_private() {
319  setConsoleEnabled(true);
320  }
321 };
322 
326 static QtConsoleInitializer_private __qt_console_init;
327 #endif // QtConsoleInitializer_created
328 
329 } // namespace sgl
330 
331 #endif // __DONT_ENABLE_QT_GRAPHICAL_CONSOLE
332 
Definition: console.h:45
This struct contains real-valued width and height fields.
Definition: gtypes.h:43
This struct contains real-valued x and y fields.
Definition: gtypes.h:202