gwindow.h
Type | |
This type represents a graphics window that supports simple graphics. | |
Functions | |
Creates and displays a graphics window with the specified dimensions. | |
Deletes the window from the screen. | |
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. | |
Clears the contents of the window. | |
Determines whether the window is visible on the screen. | |
Tests whether the window is visible. | |
Draws a line connecting the specified points. | |
Draws a line of length r in the direction theta from the initial point. | |
Draws the frame of a oval with the specified bounds. | |
Fills the frame of a oval with the specified bounds. | |
Draws the frame of a rectangle with the specified bounds. | |
Fills the frame of a rectangle with the specified bounds. | |
Sets the color used for drawing. | |
Returns the current color as a string in the form "#rrggbb" . | |
Returns the width of the graphics window in pixels. | |
Returns the height of the graphics window in pixels. | |
Schedule a repaint on the graphics window. | |
Sets the title of the graphics window. | |
Returns the title of the graphics window. | |
Draws the GObject on the background layer. | |
Moves the GObject to (x , y ) and then draws it on the window. | |
Adds the GObject to the foreground layer of the window. | |
Adds the GObject to the foreground layer of the window after moving it to the point (x , y ). | |
Adds the GObject (which must be an interactor or a label) to the control strip specified by region . | |
Removes the object from its container or region. | |
Returns a pointer to the topmost GObject containing the point (x , y ), or NULL if no such object exists. | |
Sets the alignment of the specified side region as specified by the string align . | |
Pauses for the indicated number of milliseconds. |
typedef struct GWindowCDT *GWindow;
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); }
GWindow newGWindow(double width, double height);
Usage:
gw = newGWindow(width, height);
void closeGWindow(GWindow gw);
Usage:
closeGWindow(gw);
void requestFocus(GWindow gw);
Usage:
requestFocus(gw);
void clear(GWindow gw);
Usage:
clear(gw);
void setVisible(GWindow gw, bool flag);
Usage:
setVisible(gw, flag);
bool isVisible(GWindow gw);
Usage:
if (isVisible(gw)) . . .
void drawLine(GWindow gw, double x0, double y0, double x1, double y1);
Usage:
drawLine(gw, x0, y0, x1, y1);
GPoint drawPolarLine(GWindow gw, double x, double y, double r, double theta);
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);
Usage:
drawOval(gw, x, y, width, height);
void fillOval(GWindow gw, double x, double y, double width, double height);
Usage:
fillOval(gw, x, y, width, height);
void drawRect(GWindow gw, double x, double y, double width, double height);
Usage:
drawRect(gw, x, y, width, height);
void fillRect(GWindow gw, double x, double y, double width, double height);
Usage:
fillRect(gw, x, y, width, height);
void setColor(GWindow gw, string color);
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 getColorGWindow(GWindow gw);
"#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 = getColorGWindow(gw);
double getWidth(GWindow gw);
Usage:
width = getWidth(gw);
double getHeight(GWindow gw);
Usage:
height = getHeight(gw);
void repaint(GWindow gw);
Usage:
repaint(gw);
void setWindowTitle(GWindow gw, string title);
Usage:
setWindowTitle(gw, title);
string getWindowTitle(GWindow gw);
Usage:
title = getWindowTitle(gw);
void draw(GWindow gw, GObject gobj);
GObject
on the background layer.
Usage:
draw(gw, gobj);
void drawAt(GWindow gw, GObject gobj, double x, double y);
GObject
to (x
, y
)
and then draws it on the window.
Usage:
drawAt(gw, gobj, x, y);
void add(GWindow gw, GObject gobj);
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 GObject
sUsage:
add(gw, gobj);
void addAt(GWindow gw, GObject gobj, double x, double y);
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);
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 removeGWindow(GWindow gw, GObject gobj);
Usage:
removeGWindow(gw, gobj);
GObject getGObjectAt(GWindow gw, double x, double y);
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);
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);
Usage:
pause(milliseconds);