The SimpleCxxLib package


#include "gobjects.h"

class GRect : public GObject

This class represents a graphical object whose appearance consists of a rectangular box. For example, the following code adds a filled, red 200x100 rectangle at the upper left corner of the graphics window:
   int main() {
      GWindow gw;
      cout << "This program draws a red rectangle at (0, 0)." << endl;
      GRect *rect = new GRect(0, 0, 200, 100);
      rect->setFilled(true);
      rect->setColor("RED");
      gw.add(rect);
      return 0;
   }
Constructor
GRect(width, height)
GRect(x, y, width, height) 
Constructs a rectangle with the specified width and height.
Methods
getFillColor() Returns the color used to display the filled region of this rectangle.
isFilled() Returns true if the rectangle is filled.
setBounds(rect)
setBounds(x, y, width, height) 
Changes the bounds of this rectangle to the specified values.
setFillColor(color) Sets the color used to display the filled region of this rectangle.
setFilled(flag) Sets the fill status for the rectangle, where false is outlined and true is filled.
setSize(size)
setSize(width, height) 
Changes the size of this rectangle to the specified width and height.

Constructor detail


GRect(double width, double height);
GRect(double x, double y, double width, double height);
Constructs a rectangle with the specified width and height. The first form is positioned at the origin; the second at the coordinates given by x and y.

Usage:

GRect *rect = new GRect(width, height);
GRect *rect = new GRect(x, y, width, height);

Method detail


void setSize(const GDimension & size);
void setSize(double width, double height);
Changes the size of this rectangle to the specified width and height.

Usage:

rect->setSize(size);
rect->setSize(width, height);

void setBounds(const GRectangle & size);
void setBounds(double x, double y, double width, double height);
Changes the bounds of this rectangle to the specified values.

Usage:

rect->setBounds(rect);
rect->setBounds(x, y, width, height);

void setFilled(bool flag);
Sets the fill status for the rectangle, where false is outlined and true is filled.

Usage:

rect->setFilled(flag);

bool isFilled() const;
Returns true if the rectangle is filled.

Usage:

if (rect->isFilled()) ...

void setFillColor(string color);
void setFillColor(int rgb);
Sets the color used to display the filled region of this rectangle.

Usage:

rect->setFillColor(color);

string getFillColor() const;
Returns the color used to display the filled region of this rectangle. If none has been set, getFillColor returns the empty string.

Usage:

string color = rect->getFillColor();