summaryrefslogtreecommitdiff
path: root/src/gtkext/gtkgraphdisplay.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-03-20 23:04:32 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-03-20 23:04:32 (GMT)
commitff1ce15f6c4b3516d7a34b09dd99abb32a0bd671 (patch)
treee3925ba68b25ca5a73c7547704668cb8fad32ef9 /src/gtkext/gtkgraphdisplay.c
parent86a892e1bf5d3483929da3ea72bfcbfd43f6c6bc (diff)
Introduced zoom in graph view.
Diffstat (limited to 'src/gtkext/gtkgraphdisplay.c')
-rw-r--r--src/gtkext/gtkgraphdisplay.c129
1 files changed, 115 insertions, 14 deletions
diff --git a/src/gtkext/gtkgraphdisplay.c b/src/gtkext/gtkgraphdisplay.c
index 97bb4d3..aeecc0f 100644
--- a/src/gtkext/gtkgraphdisplay.c
+++ b/src/gtkext/gtkgraphdisplay.c
@@ -146,6 +146,9 @@ static GLineCursor *gtk_graph_display_get_cursor(const GtkGraphDisplay *);
/* Place en cache un rendu destiné à l'aperçu graphique rapide. */
static void gtk_graph_display_cache_glance(GtkGraphDisplay *, cairo_t *, const GtkAllocation *, double);
+/* Spécifie l'échelle à appliquer à l'affichage du composant. */
+static void gtk_graph_display_apply_scale(GtkGraphDisplay *, double, double);
+
/* Marque ou non le composant pour une exportation prochaine. */
static void gtk_graph_display_prepare_export(GtkGraphDisplay *, bool);
@@ -205,6 +208,8 @@ static void gtk_graph_display_class_init(GtkGraphDisplayClass *class)
panel_class->get_cursor = (get_cursor_fc)gtk_graph_display_get_cursor;
panel_class->cache_glance = (cache_glance_fc)gtk_graph_display_cache_glance;
+ panel_class->scale = (apply_scale_fc)gtk_graph_display_apply_scale;
+
panel_class->prepare_export = (prepare_export_fc)gtk_graph_display_prepare_export;
}
@@ -470,16 +475,23 @@ static void gtk_graph_display_adjust_scroll_value(GtkGraphDisplay *display, GtkA
static gboolean gtk_graph_display_draw(GtkWidget *widget, cairo_t *cr, GtkGraphDisplay *display)
{
+ GtkDisplayPanel *parent; /* Autre version du composant */
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 */
size_t i; /* Boucle de parcours */
+ parent = GTK_DISPLAY_PANEL(display);
+
/* Eventuel fond pour la zone de compression */
if (display->may_collapsing && !GTK_DISPLAY_PANEL(display)->export)
{
+ cairo_save(cr);
+
+ cairo_scale(cr, parent->scale, parent->scale);
+
/* Préparation du pinceau */
pat_image = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
@@ -555,13 +567,21 @@ static gboolean gtk_graph_display_draw(GtkWidget *widget, cairo_t *cr, GtkGraphD
cairo_surface_destroy(pat_image);
+ cairo_restore(cr);
+
}
/* Dessin des ombres */
+ cairo_save(cr);
+
+ cairo_scale(cr, parent->scale, parent->scale);
+
void draw_shadow(GtkWidget *child, gpointer unused)
{
+ GGraphCluster *cluster; /* Cluster correspondant */
GtkAllocation alloc; /* Emplacement de l'enfant */
+ GtkAllocation area; /* Emplacement à considérer */
gint j; /* Boucle de parcours */
cairo_pattern_t *pattern; /* Zones d'application */
@@ -569,19 +589,30 @@ static gboolean gtk_graph_display_draw(GtkWidget *widget, cairo_t *cr, GtkGraphD
if (!GTK_IS_DISPLAY_PANEL(child))
return;
- gtk_widget_get_allocation(child, &alloc);
+ cluster = g_graph_cluster_find_by_widget(display->cluster, child);
+ assert(cluster != NULL);
+
+ g_graph_cluster_get_allocation(cluster, &alloc);
+
+ alloc.x += GRAPH_MARGIN;
+ alloc.y += GRAPH_MARGIN;
+
+ area = alloc;
for (j = 1; j < SHADOW_SIZE; j++)
{
cairo_push_group(cr);
- gtk_display_panel_define_border_path(GTK_DISPLAY_PANEL(child), cr, alloc.x + j, alloc.y + j);
+ area.x = alloc.x + j;
+ area.y = alloc.y + j;
+
+ gtk_display_panel_define_border_path(GTK_DISPLAY_PANEL(child), cr, &area);
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
cairo_fill(cr);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
- gtk_display_panel_define_border_path(GTK_DISPLAY_PANEL(child), cr, alloc.x, alloc.y);
+ gtk_display_panel_define_border_path(GTK_DISPLAY_PANEL(child), cr, &alloc);
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
cairo_fill(cr);
@@ -602,6 +633,8 @@ static gboolean gtk_graph_display_draw(GtkWidget *widget, cairo_t *cr, GtkGraphD
for (i = 0; i < display->edges_count; i++)
g_graph_edge_draw(display->edges[i], cr, true, display->hl_edge_index == i);
+ cairo_restore(cr);
+
return FALSE;
}
@@ -710,6 +743,7 @@ static gboolean gtk_graph_display_motion_notify(GtkWidget *widget, GdkEventMotio
GtkAdjustment *hadj; /* Gestionnaire du défilement */
GtkAdjustment *vadj; /* Gestionnaire du défilement */
gdouble value; /* Nouvelle valeur bornée */
+ double scale; /* Echelle appliquée au rendu */
size_t i; /* Boucle de parcours */
/* Déplacement du graphique ? */
@@ -739,8 +773,10 @@ static gboolean gtk_graph_display_motion_notify(GtkWidget *widget, GdkEventMotio
/* Survol d'un lien ? */
else
{
+ scale = GTK_DISPLAY_PANEL(display)->scale;
+
for (i = 0; i < display->edges_count; i++)
- if (g_graph_edge_detect_at(display->edges[i], event->x, event->y))
+ if (g_graph_edge_detect_at(display->edges[i], event->x / scale, event->y / scale))
{
display->hl_edge_index = i;
break;
@@ -1131,21 +1167,28 @@ static GLineCursor *gtk_graph_display_get_cursor(const GtkGraphDisplay *display)
static void gtk_graph_display_cache_glance(GtkGraphDisplay *display, cairo_t *cr, const GtkAllocation *area, double scale)
{
+ GtkDisplayPanel *parent; /* Autre version du composant */
size_t i; /* Boucle de parcours */
+ parent = GTK_DISPLAY_PANEL(display);
+
+ cairo_scale(cr, scale * parent->scale, scale * parent->scale);
+
void draw_child_glance(GtkWidget *child, gpointer unused)
{
+ GGraphCluster *cluster; /* Cluster correspondant */
GtkAllocation sub_area; /* Emplacement réservé */
if (!GTK_IS_BUFFER_DISPLAY(child))
return;
- gtk_widget_get_allocation(child, &sub_area);
+ cluster = g_graph_cluster_find_by_widget(display->cluster, child);
+ assert(cluster != NULL);
- sub_area.x *= scale;
- sub_area.y *= scale;
- sub_area.width = sub_area.width * scale + 1;
- sub_area.height = sub_area.height * scale + 1;
+ g_graph_cluster_get_allocation(cluster, &sub_area);
+
+ sub_area.x += GRAPH_MARGIN;
+ sub_area.y += GRAPH_MARGIN;
g_loaded_panel_cache_glance(G_LOADED_PANEL(child), cr, &sub_area, scale);
@@ -1153,8 +1196,6 @@ static void gtk_graph_display_cache_glance(GtkGraphDisplay *display, cairo_t *cr
gtk_container_foreach(GTK_CONTAINER(display->support), (GtkCallback)draw_child_glance, NULL);
- cairo_scale(cr, scale, scale);
-
for (i = 0; i < display->edges_count; i++)
g_graph_edge_draw(display->edges[i], cr, false, false);
@@ -1164,6 +1205,68 @@ static void gtk_graph_display_cache_glance(GtkGraphDisplay *display, cairo_t *cr
/******************************************************************************
* *
* Paramètres : display = composant GTK à mettre à jour. *
+* old = ancienne échelle appliquée. *
+* new = nouvelle échelle à appliquer. *
+* *
+* Description : Spécifie l'échelle à appliquer à l'affichage du composant. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void gtk_graph_display_apply_scale(GtkGraphDisplay *display, double old, double new)
+{
+ GtkDisplayPanel *parent; /* Autre version du composant */
+ gint right; /* Abscisse du coin droit */
+ gint bottom; /* Ordonnée du coin inférieur */
+
+ /* Traitement des blocs */
+
+ void apply_child_scale(GtkWidget *child, gpointer unused)
+ {
+ GGraphCluster *cluster; /* Cluster correspondant */
+ GtkAllocation sub_area; /* Emplacement réservé */
+ gint x; /* Abscisse du point d'arrivée */
+ gint y; /* Ordonnée du point d'arrivée */
+
+ if (!GTK_IS_BUFFER_DISPLAY(child))
+ return;
+
+ cluster = g_graph_cluster_find_by_widget(display->cluster, child);
+ assert(cluster != NULL);
+
+ g_graph_cluster_get_allocation(cluster, &sub_area);
+
+ x = (GRAPH_MARGIN + sub_area.x) * new;
+ y = (GRAPH_MARGIN + sub_area.y) * new;
+
+ gtk_fixed_move(GTK_FIXED(display->support), child, x, y);
+
+ gtk_display_panel_set_scale(GTK_DISPLAY_PANEL(child), new);
+
+ }
+
+ gtk_container_foreach(GTK_CONTAINER(display->support), (GtkCallback)apply_child_scale, NULL);
+
+ /* Calcul du nouvel espace nécessaire */
+
+ parent = GTK_DISPLAY_PANEL(display);
+
+ gtk_graph_display_compute_requested_size(display, &right, &bottom);
+
+ right *= parent->scale;
+ bottom *= parent->scale;
+
+ gtk_fixed_move(GTK_FIXED(display->support), display->extender, right - 1, bottom - 1);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : display = composant GTK à mettre à jour. *
* export = préparation d'une exportation complète du rendu ? *
* *
* Description : Marque ou non le composant pour une exportation prochaine. *
@@ -1238,8 +1341,7 @@ GtkWidget *gtk_graph_display_get_support(GtkGraphDisplay *display)
* *
* Paramètres : display = composant GTK à mettre à jour. *
* widget = composant GTK à insérer. *
-* x = abscisse du point d'insertion. *
-* y = ordonnée du point d'insertion. *
+* alloc = position du point d'insertion. *
* *
* Description : Place une vue sous forme de bloc dans le graphique. *
* *
@@ -1261,7 +1363,6 @@ void gtk_graph_display_put(GtkGraphDisplay *display, GtkWidget *widget, const Gt
}
-
/******************************************************************************
* *
* Paramètres : display = composant GTK à mettre à jour. *