The SimpleCxxLib package


#include "gobjects.h"

class GArc : public GObject

This graphical object subclass represents an elliptical arc. The arc is specified by the following parameters:

All angles in a GArc description are measured in degrees moving counterclockwise from the +x axis. Negative values for either start or sweep indicate motion in a clockwise direction.

The following diagram illustrates the interpretation of these parameters for the arc shown in red:

GArcGeometry
Constructor
GArc(width, height, start, sweep)
GArc(x, y, width, height, start, sweep) 
Creates a new GArc object consisting of an elliptical arc.
Methods
getEndPoint() Returns the point at which the arc ends.
getFillColor() Returns the color used to display the filled region of this arc.
getFrameRectangle() Returns the boundaries of the rectangle used to frame the arc.
getStartAngle() Returns the starting angle for this GArc object.
getStartPoint() Returns the point at which the arc starts.
getSweepAngle() Returns the sweep angle for this GArc object.
isFilled() Returns true if the arc is filled.
setFillColor(color) Sets the color used to display the filled region of this arc.
setFilled(flag) Sets the fill status for the arc, where false is outlined and true is filled.
setFrameRectangle(rect)
setFrameRectangle(x, y, width, height) 
Changes the boundaries of the rectangle used to frame the arc.
setStartAngle(start) Sets the starting angle for this GArc object.
setSweepAngle(start) Sets the sweep angle for this GArc object.

Constructor detail


GArc(double width, double height, double start, double sweep);
GArc(double x, double y, double width, double height, double start, double sweep);
Creates a new GArc object consisting of an elliptical arc. The first form creates a GArc whose origin is the point (0, 0); the second form positions the GArc at the point (x, y).

The following screenshots show several examples of how the GArc constructor interprets the start and sweep parameters:

GArcExamples

In the code fragments underneath each of these diagrams, r is the radius of the circular arc, and cx and cy are the coordinates of the center or the window.

Usage:

GArc *arc = new GArc(width, height, start, sweep);
GArc *arc = new GArc(x, y, width, height, start, sweep);

Method detail


void setStartAngle(double start);
Sets the starting angle for this GArc object.

Usage:

arc->setStartAngle(start);

double getStartAngle() const;
Returns the starting angle for this GArc object.

Usage:

double angle = arc->getStartAngle();

void setSweepAngle(double start);
Sets the sweep angle for this GArc object.

Usage:

arc->setSweepAngle(start);

double getSweepAngle() const;
Returns the sweep angle for this GArc object.

Usage:

double angle = arc->getSweepAngle();

GPoint getStartPoint() const;
Returns the point at which the arc starts.

Usage:

GPoint pt = arc->getStartPoint();

GPoint getEndPoint() const;
Returns the point at which the arc ends.

Usage:

GPoint pt = arc->getEndPoint();

void setFrameRectangle(const GRectangle & rect);
void setFrameRectangle(double x, double y, double width, double height);
Changes the boundaries of the rectangle used to frame the arc.

Usage:

arc->setFrameRectangle(rect);
arc->setFrameRectangle(x, y, width, height);

GRectangle getFrameRectangle() const;
Returns the boundaries of the rectangle used to frame the arc.

Usage:

GRectangle rect = arc->getFrameRectangle();

void setFilled(bool flag);
Sets the fill status for the arc, where false is outlined and true is filled. If a GArc is unfilled, the figure consists only of the arc itself. If a GArc is filled, the figure consists of the pie-shaped wedge formed by connecting the endpoints of the arc to the center. As an example, the following program draws a 270-degree arc starting at 45 degrees, filled in yellow, much like the character in the PacMan video game:
   int main() {
      GWindow gw;
      cout << "This program draws the PacMan character." << endl;
      double cx = gw.getWidth() / 2;
      double cy = gw.getHeight() / 2;
      double r = 25;
      GArc *pacman = new GArc(cx - r, cy - r, 2 * r, 2 * r, 45, 270);
      pacman->setFilled(true);
      pacman->setFillColor("YELLOW");
      gw.add(pacman);
      return 0;
   }

The program results in the following picture:

PacMan

Usage:

arc->setFilled(flag);

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

Usage:

if (arc->isFilled()) ...

void setFillColor(string color);
void setFillColor(int rgb);
Sets the color used to display the filled region of this arc. Colors are specified as strings as described in the notes for the setColor method.

Usage:

arc->setFillColor(color);

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

Usage:

string color = arc->getFillColor();