aboutsummaryrefslogtreecommitdiff
path: root/generic/Color.c
diff options
context:
space:
mode:
authorlecoanet2001-11-12 09:42:20 +0000
committerlecoanet2001-11-12 09:42:20 +0000
commit1fef084373b5ad9bfb10db7c80b6c601f7507f0a (patch)
tree7d91f96f0d077cee1d650f298dc2c2f7cc2b5409 /generic/Color.c
parenta5c5bde7dabc191360322654639a9f74a092fa5e (diff)
downloadtkzinc-1fef084373b5ad9bfb10db7c80b6c601f7507f0a.zip
tkzinc-1fef084373b5ad9bfb10db7c80b6c601f7507f0a.tar.gz
tkzinc-1fef084373b5ad9bfb10db7c80b6c601f7507f0a.tar.bz2
tkzinc-1fef084373b5ad9bfb10db7c80b6c601f7507f0a.tar.xz
Ajout des gradients nommes, les cles de la table des gradients sont desormais des chaines
Diffstat (limited to 'generic/Color.c')
-rw-r--r--generic/Color.c78
1 files changed, 61 insertions, 17 deletions
diff --git a/generic/Color.c b/generic/Color.c
index 450580c..b5d1da6 100644
--- a/generic/Color.c
+++ b/generic/Color.c
@@ -160,14 +160,6 @@ typedef struct {
*/
static Tcl_HashTable gradient_table;
-typedef struct {
- Tk_Uid name; /* Gradient spec. */
- Colormap colormap; /* Colormap used for allocating gradient
- * colors. */
- Screen *screen; /* Screen on which gradient will be drawn. */
-} GradientKey;
-
-
static int initialized = 0; /* 0 means static structures haven't been
* initialized yet. */
@@ -425,7 +417,7 @@ ColorInit()
initialized = 1;
Tcl_InitHashTable(&name_table, sizeof(NameKey)/sizeof(int));
Tcl_InitHashTable(&value_table, sizeof(ValueKey)/sizeof(int));
- Tcl_InitHashTable(&gradient_table, sizeof(GradientKey)/sizeof(int));
+ Tcl_InitHashTable(&gradient_table, TCL_STRING_KEYS);
}
@@ -1073,6 +1065,59 @@ RealizeGradient(ZnGradient *grad,
}
}
+/*
+ *--------------------------------------------------------------
+ *
+ * ZnNameGradient
+ * ZnDeleteGradientName --
+ *
+ * Save a gradient under a name or suppress the gradient
+ * name binding. The save function returns false if the
+ * name is already in use.
+ *
+ *--------------------------------------------------------------
+ */
+ZnBool
+ZnNameGradient(Tcl_Interp *interp,
+ Tk_Window tkwin,
+ char *grad_descr,
+ char *name)
+{
+ Tcl_HashEntry *hash;
+ int new;
+ ZnGradient *grad;
+
+ grad = ZnGetGradient(interp, tkwin, grad_descr);
+ if (!grad) {
+ return False;
+ }
+
+ hash = Tcl_CreateHashEntry(&gradient_table, Tk_GetUid(name), &new);
+ if (!new) {
+ return False;
+ }
+ else {
+ Tcl_SetHashValue(hash, grad);
+ }
+
+ return True;
+}
+
+void
+ZnDeleteGradientName(char *name)
+{
+ Tcl_HashEntry *hash;
+
+ if (!initialized) {
+ return;
+ }
+
+ hash = Tcl_FindHashEntry(&gradient_table, Tk_GetUid(name));
+ if (hash) {
+ Tcl_DeleteHashEntry(hash);
+ ZnFreeGradient((ZnGradient *) Tcl_GetHashValue(hash));
+ }
+}
/*
*--------------------------------------------------------------
@@ -1114,7 +1159,6 @@ ZnGetGradient(Tcl_Interp *interp,
Tk_Window tkwin,
Tk_Uid name)
{
- GradientKey key;
Tcl_HashEntry *hash;
ZnGradient *grad;
int i, j, new, num_colors, num_shades;
@@ -1123,7 +1167,10 @@ ZnGetGradient(Tcl_Interp *interp,
double x, y;
char *color_ptr, color_name[COLOR_NAME_SIZE];
char buffer[GRADIENT_NAME_SIZE];
-
+
+ if (!name || !*name) {
+ return NULL;
+ }
if (!initialized) {
ColorInit();
}
@@ -1133,11 +1180,8 @@ ZnGetGradient(Tcl_Interp *interp,
* for this request.
*/
name = Tk_GetUid(name);
- key.name = name;
- key.colormap = Tk_Colormap(tkwin);
- key.screen = Tk_Screen(tkwin);
-
- hash = Tcl_CreateHashEntry(&gradient_table, (char *) &key, &new);
+
+ hash = Tcl_CreateHashEntry(&gradient_table, name, &new);
if (!new) {
grad = (ZnGradient *) Tcl_GetHashValue(hash);
grad->ref_count++;
@@ -1324,7 +1368,7 @@ ZnGetGradient(Tcl_Interp *interp,
char *
ZnNameOfGradient(ZnGradient *grad)
{
- return ((GradientKey *) grad->hash->key.words)->name;
+ return (char *) grad->hash->key.words;
}