[cairo-commit] cairo-demo/gtkcairo_slide .cvsignore, NONE, 1.1 ChangeLog, 1.6, 1.7 README, 1.1, 1.2 cairo_custom.c, 1.4, 1.5 cairo_custom.h, 1.4, 1.5 gtkcairo_slide.c, 1.2, 1.3 puzzle.c, 1.6, 1.7

OEyvind Kolaas commit at pdx.freedesktop.org
Thu Nov 11 09:18:49 PST 2004


Committed by: pippin

Update of /cvs/cairo/cairo-demo/gtkcairo_slide
In directory gabe:/tmp/cvs-serv19676

Modified Files:
	ChangeLog README cairo_custom.c cairo_custom.h 
	gtkcairo_slide.c puzzle.c 
Added Files:
	.cvsignore 
Log Message:
code cleanups

--- NEW FILE: .cvsignore ---
gtkcairo_slide

Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtkcairo_slide/ChangeLog,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ChangeLog	23 Jun 2004 03:34:06 -0000	1.6
+++ ChangeLog	11 Nov 2004 17:18:47 -0000	1.7
@@ -1,21 +1,31 @@
-2004-06-23 OEyvind Kolaas <pippin at freedesktop.org>
+2004-11-11  Oeyvind Kolaas  <pippin at freedesktop.org>
+
+	* *.[ch]: reindentation to GNU coding style, and general code
+	cleanups.
+
+2004-06-23  OEyvind Kolaas  <pippin at freedesktop.org>
+
 	* puzzle.c : moved the font selection out of the loop drawing the
 	pieces, this leads to a speedup making gtkcairo_slide useable.
 
-2004-05-13 OEyvind Kolaas <pippin at freedesktop.org>
+2004-05-13  OEyvind Kolaas  <pippin at freedesktop.org>
+
 	* *.[ch] : removed gdk_cairo_set_color, replaced with
-    gtk_cairo_set_gdk_color from GtkCairo
+        gtk_cairo_set_gdk_color from GtkCairo
+
+2004-05-11  OEyvind Kolaas  <pippin at freedesktop.org>
 
-2004-05-11 OEyvind Kolaas <pippin at freedesktop.org>
 	* *.[ch] : replacing ct with cr
 
-2004-03-01 OEyvind Kolaas <pippin at freedesktop.org>
+2004-03-01  OEyvind Kolaas  <pippin at freedesktop.org>
+
 	* cairo_custom.[ch], puzzle.c : replaced cairo_set_gtk_color with
                                     gdk_cairo_set_color
 
-2004-02-15 OEyvind Kolaas <pippin at freedesktop.org>
+2004-02-15  OEyvind Kolaas  <pippin at freedesktop.org>
+
 	* gtkcairo_slide.c : removed superflous cairo_save/cairo_restor pairs
 
-2004-02-14 OEyvind Kolaas <pippin at freedesktop.org> 
+2004-02-14  OEyvind Kolaas  <pippin at freedesktop.org> 
 
 	Initial import

Index: README
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtkcairo_slide/README,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- README	14 Feb 2004 19:19:50 -0000	1.1
+++ README	11 Nov 2004 17:18:47 -0000	1.2
@@ -1,10 +1,20 @@
-gtkcairo_slide - GTK+ widget and application, demonstrating gtkcairo
+gtkcairo_slide
+==============
+
+GTK+ widget and application, demonstrating gtkcairo
 
 A cairo implementation of the classic sliding block puzzle, where you're supposed
 to slide the blocks into a configuration where the blocks are numbered incrementally.
 
+Implementation
+==============
+
+GtkCairoSlide is well behaved and creates a puzzle widget that is derived from the
+GtkCairo widget, this is the proper object oriented way of deriving a custom widget
+from GtkCairo. Most other examples use the api directly.
+
 Dependencies
-------------
+============
 
 GtkCairoSlide depends on gtkcairo, and it's dependencies
 

Index: cairo_custom.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtkcairo_slide/cairo_custom.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cairo_custom.c	13 May 2004 21:47:14 -0000	1.4
+++ cairo_custom.c	11 Nov 2004 17:18:47 -0000	1.5
@@ -1,48 +1,64 @@
 #include "cairo_custom.h"
 
 void
-cairo_rectangle_round ( cairo_t *cr, double x0, double y0, double width, double height, double radius) {
-    double x1,y1;
-    x1=x0+width;
-    y1=y0+height;
-    if (!width || !height)
-        return;
-    if (width/2<radius) {
-        if (height/2<radius) {
-            cairo_move_to  (cr, x0, (y0 + y1)/2);
-            cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
-            cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
-            cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
-            cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
-        } else {
-            cairo_move_to  (cr, x0, y0 + radius);
-            cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
-            cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
-            cairo_line_to (cr, x1 , y1 - radius);
-            cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
-            cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
+cairo_rectangle_round (cairo_t *cr,
+                       double x0,    double y0,
+                       double width, double height,
+                       double radius)
+{
+  double x1,y1;
+
+  x1=x0+width;
+  y1=y0+height;
+
+  if (!width || !height)
+    return;
+  if (width/2<radius)
+    {
+      if (height/2<radius)
+        {
+          cairo_move_to  (cr, x0, (y0 + y1)/2);
+          cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
+          cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
+          cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
+          cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
         }
-    } else {
-        if (height/2<radius) {
-            cairo_move_to  (cr, x0, (y0 + y1)/2);
-            cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
-            cairo_line_to (cr, x1 - radius, y0);
-            cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
-            cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
-            cairo_line_to (cr, x0 + radius, y1);
-            cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
-        } else {
-            cairo_move_to  (cr, x0, y0 + radius);
-            cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
-            cairo_line_to (cr, x1 - radius, y0);
-            cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
-            cairo_line_to (cr, x1 , y1 - radius);
-            cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
-            cairo_line_to (cr, x0 + radius, y1);
-            cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
+      else
+        {
+          cairo_move_to  (cr, x0, y0 + radius);
+          cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
+          cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
+          cairo_line_to (cr, x1 , y1 - radius);
+          cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
+          cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
         }
     }
-    cairo_close_path (cr);
+  else
+    {
+      if (height/2<radius)
+        {
+          cairo_move_to  (cr, x0, (y0 + y1)/2);
+          cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
+          cairo_line_to (cr, x1 - radius, y0);
+          cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
+          cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
+          cairo_line_to (cr, x0 + radius, y1);
+          cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
+        }
+      else
+        {
+          cairo_move_to  (cr, x0, y0 + radius);
+          cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
+          cairo_line_to (cr, x1 - radius, y0);
+          cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
+          cairo_line_to (cr, x1 , y1 - radius);
+          cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
+          cairo_line_to (cr, x0 + radius, y1);
+          cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
+        }
+    }
+
+  cairo_close_path (cr);
 }
 
 void
@@ -51,18 +67,21 @@
                 double y0,
                 double x1,
                 double y1,
-                double backoff) {
-    y0 = y0 - 1;
-    y1 = y1 + 1;
-
-    cairo_move_to (cr, x0, y0);
-    if (y1 > y0 + backoff / 2) {
-        cairo_curve_to (cr, x0, (y0 + y1) / 2, x1, (y0 + y1) / 2, x1, y1);
-    } else {
+                double backoff)
+{
+  y0 = y0 - 1;
+  y1 = y1 + 1;
 
-        cairo_curve_to (cr, x0,
-                        y0 + (backoff / 4 + (y0 + backoff / 2 - y1)), x1,
-                        y1 - (backoff / 4 + (y0 + backoff / 2 - y1)), x1,
-                        y1);
+  cairo_move_to (cr, x0, y0);
+  if (y1 > y0 + backoff / 2)
+    {
+      cairo_curve_to (cr, x0, (y0 + y1) / 2, x1, (y0 + y1) / 2, x1, y1);
+    }
+  else
+    {
+      cairo_curve_to (cr, x0,
+                      y0 + (backoff / 4 + (y0 + backoff / 2 - y1)), x1,
+                      y1 - (backoff / 4 + (y0 + backoff / 2 - y1)), x1,
+                      y1);
     }
 }

Index: cairo_custom.h
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtkcairo_slide/cairo_custom.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cairo_custom.h	13 May 2004 21:47:14 -0000	1.4
+++ cairo_custom.h	11 Nov 2004 17:18:47 -0000	1.5
@@ -3,12 +3,12 @@
 #include <gtkcairo.h>
 
 void
-cairo_rectangle_round ( cairo_t * cr,
-                        double x0,
-                        double y0,
-                        double width,
-                        double height,
-                        double radius);
+cairo_rectangle_round (cairo_t * cr,
+                       double x0,
+                       double y0,
+                       double width,
+                       double height,
+                       double radius);
 
 void
 cairo_edgeline (cairo_t * cr,

Index: gtkcairo_slide.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtkcairo_slide/gtkcairo_slide.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- gtkcairo_slide.c	23 Jun 2004 03:34:06 -0000	1.2
+++ gtkcairo_slide.c	11 Nov 2004 17:18:47 -0000	1.3
@@ -1,69 +1,73 @@
 #include <gtkcairo.h>
 #include "puzzle.h"
 
-
-GtkWidget *win;
-
 static void
-puzzle_solved (GtkWidget * widget, gpointer data) {
-    GtkWidget *dialog;
-    GtkWidget *label;
+puzzle_solved (GtkWidget *widget,
+               gpointer   data)
+{
+  GtkWidget *dialog;
+  GtkWidget *label;
+  GtkWidget *parent;
 
-    dialog = gtk_dialog_new_with_buttons ("GtkCairoSlide - solved",
-                                          GTK_WINDOW (win),
-                                          GTK_DIALOG_MODAL,
-                                          GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
-                                          NULL);
+  parent = gtk_widget_get_toplevel (widget);
 
-    label = gtk_label_new ("You solved the puzzle!");
-    gtk_misc_set_padding (GTK_MISC (label), 20, 20);
-    gtk_widget_show (label);
+  dialog = gtk_dialog_new_with_buttons ("GtkCairoSlide - solved",
+                                        GTK_WINDOW (parent),
+                                        GTK_DIALOG_MODAL,
+                                        GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+                                        NULL);
 
+  label = gtk_label_new ("You solved the puzzle!");
+  gtk_misc_set_padding (GTK_MISC (label), 20, 20);
+  gtk_widget_show (label);
 
-    gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
-    gtk_widget_show (dialog);
+  gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), label);
+  gtk_widget_show (dialog);
 
-    gtk_dialog_run (GTK_DIALOG (dialog));
-    gtk_main_quit ();
+  gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_main_quit ();
 }
 
 static void
 show_game (void) {
-    GtkWidget *vbox;
-    GtkWidget *puzzle;
+  GtkWidget *win;
+  GtkWidget *vbox;
+  GtkWidget *puzzle;
 
-	win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-	gtk_window_set_title (GTK_WINDOW (win), "Sliding GtkCairo Puzzle");
-	g_signal_connect (G_OBJECT (win), "delete-event",
-	                  G_CALLBACK (gtk_main_quit), NULL);
+  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_window_set_title (GTK_WINDOW (win), "Sliding GtkCairo Puzzle");
+  g_signal_connect (G_OBJECT (win), "delete-event",
+                    G_CALLBACK (gtk_main_quit), NULL);
 
-	vbox = gtk_vbox_new (FALSE, 6);
-	gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
+  vbox = gtk_vbox_new (FALSE, 6);
+  gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
 
-    puzzle = puzzle_new ();
+  puzzle = puzzle_new ();
 
-    g_object_set (G_OBJECT (puzzle), "rows", 4, NULL);
-    g_object_set (G_OBJECT (puzzle), "cols", 4, NULL);
-    g_object_set (G_OBJECT (puzzle), "shuffles", 2048, NULL);
+  g_object_set (G_OBJECT (puzzle), "rows", 4, NULL);
+  g_object_set (G_OBJECT (puzzle), "cols", 4, NULL);
+  g_object_set (G_OBJECT (puzzle), "shuffles", 2048, NULL);
 
-	gtk_widget_set_usize (GTK_WIDGET (puzzle), 192, 192);
+  gtk_widget_set_usize (GTK_WIDGET (puzzle), 192, 192);
 
-    g_signal_connect (G_OBJECT (puzzle), "puzzle_solved",
-                      G_CALLBACK (puzzle_solved), puzzle);
+  g_signal_connect (G_OBJECT (puzzle), "puzzle_solved",
+                    G_CALLBACK (puzzle_solved), puzzle);
 
-	gtk_container_add (GTK_CONTAINER (vbox), puzzle);
+  gtk_container_add (GTK_CONTAINER (vbox), puzzle);
 
-	gtk_container_add (GTK_CONTAINER (win), vbox);
-	gtk_widget_show_all (vbox);
-	gtk_widget_show (win);
+  gtk_container_add (GTK_CONTAINER (win), vbox);
+  gtk_widget_show_all (vbox);
+  gtk_widget_show (win);
 }
 
-int
-main (int argc, char *argv[]) {
-	gtk_init (&argc, &argv);
-	show_game ();
-	gtk_main ();
+gint
+main (gint argc,
+      gchar *argv[])
+{
+  gtk_init (&argc, &argv);
+  show_game ();
+  gtk_main ();
 
-	return 0;
+  return 0;
 }
 

Index: puzzle.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtkcairo_slide/puzzle.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- puzzle.c	29 Jun 2004 08:22:38 -0000	1.6
+++ puzzle.c	11 Nov 2004 17:18:47 -0000	1.7
@@ -13,18 +13,18 @@
 
 static int
 query_pos (Puzzle *puzzle,
-              int  x, 
-              int  y);
+           gint    x, 
+           gint    y);
 
 static void
 push_block (Puzzle *puzzle, 
-               int  block_no, 
[...1225 lines suppressed...]
-                   block->y = puzzle->item[pushed_y].y - 1;
-               else
-                   block->y = puzzle->item[pushed_y].y + 1;
-           }
-       }
+      if (pushed_y >= 0)
+        {
+          push_block (puzzle, pushed_y, 0, ydelta);
+          if (fabs (block->y - puzzle->item[pushed_y].y)>1.0001)
+            {
+              if (block->y < puzzle->item[pushed_y].y)
+                block->y = puzzle->item[pushed_y].y - 1;
+              else
+                block->y = puzzle->item[pushed_y].y + 1;
+            }
+        }
     }
-    return;
+  return;
 }




More information about the cairo-commit mailing list