Comp 2673, Spring 2002
cs3g - Graphics library information

Starting and Ending

/* call this function to open window and initialize graphics.
   The first two parameters are the size of the window, the 3rd is the
   title you'd like displayed at the top of the window */
void cs3g_begin(int=500, int=500, char * =0);

void cs3g_end();

Graphics attributes

void cs3g_setLineWidth(int);  /* linewidth in number of pixels */
void cs3g_setColor(int);  /* 1 for black, 0 for white */

Points

Points are used to send data to a draw function or to receive data from the mouse.
typedef struct {
    int x, y;
} point;

Graphics primitives (drawing functions)

/* line connecting point p1 to point p2: */
void cs3g_line(point p1, point p2);

/* line from (x1,y1) to (x2,y2): */
void cs3g_lineCoord(int x1, int y1, int x2, int y2);

/* (x1,y1) and (x2, y2) are two opposite corners of rectangle: */
void cs3g_rectangle(int x1, int y1, int x2, int y2);

/* pl is a list of the vertices of the polygon */
void cs3g_polygon(const vector  &pl);

/* like polygon, but first and last are not connected */
void cs3g_polyline(const vector  &pl);

/* (x1, y1) and (x2, y2) define a rectangle that bounds the ellipse: */ 
void cs3g_ellipse(int x1, int y1, int x2, int y2);

/* Text t is written at point (x, y): */
void cs3g_text(int x, int y, char *);

/* Filled rectangle drawn with (x1, y1) and (x2, y2) as opposite corners: */ 
void cs3g_fillRectangle(int x1, int x2, int y1, int y2);

/* (x1, y1) and (x2, y2) define a rectangle that bounds the filled ellipse: */ 
void cs3g_fillEllipse(int x1, int y1, int x2, int y2);

/* pl is the point list, giving the vertices of the filled polygon: */
void cs3g_fillPolygon(vector  pl);

Functions for input:

/* control the keyboard mode (no keyboard input given if keyboard is off) */
void cs3g_keyboardOn();
void cs3g_keyboardOff();

/* Control appearance of output as mouse is moved: */
/* echoType takes the value CURSOR, RUBBER_LINE, or RUBBER_RECT */
void cs3g_setMouseEchoType(echoType e);

/* set the anchor point if echo type is RUBBER_LINE or RUBBER_RECT: */
void cs3g_setMouseEchoRubberAnchor(point); 

/* turn on/off mouse buttons, to turn all of them off, use mask 0, to turn */
/* all on, use LEFT_BUTTON_MASK | MIDDLE_BUTTON_MASK | RIGHT_BUTTON_MASK */
void cs3g_setMouseButtonMask(int mask);

/* wait for input from user, giving up after timeout ticks of the clock.
Use INDEFINITE for no timeout period.  The returned value inputDevice is
either KEYBOARD, MOUSE or NO_DEVICE (the last occurring only if timeout
occurred before input) */
inputDevice cs3g_waitEvent(int timeout);

/* get character entered, use if waitEvent returned KEYBOARD */
char cs3g_getKeyboard();

/* get info on last mouse click.  Buttons are LEFT_BUTTON, MIDDLE_BUTTON,
   and RIGHT_BUTTON */
void cs3g_getMouse(mouse_result &m);
typedef enum {UP, DOWN} buttonStatus;
typedef struct {
    point position;           /* gives position of mouse when event occurred  */
    buttonStatus button_chord[3];  /* tells UP/DOWN position of each button   */
    int button_of_last_transition; /* which button was last clicked/released? */
} mouse_result;