#include "gobjects.h"

class GObject

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. These subclasses form a hierarchy that looks like this:

GObjectHierarchy
GArc GImage GLabel GLine GOval GRect GPolygon GCompound G3DRect GRoundRect

Most methods used for graphics take a pointer to a GObject rather than the GObject itself. Applications that use GObject pointers therefore use the arrow operator (->) to apply methods to the object pointer. For examples illustrating the use of the GObject class, see the descriptions of the individual subclasses.
Methods
contains(pt)
contains(x, y) 
Returns true if the specified point is inside the object.
getBounds() Returns the bounding box of this object, which is defined to be the smallest rectangle that covers everything drawn by the figure.
getColor() Returns the color used to display this object.
getHeight() Returns the height of this object, which is defined to be the height of the bounding box.
getLocation() Returns the location of this object as a GPoint.
getParent() Returns a pointer to the GCompound that contains this object.
getSize() Returns the size of the object as a GDimension.
getType() Returns the concrete type of the object as a string, as in "GOval" or "GRect".
getWidth() Returns the width of this object, which is defined to be the width of the bounding box.
getX() Returns the x-coordinate of the object.
getY() Returns the y-coordinate of the object.
isVisible() Returns true if this object is visible.
move(dx, dy) Moves the object on the screen using the displacements dx and dy.
sendBackward() Moves this object one step toward the back in the z dimension.
sendForward() Moves this object one step toward the front in the z dimension.
sendToBack() Moves this object to the back of the display in the z dimension.
sendToFront() Moves this object to the front of the display in the z dimension.
setColor(color) Sets the color used to display this object.
setLocation(pt)
setLocation(x, y) 
Sets the location of this object to the specified point.
setVisible(flag) Sets whether this object is visible.
toString() Returns a printable representation of the object.

Method detail


double getX() const;
Returns the x-coordinate of the object.

Usage:

double x = gobj->getX();

double getY() const;
Returns the y-coordinate of the object.

Usage:

double y = gobj->getY();

GPoint getLocation() const;
Returns the location of this object as a GPoint.

Usage:

GPoint pt = gobj->getLocation();

void setLocation(const GPoint & pt);
void setLocation(double x, double y);
Sets the location of this object to the specified point.

Usage:

gobj->setLocation(pt);
gobj->setLocation(x, y);

void move(double dx, double dy);
Moves the object on the screen using the displacements dx and dy.

Usage:

gobj->move(dx, dy);

double getWidth() const;
Returns the width of this object, which is defined to be the width of the bounding box.

Usage:

double width = gobj->getWidth();

double getHeight() const;
Returns the height of this object, which is defined to be the height of the bounding box.

Usage:

double height = gobj->getHeight();

GDimension getSize() const;
Returns the size of the object as a GDimension.

Usage:

GDimension size = gobj->getSize();

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. The coordinates of this rectangle do not necessarily match the location returned by getLocation. Given a GLabel 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.

Usage:

GRectangle rect = gobj->getBounds();

void setColor(string color);
void setColor(int rgb);
Sets the color used to display this object. The color string is usually one of the predefined color names: BLACK, BLUE, CYAN, DARK_GRAY, GRAY, GREEN, LIGHT_GRAY, MAGENTA, ORANGE, PINK, RED, WHITE, and YELLOW. The case of the individual letters in the color name is ignored, as are spaces and underscores, so that the color DARK_GRAY can be written as "Dark Gray".

The color can also be specified as a string in the form "#rrggbb" where rr, gg, and bb are pairs of hexadecimal digits indicating the red, green, and blue components of the color, respectively.

Usage:

gobj->setColor(color);

string getColor() const;
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.

Usage:

string color = gobj->getColor();

void setVisible(bool flag);
Sets whether this object is visible.

Usage:

gobj->setVisible(flag);

bool isVisible() const;
Returns true if this object is visible.

Usage:

if (gobj->isVisible()) ...

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.

Usage:

gobj->sendForward();

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.

Usage:

gobj->sendToFront();

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.

Usage:

gobj->sendBackward();

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.

Usage:

gobj->sendToBack();

bool contains(GPoint pt) const;
bool contains(double x, double y) const;
Returns true if the specified point is inside the object.

Usage:

if (gobj->contains(pt)) ...
if (gobj->contains(x, y)) ...

string getType() const;
Returns the concrete type of the object as a string, as in "GOval" or "GRect".

Usage:

string type = gobj->getType();

string toString() const;
Returns a printable representation of the object.

Usage:

gobj->toString();

GCompound *getParent() const;
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 NULL.

Usage:

GCompound *parent = gobj->getParent();