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  * In general if you #include this file, it will implicitly enable the graphical
7  * console. If you don't want to do that, you should #define a flag named
8  * __DONT_ENABLE_QT_GRAPHICAL_CONSOLE right before #include'ing this header.
9  * Once the graphical console has been enabled, it cannot easily be turned off
10  * again for that program.
11  *
12  * @author Marty Stepp
13  * @version 2018/11/22
14  * - added headless mode support
15  * @version 2018/10/18
16  * - fixed includes to avoid accidentally enabling GUI unintentionally
17  * @version 2018/09/08
18  * - added doc comments for new documentation generation
19  * @version 2018/08/27
20  * - cleaned up comments
21  * @version 2018/08/23
22  * - renamed to console.h to replace Java version
23  * - separated out gconsolewindow.h/cpp
24  * @version 2018/07/29
25  * - menu, icons, hotkeys
26  * @version 2018/07/26
27  * - refactored GConsoleWindow class
28  * @version 2018/07/15
29  * - initial version, based on io/console.h
30  */
31 
32 
33 #ifndef _console_h
34 #define _console_h
35 
36 #include <string>
37 
38 #ifndef SPL_HEADLESS_MODE
39 class GConsoleWindow;
40 struct GDimension;
41 struct GPoint;
42 #endif // SPL_HEADLESS_MODE
43 
47 void clearConsole();
48 
55 bool getConsoleClearEnabled();
56 
61 /* GWindow::CloseOperation */ int getConsoleCloseOperation();
62 
69 bool getConsoleEcho();
70 
75 bool getConsoleEnabled();
76 
83 bool getConsoleEventOnClose();
84 
89 bool getConsoleExitProgramOnClose();
90 
101 string getConsoleFont();
102 
106 double getConsoleHeight();
107 
111 #ifndef SPL_HEADLESS_MODE
112 GPoint getConsoleLocation();
113 #endif // SPL_HEADLESS_MODE
114 
119 bool getConsoleLocationSaved();
120 
126 bool getConsolePrintExceptions();
127 
134 bool getConsoleSettingsLocked();
135 
139 #ifndef SPL_HEADLESS_MODE
140 GDimension getConsoleSize();
141 #endif // SPL_HEADLESS_MODE
142 
146 double getConsoleWidth();
147 
155 #ifndef SPL_HEADLESS_MODE
156 GConsoleWindow* getConsoleWindow();
157 #endif // SPL_HEADLESS_MODE
158 
162 string getConsoleWindowTitle();
163 
170 void initializeQtGraphicalConsole();
171 
172 // defined in gwindow.h/cpp
173 extern void pause(double milliseconds);
174 
182 void setConsoleClearEnabled(bool value);
183 
187 void setConsoleCloseOperation(/*GWindow::CloseOperation*/ int op);
188 
195 void setConsoleEcho(bool echo);
196 
202 void setConsoleErrorColor(const string& color);
203 
210 void setConsoleEventOnClose(bool eventOnClose);
211 
216 void setConsoleExitProgramOnClose(bool exitOnClose);
217 
232 void setConsoleFont(const string& font);
233 
238 void setConsoleLocation(double x, double y);
239 
244 void setConsoleLocationSaved(bool value);
245 
251 void setConsoleOutputColor(const string& color);
252 
260 void setConsoleSettingsLocked(bool value);
261 
265 void setConsoleSize(double width, double height);
266 
270 void setConsoleWindowTitle(const string& title);
271 
275 void shutdownConsole();
276 
277 #endif // _console_h
278 
279 
280 /*
281  * console.h is weird in that a student's program must be able to #include it
282  * and then magically receive the graphical console instead of the standard one;
283  * but we want other lib files to be able to include console.h to get the
284  * function prototypes without actually turning the graphical console on.
285  * To achieve this, we have the __DONT_ENABLE_QT_GRAPHICAL_CONSOLE flag that lib
286  * files can set right before #include'ing console.h. If they do so, it will
287  * declare the prototypes but not initialize the graphical console.
288  */
289 #ifndef __DONT_ENABLE_QT_GRAPHICAL_CONSOLE
290 
291 extern void setConsoleEnabled(bool);
292 
293 namespace sgl {
294 namespace qtgui {
295 
296 #ifndef QtConsoleInitializer_created
297 #define QtConsoleInitializer_created
298 
301 class QtConsoleInitializer_private {
302 public:
303  /*
304  * Code to initialize the library.
305  * Implemented as a class constructor so that it will run during
306  * static initialization phase, which happens before the student's
307  * main function.
308  */
309  QtConsoleInitializer_private() {
310  setConsoleEnabled(true);
311  }
312 };
313 
317 static QtConsoleInitializer_private __qt_console_init;
318 #endif // QtConsoleInitializer_created
319 
320 } // namespace qtgui
321 } // namespace sgl
322 
323 #endif // __DONT_ENABLE_QT_GRAPHICAL_CONSOLE
324 
This struct contains real-valued width and height fields.
Definition: gtypes.h:39
Definition: console.h:293
double x
Definition: gtypes.h:218
double y
Definition: gtypes.h:219
This struct contains real-valued x and y fields.
Definition: gtypes.h:198