StanfordCPPLib
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
GCanvas Class Reference

A GCanvas is a graphical drawing surface on which you can draw shapes, lines, and colors, as well as setting the RGB color values of individual pixels. More...

#include "gcanvas.h"

Inheritance diagram for GCanvas:
GInteractor GDrawingSurface GObservable

Public Types

enum  TextPosition { TEXT_BESIDE_ICON, TEXT_UNDER_ICON, TEXT_ONLY }
 The places where an interactor can place its text relative to its icon. More...
 

Public Member Functions

 GCanvas(QWidget* parent=nullptr)
 Creates an empty canvas with a default size of 0x0 pixels and a default background and foreground color of black. More...
 
 GCanvas(string filename, QWidget* parent=nullptr)
 Creates a canvas that loads its background layer pixel data from the given image file name. More...
 
 GCanvas(std::istream &filename, QWidget* parent=nullptr)
 Creates a canvas that loads its background layer pixel data from the given input stream. More...
 
 GCanvas(double width, double height, int rgbBackground, QWidget* parent=nullptr)
 Creates an empty canvas of the specified size and optional background color. More...
 
 GCanvas(double width, double height, string rgbBackground="#00000000", QWidget* parent=nullptr)
 Creates an empty canvas of the specified size and background color. More...
 
~GCanvas()
 Frees memory allocated internally by the canvas. More...
 
void add(GObject *gobj)
 Adds the given interactor to canvas. More...
 
void add(GObject *gobj, double x, double y)
 Adds the given interactor to the canvas and moves it to the given x/y location. More...
 
void add(GObject &gobj)
 Adds the given interactor to canvas. More...
 
void add(GObject &gobj, double x, double y)
 Adds the given interactor to the canvas and moves it to the given x/y location. More...
 
void addActionListener() (deprecated)
 Adds an event listener to be notified when this interactor is clicked or generally interacted with. More...
 
void clear()
 Removes all graphical objects from the canvas foreground layer and wipes the background layer to show the current background color. More...
 
void clearObjects()
 Removes all graphical objects from the foreground layer of the canvas. More...
 
void clearPixels()
 Resets the background layer of pixels in the canvas to the current background color. More...
 
void conditionalRepaint()
 Repaints the interactor only if its contents have changed. More...
 
void conditionalRepaintRegion(int x, int y, int width, int height)
 Repaints the given region of the interactor only if its contents have changed. More...
 
void conditionalRepaintRegion(const GRectangle &bounds)
 Repaints the given region of the interactor only if its contents have changed. More...
 
bool contains(double x, double y) const
 Returns true if any of the graphical objects in the foreground layer of the canvas touch the given x/y pixel. More...
 
int countDiffPixels(const GCanvas &image) const
 Returns the total number of pixels that are not the same color between this image and the given other image. More...
 
int countDiffPixels(const GCanvas &image, int xmin, int ymin, int xmax, int ymax) const
 Returns the total number of pixels that are not the same color between this image and the given other image. More...
 
int countDiffPixels(const GCanvas *image) const
 Returns the total number of pixels that are not the same color between this image and the given other image. More...
 
int countDiffPixels(const GCanvas *image, int xmin, int ymin, int xmax, int ymax) const
 Returns the total number of pixels that are not the same color between this image and the given other image. More...
 
GCanvasdiff(const GCanvas &image, int diffPixelColor=GCANVAS_DEFAULT_DIFF_PIXEL_COLOR) const
 Generates a new canvas whose content is equal to that of this canvas but with any pixels that don't match those in parameter 'image' colored in the given color (default purple) to highlight differences between the two. More...
 
GCanvasdiff(const GCanvas *image, int diffPixelColor=GCANVAS_DEFAULT_DIFF_PIXEL_COLOR) const
 Generates a new canvas whose content is equal to that of this canvas but with any pixels that don't match those in parameter 'image' colored in the given color (default purple) to highlight differences between the two. More...
 
void draw(GObject *gobj, double x, double y)
 Draws the given graphical object onto the background pixel layer of this interactor, moving it to the given x/y location first. More...
 
void draw(GObject &gobj)
 Draws the given graphical object onto the background pixel layer of this interactor. More...
 
void draw(GObject &gobj, double x, double y)
 Draws the given graphical object onto the background pixel layer of this interactor, moving it to the given x/y location first. More...
 
void draw(GObject *gobj)
 Draws the given graphical object onto the background layer of the canvas. More...
 
void drawArc(double x, double y, double width, double height, double start, double sweep)
 Draws an unfilled arc with the given attributes onto the background pixel layer of this interactor in the current color. More...
 
void drawImage(string filename, double x=0, double y=0)
 Draws an image loaded from the given file name onto the background pixel layer of this interactor at the given x/y location. More...
 
void drawLine(const GPoint &p0, const GPoint &p1)
 Draws a line between the given two points onto the background pixel layer of this interactor at the given x/y location in the current color. More...
 
void drawLine(double x0, double y0, double x1, double y1)
 Draws a line between the given two points onto the background pixel layer of this interactor at the given x/y location in the current color. More...
 
void drawOval(const GRectangle &bounds)
 Draws an unfilled oval with the given bounding box onto the background pixel layer of this interactor at the given x/y location in the current color. More...
 
void drawOval(double x, double y, double width, double height)
 Draws an unfilled oval with the given bounding box onto the background pixel layer of this interactor at the given x/y location in the current color. More...
 
void drawPixel(double x, double y)
 Colors the given x/y pixel of the background layer of this interactor using the interactor's current color. More...
 
void drawPixel(double x, double y, int color)
 Colors the given x/y pixel of the background layer of this interactor using the given color. More...
 
void drawPixel(double x, double y, string color)
 Colors the given x/y pixel of the background layer of this interactor using the given color. More...
 
GPoint drawPolarLine(const GPoint &p0, double r, double theta)
 Draws a line using polar coordinates onto the background pixel layer of this interactor in the current color. More...
 
GPoint drawPolarLine(double x0, double y0, double r, double theta)
 Draws a line using polar coordinates onto the background pixel layer of this interactor in the current color. More...
 
void drawPolygon(std::initializer_list< double > coords)
 Draws an unfilled polygon containing the given points onto the background pixel layer of this interactor in the current color. More...
 
void drawPolygon(std::initializer_list< GPoint > points)
 Draws an unfilled polygon containing the given points onto the background pixel layer of this interactor in the current color. More...
 
void drawRect(const GRectangle &bounds)
 Draws an unfilled rectangle of the given dimensions onto the background pixel layer of this interactor in the current color. More...
 
void drawRect(double x, double y, double width, double height)
 Draws an unfilled rectangle of the given dimensions onto the background pixel layer of this interactor in the current color. More...
 
void drawString(string text, double x, double y)
 Draws a text string onto the background pixel layer of this interactor at the given x/y location in the current font and color. More...
 
bool equals(const GCanvas &other) const
 Returns true if the two given canvases contain exactly the same pixel data. More...
 
bool eventsEnabled() const
 Returns true if this interactor is currently accepting events. More...
 
void fill(int rgb)
 Sets the color of every pixel in the canvas to the given color value. More...
 
void fill(string rgb)
 Sets the color of every pixel in the canvas to the given color value. More...
 
void fillArc(double x, double y, double width, double height, double start, double sweep)
 Draws a filled arc with the given attributes onto the background pixel layer of this interactor in the current color and fill color. More...
 
void fillOval(const GRectangle &bounds)
 Draws a filled oval with the given bounding box onto the background pixel layer of this interactor at the given x/y location in the current color and fill color. More...
 
void fillOval(double x, double y, double width, double height)
 Draws a filled oval with the given bounding box onto the background pixel layer of this interactor at the given x/y location in the current color and fill color. More...
 
void fillPolygon(std::initializer_list< double > coords)
 Draws a filled polygon containing the given points onto the background pixel layer of this interactor in the current color and fill color. More...
 
void fillRect(const GRectangle &bounds)
 Draws a filled rectangle of the given dimensions onto the background pixel layer of this interactor in the current color and fill color. More...
 
void fillRect(double x, double y, double width, double height)
 Draws a filled rectangle of the given dimensions onto the background pixel layer of this interactor in the current color and fill color. More...
 
void fillRegion(double x, double y, double width, double height, int rgb)
 Sets the color of every pixel in the given rectangular range of the canvas pixel data to the given color value. More...
 
void fillRegion(double x, double y, double width, double height, string rgb)
 Sets the color of every pixel in the given rectangular range of the canvas pixel data to the given color value. More...
 
void flatten()
 Moves all graphical objects from the foreground layer to the background layer. More...
 
void fromGrid(const Grid< int > &grid)
 Replaces the entire contents of the background layer of the canvas with the contents of the given grid of RGB pixel values. More...
 
string getAccelerator() const
 Returns a string representing a hotkey for this interactor, or an empty string if no accelerator has been set. More...
 
string getActionCommand() const
 Returns an action command for this interactor, which is a semi-unique string you can use to identify it when events occur. More...
 
int getARGB(double x, double y) const
 Returns the pixel color data at the given x/y location, retaining alpha-channel transparency in the top 8 bits. More...
 
string getBackground() const
 Returns the current background color of the interactor as a string. More...
 
int getBackgroundInt() const
 Returns the current background color of the interactor as an RGB integer. More...
 
GRectangle getBounds() const
 Returns a rectangle representing the x/y position and size of this interactor. More...
 
string getColor() const
 Returns the foreground/text color of the interactor as a string. More...
 
string getColor() const
 Returns the current foreground outline color of the interactor as a string. More...
 
int getColorInt() const
 Returns the foreground/text color of the interactor as an RGB integer. More...
 
int getColorInt() const
 Returns the current foreground outline color of the interactor as an RGB integer. More...
 
GContainergetContainer() const
 Returns a pointer to the onscreen container holding this interactor. More...
 
GObjectgetElement(int index) const
 Returns a pointer to the graphical object in the foreground layer of the canvas at the specified index, numbering from back to front in the z dimension. More...
 
GObjectgetElementAt(double x, double y) const
 Returns a pointer to the first graphical object in the foreground layer of the canvas that contains the given (x, y) point, or a null pointer if no object in this canvas touches it. More...
 
int getElementCount() const
 Returns the number of graphical objects stored in the foreground layer of the canvas. More...
 
string getFilename() const
 Returns the name of the image file from which this canvas was loaded or to which it was saved most recently. More...
 
string getFillColor() const
 Returns the current fill color of the interactor as a string. More...
 
int getFillColorInt() const
 Returns the current fill color of the interactor as an RGB integer. More...
 
string getFont() const
 Returns the current text font of the interactor as a font string. More...
 
string getForeground() const
 Returns the foreground/text color of the interactor as a string. More...
 
string getForeground() const
 Returns the current foreground outline color of the interactor as a string. More...
 
int getForegroundInt() const
 Returns the foreground/text color of the interactor as an RGB integer. More...
 
int getForegroundInt() const
 Returns the current foreground outline color of the interactor as an RGB integer. More...
 
double getHeight() const
 Returns the current onscreen height of this interactor in pixels. More...
 
string getIcon() const
 Returns the file name of the icon associated with this interactor, or an empty string if no icon has been set. More...
 
int getID() const
 Returns a globally unique identifier for this interactor, which is set when the interactor is constructed. More...
 
_Internal_QWidget*  getInternalWidget() const
 Returns a direct pointer to the internal Qt widget being wrapped by this interactor. More...
 
GObject::LineStyle getLineStyle() const
 Returns the current line style which will be used to draw outlines of shapes and lines. More...
 
double getLineWidth() const
 Returns the thickness used when drawing outlines of shapes and lines. More...
 
GPoint getLocation() const
 Returns an (x, y) point representing the onscreen location of the top-left corner of this interactor within its containing window. More...
 
double getMinimumHeight() const
 Returns the minimum height in pixels that this interactor will permit itself to be resized to. More...
 
GDimension getMinimumSize() const
 Returns a GDimension structure representing the minimum size in pixels that this interactor will permit itself to be resized to. More...
 
double getMinimumWidth() const
 Returns the minimum width in pixels that this interactor will permit itself to be resized to. More...
 
string getName() const
 Returns a string representing a unique name for this interactor. More...
 
int getPixel(double x, double y) const
 Returns the color of the pixel at the given x/y coordinates of the background layer of the canvas as an integer such as 0xff00cc. More...
 
int getPixelARGB(double x, double y) const
 Returns the color of the pixel at the given x/y coordinates of the background layer of the canvas as an integer such as 0xffff00cc. More...
 
Grid< int > getPixels() const
 Returns all pixels of the background layer of the canvas as a Grid, where rows represent y values and columns represent x values. More...
 
Grid< int > getPixelsARGB() const
 Returns all pixels of the background layer of the canvas as a Grid, where rows represent y values and columns represent x values. More...
 
string getPixelString(double x, double y) const
 Returns the color of the pixel at the given x/y coordinates of the image as a string such as "#ff00cc". More...
 
double getPreferredHeight() const
 Returns the height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars. More...
 
GDimension getPreferredSize() const
 Returns a GDimension structure storing the width and height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars. More...
 
double getPreferredWidth() const
 Returns the height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars. More...
 
int getRGB(double x, double y) const
 Returns the color of the pixel at the given x/y coordinates of the background layer of the interactor as an integer such as 0xff00cc. More...
 
string getRGBString(double x, double y) const
 Returns the color of the pixel at the given x/y coordinates of the background layer of the interactor as a color string such as "#ff00cc". More...
 
GDimension getSize() const
 Returns a GDimension structure storing the current onscreen width and height of this interactor in pixels. More...
 
string getType() const
 Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox". More...
 
QWidget*  getWidget() const
 Returns a direct pointer to the internal Qt widget being wrapped by this interactor. More...
 
double getWidth() const
 Returns the current onscreen width of this interactor in pixels. More...
 
double getX() const
 Returns the x-coordinate of the top-left pixel of this interactor within its onscreen window. More...
 
double getY() const
 Returns the y-coordinate of the top-left pixel of this interactor within its onscreen window. More...
 
bool inBounds(double x, double y) const
 Returns true if the given x/y pixel is within the bounds of this interactor. More...
 
bool inBounds(int x, int y) const
 Returns true if the given x/y pixel is within the bounds of this interactor. More...
 
bool isAutoRepaint() const
 Returns true if the interactor should repaint itself automatically whenever any change is made to its graphical data. More...
 
bool isEnabled() const
 Returns true if this interactor is currently enabled. More...
 
bool isRepaintImmediately() const
 Returns true if the interactor should repaint itself automatically whenever any change is made to its graphical data. More...
 
bool isVisible() const
 Returns true if the interactor is visible on the screen. More...
 
void load(string filename)
 Reads the canvas's pixel contents from the given image file. More...
 
void remove(GObject *gobj)
 Reads the canvas's pixel contents from the given input stream. More...
 
void remove(GObject &gobj)
 Removes the given graphical object from the foreground layer of the canvas, if it was present. More...
 
void removeAll()
 Removes all graphical objects from the foreground layer of the canvas. More...
 
void removeClickListener()
 Removes the click listener from the canvas so that it will no longer call it when events occur. More...
 
void removeDoubleClickListener()
 Removes the double-click listener from the canvas so that it will no longer call it when events occur. More...
 
void removeKeyListener()
 Removes the key listener from the canvas so that it will no longer call it when events occur. More...
 
void removeMouseListener()
 Removes the mouse listener from the canvas so that it will no longer call it when events occur. More...
 
void repaint()
 Instructs the canvas to redraw its layers. More...
 
void repaintRegion(const GRectangle &bounds)
 Instructs the interactor to repaint the given region of pixel data. More...
 
void repaintRegion(int x, int y, int width, int height)
 Instructs the canvas to redraw the given region of pixels within both of its layers. More...
 
void requestFocus()
 Transfers keyboard focus to this interactor. More...
 
void resize(double width, double height, bool retain=true)
 Changes this image's bounds to be the given size. More...
 
void save(string filename)
 Saves the canvas's contents to the given image file. More...
 
void setAccelerator(string accelerator)
 Sets an accelerator hotkey for this interactor, such as "Ctrl-S". More...
 
void setActionCommand(string actionCommand)
 Sets the action command for this interactor. More...
 
void setAutoRepaint(bool autoRepaint)
 Sets whether the canvas will automatically repaint itself whenever you make a change to either the background or foreground layer. More...
 
void setBackground(int color)
 Sets the current background color of the interactor as an RGB integer. More...
 
void setBackground(string color)
 Sets the current background color of the interactor as a string. More...
 
void setBounds(double x, double y, double width, double height)
 Sets the size and location of the widget. More...
 
void setBounds(const GRectangle &size)
 Sets the size and location of the widget. More...
 
void setClickListener(GEventListener func)
 Sets a mouse listener on this canvas so that it will be called when the mouse is clicked on the canvas. More...
 
void setClickListener(GEventListenerVoid func)
 Sets a mouse listener on this canvas so that it will be called when the mouse is clicked on the canvas. More...
 
void setColor(int color)
 Sets the current foreground outline color of the interactor as as RGB integer. More...
 
void setColor(string color)
 Sets the current foreground outline color of the interactor as a string. More...
 
void setDoubleClickListener(GEventListener func)
 Sets a mouse listener on this canvas so that it will be called when the mouse is double-clicked on the canvas. More...
 
void setDoubleClickListener(GEventListenerVoid func)
 Sets a mouse listener on this canvas so that it will be called when the mouse is double-clicked on the canvas. More...
 
void setEnabled(bool value)
 Sets whether this interactor is currently enabled. More...
 
void setEventsEnabled(bool eventsEnabled)
 Sets whether the object is currently allowing itself to fire events. More...
 
void setFillColor(int color)
 Sets the current fill color of the interactor as an RGB integer. More...
 
void setFillColor(string color)
 Returns the current fill color of the interactor as a string. More...
 
void setFont(const QFont &font)
 Returns the current text font of the interactor using a Qt font object. More...
 
void setFont(string font)
 Sets the current text font of the interactor as a font string. More...
 
void setForeground(int rgb)
 Sets the current foreground outline color of the interactor as an RGB integer. More...
 
void setForeground(string color)
 Sets the current foreground outline color of the interactor as a string. More...
 
void setHeight(double height)
 Sets the onscreen height of the interactor in pixels. More...
 
void setIcon(string filename, bool retainIconSize=true)
 Sets the file name of the icon associated with this interactor, or an empty string if no icon has been set. More...
 
void setKeyListener(GEventListener func)
 Sets a key listener on this canvas so that it will be called when any key is pressed or released on the canvas. More...
 
void setKeyListener(GEventListenerVoid func)
 Sets a key listener on this canvas so that it will be called when any key is pressed or released on the canvas. More...
 
void setLineStyle(GObject::LineStyle lineStyle)
 Sets the current line style which will be used to draw outlines of shapes and lines. More...
 
void setLineWidth(double lineWidth)
 Sets the thickness used when drawing outlines of shapes and lines. More...
 
void setLocation(double x, double y)
 Sets the onscreen x/y-coordinate of the top-left corner of the interactor relative to its window. More...
 
void setMinimumSize(double width, double height)
 Sets the minimum size in pixels that this interactor will permit itself to be resized to. More...
 
void setMinimumSize(const GDimension &size)
 Sets the minimum size in pixels that this interactor will permit itself to be resized to. More...
 
void setMouseListener(GEventListener func)
 Sets a mouse listener on this canvas so that it will be called when the mouse is moved or clicked on the canvas. More...
 
void setMouseListener(GEventListenerVoid func)
 Sets a mouse listener on this canvas so that it will be called when the mouse is moved or clicked on the canvas. More...
 
void setName(string name)
 Sets a string representing a unique name for this interactor. More...
 
void setPixel(double x, double y, string color)
 Sets the color of the given x/y pixel in the background layer of the interactor to the given color. More...
 
void setPixel(double x, double y, int rgb)
 Sets the color of the given x/y pixel in the background layer of the canvas to the given RGB value. More...
 
void setPixel(double x, double y, int r, int g, int b)
 Sets the color of the given x/y pixel in the background layer of the canvas to the given RGB values. More...
 
void setPixelARGB(double x, double y, int argb)
 Sets the color of the given x/y pixel in the background layer of the canvas to the given ARGB value. More...
 
void setPixelARGB(double x, double y, int a, int r, int g, int b)
 Sets the color of the given x/y pixel in the background layer of the canvas to the given ARGB values. More...
 
void setPixels(const Grid< int > &pixels)
 Sets the color of the all pixels in the background layer of the canvas to the given RGB values, using rows as y-values and columns as x-values. More...
 
void setPixelsARGB(const Grid< int > &pixelsARGB)
 Sets the color of the all pixels in the background layer of the canvas to the given ARGB values, using rows as y-values and columns as x-values. More...
 
void setPreferredHeight(double height)
 Sets the height in pixels that this interactor would prefer to be. More...
 
void setPreferredSize(double width, double height)
 Sets the width and height in pixels that this interactor would prefer to be. More...
 
void setPreferredSize(const GDimension &size)
 Sets the size in pixels that this interactor would prefer to be. More...
 
void setPreferredWidth(double width)
 Sets the width in pixels that this interactor would prefer to be. More...
 
void setRepaintImmediately(bool autoRepaint)
 Sets whether the interactor should repaint itself automatically whenever any change is made to its graphical data. More...
 
void setRGB(double x, double y, int rgb)
 Sets the color of the given x/y pixel in the background layer of the interactor to the given RGB values. More...
 
void setRGB(double x, double y, int r, int g, int b)
 Sets the color of the given x/y pixel in the background layer of the interactor to the given RGB values. More...
 
void setRGB(double x, double y, string color)
 Sets the color of the given x/y pixel in the background layer of the interactor to the given color. More...
 
void setSize(double width, double height)
 Sets the onscreen width and height of the interactor in pixels. More...
 
void setSize(const GDimension &size)
 Sets the onscreen width and height of the interactor in pixels. More...
 
void setTooltip(string tooltipText)
 Sets a "tooltip" that will appear if the user hovers their mouse over the interactor. More...
 
void setVisible(bool visible)
 Returns true if the interactor is visible on the screen. More...
 
void setWidth(double width)
 Sets the onscreen width of the interactor in pixels. More...
 
void setX(double x)
 Sets the onscreen x-coordinate of the top-left corner of the interactor relative to its window. More...
 
void setY(double y)
 Sets the onscreen y-coordinate of the top-left corner of the interactor relative to its window. More...
 
GImagetoGImage() const
 Converts the pixels of the canvas into a GImage object. More...
 
Grid< int > toGrid() const
 Converts this canvas's pixel data into a grid of RGB pixels. More...
 
void toGrid(Grid< int > &grid) const
 Converts this canvas's pixel data into a grid of RGB pixels. More...
 
string toString() const
 Returns a string representation of this observable object's state. More...
 

Static Public Member Functions

static int createRgbPixel(int red, int green, int blue)
 Creates a single RGB integer from the given R-G-B components from 0-255. More...
 
static int getAlpha(int argb)
 Extracts the alpha component from 0-255 of the given ARGB integer. More...
 
static int getBlue(int rgb)
 Extracts the blue component from 0-255 of the given RGB integer. More...
 
static int getGreen(int rgb)
 Extracts the green component from 0-255 of the given RGB integer. More...
 
static int getRed(int rgb)
 Extracts the red component from 0-255 of the given RGB integer. More...
 
static void getRedGreenBlue(int rgb, int &red, int &green, int &blue)
 Extracts the red, green, and blue components from 0-255 of the given RGB integer, filling by reference. More...
 

Static Public Attributes

static const int WIDTH_HEIGHT_MAX = 65535
 Largest value that an image's width and/or height can have. More...
 

Protected Member Functions

void checkBounds(string member, double x, double y, double width, double height) const
 Throws an error if the given x/y values are out of bounds. More...
 
void checkColor(string member, int rgb) const
 Throws an error if the given rgb value is not a valid color. More...
 
void checkSize(string member, double width, double height) const
 Throws an error if the given width/height values are out of bounds. More...
 
void clearEventListeners()
 Removes all event listeners from this object. More...
 
void ensureThreadSafety(string memberName="")
 Ensures that we are currently in the Qt GUI thread. More...
 
void fireEvent(GEvent &event)
 Sends out the given event to any attached listeners. More...
 
void fireGEvent(QEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QCloseEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QKeyEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QMouseEvent *event, EventType eventType, string eventName, string actionCommand="")
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QResizeEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QTimerEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QWheelEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QWindowStateChangeEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
bool hasEventListener(string eventName) const
 Returns true if the observable object has a listener for the given type of event. More...
 
void initializeGObject(GObject &obj, bool filled=false)
 Initializes a new graphical object to be drawn. More...
 
void initializeGObject(GObject *obj, bool filled=false)
 Initializes a new graphical object to be drawn. More...
 
bool isAcceptingEvent(int eventMask) const
 Returns true if the observable object has a listener for the given type of event. More...
 
bool isAcceptingEvent(const GEvent &event) const
 Returns true if the observable object has a listener for the given type of event. More...
 
bool isAcceptingEvent(string eventType) const
 Returns true if the observable object has a listener for the given type of event. More...
 
void removeEventListener(string eventName)
 Removes any event listener from this observable object that would respond to the given type of event, such as "click" or "keydown". More...
 
void removeEventListeners(std::initializer_list< string > eventNames)
 Removes any event listener from this observable object that would respond to the given types of events, such as "click" or "keydown". More...
 
void setEventListener(string eventName, GEventListener func)
 Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown". More...
 
void setEventListener(string eventName, GEventListenerVoid func)
 Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown". More...
 
void setEventListeners(std::initializer_list< string > eventNames, GEventListener func)
 Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown". More...
 
void setEventListeners(std::initializer_list< string > eventNames, GEventListenerVoid func)
 Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown". More...
 

Protected Attributes

bool _autoRepaint
 
string _backgroundColor
 
int _backgroundColorInt
 
string _color
 
int _colorInt
 
string _fillColor
 
int _fillColorInt
 
string _font
 
GDrawingSurface_forwardTarget
 
GObject::LineStyle _lineStyle
 
double _lineWidth
 

Detailed Description

A GCanvas is a graphical drawing surface on which you can draw shapes, lines, and colors, as well as setting the RGB color values of individual pixels.

The graphical canvas consists of two layers:

1) The background layer provides a surface for drawing static pictures that involve no animation, or for 2D pixel-based drawing algorithms. The class includes several drawXxx and fillXxx methods that draw lines, rectangles, and ovals on the background layer.

The setPixel and setPixels methods manipulate the color of pixels in the background layer. You can get all of the pixels as a Grid using getPixels, modify the grid, then pass it back in using setPixels, to perform 2D pixel-based manipulations on the canvas.

2) The foreground layer provides an abstraction for adding stateful shapes and graphical objects onto the canvas. The add() methods that accept GObject parameters place these objects onto the foreground layer. The advantage of the foreground layer is that you can manipulate the object over time, such as moving it, changing its color, size, or other properties, and see these changes immediately on the screen. This makes the foreground layer most appropriate for animations or moving sprites.

A GCanvas is implicitly added to the center of every GWindow when the client calls the window's add(), drawXxx/fillXxx, or other methods. In most cases the window just forwards these method calls to its internal GCanvas, which performs the bulk of the work.

See gobjects.h for more detail about drawing shapes and objects.

Member Enumeration Documentation

◆ TextPosition

enum TextPosition
inherited

The places where an interactor can place its text relative to its icon.

Enumerator
TEXT_BESIDE_ICON 
TEXT_UNDER_ICON 
TEXT_ONLY 

Constructor & Destructor Documentation

◆ GCanvas() [1/5]

GCanvas ( QWidget*   parent = nullptr)

Creates an empty canvas with a default size of 0x0 pixels and a default background and foreground color of black.

◆ GCanvas() [2/5]

GCanvas ( string   filename,
QWidget*   parent = nullptr 
)

Creates a canvas that loads its background layer pixel data from the given image file name.

Exceptions
ErrorExceptionif the given file does not exist or cannot be read as a valid image file

◆ GCanvas() [3/5]

GCanvas ( std::istream &  filename,
QWidget*   parent = nullptr 
)

Creates a canvas that loads its background layer pixel data from the given input stream.

Exceptions
ErrorExceptionif the given stream cannot be read as a valid image file

◆ GCanvas() [4/5]

GCanvas ( double  width,
double  height,
int  rgbBackground,
QWidget*   parent = nullptr 
)

Creates an empty canvas of the specified size and optional background color.

If no background color is passed, a default transparent background is used.

Exceptions
ErrorExceptionif the given width/height ranges are negative
ErrorExceptionif the given rgb value is invalid or out of range

◆ GCanvas() [5/5]

GCanvas ( double  width,
double  height,
string   rgbBackground = "#00000000",
QWidget*   parent = nullptr 
)

Creates an empty canvas of the specified size and background color.

If no background color is passed, a default transparent background is used.

Exceptions
ErrorExceptionif the given width/height ranges are negative
ErrorExceptionif the given rgb value is invalid or out of range

◆ ~GCanvas()

~GCanvas ( )
virtual

Frees memory allocated internally by the canvas.

Member Function Documentation

◆ add() [1/4]

void add ( GObject gobj)
virtual

Adds the given interactor to canvas.

Exceptions
ErrorExceptionif the interactor is null

◆ add() [2/4]

void add ( GObject gobj,
double  x,
double  y 
)
virtual

Adds the given interactor to the canvas and moves it to the given x/y location.

Exceptions
ErrorExceptionif the interactor is null

◆ add() [3/4]

void add ( GObject gobj)
virtual

Adds the given interactor to canvas.

◆ add() [4/4]

void add ( GObject gobj,
double  x,
double  y 
)
virtual

Adds the given interactor to the canvas and moves it to the given x/y location.

◆ addActionListener()

void addActionListener ( )
virtualinherited

Adds an event listener to be notified when this interactor is clicked or generally interacted with.

Deprecated:
does nothing; use setActionListener instead

◆ checkBounds()

void checkBounds ( string   member,
double  x,
double  y,
double  width,
double  height 
) const
protectedinherited

Throws an error if the given x/y values are out of bounds.

◆ checkColor()

void checkColor ( string   member,
int  rgb 
) const
protectedinherited

Throws an error if the given rgb value is not a valid color.

◆ checkSize()

void checkSize ( string   member,
double  width,
double  height 
) const
protectedinherited

Throws an error if the given width/height values are out of bounds.

◆ clear()

void clear ( )
virtual

Removes all graphical objects from the canvas foreground layer and wipes the background layer to show the current background color.

Implements GDrawingSurface.

◆ clearEventListeners()

void clearEventListeners ( )
protectedvirtualinherited

Removes all event listeners from this object.

◆ clearObjects()

void clearObjects ( )
virtual

Removes all graphical objects from the foreground layer of the canvas.

This means that any shapes added using the add() methods, such as GRect, GOval, etc. will be removed, while any shapes drawn directly onto the canvas's background pixel layer by calling the drawXxx() methods will be retained. To clear the background layer as well, call clearPixels or clear instead.

◆ clearPixels()

void clearPixels ( )
virtual

Resets the background layer of pixels in the canvas to the current background color.

This means that any shapes added using the add() methods, such as GRect, GOval, etc. will remain, while any shapes drawn directly onto the canvas's background pixel layer by calling the drawXxx() methods will be wiped out. To clear the shapes added to the foreground layer as well, call clearObjects or clear instead.

◆ conditionalRepaint()

void conditionalRepaint ( )
virtualinherited

Repaints the interactor only if its contents have changed.

◆ conditionalRepaintRegion() [1/2]

void conditionalRepaintRegion ( int  x,
int  y,
int  width,
int  height 
)
virtualinherited

Repaints the given region of the interactor only if its contents have changed.

◆ conditionalRepaintRegion() [2/2]

void conditionalRepaintRegion ( const GRectangle bounds)
virtualinherited

Repaints the given region of the interactor only if its contents have changed.

◆ contains()

bool contains ( double  x,
double  y 
) const
virtual

Returns true if any of the graphical objects in the foreground layer of the canvas touch the given x/y pixel.

◆ countDiffPixels() [1/4]

int countDiffPixels ( const GCanvas image) const
virtual

Returns the total number of pixels that are not the same color between this image and the given other image.

If the images are not the same size, any pixels in the range of one image but out of the bounds of the other are considered to be differing. In this version of the method, the entire images are compared.

◆ countDiffPixels() [2/4]

int countDiffPixels ( const GCanvas image,
int  xmin,
int  ymin,
int  xmax,
int  ymax 
) const
virtual

Returns the total number of pixels that are not the same color between this image and the given other image.

If the images are not the same size, any pixels in the range of one image but out of the bounds of the other are considered to be differing. In this version of the method, you pass an (x,y) range of pixels to compare.

◆ countDiffPixels() [3/4]

int countDiffPixels ( const GCanvas image) const
virtual

Returns the total number of pixels that are not the same color between this image and the given other image.

If the images are not the same size, any pixels in the range of one image but out of the bounds of the other are considered to be differing. In this version of the method, the entire images are compared.

Exceptions
ErrorExceptionif the image passed is null

◆ countDiffPixels() [4/4]

int countDiffPixels ( const GCanvas image,
int  xmin,
int  ymin,
int  xmax,
int  ymax 
) const
virtual

Returns the total number of pixels that are not the same color between this image and the given other image.

If the images are not the same size, any pixels in the range of one image but out of the bounds of the other are considered to be differing. In this version of the method, you pass an (x,y) range of pixels to compare.

Exceptions
ErrorExceptionif the image passed is null

◆ createRgbPixel()

int createRgbPixel ( int  red,
int  green,
int  blue 
)
static

Creates a single RGB integer from the given R-G-B components from 0-255.

Exceptions
ErrorExceptionif red, green, or blue is not between 0-255 inclusive

◆ diff() [1/2]

GCanvas * diff ( const GCanvas image,
int  diffPixelColor = GCANVAS_DEFAULT_DIFF_PIXEL_COLOR 
) const
virtual

Generates a new canvas whose content is equal to that of this canvas but with any pixels that don't match those in parameter 'image' colored in the given color (default purple) to highlight differences between the two.

◆ diff() [2/2]

GCanvas * diff ( const GCanvas image,
int  diffPixelColor = GCANVAS_DEFAULT_DIFF_PIXEL_COLOR 
) const
virtual

Generates a new canvas whose content is equal to that of this canvas but with any pixels that don't match those in parameter 'image' colored in the given color (default purple) to highlight differences between the two.

Exceptions
ErrorExceptionif the image passed is null

◆ draw() [1/4]

void draw ( GObject gobj,
double  x,
double  y 
)
virtualinherited

Draws the given graphical object onto the background pixel layer of this interactor, moving it to the given x/y location first.

Exceptions
ErrorExceptionif the object is null

◆ draw() [2/4]

void draw ( GObject gobj)
virtualinherited

Draws the given graphical object onto the background pixel layer of this interactor.

◆ draw() [3/4]

void draw ( GObject gobj,
double  x,
double  y 
)
virtualinherited

Draws the given graphical object onto the background pixel layer of this interactor, moving it to the given x/y location first.

◆ draw() [4/4]

void draw ( GObject gobj)
virtual

Draws the given graphical object onto the background layer of the canvas.

Note that since it is drawn on the background layer, future changes to the graphical object, such as setting its location, color, size, etc., will not be reflected immediately on this canvas. If you do want such changes to be reflected, instead add the shape to the foreground layer using add().

Exceptions
ErrorExceptionif the object passed is null

Implements GDrawingSurface.

◆ drawArc()

void drawArc ( double  x,
double  y,
double  width,
double  height,
double  start,
double  sweep 
)
virtualinherited

Draws an unfilled arc with the given attributes onto the background pixel layer of this interactor in the current color.

See gobjects.h for explanation of GArc parameters.

◆ drawImage()

void drawImage ( string   filename,
double  x = 0,
double  y = 0 
)
virtualinherited

Draws an image loaded from the given file name onto the background pixel layer of this interactor at the given x/y location.

See gobjects.h for explanation of GImage parameters.

Exceptions
ErrorExceptionif the given file is not found or cannot be loaded as a valid image file

◆ drawLine() [1/2]

void drawLine ( const GPoint p0,
const GPoint p1 
)
virtualinherited

Draws a line between the given two points onto the background pixel layer of this interactor at the given x/y location in the current color.

See gobjects.h for explanation of GLine parameters.

◆ drawLine() [2/2]

void drawLine ( double  x0,
double  y0,
double  x1,
double  y1 
)
virtualinherited

Draws a line between the given two points onto the background pixel layer of this interactor at the given x/y location in the current color.

See gobjects.h for explanation of GLine parameters.

◆ drawOval() [1/2]

void drawOval ( const GRectangle bounds)
virtualinherited

Draws an unfilled oval with the given bounding box onto the background pixel layer of this interactor at the given x/y location in the current color.

See gobjects.h for explanation of GOval parameters.

◆ drawOval() [2/2]

void drawOval ( double  x,
double  y,
double  width,
double  height 
)
virtualinherited

Draws an unfilled oval with the given bounding box onto the background pixel layer of this interactor at the given x/y location in the current color.

See gobjects.h for explanation of GOval parameters.

◆ drawPixel() [1/3]

void drawPixel ( double  x,
double  y 
)
virtualinherited

Colors the given x/y pixel of the background layer of this interactor using the interactor's current color.

◆ drawPixel() [2/3]

void drawPixel ( double  x,
double  y,
int  color 
)
virtualinherited

Colors the given x/y pixel of the background layer of this interactor using the given color.

◆ drawPixel() [3/3]

void drawPixel ( double  x,
double  y,
string   color 
)
virtualinherited

Colors the given x/y pixel of the background layer of this interactor using the given color.

◆ drawPolarLine() [1/2]

GPoint drawPolarLine ( const GPoint p0,
double  r,
double  theta 
)
virtualinherited

Draws a line using polar coordinates onto the background pixel layer of this interactor in the current color.

The line begins at the given x/y point and extends from there by the given angle and radius. Returns the end point opposite p0 where the line ends. See gobjects.h for explanation of GLine parameters.

◆ drawPolarLine() [2/2]

GPoint drawPolarLine ( double  x0,
double  y0,
double  r,
double  theta 
)
virtualinherited

Draws a line using polar coordinates onto the background pixel layer of this interactor in the current color.

The line begins at the given x/y point and extends from there by the given angle and radius. Returns the end point where the line ends. See gobjects.h for explanation of GLine parameters.

◆ drawPolygon() [1/2]

void drawPolygon ( std::initializer_list< double >  coords)
virtualinherited

Draws an unfilled polygon containing the given points onto the background pixel layer of this interactor in the current color.

See gobjects.h for explanation of GPolygon parameters.

◆ drawPolygon() [2/2]

void drawPolygon ( std::initializer_list< GPoint points)
virtualinherited

Draws an unfilled polygon containing the given points onto the background pixel layer of this interactor in the current color.

See gobjects.h for explanation of GPolygon parameters.

◆ drawRect() [1/2]

void drawRect ( const GRectangle bounds)
virtualinherited

Draws an unfilled rectangle of the given dimensions onto the background pixel layer of this interactor in the current color.

See gobjects.h for explanation of GRect parameters.

◆ drawRect() [2/2]

void drawRect ( double  x,
double  y,
double  width,
double  height 
)
virtualinherited

Draws an unfilled rectangle of the given dimensions onto the background pixel layer of this interactor in the current color.

See gobjects.h for explanation of GRect parameters.

◆ drawString()

void drawString ( string   text,
double  x,
double  y 
)
virtualinherited

Draws a text string onto the background pixel layer of this interactor at the given x/y location in the current font and color.

See gobjects.h for explanation of GText parameters.

◆ ensureThreadSafety()

void ensureThreadSafety ( string   memberName = "")
protectedvirtualinherited

Ensures that we are currently in the Qt GUI thread.

◆ equals()

bool equals ( const GCanvas other) const
virtual

Returns true if the two given canvases contain exactly the same pixel data.

◆ eventsEnabled()

bool eventsEnabled ( ) const
virtualinherited

Returns true if this interactor is currently accepting events.

Initially true. An interactor must be visible and added to an onscreen window to receive events.

Reimplemented from GObservable.

◆ fill() [1/2]

void fill ( int  rgb)
virtual

Sets the color of every pixel in the canvas to the given color value.

See gcolor.h for more detail about colors.

Exceptions
ErrorExceptionif the given rgb value is not a valid color

◆ fill() [2/2]

void fill ( string   rgb)
virtual

Sets the color of every pixel in the canvas to the given color value.

See gcolor.h for more detail about colors.

◆ fillArc()

void fillArc ( double  x,
double  y,
double  width,
double  height,
double  start,
double  sweep 
)
virtualinherited

Draws a filled arc with the given attributes onto the background pixel layer of this interactor in the current color and fill color.

See gobjects.h for explanation of GArc parameters.

◆ fillOval() [1/2]

void fillOval ( const GRectangle bounds)
virtualinherited

Draws a filled oval with the given bounding box onto the background pixel layer of this interactor at the given x/y location in the current color and fill color.

See gobjects.h for explanation of GOval parameters.

◆ fillOval() [2/2]

void fillOval ( double  x,
double  y,
double  width,
double  height 
)
virtualinherited

Draws a filled oval with the given bounding box onto the background pixel layer of this interactor at the given x/y location in the current color and fill color.

See gobjects.h for explanation of GOval parameters.

◆ fillPolygon()

void fillPolygon ( std::initializer_list< double >  coords)
virtualinherited

Draws a filled polygon containing the given points onto the background pixel layer of this interactor in the current color and fill color.

See gobjects.h for explanation of GPolygon parameters.

◆ fillRect() [1/2]

void fillRect ( const GRectangle bounds)
virtualinherited

Draws a filled rectangle of the given dimensions onto the background pixel layer of this interactor in the current color and fill color.

See gobjects.h for explanation of GRect parameters.

◆ fillRect() [2/2]

void fillRect ( double  x,
double  y,
double  width,
double  height 
)
virtualinherited

Draws a filled rectangle of the given dimensions onto the background pixel layer of this interactor in the current color and fill color.

See gobjects.h for explanation of GRect parameters.

◆ fillRegion() [1/2]

void fillRegion ( double  x,
double  y,
double  width,
double  height,
int  rgb 
)
virtual

Sets the color of every pixel in the given rectangular range of the canvas pixel data to the given color value.

Specifically, the pixels in the rectangular range (x, y) through (x + width - 1, y + height - 1) become filled with the given color.

Exceptions
ErrorExceptionif the given x/y/width/height range goes outside the bounds of the image, or if the given rgb value is not a valid color

◆ fillRegion() [2/2]

void fillRegion ( double  x,
double  y,
double  width,
double  height,
string   rgb 
)
virtual

Sets the color of every pixel in the given rectangular range of the canvas pixel data to the given color value.

Specifically, the pixels in the rectangular range (x, y) through (x + width - 1, y + height - 1) become filled with the given color.

Exceptions
ErrorExceptionif the given x/y/width/height range goes outside the bounds of the image

◆ fireEvent()

void fireEvent ( GEvent event)
protectedvirtualinherited

Sends out the given event to any attached listeners.

◆ fireGEvent() [1/8]

void fireGEvent ( QEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [2/8]

void fireGEvent ( QCloseEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [3/8]

void fireGEvent ( QKeyEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [4/8]

void fireGEvent ( QMouseEvent *  event,
EventType  eventType,
string   eventName,
string   actionCommand = "" 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [5/8]

void fireGEvent ( QResizeEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [6/8]

void fireGEvent ( QTimerEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [7/8]

void fireGEvent ( QWheelEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [8/8]

void fireGEvent ( QWindowStateChangeEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ flatten()

void flatten ( )
virtual

Moves all graphical objects from the foreground layer to the background layer.

This means that future changes to those objects will not be seen on the canvas.

◆ fromGrid()

void fromGrid ( const Grid< int > &  grid)
virtual

Replaces the entire contents of the background layer of the canvas with the contents of the given grid of RGB pixel values.

If this image is not the same size as the grid, the image is resized. Any previous background layer contents are lost. Equivalent to getPixels.

◆ getAccelerator()

string getAccelerator ( ) const
virtualinherited

Returns a string representing a hotkey for this interactor, or an empty string if no accelerator has been set.

Returns
an accelerator such as "Ctrl-S"

Reimplemented in GButton.

◆ getActionCommand()

string getActionCommand ( ) const
virtualinherited

Returns an action command for this interactor, which is a semi-unique string you can use to identify it when events occur.

For example, for buttons, the default action command is the button's text.

Reimplemented in GChooser, GRadioButton, GCheckBox, and GButton.

◆ getAlpha()

int getAlpha ( int  argb)
static

Extracts the alpha component from 0-255 of the given ARGB integer.

The alpha component comes from bits 24-31 (most significant) of the integer.

◆ getARGB()

int getARGB ( double  x,
double  y 
) const
virtualinherited

Returns the pixel color data at the given x/y location, retaining alpha-channel transparency in the top 8 bits.

◆ getBackground()

string getBackground ( ) const
virtual

Returns the current background color of the interactor as a string.

See gcolor.h for more detail about color strings.

Reimplemented from GDrawingSurface.

◆ getBackgroundInt()

int getBackgroundInt ( ) const
virtual

Returns the current background color of the interactor as an RGB integer.

See gcolor.h for more detail about colors.

Reimplemented from GDrawingSurface.

◆ getBlue()

int getBlue ( int  rgb)
static

Extracts the blue component from 0-255 of the given RGB integer.

The blue component comes from bits 0-7 (least significant) of the integer.

◆ getBounds()

GRectangle getBounds ( ) const
virtualinherited

Returns a rectangle representing the x/y position and size of this interactor.

◆ getColor() [1/2]

string getColor ( ) const
virtualinherited

Returns the foreground/text color of the interactor as a string.

Equivalent to getForeground.

Returns
a string such as "blue" or "#7700ff"

◆ getColor() [2/2]

string getColor ( ) const
virtualinherited

Returns the current foreground outline color of the interactor as a string.

This color will be used to draw the outlines of shapes drawn using the drawXxx and fillXxx methods, as well as being the default color used when calling setPixel or setRGB. See gcolor.h for more detail about color strings. Equivalent to getForeground.

◆ getColorInt() [1/2]

int getColorInt ( ) const
virtualinherited

Returns the foreground/text color of the interactor as an RGB integer.

Equivalent to getForegroundInt.

Returns
an integer such as 0x7700ff

◆ getColorInt() [2/2]

int getColorInt ( ) const
virtualinherited

Returns the current foreground outline color of the interactor as an RGB integer.

This color will be used to draw the outlines of shapes drawn using the drawXxx and fillXxx methods, as well as being the default color used when calling setPixel or setRGB. See gcolor.h for more detail about colors. Equivalent to getForegroundInt.

◆ getContainer()

GContainer * getContainer ( ) const
virtualinherited

Returns a pointer to the onscreen container holding this interactor.

When an interactor is created, its container is initially null. This will become non-null automatically if you add the interactor to a window or other layout container. Interactors must be added to a container or window to receive events or to become visible on the screen.

Returns
the container, or nullptr if interactor has not yet been added to any container

◆ getElement()

GObject * getElement ( int  index) const
virtual

Returns a pointer to the graphical object in the foreground layer of the canvas at the specified index, numbering from back to front in the z dimension.

Exceptions
ErrorExceptionif the index is out of range

◆ getElementAt()

GObject * getElementAt ( double  x,
double  y 
) const
virtual

Returns a pointer to the first graphical object in the foreground layer of the canvas that contains the given (x, y) point, or a null pointer if no object in this canvas touches it.

◆ getElementCount()

int getElementCount ( ) const
virtual

Returns the number of graphical objects stored in the foreground layer of the canvas.

◆ getFilename()

string getFilename ( ) const
virtual

Returns the name of the image file from which this canvas was loaded or to which it was saved most recently.

If this canvas was not associated with any file, returns "".

◆ getFillColor()

string getFillColor ( ) const
virtualinherited

Returns the current fill color of the interactor as a string.

This color will appear in shapes drawn using the fillXxx methods. See gcolor.h for more detail about color strings.

◆ getFillColorInt()

int getFillColorInt ( ) const
virtualinherited

Returns the current fill color of the interactor as an RGB integer.

This color will appear in shapes drawn using the fillXxx methods. See gcolor.h for more detail about color strings.

◆ getFont()

string getFont ( ) const
virtual

Returns the current text font of the interactor as a font string.

This font will be used when drawing text strings using drawString. See gfont.h for more detail about font strings.

Reimplemented from GDrawingSurface.

◆ getForeground() [1/2]

string getForeground ( ) const
virtualinherited

Returns the foreground/text color of the interactor as a string.

Equivalent to getColor.

Returns
a string such as "blue" or "#7700ff"

◆ getForeground() [2/2]

string getForeground ( ) const
virtualinherited

Returns the current foreground outline color of the interactor as a string.

This color will be used to draw the outlines of shapes drawn using the drawXxx and fillXxx methods, as well as being the default color used when calling setPixel or setRGB. See gcolor.h for more detail about color strings. Equivalent to getColor.

◆ getForegroundInt() [1/2]

int getForegroundInt ( ) const
virtualinherited

Returns the foreground/text color of the interactor as an RGB integer.

Equivalent to getColorInt.

Returns
an integer such as 0x7700ff

◆ getForegroundInt() [2/2]

int getForegroundInt ( ) const
virtualinherited

Returns the current foreground outline color of the interactor as an RGB integer.

This color will be used to draw the outlines of shapes drawn using the drawXxx and fillXxx methods, as well as being the default color used when calling setPixel or setRGB. See gcolor.h for more detail about colors. Equivalent to getColor.

◆ getGreen()

int getGreen ( int  rgb)
static

Extracts the green component from 0-255 of the given RGB integer.

The green component comes from bits 8-15 of the integer.

◆ getHeight()

double getHeight ( ) const
virtualinherited

Returns the current onscreen height of this interactor in pixels.

◆ getIcon()

string getIcon ( ) const
virtualinherited

Returns the file name of the icon associated with this interactor, or an empty string if no icon has been set.

Not all types of interactors support icons.

◆ getID()

int getID ( ) const
virtualinherited

Returns a globally unique identifier for this interactor, which is set when the interactor is constructed.

These IDs can be useful for debugging to help identify interactors uniquely.

◆ getInternalWidget()

_Internal_QWidget* getInternalWidget ( ) const
virtual

Returns a direct pointer to the internal Qt widget being wrapped by this interactor.

This must be overridden by all interactor subclasses. Students/clients generally should not need to call this.

Implements GInteractor.

◆ getLineStyle()

GObject::LineStyle getLineStyle ( ) const
virtualinherited

Returns the current line style which will be used to draw outlines of shapes and lines.

The default line style is a solid line (GObject::LINE_SOLID).

◆ getLineWidth()

double getLineWidth ( ) const
virtualinherited

Returns the thickness used when drawing outlines of shapes and lines.

The default thickness is 1.

◆ getLocation()

GPoint getLocation ( ) const
virtualinherited

Returns an (x, y) point representing the onscreen location of the top-left corner of this interactor within its containing window.

◆ getMinimumHeight()

double getMinimumHeight ( ) const
virtualinherited

Returns the minimum height in pixels that this interactor will permit itself to be resized to.

◆ getMinimumSize()

GDimension getMinimumSize ( ) const
virtualinherited

Returns a GDimension structure representing the minimum size in pixels that this interactor will permit itself to be resized to.

◆ getMinimumWidth()

double getMinimumWidth ( ) const
virtualinherited

Returns the minimum width in pixels that this interactor will permit itself to be resized to.

◆ getName()

string getName ( ) const
virtualinherited

Returns a string representing a unique name for this interactor.

The default name string uses the interactor's type and its ID to make a string like "GButton_14", but you can override this by calling setName.

Returns
a string such as "GButton_14"

◆ getPixel()

int getPixel ( double  x,
double  y 
) const
virtual

Returns the color of the pixel at the given x/y coordinates of the background layer of the canvas as an integer such as 0xff00cc.

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixels to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixels to submit all of your changes.

Exceptions
ErrorExceptionif the given x/y values are out of bounds.

Implements GDrawingSurface.

◆ getPixelARGB()

int getPixelARGB ( double  x,
double  y 
) const
virtual

Returns the color of the pixel at the given x/y coordinates of the background layer of the canvas as an integer such as 0xffff00cc.

This differs from getPixel in that it explicitly retains and returns the alpha channel of the pixel in the top 8 bits, allowing for transparency effects.

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixels to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixels to submit all of your changes.

Exceptions
ErrorExceptionif the given x/y values are out of bounds.

Implements GDrawingSurface.

◆ getPixels()

Grid< int > getPixels ( ) const
virtual

Returns all pixels of the background layer of the canvas as a Grid, where rows represent y values and columns represent x values.

So for example, grid[y][x] returns the RGB int value at that pixel. Equivalent to toGrid.

Implements GDrawingSurface.

◆ getPixelsARGB()

Grid< int > getPixelsARGB ( ) const
virtual

Returns all pixels of the background layer of the canvas as a Grid, where rows represent y values and columns represent x values.

This differs from getPixels in that it explicitly retains and returns the alpha channel of each pixel in the top 8 bits, allowing for transparency effects.

Implements GDrawingSurface.

◆ getPixelString()

string getPixelString ( double  x,
double  y 
) const
virtualinherited

Returns the color of the pixel at the given x/y coordinates of the image as a string such as "#ff00cc".

The string that is returned comes from the GWindow function convertRGBToColor; see documentation of that function. Throws an error if the given x/y values are out of bounds.

◆ getPreferredHeight()

double getPreferredHeight ( ) const
virtualinherited

Returns the height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars.

◆ getPreferredSize()

GDimension getPreferredSize ( ) const
virtualinherited

Returns a GDimension structure storing the width and height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars.

Reimplemented in GContainer.

◆ getPreferredWidth()

double getPreferredWidth ( ) const
virtualinherited

Returns the height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars.

◆ getRed()

int getRed ( int  rgb)
static

Extracts the red component from 0-255 of the given RGB integer.

The red component comes from bits 16-23 of the integer.

◆ getRedGreenBlue()

void getRedGreenBlue ( int  rgb,
int &  red,
int &  green,
int &  blue 
)
static

Extracts the red, green, and blue components from 0-255 of the given RGB integer, filling by reference.

◆ getRGB()

int getRGB ( double  x,
double  y 
) const
virtualinherited

Returns the color of the pixel at the given x/y coordinates of the background layer of the interactor as an integer such as 0xff00cc.

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixels to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixels to submit all of your changes.

Equivalent to getPixel.

Exceptions
ErrorExceptionif the given x/y values are out of bounds.

◆ getRGBString()

string getRGBString ( double  x,
double  y 
) const
virtualinherited

Returns the color of the pixel at the given x/y coordinates of the background layer of the interactor as a color string such as "#ff00cc".

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixels to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixels to submit all of your changes.

Exceptions
ErrorExceptionif the given x/y values are out of bounds.

◆ getSize()

GDimension getSize ( ) const
virtualinherited

Returns a GDimension structure storing the current onscreen width and height of this interactor in pixels.

◆ getType()

string getType ( ) const
virtual

Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox".

All subclasses of GInteractor must implement this method.

Returns
a string such as "GCheckBox"

Implements GInteractor.

◆ getWidget()

QWidget* getWidget ( ) const
virtual

Returns a direct pointer to the internal Qt widget being wrapped by this interactor.

This must be overridden by all interactor subclasses. Students/clients generally should not need to call this.

Implements GInteractor.

◆ getWidth()

double getWidth ( ) const
virtualinherited

Returns the current onscreen width of this interactor in pixels.

◆ getX()

double getX ( ) const
virtualinherited

Returns the x-coordinate of the top-left pixel of this interactor within its onscreen window.

◆ getY()

double getY ( ) const
virtualinherited

Returns the y-coordinate of the top-left pixel of this interactor within its onscreen window.

◆ hasEventListener()

bool hasEventListener ( string   eventName) const
protectedvirtualinherited

Returns true if the observable object has a listener for the given type of event.

◆ inBounds() [1/2]

bool inBounds ( double  x,
double  y 
) const
virtualinherited

Returns true if the given x/y pixel is within the bounds of this interactor.

◆ inBounds() [2/2]

bool inBounds ( int  x,
int  y 
) const
virtualinherited

Returns true if the given x/y pixel is within the bounds of this interactor.

Reimplemented in GTable.

◆ initializeGObject() [1/2]

void initializeGObject ( GObject obj,
bool  filled = false 
)
protectedvirtualinherited

Initializes a new graphical object to be drawn.

Used as a convenience method to set the color, fill color, outline style, font, and other settings of graphical objects based on the settings of the drawing surface.

◆ initializeGObject() [2/2]

void initializeGObject ( GObject obj,
bool  filled = false 
)
protectedvirtualinherited

Initializes a new graphical object to be drawn.

Used as a convenience method to set the color, fill color, outline style, font, and other settings of graphical objects based on the settings of the drawing surface.

◆ isAcceptingEvent() [1/3]

bool isAcceptingEvent ( int  eventMask) const
protectedvirtualinherited

Returns true if the observable object has a listener for the given type of event.

See gevent.h for event types and masks.

◆ isAcceptingEvent() [2/3]

bool isAcceptingEvent ( const GEvent event) const
protectedvirtualinherited

Returns true if the observable object has a listener for the given type of event.

◆ isAcceptingEvent() [3/3]

bool isAcceptingEvent ( string   eventType) const
protectedvirtualinherited

Returns true if the observable object has a listener for the given type of event.

◆ isAutoRepaint()

bool isAutoRepaint ( ) const
virtual

Returns true if the interactor should repaint itself automatically whenever any change is made to its graphical data.

But if you call setAutoRepaint(false), you must manually repaint the interactor to see any changes. This can be desirable if you plan to make a large batch of changes and want to repaint only after all of them are done. Equivalent to isRepaintImmediately.

Reimplemented from GDrawingSurface.

◆ isEnabled()

bool isEnabled ( ) const
virtualinherited

Returns true if this interactor is currently enabled.

Most interactors begin as enabled but can be disabled to stop them from being able to be clicked on or otherwise emit events.

◆ isRepaintImmediately()

bool isRepaintImmediately ( ) const
virtualinherited

Returns true if the interactor should repaint itself automatically whenever any change is made to its graphical data.

But if you call setAutoRepaint(false), you must manually repaint the interactor to see any changes. This can be desirable if you plan to make a large batch of changes and want to repaint only after all of them are done. Equivalent to isAutoRepaint.

Reimplemented in GWindow.

◆ isVisible()

bool isVisible ( ) const
virtualinherited

Returns true if the interactor is visible on the screen.

Interactors will not be visible until they are added to an onscreen window or container.

◆ load()

void load ( string   filename)
virtual

Reads the canvas's pixel contents from the given image file.

Exceptions
ErrorExceptionif the given file does not exist or cannot be read as a valid image file

◆ remove() [1/2]

void remove ( GObject gobj)
virtual

Reads the canvas's pixel contents from the given input stream.

Exceptions
ErrorExceptionif the given file does not exist or cannot be read as a valid image file Removes the given graphical object from the foreground layer of the canvas, if it was present.
ErrorExceptionif the graphical object is null

◆ remove() [2/2]

void remove ( GObject gobj)
virtual

Removes the given graphical object from the foreground layer of the canvas, if it was present.

◆ removeAll()

void removeAll ( )
virtual

Removes all graphical objects from the foreground layer of the canvas.

◆ removeClickListener()

void removeClickListener ( )
virtual

Removes the click listener from the canvas so that it will no longer call it when events occur.

◆ removeDoubleClickListener()

void removeDoubleClickListener ( )
virtual

Removes the double-click listener from the canvas so that it will no longer call it when events occur.

◆ removeEventListener()

void removeEventListener ( string   eventName)
protectedvirtualinherited

Removes any event listener from this observable object that would respond to the given type of event, such as "click" or "keydown".

◆ removeEventListeners()

void removeEventListeners ( std::initializer_list< string >  eventNames)
protectedvirtualinherited

Removes any event listener from this observable object that would respond to the given types of events, such as "click" or "keydown".

◆ removeKeyListener()

void removeKeyListener ( )
virtual

Removes the key listener from the canvas so that it will no longer call it when events occur.

◆ removeMouseListener()

void removeMouseListener ( )
virtual

Removes the mouse listener from the canvas so that it will no longer call it when events occur.

◆ repaint()

void repaint ( )
virtual

Instructs the canvas to redraw its layers.

By default the canvas will automatically repaint itself whenever you make a change to either the background or foreground layer. But if you call setAutoRepaint(false), you must manually repaint the canvas to see any changes. This can be desirable if you plan to make a large batch of changes and want to repaint only after all of them are done.

Implements GDrawingSurface.

◆ repaintRegion() [1/2]

void repaintRegion ( const GRectangle bounds)
virtualinherited

Instructs the interactor to repaint the given region of pixel data.

This can be preferable to repaint() for performance purposes if you have made a small change that affects only the given rectangular region of the interactor.

◆ repaintRegion() [2/2]

void repaintRegion ( int  x,
int  y,
int  width,
int  height 
)
virtual

Instructs the canvas to redraw the given region of pixels within both of its layers.

Implements GDrawingSurface.

◆ requestFocus()

void requestFocus ( )
virtualinherited

Transfers keyboard focus to this interactor.

Reimplemented in GTable.

◆ resize()

void resize ( double  width,
double  height,
bool  retain = true 
)
virtual

Changes this image's bounds to be the given size.

This does not scale the image but rather just changes the max x/y that can be painted onto this image. If the 'retain' parameter is not passed or is set to true, any existing pixel values will be kept during the resize. If 'retain' is false, the contents will be wiped and set to the default. Any existing pixel contents are discarded and revert to defaults.

Exceptions
ErrorExceptionif the given width/height ranges are negative

◆ save()

void save ( string   filename)
virtual

Saves the canvas's contents to the given image file.

Exceptions
ErrorExceptionif the given file is not writeable.

◆ setAccelerator()

void setAccelerator ( string   accelerator)
virtualinherited

Sets an accelerator hotkey for this interactor, such as "Ctrl-S".

Not all interactor types support accelerators.

Parameters
acceleratora hotkey such as "Ctrl-S"

Reimplemented in GButton.

◆ setActionCommand()

void setActionCommand ( string   actionCommand)
virtualinherited

Sets the action command for this interactor.

The action command is meant to be a semi-unique string you can use to identify the interactor when events occur. For example, for buttons, the default action command is the button's text, but you can change it to a different string if you prefer. The main usage of this feature is if you want to use the same function as an event listener for many interactors, you can use the action command to help distinguish which interactor generates each event.

◆ setAutoRepaint()

void setAutoRepaint ( bool  autoRepaint)
virtual

Sets whether the canvas will automatically repaint itself whenever you make a change to either the background or foreground layer.

By default this is true. But if you call setAutoRepaint(false), you must manually repaint the canvas to see any changes. This can be desirable if you plan to make a large batch of changes and want to repaint only after all of them are done.

Reimplemented from GDrawingSurface.

◆ setBackground() [1/2]

void setBackground ( int  color)
virtual

Sets the current background color of the interactor as an RGB integer.

See gcolor.h for more detail about colors.

Reimplemented from GDrawingSurface.

◆ setBackground() [2/2]

void setBackground ( string   color)
virtual

Sets the current background color of the interactor as a string.

See gcolor.h for more detail about color strings.

Reimplemented from GDrawingSurface.

◆ setBounds() [1/2]

void setBounds ( double  x,
double  y,
double  width,
double  height 
)
virtualinherited

Sets the size and location of the widget.

In general you should avoid explicitly sizing and positioning widgets in this way; instead, use containers and regions to help you lay out widgets at the proper sizes.

Reimplemented in GLabel.

◆ setBounds() [2/2]

void setBounds ( const GRectangle size)
virtualinherited

Sets the size and location of the widget.

In general you should avoid explicitly sizing and positioning widgets in this way; instead, use containers and regions to help you lay out widgets at the proper sizes.

Reimplemented in GLabel.

◆ setClickListener() [1/2]

void setClickListener ( GEventListener  func)
virtual

Sets a mouse listener on this canvas so that it will be called when the mouse is clicked on the canvas.

Any existing click listener will be replaced.

◆ setClickListener() [2/2]

void setClickListener ( GEventListenerVoid  func)
virtual

Sets a mouse listener on this canvas so that it will be called when the mouse is clicked on the canvas.

Any existing click listener will be replaced.

◆ setColor() [1/2]

void setColor ( int  color)
virtual

Sets the current foreground outline color of the interactor as as RGB integer.

This color will be used to draw the outlines of shapes drawn using the drawXxx and fillXxx methods, as well as being the default color used when calling setPixel or setRGB. See gcolor.h for more detail about color strings. Equivalent to setForeground.

Reimplemented from GDrawingSurface.

◆ setColor() [2/2]

void setColor ( string   color)
virtual

Sets the current foreground outline color of the interactor as a string.

This color will be used to draw the outlines of shapes drawn using the drawXxx and fillXxx methods, as well as being the default color used when calling setPixel or setRGB. See gcolor.h for more detail about color strings. Equivalent to setForeground.

Reimplemented from GDrawingSurface.

◆ setDoubleClickListener() [1/2]

void setDoubleClickListener ( GEventListener  func)
virtual

Sets a mouse listener on this canvas so that it will be called when the mouse is double-clicked on the canvas.

Any existing double-click listener will be replaced.

◆ setDoubleClickListener() [2/2]

void setDoubleClickListener ( GEventListenerVoid  func)
virtual

Sets a mouse listener on this canvas so that it will be called when the mouse is double-clicked on the canvas.

Any existing double-click listener will be replaced.

◆ setEnabled()

void setEnabled ( bool  value)
virtualinherited

Sets whether this interactor is currently enabled.

Most interactors begin as enabled but can be disabled to stop them from being able to be clicked on or otherwise emit events.

◆ setEventListener() [1/2]

void setEventListener ( string   eventName,
GEventListener  func 
)
protectedvirtualinherited

Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown".

Any prior listener for that type of event is replaced.

◆ setEventListener() [2/2]

void setEventListener ( string   eventName,
GEventListenerVoid  func 
)
protectedvirtualinherited

Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown".

Any prior listener for that type of event is replaced.

◆ setEventListeners() [1/2]

void setEventListeners ( std::initializer_list< string >  eventNames,
GEventListener  func 
)
protectedvirtualinherited

Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown".

Any prior listener for those types of event are replaced.

◆ setEventListeners() [2/2]

void setEventListeners ( std::initializer_list< string >  eventNames,
GEventListenerVoid  func 
)
protectedvirtualinherited

Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown".

Any prior listener for those types of event are replaced.

◆ setEventsEnabled()

void setEventsEnabled ( bool  eventsEnabled)
virtualinherited

Sets whether the object is currently allowing itself to fire events.

Initially this is true.

◆ setFillColor() [1/2]

void setFillColor ( int  color)
virtualinherited

Sets the current fill color of the interactor as an RGB integer.

This color will appear in shapes drawn using the fillXxx methods. See gcolor.h for more detail about color strings.

◆ setFillColor() [2/2]

void setFillColor ( string   color)
virtualinherited

Returns the current fill color of the interactor as a string.

This color will appear in shapes drawn using the fillXxx methods. See gcolor.h for more detail about color strings.

◆ setFont() [1/2]

void setFont ( const QFont &  font)
virtual

Returns the current text font of the interactor using a Qt font object.

This font will be used when drawing text strings using drawString.

Reimplemented from GDrawingSurface.

◆ setFont() [2/2]

void setFont ( string   font)
virtual

Sets the current text font of the interactor as a font string.

This font will be used when drawing text strings using drawString. See gfont.h for more detail about font strings.

Reimplemented from GDrawingSurface.

◆ setForeground() [1/2]

void setForeground ( int  color)
virtual

Sets the current foreground outline color of the interactor as an RGB integer.

This color will be used to draw the outlines of shapes drawn using the drawXxx and fillXxx methods, as well as being the default color used when calling setPixel or setRGB. See gcolor.h for more detail about color strings. Equivalent to setColor.

Reimplemented from GDrawingSurface.

◆ setForeground() [2/2]

void setForeground ( string   color)
virtual

Sets the current foreground outline color of the interactor as a string.

This color will be used to draw the outlines of shapes drawn using the drawXxx and fillXxx methods, as well as being the default color used when calling setPixel or setRGB. See gcolor.h for more detail about color strings. Equivalent to setColor.

Reimplemented from GDrawingSurface.

◆ setHeight()

void setHeight ( double  height)
virtualinherited

Sets the onscreen height of the interactor in pixels.

Exceptions
ErrorExceptionif height is negative

Reimplemented in GLabel.

◆ setIcon()

void setIcon ( string   filename,
bool  retainIconSize = true 
)
virtualinherited

Sets the file name of the icon associated with this interactor, or an empty string if no icon has been set.

Not all types of interactors support icons.

Parameters
filenameicon file path to use
retainIconSizetrue if icon should stay at its existing pixel size (default), or false if it should be resized to fit the interactor

Reimplemented in GLabel, and GButton.

◆ setKeyListener() [1/2]

void setKeyListener ( GEventListener  func)
virtual

Sets a key listener on this canvas so that it will be called when any key is pressed or released on the canvas.

Any existing key listener will be replaced.

◆ setKeyListener() [2/2]

void setKeyListener ( GEventListenerVoid  func)
virtual

Sets a key listener on this canvas so that it will be called when any key is pressed or released on the canvas.

Any existing key listener will be replaced.

◆ setLineStyle()

void setLineStyle ( GObject::LineStyle  lineStyle)
virtualinherited

Sets the current line style which will be used to draw outlines of shapes and lines.

The default line style is a solid line (GObject::LINE_SOLID).

◆ setLineWidth()

void setLineWidth ( double  lineWidth)
virtualinherited

Sets the thickness used when drawing outlines of shapes and lines.

The default thickness is 1.

◆ setLocation()

void setLocation ( double  x,
double  y 
)
virtualinherited

Sets the onscreen x/y-coordinate of the top-left corner of the interactor relative to its window.

Generally clients should not call this and should instead use containers and layout regions to position interactors.

Reimplemented in GLabel.

◆ setMinimumSize() [1/2]

void setMinimumSize ( double  width,
double  height 
)
virtualinherited

Sets the minimum size in pixels that this interactor will permit itself to be resized to.

Exceptions
ErrorExceptionif width or height is negative

◆ setMinimumSize() [2/2]

void setMinimumSize ( const GDimension size)
virtualinherited

Sets the minimum size in pixels that this interactor will permit itself to be resized to.

Exceptions
ErrorExceptionif width or height is negative

◆ setMouseListener() [1/2]

void setMouseListener ( GEventListener  func)
virtual

Sets a mouse listener on this canvas so that it will be called when the mouse is moved or clicked on the canvas.

Any existing mouse listener will be replaced.

◆ setMouseListener() [2/2]

void setMouseListener ( GEventListenerVoid  func)
virtual

Sets a mouse listener on this canvas so that it will be called when the mouse is moved or clicked on the canvas.

Any existing mouse listener will be replaced.

◆ setName()

void setName ( string   name)
virtualinherited

Sets a string representing a unique name for this interactor.

The default name string uses the interactor's type and its ID to make a string like "GButton_14", but you can override this by calling setName.

Parameters
namea string such as "GButton_14"

◆ setPixel() [1/3]

void setPixel ( double  x,
double  y,
string   color 
)
virtualinherited

Sets the color of the given x/y pixel in the background layer of the interactor to the given color.

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixels to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixels to submit all of your changes. Equivalent to setRGB.

Exceptions
ErrorExceptionif x/y is out of range

◆ setPixel() [2/3]

void setPixel ( double  x,
double  y,
int  rgb 
)
virtual

Sets the color of the given x/y pixel in the background layer of the canvas to the given RGB value.

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixels to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixels to submit all of your changes.

Exceptions
ErrorExceptionif x/y is out of range or rgb is an invalid color

Implements GDrawingSurface.

◆ setPixel() [3/3]

void setPixel ( double  x,
double  y,
int  r,
int  g,
int  b 
)
virtual

Sets the color of the given x/y pixel in the background layer of the canvas to the given RGB values.

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixels to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixels to submit all of your changes.

Exceptions
ErrorExceptionif x/y is out of range or r,g,b are not between 0-255

Reimplemented from GDrawingSurface.

◆ setPixelARGB() [1/2]

void setPixelARGB ( double  x,
double  y,
int  argb 
)
virtual

Sets the color of the given x/y pixel in the background layer of the canvas to the given ARGB value.

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixelsARGB to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixelsARGB to submit all of your changes.

Exceptions
ErrorExceptionif x/y is out of range or argb is an invalid color

Implements GDrawingSurface.

◆ setPixelARGB() [2/2]

void setPixelARGB ( double  x,
double  y,
int  a,
int  r,
int  g,
int  b 
)
virtual

Sets the color of the given x/y pixel in the background layer of the canvas to the given ARGB values.

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixelsARGB to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixelsARGB to submit all of your changes.

Exceptions
ErrorExceptionif x/y is out of range or a,r,g,b are not between 0-255

Reimplemented from GDrawingSurface.

◆ setPixels()

void setPixels ( const Grid< int > &  pixels)
virtual

Sets the color of the all pixels in the background layer of the canvas to the given RGB values, using rows as y-values and columns as x-values.

Any existing background layer pixels will be replaced. If the given grid is not the same size as this canvas, the canvas will be resized to match the grid. Equivalent to fromGrid.

Implements GDrawingSurface.

◆ setPixelsARGB()

void setPixelsARGB ( const Grid< int > &  pixelsARGB)
virtual

Sets the color of the all pixels in the background layer of the canvas to the given ARGB values, using rows as y-values and columns as x-values.

Any existing background layer pixels will be replaced. If the given grid is not the same size as this canvas, the canvas will be resized to match the grid.

Implements GDrawingSurface.

◆ setPreferredHeight()

void setPreferredHeight ( double  height)
virtualinherited

Sets the height in pixels that this interactor would prefer to be.

Normally clients do not need to call this method; the interactor can figure out its own preferred size. But calling it can help you to hint to the container/layout system if you want a given interactor to "prefer" to make itself larger or smaller for the purposes of your particular program.

◆ setPreferredSize() [1/2]

void setPreferredSize ( double  width,
double  height 
)
virtualinherited

Sets the width and height in pixels that this interactor would prefer to be.

Normally clients do not need to call this method; the interactor can figure out its own preferred size. But calling it can help you to hint to the container/layout system if you want a given interactor to "prefer" to make itself larger or smaller for the purposes of your particular program.

◆ setPreferredSize() [2/2]

void setPreferredSize ( const GDimension size)
virtualinherited

Sets the size in pixels that this interactor would prefer to be.

Normally clients do not need to call this method; the interactor can figure out its own preferred size.

◆ setPreferredWidth()

void setPreferredWidth ( double  width)
virtualinherited

Sets the width in pixels that this interactor would prefer to be.

Normally clients do not need to call this method; the interactor can figure out its own preferred size.

◆ setRepaintImmediately()

void setRepaintImmediately ( bool  autoRepaint)
virtualinherited

Sets whether the interactor should repaint itself automatically whenever any change is made to its graphical data.

By default this is true. But if you call setAutoRepaint(false), you must manually repaint the interactor to see any changes. This can be desirable if you plan to make a large batch of changes and want to repaint only after all of them are done. Equivalent to setAutoRepaint.

◆ setRGB() [1/3]

void setRGB ( double  x,
double  y,
int  rgb 
)
virtualinherited

Sets the color of the given x/y pixel in the background layer of the interactor to the given RGB values.

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixels to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixels to submit all of your changes. Equivalent to setPixel.

Exceptions
ErrorExceptionif x/y is out of range or rgb is an invalid color

◆ setRGB() [2/3]

void setRGB ( double  x,
double  y,
int  r,
int  g,
int  b 
)
virtualinherited

Sets the color of the given x/y pixel in the background layer of the interactor to the given RGB values.

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixels to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixels to submit all of your changes. Equivalent to setPixel.

Exceptions
ErrorExceptionif x/y is out of range or r,g,b are not between 0-255

◆ setRGB() [3/3]

void setRGB ( double  x,
double  y,
string   color 
)
virtualinherited

Sets the color of the given x/y pixel in the background layer of the interactor to the given color.

Note that if you are planning to set many pixels in the background and want maximum performance, you should instead call getPixels to extract all pixels into a Grid, then manipulate all desired pixels in that Grid, then call setPixels to submit all of your changes. Equivalent to setPixel.

Exceptions
ErrorExceptionif x/y is out of range

◆ setSize() [1/2]

void setSize ( double  width,
double  height 
)
virtualinherited

Sets the onscreen width and height of the interactor in pixels.

Exceptions
ErrorExceptionif width or height is negative

Reimplemented in GLabel.

◆ setSize() [2/2]

void setSize ( const GDimension size)
virtualinherited

Sets the onscreen width and height of the interactor in pixels.

Exceptions
ErrorExceptionif width or height is negative

Reimplemented in GLabel.

◆ setTooltip()

void setTooltip ( string   tooltipText)
virtualinherited

Sets a "tooltip" that will appear if the user hovers their mouse over the interactor.

Set an empty string to clear the tooltip.

◆ setVisible()

void setVisible ( bool  visible)
virtualinherited

Returns true if the interactor is visible on the screen.

Interactors will not be visible until they are added to an onscreen window or container. If you call setVisible on an interactor that is not in any onscreen container, it will have no effect.

Reimplemented in GLabel.

◆ setWidth()

void setWidth ( double  width)
virtualinherited

Sets the onscreen width of the interactor in pixels.

Exceptions
ErrorExceptionif width is negative

Reimplemented in GLabel.

◆ setX()

void setX ( double  x)
virtualinherited

Sets the onscreen x-coordinate of the top-left corner of the interactor relative to its window.

Generally clients should not call this and should instead use containers and layout regions to position interactors.

Reimplemented in GLabel.

◆ setY()

void setY ( double  y)
virtualinherited

Sets the onscreen y-coordinate of the top-left corner of the interactor relative to its window.

Generally clients should not call this and should instead use containers and layout regions to position interactors.

Reimplemented in GLabel.

◆ toGImage()

GImage * toGImage ( ) const
virtual

Converts the pixels of the canvas into a GImage object.

◆ toGrid() [1/2]

Grid< int > toGrid ( ) const
virtual

Converts this canvas's pixel data into a grid of RGB pixels.

The grid's first index is a row or y-index, and its second index is the column or x-index. So for example, grid[y][x] returns the RGB int value at that pixel. In this version of the method, the grid is returned. Equivalent to getPixels.

◆ toGrid() [2/2]

void toGrid ( Grid< int > &  grid) const
virtual

Converts this canvas's pixel data into a grid of RGB pixels.

The grid's first index is a row or y-index, and its second index is the column or x-index. So for example, grid[y][x] returns the RGB int value at that pixel. In this version of the method, the grid is filled by reference. Equivalent to getPixels.

◆ toString()

string toString ( ) const
virtualinherited

Returns a string representation of this observable object's state.

Primarily used for debugging purposes.

Member Data Documentation

◆ _autoRepaint

bool _autoRepaint
protectedinherited

◆ _backgroundColor

string _backgroundColor
protectedinherited

◆ _backgroundColorInt

int _backgroundColorInt
protectedinherited

◆ _color

string _color
protectedinherited

◆ _colorInt

int _colorInt
protectedinherited

◆ _fillColor

string _fillColor
protectedinherited

◆ _fillColorInt

int _fillColorInt
protectedinherited

◆ _font

string _font
protectedinherited

◆ _forwardTarget

GDrawingSurface* _forwardTarget
protectedinherited

◆ _lineStyle

GObject::LineStyle _lineStyle
protectedinherited

◆ _lineWidth

double _lineWidth
protectedinherited

◆ WIDTH_HEIGHT_MAX

const int WIDTH_HEIGHT_MAX = 65535
static

Largest value that an image's width and/or height can have.

Error will be thrown if you try to make/resize an image larger than this.