StanfordCPPLib
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GObject Class Referenceabstract

This class is the common superclass of all graphical objects that can be displayed on a graphical window. More...

#include "gobjects.h"

Inheritance diagram for GObject:
GArc GCompound GImage GLine GOval GPolygon GRect GText

Public Types

enum  LineStyle { LINE_NONE, LINE_SOLID, LINE_DASH, LINE_DOT, LINE_DASH_DOT, LINE_DASH_DOT_DOT }
 Styles that can be used for the outline around various shapes. More...
 

Public Member Functions

~GObject()
 Frees the storage for the object. More...
 
bool contains(double x, double y) const
 Returns true if the specified point is inside the object. More...
 
bool contains(const GPoint &pt) const
 Returns true if the specified point is inside the object. More...
 
GPoint getBottomRightLocation() const
 Returns the x/y coordinates of the bottom/right corner of the object. More...
 
double getBottomY() const
 Returns the y-coordinate of the bottom of the object. More...
 
GRectangle getBounds() const
 Returns the bounding box of this object, which is defined to be the smallest rectangle that covers everything drawn by the figure. More...
 
GPoint getCenterLocation() const
 Returns the x/y-coordinates of the center of the object. More...
 
double getCenterX() const
 Returns the x-coordinate of the center of the object. More...
 
double getCenterY() const
 Returns the y-coordinate of the center of the object. More...
 
string getColor() const
 Returns the color used to display this object. More...
 
string getFillColor() const
 Returns the color used to display the filled region of this object. More...
 
double getHeight() const
 Returns the height of this object, which is the same as the height of its bounding box. More...
 
LineStyle getLineStyle() const
 Returns the object's style such as solid or dashed. More...
 
double getLineWidth() const
 Returns the width of the line used to draw this object. More...
 
GPoint getLocation() const
 Returns the location of the top-left corner of object. More...
 
double getOpacity() const
 Returns how opaque (non-transparent) this object will appear from 0.0 (completely transparent) to 1.0 (completely opaque, default). More...
 
GCompoundgetParent() const
 Returns a pointer to the GCompound that contains this object. More...
 
double getRightX() const
 Returns the x-coordinate of the right side of the object. More...
 
GDimension getSize() const
 Returns the size of the object as a GDimension. More...
 
string getType() const =0
 Returns the type of the object as a string, such as "GOval" or "GRect". More...
 
double getWidth() const
 Returns the width of this object, which is equal to the width of the bounding box. More...
 
double getX() const
 Returns the leftmost x-coordinate of the object. More...
 
double getY() const
 Returns the topmost y-coordinate of the object. More...
 
bool isFilled() const
 Returns true if the object is filled with color. More...
 
bool isTransformed() const
 Returns true if this object has been transformed by calling methods such as rotate() or scale() on it. More...
 
bool isVisible() const
 Returns true if this object is visible on screen. More...
 
void move(double dx, double dy)
 Moves the object on the screen using the displacements dx and dy. More...
 
void repaint()
 Instructs the object to redraw itself on screen. More...
 
void resetTransform()
 Undoes any previous scale/rotate transformations on this object. More...
 
void rotate(double theta)
 Transforms the object by rotating it theta degrees counterclockwise around its origin. More...
 
void scale(double sf)
 Scales the object by the specified scale factor. More...
 
void scale(double sx, double sy)
 Scales the object by the specified scale factors. More...
 
void sendBackward()
 Moves this object one step toward the back in the z dimension. More...
 
void sendForward()
 Moves this object one step toward the front in the z dimension. More...
 
void sendToBack()
 Moves this object to the back of the display in the z dimension. More...
 
void sendToFront()
 Moves this object to the front of the display in the z dimension. More...
 
void setBottomRightLocation(double x, double y)
 Sets the location of the bottom/right of this object. More...
 
void setBottomRightLocation(const GPoint &pt)
 Sets the location of the bottom/right of this object. More...
 
void setBottomY(double y)
 Sets the location of the bottom y-coordinate of this object. More...
 
void setBounds(double x, double y, double width, double height)
 Changes the bounds of this object to the specified values. More...
 
void setBounds(const GRectangle &size)
 Changes the bounds of this object to the specified rectangle. More...
 
void setCenterLocation(double x, double y)
 Sets the location of the center of this object. More...
 
void setCenterLocation(const GPoint &pt)
 Sets the location of the center of this object. More...
 
void setCenterX(double x)
 Sets the x-coordinate of the center of this object. More...
 
void setCenterY(double y)
 Sets the y-coordinate of the center of this object. More...
 
void setColor(int r, int g, int b)
 Sets the color used to display this object. More...
 
void setColor(int rgb)
 Sets the color used to display this object. More...
 
void setColor(string color)
 Sets the color used to display this object. More...
 
void setFillColor(int r, int g, int b)
 Sets the color used to display the filled region of this object, if any. More...
 
void setFillColor(int rgb)
 Sets the color used to display the filled region of this object, if any. More...
 
void setFillColor(string color)
 Sets the color used to display the filled region of this object, if any. More...
 
void setFilled(bool flag)
 Sets the fill status for the object, where false is outlined and true is filled. More...
 
void setFont(const QFont &font)
 Changes the font used to display the object as specified by the given Qt font. More...
 
void setFont(string font)
 Changes the font used to display the object as specified by the string font, which has the following format: More...
 
void setForeground(int r, int g, int b)
 Sets the color used to display this object. More...
 
void setForeground(int rgb)
 Sets the color used to display this object. More...
 
void setForeground(string color)
 Sets the color used to display this object. More...
 
void setHeight(double height)
 Changes the height of this object to the specified height without changing its width. More...
 
void setLineStyle(LineStyle lineStyle)
 Sets the object's style such as solid (GObject::LINE_SOLID) or dashed (GObject::LINE_DASH). More...
 
void setLineWidth(double lineWidth)
 Sets the width of the line used to draw this object. More...
 
void setLocation(double x, double y)
 Sets the location of the top-left corner of this object to the specified coordinates. More...
 
void setLocation(const GPoint &pt)
 Sets the location of the top-left corner of this object to the specified point. More...
 
void setOpacity(double opacity)
 Sets how opaque (non-transparent) this object will appear from 0.0 (completely transparent) to 1.0 (completely opaque, default). More...
 
void setRightX(double x)
 Sets the location of the rightmost x-coordinate of this object. More...
 
void setSize(double width, double height)
 Changes the size of this object to the specified width and height. More...
 
void setSize(const GDimension &size)
 Changes the size of this object to the specified width and height. More...
 
void setVisible(bool flag)
 Sets whether this object is visible. More...
 
void setWidth(double width)
 Changes the width of this object to the specified width without changing its height. More...
 
void setX(double x)
 Sets the x location of the left side of this object. More...
 
void setY(double y)
 Sets the y location of the top of this object. More...
 
string toString() const
 Returns a printable representation of the object. More...
 

Static Public Member Functions

static bool isAntiAliasing()
 Returns whether we should globally anti-alias graphical objects. More...
 
static void setAntiAliasing(bool value)
 Globally turns on/off the anti-aliasing feature that smooths out the edges of onscreen shapes. More...
 

Protected Member Functions

string toStringExtra() const
 Returns a string containing any extra unique information about this type of graphical object. More...
 

Protected Attributes

QBrush _brush
 
string _color
 
int _colorInt
 
string _fillColor
 
int _fillColorInt
 
bool _fillFlag
 
string _font
 
double _height
 
LineStyle _lineStyle
 
double _lineWidth
 
double _opacity
 
GCompound_parent
 
QPen _pen
 
QTransform _transform
 
bool _transformed
 
bool _visible
 
double _width
 
double _x
 
double _y
 

Detailed Description

This class is the common superclass of all graphical objects that can be displayed on a graphical window.

The class GObject itself is an abstract class, which means that you are not allowed to construct a GObject directly but must instead construct one of the concrete subclasses.

Most methods used for graphics take a pointer to a

rather than the

itself. Applications that use

pointers therefore use the arrow operator (

->

) to apply methods to the object pointer. For examples illustrating the use of the

class, see the descriptions of the individual subclasses.

Member Enumeration Documentation

◆ LineStyle

enum LineStyle

Styles that can be used for the outline around various shapes.

Call setLineStyle on a GObject and pass one of these values.

Enumerator
LINE_NONE 
LINE_SOLID 
LINE_DASH 
LINE_DOT 
LINE_DASH_DOT 
LINE_DASH_DOT_DOT 

Constructor & Destructor Documentation

◆ ~GObject()

~GObject ( )
virtual

Frees the storage for the object.

Member Function Documentation

◆ contains() [1/2]

bool contains ( double  x,
double  y 
) const
virtual

Returns true if the specified point is inside the object.

Reimplemented in GRoundRect, GPolygon, GOval, GLine, GCompound, and GArc.

◆ contains() [2/2]

bool contains ( const GPoint pt) const
virtual

Returns true if the specified point is inside the object.

◆ getBottomRightLocation()

GPoint getBottomRightLocation ( ) const
virtual

Returns the x/y coordinates of the bottom/right corner of the object.

◆ getBottomY()

double getBottomY ( ) const
virtual

Returns the y-coordinate of the bottom of the object.

Equivalent to the top y-coordinate plus the object's height.

◆ getBounds()

GRectangle getBounds ( ) const
virtual

Returns the bounding box of this object, which is defined to be the smallest rectangle that covers everything drawn by the figure.

The coordinates of this rectangle do not necessarily match the location returned by getLocation. Given a GText object, for example, getLocation returns the coordinates of the point on the baseline at which the string begins; the getBounds method, by contrast, returns a rectangle that covers the entire window area occupied by the string.

Reimplemented in GText, GPolygon, GLine, GCompound, and GArc.

◆ getCenterLocation()

GPoint getCenterLocation ( ) const
virtual

Returns the x/y-coordinates of the center of the object.

Equivalent to the top/left plus half the object's size.

◆ getCenterX()

double getCenterX ( ) const
virtual

Returns the x-coordinate of the center of the object.

Equivalent to the top/left plus half the object's width.

◆ getCenterY()

double getCenterY ( ) const
virtual

Returns the y-coordinate of the center of the object.

Equivalent to the top/left plus half the object's height.

◆ getColor()

string getColor ( ) const
virtual

Returns the color used to display this object.

This color is always returned as a string in the form "#rrggbb", where rr, gg, and bb are the red, green, and blue components of the color, expressed as two-digit hexadecimal values.

◆ getFillColor()

string getFillColor ( ) const
virtual

Returns the color used to display the filled region of this object.

If none has been set, returns the empty string.

◆ getHeight()

double getHeight ( ) const
virtual

Returns the height of this object, which is the same as the height of its bounding box.

Reimplemented in GPolygon, and GLine.

◆ getLineStyle()

GObject::LineStyle getLineStyle ( ) const
virtual

Returns the object's style such as solid or dashed.

◆ getLineWidth()

double getLineWidth ( ) const
virtual

Returns the width of the line used to draw this object.

Returns
default 1

◆ getLocation()

GPoint getLocation ( ) const
virtual

Returns the location of the top-left corner of object.

◆ getOpacity()

double getOpacity ( ) const
virtual

Returns how opaque (non-transparent) this object will appear from 0.0 (completely transparent) to 1.0 (completely opaque, default).

◆ getParent()

GCompound * getParent ( ) const
virtual

Returns a pointer to the GCompound that contains this object.

Every GWindow is initialized to contain a single GCompound that is aligned with the window. Adding objects to the window adds them to that GCompound, which means that every object you add to the window has a parent. Calling getParent on the top-level GCompound returns nullptr.

◆ getRightX()

double getRightX ( ) const
virtual

Returns the x-coordinate of the right side of the object.

Equivalent to the left x-coordinate plus the object's width.

◆ getSize()

GDimension getSize ( ) const
virtual

Returns the size of the object as a GDimension.

◆ getType()

virtual string getType ( ) const
pure virtual

Returns the type of the object as a string, such as "GOval" or "GRect".

Each GObject subtype must override this method.

Implemented in GText, GRoundRect, GRect, GPolygon, GOval, GLine, GImage, GCompound, and GArc.

◆ getWidth()

double getWidth ( ) const
virtual

Returns the width of this object, which is equal to the width of the bounding box.

Reimplemented in GPolygon, and GLine.

◆ getX()

double getX ( ) const
virtual

Returns the leftmost x-coordinate of the object.

◆ getY()

double getY ( ) const
virtual

Returns the topmost y-coordinate of the object.

◆ isAntiAliasing()

bool isAntiAliasing ( )
static

Returns whether we should globally anti-alias graphical objects.

On by default.

◆ isFilled()

bool isFilled ( ) const
virtual

Returns true if the object is filled with color.

◆ isTransformed()

bool isTransformed ( ) const
virtual

Returns true if this object has been transformed by calling methods such as rotate() or scale() on it.

Certain operations (such as setSize) cannot be performed after a graphical object has been transformed.

◆ isVisible()

bool isVisible ( ) const
virtual

Returns true if this object is visible on screen.

◆ move()

void move ( double  dx,
double  dy 
)
virtual

Moves the object on the screen using the displacements dx and dy.

◆ repaint()

void repaint ( )
virtual

Instructs the object to redraw itself on screen.

Reimplemented in GCompound.

◆ resetTransform()

void resetTransform ( )
virtual

Undoes any previous scale/rotate transformations on this object.

◆ rotate()

void rotate ( double  theta)
virtual

Transforms the object by rotating it theta degrees counterclockwise around its origin.

After calling this method on a graphical object, isTransformed will return true for that object unless you subsequently call resetTransform on it.

◆ scale() [1/2]

void scale ( double  sf)
virtual

Scales the object by the specified scale factor.

This form scales the object by sf in both dimensions, so that invoking gobj->scale(2); doubles the size of the object. After calling this method on a graphical object, isTransformed will return true for that object unless you subsequently call resetTransform on it.

◆ scale() [2/2]

void scale ( double  sx,
double  sy 
)
virtual

Scales the object by the specified scale factors.

For example, gobj->scale(2, 2); doubles the size of the object. This form applies independent scale factors to the x and y dimensions. After calling this method on a graphical object, isTransformed will return true for that object unless you subsequently call resetTransform on it.

◆ sendBackward()

void sendBackward ( )

Moves this object one step toward the back in the z dimension.

If it was already at the back of the stack, nothing happens.

◆ sendForward()

void sendForward ( )

Moves this object one step toward the front in the z dimension.

If it was already at the front of the stack, nothing happens.

◆ sendToBack()

void sendToBack ( )

Moves this object to the back of the display in the z dimension.

By moving it to the back, this object will appear to be behind the other graphical objects on the display and may be obscured by other objects in front.

◆ sendToFront()

void sendToFront ( )

Moves this object to the front of the display in the z dimension.

By moving it to the front, this object will appear to be on top of the other graphical objects on the display and may hide any objects that are further back.

◆ setAntiAliasing()

void setAntiAliasing ( bool  value)
static

Globally turns on/off the anti-aliasing feature that smooths out the edges of onscreen shapes.

On by default. Does not repaint any onscreen objects when called; you must do this yourself.

◆ setBottomRightLocation() [1/2]

void setBottomRightLocation ( double  x,
double  y 
)
virtual

Sets the location of the bottom/right of this object.

◆ setBottomRightLocation() [2/2]

void setBottomRightLocation ( const GPoint pt)
virtual

Sets the location of the bottom/right of this object.

◆ setBottomY()

void setBottomY ( double  y)
virtual

Sets the location of the bottom y-coordinate of this object.

◆ setBounds() [1/2]

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

Changes the bounds of this object to the specified values.

◆ setBounds() [2/2]

void setBounds ( const GRectangle size)
virtual

Changes the bounds of this object to the specified rectangle.

◆ setCenterLocation() [1/2]

void setCenterLocation ( double  x,
double  y 
)
virtual

Sets the location of the center of this object.

◆ setCenterLocation() [2/2]

void setCenterLocation ( const GPoint pt)
virtual

Sets the location of the center of this object.

◆ setCenterX()

void setCenterX ( double  x)
virtual

Sets the x-coordinate of the center of this object.

◆ setCenterY()

void setCenterY ( double  y)
virtual

Sets the y-coordinate of the center of this object.

◆ setColor() [1/3]

void setColor ( int  r,
int  g,
int  b 
)
virtual

Sets the color used to display this object.

See gcolor.h for more detail about how to specify colors.

Equivalent to setForeground.

Parameters
rredness from 0-255
ggreenness from 0-255
bblueness from 0-255

◆ setColor() [2/3]

void setColor ( int  rgb)
virtual

Sets the color used to display this object.

See gcolor.h for more detail about how to specify colors.

Equivalent to setForeground.

Parameters
rgban RGB integer value such as 0x7700ff

◆ setColor() [3/3]

void setColor ( string   color)
virtual

Sets the color used to display this object.

See gcolor.h for more detail about how to specify colors.

Equivalent to setForeground.

a color string such as "#7700ff" or "purple"

◆ setFillColor() [1/3]

void setFillColor ( int  r,
int  g,
int  b 
)
virtual

Sets the color used to display the filled region of this object, if any.

As a side effect, sets this object to be filled (setFilled(true)). See gcolor.h for more detail about how to specify colors. If an empty string is passed, sets filled to false.

Parameters
rredness from 0-255
ggreenness from 0-255
bblueness from 0-255

◆ setFillColor() [2/3]

void setFillColor ( int  rgb)
virtual

Sets the color used to display the filled region of this object, if any.

As a side effect, sets this object to be filled (setFilled(true)). See gcolor.h for more detail about how to specify colors.

Parameters
rgban RGB integer value such as 0x7700ff

◆ setFillColor() [3/3]

void setFillColor ( string   color)
virtual

Sets the color used to display the filled region of this object, if any.

As a side effect, sets this object to be filled (setFilled(true)). See gcolor.h for more detail about how to specify colors. If an empty string is passed, sets filled to false.

a color string such as "#7700ff" or "purple"

◆ setFilled()

void setFilled ( bool  flag)
virtual

Sets the fill status for the object, where false is outlined and true is filled.

◆ setFont() [1/2]

void setFont ( const QFont &  font)
virtual

Changes the font used to display the object as specified by the given Qt font.

See gfont.h for more detail about how to specify fonts.

Reimplemented in GText.

◆ setFont() [2/2]

void setFont ( string   font)
virtual

Changes the font used to display the object as specified by the string font, which has the following format:

"family-style-size"

where both style and size are optional. If any of these elements are missing or specified as an asterisk, the existing value is retained. See gfont.h for more detail about how to specify fonts.

Reimplemented in GText.

◆ setForeground() [1/3]

void setForeground ( int  r,
int  g,
int  b 
)
virtual

Sets the color used to display this object.

See gcolor.h for more detail about how to specify colors.

Equivalent to setColor.

Parameters
rredness from 0-255
ggreenness from 0-255
bblueness from 0-255

◆ setForeground() [2/3]

void setForeground ( int  rgb)
virtual

Sets the color used to display this object.

See gcolor.h for more detail about how to specify colors.

Equivalent to setColor.

Parameters
rgban RGB integer value such as 0x7700ff

◆ setForeground() [3/3]

void setForeground ( string   color)
virtual

Sets the color used to display this object.

See gcolor.h for more detail about how to specify colors.

Equivalent to setColor.

a color string such as "#7700ff" or "purple"

◆ setHeight()

void setHeight ( double  height)
virtual

Changes the height of this object to the specified height without changing its width.

◆ setLineStyle()

void setLineStyle ( GObject::LineStyle  lineStyle)
virtual

Sets the object's style such as solid (GObject::LINE_SOLID) or dashed (GObject::LINE_DASH).

◆ setLineWidth()

void setLineWidth ( double  lineWidth)
virtual

Sets the width of the line used to draw this object.

The default line width is 1.

◆ setLocation() [1/2]

void setLocation ( double  x,
double  y 
)
virtual

Sets the location of the top-left corner of this object to the specified coordinates.

◆ setLocation() [2/2]

void setLocation ( const GPoint pt)
virtual

Sets the location of the top-left corner of this object to the specified point.

◆ setOpacity()

void setOpacity ( double  opacity)
virtual

Sets how opaque (non-transparent) this object will appear from 0.0 (completely transparent) to 1.0 (completely opaque, default).

Exceptions
ErrorExceptionif opacity is out of range [0.0, 1.0]

◆ setRightX()

void setRightX ( double  x)
virtual

Sets the location of the rightmost x-coordinate of this object.

◆ setSize() [1/2]

void setSize ( double  width,
double  height 
)
virtual

Changes the size of this object to the specified width and height.

◆ setSize() [2/2]

void setSize ( const GDimension size)
virtual

Changes the size of this object to the specified width and height.

◆ setVisible()

void setVisible ( bool  flag)
virtual

Sets whether this object is visible.

Graphical objects are initially visible when created.

◆ setWidth()

void setWidth ( double  width)
virtual

Changes the width of this object to the specified width without changing its height.

◆ setX()

void setX ( double  x)
virtual

Sets the x location of the left side of this object.

◆ setY()

void setY ( double  y)
virtual

Sets the y location of the top of this object.

◆ toString()

string toString ( ) const
virtual

Returns a printable representation of the object.

Reimplemented in GCompound.

◆ toStringExtra()

string toStringExtra ( ) const
protectedvirtual

Returns a string containing any extra unique information about this type of graphical object.

Reimplemented in GText, GRoundRect, GPolygon, GLine, GImage, and GArc.

Friends And Related Function Documentation

◆ GArc

friend class GArc
friend

◆ GCompound

friend class GCompound
friend

◆ GImage

friend class GImage
friend

◆ GInteractor

friend class GInteractor
friend

◆ GLine

friend class GLine
friend

◆ GOval

friend class GOval
friend

◆ GPolygon

friend class GPolygon
friend

◆ GRect

friend class GRect
friend

◆ GRoundRect

friend class GRoundRect
friend

◆ GText

friend class GText
friend

Member Data Documentation

◆ _brush

QBrush _brush
protected

◆ _color

string _color
protected

◆ _colorInt

int _colorInt
protected

◆ _fillColor

string _fillColor
protected

◆ _fillColorInt

int _fillColorInt
protected

◆ _fillFlag

bool _fillFlag
protected

◆ _font

string _font
protected

◆ _height

double _height
protected

◆ _lineStyle

LineStyle _lineStyle
protected

◆ _lineWidth

double _lineWidth
protected

◆ _opacity

double _opacity
protected

◆ _parent

GCompound* _parent
protected

◆ _pen

QPen _pen
protected

◆ _transform

QTransform _transform
protected

◆ _transformed

bool _transformed
protected

◆ _visible

bool _visible
protected

◆ _width

double _width
protected

◆ _x

double _x
protected

◆ _y

double _y
protected