[gtk+] tests: Use drawing area in testellipsise



commit 4a604cf9273378ad7bef7352f5579073789cf766
Author: Benjamin Otte <otte redhat com>
Date:   Fri Nov 18 22:37:41 2016 +0100

    tests: Use drawing area in testellipsise

 tests/testellipsise.c |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)
---
diff --git a/tests/testellipsise.c b/tests/testellipsise.c
index e8d4220..52ea06f 100644
--- a/tests/testellipsise.c
+++ b/tests/testellipsise.c
@@ -62,11 +62,14 @@ scale_changed_cb (GtkRange *range,
   redraw_event_box (label);
 }
 
-static gboolean
-ebox_draw_cb (GtkWidget *widget,
-              cairo_t   *cr,
-              gpointer   data)
+static void
+overlay_draw (GtkDrawingArea *da,
+              cairo_t        *cr,
+              int             width,
+              int             height,
+              gpointer        data)
 {
+  GtkWidget *widget = GTK_WIDGET (da);
   PangoLayout *layout;
   const double dashes[] = { 6, 18 };
   GtkAllocation label_allocation;
@@ -78,7 +81,8 @@ ebox_draw_cb (GtkWidget *widget,
   cairo_set_line_width (cr, 1);
 
   cairo_set_source_rgb (cr, 1, 1, 1);
-  cairo_paint (cr);
+  cairo_rectangle (cr, 0, 0, width, height);
+  cairo_fill (cr);
 
   gtk_widget_translate_coordinates (label, widget, 0, 0, &x, &y);
   layout = gtk_widget_create_pango_layout (widget, "");
@@ -115,15 +119,13 @@ ebox_draw_cb (GtkWidget *widget,
   cairo_set_source_rgb (cr, 0.2, 0.8, 0.2);
   cairo_set_dash (cr, dashes, 2, 12.5);
   cairo_stroke (cr);
-
-  return FALSE;
 }
 
 int
 main (int argc, char *argv[])
 {
   GtkWidget *window, *vbox, *label;
-  GtkWidget *combo, *scale, *ebox;
+  GtkWidget *combo, *scale, *overlay, *da;
 
   gtk_init (&argc, &argv);
 
@@ -148,18 +150,22 @@ main (int argc, char *argv[])
   gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
   gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
 
-  ebox = gtk_event_box_new ();
-  gtk_container_add (GTK_CONTAINER (ebox), label);
+  da = gtk_drawing_area_new ();
+  gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), overlay_draw, label, NULL);
+
+  overlay = gtk_overlay_new ();
+  gtk_container_add (GTK_CONTAINER (overlay), da);
+  gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
 
   gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, TRUE);
   gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, TRUE);
-  gtk_box_pack_start (GTK_BOX (vbox), ebox, TRUE, TRUE);
+  gtk_box_pack_start (GTK_BOX (vbox), overlay, TRUE, TRUE);
 
   g_object_set_data (G_OBJECT (label), "combo", combo);
 
   g_signal_connect (combo, "changed", G_CALLBACK (combo_changed_cb), label);
   g_signal_connect (scale, "value-changed", G_CALLBACK (scale_changed_cb), label);
-  g_signal_connect (ebox, "draw", G_CALLBACK (ebox_draw_cb), label);
+
 
   gtk_widget_show_all (window);
 


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