[gtk+/rendering-cleanup-next: 9/153] ruler: Change the way the ruler handles exposes



commit 762f0352e20dbb89b747abf49119f091119b3b92
Author: Benjamin Otte <otte redhat com>
Date:   Thu Sep 2 14:57:16 2010 +0200

    ruler: Change the way the ruler handles exposes
    
    1) Don't directly draw in motion-notify, instead call
       gtk_widget_queue_draw()
    2) Don't draw ticks in expose events anymore, only when they were
       changed

 gtk/gtkruler.c |   36 ++++++++++++++++++++++++++----------
 1 files changed, 26 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkruler.c b/gtk/gtkruler.c
index bd1e071..e71aeff 100644
--- a/gtk/gtkruler.c
+++ b/gtk/gtkruler.c
@@ -306,6 +306,26 @@ gtk_ruler_new (GtkOrientation orientation)
                        NULL);
 }
 
+/**
+ * gtk_ruler_invalidate_ticks:
+ * @ruler: the ruler to invalidate
+ *
+ * For performance reasons, #GtkRuler keeps a backbuffer containing the
+ * prerendered contents of the ticks. To cause a repaint this buffer,
+ * call this function instead of gtk_widget_queue_draw().
+ **/
+static void
+gtk_ruler_invalidate_ticks (GtkRuler *ruler)
+{
+  g_return_if_fail (GTK_IS_RULER (ruler));
+
+  if (ruler->priv->backing_store == NULL)
+    return;
+
+  gtk_ruler_draw_ticks (ruler);
+  gtk_widget_queue_draw (GTK_WIDGET (ruler));
+}
+
 void
 gtk_ruler_set_metric (GtkRuler      *ruler,
 		      GtkMetricType  metric)
@@ -318,10 +338,9 @@ gtk_ruler_set_metric (GtkRuler      *ruler,
 
   priv->metric = (GtkRulerMetric *) &ruler_metrics[metric];
 
-  if (gtk_widget_is_drawable (GTK_WIDGET (ruler)))
-    gtk_widget_queue_draw (GTK_WIDGET (ruler));
-
   g_object_notify (G_OBJECT (ruler), "metric");
+
+  gtk_ruler_invalidate_ticks (ruler);
 }
 
 /**
@@ -398,8 +417,7 @@ gtk_ruler_set_range (GtkRuler *ruler,
     }
   g_object_thaw_notify (G_OBJECT (ruler));
 
-  if (gtk_widget_is_drawable (GTK_WIDGET (ruler)))
-    gtk_widget_queue_draw (GTK_WIDGET (ruler));
+  gtk_ruler_invalidate_ticks (ruler);
 }
 
 /**
@@ -596,9 +614,7 @@ gtk_ruler_motion_notify (GtkWidget      *widget,
 
   g_object_notify (G_OBJECT (ruler), "position");
 
-  /*  Make sure the ruler has been allocated already  */
-  if (priv->backing_store != NULL)
-    gtk_ruler_draw_pos (ruler);
+  gtk_widget_queue_draw (widget);
 
   return FALSE;
 }
@@ -613,8 +629,6 @@ gtk_ruler_expose (GtkWidget      *widget,
       GtkRulerPrivate *priv = ruler->priv;
       cairo_t *cr;
 
-      gtk_ruler_draw_ticks (ruler);
-
       cr = gdk_cairo_create (gtk_widget_get_window (widget));
       cairo_set_source_surface (cr, priv->backing_store, 0, 0);
       gdk_cairo_region (cr, event->region);
@@ -648,6 +662,8 @@ gtk_ruler_make_pixmap (GtkRuler *ruler)
 
   priv->xsrc = 0;
   priv->ysrc = 0;
+
+  gtk_ruler_draw_ticks (ruler);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]