gwindow.h

This interface defines an abstract type representing a graphics window.
Type
GWindow This type represents a graphics window that supports simple graphics.
Functions
newGWindow(width, height) Creates and displays a graphics window with the specified dimensions.
closeGWindow(gw) Deletes the window from the screen.
requestFocus(gw) Asks the system to assign the keyboard focus to the window, which brings it to the top and ensures that key events are delivered to the window.
clear(gw) Clears the contents of the window.
setVisible(gw, flag) Determines whether the window is visible on the screen.
isVisible(gw) Tests whether the window is visible.
drawLine(gw, x0, y0, x1, y1) Draws a line connecting the specified points.
drawPolarLine(gw, x, y, r, theta) Draws a line of length r in the direction theta from the initial point.
drawOval(gw, x, y, width, height) Draws the frame of a oval with the specified bounds.
fillOval(gw, x, y, width, height) Fills the frame of a oval with the specified bounds.
drawRect(gw, x, y, width, height) Draws the frame of a rectangle with the specified bounds.
fillRect(gw, x, y, width, height) Fills the frame of a rectangle with the specified bounds.
setColor(gw, color) Sets the color used for drawing.
getColor(gw) Returns the current color as a string in the form "#rrggbb".
getWidth(gw) Returns the width of the graphics window in pixels.
getHeight(gw) Returns the height of the graphics window in pixels.
repaint(gw) Schedule a repaint on the graphics window.
setWindowTitle(gw, title) Sets the title of the graphics window.
getWindowTitle(gw) Returns the title of the graphics window.
draw(gw, gobj) Draws the GObject on the background layer.
drawAt(gw, gobj, x, y) Moves the GObject to (x, y) and then draws it on the window.
add(gw, gobj) Adds the GObject to the foreground layer of the window.
addAt(gw, gobj, x, y) Adds the GObject to the foreground layer of the window after moving it to the point (x, y).
addToRegion(gw, gobj, region) Adds the GObject (which must be an interactor or a label) to the control strip specified by region.
remove(gw, gobj) Removes the object from its container or region.
getGObjectAt(gw, x, y) Returns a pointer to the topmost GObject containing the point (x, y), or NULL if no such object exists.
setRegionAlignment(gw, region, align) Sets the alignment of the specified side region as specified by the string align.
pause(milliseconds) Pauses for the indicated number of milliseconds.

Type detail


typedef struct GWindowCDT *GWindow;
This type represents a graphics window that supports simple graphics. Each GWindow consists of two layers. The background layer provides a surface for drawing static pictures that involve no animation. Graphical objects drawn in the background layer are persistent and do not require the client to update the contents of the window. The foreground layer contains graphical objects that are redrawn as necessary.

The GWindow type includes several functions that draw lines, rectangles, and ovals on the background layer without making use of the facilities of the gobjects.h interface. For example, the following program draws a diamond, rectangle, and oval at the center of the window.

   main() {
      double width, height;
      GWindow gw;

      gw = newGWindow(500, 300);
      width = getWidth(gw);
      height = getHeight(gw);
      drawLine(gw, 0, height / 2, width / 2, 0);
      drawLine(gw, width / 2, 0, width, height / 2);
      drawLine(gw, width, height / 2, width / 2, height);
      drawLine(gw, width / 2, height, 0, height / 2);
      setColor(gw, "BLUE");
      fillRect(gw, width / 4, height / 4, width / 2, height / 2);
      setColor(gw, "GRAY");
      fillOval(gw, width / 4, height / 4, width / 2, height / 2);
   }

Function detail


GWindow newGWindow(double width, double height);
Creates and displays a graphics window with the specified dimensions.

Usage:

gw = newGWindow(width, height);

void closeGWindow(GWindow gw);
Deletes the window from the screen.

Usage:

closeGWindow(gw);

void requestFocus(GWindow gw);
Asks the system to assign the keyboard focus to the window, which brings it to the top and ensures that key events are delivered to the window. Clicking in the window automatically requests the focus.

Usage:

requestFocus(gw);

void clear(GWindow gw);
Clears the contents of the window.

Usage:

clear(gw);

void setVisible(GWindow gw, bool flag);
Determines whether the window is visible on the screen.

Usage:

setVisible(gw, flag);

bool isVisible(GWindow gw);
Tests whether the window is visible.

Usage:

if (isVisible(gw)) . . .

void drawLine(GWindow gw, double x0, double y0, double x1, double y1);
Draws a line connecting the specified points.

Usage:

drawLine(gw, x0, y0, x1, y1);

GPoint drawPolarLine(GWindow gw, double x, double y, double r, double theta);
Draws a line of length r in the direction theta from the initial point. The angle theta is measured in degrees counterclockwise from the +x axis. The method returns the end point of the line.

Usage:

pt = drawPolarLine(gw, x, y, r, theta);

void drawOval(GWindow gw, double x, double y, double width, double height);
Draws the frame of a oval with the specified bounds.

Usage:

drawOval(gw, x, y, width, height);

void fillOval(GWindow gw, double x, double y, double width, double height);
Fills the frame of a oval with the specified bounds.

Usage:

fillOval(gw, x, y, width, height);

void drawRect(GWindow gw, double x, double y, double width, double height);
Draws the frame of a rectangle with the specified bounds.

Usage:

drawRect(gw, x, y, width, height);

void fillRect(GWindow gw, double x, double y, double width, double height);
Fills the frame of a rectangle with the specified bounds.

Usage:

fillRect(gw, x, y, width, height);

void setColor(GWindow gw, string color);
Sets the color used for drawing. The color parameter is usually one of the predefined color names from Java: BLACK, BLUE, CYAN, DARK_GRAY, GRAY, GREEN, LIGHT_GRAY, MAGENTA, ORANGE, PINK, RED, WHITE, or YELLOW. The case of the individual letters in the color name is ignored, as are spaces and underscores, so that the Java color DARK_GRAY could be written as "Dark Gray".

Usage:

setColor(gw, color);

string getColor(GWindow gw);
Returns the current color as a string in the form "#rrggbb". In this string, the values rr, gg, and bb are two-digit hexadecimal values representing the red, green, and blue components of the color, respectively.

Usage:

color = getColor(gw);

double getWidth(GWindow gw);
Returns the width of the graphics window in pixels.

Usage:

width = getWidth(gw);

double getHeight(GWindow gw);
Returns the height of the graphics window in pixels.

Usage:

height = getHeight(gw);

void repaint(GWindow gw);
Schedule a repaint on the graphics window.

Usage:

repaint(gw);

void setWindowTitle(GWindow gw, string title);
Sets the title of the graphics window.

Usage:

setWindowTitle(gw, title);

string getWindowTitle(GWindow gw);
Returns the title of the graphics window.

Usage:

title = getWindowTitle(gw);

void draw(GWindow gw, GObject gobj);
Draws the GObject on the background layer.

Usage:

draw(gw, gobj);

void drawAt(GWindow gw, GObject gobj, double x, double y);
Moves the GObject to (x, y) and then draws it on the window.

Usage:

drawAt(gw, gobj, x, y);

void add(GWindow gw, GObject gobj);
Adds the GObject to the foreground layer of the window. Adding a GObject to a GWindow transfers control of the memory for that object from the client to the graphics package. Freeing a GWindow automatically frees any GObjects it contains.

Usage:

add(gw, gobj);

void addAt(GWindow gw, GObject gobj, double x, double y);
Adds the GObject to the foreground layer of the window after moving it to the point (x, y).

Usage:

addAt(gw, gobj, x, y);

void addToRegion(GWindow gw, GObject gobj, string region);
Adds the GObject (which must be an interactor or a label) to the control strip specified by region. The region parameter must be one of the strings "NORTH", "EAST", "SOUTH", or "WEST".

Usage:

addToRegion(gw, gobj, region);

void remove(GWindow gw, GObject gobj);
Removes the object from its container or region.

Usage:

remove(gw, gobj);

GObject getGObjectAt(GWindow gw, double x, double y);
Returns a pointer to the topmost GObject containing the point (x, y), or NULL if no such object exists.

Usage:

gobj = getGObjectAt(gw, x, y);

void setRegionAlignment(GWindow gw, string region, string align);
Sets the alignment of the specified side region as specified by the string align. The region parameter must be one of the strings "NORTH", "EAST", "SOUTH", or "WEST" and the align parameter must be "LEFT", "RIGHT", or "CENTER". By default, side panels use CENTER alignment.

Usage:

setRegionAlignment(gw, region, align);

void pause(double milliseconds);
Pauses for the indicated number of milliseconds. This function is useful for animation where the motion would otherwise be too fast.

Usage:

pause(milliseconds);