[cairo-commit] cairo-demo/path_paint ChangeLog, 1.8, 1.9 Makefile, 1.2, 1.3 path_paint.c, 1.8, 1.9

Behdad Esfahbod commit at pdx.freedesktop.org
Mon Aug 15 17:22:16 PDT 2005


Committed by: behdad

Update of /cvs/cairo/cairo-demo/path_paint
In directory gabe:/tmp/cvs-serv7594

Modified Files:
	ChangeLog Makefile path_paint.c 
Log Message:
2005-08-15  Behdad Esfahbod  <behdad at behdad.org>

        * path_paint.c: use Gtk+ proper instead of gtkcairo.
        Patch from Behnam Esfahbod. (#4081)



Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/path_paint/ChangeLog,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- ChangeLog	8 Aug 2005 00:31:39 -0000	1.8
+++ ChangeLog	16 Aug 2005 00:22:14 -0000	1.9
@@ -1,3 +1,8 @@
+2005-08-15  Behdad Esfahbod  <behdad at behdad.org>
+
+	* path_paint.c: use Gtk+ proper instead of gtkcairo.
+	Patch from Behnam Esfahbod. (#4081)
+
 2005-08-08  Øyvind Kolås  <pippin at freedesktop.org>
 
 	* path_paint.c: make the default alpha value be 0.5

Index: Makefile
===================================================================
RCS file: /cvs/cairo/cairo-demo/path_paint/Makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Makefile	11 Nov 2004 15:20:56 -0000	1.2
+++ Makefile	16 Aug 2005 00:22:14 -0000	1.3
@@ -1,10 +1,10 @@
 APPS    = path_paint
 
-CFLAGS  = -Wall
+CFLAGS  = -Wall -g
 LDFLAGS = -lm
 
-CFLAGS  += `pkg-config gtkcairo --cflags`
-LDFLAGS += `pkg-config gtkcairo --libs`
+CFLAGS  += `pkg-config gtk+-2.0 --cflags`
+LDFLAGS += `pkg-config gtk+-2.0 --libs`
 
 all: $(APPS) 
 

Index: path_paint.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/path_paint/path_paint.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- path_paint.c	8 Aug 2005 00:31:39 -0000	1.8
+++ path_paint.c	16 Aug 2005 00:22:14 -0000	1.9
@@ -1,6 +1,6 @@
 #include <gtk/gtk.h>
+#include <cairo.h>
 #include <math.h>
-#include <gtkcairo.h>
 #include <gdk/gdkkeysyms.h>
 #include <string.h>
 
@@ -17,7 +17,7 @@
  */
 #define USE_HINT
 
-GtkWidget *gtkcairo = NULL;
+GtkWidget *canvas = NULL;
 
 gboolean pen_color_is_black = TRUE;
 gint     pen_radius         = 8;
@@ -35,51 +35,38 @@
 
 gboolean pen_is_down = FALSE;
 
-void
-destroy ()
-{
-  cairo_destroy (cr_save);
-}
-
-
 /* utility functions, defined at bottom,
  * constructing a path from coordinate arrays
  */
-void
+static void
 points_to_linear_path (cairo_t *cr,
                        gdouble  coord_x[],
                        gdouble  coord_y[],
                        gint     n_coords);
-void
+static void
 points_to_bezier_path (cairo_t *cr,
                        gdouble  coord_x[],
                        gdouble  coord_y[],
                        gint     n_coords);
 
 
-void
+static void
 drawapp_render (cairo_t *cr)
 {
   cairo_save (cr);
 
-  cairo_rectangle (cr, 0,0, WIDTH, HEIGHT);
   cairo_set_source_rgb (cr, 1,1,1);
-  cairo_fill (cr);
+  cairo_paint (cr);
 
   cairo_set_source_surface (cr, back_surface, 0, 0);
-  cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
-  cairo_fill (cr);
+  cairo_paint (cr);
 
   cairo_set_line_width (cr, pen_radius*2);
 
   if (pen_color_is_black)
-    {
       cairo_set_source_rgba (cr, 0,0,0, 0.5);
-    }
   else
-    {
       cairo_set_source_rgba (cr, 1,1,1, 0.5);
-    }
 
   cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
   cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
@@ -90,20 +77,20 @@
   cairo_restore (cr);
 }
 
-void
+static void
 apply_coords (guchar *buffer)
 {
   drawapp_render (cr_save);
   memcpy (buffer, temp_buffer, HEIGHT*STRIDE);
 }
 
-void
+static void
 coords_clear (void)
 {
   coord_count = 0;
 }
 
-void
+static void
 coords_add (gdouble x,
             gdouble y)
 {
@@ -115,47 +102,49 @@
     }
 }
 
-void
-paint (GtkCairo *gtkcairo,
-       cairo_t  *cr,
-       gpointer data)
+static void
+paint (GtkWidget      *widget,
+       GdkEventExpose *eev,
+       gpointer        data)
 {
+  cairo_t *cr;
+  cr = gdk_cairo_create (widget->window);
   drawapp_render (cr);
+  cairo_destroy (cr);
 }
 
-void
+static void
 pen_motion (gdouble  x,
-            gdouble  y,
-            gboolean pen_is_down)
+            gdouble  y)
 {
   if (pen_is_down)
     {
       coords_add (x,y);
-      gtk_widget_queue_draw (gtkcairo);
+      gtk_widget_queue_draw (canvas);
     }
 }
 
-void
+static void
 pen_down (gdouble x,
           gdouble y)
 {
   pen_is_down = TRUE;
   coords_add (x,y);
-  gtk_widget_queue_draw (gtkcairo);
+  gtk_widget_queue_draw (canvas);
 }
 
-void
+static void
 pen_up (gdouble x,
         gdouble y)
 {
   pen_is_down = FALSE;
   apply_coords (buffer);
   coords_clear ();
-  gtk_widget_queue_draw (gtkcairo);
+  gtk_widget_queue_draw (canvas);
 }
 
 
-void
+static void
 init (void)
 {
   coords_clear ();
@@ -169,7 +158,6 @@
   memset (temp_buffer, 0, sizeof(temp_buffer));
 
   cr_save = cairo_create (temp_surface);
-
 }
 
 /* just wrapping the gtk events */
@@ -197,7 +185,7 @@
               GdkEventMotion *mev,
               gpointer        user_data)
 {
-  pen_motion (mev->x, mev->y, pen_is_down);
+  pen_motion (mev->x, mev->y);
   gdk_window_get_pointer (widget->window, NULL, NULL, NULL);
 
   return TRUE;
@@ -212,10 +200,7 @@
     {
       case GDK_x:
       case GDK_X:
-        if (pen_color_is_black)
-          pen_color_is_black = FALSE;
-        else
-          pen_color_is_black = TRUE;
+        pen_color_is_black = !pen_color_is_black;
       default:
         break;
     }
@@ -232,9 +217,9 @@
 
   mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
-  gtkcairo = gtk_cairo_new ();
+  canvas = gtk_drawing_area_new ();
 
-  gtk_widget_set_events (gtkcairo,
+  gtk_widget_set_events (canvas,
                          GDK_EXPOSURE_MASK            |
 #ifdef USE_HINT
                          GDK_POINTER_MOTION_HINT_MASK |
@@ -243,21 +228,23 @@
                          GDK_BUTTON_PRESS_MASK        |
                          GDK_KEY_PRESS_MASK           |
                          GDK_BUTTON_RELEASE_MASK);
-  gtk_widget_set_size_request (gtkcairo, WIDTH, HEIGHT);
+  gtk_widget_set_size_request (canvas, WIDTH, HEIGHT);
 
-  g_signal_connect (G_OBJECT (gtkcairo), "paint",
+  g_signal_connect (mainwin, "destroy",
+		    G_CALLBACK (gtk_main_quit), NULL);
+  g_signal_connect (G_OBJECT (canvas), "expose-event",
                     G_CALLBACK (paint), NULL);
-  g_signal_connect (G_OBJECT (gtkcairo), "motion_notify_event",
+  g_signal_connect (G_OBJECT (canvas), "motion_notify_event",
                     G_CALLBACK (event_motion), NULL);
-  g_signal_connect (G_OBJECT (gtkcairo), "button_press_event",
+  g_signal_connect (G_OBJECT (canvas), "button_press_event",
                     G_CALLBACK (event_press), NULL);
-  g_signal_connect (G_OBJECT (gtkcairo), "button_release_event",
+  g_signal_connect (G_OBJECT (canvas), "button_release_event",
                     G_CALLBACK (event_release), NULL);
-  g_signal_connect (G_OBJECT (gtkcairo), "key_press_event",
+  g_signal_connect (G_OBJECT (canvas), "key_press_event",
                     G_CALLBACK (event_keypress), NULL);
-  g_object_set (G_OBJECT (gtkcairo), "can_focus", 1, NULL);
+  g_object_set (G_OBJECT (canvas), "can_focus", 1, NULL);
 
-  gtk_container_add (GTK_CONTAINER (mainwin), gtkcairo);
+  gtk_container_add (GTK_CONTAINER (mainwin), canvas);
 
   init ();
   gtk_widget_show_all (mainwin);
@@ -272,7 +259,7 @@
 /* utility function that creates a smooth path from a set
  * of coordinates
  */
-void
+static void
 points_to_bezier_path (cairo_t *cr,
                        gdouble  coord_x[],
                        gdouble  coord_y[],
@@ -359,7 +346,7 @@
 /* this function is included, just to be
  * able to check the improvement over the easiest method
  */
-void
+static void
 points_to_linear_path (cairo_t *cr,
                        gdouble  coord_x[],
                        gdouble  coord_y[],



More information about the cairo-commit mailing list