summaryrefslogtreecommitdiff
path: root/src/glibext/gbinportion.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2014-09-15 20:30:37 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2014-09-15 20:30:37 (GMT)
commit74642fbdeefaec21885e5fb6cad432e3e3b47cdb (patch)
tree11c5a34a3cdae86feefe6a35052b0384480fee75 /src/glibext/gbinportion.c
parentce8c1719963657aeaf963650183e46979cab0d68 (diff)
Defined a GTK3 style for binary portions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@404 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/glibext/gbinportion.c')
-rw-r--r--src/glibext/gbinportion.c267
1 files changed, 17 insertions, 250 deletions
diff --git a/src/glibext/gbinportion.c b/src/glibext/gbinportion.c
index 2cc9fda..41778ba 100644
--- a/src/glibext/gbinportion.c
+++ b/src/glibext/gbinportion.c
@@ -36,36 +36,6 @@
-/* --------------------------- COULEURS DE REPRESENTATION --------------------------- */
-
-
-/* Information sur une colorisation de portion */
-typedef struct _portion_color
-{
- bp_color_t code; /* Identifiant pour les usages */
- char *name; /* Désignation humaine */
-
- double red; /* Taux de rouge */
- double green; /* Taux de vert */
- double blue; /* Taux de bleu */
- double alpha; /* Transparence */
-
-} portion_color;
-
-
-/* Mémoire centrale... */
-static portion_color *_portion_colors = NULL;
-static size_t _portion_colors_count = 0;
-
-
-/* Compare deux enregistrements de couleur pour portions. */
-static int compare_portion_colors(const portion_color *, const portion_color *);
-
-/* Tente de retrouver une couleur de portion donnée. */
-static portion_color *find_binary_portion_color(bp_color_t);
-
-
-
/* ------------------------------- PORTION DE BINAIRE ------------------------------- */
@@ -76,7 +46,7 @@ struct _GBinPortion
GBinPortion *container; /* Portion parente ou racine */
- bp_color_t code; /* Code de la couleur de fond */
+ char *code; /* Code de la couleur de fond */
char *desc; /* Désignation humaine */
@@ -122,207 +92,6 @@ static bool g_binary_portion_compute_sub_area(GBinPortion *, GBinPortion *, cons
/* ---------------------------------------------------------------------------------- */
-/* COULEURS DE REPRESENTATION */
-/* ---------------------------------------------------------------------------------- */
-
-
-/******************************************************************************
-* *
-* Paramètres : a = échantillon n°1 à comparer. *
-* b = échantillon n°2 à comparer. *
-* *
-* Description : Compare deux enregistrements de couleur pour portions. *
-* *
-* Retour : Bilan de la comparaison. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static int compare_portion_colors(const portion_color *a, const portion_color *b)
-{
- int result; /* Bilan à renvoyer */
-
- if (a->code < b->code)
- result = -1;
-
- else if (a->code > b->code)
- result = 1;
-
- else
- result = 0;
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : name = désignation humaine de la couleur. *
-* red = taux de rouge dans la couleur. *
-* gren = taux de vert dans la couleur. *
-* blue = taux de bleu dans la couleur. *
-* alpha = transparence de la couleur. *
-* *
-* Description : Enregistre une couleur pour le dessin de portions. *
-* *
-* Retour : true si l'enregistrement a pu être effectué, false sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool register_binary_portion_color(const char *name, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
-{
- bp_color_t code; /* Accès rapide à la couleur */
- portion_color *new; /* Nouvel élément à constituer */
-
- /* Vérification de l'unicité des noms */
-
- code = fnv_64a_hash(name);
-
- new = find_binary_portion_color(code);
- if (new != NULL) return false;
-
- /* Création du nouvel élément */
-
- _portion_colors = (portion_color *)realloc(_portion_colors,
- ++_portion_colors_count * sizeof(portion_color));
-
- new = &_portion_colors[_portion_colors_count - 1];
-
- /* Définition du nouvel élément */
-
- new->name = strdup(name);
- new->code = code;
-
- new->red = red / 255.0;
- new->green = green / 255.0;
- new->blue = blue / 255.0;
- new->alpha = alpha / 255.0;
-
- /* Actualisation finale par tri */
-
- qsort(_portion_colors, _portion_colors_count, sizeof(portion_color),
- (__compar_fn_t)compare_portion_colors);
-
- return true;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : name = désignation humaine de la couleur. *
-* *
-* Description : Supprime une couleur pour le dessin de portions. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void unregister_binary_portion_color(const char *name)
-{
- bp_color_t code; /* Accès rapide à la couleur */
- portion_color *item; /* Elément à retirer */
- size_t left; /* Quantité à déplacer */
-
- code = fnv_64a_hash(name);
-
- item = find_binary_portion_color(code);
- if (item == NULL) return;
-
- free(item->name);
-
- left = (size_t)(_portion_colors + _portion_colors_count) - (size_t)(item + 1);
-
- if (left > 0)
- memmove(item, item + 1, left);
-
- _portion_colors = (portion_color *)realloc(_portion_colors,
- --_portion_colors_count * sizeof(portion_color));
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : code = identifiant de la couleur à retrouver. *
-* *
-* Description : Tente de retrouver une couleur de portion donnée. *
-* *
-* Retour : Caractéristiques de la couleur visée, ou NULL. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static portion_color *find_binary_portion_color(bp_color_t code)
-{
- portion_color *result; /* Elément trouvé à retourner */
-
- result = (portion_color *)bsearch(&code, _portion_colors,
- _portion_colors_count, sizeof(portion_color),
- (__compar_fn_t)compare_portion_colors);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : - *
-* *
-* Description : Enregistre les couleurs de base pour le dessin des portions. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void init_binary_portion_colors(void)
-{
- register_binary_portion_color(BPC_RAW, 0, 0, 0, 255);
- register_binary_portion_color(BPC_CODE, 0, 0, 255, 255);
- register_binary_portion_color(BPC_DATA, 255, 255, 0, 255);
- register_binary_portion_color(BPC_DATA_RO, 0, 255, 0, 255);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : - *
-* *
-* Description : Supprime les couleurs de base pour le dessin des portions. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void exit_binary_portion_colors(void)
-{
- while (_portion_colors_count > 0)
- unregister_binary_portion_color(_portion_colors[0].name);
-
- if (_portion_colors != NULL)
- {
- free(_portion_colors);
- _portion_colors = NULL;
- }
-
-}
-
-
-
-/* ---------------------------------------------------------------------------------- */
/* PORTION DE BINAIRE */
/* ---------------------------------------------------------------------------------- */
@@ -412,6 +181,8 @@ static void g_binary_portion_dispose(GBinPortion *portion)
static void g_binary_portion_finalize(GBinPortion *portion)
{
+ free(portion->code);
+
if (portion->desc != NULL)
free(portion->desc);
@@ -441,7 +212,7 @@ GBinPortion *g_binary_portion_new(const char *code)
result = g_object_new(G_TYPE_BIN_PORTION, NULL);
- result->code = fnv_64a_hash(code);
+ result->code = strdup(code);
return result;
@@ -874,6 +645,11 @@ gboolean g_binary_portion_query_tooltip(GBinPortion *portion, gint x, gint y, co
+extern GtkCssProvider *__provider; /* Fournisseur par défaut */
+
+
+
+
/******************************************************************************
* *
* Paramètres : portion = description de partie à consulter. *
@@ -888,36 +664,27 @@ gboolean g_binary_portion_query_tooltip(GBinPortion *portion, gint x, gint y, co
* *
******************************************************************************/
-void g_binary_portion_draw(GBinPortion *portion, cairo_t *cr, const GdkRectangle *area)
+void g_binary_portion_draw(GBinPortion *portion, GtkStyleContext *context, cairo_t *cr, const GdkRectangle *area)
{
- portion_color *color; /* Couleur du fond */
size_t i; /* Boucle de parcours */
GBinPortion *sub; /* Portion incluse à montrer */
GdkRectangle sub_area; /* Etendue d'une sous-portion */
/* Dessin de la portion courante */
- cairo_set_line_width(cr, 1.0);
+ //cairo_set_line_width(cr, 1.0);
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
- color = find_binary_portion_color(portion->code);
+ gtk_style_context_save(context);
- if (color != NULL)
- cairo_set_source_rgba(cr,
- color->red, color->green, color->blue,
- color->alpha);
+ gtk_style_context_add_class(context, portion->code);
- cairo_rectangle(cr, area->x, area->y, area->width, area->height);
- cairo_fill(cr);
+ gtk_render_background(context, cr, area->x, area->y, area->width, area->height);
- if (color != NULL)
- cairo_set_source_rgba(cr,
- color->red * 0.7, color->green * 0.7, color->blue * 0.7,
- color->alpha);
+ gtk_render_frame(context, cr, area->x, area->y, area->width, area->height);
- cairo_rectangle(cr, area->x, area->y, area->width, area->height);
- cairo_stroke(cr);
+ gtk_style_context_restore(context);
/* Dessin des portions incluses */
@@ -931,7 +698,7 @@ void g_binary_portion_draw(GBinPortion *portion, cairo_t *cr, const GdkRectangle
if (!g_binary_portion_compute_sub_area(portion, sub, area, &sub_area))
continue;
- g_binary_portion_draw(sub, cr, &sub_area);
+ g_binary_portion_draw(sub, context, cr, &sub_area);
}