/*
* tkRectOval.c --
*
* This file implements rectangle and oval items for canvas
* widgets.
*
* Copyright (c) 1991-1994 The Regents of the University of California.
* Copyright (c) 1994-1996 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkRectOval.c 1.39 96/03/02 17:28:06
*/
#include "tkInt.h"
/*
*/
typedef struct RectOvalItem {
* types. MUST BE FIRST IN STRUCTURE. */
* or oval (x1, y1, x2, y2). Item includes
* x1 and x2 but not y1 and y2. */
} RectOvalItem;
/*
* Information used for parsing configuration specs:
*/
};
(char *) NULL, 0, 0}
};
/*
* Prototypes for procedures defined in this file:
*/
char **argv));
/*
* The structures below defines the rectangle and oval item types
* by means of procedures that can be invoked by generic item code.
*/
"rectangle", /* name */
sizeof(RectOvalItem), /* itemSize */
CreateRectOval, /* createProc */
configSpecs, /* configSpecs */
ConfigureRectOval, /* configureProc */
RectOvalCoords, /* coordProc */
DeleteRectOval, /* deleteProc */
DisplayRectOval, /* displayProc */
0, /* alwaysRedraw */
RectToPoint, /* pointProc */
RectToArea, /* areaProc */
RectOvalToPostscript, /* postscriptProc */
ScaleRectOval, /* scaleProc */
TranslateRectOval, /* translateProc */
};
"oval", /* name */
sizeof(RectOvalItem), /* itemSize */
CreateRectOval, /* createProc */
configSpecs, /* configSpecs */
ConfigureRectOval, /* configureProc */
RectOvalCoords, /* coordProc */
DeleteRectOval, /* deleteProc */
DisplayRectOval, /* displayProc */
0, /* alwaysRedraw */
OvalToPoint, /* pointProc */
OvalToArea, /* areaProc */
RectOvalToPostscript, /* postscriptProc */
ScaleRectOval, /* scaleProc */
TranslateRectOval, /* translateProc */
};
/*
*--------------------------------------------------------------
*
* CreateRectOval --
*
* This procedure is invoked to create a new rectangle
* or oval item in a canvas.
*
* Results:
* A standard Tcl return value. If an error occurred in
* creating the item, then an error message is left in
* interp->result; in this case itemPtr is left uninitialized,
* so it can be safely freed by the caller.
*
* Side effects:
* A new rectangle or oval item is created.
*
*--------------------------------------------------------------
*/
static int
* has been initialized by caller. */
int argc; /* Number of arguments in argv. */
char **argv; /* Arguments describing rectangle. */
{
if (argc < 4) {
(char *) NULL);
return TCL_ERROR;
}
/*
* Carry out initialization that is needed in order to clean
* up after errors during the the remainder of this procedure.
*/
/*
* Process the arguments to fill in the item record.
*/
return TCL_ERROR;
}
!= TCL_OK) {
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* RectOvalCoords --
*
* This procedure is invoked to process the "coords" widget
* command on rectangles and ovals. See the user documentation
* for details on what it does.
*
* Results:
* Returns TCL_OK or TCL_ERROR, and sets interp->result.
*
* Side effects:
* The coordinates for the given item may be changed.
*
*--------------------------------------------------------------
*/
static int
* read or modified. */
int argc; /* Number of coordinates supplied in
* argv. */
char **argv; /* Array of coordinates: x1, y1,
* x2, y2, ... */
{
if (argc == 0) {
(char *) NULL);
} else if (argc == 4) {
return TCL_ERROR;
}
} else {
"wrong # coordinates: expected 0 or 4, got %d",
argc);
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* ConfigureRectOval --
*
* This procedure is invoked to configure various aspects
* of a rectangle or oval item, such as its border and
* background colors.
*
* Results:
* A standard Tcl result code. If an error occurs, then
* an error message is left in interp->result.
*
* Side effects:
* Configuration information, such as colors and stipple
* patterns, may be set for itemPtr.
*
*--------------------------------------------------------------
*/
static int
int argc; /* Number of elements in argv. */
char **argv; /* Arguments describing things to configure. */
int flags; /* Flags to pass to Tk_ConfigureWidget. */
{
unsigned long mask;
return TCL_ERROR;
}
/*
* A few of the options require additional processing, such as
* graphics contexts.
*/
}
} else {
}
}
} else {
} else {
mask = GCForeground;
}
}
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* DeleteRectOval --
*
* This procedure is called to clean up the data structure
* associated with a rectangle or oval item.
*
* Results:
* None.
*
* Side effects:
* Resources associated with itemPtr are released.
*
*--------------------------------------------------------------
*/
static void
* canvas. */
{
}
}
}
}
}
}
/*
*--------------------------------------------------------------
*
* ComputeRectOvalBbox --
*
* This procedure is invoked to compute the bounding box of
* all the pixels that may be drawn as part of a rectangle
* or oval.
*
* Results:
* None.
*
* Side effects:
* The fields x1, y1, x2, and y2 are updated in the header
* for itemPtr.
*
*--------------------------------------------------------------
*/
/* ARGSUSED */
static void
* recomputed. */
{
double dtmp;
/*
* Make sure that the first coordinates are the lowest ones.
*/
double tmp;
}
double tmp;
}
bloat = 0;
} else {
}
/*
* Special note: the rectangle is always drawn at least 1x1 in
* size, so round up the upper coordinates to be at least 1 unit
* greater than the lower ones.
*/
}
}
}
/*
*--------------------------------------------------------------
*
* DisplayRectOval --
*
* This procedure is invoked to draw a rectangle or oval
* item in a given drawable.
*
* Results:
* None.
*
* Side effects:
* ItemPtr is drawn in drawable using the transformation
* information in canvas.
*
*--------------------------------------------------------------
*/
static void
* item. */
* must be redisplayed (not used). */
{
/*
* Compute the screen coordinates of the bounding box for the item.
* Make sure that the bbox is at least one pixel large, since some
* X servers will die if it isn't.
*/
}
}
/*
* Display filled part first (if wanted), then outline. If we're
* stippling, then modify the stipple offset in the GC. Be sure to
* reset the offset when done, since the GC is supposed to be
* read-only.
*/
}
} else {
0, 360*64);
}
}
}
} else {
}
}
}
/*
*--------------------------------------------------------------
*
* RectToPoint --
*
* Computes the distance from a given point to a given
* rectangle, in canvas units.
*
* Results:
* The return value is 0 if the point whose x and y coordinates
* are coordPtr[0] and coordPtr[1] is inside the rectangle. If the
* point isn't inside the rectangle then the return value is the
* distance from the point to the rectangle. If itemPtr is filled,
* then anywhere in the interior is considered "inside"; if
* itemPtr isn't filled, then "inside" means only the area
* occupied by the outline.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
/* ARGSUSED */
static double
double *pointPtr; /* Pointer to x and y coordinates. */
{
/*
* Generate a new larger rectangle that includes the border
* width, if there is one.
*/
}
/*
* If the point is inside the rectangle, handle specially:
* distance is 0 if rectangle is filled, otherwise compute
* distance to nearest edge of rectangle and subtract width
* of edge.
*/
return 0.0;
}
}
}
}
if (xDiff < 0.0) {
return 0.0;
}
return xDiff;
}
/*
* Point is outside rectangle.
*/
} else {
xDiff = 0;
}
} else {
yDiff = 0;
}
}
/*
*--------------------------------------------------------------
*
* OvalToPoint --
*
* Computes the distance from a given point to a given
* oval, in canvas units.
*
* Results:
* The return value is 0 if the point whose x and y coordinates
* are coordPtr[0] and coordPtr[1] is inside the oval. If the
* point isn't inside the oval then the return value is the
* distance from the point to the oval. If itemPtr is filled,
* then anywhere in the interior is considered "inside"; if
* itemPtr isn't filled, then "inside" means only the area
* occupied by the outline.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
/* ARGSUSED */
static double
double *pointPtr; /* Pointer to x and y coordinates. */
{
double width;
int filled;
width = 0.0;
filled = 1;
}
}
/*
*--------------------------------------------------------------
*
* RectToArea --
*
* This procedure is called to determine whether an item
* lies entirely inside, entirely outside, or overlapping
* a given rectangle.
*
* Results:
* -1 is returned if the item is entirely outside the area
* given by rectPtr, 0 if it overlaps, and 1 if it is entirely
* inside the given area.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
/* ARGSUSED */
static int
double *areaPtr; /* Pointer to array of four coordinates
* (x1, y1, x2, y2) describing rectangular
* area. */
{
double halfWidth;
halfWidth = 0.0;
}
return -1;
}
return -1;
}
return 1;
}
return 0;
}
/*
*--------------------------------------------------------------
*
* OvalToArea --
*
* This procedure is called to determine whether an item
* lies entirely inside, entirely outside, or overlapping
* a given rectangular area.
*
* Results:
* -1 is returned if the item is entirely outside the area
* given by rectPtr, 0 if it overlaps, and 1 if it is entirely
* inside the given area.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
/* ARGSUSED */
static int
double *areaPtr; /* Pointer to array of four coordinates
* (x1, y1, x2, y2) describing rectangular
* area. */
{
int result;
/*
* Expand the oval to include the width of the outline, if any.
*/
halfWidth = 0.0;
}
/*
* If the rectangle appears to overlap the oval and the oval
* isn't filled, do one more check to see if perhaps all four
* of the rectangle's corners are totally inside the oval's
* unfilled center, in which case we should return "outside".
*/
return -1;
}
}
return result;
}
/*
*--------------------------------------------------------------
*
* ScaleRectOval --
*
* This procedure is invoked to rescale a rectangle or oval
* item.
*
* Results:
* None.
*
* Side effects:
* The rectangle or oval referred to by itemPtr is rescaled
* so that the following transformation is applied to all
* point coordinates:
* x' = originX + scaleX*(x-originX)
* y' = originY + scaleY*(y-originY)
*
*--------------------------------------------------------------
*/
static void
double scaleX; /* Amount to scale in X direction. */
double scaleY; /* Amount to scale in Y direction. */
{
}
/*
*--------------------------------------------------------------
*
* TranslateRectOval --
*
* This procedure is called to move a rectangle or oval by a
* given amount.
*
* Results:
* None.
*
* Side effects:
* The position of the rectangle or oval is offset by
* (xDelta, yDelta), and the bounding box is updated in the
* generic part of the item structure.
*
*--------------------------------------------------------------
*/
static void
* moved. */
{
}
/*
*--------------------------------------------------------------
*
* RectOvalToPostscript --
*
* This procedure is called to generate Postscript for
* rectangle and oval items.
*
* Results:
* The return value is a standard Tcl result. If an error
* occurs in generating Postscript then an error message is
* left in interp->result, replacing whatever used to be there.
* If no error occurs, then Postscript for the rectangle is
* appended to the result.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static int
* wanted. */
int prepass; /* 1 means this is a prepass to
* collect font information; 0 means
* final Postscript is being created. */
{
/*
* Generate a string that creates a path for the rectangle or oval.
* This is the only part of the procedure's code that is type-
* specific.
*/
} else {
sprintf(pathCmd, "matrix currentmatrix\n%.15g %.15g translate %.15g %.15g scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n",
}
/*
* First draw the filled area of the rectangle.
*/
!= TCL_OK) {
return TCL_ERROR;
}
!= TCL_OK) {
return TCL_ERROR;
}
}
} else {
}
}
/*
* Now draw the outline, if there is one.
*/
" 0 setlinejoin 2 setlinecap\n", (char *) NULL);
!= TCL_OK) {
return TCL_ERROR;
}
}
return TCL_OK;
}