/*
* tkCanvImg.c --
*
* This file implements image items for canvas widgets.
*
* Copyright (c) 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: @(#) tkCanvImg.c 1.17 96/02/17 17:18:43
*/
#include "tkInt.h"
#include "tkCanvas.h"
/*
* The structure below defines the record for each image item.
*/
typedef struct ImageItem {
* types. MUST BE FIRST IN STRUCTURE. */
double x, y; /* Coordinates of positioning point for
* image. */
* (x,y). */
* NULL means no image right now. */
* no image at present. */
} ImageItem;
/*
* Information used for parsing configuration specs:
*/
};
(char *) NULL, 0, 0}
};
/*
* Prototypes for procedures defined in this file:
*/
int imgHeight));
char **argv));
/*
* The structures below defines the image item type in terms of
* procedures that can be invoked by generic item code.
*/
"image", /* name */
sizeof(ImageItem), /* itemSize */
CreateImage, /* createProc */
configSpecs, /* configSpecs */
ConfigureImage, /* configureProc */
ImageCoords, /* coordProc */
DeleteImage, /* deleteProc */
DisplayImage, /* displayProc */
0, /* alwaysRedraw */
ImageToPoint, /* pointProc */
ImageToArea, /* areaProc */
ScaleImage, /* scaleProc */
TranslateImage, /* translateProc */
};
/*
*--------------------------------------------------------------
*
* CreateImage --
*
* This procedure is invoked to create a new image
* 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 image item is created.
*
*--------------------------------------------------------------
*/
static int
* has been initialized by caller. */
int argc; /* Number of arguments in argv. */
char **argv; /* Arguments describing rectangle. */
{
if (argc < 2) {
(char *) NULL);
return TCL_ERROR;
}
/*
* Initialize item's record.
*/
/*
* Process the arguments to fill in the item record.
*/
!= TCL_OK)) {
return TCL_ERROR;
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* ImageCoords --
*
* This procedure is invoked to process the "coords" widget
* command on image items. 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, ... */
{
char x[TCL_DOUBLE_SPACE], y[TCL_DOUBLE_SPACE];
if (argc == 0) {
} else if (argc == 2) {
return TCL_ERROR;
}
} else {
"wrong # coordinates: expected 0 or 2, got %d", argc);
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* ConfigureImage --
*
* This procedure is invoked to configure various aspects
* of an image item, such as its anchor position.
*
* Results:
* A standard Tcl result code. If an error occurs, then
* an error message is left in interp->result.
*
* Side effects:
* Configuration information 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. */
{
return TCL_ERROR;
}
/*
* Create the image. Save the old image around and don't free it
* until after the new one is allocated. This keeps the reference
* count from going to zero so the image doesn't have to be recreated
* if it hasn't changed.
*/
return TCL_ERROR;
}
} else {
}
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* DeleteImage --
*
* This procedure is called to clean up the data structure
* associated with a image item.
*
* Results:
* None.
*
* Side effects:
* Resources associated with itemPtr are released.
*
*--------------------------------------------------------------
*/
static void
* canvas. */
{
}
}
}
/*
*--------------------------------------------------------------
*
* ComputeImageBbox --
*
* This procedure is invoked to compute the bounding box of
* all the pixels that may be drawn as part of a image item.
* This procedure is where the child image's placement is
* computed.
*
* Results:
* None.
*
* Side effects:
* The fields x1, y1, x2, and y2 are updated in the header
* for itemPtr.
*
*--------------------------------------------------------------
*/
/* ARGSUSED */
static void
* recomputed. */
{
int x, y;
return;
}
/*
* Compute location and size of image, using anchor information.
*/
case TK_ANCHOR_N:
x -= width/2;
break;
case TK_ANCHOR_NE:
x -= width;
break;
case TK_ANCHOR_E:
x -= width;
y -= height/2;
break;
case TK_ANCHOR_SE:
x -= width;
y -= height;
break;
case TK_ANCHOR_S:
x -= width/2;
y -= height;
break;
case TK_ANCHOR_SW:
y -= height;
break;
case TK_ANCHOR_W:
y -= height/2;
break;
case TK_ANCHOR_NW:
break;
case TK_ANCHOR_CENTER:
x -= width/2;
y -= height/2;
break;
}
/*
* Store the information in the item header.
*/
}
/*
*--------------------------------------------------------------
*
* DisplayImage --
*
* This procedure is invoked to draw a image 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). */
{
return;
}
/*
* Translate the coordinates to those of the image, then redisplay it.
*/
Tk_CanvasDrawableCoords(canvas, (double) x, (double) y,
}
/*
*--------------------------------------------------------------
*
* ImageToPoint --
*
* 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 image. If the
* point isn't inside the image then the return value is the
* distance from the point to the image.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static double
double *coordPtr; /* Pointer to x and y coordinates. */
{
/*
* Point is outside rectangle.
*/
} else {
xDiff = 0;
}
} else {
yDiff = 0;
}
}
/*
*--------------------------------------------------------------
*
* ImageToArea --
*
* 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.
*
*--------------------------------------------------------------
*/
static int
double *rectPtr; /* Pointer to array of four coordinates
* (x1, y1, x2, y2) describing rectangular
* area. */
{
return -1;
}
return 1;
}
return 0;
}
/*
*--------------------------------------------------------------
*
* ScaleImage --
*
* This procedure is invoked to rescale an item.
*
* Results:
* None.
*
* Side effects:
* The item 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. */
{
}
/*
*--------------------------------------------------------------
*
* TranslateImage --
*
* This procedure is called to move an item by a given amount.
*
* Results:
* None.
*
* Side effects:
* The position of the item is offset by (xDelta, yDelta), and
* the bounding box is updated in the generic part of the item
* structure.
*
*--------------------------------------------------------------
*/
static void
* moved. */
{
}
/*
*----------------------------------------------------------------------
*
* ImageChangedProc --
*
* This procedure is invoked by the image code whenever the manager
* for an image does something that affects the image's size or
* how it is displayed.
*
* Results:
* None.
*
* Side effects:
* Arranges for the canvas to get redisplayed.
*
*----------------------------------------------------------------------
*/
static void
int x, y; /* Upper left pixel (within image)
* that must be redisplayed. */
* (may be <= 0). */
{
/*
* If the image's size changed and it's not anchored at its
* northwest corner then just redisplay the entire area of the
* image. This is a bit over-conservative, but we need to do
* something because a size change also means a position change.
*/
x = y = 0;
}
}