[cairo-commit] cairo-demo/gtkcairo_slide ChangeLog, 1.2, 1.3 cairo_custom.c, 1.1, 1.2 cairo_custom.h, 1.1, 1.2 puzzle.c, 1.1, 1.2

OEyvind Kolaas commit at pdx.freedesktop.org
Sat May 1 08:03:20 PDT 2004


Committed by: pippin

Update of /cvs/cairo/cairo-demo/gtkcairo_slide
In directory pdx:/tmp/cvs-serv18030

Modified Files:
	ChangeLog cairo_custom.c cairo_custom.h puzzle.c 
Log Message:
replaced cairo_set_gtk_color with gdk_cairo_set_color


Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtkcairo_slide/ChangeLog,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** a/ChangeLog	15 Feb 2004 15:58:26 -0000	1.2
--- b/ChangeLog	1 May 2004 15:03:18 -0000	1.3
***************
*** 1,2 ****
--- 1,6 ----
+ 2004-01-03 OEyvind Kolaas <pippin at freedesktop.org>
+     * cairo_custom.[ch], puzzle.c : replaced cairo_set_gtk_color with
+                                     gdk_cairo_set_color
+ 
  2004-15-02 OEyvind Kolaas <pippin at freedesktop.org>
  	* gtkcairo_slide.c : removed superflous cairo_save/cairo_restor pairs

Index: cairo_custom.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtkcairo_slide/cairo_custom.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** a/cairo_custom.c	14 Feb 2004 19:19:50 -0000	1.1
--- b/cairo_custom.c	1 May 2004 15:03:18 -0000	1.2
***************
*** 68,137 ****
  }
  
- static double color_fg[5][3];
- static double color_bg[5][3];
- static double color_light[5][3];
- static double color_dark[5][3];
- static double color_mid[5][3];
- static double color_text[5][3];
- static double color_base[5][3];
- 
  void
! cairo_init_gtk_color (GtkWidget *widget) {
!     GtkStateType state;
! 
!     for (state = GTK_STATE_NORMAL;state<=GTK_STATE_INSENSITIVE;state++) {
!         color_fg[state][0] = widget->style->fg[state].red/65535.0;
!         color_fg[state][1] = widget->style->fg[state].green/65535.0;
!         color_fg[state][2] = widget->style->fg[state].blue/65535.0;
! 
!         color_bg[state][0] = widget->style->bg[state].red/65535.0;
!         color_bg[state][1] = widget->style->bg[state].green/65535.0;
!         color_bg[state][2] = widget->style->bg[state].blue/65535.0;
! 
!         color_light[state][0] = widget->style->light[state].red/65535.0;
!         color_light[state][1] = widget->style->light[state].green/65535.0;
!         color_light[state][2] = widget->style->light[state].blue/65535.0;
! 
!         color_dark[state][0] = widget->style->dark[state].red/65535.0;
!         color_dark[state][1] = widget->style->dark[state].green/65535.0;
!         color_dark[state][2] = widget->style->dark[state].blue/65535.0;
! 
! 
!         color_mid[state][0] = widget->style->mid[state].red/65535.0;
!         color_mid[state][1] = widget->style->mid[state].green/65535.0;
!         color_mid[state][2] = widget->style->mid[state].blue/65535.0;
! 
! 
! 
!         color_text[state][0] = widget->style->text[state].red/65535.0;
!         color_text[state][1] = widget->style->text[state].green/65535.0;
!         color_text[state][2] = widget->style->text[state].blue/65535.0;
! 
  
!         color_base[state][0] = widget->style->base[state].red/65535.0;
!         color_base[state][1] = widget->style->base[state].green/65535.0;
!         color_base[state][2] = widget->style->base[state].blue/65535.0;
!     }
! }
  
! void
! cairo_set_gtk_color (cairo_t *ct, const char *item, GtkStateType state) {
!     /* these checks should be rearranged descending according to amount of use */
!     if (!strcmp (item, "fg")) {
!         cairo_set_rgb_color (ct, color_fg[state][0], color_fg[state][1],color_fg[state][2]);
!     } else if (!strcmp (item, "bg")) {
!         cairo_set_rgb_color (ct, color_bg[state][0], color_bg[state][1],color_bg[state][2]);
!     } else if (!strcmp (item, "text")) {
!         cairo_set_rgb_color (ct, color_text[state][0], color_text[state][1],color_text[state][2]);
!     } else if (!strcmp (item, "light")) {
!         cairo_set_rgb_color (ct, color_light[state][0], color_light[state][1],color_light[state][2]);
!     } else if (!strcmp (item, "dark")) {
!         cairo_set_rgb_color (ct, color_dark[state][0], color_dark[state][1],color_dark[state][2]);
!     } else if (!strcmp (item, "mid")) {
!         cairo_set_rgb_color (ct, color_mid[state][0], color_mid[state][1],color_mid[state][2]);
!     } else if (!strcmp (item, "base")) { /* base */
!         cairo_set_rgb_color (ct, color_base[state][0], color_base[state][1],color_base[state][2]);
!     } else {
!         fprintf (stderr, "Eeek,. unknown item %s passed to cairo_set_gtk_color()\n", item);
!     }
  }
--- 68,81 ----
  }
  
  void
! gdk_cairo_set_color (cairo_t *ct,
!                      GdkColor *color)
! {
!     double red, green, blue;
  
!     red   = color->red   / 65535.0;
!     green = color->green / 65535.0;
!     blue  = color->blue  / 65535.0;
  
!     cairo_set_rgb_color (ct, red, green, blue);
  }

Index: cairo_custom.h
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtkcairo_slide/cairo_custom.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** a/cairo_custom.h	14 Feb 2004 19:19:50 -0000	1.1
--- b/cairo_custom.h	1 May 2004 15:03:18 -0000	1.2
***************
*** 4,7 ****
--- 4,11 ----
  
  void
+ gdk_cairo_set_color (cairo_t  *ct,
+                      GdkColor *color);
+ 
+ void
  cairo_rectangle_round ( cairo_t * ct,
                          double x0,
***************
*** 18,26 ****
                  double y1,
                  double backoff);
- void
- cairo_init_gtk_color (GtkWidget *widget);
- 
- void
- cairo_set_gtk_color (cairo_t *ct, const char *item, GtkStateType state);
  
  #endif /* CAIRO_CUSTOM_H */
--- 22,25 ----

Index: puzzle.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/gtkcairo_slide/puzzle.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** a/puzzle.c	14 Feb 2004 19:19:50 -0000	1.1
--- b/puzzle.c	1 May 2004 15:03:18 -0000	1.2
***************
*** 37,41 ****
      double x;
      double y;
!     char  label[16];  
  };
  
--- 37,41 ----
      double x;
      double y;
!     char  label[16];
  };
  
***************
*** 48,54 ****
      double cursorx;
      double cursory;
!     
      struct PuzzleItem *item;
!     
      gint grabbed;
  
--- 48,54 ----
      double cursorx;
      double cursory;
! 
      struct PuzzleItem *item;
! 
      gint grabbed;
  
***************
*** 76,84 ****
  
  static void
! set_property (GObject *object,
!                 guint  property_id,
!          const GValue *value,
!            GParamSpec *psec) {
!            
      Puzzle *puzzle = PUZZLE (object);
  
--- 76,84 ----
  
  static void
! set_property (GObject      *object,
!               guint         property_id,
!               const GValue *value,
!               GParamSpec   *psec)
! {
      Puzzle *puzzle = PUZZLE (object);
  
***************
*** 106,121 ****
                  guint  property_id,
                 GValue *value,
!            GParamSpec *pspec) {
!            
      Puzzle *puzzle = PUZZLE (object);
  
      switch (property_id) {
!     case PUZZLE_ROWS: 
              g_value_set_int (value, puzzle->rows);
          break;
!     case PUZZLE_COLS: 
              g_value_set_int (value, puzzle->rows);
          break;
!     case PUZZLE_SHUFFLES: 
              g_value_set_int (value, puzzle->shuffles);
          break;
--- 106,121 ----
                  guint  property_id,
                 GValue *value,
!            GParamSpec *pspec)
! {
      Puzzle *puzzle = PUZZLE (object);
  
      switch (property_id) {
!     case PUZZLE_ROWS:
              g_value_set_int (value, puzzle->rows);
          break;
!     case PUZZLE_COLS:
              g_value_set_int (value, puzzle->rows);
          break;
!     case PUZZLE_SHUFFLES:
              g_value_set_int (value, puzzle->shuffles);
          break;
***************
*** 203,208 ****
  
  GType
! puzzle_get_type (void) {
      static GType ge_type = 0;
      if (!ge_type) {
          static const GTypeInfo ge_info = {
--- 203,210 ----
  
  GType
! puzzle_get_type (void)
! {
      static GType ge_type = 0;
+ 
      if (!ge_type) {
          static const GTypeInfo ge_info = {
***************
*** 228,242 ****
  /* prototypes for event functions registered with the object */
  
! static gboolean event_press (GtkWidget *widget,
!                         GdkEventButton *bev,
!                               gpointer  user_data);
  
! static gboolean event_release (GtkWidget *widget,
!                           GdkEventButton *bev,
!                                 gpointer  user_data);
  
! static gboolean event_motion (GtkWidget *widget,
!                          GdkEventMotion *mev,
!                                gpointer  user_data);
  
  static void puzzle_class_init (PuzzleClass *class);
--- 230,244 ----
  /* prototypes for event functions registered with the object */
  
! static gboolean event_press (GtkWidget      *widget,
!                              GdkEventButton *bev,
!                              gpointer        user_data);
  
! static gboolean event_release (GtkWidget      *widget,
!                                GdkEventButton *bev,
!                                gpointer        user_data);
  
! static gboolean event_motion (GtkWidget      *widget,
!                               GdkEventMotion *mev,
!                               gpointer        user_data);
  
  static void puzzle_class_init (PuzzleClass *class);
***************
*** 245,253 ****
  
  static void redraw (GtkCairo *gtkcairo,
!                      cairo_t *ct,
                      gpointer  user_data);
  
  GtkWidget *
! puzzle_new (void) {
      GtkWidget *widget = GTK_WIDGET (g_object_new (puzzle_get_type (), NULL));
      Puzzle *puzzle = PUZZLE (widget);
--- 247,256 ----
  
  static void redraw (GtkCairo *gtkcairo,
!                     cairo_t  *ct,
                      gpointer  user_data);
  
  GtkWidget *
! puzzle_new (void)
! {
      GtkWidget *widget = GTK_WIDGET (g_object_new (puzzle_get_type (), NULL));
      Puzzle *puzzle = PUZZLE (widget);
***************
*** 276,281 ****
                        G_CALLBACK (event_release), puzzle);
  
-     gtk_widget_show (widget);
- 
      return widget;
  }
--- 279,282 ----
***************
*** 284,289 ****
  
  static gboolean
! event_press (GtkWidget * widget,
!              GdkEventButton * bev, gpointer user_data) {
      Puzzle *puzzle = PUZZLE (user_data);
  
--- 285,292 ----
  
  static gboolean
! event_press (GtkWidget      *widget,
!              GdkEventButton *bev,
!              gpointer        user_data)
! {
      Puzzle *puzzle = PUZZLE (user_data);
  
***************
*** 294,298 ****
          case 1:
                puzzle->grabbed = query_pos (puzzle, bev->x, bev->y);
-               
                /* request a redraw, since we've changed the state of our widget */
                gtk_widget_queue_draw (GTK_WIDGET (puzzle));
--- 297,300 ----
***************
*** 319,324 ****
  
  static gboolean
! event_motion (GtkWidget * widget,
!               GdkEventMotion * mev, gpointer user_data) {
      Puzzle *puzzle = PUZZLE (user_data);
  
--- 321,328 ----
  
  static gboolean
! event_motion (GtkWidget      *widget,
!               GdkEventMotion *mev,
!               gpointer        user_data)
! {
      Puzzle *puzzle = PUZZLE (user_data);
  
***************
*** 332,336 ****
               g_signal_emit (G_OBJECT (puzzle),
                              puzzle_signals
!                             [PUZZLE_SOLVED_SIGNAL], 0);            
          }
  
--- 336,340 ----
               g_signal_emit (G_OBJECT (puzzle),
                              puzzle_signals
!                             [PUZZLE_SOLVED_SIGNAL], 0);
          }
  
***************
*** 338,342 ****
          /* request a redraw, since we've changed the state of our widget */
          gtk_widget_queue_draw (GTK_WIDGET (puzzle));
!         
          puzzle->cursorx = mev->x;
          puzzle->cursory = mev->y;
--- 342,346 ----
          /* request a redraw, since we've changed the state of our widget */
          gtk_widget_queue_draw (GTK_WIDGET (puzzle));
! 
          puzzle->cursorx = mev->x;
          puzzle->cursory = mev->y;
***************
*** 348,358 ****
  
  static void
! redraw (GtkCairo * gtkcairo, cairo_t * ct, gpointer user_data) {
      GtkWidget *widget = GTK_WIDGET (gtkcairo);
      Puzzle *puzzle = PUZZLE (gtkcairo);
  
-     /* initialize the utility functions for getting colors from the gtk style */
-     cairo_init_gtk_color (widget);
-     
      puzzle->ratio_x = (double) widget->allocation.width/puzzle->cols;
      puzzle->ratio_y = (double) widget->allocation.height/puzzle->rows;
--- 352,362 ----
  
  static void
! redraw (GtkCairo *gtkcairo,
!         cairo_t  *ct,
!         gpointer  user_data)
! {
      GtkWidget *widget = GTK_WIDGET (gtkcairo);
      Puzzle *puzzle = PUZZLE (gtkcairo);
  
      puzzle->ratio_x = (double) widget->allocation.width/puzzle->cols;
      puzzle->ratio_y = (double) widget->allocation.height/puzzle->rows;
***************
*** 376,381 ****
  
  
! static void 
! get_empty (Puzzle *puzzle, 
                int *col,
                int *row);
--- 380,385 ----
  
  
! static void
! get_empty (Puzzle *puzzle,
                int *col,
                int *row);
***************
*** 390,399 ****
     since initialization, since the shuffeling presumes that
     the order haven't changed.
! */   
  
  #include <assert.h>
  
! static 
! void puzzle_shuffle (Puzzle *puzzle, gint shuffles){
      while (shuffles--) {
        gint empty_x;
--- 394,405 ----
     since initialization, since the shuffeling presumes that
     the order haven't changed.
! */
  
  #include <assert.h>
  
! static
! void puzzle_shuffle (Puzzle *puzzle,
!                      gint    shuffles)
! {
      while (shuffles--) {
        gint empty_x;
***************
*** 401,407 ****
        gint block_no;
        gint direction = g_random_int_range (0, 5);
!     
        get_empty (puzzle, &empty_x, &empty_y);
!       
        switch (direction){
          case 0:
--- 407,413 ----
        gint block_no;
        gint direction = g_random_int_range (0, 5);
! 
        get_empty (puzzle, &empty_x, &empty_y);
! 
        switch (direction){
          case 0:
***************
*** 433,437 ****
  }
  
! static void get_empty (Puzzle *puzzle, gint *col, gint *row){    
      if (!col || !row)
          return;
--- 439,447 ----
  }
  
! static void
! get_empty (Puzzle *puzzle,
!              gint *col,
!              gint *row)
! {
      if (!col || !row)
          return;
***************
*** 451,456 ****
  }
  
! static int get_at (Puzzle *puzzle, gint col, gint row){    
     gint item_no;
     for (item_no=0;item_no< puzzle->cols*puzzle->rows-1; item_no++){
         if (puzzle->item[item_no].x == col && puzzle->item[item_no].y == row){
--- 461,471 ----
  }
  
! static int
! get_at (Puzzle *puzzle,
!         gint    col,
!         gint    row)
! {
     gint item_no;
+ 
     for (item_no=0;item_no< puzzle->cols*puzzle->rows-1; item_no++){
         if (puzzle->item[item_no].x == col && puzzle->item[item_no].y == row){
***************
*** 463,470 ****
  /* initialize a board of specified size */
  static void
! board_init (GtkWidget *widget){
      Puzzle *puzzle = PUZZLE (widget);
      gint row, col;
!     
      if (puzzle->item){
          free (puzzle->item);
--- 478,486 ----
  /* initialize a board of specified size */
  static void
! board_init (GtkWidget *widget)
! {
      Puzzle *puzzle = PUZZLE (widget);
      gint row, col;
! 
      if (puzzle->item){
          free (puzzle->item);
***************
*** 481,495 ****
                  puzzle->item[row*puzzle->cols + col].y=row;
                  sprintf (puzzle->item[row*puzzle->cols + col].label, "%i", row*puzzle->cols + col +1);
!             }            
          }
      }
      puzzle_shuffle (puzzle, puzzle->shuffles);
!     gtk_widget_queue_draw (GTK_WIDGET (puzzle));    
  }
  
  static gint
! board_solved (Puzzle *puzzle) {
      gint item_no=0;
!     
      for (item_no=0;item_no<puzzle->rows * puzzle->cols-1;item_no++ ) {
          struct PuzzleItem *item= & (puzzle->item [item_no]);
--- 497,512 ----
                  puzzle->item[row*puzzle->cols + col].y=row;
                  sprintf (puzzle->item[row*puzzle->cols + col].label, "%i", row*puzzle->cols + col +1);
!             }
          }
      }
      puzzle_shuffle (puzzle, puzzle->shuffles);
!     gtk_widget_queue_draw (GTK_WIDGET (puzzle));
  }
  
  static gint
! board_solved (Puzzle *puzzle)
! {
      gint item_no=0;
! 
      for (item_no=0;item_no<puzzle->rows * puzzle->cols-1;item_no++ ) {
          struct PuzzleItem *item= & (puzzle->item [item_no]);
***************
*** 503,513 ****
  
  
! /* query which block is at the given mouse coordinates, 
     returns -1 if no block was found
  */
  static int
! query_pos (Puzzle *puzzle, int x, int y) {
      int item_no;
-     
      cairo_t *ct = gtk_cairo_get_cairo (GTK_CAIRO (puzzle));
  
--- 520,532 ----
  
  
! /* query which block is at the given mouse coordinates,
     returns -1 if no block was found
  */
  static int
! query_pos (Puzzle *puzzle,
!            int     x,
!            int     y)
! {
      int item_no;
      cairo_t *ct = gtk_cairo_get_cairo (GTK_CAIRO (puzzle));
  
***************
*** 522,526 ****
          cairo_save (ct);
          cairo_rectangle_round (ct, item->x-0.4, item->y-0.4, 0.8, 0.8, 0.4);
!         
          if (cairo_in_fill (ct, (x)/ puzzle->ratio_x -0.5, (y) / puzzle->ratio_y -0.5)){
                  cairo_restore (ct);
--- 541,545 ----
          cairo_save (ct);
          cairo_rectangle_round (ct, item->x-0.4, item->y-0.4, 0.8, 0.8, 0.4);
! 
          if (cairo_in_fill (ct, (x)/ puzzle->ratio_x -0.5, (y) / puzzle->ratio_y -0.5)){
                  cairo_restore (ct);
***************
*** 532,536 ****
  
      cairo_restore (ct);
!     return -1;    
  }
  
--- 551,555 ----
  
      cairo_restore (ct);
!     return -1;
  }
  
***************
*** 538,543 ****
  */
  static void
! draw_board (Puzzle *puzzle, cairo_t *ct) {
      int item_no;
  
      cairo_save (ct);
--- 557,567 ----
  */
  static void
! draw_board (Puzzle  *puzzle,
!             cairo_t *ct)
! {
      int item_no;
+     GtkStyle *style;
+ 
+     style = GTK_WIDGET (puzzle)->style;
  
      cairo_save (ct);
***************
*** 545,576 ****
      cairo_translate (ct, 0.5, 0.5);
  
-         
          for (item_no=0;item_no<puzzle->rows*puzzle->cols-1;item_no++) {
              struct PuzzleItem *item= & (puzzle->item [item_no]);
-             cairo_save (ct);
                 cairo_rectangle_round (ct, item->x-0.36, item->y-0.36, 0.8, 0.8, 0.4);
                 cairo_set_line_width (ct, 0.07);
                 if (item_no==puzzle->grabbed) {
!                   cairo_set_gtk_color (ct, "dark", GTK_STATE_SELECTED);
                 } else {
                    if ( fabs(floor(item->x)-item->x)<0.01 && fabs(floor(item->y)-item->y)<0.01) {
!                       cairo_set_gtk_color (ct, "dark", GTK_STATE_NORMAL);
                    } else {
!                       cairo_set_gtk_color (ct, "dark", GTK_STATE_ACTIVE);
                    }
                 }
!                 
                 cairo_stroke (ct);
!             cairo_restore (ct);
!             cairo_save (ct);
                 cairo_rectangle_round (ct, item->x-0.4, item->y-0.4, 0.8, 0.8, 0.4);
                 cairo_save (ct);
                    if (item_no==puzzle->grabbed) {
!                      cairo_set_gtk_color (ct, "base", GTK_STATE_SELECTED);
                    } else {
                       if ( fabs(floor(item->x)-item->x)<0.01 && fabs(floor(item->y)-item->y)<0.01) {
!                          cairo_set_gtk_color (ct, "base", GTK_STATE_NORMAL);
                       } else {
!                          cairo_set_gtk_color (ct, "base", GTK_STATE_NORMAL);
                       }
                    }
--- 569,599 ----
      cairo_translate (ct, 0.5, 0.5);
  
          for (item_no=0;item_no<puzzle->rows*puzzle->cols-1;item_no++) {
              struct PuzzleItem *item= & (puzzle->item [item_no]);
                 cairo_rectangle_round (ct, item->x-0.36, item->y-0.36, 0.8, 0.8, 0.4);
                 cairo_set_line_width (ct, 0.07);
                 if (item_no==puzzle->grabbed) {
! 
!                   gdk_cairo_set_color (ct, &style->dark[GTK_STATE_NORMAL]);
! 
                 } else {
                    if ( fabs(floor(item->x)-item->x)<0.01 && fabs(floor(item->y)-item->y)<0.01) {
!                       gdk_cairo_set_color (ct, &style->dark[GTK_STATE_NORMAL]);
                    } else {
!                       gdk_cairo_set_color (ct, &style->dark[GTK_STATE_ACTIVE]);
                    }
                 }
! 
                 cairo_stroke (ct);
! 
                 cairo_rectangle_round (ct, item->x-0.4, item->y-0.4, 0.8, 0.8, 0.4);
                 cairo_save (ct);
                    if (item_no==puzzle->grabbed) {
!                      gdk_cairo_set_color (ct, &style->base[GTK_STATE_SELECTED]);
                    } else {
                       if ( fabs(floor(item->x)-item->x)<0.01 && fabs(floor(item->y)-item->y)<0.01) {
!                          gdk_cairo_set_color (ct, &style->base[GTK_STATE_NORMAL]);
                       } else {
!                          gdk_cairo_set_color (ct, &style->base[GTK_STATE_NORMAL]);
                       }
                    }
***************
*** 578,593 ****
                 cairo_restore (ct);
                 if (item_no==puzzle->grabbed) {
!                   cairo_set_gtk_color (ct, "mid", GTK_STATE_SELECTED);
                 } else {
                    if ( fabs(floor(item->x)-item->x)<0.01 && fabs(floor(item->y)-item->y)<0.01) {
!                       cairo_set_gtk_color (ct, "mid", GTK_STATE_NORMAL);
                    } else {
!                       cairo_set_gtk_color (ct, "dark", GTK_STATE_ACTIVE);
                    }
                 }
                 cairo_set_line_width (ct, 0.05);
                 cairo_stroke (ct);
!             cairo_restore (ct);
!             cairo_save (ct);
                  {
                    cairo_text_extents_t extents;
--- 601,615 ----
                 cairo_restore (ct);
                 if (item_no==puzzle->grabbed) {
!                  gdk_cairo_set_color (ct, &style->mid[GTK_STATE_SELECTED]);
                 } else {
                    if ( fabs(floor(item->x)-item->x)<0.01 && fabs(floor(item->y)-item->y)<0.01) {
!                       gdk_cairo_set_color (ct, &style->mid[GTK_STATE_NORMAL]);
                    } else {
!                       gdk_cairo_set_color (ct, &style->dark[GTK_STATE_ACTIVE]);
                    }
                 }
                 cairo_set_line_width (ct, 0.05);
                 cairo_stroke (ct);
! 
                  {
                    cairo_text_extents_t extents;
***************
*** 599,614 ****
  
                  }
-             
                 if (item_no==puzzle->grabbed) {
!                   cairo_set_gtk_color (ct, "text", GTK_STATE_SELECTED);
                 } else {
                    if ( fabs(floor(item->x)-item->x)<0.01 && fabs(floor(item->y)-item->y)<0.01) {
!                       cairo_set_gtk_color (ct, "text", GTK_STATE_NORMAL);
                    } else {
!                       cairo_set_gtk_color (ct, "text", GTK_STATE_NORMAL);
                    }
                 }
                 cairo_show_text (ct, item->label);
-             cairo_restore (ct);
          }
  
--- 621,634 ----
  
                  }
                 if (item_no==puzzle->grabbed) {
!                   gdk_cairo_set_color (ct, &style->text[GTK_STATE_SELECTED]);
                 } else {
                    if ( fabs(floor(item->x)-item->x)<0.01 && fabs(floor(item->y)-item->y)<0.01) {
!                       gdk_cairo_set_color (ct, &style->text[GTK_STATE_NORMAL]);
                    } else {
!                       gdk_cairo_set_color (ct, &style->text[GTK_STATE_NORMAL]);
                    }
                 }
                 cairo_show_text (ct, item->label);
          }
  
***************
*** 619,629 ****
  /* returns which block would be pushed by shifting 'block' the given amount
     in x direction
!    
     return: >=0 block id
              -1 none
              -2 going off board
! */            
  static int
! who_is_pushed_x (Puzzle *puzzle, int block_no, double xdelta){
      int item_no;
      struct PuzzleItem *block= & (puzzle->item [block_no]);
--- 639,652 ----
  /* returns which block would be pushed by shifting 'block' the given amount
     in x direction
! 
     return: >=0 block id
              -1 none
              -2 going off board
! */
  static int
! who_is_pushed_x (Puzzle *puzzle,
!                  int     block_no,
!                  double  xdelta)
! {
      int item_no;
      struct PuzzleItem *block= & (puzzle->item [block_no]);
***************
*** 632,639 ****
          if (block->x+xdelta<0)
              return -2;
!     
          for (item_no=0;item_no<puzzle->rows*puzzle->cols-1;item_no++){
              struct PuzzleItem *item= & (puzzle->item [item_no]);
!             if (block->x > item->x && block->x + xdelta - 1 <= item->x  
                  && item->y < block->y + 1 && item->y > block->y -1  ){
                  return item_no;
--- 655,662 ----
          if (block->x+xdelta<0)
              return -2;
! 
          for (item_no=0;item_no<puzzle->rows*puzzle->cols-1;item_no++){
              struct PuzzleItem *item= & (puzzle->item [item_no]);
!             if (block->x > item->x && block->x + xdelta - 1 <= item->x
                  && item->y < block->y + 1 && item->y > block->y -1  ){
                  return item_no;
***************
*** 646,651 ****
          for (item_no=0;item_no<puzzle->rows*puzzle->cols-1;item_no++){
              struct PuzzleItem *item= & (puzzle->item [item_no]);
!             if (block->x < item->x && block->x + xdelta + 1 >= item->x   
!                 && item->y < block->y + 1 && item->y > block->y -1  ){            
                  return item_no;
              }
--- 669,674 ----
          for (item_no=0;item_no<puzzle->rows*puzzle->cols-1;item_no++){
              struct PuzzleItem *item= & (puzzle->item [item_no]);
!             if (block->x < item->x && block->x + xdelta + 1 >= item->x
!                 && item->y < block->y + 1 && item->y > block->y -1  ){
                  return item_no;
              }
***************
*** 657,667 ****
  /* returns which block would be pushed by shifting 'block' the given amount
     in y direction
!    
     return: >=0 block id
              -1 none
              -2 going off board
! */            
  static int
! who_is_pushed_y (Puzzle *puzzle, int block_no, double ydelta){
      int item_no;
      struct PuzzleItem *block= & (puzzle->item [block_no]);
--- 680,693 ----
  /* returns which block would be pushed by shifting 'block' the given amount
     in y direction
! 
     return: >=0 block id
              -1 none
              -2 going off board
! */
  static int
! who_is_pushed_y (Puzzle *puzzle,
!                  int     block_no,
!                  double  ydelta)
! {
      int item_no;
      struct PuzzleItem *block= & (puzzle->item [block_no]);
***************
*** 670,677 ****
          if (block->y+ydelta<0)
              return -2;
!     
          for (item_no=0;item_no<puzzle->rows*puzzle->cols-1;item_no++){
              struct PuzzleItem *item= & (puzzle->item [item_no]);
!             if (block->y > item->y && block->y + ydelta - 1 <= item->y   
                  && item->x < block->x + 1 && item->x > block->x -1  ){
  
--- 696,703 ----
          if (block->y+ydelta<0)
              return -2;
! 
          for (item_no=0;item_no<puzzle->rows*puzzle->cols-1;item_no++){
              struct PuzzleItem *item= & (puzzle->item [item_no]);
!             if (block->y > item->y && block->y + ydelta - 1 <= item->y
                  && item->x < block->x + 1 && item->x > block->x -1  ){
  
***************
*** 685,694 ****
          for (item_no=0;item_no<puzzle->rows*puzzle->cols-1;item_no++){
              struct PuzzleItem *item= & (puzzle->item [item_no]);
!             if (block->y < item->y && block->y + ydelta + 1 >= item->y   
                  && item->x < block->x + 1 && item->x > block->x -1  ){
                  return item_no;
              }
          }
!     }        
      return -1;
  }
--- 711,720 ----
          for (item_no=0;item_no<puzzle->rows*puzzle->cols-1;item_no++){
              struct PuzzleItem *item= & (puzzle->item [item_no]);
!             if (block->y < item->y && block->y + ydelta + 1 >= item->y
                  && item->x < block->x + 1 && item->x > block->x -1  ){
                  return item_no;
              }
          }
!     }
      return -1;
  }
***************
*** 696,703 ****
  /* attempt to push a block the given delta in x and y directions */
  static void
! push_block (Puzzle *puzzle, int block_no, double xdelta, double ydelta) {
      struct PuzzleItem *block= & (puzzle->item [block_no]);
      gint pushed_x, pushed_y;
!     
      if (floor (block->y)-block->y == 0 && xdelta != 0.0){
         if (xdelta>=0.9)
--- 722,733 ----
  /* attempt to push a block the given delta in x and y directions */
  static void
! push_block (Puzzle *puzzle,
!             int     block_no,
!             double  xdelta,
!             double  ydelta)
! {
      struct PuzzleItem *block= & (puzzle->item [block_no]);
      gint pushed_x, pushed_y;
! 
      if (floor (block->y)-block->y == 0 && xdelta != 0.0){
         if (xdelta>=0.9)
***************
*** 708,712 ****
         pushed_x = who_is_pushed_x (puzzle, block_no, xdelta);
  
!        if ( pushed_x == -1 || pushed_x == -2){        
             block->x += xdelta;
             if (block->x >= puzzle->cols-1) {
--- 738,742 ----
         pushed_x = who_is_pushed_x (puzzle, block_no, xdelta);
  
!        if ( pushed_x == -1 || pushed_x == -2){
             block->x += xdelta;
             if (block->x >= puzzle->cols-1) {
***************
*** 714,718 ****
             } else if (block->x < 0) {
                 block->x = 0;
!            }           
             return;
         }
--- 744,748 ----
             } else if (block->x < 0) {
                 block->x = 0;
!            }
             return;
         }
***************
*** 728,733 ****
         }
      }
!     
!     
      if (floor (block->x)-block->x == 0) {
         if (ydelta>=0.9)
--- 758,763 ----
         }
      }
! 
! 
      if (floor (block->x)-block->x == 0) {
         if (ydelta>=0.9)
***************
*** 747,751 ****
             return;
         }
!        
         if (pushed_y >= 0) {
             push_block (puzzle, pushed_y, 0, ydelta);
--- 777,781 ----
             return;
         }
! 
         if (pushed_y >= 0) {
             push_block (puzzle, pushed_y, 0, ydelta);
***************
*** 758,761 ****
         }
      }
!     return;    
  }
--- 788,791 ----
         }
      }
!     return;
  }





More information about the cairo-commit mailing list