From e2d30b28338f4d2947117bd98b9555915fd55fe0 Mon Sep 17 00:00:00 2001 From: raveit65 Date: Sat, 9 Jul 2016 13:31:18 +0200 Subject: GTK+-3 graph-widget: improve expose --> draw changes taken from: https://git.gnome.org/browse/gnome-power-manager/commit/?id=cd9255c --- src/gpm-graph-widget.c | 63 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/gpm-graph-widget.c b/src/gpm-graph-widget.c index 1f6f9ed..af74ba7 100644 --- a/src/gpm-graph-widget.c +++ b/src/gpm-graph-widget.c @@ -1075,6 +1075,43 @@ gpm_graph_widget_legend_calculate_size (GpmGraphWidget *graph, cairo_t *cr, return TRUE; } +#if GTK_CHECK_VERSION (3, 0, 0) +/** + * gpm_graph_widget_draw: + * @graph: This class instance + * @event: The expose event + * + * Just repaint the entire graph widget on expose. + **/ +static gboolean +gpm_graph_widget_draw (GtkWidget *widget, cairo_t *cr) +{ + GtkAllocation allocation; + gint legend_x = 0; + gint legend_y = 0; + guint legend_height = 0; + guint legend_width = 0; + gfloat data_x; + gfloat data_y; + + GpmGraphWidget *graph = (GpmGraphWidget*) widget; + g_return_val_if_fail (graph != NULL, FALSE); + g_return_val_if_fail (GPM_IS_GRAPH_WIDGET (graph), FALSE); + + gpm_graph_widget_legend_calculate_size (graph, cr, &legend_width, &legend_height); + cairo_save (cr); + + /* we need this so we know the y text */ + if (graph->priv->autorange_x) + gpm_graph_widget_autorange_x (graph); + if (graph->priv->autorange_y) + gpm_graph_widget_autorange_y (graph); + + graph->priv->box_x = gpm_graph_widget_get_y_label_max_width (graph, cr) + 10; + graph->priv->box_y = 5; + + gtk_widget_get_allocation (widget, &allocation); +#else /** * gpm_graph_widget_draw_graph: * @graph: This class instance @@ -1110,6 +1147,7 @@ gpm_graph_widget_draw_graph (GtkWidget *graph_widget, cairo_t *cr) graph->priv->box_y = 5; gtk_widget_get_allocation (graph_widget, &allocation); +#endif graph->priv->box_height = allocation.height - (20 + graph->priv->box_y); /* make size adjustment for legend */ @@ -1142,8 +1180,12 @@ gpm_graph_widget_draw_graph (GtkWidget *graph_widget, cairo_t *cr) gpm_graph_widget_draw_legend (graph, legend_x, legend_y, legend_width, legend_height); cairo_restore (cr); +#if GTK_CHECK_VERSION (3, 0, 0) + return FALSE; +#endif } +#if !GTK_CHECK_VERSION (3, 0, 0) /** * gpm_graph_widget_expose: * @graph: This class instance @@ -1152,25 +1194,8 @@ gpm_graph_widget_draw_graph (GtkWidget *graph_widget, cairo_t *cr) * Just repaint the entire graph widget on expose. **/ static gboolean -#if GTK_CHECK_VERSION (3, 0, 0) -gpm_graph_widget_draw (GtkWidget *graph, cairo_t *cr) -#else gpm_graph_widget_expose (GtkWidget *graph, GdkEventExpose *event) -#endif { -#if GTK_CHECK_VERSION (3, 0, 0) - GdkRectangle area; - gdouble x1, y1, x2, y2; - - cairo_clip_extents (cr, &x1, &y1, &x2, &y2); - area.x = floor (x1); - area.y = floor (y1); - area.width = ceil (x2) - area.x; - area.height = ceil (y2) - area.y; - cairo_rectangle (cr, - area.x, area.y, - area.width, area.height); -#else cairo_t *cr; /* get a cairo_t */ @@ -1178,17 +1203,15 @@ gpm_graph_widget_expose (GtkWidget *graph, GdkEventExpose *event) cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height); -#endif cairo_clip (cr); ((GpmGraphWidget *)graph)->priv->cr = cr; gpm_graph_widget_draw_graph (graph, cr); -#if !GTK_CHECK_VERSION (3, 0, 0) cairo_destroy (cr); -#endif return FALSE; } +#endif /** * gpm_graph_widget_new: -- cgit v1.2.1