/*
* tkCanvBmap.c --
*
* This file implements bitmap items for canvas widgets.
*
* Copyright (c) 1992-1994 The Regents of the University of California.
* Copyright (c) 1994-1995 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: @(#) tkCanvBmap.c 1.29 96/02/17 16:59:10
*/
#include "tkInt.h"
#include "tkCanvas.h"
/*
* The structure below defines the record for each bitmap item.
*/
typedef struct BitmapItem {
* types. MUST BE FIRST IN STRUCTURE. */
double x, y; /* Coordinates of positioning point for
* bitmap. */
* (x,y). */
* bitmap on screen. */
} BitmapItem;
/*
* Information used for parsing configuration specs:
*/
};
(char *) NULL, 0, 0}
};
/*
* Prototypes for procedures defined in this file:
*/
char **argv));
BitmapItem *bmapPtr));
/*
* The structures below defines the bitmap item type in terms of
* procedures that can be invoked by generic item code.
*/
"bitmap", /* name */
sizeof(BitmapItem), /* itemSize */
CreateBitmap, /* createProc */
configSpecs, /* configSpecs */
ConfigureBitmap, /* configureProc */
BitmapCoords, /* coordProc */
DeleteBitmap, /* deleteProc */
DisplayBitmap, /* displayProc */
0, /* alwaysRedraw */
BitmapToPoint, /* pointProc */
BitmapToArea, /* areaProc */
BitmapToPostscript, /* postscriptProc */
ScaleBitmap, /* scaleProc */
TranslateBitmap, /* translateProc */
};
/*
*--------------------------------------------------------------
*
* CreateBitmap --
*
* This procedure is invoked to create a new bitmap
* 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 bitmap 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;
}
/*
*--------------------------------------------------------------
*
* BitmapCoords --
*
* This procedure is invoked to process the "coords" widget
* command on bitmap 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) {
!= TCL_OK)) {
return TCL_ERROR;
}
} else {
"wrong # coordinates: expected 0 or 2, got %d", argc);
return TCL_ERROR;
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* ConfigureBitmap --
*
* This procedure is invoked to configure various aspects
* of a bitmap 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. */
{
unsigned long mask;
return TCL_ERROR;
}
/*
* A few of the options require additional processing, such as those
* that determine the graphics context.
*/
mask = GCForeground;
mask |= GCBackground;
} else {
mask |= GCClipMask;
}
}
return TCL_OK;
}
/*
*--------------------------------------------------------------
*
* DeleteBitmap --
*
* This procedure is called to clean up the data structure
* associated with a bitmap item.
*
* Results:
* None.
*
* Side effects:
* Resources associated with itemPtr are released.
*
*--------------------------------------------------------------
*/
static void
* canvas. */
{
}
}
}
}
}
/*
*--------------------------------------------------------------
*
* ComputeBitmapBbox --
*
* This procedure is invoked to compute the bounding box of
* all the pixels that may be drawn as part of a bitmap item.
* This procedure is where the child bitmap'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 bitmap, 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.
*/
}
/*
*--------------------------------------------------------------
*
* DisplayBitmap --
*
* This procedure is invoked to draw a bitmap 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). */
{
/*
* If the area being displayed doesn't cover the whole bitmap,
* then only redisplay the part of the bitmap that needs
* redisplay.
*/
} else {
bmapX = 0;
} else {
}
}
} else {
bmapY = 0;
} else {
}
}
/*
* Must modify the mask origin within the graphics context
* to line up with the bitmap's origin (in order to make
* bitmaps with "-background {}" work right).
*/
}
}
/*
*--------------------------------------------------------------
*
* BitmapToPoint --
*
* 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 bitmap. If the
* point isn't inside the bitmap then the return value is the
* distance from the point to the bitmap.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
/* ARGSUSED */
static double
double *coordPtr; /* Pointer to x and y coordinates. */
{
/*
* Point is outside rectangle.
*/
} else {
xDiff = 0;
}
} else {
yDiff = 0;
}
}
/*
*--------------------------------------------------------------
*
* BitmapToArea --
*
* 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 *rectPtr; /* Pointer to array of four coordinates
* (x1, y1, x2, y2) describing rectangular
* area. */
{
return -1;
}
return 1;
}
return 0;
}
/*
*--------------------------------------------------------------
*
* ScaleBitmap --
*
* This procedure is invoked to rescale a bitmap item in a
* canvas. It is one of the standard item procedures for
* bitmap items, and is invoked by the generic canvas code.
*
* 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. */
{
}
/*
*--------------------------------------------------------------
*
* TranslateBitmap --
*
* 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. */
{
}
/*
*--------------------------------------------------------------
*
* BitmapToPostscript --
*
* This procedure is called to generate Postscript for
* bitmap 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 item is appended
* to the result.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static int
* here. */
* wanted. */
int prepass; /* 1 means this is a prepass to
* collect font information; 0 means
* final Postscript is being created. */
{
double x, y;
int curRow;
return TCL_OK;
}
/*
* Compute the coordinates of the lower-left corner of the bitmap,
* taking into account the anchor position for the bitmp.
*/
x = bmapPtr->x;
case TK_ANCHOR_NW: y -= height; break;
case TK_ANCHOR_SE: x -= width; break;
case TK_ANCHOR_SW: break;
}
/*
* Color the background, if there is one.
*/
"%.15g %.15g moveto %d 0 rlineto 0 %d rlineto %d %s\n",
return TCL_ERROR;
}
}
/*
* Draw the bitmap, if there is a foreground color. If the bitmap
* is very large, then chop it up into multiple bitmaps, each
* consisting of one or more rows. This is needed because Postscript
* can't handle single strings longer than 64 KBytes long.
*/
return TCL_ERROR;
}
if (width > 60000) {
" for bitmaps more than 60000 pixels wide",
(char *) NULL);
return TCL_ERROR;
}
if (rowsAtOnce < 1) {
rowsAtOnce = 1;
}
}
return TCL_ERROR;
}
}
}
return TCL_OK;
}