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"
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() override | |
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() override |
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... | |
GCanvas * | diff(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... | |
GCanvas * | diff(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) override |
Draws the given graphical object onto the background layer of the canvas. More... | |
void | draw(QPainter *painter) override |
Draws this interactor with the given Qt painter object. 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 override |
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 | fillPolygon(std::initializer_list< GPoint > 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... | |
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 override |
Returns the current background color of the interactor as a string. More... | |
int | getBackgroundInt() const override |
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... | |
GContainer * | getContainer() const |
Returns a pointer to the onscreen container holding this interactor. More... | |
GObject * | getElement(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... | |
GObject * | getElementAt(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 override |
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 override |
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 override |
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 override |
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... | |
std::vector< std::vector< int > > | getPixels() const override |
Returns all pixels of the surface as a nested STL vector of vectors, where the first index represents the x value and the second index represents the y value. More... | |
std::vector< std::vector< int > > | getPixelsARGB() const override |
Returns all pixels of the background layer of the canvas as a nested STL vector of vectors, where the first index represents the x value and the second index represents the y value. More... | |
int ** | getPixelsArray() const override |
Returns all pixels of the background layer of the canvas as a heap-allocated 2D array, where the first index represents the x value and the second index represents the y value. More... | |
int ** | getPixelsArrayARGB() const override |
Returns all pixels of the background layer of the canvas as a heap-allocated 2D array, where the first index represents the x value and the second index represents the y value. 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 override |
Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox". More... | |
QWidget* | getWidget() const override |
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 override |
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 | removeActionListener() |
Removes the action listener from this interactor so that it will no longer call it when events occur. More... | |
void | removeAll() |
Removes all graphical objects from the foreground layer of the canvas. More... | |
void | removeClickListener() |
Removes the click listener from this interactor so that it will no longer call it when events occur. More... | |
void | removeDoubleClickListener() |
Removes the double-click listener from this interactor so that it will no longer call it when events occur. More... | |
void | removeKeyListener() |
Removes the key listener from this interactor so that it will no longer call it when key events occur. More... | |
void | removeMouseListener() |
Removes the mouse listener from this interactor so that it will no longer call it when events occur. More... | |
void | repaint() override |
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) override |
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 | setActionListener(GEventListener func) |
Sets an action listener on this interactor so that it will be called when it is interacted with in its primary way. More... | |
void | setActionListener(GEventListenerVoid func) |
Sets an action listener on this interactor so that it will be called when it is interacted with in its primary way. More... | |
void | setAutoRepaint(bool autoRepaint) override |
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) override |
Sets the current background color of the interactor as an RGB integer. More... | |
void | setBackground(string color) override |
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 interactor so that it will be called when the mouse is clicked on it. More... | |
void | setClickListener(GEventListenerVoid func) |
Sets a mouse listener on this interactor so that it will be called when the mouse is clicked on it. More... | |
void | setColor(int color) override |
Sets the current foreground outline color of the interactor as as RGB integer. More... | |
void | setColor(string color) override |
Sets the current foreground outline color of the interactor as a string. More... | |
void | setDoubleClickListener(GEventListener func) |
Sets a mouse listener on this interactor so that it will be called when the mouse is double-clicked on it. More... | |
void | setDoubleClickListener(GEventListenerVoid func) |
Sets a mouse listener on this interactor so that it will be called when the mouse is double-clicked on it. 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) override |
Returns the current text font of the interactor using a Qt font object. More... | |
void | setFont(string font) override |
Sets the current text font of the interactor as a font string. More... | |
void | setForeground(int rgb) override |
Sets the current foreground outline color of the interactor as an RGB integer. More... | |
void | setForeground(string color) override |
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(const QIcon &icon) |
Sets the icon associated with this interactor. More... | |
void | setIcon(const QPixmap &icon) |
Sets the icon associated with this interactor. 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) override |
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) override |
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 interactor so that it will be called when the mouse is moved or clicked on it. More... | |
void | setMouseListener(GEventListenerVoid func) |
Sets a mouse listener on this interactor so that it will be called when the mouse is moved or clicked on it. More... | |
void | setName(string name) |
Sets a string representing a unique name for this interactor. More... | |
void | setPixel(double x, double y, int rgb) override |
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) override |
Sets the color of the given x/y pixel in the background layer of the canvas to the given RGB values. 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 | setPixelARGB(double x, double y, int argb) override |
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) override |
Sets the color of the given x/y pixel in the background layer of the canvas to the given ARGB values. More... | |
void | setPixels(int **pixels, int width=-1, int height=-1) override |
Sets the color of the all pixels in the background layer of the canvas to the given RGB values, where the first index represents the x-coordinate and the second index represents the y-coordinate. More... | |
void | setPixels(const std::vector< std::vector< int >> &pixels) override |
Sets the color of the all pixels in the background layer of the canvas to the given RGB values, where the first index represents the x-coordinate and the second index represents the y-coordinate. More... | |
void | setPixelsARGB(int **pixelsARGB, int width=-1, int height=-1) override |
Sets the color of the all pixels in the background layer of the canvas to the given ARGB values, where the first index represents the x-coordinate and the second index represents the y-coordinate. More... | |
void | setPixelsARGB(const std::vector< std::vector< int >> &pixelsARGB) override |
Sets the color of the all pixels in the background layer of the canvas to the given ARGB values, where the first index represents the x-coordinate and the second index represents the y-coordinate. 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... | |
GImage * | toGImage() const |
Converts the pixels of the canvas into a GImage object. More... | |
string | toString() const |
Returns a string representation of this observable object's state. More... | |
Static Public Member Functions | |
static int | createArgbPixel(int alpha, int red, int green, int blue) |
Creates a single ARGB integer from the given A-R-G-B components from 0-255. More... | |
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 |
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 2D array using getPixels, modify the array, 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.
|
inherited |
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 | ( | string | filename, |
QWidget* | parent = nullptr |
||
) |
Creates a canvas that loads its background layer pixel data from the given image file name.
ErrorException | if the given file does not exist or cannot be read as a valid image file |
GCanvas | ( | std::istream & | filename, |
QWidget* | parent = nullptr |
||
) |
Creates a canvas that loads its background layer pixel data from the given input stream.
ErrorException | if the given stream cannot be read as a valid image file |
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.
ErrorException | if the given width/height ranges are negative |
ErrorException | if the given rgb value is invalid or out of range |
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.
ErrorException | if the given width/height ranges are negative |
ErrorException | if the given rgb value is invalid or out of range |
|
override |
Frees memory allocated internally by the canvas.
|
virtual |
Adds the given interactor to canvas.
ErrorException | if the interactor is null |
|
virtual |
Adds the given interactor to the canvas and moves it to the given x/y location.
ErrorException | if the interactor is null |
|
virtual |
Adds the given interactor to canvas.
|
virtual |
Adds the given interactor to the canvas and moves it to the given x/y location.
|
virtualinherited |
Adds an event listener to be notified when this interactor is clicked or generally interacted with.
|
protectedinherited |
Throws an error if the given x/y values are out of bounds.
|
protectedinherited |
Throws an error if the given rgb value is not a valid color.
|
protectedinherited |
Throws an error if the given width/height values are out of bounds.
|
overridevirtual |
Removes all graphical objects from the canvas foreground layer and wipes the background layer to show the current background color.
Implements GDrawingSurface.
|
protectedvirtualinherited |
Removes all event listeners from this object.
|
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.
|
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.
|
virtualinherited |
Repaints the interactor only if its contents have changed.
|
virtualinherited |
Repaints the given region of the interactor only if its contents have changed.
|
virtualinherited |
Repaints the given region of the interactor only if its contents have changed.
|
virtual |
Returns true if any of the graphical objects in the foreground layer of the canvas touch the given x/y pixel.
|
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.
|
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.
|
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.
ErrorException | if the image passed is null |
|
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.
ErrorException | if the image passed is null |
|
static |
Creates a single ARGB integer from the given A-R-G-B components from 0-255.
ErrorException | if alpha, red, green, or blue is not between 0-255 inclusive |
|
static |
Creates a single RGB integer from the given R-G-B components from 0-255.
ErrorException | if red, green, or blue is not between 0-255 inclusive |
|
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.
|
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.
ErrorException | if the image passed is null |
|
virtualinherited |
Draws the given graphical object onto the background pixel layer of this interactor, moving it to the given x/y location first.
ErrorException | if the object is null |
|
virtualinherited |
Draws the given graphical object onto the background pixel layer of this interactor.
|
virtualinherited |
Draws the given graphical object onto the background pixel layer of this interactor, moving it to the given x/y location first.
|
overridevirtual |
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().
ErrorException | if the object passed is null |
Implements GDrawingSurface.
|
overridevirtual |
Draws this interactor with the given Qt painter object.
Implements GDrawingSurface.
|
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.
|
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.
ErrorException | if the given file is not found or cannot be loaded as a valid image file |
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.
|
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.
|
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.
|
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.
|
virtualinherited |
Colors the given x/y pixel of the background layer of this interactor using the interactor's current color.
|
virtualinherited |
Colors the given x/y pixel of the background layer of this interactor using the given color.
|
virtualinherited |
Colors the given x/y pixel of the background layer of this interactor using the given color.
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
protectedvirtualinherited |
Ensures that we are currently in the Qt GUI thread.
|
virtual |
Returns true if the two given canvases contain exactly the same pixel data.
|
overridevirtualinherited |
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.
|
virtual |
Sets the color of every pixel in the canvas to the given color value.
See gcolor.h for more detail about colors.
ErrorException | if the given rgb value is not a valid color |
|
virtual |
Sets the color of every pixel in the canvas to the given color value.
See gcolor.h for more detail about colors.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
ErrorException | if 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 |
|
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.
ErrorException | if the given x/y/width/height range goes outside the bounds of the image |
|
protectedvirtualinherited |
Sends out the given event to any attached listeners.
|
protectedvirtualinherited |
Creates an event of the given type, then sends it out to any attached listeners.
|
protectedvirtualinherited |
Creates an event of the given type, then sends it out to any attached listeners.
|
protectedvirtualinherited |
Creates an event of the given type, then sends it out to any attached listeners.
|
protectedvirtualinherited |
Creates an event of the given type, then sends it out to any attached listeners.
|
protectedvirtualinherited |
Creates an event of the given type, then sends it out to any attached listeners.
|
protectedvirtualinherited |
Creates an event of the given type, then sends it out to any attached listeners.
|
protectedvirtualinherited |
Creates an event of the given type, then sends it out to any attached listeners.
|
protectedvirtualinherited |
Creates an event of the given type, then sends it out to any attached listeners.
|
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.
|
virtualinherited |
Returns a string representing a hotkey for this interactor, or an empty string if no accelerator has been set.
Reimplemented in GButton.
|
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, GButton, and GCheckBox.
|
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.
|
virtualinherited |
Returns the pixel color data at the given x/y location, retaining alpha-channel transparency in the top 8 bits.
|
overridevirtual |
Returns the current background color of the interactor as a string.
See gcolor.h for more detail about color strings.
Reimplemented from GDrawingSurface.
|
overridevirtual |
Returns the current background color of the interactor as an RGB integer.
See gcolor.h for more detail about colors.
Reimplemented from GDrawingSurface.
|
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.
|
virtualinherited |
Returns a rectangle representing the x/y position and size of this interactor.
|
virtualinherited |
Returns the foreground/text color of the interactor as a string.
Equivalent to getForeground.
|
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.
|
virtualinherited |
Returns the foreground/text color of the interactor as an RGB integer.
Equivalent to getForegroundInt.
|
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.
|
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.
|
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.
ErrorException | if the index is out of range |
|
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.
|
virtual |
Returns the number of graphical objects stored in the foreground layer of the canvas.
|
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 "".
|
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.
|
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.
|
overridevirtual |
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.
|
virtualinherited |
Returns the foreground/text color of the interactor as a string.
Equivalent to getColor.
|
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.
|
virtualinherited |
Returns the foreground/text color of the interactor as an RGB integer.
Equivalent to getColorInt.
|
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.
|
static |
Extracts the green component from 0-255 of the given RGB integer.
The green component comes from bits 8-15 of the integer.
|
virtualinherited |
Returns the current onscreen height of this interactor in pixels.
|
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.
|
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.
|
overridevirtual |
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.
|
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).
|
virtualinherited |
Returns the thickness used when drawing outlines of shapes and lines.
The default thickness is 1.
|
virtualinherited |
Returns an (x, y) point representing the onscreen location of the top-left corner of this interactor within its containing window.
|
virtualinherited |
Returns the minimum height in pixels that this interactor will permit itself to be resized to.
|
virtualinherited |
Returns a GDimension structure representing the minimum size in pixels that this interactor will permit itself to be resized to.
|
virtualinherited |
Returns the minimum width in pixels that this interactor will permit itself to be resized to.
|
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.
|
overridevirtual |
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 2D array, then manipulate all desired pixels in that array, then call setPixels to submit all of your changes.
ErrorException | if the given x/y values are out of bounds. |
Implements GDrawingSurface.
|
overridevirtual |
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 2D array, then manipulate all desired pixels in that array, then call setPixels to submit all of your changes.
ErrorException | if the given x/y values are out of bounds. |
Implements GDrawingSurface.
|
overridevirtual |
Returns all pixels of the surface as a nested STL vector of vectors, where the first index represents the x value and the second index represents the y value.
Implements GDrawingSurface.
|
overridevirtual |
Returns all pixels of the background layer of the canvas as a nested STL vector of vectors, where the first index represents the x value and the second index represents the y value.
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.
|
overridevirtual |
Returns all pixels of the background layer of the canvas as a heap-allocated 2D array, where the first index represents the x value and the second index represents the y value.
So for example, pixels[x][y] returns the RGB int value at that pixel. The caller is responsible for freeing the memory for this array using delete[].
Implements GDrawingSurface.
|
overridevirtual |
Returns all pixels of the background layer of the canvas as a heap-allocated 2D array, where the first index represents the x value and the second index represents the y value.
So for example, pixels[x][y] returns the ARGB int value at that pixel. This differs from getPixelsArray in that it explicitly retains and returns the alpha channel of each pixel in the top 8 bits, allowing for transparency effects. The caller is responsible for freeing the memory for this array using delete[].
Implements GDrawingSurface.
|
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.
|
virtualinherited |
Returns the height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars.
|
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.
|
virtualinherited |
Returns the height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars.
|
static |
Extracts the red component from 0-255 of the given RGB integer.
The red component comes from bits 16-23 of the integer.
|
static |
Extracts the red, green, and blue components from 0-255 of the given RGB integer, filling by reference.
|
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.
ErrorException | if the given x/y values are out of bounds. |
|
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.
ErrorException | if the given x/y values are out of bounds. |
|
virtualinherited |
Returns a GDimension structure storing the current onscreen width and height of this interactor in pixels.
|
overridevirtual |
Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox".
All subclasses of GInteractor must implement this method.
Implements GInteractor.
|
overridevirtual |
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.
|
virtualinherited |
Returns the current onscreen width of this interactor in pixels.
|
virtualinherited |
Returns the x-coordinate of the top-left pixel of this interactor within its onscreen window.
|
virtualinherited |
Returns the y-coordinate of the top-left pixel of this interactor within its onscreen window.
|
protectedvirtualinherited |
Returns true if the observable object has a listener for the given type of event.
|
virtualinherited |
Returns true if the given x/y pixel is within the bounds of this interactor.
|
virtualinherited |
Returns true if the given x/y pixel is within the bounds of this interactor.
|
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.
|
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.
|
protectedvirtualinherited |
Returns true if the observable object has a listener for the given type of event.
See gevent.h for event types and masks.
|
protectedvirtualinherited |
Returns true if the observable object has a listener for the given type of event.
|
protectedvirtualinherited |
Returns true if the observable object has a listener for the given type of event.
|
overridevirtual |
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.
|
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.
|
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.
|
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.
|
virtual |
Reads the canvas's pixel contents from the given image file.
ErrorException | if the given file does not exist or cannot be read as a valid image file |
|
virtual |
Reads the canvas's pixel contents from the given input stream.
ErrorException | if 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. |
ErrorException | if the graphical object is null |
|
virtual |
Removes the given graphical object from the foreground layer of the canvas, if it was present.
|
virtualinherited |
Removes the action listener from this interactor so that it will no longer call it when events occur.
|
virtual |
Removes all graphical objects from the foreground layer of the canvas.
|
virtualinherited |
Removes the click listener from this interactor so that it will no longer call it when events occur.
|
virtualinherited |
Removes the double-click listener from this interactor so that it will no longer call it when events occur.
|
protectedvirtualinherited |
Removes any event listener from this observable object that would respond to the given type of event, such as "click" or "keydown".
|
protectedvirtualinherited |
Removes any event listener from this observable object that would respond to the given types of events, such as "click" or "keydown".
|
virtualinherited |
Removes the key listener from this interactor so that it will no longer call it when key events occur.
|
virtualinherited |
Removes the mouse listener from this interactor so that it will no longer call it when events occur.
|
overridevirtual |
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.
|
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.
|
overridevirtual |
Instructs the canvas to redraw the given region of pixels within both of its layers.
Implements GDrawingSurface.
|
virtualinherited |
Transfers keyboard focus to this interactor.
Reimplemented in GTable.
void resize | ( | double | width, |
double | height, | ||
bool | retain = true |
||
) |
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.
ErrorException | if the given width/height ranges are negative |
|
virtual |
Saves the canvas's contents to the given image file.
ErrorException | if the given file is not writeable. |
|
virtualinherited |
Sets an accelerator hotkey for this interactor, such as "Ctrl-S".
Not all interactor types support accelerators.
accelerator | a hotkey such as "Ctrl-S" |
Reimplemented in GButton.
|
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.
|
virtualinherited |
Sets an action listener on this interactor so that it will be called when it is interacted with in its primary way.
For example, if this interactor is a button, this will fire when it is clicked. Any existing action listener will be replaced.
|
virtualinherited |
Sets an action listener on this interactor so that it will be called when it is interacted with in its primary way.
For example, if this interactor is a button, this will fire when it is clicked. Any existing action listener will be replaced.
|
overridevirtual |
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.
|
overridevirtual |
Sets the current background color of the interactor as an RGB integer.
See gcolor.h for more detail about colors.
Reimplemented from GDrawingSurface.
|
overridevirtual |
Sets the current background color of the interactor as a string.
See gcolor.h for more detail about color strings.
Reimplemented from GDrawingSurface.
|
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.
|
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.
|
virtualinherited |
Sets a mouse listener on this interactor so that it will be called when the mouse is clicked on it.
Any existing click listener will be replaced.
|
virtualinherited |
Sets a mouse listener on this interactor so that it will be called when the mouse is clicked on it.
Any existing click listener will be replaced.
|
overridevirtual |
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.
|
overridevirtual |
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.
|
virtualinherited |
Sets a mouse listener on this interactor so that it will be called when the mouse is double-clicked on it.
Any existing double-click listener will be replaced.
|
virtualinherited |
Sets a mouse listener on this interactor so that it will be called when the mouse is double-clicked on it.
Any existing double-click listener will be replaced.
|
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.
|
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.
|
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.
|
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.
|
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.
|
virtualinherited |
Sets whether the object is currently allowing itself to fire events.
Initially this is true.
|
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.
|
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.
|
overridevirtual |
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.
|
overridevirtual |
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.
|
overridevirtual |
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.
|
overridevirtual |
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.
|
virtualinherited |
Sets the onscreen height of the interactor in pixels.
ErrorException | if height is negative |
Reimplemented in GLabel.
|
virtualinherited |
|
virtualinherited |
|
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.
filename | icon file path to use |
retainIconSize | true if icon should stay at its existing pixel size (default), or false if it should be resized to fit the interactor |
|
overridevirtual |
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.
Reimplemented from GInteractor.
|
overridevirtual |
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.
Reimplemented from GInteractor.
|
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).
|
virtualinherited |
Sets the thickness used when drawing outlines of shapes and lines.
The default thickness is 1.
|
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.
|
virtualinherited |
Sets the minimum size in pixels that this interactor will permit itself to be resized to.
ErrorException | if width or height is negative |
|
virtualinherited |
Sets the minimum size in pixels that this interactor will permit itself to be resized to.
ErrorException | if width or height is negative |
|
virtualinherited |
Sets a mouse listener on this interactor so that it will be called when the mouse is moved or clicked on it.
Any existing mouse listener will be replaced.
Reimplemented in GBrowserPane, and GTextArea.
|
virtualinherited |
Sets a mouse listener on this interactor so that it will be called when the mouse is moved or clicked on it.
Any existing mouse listener will be replaced.
Reimplemented in GBrowserPane, and GTextArea.
|
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.
name | a string such as "GButton_14" |
|
overridevirtual |
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 2D array, then manipulate all desired pixels in that array, then call setPixels to submit all of your changes.
ErrorException | if x/y is out of range or rgb is an invalid color |
Implements GDrawingSurface.
|
overridevirtual |
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 2D array, then manipulate all desired pixels in that array, then call setPixels to submit all of your changes.
ErrorException | if x/y is out of range or r,g,b are not between 0-255 |
Reimplemented from GDrawingSurface.
|
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 nested vector, then manipulate all desired pixels in that vector, then call setPixels to submit all of your changes. Equivalent to setRGB.
ErrorException | if x/y is out of range |
|
overridevirtual |
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 2D array, then manipulate all desired pixels in that array, then call setPixelsARGB to submit all of your changes.
ErrorException | if x/y is out of range or argb is an invalid color |
Implements GDrawingSurface.
|
overridevirtual |
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 2D array, then manipulate all desired pixels in that array, then call setPixelsARGB to submit all of your changes.
ErrorException | if x/y is out of range or a,r,g,b are not between 0-255 |
Reimplemented from GDrawingSurface.
|
overridevirtual |
Sets the color of the all pixels in the background layer of the canvas to the given RGB values, where the first index represents the x-coordinate and the second index represents the y-coordinate.
Any existing background layer pixels will be replaced. If the given array is not the same size as this canvas, the canvas will be resized to match the array.
Implements GDrawingSurface.
|
overridevirtual |
Sets the color of the all pixels in the background layer of the canvas to the given RGB values, where the first index represents the x-coordinate and the second index represents the y-coordinate.
Any existing background layer pixels will be replaced. If the given vector is not the same size as this interactor, the interactor will be resized to match the vector.
Implements GDrawingSurface.
|
overridevirtual |
Sets the color of the all pixels in the background layer of the canvas to the given ARGB values, where the first index represents the x-coordinate and the second index represents the y-coordinate.
Any existing background layer pixels will be replaced. If the given array is not the same size as this canvas, the canvas will be resized to match the array.
Implements GDrawingSurface.
|
overridevirtual |
Sets the color of the all pixels in the background layer of the canvas to the given ARGB values, where the first index represents the x-coordinate and the second index represents the y-coordinate.
Any existing background layer pixels will be replaced. If the given grid is not the same size as this interactor, the interactor will be resized to match the grid.
Implements GDrawingSurface.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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 vector, then manipulate all desired pixels in that vector, then call setPixels to submit all of your changes. Equivalent to setPixel.
ErrorException | if x/y is out of range or rgb is an invalid color |
|
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 vector, then manipulate all desired pixels in that vector, then call setPixels to submit all of your changes. Equivalent to setPixel.
ErrorException | if x/y is out of range or r,g,b are not between 0-255 |
|
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 vector, then manipulate all desired pixels in that vector, then call setPixels to submit all of your changes. Equivalent to setPixel.
ErrorException | if x/y is out of range |
|
virtualinherited |
Sets the onscreen width and height of the interactor in pixels.
ErrorException | if width or height is negative |
Reimplemented in GLabel.
|
virtualinherited |
Sets the onscreen width and height of the interactor in pixels.
ErrorException | if width or height is negative |
Reimplemented in GLabel.
|
virtualinherited |
Sets a "tooltip" that will appear if the user hovers their mouse over the interactor.
Set an empty string to clear the tooltip.
|
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.
|
virtualinherited |
Sets the onscreen width of the interactor in pixels.
ErrorException | if width is negative |
Reimplemented in GLabel.
|
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.
|
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.
|
virtualinherited |
Returns a string representation of this observable object's state.
Primarily used for debugging purposes.
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
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.