SGL
gwindow.h
1 /*
2  * File: gwindow.h
3  * ---------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/03
7  * - removed dependency on custom collections
8  * @version 2019/05/05
9  * - added static method for isDarkMode checking support
10  * - added static methods to ask for system default widget bg/fg color
11  * @version 2019/04/09
12  * - added toolbar support
13  * @version 2018/10/20
14  * - added high-density screen features
15  * @version 2018/09/09
16  * - added doc comments for new documentation generation
17  * @version 2018/09/05
18  * - refactored to use a border layout GContainer "content pane" for storing all interactors
19  * @version 2018/08/23
20  * - renamed to gwindow.h to replace Java version
21  * @version 2018/07/29
22  * - menu bars
23  * @version 2018/06/25
24  * - initial version
25  */
26 
27 
28 #ifndef _gwindow_h
29 #define _gwindow_h
30 
31 #include <map>
32 #include <set>
33 #include <string>
34 #include <QCloseEvent>
35 #include <QEvent>
36 #include <QLayout>
37 #include <QMainWindow>
38 #include <QRect>
39 
40 #include "gcanvas.h"
41 #include "gcontainer.h"
42 #include "gdrawingsurface.h"
43 #include "geventqueue.h"
44 #include "ginteractor.h"
45 #include "gtypes.h"
46 
47 class _Internal_QMainWindow;
48 
98 class GWindow : public GObservable, public virtual GForwardDrawingSurface {
99 public:
103  enum Region {
109  };
110 
119  };
120 
125  static const int DEFAULT_WIDTH;
126 
131  static const int DEFAULT_HEIGHT;
132 
137  static const int HIGH_DPI_SCREEN_THRESHOLD;
138 
143  static const int STANDARD_SCREEN_DPI;
144 
149  static const string DEFAULT_ICON_FILENAME;
150 
154  GWindow(bool visible = true);
155 
159  GWindow(double width, double height, bool visible = true);
160 
164  GWindow(double x, double y, double width, double height, bool visible = true);
165 
169  ~GWindow() override;
170 
176  virtual void add(GInteractor* interactor);
177 
184  virtual void add(GInteractor* interactor, double x, double y);
185 
190  virtual void add(GInteractor& interactor);
191 
197  virtual void add(GInteractor& interactor, double x, double y);
198 
204  virtual void add(GObject* obj);
205 
212  virtual void add(GObject* obj, double x, double y);
213 
218  virtual void add(GObject& obj);
219 
225  virtual void add(GObject& obj, double x, double y);
226 
231  virtual QMenu* addMenu(const string& text);
232 
241  virtual QAction* addMenuItem(const string& menu, const string& item,
242  const string& icon = "");
243 
252  virtual QAction* addMenuItem(const string& menu, const string& item,
253  const string& icon, GEventListenerVoid func);
254 
263  virtual QAction* addMenuItem(const string& menu, const string& item,
264  const QIcon& icon, GEventListenerVoid func);
265 
274  virtual QAction* addMenuItem(const string& menu, const string& item,
275  const QPixmap& icon, GEventListenerVoid func);
276 
285  virtual QAction* addMenuItemCheckBox(const string& menu, const string& item,
286  bool checked = false,
287  const string& icon = "");
288 
297  virtual QAction* addMenuItemCheckBox(const string& menu, const string& item,
298  bool checked,
299  const string& icon, GEventListenerVoid func);
300 
305  virtual QAction* addMenuSeparator(const string& menu);
306 
314  virtual QMenu* addSubMenu(const string& menu, const string& submenu);
315 
320  virtual void addToRegion(GInteractor* interactor, Region region);
321 
326  virtual void addToRegion(GInteractor* interactor, const string& region = "Center");
327 
331  virtual void addToRegion(GInteractor& interactor, Region region);
332 
336  virtual void addToRegion(GInteractor& interactor, const string& region = "Center");
337 
341  virtual void addToolbar(const string& title = "");
342 
349  virtual QAction* addToolbarItem(const string& item,
350  const string& icon = "");
351 
358  virtual QAction* addToolbarItem(const string& item,
359  const string& icon,
360  GEventListenerVoid func);
361 
368  virtual QAction* addToolbarItem(const string& item,
369  const QIcon& icon,
370  GEventListenerVoid func);
371 
378  virtual QAction* addToolbarItem(const string& item,
379  const QPixmap& icon,
380  GEventListenerVoid func);
381 
386  virtual QAction* addToolbarSeparator();
387 
391  void clear() override;
392 
397  virtual void clearCanvas();
398 
407  virtual void clearCanvasObjects();
408 
418  virtual void clearCanvasPixels();
419 
423  virtual void clearRegion(Region region);
424 
428  virtual void clearRegion(const string& region);
429 
433  virtual void clearToolbarItems();
434 
438  virtual void center();
439 
445  static string chooseLightDarkModeColor(const string& lightColor,
446  const string& darkColor);
447 
453  static int chooseLightDarkModeColorInt(int lightColor, int darkColor);
454 
460  virtual void close();
461 
471  virtual void compareToImage(const string& filename, bool ignoreWindowSize = true) const;
472 
478  bool eventsEnabled() const override;
479 
485  virtual GCanvas* getCanvas() const;
486 
490  virtual double getCanvasHeight() const;
491 
495  virtual GDimension getCanvasSize() const;
496 
500  virtual double getCanvasWidth() const;
501 
506  virtual CloseOperation getCloseOperation() const;
507 
514  static string getDefaultInteractorBackgroundColor();
515 
523 
530  static string getDefaultInteractorTextColor();
531 
539 
545  virtual GObject* getGObject(int index) const;
546 
552  virtual GObject* getGObjectAt(double x, double y) const;
553 
557  virtual int getGObjectCount() const;
558 
564  static QMainWindow* getLastWindow();
565 
570  virtual GPoint getLocation() const;
571 
576  virtual double getHeight() const;
577 
584  virtual GDimension getPreferredSize() const;
585 
589  virtual double getRegionHeight(Region region) const;
590 
594  virtual double getRegionHeight(const string& region) const;
595 
599  virtual GDimension getRegionSize(Region region) const;
600 
604  virtual GDimension getRegionSize(const string& region) const;
605 
609  virtual double getRegionWidth(Region region) const;
610 
614  virtual double getRegionWidth(const string& region) const;
615 
620  static int getScreenDpi();
621 
626  static double getScreenDpiScaleRatio();
627 
631  static double getScreenHeight();
632 
636  static GDimension getScreenSize();
637 
641  static double getScreenWidth();
642 
647  virtual GDimension getSize() const;
648 
652  virtual string getTitle() const;
653 
654  /* @inherit */
655  string getType() const override;
656 
662  virtual QWidget* getWidget() const;
663 
668  virtual double getWidth() const;
669 
674  virtual double getX() const;
675 
680  virtual double getY() const;
681 
685  virtual bool hasToolbar() const;
686 
691  virtual void hide();
692 
701  virtual bool inBounds(double x, double y) const;
702 
707  virtual bool inCanvasBounds(double x, double y) const;
708 
715  static bool isDarkMode();
716 
722  static bool isHighDensityScreen();
723 
728  static bool isHighDpiScalingEnabled();
729 
734  virtual bool isMaximized() const;
735 
740  virtual bool isMinimized() const;
741 
745  virtual bool isOpen() const;
746 
747  /* @inherit */
748  bool isRepaintImmediately() const override;
749 
754  virtual bool isResizable() const;
755 
759  virtual bool isVisible() const;
760 
766  virtual void loadCanvasPixels(const string& filename);
767 
771  virtual void maximize();
772 
777  virtual void minimize();
778 
785  virtual void pack();
786 
792  virtual void pause(double ms);
793 
800  virtual void rememberPosition();
801 
808  virtual void remove(GInteractor* interactor);
809 
815  virtual void remove(GInteractor& interactor);
816 
822  virtual void remove(GObject* obj);
823 
828  virtual void remove(GObject& obj);
829 
834  virtual void removeClickListener();
835 
841  virtual void removeFromRegion(GInteractor* interactor, Region region);
842 
848  virtual void removeFromRegion(GInteractor* interactor, const string& region);
849 
854  virtual void removeFromRegion(GInteractor& interactor, Region region);
855 
860  virtual void removeFromRegion(GInteractor& interactor, const string& region);
861 
866  virtual void removeKeyListener();
867 
872  virtual void removeMenuListener();
873 
878  virtual void removeMouseListener();
879 
884  virtual void removeTimerListener();
885 
889  virtual void removeToolbar();
890 
895  virtual void removeWindowListener();
896 
902  virtual void requestFocus();
903 
907  virtual void restore();
908 
915  virtual void saveCanvasPixels(const string& filename);
916 
917  /* @inherit */
918  void setBackground(int color) override;
919 
920  /* @inherit */
921  void setBackground(const string& color) override;
922 
927  virtual void setCanvasHeight(double height);
928 
933  virtual void setCanvasSize(double width, double height);
934 
939  virtual void setCanvasSize(const GDimension& size);
940 
945  virtual void setCanvasWidth(double width);
946 
955  virtual void setClickListener(GEventListener func);
956 
965  virtual void setClickListener(GEventListenerVoid func);
966 
970  virtual void setCloseOperation(CloseOperation op);
971 
976  virtual void setExitOnClose(bool exitOnClose);
977 
981  virtual void setHeight(double width);
982 
988  virtual void setKeyListener(GEventListener func);
989 
995  virtual void setKeyListener(GEventListenerVoid func);
996 
1000  virtual void setLocation(double x, double y);
1001 
1005  virtual void setLocation(const GPoint& p);
1006 
1011  virtual void setMenuItemEnabled(const string& menu, const string& item, bool enabled);
1012 
1018  virtual void setMenuListener(GEventListener func);
1019 
1025  virtual void setMenuListener(GEventListenerVoid func);
1026 
1032  virtual void setMouseListener(GEventListener func);
1033 
1039  virtual void setMouseListener(GEventListenerVoid func);
1040 
1045  virtual void setRegionAlignment(Region region, HorizontalAlignment halign);
1046 
1051  virtual void setRegionAlignment(Region region, VerticalAlignment valign);
1052 
1057  virtual void setRegionAlignment(Region region, HorizontalAlignment halign, VerticalAlignment valign);
1058 
1063  virtual void setRegionAlignment(const string& region, const string& align);
1064 
1069  virtual void setRegionAlignment(const string& region, const string& halign, const string& valign);
1070 
1075  virtual void setRegionHorizontalAlignment(Region region, HorizontalAlignment halign);
1076 
1081  virtual void setRegionHorizontalAlignment(const string& region, const string& halign);
1082 
1087  virtual void setRegionVerticalAlignment(const string& region, const string& valign);
1088 
1093  virtual void setRegionVerticalAlignment(Region region, VerticalAlignment valign);
1094 
1099  virtual void setResizable(bool resizable);
1100 
1108  virtual void setSize(double width, double height);
1109 
1117  virtual void setSize(const GDimension& size);
1118 
1124  virtual void setTimerListener(double ms, GEventListener func);
1125 
1131  virtual void setTimerListener(double ms, GEventListenerVoid func);
1132 
1133  // TODO: setTimerListenerOnce?
1134 
1139  virtual void setTitle(const string& title);
1140 
1146  virtual void setVisible(bool visible);
1147 
1151  virtual void setWidth(double width);
1152 
1156  virtual void setWindowIcon(const string& iconFile);
1157 
1163  virtual void setWindowListener(GEventListener func);
1164 
1170  virtual void setWindowListener(GEventListenerVoid func);
1171 
1176  virtual void setWindowTitle(const string& title);
1177 
1181  virtual void setX(double x);
1182 
1186  virtual void setY(double y);
1187 
1192  virtual void show();
1193 
1199  virtual void sleep(double ms);
1200 
1205  virtual void toBack();
1206 
1211  virtual void toFront();
1212 
1213 protected:
1217  virtual void processKeyPressEventInternal(QKeyEvent* event);
1218 
1219 private:
1220  Q_DISABLE_COPY(GWindow)
1221 
1222  static _Internal_QMainWindow* _lastWindow;
1223 
1224  void ensureForwardTarget() override;
1225  void _init(double width, double height, bool visible);
1226  static Region stringToRegion(const string& regionStr);
1227 
1228  _Internal_QMainWindow* _iqmainwindow;
1229  GContainer* _contentPane;
1230  GCanvas* _canvas;
1231  bool _resizable;
1232  CloseOperation _closeOperation;
1233  std::map<string, QMenu*> _menuMap;
1234  std::map<string, QAction*> _menuActionMap;
1235  QToolBar* _toolbar;
1236 
1237  friend class GInteractor;
1238  friend class _Internal_QMainWindow;
1239 };
1240 
1241 
1242 // global functions for compatibility
1243 
1249 int convertColorToRGB(const string& colorName);
1250 
1258 string convertRGBToColor(int rgb);
1259 
1264 void exitGraphics();
1265 
1269 double getScreenHeight();
1270 
1274 GDimension getScreenSize();
1275 
1279 double getScreenWidth();
1280 
1285 void pause(double milliseconds);
1286 
1291 void repaint();
1292 
1293 
1298 class _Internal_QMainWindow : public QMainWindow {
1299  Q_OBJECT
1300 
1301 public:
1302  _Internal_QMainWindow(GWindow* gwindow, QWidget* parent = nullptr);
1303 
1304  void changeEvent(QEvent* event) override;
1305  void closeEvent(QCloseEvent* event) override;
1306  void keyPressEvent(QKeyEvent* event) override;
1307  void resizeEvent(QResizeEvent* event) override;
1308  void timerEvent(QTimerEvent* event) override;
1309  virtual bool timerExists(int id = -1);
1310  virtual int timerStart(double ms);
1311  virtual void timerStop(int id = -1);
1312 
1313 public slots:
1314  void handleMenuAction(const string& menu, const string& item);
1315 
1316 private:
1317  GWindow* _gwindow;
1318  std::set<int> _timerIDs;
1319 
1320  void processTimerEvent();
1321 
1322  friend class GWindow;
1323 };
1324 
1325 #endif // _gwindow_h
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:821
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:556
static double getScreenHeight()
Returns the height of the entire screen in pixels.
Definition: gwindow.cpp:765
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:295
virtual void setX(double x)
Sets the window&#39;s left x location on the screen to the given coordinate.
Definition: gwindow.cpp:1278
This struct contains real-valued width and height fields.
Definition: gtypes.h:39
virtual void setY(double y)
Sets the window&#39;s top y location on the screen to the given coordinate.
Definition: gwindow.cpp:1282
virtual void center()
Relocates the window to the exact center of the current screen.
Definition: gwindow.cpp:579
virtual void setResizable(bool resizable)
Sets whether the window allows itself to be resized.
Definition: gwindow.cpp:1174
void clear() override
Removes all interactors from all regionss of the window.
Definition: gwindow.cpp:526
virtual void setExitOnClose(bool exitOnClose)
Sets whether the library&#39;s GUI system should shut down when the window is closed. ...
Definition: gwindow.cpp:1068
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:724
virtual double getRegionWidth(Region region) const
Returns the width of the given region of the window in pixels.
Definition: gwindow.cpp:748
A GCanvas is a graphical drawing surface on which you can draw shapes, lines, and colors...
Definition: gcanvas.h:70
virtual double getHeight() const
Returns the total height of the window in pixels, excluding its title bar and borders.
Definition: gwindow.cpp:720
virtual void removeFromRegion(GInteractor *interactor, Region region)
Removes the given interactor from the given region within this window.
Definition: gwindow.cpp:939
virtual void clearToolbarItems()
Removes all items from the window&#39;s toolbar, if present.
Definition: gwindow.cpp:570
static double getScreenDpiScaleRatio()
Returns the ratio of this screen&#39;s DPI compared to a normal low-DPI screen.
Definition: gwindow.cpp:760
virtual void setSize(double width, double height)
Sets the window&#39;s total width and height in pixels.
Definition: gwindow.cpp:1196
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:638
virtual void removeMouseListener()
Removes the mouse listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:976
static const string DEFAULT_ICON_FILENAME
The default file name used to load a GWindow&#39;s initial title bar icon.
Definition: gwindow.h:149
virtual QMenu * addSubMenu(string menu, string submenu)
Adds a sub-menu within an existing menu.
Definition: gwindow.cpp:354
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:801
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:877
bool isRepaintImmediately() const override
Returns true if the interactor should repaint itself automatically whenever any change is made to its...
Definition: gwindow.cpp:865
virtual void setRegionVerticalAlignment(string region, string valign)
Sets the vertical alignment of interactors in the given region of the window.
Definition: gwindow.cpp:1170
virtual double getWidth() const
Returns the total width of the window in pixels, excluding its title bar and borders.
Definition: gwindow.cpp:797
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:1080
virtual double getCanvasWidth() const
Returns the width of the window&#39;s central canvas area in pixels.
Definition: gwindow.cpp:653
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:125
virtual void setWidth(double width)
Sets the window&#39;s total width in pixels.
Definition: gwindow.cpp:1241
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:825
virtual double getRegionHeight(Region region) const
Returns the height of the given region of the window in pixels.
Definition: gwindow.cpp:732
A GObservable object is one that is able to send out events.
Definition: gobservable.h:36
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:591
GWindow(bool visible=true)
Creates a new window of a default width and height.
Definition: gwindow.cpp:74
CloseOperation
The various actions that can occur when a window closes.
Definition: gwindow.h:114
virtual void setCloseOperation(CloseOperation op)
Sets what should happen when the window is closed.
Definition: gwindow.cpp:1061
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:805
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:1039
virtual QAction * addMenuSeparator(string menu)
Adds a horizontal line separator to the end of the given menu.
Definition: gwindow.cpp:339
virtual void setRegionAlignment(Region region, HorizontalAlignment halign)
Sets the horizontal alignment of interactors in the given region of the window.
Definition: gwindow.cpp:1138
Definition: gwindow.h:108
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:1044
Definition: gcontainer.h:97
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:1316
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:1254
Definition: gwindow.h:118
~GWindow() override
Frees memory allocated internally by the window.
Definition: gwindow.cpp:129
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:131
string getType() const override
Returns the concrete type of the object as a string, such as "GButton" or "GWindow".
Definition: gwindow.cpp:789
virtual bool isVisible() const
Returns true if the window is visible on the screen.
Definition: gwindow.cpp:873
Definition: gcontainer.h:101
static string getDefaultInteractorBackgroundColor()
Returns the default color for backgrounds of interactors as a string.
Definition: gwindow.cpp:662
static const int STANDARD_SCREEN_DPI
The minimum number of dots per inch on a "normal" low-DPI screen.
Definition: gwindow.h:143
virtual void clearCanvasObjects()
Removes all graphical objects from the graphical canvas in this window.
Definition: gwindow.cpp:550
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:840
Definition: gwindow.h:115
virtual void setWindowIcon(string iconFile)
Sets the window to use the.
Definition: gwindow.cpp:1245
Definition: gwindow.h:116
virtual void removeKeyListener()
Removes the key listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:966
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:1006
Definition: gwindow.h:104
static int getDefaultInteractorTextColorInt()
Returns the default color for text on interactors as an RGB integer.
Definition: gwindow.cpp:681
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:48
virtual CloseOperation getCloseOperation() const
Returns a constant representing the action that will be taken when the user closes the window...
Definition: gwindow.cpp:658
virtual GDimension getRegionSize(Region region) const
Returns the width and height of the given region of the window in pixels.
Definition: gwindow.cpp:740
virtual void setWindowTitle(string title)
Sets the window&#39;s title bar text to the given string.
Definition: gwindow.cpp:1274
Definition: gwindow.h:117
virtual void maximize()
Puts the window in a maximized state, occupying the entire screen.
Definition: gwindow.cpp:882
static string getDefaultInteractorTextColor()
Returns the default color for text on interactors as a string.
Definition: gwindow.cpp:677
static int getScreenDpi()
Returns the dots-per-inch of the screen.
Definition: gwindow.cpp:756
virtual void removeTimerListener()
Removes the timer listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:982
virtual QAction * addToolbarItem(string item, string icon="")
Adds a new item to the window&#39;s toolbar.
Definition: gwindow.cpp:411
virtual void hide()
Makes the window be not visible on the screen.
Definition: gwindow.cpp:813
virtual void removeToolbar()
Removes the toolbar from this window, if one was present.
Definition: gwindow.cpp:986
Definition: gcontainer.h:98
virtual double getCanvasHeight() const
Returns the height of the window&#39;s central canvas area in pixels.
Definition: gwindow.cpp:643
virtual void minimize()
Puts the window in a minimized (iconified) state, which often displays as the window being hidden exc...
Definition: gwindow.cpp:888
virtual GDimension getCanvasSize() const
Returns the width and height of the window&#39;s central canvas area in pixels.
Definition: gwindow.cpp:648
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:1106
Definition: gwindow.h:107
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:586
This class is the common superclass of all graphical objects that can be displayed on a graphical win...
Definition: gobjects.h:62
virtual bool isResizable() const
Returns true if the window allows itself to be resized.
Definition: gwindow.cpp:869
virtual void setTitle(string title)
Sets the window&#39;s title bar text to the given string.
Definition: gwindow.cpp:1229
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:692
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:1056
Definition: gcontainer.h:100
virtual void setHeight(double width)
Sets the window&#39;s total height in pixels.
Definition: gwindow.cpp:1076
virtual bool isMaximized() const
Returns true if the window is in a maximized state, occupying the entire screen.
Definition: gwindow.cpp:852
void setBackground(int color) override
Sets the current background color of the interactor as an RGB integer.
Definition: gwindow.cpp:1024
virtual void setVisible(bool visible)
Sets whether the window can be seen on the screen.
Definition: gwindow.cpp:1235
virtual void pause(double ms)
Causes the current thread to pause itself for the given number of milliseconds.
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:1114
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:817
virtual void addToRegion(GInteractor *interactor, Region region)
Adds the given interactor to the given region in this window.
Definition: gwindow.cpp:372
virtual void clearRegion(Region region)
Removes all interactors from the given region of this window.
Definition: gwindow.cpp:562
virtual string getTitle() const
Returns the title bar text for the window.
Definition: gwindow.cpp:785
Definition: gwindow.h:106
virtual GDimension getPreferredSize() const
Returns the size that the window would prefer to be.
Definition: gwindow.cpp:728
virtual QAction * addToolbarSeparator()
Adds a separator to the window&#39;s toolbar.
Definition: gwindow.cpp:514
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:1122
This class represents a graphics window that supports simple graphics.
Definition: gwindow.h:98
virtual void toBack()
Moves the window to the back of the z-ordering in the operating system, underneath any other windows ...
Definition: gwindow.cpp:1310
virtual void addToolbar(string title="")
Adds a toolbar to this window where action buttons can be placed.
Definition: gwindow.cpp:399
Region
The five regions of window border layouts.
Definition: gwindow.h:103
static double getScreenWidth()
Returns the width of the entire screen in pixels.
Definition: gwindow.cpp:777
virtual void clearCanvas()
Removes all graphical objects from the graphical canvas in this window and resets the background laye...
Definition: gwindow.cpp:544
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:700
virtual bool isOpen() const
Returns true if the window is currently open and visible on the screen.
Definition: gwindow.cpp:861
Definition: gwindow.h:105
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:1130
virtual GDimension getSize() const
Returns the total width and height of the window in pixels, excluding its title bar and borders...
Definition: gwindow.cpp:781
virtual void saveCanvasPixels(string filename)
Writes the contents of the window&#39;s graphical canvas to the given output filename.
Definition: gwindow.cpp:1019
virtual void close()
Closes the window.
Definition: gwindow.cpp:595
virtual QAction * addMenuItem(string menu, string item, string icon="")
Adds a new menu item to the given menu.
Definition: gwindow.cpp:198
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:857
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:137
static int getDefaultInteractorBackgroundColorInt()
Returns the default color for text on interactors as an RGB integer.
Definition: gwindow.cpp:666
virtual bool hasToolbar() const
Returns true if this window has a toolbar.
Definition: gwindow.cpp:809
virtual void restore()
Puts the window in a normal state, neither minimized or maximized.
Definition: gwindow.cpp:1013
virtual int getGObjectCount() const
Returns the total number of graphical objects in the window&#39;s canvas.
Definition: gwindow.cpp:708
static bool isHighDpiScalingEnabled()
Returns whether we should scale some windows when run on high-density screens.
Definition: gwindow.cpp:844
Definition: gcontainer.h:99
virtual void removeClickListener()
Removes the click listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:933
virtual void show()
Sets the window to be visible on the screen.
Definition: gwindow.cpp:1286
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:1213
virtual QMenu * addMenu(string text)
Adds a menu with the given text to the window&#39;s top menu bar.
Definition: gwindow.cpp:182
virtual void removeWindowListener()
Removes the window listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:996
virtual void sleep(double ms)
Causes the current thread to pause itself for the given number of milliseconds.
Definition: gwindow.cpp:1290
virtual void add(GInteractor *interactor)
Adds the given interactor to the center region of the window.
Definition: gwindow.cpp:140
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:1090
This struct contains real-valued x and y fields.
Definition: gtypes.h:198
A GContainer is a logical grouping for interactors.
Definition: gcontainer.h:69
virtual void removeMenuListener()
Removes the menu listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:972
static GDimension getScreenSize()
Returns the width and height of the entire screen in pixels.
Definition: gwindow.cpp:769
virtual void pack()
Resizes the window to its preferred size.
Definition: gwindow.cpp:894
virtual void setRegionHorizontalAlignment(Region region, HorizontalAlignment halign)
Sets the horizontal alignment of interactors in the given region of the window.
Definition: gwindow.cpp:1158