diff options
Diffstat (limited to 'generic/tkObj.c')
-rw-r--r-- | generic/tkObj.c | 95 |
1 files changed, 91 insertions, 4 deletions
diff --git a/generic/tkObj.c b/generic/tkObj.c index 41cc589..c8bc746 100644 --- a/generic/tkObj.c +++ b/generic/tkObj.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkObj.c,v 1.22 2008/10/15 06:41:06 nijtmans Exp $ + * RCS: @(#) $Id: tkObj.c,v 1.23 2008/11/27 23:47:09 ferrieux Exp $ */ #include "tkInt.h" @@ -125,7 +125,7 @@ static const Tcl_ObjType windowObjType = { /* *---------------------------------------------------------------------- * - * Tk_GetPixelsFromObj -- + * GetPixelsFromObjEx -- * * Attempt to return a pixel value from the Tcl object "objPtr". If the * object is not already a pixel value, an attempt will be made to @@ -143,12 +143,14 @@ static const Tcl_ObjType windowObjType = { *---------------------------------------------------------------------- */ +static int -Tk_GetPixelsFromObj( +GetPixelsFromObjEx( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ Tk_Window tkwin, Tcl_Obj *objPtr, /* The object from which to get pixels. */ - int *intPtr) /* Place to store resulting pixels. */ + int *intPtr, + double *dblPtr) /* Places to store resulting pixels. */ { int result; double d; @@ -166,6 +168,9 @@ Tk_GetPixelsFromObj( if (SIMPLE_PIXELREP(objPtr)) { *intPtr = GET_SIMPLEPIXEL(objPtr); + if (dblPtr) { + *dblPtr=(double)(*intPtr); + } } else { pixelPtr = GET_COMPLEXPIXEL(objPtr); if (pixelPtr->tkwin != tkwin) { @@ -180,6 +185,9 @@ Tk_GetPixelsFromObj( pixelPtr->returnValue = (int) (d + 0.5); } pixelPtr->tkwin = tkwin; + if (dblPtr) { + *dblPtr=(double)d; + } } *intPtr = pixelPtr->returnValue; } @@ -189,6 +197,85 @@ Tk_GetPixelsFromObj( /* *---------------------------------------------------------------------- * + * Tk_GetPixelsFromObj -- + * + * Attempt to return a pixel value from the Tcl object "objPtr". If the + * object is not already a pixel value, an attempt will be made to + * convert it to one. + * + * Results: + * The return value is a standard Tcl object result. If an error occurs + * during conversion, an error message is left in the interpreter's + * result unless "interp" is NULL. + * + * Side effects: + * If the object is not already a pixel, the conversion will free any old + * internal representation. + * + *---------------------------------------------------------------------- + */ + +int +Tk_GetPixelsFromObj( + Tcl_Interp *interp, /* Used for error reporting if not NULL. */ + Tk_Window tkwin, + Tcl_Obj *objPtr, /* The object from which to get pixels. */ + int *intPtr) /* Place to store resulting pixels. */ +{ + return GetPixelsFromObjEx(interp,tkwin,objPtr,intPtr,NULL); +} + +/* + *---------------------------------------------------------------------- + * + * Tk_GetDoublePixelsFromObj -- + * + * Attempt to return a double pixel value from the Tcl object + * "objPtr". If the object is not already a pixel value, an attempt will + * be made to convert it to one, the internal unit being pixels. + * + * Results: + * The return value is a standard Tcl object result. If an error occurs + * during conversion, an error message is left in the interpreter's + * result unless "interp" is NULL. + * + * Side effects: + * If the object is not already a pixel, the conversion will free any old + * internal representation. + * + *---------------------------------------------------------------------- + */ + +int +Tk_GetDoublePixelsFromObj( + Tcl_Interp *interp, /* Used for error reporting if not NULL. */ + Tk_Window tkwin, + Tcl_Obj *objPtr, /* The object from which to get pixels. */ + double *doublePtr) /* Place to store resulting pixels. */ +{ + double d; + int result,val; + + result=GetPixelsFromObjEx(interp, tkwin, objPtr, &val, &d); + if (result != TCL_OK) { + return result; + } + if (!SIMPLE_PIXELREP(objPtr)) { + PixelRep *pixelPtr; + pixelPtr = GET_COMPLEXPIXEL(objPtr); + if (pixelPtr->units >= 0) { + /* internally "shimmer" to pixel units */ + pixelPtr->units=-1; + pixelPtr->value=d; + } + } + *doublePtr = d; + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * * FreePixelInternalRep -- * * Deallocate the storage associated with a pixel object's internal |