From a5befb7f79676109c4dab8fcfe54f85e7998afa5 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Wed, 3 Mar 2004 16:40:50 +0000 Subject: Added new attribute types ZN_CONFIG_CHAR and ZN_CONFIG_UCHAR Changed the ZN_CONFIG_ALPHA type to be processed as a char, this fixes a potentially long standing bug when configuring an alpha value. --- generic/Item.c | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'generic/Item.c') diff --git a/generic/Item.c b/generic/Item.c index ae71348..f6ed14d 100644 --- a/generic/Item.c +++ b/generic/Item.c @@ -97,6 +97,8 @@ static char *attribute_type_strings[] = { "fillrule", "short", "unsignedshort" + "char" + "unsignedchar" }; @@ -770,6 +772,34 @@ ZnConfigureAttributes(ZnWInfo *wi, } } break; + case ZN_CONFIG_CHAR: + case ZN_CONFIG_UCHAR: + case ZN_CONFIG_ALPHA: + { + int integer; + if (Tcl_GetIntFromObj(wi->interp, args[i+1], &integer) == TCL_ERROR) { + return TCL_ERROR; + } + switch (desc->type) { + case ZN_CONFIG_UCHAR: + if (integer < 0) { + integer = 0; + } + case ZN_CONFIG_ALPHA: + if (integer < 0) { + integer = 0; + } + if (integer > 100) { + integer = 100; + } + break; + } + if (integer != *((char *) valp)) { + *((char *) valp) = integer; + *flags |= desc->flags; + } + break; + } case ZN_CONFIG_SHORT: case ZN_CONFIG_USHORT: { @@ -806,7 +836,6 @@ ZnConfigureAttributes(ZnWInfo *wi, case ZN_CONFIG_INT: case ZN_CONFIG_UINT: case ZN_CONFIG_ANGLE: - case ZN_CONFIG_ALPHA: { int integer; if (Tcl_GetIntFromObj(wi->interp, args[i+1], &integer) == TCL_ERROR) { @@ -823,14 +852,6 @@ ZnConfigureAttributes(ZnWInfo *wi, integer = 0; } break; - case ZN_CONFIG_ALPHA: - if (integer < 0) { - integer = 0; - } - if (integer > 100) { - integer = 100; - } - break; } if (integer != *((int *) valp)) { *((int *) valp) = integer; @@ -1110,6 +1131,13 @@ AttributeToObj(ZnWInfo *wi, str = Tk_PathName(*((Tk_Window *) valp)); } break; + case ZN_CONFIG_CHAR: + Tcl_SetIntObj(result, *((char *) valp)); + return; + case ZN_CONFIG_UCHAR: + case ZN_CONFIG_ALPHA: + Tcl_SetIntObj(result, *((unsigned char *) valp)); + return; case ZN_CONFIG_USHORT: case ZN_CONFIG_PRI: Tcl_SetIntObj(result, *((unsigned short *) valp)); @@ -1122,7 +1150,6 @@ AttributeToObj(ZnWInfo *wi, return; case ZN_CONFIG_INT: case ZN_CONFIG_ANGLE: - case ZN_CONFIG_ALPHA: Tcl_SetIntObj(result, *((int *) valp)); return; case ZN_CONFIG_DIM: -- cgit v1.1