summaryrefslogtreecommitdiff
path: root/src/glibext
diff options
context:
space:
mode:
Diffstat (limited to 'src/glibext')
-rw-r--r--src/glibext/configuration.c74
-rw-r--r--src/glibext/configuration.h2
2 files changed, 76 insertions, 0 deletions
diff --git a/src/glibext/configuration.c b/src/glibext/configuration.c
index 03575b0..09d2d37 100644
--- a/src/glibext/configuration.c
+++ b/src/glibext/configuration.c
@@ -52,6 +52,7 @@ typedef union _param_value
int integer; /* Valeur entière */
unsigned long ulong; /* Valeur entière positive */
char *string; /* Chaîne de caractères */
+ GdkRGBA color; /* Couleur avec transparence */
} param_value;
@@ -343,6 +344,10 @@ GCfgParam *g_config_param_new(const char *path, ConfigParamType type, ...)
result->def.string = strdup(result->def.string);
break;
+ case CPT_COLOR:
+ result->def.color = *va_arg(ap, GdkRGBA *);
+ break;
+
default:
g_object_unref(G_OBJECT(result));
result = NULL;
@@ -412,6 +417,8 @@ static bool g_config_param_read(GCfgParam *param, xmlXPathContextPtr context)
char *access; /* Chemin d'accès XML */
char *value; /* Valeur en chaîne de carac. */
unsigned long ulval; /* Valeur transformée */
+ GdkRGBA color; /* Couleur transformée */
+ char *end; /* Position terminale */
access = strdup(param->path);
access = strrpl(access, ".", "/");
@@ -443,6 +450,20 @@ static bool g_config_param_read(GCfgParam *param, xmlXPathContextPtr context)
g_config_param_set_value(param, value);
break;
+ case CPT_COLOR:
+ color.red = strtod(value, &end);
+ if (*end != ';') goto gcpr_bad_value;
+ else end++;
+ color.green = strtod(end, &end);
+ if (*end != ';') goto gcpr_bad_value;
+ else end++;
+ color.blue = strtod(end, &end);
+ if (*end != ';') goto gcpr_bad_value;
+ else end++;
+ color.alpha = strtod(end, &end);
+ g_config_param_set_value(param, &color);
+ break;
+
default:
assert(false);
break;
@@ -457,6 +478,12 @@ static bool g_config_param_read(GCfgParam *param, xmlXPathContextPtr context)
return true;
+ gcpr_bad_value:
+
+ free(value);
+
+ return false;
+
}
@@ -481,6 +508,7 @@ static bool g_config_param_write(GCfgParam *param, xmlDocPtr xdoc, xmlXPathConte
char *access; /* Chemin d'accès XML */
char int_val[sizeof(XSTR(INT_MIN)) + 1];/* Valeur en chaîne de carac. */
char ul_val[sizeof(XSTR(ULONG_MAX)) + 1];/* Valeur en chaîne de carac. */
+ char *color; /* Valeurs d'une couleur */
state = g_config_param_get_state(param);
@@ -524,6 +552,19 @@ static bool g_config_param_write(GCfgParam *param, xmlDocPtr xdoc, xmlXPathConte
param->cur.string != NULL ? param->cur.string : "");
break;
+ case CPT_COLOR:
+
+ asprintf(&color, "%f;%f;%f;%f",
+ param->cur.color.red,
+ param->cur.color.green,
+ param->cur.color.blue,
+ param->cur.color.alpha);
+
+ result = add_content_to_node(xdoc, context, access, color);
+
+ free(color);
+ break;
+
default:
assert(false);
break;
@@ -650,6 +691,14 @@ ConfigParamState g_config_param_get_state(GCfgParam *param)
param->cached_state = CPS_CHANGED;
break;
+ case CPT_COLOR:
+ param->cached_state = (param->def.color.red == param->cur.color.red
+ && param->def.color.blue == param->cur.color.blue
+ && param->def.color.green == param->cur.color.green
+ && param->def.color.alpha == param->cur.color.alpha
+ ? CPS_DEFAULT : CPS_CHANGED);
+ break;
+
default:
break;
@@ -700,6 +749,13 @@ void g_config_param_make_empty(GCfgParam *param)
}
break;
+ case CPT_COLOR:
+ param->cur.color.red = 0;
+ param->cur.color.blue = 0;
+ param->cur.color.green = 0;
+ param->cur.color.alpha = 0;
+ break;
+
default:
break;
@@ -758,6 +814,10 @@ void g_config_param_reset(GCfgParam *param)
param->cur.string = NULL;
break;
+ case CPT_COLOR:
+ param->cur.color = param->def.color;
+ break;
+
default:
assert(false);
break;
@@ -798,6 +858,7 @@ void g_config_param_set_value(GCfgParam *param, ...)
int old_integer; /* Valeur entière */
unsigned long old_ulong; /* Valeur entière positive */
char *old_string; /* Chaîne de caractères */
+ GdkRGBA old_color; /* Couleur avec transparence */
bool modified; /* Détermine une modification */
va_start(ap, param);
@@ -840,6 +901,15 @@ void g_config_param_set_value(GCfgParam *param, ...)
break;
+ case CPT_COLOR:
+ old_color = param->cur.color;
+ param->cur.color = *va_arg(ap, GdkRGBA *);
+ modified = (old_color.red != param->cur.color.red
+ || old_color.blue != param->cur.color.blue
+ || old_color.green != param->cur.color.green
+ || old_color.alpha != param->cur.color.alpha);
+ break;
+
default:
assert(false);
modified = false;
@@ -900,6 +970,10 @@ void g_config_param_get_value(GCfgParam *param, ...)
*(va_arg(ap, char **)) = param->cur.string;
break;
+ case CPT_COLOR:
+ *(va_arg(ap, GdkRGBA *)) = param->cur.color;
+ break;
+
default:
assert(false);
break;
diff --git a/src/glibext/configuration.h b/src/glibext/configuration.h
index 7da2452..0f352ea 100644
--- a/src/glibext/configuration.h
+++ b/src/glibext/configuration.h
@@ -27,6 +27,7 @@
#include <glib-object.h>
#include <stdbool.h>
+#include <gdk/gdk.h>
@@ -40,6 +41,7 @@ typedef enum _ConfigParamType
CPT_INTEGER, /* Valeur entière */
CPT_ULONG, /* Valeur entière positive */
CPT_STRING, /* Chaîne de caractère */
+ CPT_COLOR, /* Couleur avec transparence */
CPT_COUNT