[cairo-commit] cairo-demo/svgspacewar ChangeLog, 1.2, 1.3 Makefile, 1.1, 1.2 svgspacewar.c, 1.1, 1.2

Carl Worth commit at pdx.freedesktop.org
Tue Jun 21 08:28:25 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo-demo/svgspacewar
In directory gabe:/tmp/cvs-serv22336

Modified Files:
	ChangeLog Makefile svgspacewar.c 
Log Message:


        From Nigel Tao <nigel.tao at myrealbox.com>:

        * Makefile:
        * svgspacewar.c: (main), (on_expose_event), (draw_energy_bar),
        (draw_ship_body), (draw_flare), (draw_turning_flare),
        (draw_missile), (draw_exploded_missile), (draw_star),
        (show_text_message): Track changes in cairo API, bringing things
        up to work with cairo 0.5.0. Now uses cairo support in GTK+
        rather than using gtkcairo.


Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/svgspacewar/ChangeLog,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ChangeLog	31 Mar 2005 14:41:20 -0000	1.2
+++ ChangeLog	21 Jun 2005 15:28:23 -0000	1.3
@@ -1,3 +1,15 @@
+2005-06-21  Carl Worth  <cworth at cworth.org>
+
+	From Nigel Tao <nigel.tao at myrealbox.com>:
+
+	* Makefile:
+	* svgspacewar.c: (main), (on_expose_event), (draw_energy_bar),
+	(draw_ship_body), (draw_flare), (draw_turning_flare),
+	(draw_missile), (draw_exploded_missile), (draw_star),
+	(show_text_message): Track changes in cairo API, bringing things
+	up to work with cairo 0.5.0. Now uses cairo support in GTK+
+	rather than using gtkcairo.
+
 2005-03-31  Øyvind Kolås  <pippin at freedesktop.org>
 
 	* .cvsignore: added svgspacewar

Index: Makefile
===================================================================
RCS file: /cvs/cairo/cairo-demo/svgspacewar/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile	31 Mar 2005 14:37:58 -0000	1.1
+++ Makefile	21 Jun 2005 15:28:23 -0000	1.2
@@ -5,8 +5,8 @@
 
 CFLAGS  = -g -Wall
 
-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: svgspacewar.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/svgspacewar/svgspacewar.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- svgspacewar.c	31 Mar 2005 14:37:58 -0000	1.1
+++ svgspacewar.c	21 Jun 2005 15:28:23 -0000	1.2
@@ -10,7 +10,6 @@
 #include <time.h>
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
-#include <gtkcairo.h>
 #include <sys/timeb.h>
 
 #define WIDTH  800
@@ -139,11 +138,11 @@
 static void init_stars_array (void);
 static void init_trigonometric_tables (void);
 static void on_collision (player_t *, missile_t *);
+static gint on_expose_event (GtkWidget *, GdkEventExpose *);
 static gint on_key_event (GtkWidget *, GdkEventKey *, gboolean);
 static gint on_key_press (GtkWidget *, GdkEventKey *);
 static gint on_key_release (GtkWidget *, GdkEventKey *);
 static gint on_timeout (gpointer);
-static void paint (GtkWidget *, cairo_t *, gpointer);
 static void reset ();
 static void scale_for_aspect_ratio (cairo_t *, int, int);
 static void show_text_message (cairo_t *, int, int, const char *);
@@ -233,7 +232,6 @@
   reset ();
 
   GtkWidget *window;
-  GtkWidget *gtkcairo;
 
   gtk_init (&argc, &argv);
 
@@ -241,17 +239,16 @@
   g_signal_connect (G_OBJECT (window), "delete-event",
 		    G_CALLBACK (gtk_main_quit), NULL);
 
-  gtkcairo = gtk_cairo_new ();
   gtk_window_set_default_size (GTK_WINDOW (window), WIDTH, HEIGHT);
 
-  g_signal_connect (G_OBJECT (gtkcairo), "paint", G_CALLBACK (paint), NULL);
+  g_signal_connect (G_OBJECT (window), "expose_event",
+		    G_CALLBACK (on_expose_event), NULL);
   g_signal_connect (G_OBJECT (window), "key_press_event",
 		    G_CALLBACK (on_key_press), NULL);
   g_signal_connect (G_OBJECT (window), "key_release_event",
 		    G_CALLBACK (on_key_release), NULL);
-  g_timeout_add (MILLIS_PER_FRAME, (GSourceFunc) on_timeout, gtkcairo);
+  g_timeout_add (MILLIS_PER_FRAME, (GSourceFunc) on_timeout, window);
 
-  gtk_container_add (GTK_CONTAINER (window), gtkcairo);
   gtk_widget_show_all (window);
   gtk_main ();
 
@@ -270,9 +267,10 @@
 
 //------------------------------------------------------------------------------
 
-static void
-paint (GtkWidget * widget, cairo_t * cr, void *data)
+static gint
+on_expose_event (GtkWidget * widget, GdkEventExpose * event)
 {
+  cairo_t *cr = gdk_cairo_create (widget->window);
   int i;
   long start_time;
   if (show_fps)
@@ -288,9 +286,9 @@
   cairo_scale (cr, debug_scale_factor, debug_scale_factor);
 
   cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
-  cairo_set_rgb_color (cr, 0.1, 0.0, 0.1);
+  cairo_set_source_rgb (cr, 0.1, 0.0, 0.1);
   cairo_clip (cr);
-  cairo_fill (cr);
+  cairo_paint (cr);
 
   // draw any stars...
   for (i = 0; i < NUMBER_OF_STARS; i++)
@@ -380,6 +378,9 @@
 	  millis_taken_for_frames = 0L;
 	}
     }
+
+  cairo_destroy (cr);
+  return TRUE;
 }
 
 //------------------------------------------------------------------------------
@@ -421,19 +422,20 @@
   cairo_save (cr);
   cairo_pattern_t *pat =
     cairo_pattern_create_linear (0, 0, SHIP_MAX_ENERGY / 5, 0);
-  cairo_pattern_add_color_stop (pat, 0,
-				p->secondary_color.r, p->secondary_color.g,
-				p->secondary_color.b, alpha);
-  cairo_pattern_add_color_stop (pat, 1, p->primary_color.r,
-				p->primary_color.g, p->primary_color.b,
-				alpha);
+  cairo_pattern_add_color_stop_rgba (pat, 0,
+				     p->secondary_color.r,
+				     p->secondary_color.g,
+				     p->secondary_color.b, alpha);
+  cairo_pattern_add_color_stop_rgba (pat, 1, p->primary_color.r,
+				     p->primary_color.g, p->primary_color.b,
+				     alpha);
 
-  cairo_set_pattern (cr, pat);
+  cairo_set_source (cr, pat);
   cairo_fill (cr);
   cairo_pattern_destroy (pat);
   cairo_restore (cr);
 
-  cairo_set_rgb_color (cr, 0, 0, 0);
+  cairo_set_source_rgb (cr, 0, 0, 0);
   cairo_stroke (cr);
   cairo_restore (cr);
 }
@@ -446,9 +448,8 @@
   if (p->is_hit)
     {
       cairo_save (cr);
-      cairo_set_rgb_color (cr, p->primary_color.r, p->primary_color.g,
-			   p->primary_color.b);
-      cairo_set_alpha (cr, 0.5);
+      cairo_set_source_rgba (cr, p->primary_color.r, p->primary_color.g,
+			     p->primary_color.b, 0.5);
       cairo_arc (cr, 0, 0, SHIP_RADIUS / FIXED_POINT_SCALE_FACTOR, 0, TWO_PI);
       cairo_stroke (cr);
       cairo_restore (cr);
@@ -495,19 +496,19 @@
   cairo_save (cr);
   cairo_pattern_t *pat =
     cairo_pattern_create_linear (-30.0, -30.0, 30.0, 30.0);
-  cairo_pattern_add_color_stop (pat, 0,
-				p->primary_color.r, p->primary_color.g,
-				p->primary_color.b, 1);
-  cairo_pattern_add_color_stop (pat, 1, p->secondary_color.r,
-				p->secondary_color.g, p->secondary_color.b,
-				1);
+  cairo_pattern_add_color_stop_rgba (pat, 0,
+				     p->primary_color.r, p->primary_color.g,
+				     p->primary_color.b, 1);
+  cairo_pattern_add_color_stop_rgba (pat, 1, p->secondary_color.r,
+				     p->secondary_color.g,
+				     p->secondary_color.b, 1);
 
-  cairo_set_pattern (cr, pat);
+  cairo_set_source (cr, pat);
   cairo_fill (cr);
   cairo_pattern_destroy (pat);
   cairo_restore (cr);
 
-  cairo_set_rgb_color (cr, 0, 0, 0);
+  cairo_set_source_rgb (cr, 0, 0, 0);
   cairo_stroke (cr);
   cairo_restore (cr);
   cairo_restore (cr);
@@ -522,10 +523,10 @@
   cairo_translate (cr, 0, 22);
   cairo_pattern_t *pat = cairo_pattern_create_radial (0, 0, 2, 0, 5, 12);
 
-  cairo_pattern_add_color_stop (pat, 0.0, color.r, color.g, color.b, 1);
-  cairo_pattern_add_color_stop (pat, 0.3, 1, 1, 1, 1);
-  cairo_pattern_add_color_stop (pat, 1.0, color.r, color.g, color.b, 0);
-  cairo_set_pattern (cr, pat);
+  cairo_pattern_add_color_stop_rgba (pat, 0.0, color.r, color.g, color.b, 1);
+  cairo_pattern_add_color_stop_rgba (pat, 0.3, 1, 1, 1, 1);
+  cairo_pattern_add_color_stop_rgba (pat, 1.0, color.r, color.g, color.b, 0);
+  cairo_set_source (cr, pat);
   cairo_arc (cr, 0, 0, 20, 0, TWO_PI);
   cairo_fill (cr);
   cairo_pattern_destroy (pat);
@@ -540,9 +541,9 @@
   cairo_save (cr);
   cairo_pattern_t *pat = cairo_pattern_create_radial (0, 0, 1, 0, 0, 7);
 
-  cairo_pattern_add_color_stop (pat, 0.0, 1, 1, 1, 1);
-  cairo_pattern_add_color_stop (pat, 1.0, color.r, color.g, color.b, 0);
-  cairo_set_pattern (cr, pat);
+  cairo_pattern_add_color_stop_rgba (pat, 0.0, 1, 1, 1, 1);
+  cairo_pattern_add_color_stop_rgba (pat, 1.0, color.r, color.g, color.b, 0);
+  cairo_set_source (cr, pat);
 
   cairo_save (cr);
   cairo_translate (cr, -23 * right_hand_side, 28);
@@ -587,14 +588,15 @@
       cairo_curve_to (cr, -4, -2, -3, -4, 0, -4);
 
       pat = cairo_pattern_create_linear (0.0, -5.0, 0.0, 5.0);
-      cairo_pattern_add_color_stop (pat, 0,
-				    m->primary_color.r, m->primary_color.g,
-				    m->primary_color.b, alpha);
-      cairo_pattern_add_color_stop (pat, 1, m->secondary_color.r,
-				    m->secondary_color.g,
-				    m->secondary_color.b, alpha);
+      cairo_pattern_add_color_stop_rgba (pat, 0,
+					 m->primary_color.r,
+					 m->primary_color.g,
+					 m->primary_color.b, alpha);
+      cairo_pattern_add_color_stop_rgba (pat, 1, m->secondary_color.r,
+					 m->secondary_color.g,
+					 m->secondary_color.b, alpha);
 
-      cairo_set_pattern (cr, pat);
+      cairo_set_source (cr, pat);
       cairo_fill (cr);
       cairo_pattern_destroy (pat);
       cairo_restore (cr);
@@ -603,14 +605,15 @@
       cairo_arc (cr, 0, 0, 3, 0, TWO_PI);
 
       pat = cairo_pattern_create_linear (0, 3, 0, -3);
-      cairo_pattern_add_color_stop (pat, 0,
-				    m->primary_color.r, m->primary_color.g,
-				    m->primary_color.b, alpha);
-      cairo_pattern_add_color_stop (pat, 1, m->secondary_color.r,
-				    m->secondary_color.g,
-				    m->secondary_color.b, alpha);
+      cairo_pattern_add_color_stop_rgba (pat, 0,
+					 m->primary_color.r,
+					 m->primary_color.g,
+					 m->primary_color.b, alpha);
+      cairo_pattern_add_color_stop_rgba (pat, 1, m->secondary_color.r,
+					 m->secondary_color.g,
+					 m->secondary_color.b, alpha);
 
-      cairo_set_pattern (cr, pat);
+      cairo_set_source (cr, pat);
       cairo_fill (cr);
       cairo_pattern_destroy (pat);
       cairo_restore (cr);
@@ -636,15 +639,15 @@
   cairo_arc (cr, 0, 0, 30, 0, TWO_PI);
 
   pat = cairo_pattern_create_radial (0, 0, 0, 0, 0, 30);
-  cairo_pattern_add_color_stop (pat, 0,
-				m->primary_color.r, m->primary_color.g,
-				m->primary_color.b, alpha);
-  cairo_pattern_add_color_stop (pat, 0.5, m->secondary_color.r,
-				m->secondary_color.g, m->secondary_color.b,
-				alpha * 0.75);
-  cairo_pattern_add_color_stop (pat, 1, 0, 0, 0, 0);
+  cairo_pattern_add_color_stop_rgba (pat, 0,
+				     m->primary_color.r, m->primary_color.g,
+				     m->primary_color.b, alpha);
+  cairo_pattern_add_color_stop_rgba (pat, 0.5, m->secondary_color.r,
+				     m->secondary_color.g,
+				     m->secondary_color.b, alpha * 0.75);
+  cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 0);
 
-  cairo_set_pattern (cr, pat);
+  cairo_set_source (cr, pat);
   cairo_fill (cr);
   cairo_pattern_destroy (pat);
   cairo_restore (cr);
@@ -681,7 +684,7 @@
 		 r2 * sin_table[9 * a] / FIXED_POINT_SCALE_FACTOR);
 
   float c = 0.5;
-  cairo_set_rgb_color (cr, c, c, c);
+  cairo_set_source_rgb (cr, c, c, c);
   cairo_fill (cr);
 }
 
@@ -950,16 +953,15 @@
   cairo_save (cr);
   cairo_text_extents_t extents;
 
-  cairo_select_font (cr, "Serif",
-		     CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
+  cairo_select_font_face (cr, "Serif",
+			  CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
 
-  cairo_scale_font (cr, font_size);
+  cairo_set_font_size (cr, font_size);
   cairo_text_extents (cr, message, &extents);
   double x = (WIDTH / 2) - (extents.width / 2 + extents.x_bearing);
   double y = (HEIGHT / 2) - (extents.height / 2 + extents.y_bearing);
 
-  cairo_set_rgb_color (cr, 1, 1, 1);
-  cairo_set_alpha (cr, 1);
+  cairo_set_source_rgba (cr, 1, 1, 1, 1);
   cairo_move_to (cr, x, y + dy);
   cairo_show_text (cr, message);
   cairo_restore (cr);




More information about the cairo-commit mailing list