SGL
gwindow.h
1 /*
2  * File: gwindow.h
3  * ---------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/09
7  * - added sgl namespace
8  * @version 2021/04/03
9  * - removed dependency on custom collections
10  * @version 2019/05/05
11  * - added static method for isDarkMode checking support
12  * - added static methods to ask for system default widget bg/fg color
13  * @version 2019/04/09
14  * - added toolbar support
15  * @version 2018/10/20
16  * - added high-density screen features
17  * @version 2018/09/09
18  * - added doc comments for new documentation generation
19  * @version 2018/09/05
20  * - refactored to use a border layout GContainer "content pane" for storing all interactors
21  * @version 2018/08/23
22  * - renamed to gwindow.h to replace Java version
23  * @version 2018/07/29
24  * - menu bars
25  * @version 2018/06/25
26  * - initial version
27  */
28 
29 
30 #ifndef _gwindow_h
31 #define _gwindow_h
32 
33 #include <map>
34 #include <set>
35 #include <string>
36 #include <QCloseEvent>
37 #include <QEvent>
38 #include <QLayout>
39 #include <QMainWindow>
40 #include <QRect>
41 
42 #include "gcanvas.h"
43 #include "gcontainer.h"
44 #include "gdrawingsurface.h"
45 #include "geventqueue.h"
46 #include "ginteractor.h"
47 #include "gtypes.h"
48 
49 namespace sgl {
50 
51 class _Internal_QMainWindow;
52 
102 class GWindow : public GObservable, public virtual GForwardDrawingSurface {
103 public:
107  enum Region {
113  };
114 
123  };
124 
129  static const int DEFAULT_WIDTH;
130 
135  static const int DEFAULT_HEIGHT;
136 
141  static const int HIGH_DPI_SCREEN_THRESHOLD;
142 
147  static const int STANDARD_SCREEN_DPI;
148 
153  static const string DEFAULT_ICON_FILENAME;
154 
158  GWindow(bool visible = true);
159 
163  GWindow(double width, double height, bool visible = true);
164 
168  GWindow(double x, double y, double width, double height, bool visible = true);
169 
173  ~GWindow() override;
174 
180  virtual void add(GInteractor* interactor);
181 
188  virtual void add(GInteractor* interactor, double x, double y);
189 
194  virtual void add(GInteractor& interactor);
195 
201  virtual void add(GInteractor& interactor, double x, double y);
202 
208  virtual void add(GObject* obj);
209 
216  virtual void add(GObject* obj, double x, double y);
217 
222  virtual void add(GObject& obj);
223 
229  virtual void add(GObject& obj, double x, double y);
230 
235  virtual QMenu* addMenu(const string& text);
236 
245  virtual QAction* addMenuItem(const string& menu, const string& item,
246  const string& icon = "");
247 
256  virtual QAction* addMenuItem(const string& menu, const string& item,
257  const string& icon, GEventListenerVoid func);
258 
267  virtual QAction* addMenuItem(const string& menu, const string& item,
268  const QIcon& icon, GEventListenerVoid func);
269 
278  virtual QAction* addMenuItem(const string& menu, const string& item,
279  const QPixmap& icon, GEventListenerVoid func);
280 
289  virtual QAction* addMenuItemCheckBox(const string& menu, const string& item,
290  bool checked = false,
291  const string& icon = "");
292 
301  virtual QAction* addMenuItemCheckBox(const string& menu, const string& item,
302  bool checked,
303  const string& icon, GEventListenerVoid func);
304 
309  virtual QAction* addMenuSeparator(const string& menu);
310 
318  virtual QMenu* addSubMenu(const string& menu, const string& submenu);
319 
324  virtual void addToRegion(GInteractor* interactor, Region region);
325 
330  virtual void addToRegion(GInteractor* interactor, const string& region = "Center");
331 
335  virtual void addToRegion(GInteractor& interactor, Region region);
336 
340  virtual void addToRegion(GInteractor& interactor, const string& region = "Center");
341 
345  virtual void addToolbar(const string& title = "");
346 
353  virtual QAction* addToolbarItem(const string& item,
354  const string& icon = "");
355 
362  virtual QAction* addToolbarItem(const string& item,
363  const string& icon,
364  GEventListenerVoid func);
365 
372  virtual QAction* addToolbarItem(const string& item,
373  const QIcon& icon,
374  GEventListenerVoid func);
375 
382  virtual QAction* addToolbarItem(const string& item,
383  const QPixmap& icon,
384  GEventListenerVoid func);
385 
390  virtual QAction* addToolbarSeparator();
391 
395  void clear() override;
396 
401  virtual void clearCanvas();
402 
411  virtual void clearCanvasObjects();
412 
422  virtual void clearCanvasPixels();
423 
427  virtual void clearRegion(Region region);
428 
432  virtual void clearRegion(const string& region);
433 
437  virtual void clearToolbarItems();
438 
442  virtual void center();
443 
449  static string chooseLightDarkModeColor(const string& lightColor,
450  const string& darkColor);
451 
457  static int chooseLightDarkModeColorInt(int lightColor, int darkColor);
458 
464  virtual void close();
465 
475  virtual void compareToImage(const string& filename, bool ignoreWindowSize = true) const;
476 
482  bool eventsEnabled() const override;
483 
489  virtual GCanvas* getCanvas() const;
490 
494  virtual double getCanvasHeight() const;
495 
499  virtual GDimension getCanvasSize() const;
500 
504  virtual double getCanvasWidth() const;
505 
510  virtual CloseOperation getCloseOperation() const;
511 
518  static string getDefaultInteractorBackgroundColor();
519 
527 
534  static string getDefaultInteractorTextColor();
535 
543 
549  virtual GObject* getGObject(int index) const;
550 
556  virtual GObject* getGObjectAt(double x, double y) const;
557 
561  virtual int getGObjectCount() const;
562 
568  static QMainWindow* getLastWindow();
569 
574  virtual GPoint getLocation() const;
575 
580  virtual double getHeight() const;
581 
588  virtual GDimension getPreferredSize() const;
589 
593  virtual double getRegionHeight(Region region) const;
594 
598  virtual double getRegionHeight(const string& region) const;
599 
603  virtual GDimension getRegionSize(Region region) const;
604 
608  virtual GDimension getRegionSize(const string& region) const;
609 
613  virtual double getRegionWidth(Region region) const;
614 
618  virtual double getRegionWidth(const string& region) const;
619 
624  static int getScreenDpi();
625 
630  static double getScreenDpiScaleRatio();
631 
635  static double getScreenHeight();
636 
640  static GDimension getScreenSize();
641 
645  static double getScreenWidth();
646 
651  virtual GDimension getSize() const;
652 
656  virtual string getTitle() const;
657 
658  /* @inherit */
659  string getType() const override;
660 
666  virtual QWidget* getWidget() const;
667 
672  virtual double getWidth() const;
673 
678  virtual double getX() const;
679 
684  virtual double getY() const;
685 
689  virtual bool hasToolbar() const;
690 
695  virtual void hide();
696 
705  virtual bool inBounds(double x, double y) const;
706 
711  virtual bool inCanvasBounds(double x, double y) const;
712 
719  static bool isDarkMode();
720 
726  static bool isHighDensityScreen();
727 
732  static bool isHighDpiScalingEnabled();
733 
738  virtual bool isMaximized() const;
739 
744  virtual bool isMinimized() const;
745 
749  virtual bool isOpen() const;
750 
751  /* @inherit */
752  bool isRepaintImmediately() const override;
753 
758  virtual bool isResizable() const;
759 
763  virtual bool isVisible() const;
764 
770  virtual void loadCanvasPixels(const string& filename);
771 
775  virtual void maximize();
776 
781  virtual void minimize();
782 
789  virtual void pack();
790 
796  virtual void pause(double ms);
797 
804  virtual void rememberPosition();
805 
812  virtual void remove(GInteractor* interactor);
813 
819  virtual void remove(GInteractor& interactor);
820 
826  virtual void remove(GObject* obj);
827 
832  virtual void remove(GObject& obj);
833 
838  virtual void removeClickListener();
839 
845  virtual void removeFromRegion(GInteractor* interactor, Region region);
846 
852  virtual void removeFromRegion(GInteractor* interactor, const string& region);
853 
858  virtual void removeFromRegion(GInteractor& interactor, Region region);
859 
864  virtual void removeFromRegion(GInteractor& interactor, const string& region);
865 
870  virtual void removeKeyListener();
871 
876  virtual void removeMenuListener();
877 
882  virtual void removeMouseListener();
883 
888  virtual void removeTimerListener();
889 
893  virtual void removeToolbar();
894 
899  virtual void removeWindowListener();
900 
906  virtual void requestFocus();
907 
911  virtual void restore();
912 
919  virtual void saveCanvasPixels(const string& filename);
920 
921  /* @inherit */
922  void setBackground(int color) override;
923 
924  /* @inherit */
925  void setBackground(const string& color) override;
926 
931  virtual void setCanvasHeight(double height);
932 
937  virtual void setCanvasSize(double width, double height);
938 
943  virtual void setCanvasSize(const GDimension& size);
944 
949  virtual void setCanvasWidth(double width);
950 
959  virtual void setClickListener(GEventListener func);
960 
969  virtual void setClickListener(GEventListenerVoid func);
970 
974  virtual void setCloseOperation(CloseOperation op);
975 
980  virtual void setExitOnClose(bool exitOnClose);
981 
985  virtual void setHeight(double width);
986 
992  virtual void setKeyListener(GEventListener func);
993 
999  virtual void setKeyListener(GEventListenerVoid func);
1000 
1004  virtual void setLocation(double x, double y);
1005 
1009  virtual void setLocation(const GPoint& p);
1010 
1015  virtual void setMenuItemEnabled(const string& menu, const string& item, bool enabled);
1016 
1022  virtual void setMenuListener(GEventListener func);
1023 
1029  virtual void setMenuListener(GEventListenerVoid func);
1030 
1036  virtual void setMouseListener(GEventListener func);
1037 
1043  virtual void setMouseListener(GEventListenerVoid func);
1044 
1049  virtual void setRegionAlignment(Region region, HorizontalAlignment halign);
1050 
1055  virtual void setRegionAlignment(Region region, VerticalAlignment valign);
1056 
1061  virtual void setRegionAlignment(Region region, HorizontalAlignment halign, VerticalAlignment valign);
1062 
1067  virtual void setRegionAlignment(const string& region, const string& align);
1068 
1073  virtual void setRegionAlignment(const string& region, const string& halign, const string& valign);
1074 
1079  virtual void setRegionHorizontalAlignment(Region region, HorizontalAlignment halign);
1080 
1085  virtual void setRegionHorizontalAlignment(const string& region, const string& halign);
1086 
1091  virtual void setRegionVerticalAlignment(const string& region, const string& valign);
1092 
1097  virtual void setRegionVerticalAlignment(Region region, VerticalAlignment valign);
1098 
1103  virtual void setResizable(bool resizable);
1104 
1112  virtual void setSize(double width, double height);
1113 
1121  virtual void setSize(const GDimension& size);
1122 
1128  virtual void setTimerListener(double ms, GEventListener func);
1129 
1135  virtual void setTimerListener(double ms, GEventListenerVoid func);
1136 
1137  // TODO: setTimerListenerOnce?
1138 
1143  virtual void setTitle(const string& title);
1144 
1150  virtual void setVisible(bool visible);
1151 
1155  virtual void setWidth(double width);
1156 
1160  virtual void setWindowIcon(const string& iconFile);
1161 
1167  virtual void setWindowListener(GEventListener func);
1168 
1174  virtual void setWindowListener(GEventListenerVoid func);
1175 
1180  virtual void setWindowTitle(const string& title);
1181 
1185  virtual void setX(double x);
1186 
1190  virtual void setY(double y);
1191 
1196  virtual void show();
1197 
1203  virtual void sleep(double ms);
1204 
1209  virtual void toBack();
1210 
1215  virtual void toFront();
1216 
1217 protected:
1221  virtual void processKeyPressEventInternal(QKeyEvent* event);
1222 
1223 private:
1224  Q_DISABLE_COPY(GWindow)
1225 
1226  static _Internal_QMainWindow* _lastWindow;
1227 
1228  void ensureForwardTarget() override;
1229  void _init(double width, double height, bool visible);
1230  static Region stringToRegion(const string& regionStr);
1231 
1232  _Internal_QMainWindow* _iqmainwindow;
1233  GContainer* _contentPane;
1234  GCanvas* _canvas;
1235  bool _resizable;
1236  CloseOperation _closeOperation;
1237  std::map<string, QMenu*> _menuMap;
1238  std::map<string, QAction*> _menuActionMap;
1239  QToolBar* _toolbar;
1240 
1241  friend class GInteractor;
1242  friend class _Internal_QMainWindow;
1243 };
1244 
1245 
1246 // global functions for compatibility
1247 
1253 int convertColorToRGB(const string& colorName);
1254 
1262 string convertRGBToColor(int rgb);
1263 
1268 void exitGraphics();
1269 
1273 double getScreenHeight();
1274 
1279 
1283 double getScreenWidth();
1284 
1289 void pause(double milliseconds);
1290 
1295 void repaint();
1296 
1297 
1302 class _Internal_QMainWindow : public QMainWindow {
1303  Q_OBJECT
1304 
1305 public:
1306  _Internal_QMainWindow(GWindow* gwindow, QWidget* parent = nullptr);
1307 
1308  void changeEvent(QEvent* event) override;
1309  void closeEvent(QCloseEvent* event) override;
1310  void keyPressEvent(QKeyEvent* event) override;
1311  void resizeEvent(QResizeEvent* event) override;
1312  void timerEvent(QTimerEvent* event) override;
1313  virtual bool timerExists(int id = -1);
1314  virtual int timerStart(double ms);
1315  virtual void timerStop(int id = -1);
1316 
1317 public slots:
1318  void handleMenuAction(const string& menu, const string& item);
1319 
1320 private:
1321  GWindow* _gwindow;
1322  std::set<int> _timerIDs;
1323 
1324  void processTimerEvent();
1325 
1326  friend class GWindow;
1327 };
1328 
1329 } // namespace sgl
1330 
1331 #endif // _gwindow_h
A GContainer is a logical grouping for interactors.
Definition: gcontainer.h:73
virtual void setLocation(double x, double y)
Sets the window&#39;s top-left x/y location on the screen to the given coordinates.
Definition: gwindow.cpp:1084
Definition: gwindow.h:122
virtual bool isMinimized() const
Returns true if the window is in a minimized (iconified) state, which often displays as the window be...
Definition: gwindow.cpp:861
This class represents a graphics window that supports simple graphics.
Definition: gwindow.h:102
virtual void maximize()
Puts the window in a maximized state, occupying the entire screen.
Definition: gwindow.cpp:886
string getType() const override
Returns the concrete type of the object as a string, such as "GButton" or "GWindow".
Definition: gwindow.cpp:793
virtual double getRegionHeight(Region region) const
Returns the height of the given region of the window in pixels.
Definition: gwindow.cpp:736
virtual void setCloseOperation(CloseOperation op)
Sets what should happen when the window is closed.
Definition: gwindow.cpp:1065
virtual void show()
Sets the window to be visible on the screen.
Definition: gwindow.cpp:1290
GWindow(bool visible=true)
Creates a new window of a default width and height.
Definition: gwindow.cpp:78
virtual bool isOpen() const
Returns true if the window is currently open and visible on the screen.
Definition: gwindow.cpp:865
Region
The five regions of window border layouts.
Definition: gwindow.h:107
virtual void setWindowListener(GEventListener func)
Sets a window listener on this window so that it will be called when window events occur...
Definition: gwindow.cpp:1258
Definition: gwindow.h:120
void exitGraphics()
Closes all graphics windows and exits from the application without waiting for any additional user in...
Definition: gwindow.cpp:1338
virtual CloseOperation getCloseOperation() const
Returns a constant representing the action that will be taken when the user closes the window...
Definition: gwindow.cpp:662
static double getScreenHeight()
Returns the height of the entire screen in pixels.
Definition: gwindow.cpp:769
HorizontalAlignment
The supported kinds of horizontal alignment of a widget or onscreen object.
Definition: gtypes.h:136
virtual void setResizable(bool resizable)
Sets whether the window allows itself to be resized.
Definition: gwindow.cpp:1178
Definition: gwindow.h:112
Definition: gcontainer.h:103
virtual QAction * addToolbarItem(string item, string icon="")
Adds a new item to the window&#39;s toolbar.
Definition: gwindow.cpp:415
virtual int getGObjectCount() const
Returns the total number of graphical objects in the window&#39;s canvas.
Definition: gwindow.cpp:712
Definition: gcontainer.h:104
virtual QAction * addMenuSeparator(string menu)
Adds a horizontal line separator to the end of the given menu.
Definition: gwindow.cpp:343
Definition: gwindow.h:110
virtual void saveCanvasPixels(string filename)
Writes the contents of the window&#39;s graphical canvas to the given output filename.
Definition: gwindow.cpp:1023
virtual bool isVisible() const
Returns true if the window is visible on the screen.
Definition: gwindow.cpp:877
double getScreenHeight()
Returns the height of the entire display screen.
Definition: gwindow.cpp:1342
virtual void clearCanvasObjects()
Removes all graphical objects from the graphical canvas in this window.
Definition: gwindow.cpp:554
virtual GDimension getRegionSize(Region region) const
Returns the width and height of the given region of the window in pixels.
Definition: gwindow.cpp:744
static bool isHighDpiScalingEnabled()
Returns whether we should scale some windows when run on high-density screens.
Definition: gwindow.cpp:848
virtual void close()
Closes the window.
Definition: gwindow.cpp:599
Definition: gwindow.h:109
virtual void setWidth(double width)
Sets the window&#39;s total width in pixels.
Definition: gwindow.cpp:1245
virtual string getTitle() const
Returns the title bar text for the window.
Definition: gwindow.cpp:789
virtual void setMouseListener(GEventListener func)
Sets a mouse listener on the window&#39;s canvas so that it will be called when the user moves or clicks ...
Definition: gwindow.cpp:1134
virtual void addToRegion(GInteractor *interactor, Region region)
Adds the given interactor to the given region in this window.
Definition: gwindow.cpp:376
static bool isHighDensityScreen()
Returns whether the dots-per-inch of the screen are high enough to consider it a "high-density" scree...
Definition: gwindow.cpp:844
virtual void setCanvasHeight(double height)
Resizes the window so that its central canvas region will occupy exactly the given height in pixels...
Definition: gwindow.cpp:1043
virtual void setSize(double width, double height)
Sets the window&#39;s total width and height in pixels.
Definition: gwindow.cpp:1200
virtual void removeMenuListener()
Removes the menu listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:976
virtual void loadCanvasPixels(string filename)
Reads pixel data from the file with the given name and loads it into the window&#39;s canvas area...
Definition: gwindow.cpp:881
virtual double getHeight() const
Returns the total height of the window in pixels, excluding its title bar and borders.
Definition: gwindow.cpp:724
virtual GDimension getSize() const
Returns the total width and height of the window in pixels, excluding its title bar and borders...
Definition: gwindow.cpp:785
virtual void setClickListener(GEventListener func)
Sets a mouse listener on this window so that it will be called when the mouse is clicked on the windo...
Definition: gwindow.cpp:1110
Definition: gcontainer.h:101
~GWindow() override
Frees memory allocated internally by the window.
Definition: gwindow.cpp:133
virtual void removeFromRegion(GInteractor *interactor, Region region)
Removes the given interactor from the given region within this window.
Definition: gwindow.cpp:943
virtual void clearRegion(Region region)
Removes all interactors from the given region of this window.
Definition: gwindow.cpp:566
virtual GObject * getGObjectAt(double x, double y) const
Returns the top-most graphical object in the z-ordering in the window&#39;s graphical canvas that touches...
Definition: gwindow.cpp:704
void pause(double milliseconds)
Pauses for the indicated number of milliseconds.
Definition: gwindow.cpp:1355
void repaint()
Issues a request to update the most recently created graphics window.
Definition: gwindow.cpp:1360
This class is the common superclass of all graphical objects that can be displayed on a graphical win...
Definition: gobjects.h:66
std::function< void(GEvent)> GEventListener
Types for the event listener functions to be passed to various interactors.
Definition: gevent.h:38
virtual void setWindowIcon(string iconFile)
Sets the window to use the.
Definition: gwindow.cpp:1249
Definition: console.h:45
virtual bool isResizable() const
Returns true if the window allows itself to be resized.
Definition: gwindow.cpp:873
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:52
virtual void addToolbar(string title="")
Adds a toolbar to this window where action buttons can be placed.
Definition: gwindow.cpp:403
Definition: gcontainer.h:105
virtual double getY() const
Returns the y location of the top edge of the interior of the window on screen, excluding any onscree...
Definition: gwindow.cpp:809
virtual void setCanvasSize(double width, double height)
Resizes the window so that its central canvas region will occupy exactly the given width and height i...
Definition: gwindow.cpp:1048
static string getDefaultInteractorBackgroundColor()
Returns the default color for backgrounds of interactors as a string.
Definition: gwindow.cpp:666
virtual void add(GInteractor *interactor)
Adds the given interactor to the center region of the window.
Definition: gwindow.cpp:144
static const int HIGH_DPI_SCREEN_THRESHOLD
The minimum number of dots per inch before a screen is considered to be high-density or high-DPI...
Definition: gwindow.h:141
A GCanvas is a graphical drawing surface on which you can draw shapes, lines, and colors...
Definition: gcanvas.h:75
virtual void setHeight(double width)
Sets the window&#39;s total height in pixels.
Definition: gwindow.cpp:1080
virtual QAction * addMenuItem(string menu, string item, string icon="")
Adds a new menu item to the given menu.
Definition: gwindow.cpp:202
virtual void requestFocus()
Asks the system to assign the keyboard focus to the window, which brings it to the top and ensures th...
Definition: gwindow.cpp:1010
virtual QMenu * addMenu(string text)
Adds a menu with the given text to the window&#39;s top menu bar.
Definition: gwindow.cpp:186
Definition: gwindow.h:119
virtual GCanvas * getCanvas() const
Returns a direct pointer to the window&#39;s internal graphical canvas on which shapes and objects are dr...
Definition: gwindow.cpp:642
static int getScreenDpi()
Returns the dots-per-inch of the screen.
Definition: gwindow.cpp:760
static int chooseLightDarkModeColorInt(int lightColor, int darkColor)
Returns which color to use depending on whether the user&#39;s computer is in light or dark mode...
Definition: gwindow.cpp:595
virtual void clearCanvasPixels()
Resets the background layer of pixels in the window&#39;s canvas to the window&#39;s background color...
Definition: gwindow.cpp:560
virtual void removeKeyListener()
Removes the key listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:970
virtual void setMenuListener(GEventListener func)
Sets a menu listener on this window so that it will be called when menu items are clicked...
Definition: gwindow.cpp:1126
static int getDefaultInteractorTextColorInt()
Returns the default color for text on interactors as an RGB integer.
Definition: gwindow.cpp:685
static bool isDarkMode()
Returns true if the user&#39;s computer is in "dark mode." This is a popular dark color scheme mostly use...
Definition: gwindow.cpp:829
bool isRepaintImmediately() const override
Returns true if the interactor should repaint itself automatically whenever any change is made to its...
Definition: gwindow.cpp:869
static string chooseLightDarkModeColor(string lightColor, string darkColor)
Returns which color to use depending on whether the user&#39;s computer is in light or dark mode...
Definition: gwindow.cpp:590
Definition: gwindow.h:108
virtual void setVisible(bool visible)
Sets whether the window can be seen on the screen.
Definition: gwindow.cpp:1239
virtual void setRegionHorizontalAlignment(Region region, HorizontalAlignment halign)
Sets the horizontal alignment of interactors in the given region of the window.
Definition: gwindow.cpp:1162
std::function< void()> GEventListenerVoid
Types for the event listener functions to be passed to various interactors.
Definition: gevent.h:44
virtual void removeToolbar()
Removes the toolbar from this window, if one was present.
Definition: gwindow.cpp:990
virtual void removeTimerListener()
Removes the timer listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:986
virtual void setMenuItemEnabled(string menu, string item, bool enabled)
Sets whether the given item in the given menu is enabled or disabled.
Definition: gwindow.cpp:1094
int convertColorToRGB(string colorName)
Converts a color name into an integer that encodes the red, green, and blue components of the color...
Definition: gwindow.cpp:1330
static double getScreenWidth()
Returns the width of the entire screen in pixels.
Definition: gwindow.cpp:781
virtual void minimize()
Puts the window in a minimized (iconified) state, which often displays as the window being hidden exc...
Definition: gwindow.cpp:892
static const string DEFAULT_ICON_FILENAME
The default file name used to load a GWindow&#39;s initial title bar icon.
Definition: gwindow.h:153
static int getDefaultInteractorBackgroundColorInt()
Returns the default color for text on interactors as an RGB integer.
Definition: gwindow.cpp:670
virtual void setRegionVerticalAlignment(string region, string valign)
Sets the vertical alignment of interactors in the given region of the window.
Definition: gwindow.cpp:1174
A GObservable object is one that is able to send out events.
Definition: gobservable.h:40
static const int DEFAULT_HEIGHT
The default height of a newly created window in pixels if its height is not explicitly specified...
Definition: gwindow.h:135
static double getScreenDpiScaleRatio()
Returns the ratio of this screen&#39;s DPI compared to a normal low-DPI screen.
Definition: gwindow.cpp:764
static const int STANDARD_SCREEN_DPI
The minimum number of dots per inch on a "normal" low-DPI screen.
Definition: gwindow.h:147
virtual GDimension getPreferredSize() const
Returns the size that the window would prefer to be.
Definition: gwindow.cpp:732
virtual GPoint getLocation() const
Returns the x/y location of the top-left corner of the interior of the window on screen, excluding any onscreen window title bar and frame.
Definition: gwindow.cpp:728
virtual void hide()
Makes the window be not visible on the screen.
Definition: gwindow.cpp:817
GDimension getScreenSize()
Returns the width/height of the entire display screen.
Definition: gwindow.cpp:1346
static string getDefaultInteractorTextColor()
Returns the default color for text on interactors as a string.
Definition: gwindow.cpp:681
This struct contains real-valued width and height fields.
Definition: gtypes.h:43
virtual GDimension getCanvasSize() const
Returns the width and height of the window&#39;s central canvas area in pixels.
Definition: gwindow.cpp:652
virtual void setWindowTitle(string title)
Sets the window&#39;s title bar text to the given string.
Definition: gwindow.cpp:1278
virtual double getX() const
Returns the x location of the left edge of the interior of the window on screen, excluding any onscre...
Definition: gwindow.cpp:805
virtual QAction * addToolbarSeparator()
Adds a separator to the window&#39;s toolbar.
Definition: gwindow.cpp:518
static GDimension getScreenSize()
Returns the width and height of the entire screen in pixels.
Definition: gwindow.cpp:773
Definition: gwindow.h:121
virtual void clearToolbarItems()
Removes all items from the window&#39;s toolbar, if present.
Definition: gwindow.cpp:574
void setBackground(int color) override
Sets the current background color of the interactor as an RGB integer.
Definition: gwindow.cpp:1028
virtual void setTimerListener(double ms, GEventListener func)
Sets a menu listener on this window so that it will be called when timer delays elapse, sending a timer event.
Definition: gwindow.cpp:1217
virtual void clearCanvas()
Removes all graphical objects from the graphical canvas in this window and resets the background laye...
Definition: gwindow.cpp:548
virtual void restore()
Puts the window in a normal state, neither minimized or maximized.
Definition: gwindow.cpp:1017
virtual double getRegionWidth(Region region) const
Returns the width of the given region of the window in pixels.
Definition: gwindow.cpp:752
virtual void removeWindowListener()
Removes the window listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:1000
Definition: gwindow.h:111
virtual void setY(double y)
Sets the window&#39;s top y location on the screen to the given coordinate.
Definition: gwindow.cpp:1286
virtual QAction * addMenuItemCheckBox(string menu, string item, bool checked=false, string icon="")
Adds a new checkbox menu item to the given menu.
Definition: gwindow.cpp:299
virtual void setExitOnClose(bool exitOnClose)
Sets whether the library&#39;s GUI system should shut down when the window is closed. ...
Definition: gwindow.cpp:1072
virtual bool hasToolbar() const
Returns true if this window has a toolbar.
Definition: gwindow.cpp:813
virtual void setCanvasWidth(double width)
Resizes the window so that its central canvas region will occupy exactly the given width in pixels...
Definition: gwindow.cpp:1060
virtual void setX(double x)
Sets the window&#39;s left x location on the screen to the given coordinate.
Definition: gwindow.cpp:1282
virtual void sleep(double ms)
Causes the current thread to pause itself for the given number of milliseconds.
Definition: gwindow.cpp:1294
virtual double getCanvasHeight() const
Returns the height of the window&#39;s central canvas area in pixels.
Definition: gwindow.cpp:647
Definition: gcontainer.h:102
This struct contains real-valued x and y fields.
Definition: gtypes.h:202
virtual bool inBounds(double x, double y) const
Returns true if the given x/y location is within the bounds of the entire window. ...
Definition: gwindow.cpp:821
virtual void toBack()
Moves the window to the back of the z-ordering in the operating system, underneath any other windows ...
Definition: gwindow.cpp:1314
virtual bool isMaximized() const
Returns true if the window is in a maximized state, occupying the entire screen.
Definition: gwindow.cpp:856
virtual bool inCanvasBounds(double x, double y) const
Returns true if the given x/y location is within the bounds of the central canvas area of the window...
Definition: gwindow.cpp:825
virtual void pack()
Resizes the window to its preferred size.
Definition: gwindow.cpp:898
virtual void setKeyListener(GEventListener func)
Sets a key listener on this window so that it will be called when the user presses any key...
Definition: gwindow.cpp:1118
virtual double getCanvasWidth() const
Returns the width of the window&#39;s central canvas area in pixels.
Definition: gwindow.cpp:657
virtual GObject * getGObject(int index) const
Returns the graphical object at the given 0-based index in the window&#39;s graphical canvas...
Definition: gwindow.cpp:696
virtual void removeClickListener()
Removes the click listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:937
CloseOperation
The various actions that can occur when a window closes.
Definition: gwindow.h:118
virtual void setRegionAlignment(Region region, HorizontalAlignment halign)
Sets the horizontal alignment of interactors in the given region of the window.
Definition: gwindow.cpp:1142
virtual void center()
Relocates the window to the exact center of the current screen.
Definition: gwindow.cpp:583
virtual void setTitle(string title)
Sets the window&#39;s title bar text to the given string.
Definition: gwindow.cpp:1233
void clear() override
Removes all interactors from all regionss of the window.
Definition: gwindow.cpp:530
virtual double getWidth() const
Returns the total width of the window in pixels, excluding its title bar and borders.
Definition: gwindow.cpp:801
double getScreenWidth()
Returns the width of the entire display screen.
Definition: gwindow.cpp:1350
virtual void toFront()
Moves the window to the front of the z-ordering in the operating system, in front of any other window...
Definition: gwindow.cpp:1320
string convertRGBToColor(int rgb)
Converts an rgb value into a color name in the form "#rrggbb".
Definition: gwindow.cpp:1334
virtual void removeMouseListener()
Removes the mouse listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:980
virtual void pause(double ms)
Causes the current thread to pause itself for the given number of milliseconds.
Definition: gwindow.cpp:902
VerticalAlignment
The supported kinds of vertical alignment of a widget or onscreen object.
Definition: gtypes.h:147
virtual QMenu * addSubMenu(string menu, string submenu)
Adds a sub-menu within an existing menu.
Definition: gwindow.cpp:358
static const int DEFAULT_WIDTH
The default width of a newly created window in pixels if its width is not explicitly specified...
Definition: gwindow.h:129