summaryrefslogtreecommitdiff
path: root/src/gtkext/gtkgraphdisplay.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-03-01 14:57:19 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-03-01 14:57:19 (GMT)
commit72bebbd9dc7d59f69e23442b6c5b5526feb2a1a9 (patch)
tree94506e5bce1f511a3704a7f7d505ceb91432b23d /src/gtkext/gtkgraphdisplay.c
parent1dae3be2d0860b601d780583365ea7827a6a1be6 (diff)
Drawn a preview of blocks to collapse in graph view.
Diffstat (limited to 'src/gtkext/gtkgraphdisplay.c')
-rw-r--r--src/gtkext/gtkgraphdisplay.c150
1 files changed, 150 insertions, 0 deletions
diff --git a/src/gtkext/gtkgraphdisplay.c b/src/gtkext/gtkgraphdisplay.c
index 72519a2..fb89b2e 100644
--- a/src/gtkext/gtkgraphdisplay.c
+++ b/src/gtkext/gtkgraphdisplay.c
@@ -25,6 +25,7 @@
#include <assert.h>
+#include <math.h>
#include <i18n.h>
@@ -55,6 +56,8 @@ struct _GtkGraphDisplay
segcnt_list *highlighted; /* Segments mis en évidence */
GGraphCluster *cluster; /* Disposition en graphique */
+ GtkAllocation collapsing_area; /* Aire à compresser */
+ bool may_collapsing; /* Validité de cette aire */
GGraphEdge **edges; /* Liens entre les noeuds */
size_t edges_count; /* Quantité de ces liens */
@@ -82,6 +85,9 @@ struct _GtkGraphDisplayClass
/* Marges en bordure de graphique */
#define GRAPH_MARGIN 23
+/* Taille du cadrillage pour l'aperçu des compressions */
+#define COLLAPSING_GRID_SIZE 4
+
/* Initialise la classe générique des graphiques de code. */
static void gtk_graph_display_class_init(GtkGraphDisplayClass *);
@@ -149,6 +155,9 @@ static void gtk_graph_display_changed_highlights(GtkBlockDisplay *, GtkGraphDisp
/* Notifie une incapacité de déplacement au sein d'un noeud. */
static void gtk_graph_display_reach_caret_limit(GtkBufferDisplay *, GdkScrollDirection, GtkGraphDisplay *);
+/* Prend note de la proximité d'une compression de blocs. */
+static void gtk_graph_display_prepare_collasping(GtkBufferDisplay *, gboolean, GtkGraphDisplay *);
+
/* Détermine le type du composant d'affichage en graphique. */
@@ -457,6 +466,93 @@ static void gtk_graph_display_adjust_scroll_value(GtkGraphDisplay *display, GtkA
static gboolean gtk_graph_display_draw(GtkWidget *widget, cairo_t *cr, GtkGraphDisplay *display)
{
size_t i; /* Boucle de parcours */
+ cairo_surface_t *pat_image; /* Fond du futur pinceau */
+ cairo_t *pat_cr; /* Pinceau pour le pinceau */
+ cairo_pattern_t *pattern; /* Patron de remplissage */
+ double degrees; /* Conversion en degrés */
+
+ /* Eventuel fond pour la zone de compression */
+
+ if (display->may_collapsing)
+ {
+ /* Préparation du pinceau */
+
+ pat_image = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+ 2 * COLLAPSING_GRID_SIZE, 2 * COLLAPSING_GRID_SIZE);
+
+ pat_cr = cairo_create(pat_image);
+
+ cairo_set_source_rgba(pat_cr, 1.0, 1.0, 1.0, 0.05);
+
+ cairo_rectangle(pat_cr,
+ 0, 0,
+ COLLAPSING_GRID_SIZE, COLLAPSING_GRID_SIZE);
+
+ cairo_fill(pat_cr);
+
+ cairo_rectangle(pat_cr,
+ COLLAPSING_GRID_SIZE, COLLAPSING_GRID_SIZE,
+ COLLAPSING_GRID_SIZE, COLLAPSING_GRID_SIZE);
+
+ cairo_fill(pat_cr);
+
+ pattern = cairo_pattern_create_for_surface(pat_image);
+ cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
+
+
+ /* Dessin de la zone */
+
+ degrees = M_PI / 180.0;
+
+ cairo_arc(cr,
+ display->collapsing_area.x + BORDER_CORNER_RADIUS,
+ display->collapsing_area.y + BORDER_CORNER_RADIUS,
+ BORDER_CORNER_RADIUS, 180 * degrees, 270 * degrees);
+
+ cairo_line_to(cr,
+ display->collapsing_area.x + display->collapsing_area.width - BORDER_CORNER_RADIUS,
+ display->collapsing_area.y);
+
+ cairo_arc(cr,
+ display->collapsing_area.x + display->collapsing_area.width - BORDER_CORNER_RADIUS,
+ display->collapsing_area.y + BORDER_CORNER_RADIUS,
+ BORDER_CORNER_RADIUS, 270 * degrees, 360 * degrees);
+
+ cairo_line_to(cr,
+ display->collapsing_area.x + display->collapsing_area.width,
+ display->collapsing_area.y + display->collapsing_area.height - BORDER_CORNER_RADIUS);
+
+ cairo_arc(cr,
+ display->collapsing_area.x + display->collapsing_area.width - BORDER_CORNER_RADIUS,
+ display->collapsing_area.y + display->collapsing_area.height - BORDER_CORNER_RADIUS,
+ BORDER_CORNER_RADIUS, 0 * degrees, 90 * degrees);
+
+ cairo_line_to(cr,
+ display->collapsing_area.x + BORDER_CORNER_RADIUS,
+ display->collapsing_area.y + display->collapsing_area.height);
+
+ cairo_arc(cr,
+ display->collapsing_area.x + BORDER_CORNER_RADIUS,
+ display->collapsing_area.y + display->collapsing_area.height - BORDER_CORNER_RADIUS,
+ BORDER_CORNER_RADIUS, 90 * degrees, 180 * degrees);
+
+ cairo_close_path(cr);
+
+ cairo_set_source(cr, pattern);
+
+ cairo_fill(cr);
+
+ /* Sortie propre */
+
+ cairo_pattern_destroy(pattern);
+
+ cairo_destroy(pat_cr);
+
+ cairo_surface_destroy(pat_image);
+
+ }
+
+ /* Dessin des ombres */
void draw_shadow(GtkWidget *child, gpointer unused)
{
@@ -1098,6 +1194,7 @@ GtkWidget *gtk_graph_display_new(void)
void gtk_graph_display_put(GtkGraphDisplay *display, GtkWidget *widget, const GtkAllocation *alloc)
{
g_signal_connect(widget, "reach-limit", G_CALLBACK(gtk_graph_display_reach_caret_limit), display);
+ g_signal_connect(widget, "prepare-collapsing", G_CALLBACK(gtk_graph_display_prepare_collasping), display);
g_signal_connect(widget, "highlight-changed", G_CALLBACK(gtk_graph_display_changed_highlights), display);
gtk_fixed_put(GTK_FIXED(display->support), widget, GRAPH_MARGIN + alloc->x, GRAPH_MARGIN + alloc->y);
@@ -1180,6 +1277,8 @@ static void gtk_graph_display_reset(GtkGraphDisplay *display, bool dispose)
display->cluster = NULL;
}
+ display->may_collapsing = false;
+
for (i = 0; i < display->edges_count; i++)
g_object_unref(G_OBJECT(display->edges[i]));
@@ -1422,3 +1521,54 @@ static void gtk_graph_display_reach_caret_limit(GtkBufferDisplay *node, GdkScrol
/* TODO : scrolling... */
#endif
}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = composant d'affichage impliqué dans la procédure. *
+* done = indique si la préparation est à jeter. *
+* display = support graphique de tous les noeuds. *
+* *
+* Description : Prend note de la proximité d'une compression de blocs. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void gtk_graph_display_prepare_collasping(GtkBufferDisplay *node, gboolean done, GtkGraphDisplay *display)
+{
+ GGraphCluster *cluster; /* Ensemble à priori concerné */
+
+ if (!done)
+ {
+ cluster = g_graph_cluster_find_by_widget(display->cluster, GTK_WIDGET(node));
+
+ if (cluster == NULL)
+ done = TRUE;
+
+ else
+ {
+ g_graph_cluster_compute_needed_alloc(cluster, &display->collapsing_area);
+ g_object_unref(G_OBJECT(cluster));
+
+ display->collapsing_area.x += GRAPH_MARGIN;
+ display->collapsing_area.y += GRAPH_MARGIN;
+
+ assert(BORDER_CORNER_RADIUS < GRAPH_MARGIN);
+
+ display->collapsing_area.x -= BORDER_CORNER_RADIUS;
+ display->collapsing_area.y -= BORDER_CORNER_RADIUS;
+ display->collapsing_area.width += 2 * BORDER_CORNER_RADIUS;
+ display->collapsing_area.height += 2 * BORDER_CORNER_RADIUS;
+
+ }
+
+ }
+
+ display->may_collapsing = !done;
+
+ gtk_widget_queue_draw(GTK_WIDGET(display));
+
+}