34 #include <QCloseEvent> 37 #include <QMainWindow> 41 #include "gcontainer.h" 42 #include "gdrawingsurface.h" 43 #include "geventqueue.h" 44 #include "ginteractor.h" 47 class _Internal_QMainWindow;
159 GWindow(
double width,
double height,
bool visible =
true);
164 GWindow(
double x,
double y,
double width,
double height,
bool visible =
true);
212 virtual void add(
GObject* obj,
double x,
double y);
225 virtual void add(
GObject& obj,
double x,
double y);
231 virtual QMenu*
addMenu(
const string& text);
241 virtual QAction*
addMenuItem(
const string& menu,
const string& item,
242 const string& icon =
"");
252 virtual QAction*
addMenuItem(
const string& menu,
const string& item,
253 const string& icon, GEventListenerVoid func);
263 virtual QAction*
addMenuItem(
const string& menu,
const string& item,
264 const QIcon& icon, GEventListenerVoid func);
274 virtual QAction*
addMenuItem(
const string& menu,
const string& item,
275 const QPixmap& icon, GEventListenerVoid func);
286 bool checked =
false,
287 const string& icon =
"");
299 const string& icon, GEventListenerVoid func);
314 virtual QMenu*
addSubMenu(
const string& menu,
const string& submenu);
341 virtual void addToolbar(
const string& title =
"");
350 const string& icon =
"");
360 GEventListenerVoid func);
370 GEventListenerVoid func);
380 GEventListenerVoid func);
391 void clear()
override;
446 const string& darkColor);
460 virtual void close();
471 virtual void compareToImage(
const string& filename,
bool ignoreWindowSize =
true)
const;
478 bool eventsEnabled()
const override;
564 static QMainWindow* getLastWindow();
655 string
getType()
const override;
662 virtual QWidget* getWidget()
const;
674 virtual double getX()
const;
680 virtual double getY()
const;
701 virtual bool inBounds(
double x,
double y)
const;
745 virtual bool isOpen()
const;
792 virtual void pause(
double ms);
800 virtual void rememberPosition();
822 virtual void remove(
GObject* obj);
828 virtual void remove(
GObject& obj);
1011 virtual void setMenuItemEnabled(
const string& menu,
const string& item,
bool enabled);
1069 virtual void setRegionAlignment(
const string& region,
const string& halign,
const string& valign);
1108 virtual void setSize(
double width,
double height);
1139 virtual void setTitle(
const string& title);
1151 virtual void setWidth(
double width);
1181 virtual void setX(
double x);
1186 virtual void setY(
double y);
1192 virtual void show();
1199 virtual void sleep(
double ms);
1217 virtual void processKeyPressEventInternal(QKeyEvent* event);
1222 static _Internal_QMainWindow* _lastWindow;
1224 void ensureForwardTarget()
override;
1225 void _init(
double width,
double height,
bool visible);
1226 static Region stringToRegion(
const string& regionStr);
1228 _Internal_QMainWindow* _iqmainwindow;
1233 std::map<string, QMenu*> _menuMap;
1234 std::map<string, QAction*> _menuActionMap;
1238 friend class _Internal_QMainWindow;
1249 int convertColorToRGB(
const string& colorName);
1258 string convertRGBToColor(
int rgb);
1264 void exitGraphics();
1269 double getScreenHeight();
1279 double getScreenWidth();
1285 void pause(
double milliseconds);
1298 class _Internal_QMainWindow :
public QMainWindow {
1302 _Internal_QMainWindow(
GWindow* gwindow, QWidget* parent =
nullptr);
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);
1314 void handleMenuAction(
const string& menu,
const string& item);
1318 std::set<int> _timerIDs;
1320 void processTimerEvent();
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's canvas to the window'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'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'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'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's toolbar, if present.
Definition: gwindow.cpp:570
static double getScreenDpiScaleRatio()
Returns the ratio of this screen's DPI compared to a normal low-DPI screen.
Definition: gwindow.cpp:760
virtual void setSize(double width, double height)
Sets the window's total width and height in pixels.
Definition: gwindow.cpp:1196
virtual GCanvas * getCanvas() const
Returns a direct pointer to the window'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'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'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'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'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's total width in pixels.
Definition: gwindow.cpp:1241
static bool isDarkMode()
Returns true if the user'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'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'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'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'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'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'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'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'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'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'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'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'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'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'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'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