[gnome-games] aisleriot: Add aisleriot_card_theme_paint_card()



commit d4dd818b0bfd57d0932d52defd3e0bcad749629e
Author: Christian Persch <chpe gnome org>
Date:   Thu Aug 12 23:54:53 2010 +0200

    aisleriot: Add aisleriot_card_theme_paint_card()
    
    ... and remove aisleriot_card_theme_get_card_surface().

 aisleriot/lib/ar-card-surface-cache.c |   15 ++++++++-
 aisleriot/lib/ar-card-theme-private.h |    5 ++-
 aisleriot/lib/ar-card-theme.c         |   51 +++++++++++++--------------------
 aisleriot/lib/ar-card-theme.h         |    5 ++-
 libgames-support/games-preimage.c     |   36 ++++++++---------------
 libgames-support/games-preimage.h     |   18 ++++++------
 6 files changed, 60 insertions(+), 70 deletions(-)
---
diff --git a/aisleriot/lib/ar-card-surface-cache.c b/aisleriot/lib/ar-card-surface-cache.c
index db89059..bfb666a 100644
--- a/aisleriot/lib/ar-card-surface-cache.c
+++ b/aisleriot/lib/ar-card-surface-cache.c
@@ -302,10 +302,21 @@ ar_card_surface_cache_get_card_surface_by_id (ArCardSurfaceCache *cache,
   }
 
   if (surface == NULL) {
+    CardSize card_size;
+    cairo_t *cr;
+
     LOG_CACHE_MISS (cache);
 
-    surface = ar_card_theme_get_card_surface (priv->theme, card_id);
-    if (surface == NULL) {
+    ar_card_theme_get_size (priv->theme, &card_size);
+
+    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+                                          card_size.width, card_size.height);
+    cr = cairo_create (surface);
+    ar_card_theme_paint_card (priv->theme, cr, card_id);
+    cairo_destroy (cr);
+
+    if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {
+      cairo_surface_destroy (surface);
       priv->cards[card_id] = FAILED_SURFACE;
       return NULL;
     }
diff --git a/aisleriot/lib/ar-card-theme-private.h b/aisleriot/lib/ar-card-theme-private.h
index 71aba3c..8d1e532 100644
--- a/aisleriot/lib/ar-card-theme-private.h
+++ b/aisleriot/lib/ar-card-theme-private.h
@@ -83,8 +83,9 @@ struct _ArCardThemeClass {
                                      int card_id);
 
 #if GTK_CHECK_VERSION (2, 10, 0)
-  cairo_surface_t* (* get_card_surface) (ArCardTheme *theme,
-                                         int card_id);
+  void        (* paint_card)        (ArCardTheme *theme,
+                                     cairo_t *cr,
+                                     int card_id);
   void        (* set_font_options)  (ArCardTheme *theme,
                                      const cairo_font_options_t *font_options);
 #endif
diff --git a/aisleriot/lib/ar-card-theme.c b/aisleriot/lib/ar-card-theme.c
index 443c1ba..bbea592 100644
--- a/aisleriot/lib/ar-card-theme.c
+++ b/aisleriot/lib/ar-card-theme.c
@@ -113,29 +113,23 @@ ar_card_theme_class_get_theme_info (ArCardThemeClass *klass,
 }
 
 #if GTK_CHECK_VERSION (2, 10,0)
-static cairo_surface_t *
-ar_card_theme_class_real_get_card_surface (ArCardTheme *theme,
-                                           int cardid)
+static void
+ar_card_theme_class_real_paint_card (ArCardTheme *theme,
+                                     cairo_t *cr,
+                                     int cardid)
 {
   GdkPixbuf *pixbuf;
-  cairo_surface_t *surface;
-  cairo_t *cr;
 
   pixbuf = ar_card_theme_get_card_pixbuf (theme, cardid);
   if (pixbuf == NULL)
-    return NULL;
+    return;
 
-  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
-                                        gdk_pixbuf_get_width (pixbuf),
-                                        gdk_pixbuf_get_height (pixbuf));
-  cr = cairo_create (surface);
+  cairo_save (cr);
   gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
   cairo_paint (cr);
-  cairo_destroy (cr);
+  cairo_restore (cr);
 
   g_object_unref (pixbuf);
-
-  return surface;
 }
 #endif /* GTK 2.10 */
 
@@ -151,7 +145,7 @@ ar_card_theme_class_init (ArCardThemeClass * klass)
   klass->get_theme_info = ar_card_theme_class_get_theme_info;
 
 #if GTK_CHECK_VERSION (2, 10,0)
-  klass->get_card_surface = ar_card_theme_class_real_get_card_surface;
+  klass->paint_card = ar_card_theme_class_real_paint_card;
 #endif
 
   g_object_class_install_property
@@ -366,30 +360,25 @@ ar_card_theme_get_card_pixbuf (ArCardTheme *theme,
 
 #if GTK_CHECK_VERSION (2, 10,0)
 /**
-* ar_card_theme_get_card_surface:
-* @theme:
-* @card_id:
-*
-* Returns a #cairo_surface_t for the selected card using the currently loaded
-* theme and the currently selected size.
-*
-* Returns: a new #cairo_surface_t, or %NULL if there was an error
+ * ar_card_theme_paint_card:
+ * @theme:
+ * @cr:
+ * @card_id:
+ *
+ * Paints the card to @cr.
 */
-cairo_surface_t *
-ar_card_theme_get_card_surface (ArCardTheme *theme,
-                                int cardid)
+void
+ar_card_theme_paint_card (ArCardTheme *theme,
+                          cairo_t *cr,
+                          int cardid)
 {
-  cairo_surface_t *surface = NULL;
-
-  g_return_val_if_fail ((cardid >= 0) && (cardid < AR_CARDS_TOTAL), NULL);
+  g_return_if_fail ((cardid >= 0) && (cardid < AR_CARDS_TOTAL));
 
   _games_profile_start ("loading card %d from theme %s", cardid, theme->theme_info->display_name);
 
-  surface = theme->klass->get_card_surface (theme, cardid);
+  theme->klass->paint_card (theme, cr, cardid);
 
   _games_profile_end ("loading card %d from theme %s", cardid, theme->theme_info->display_name);
-
-  return surface;
 }
 #endif /* GTK 2.10 */
 
diff --git a/aisleriot/lib/ar-card-theme.h b/aisleriot/lib/ar-card-theme.h
index dce2b18..66066eb 100644
--- a/aisleriot/lib/ar-card-theme.h
+++ b/aisleriot/lib/ar-card-theme.h
@@ -96,8 +96,9 @@ GdkPixbuf *ar_card_theme_get_card_pixbuf (ArCardTheme * theme,
                                           int cardid);
 
 #if GTK_CHECK_VERSION (2, 10,0)
-cairo_surface_t *ar_card_theme_get_card_surface (ArCardTheme *theme,
-                                                 int cardid);
+void ar_card_theme_paint_card (ArCardTheme *theme,
+                                cairo_t *cr,
+                                int cardid);
 #endif
 
 G_END_DECLS
diff --git a/libgames-support/games-preimage.c b/libgames-support/games-preimage.c
index 92e7df1..6df11f9 100644
--- a/libgames-support/games-preimage.c
+++ b/libgames-support/games-preimage.c
@@ -178,9 +178,9 @@ cairo_pixels_to_pixbuf (guint8 * pixels, int rowstride, int height)
  * Returns: %TRUE, of %FALSE if there was an error or @preimage
  * isn't a scalable SVG image
  */
-gboolean
+void
 games_preimage_render_cairo_sub (GamesPreimage * preimage,
-                                 cairo_surface_t *surface,
+                                 cairo_t *cr,
                                  const char *node,
                                  int width,
                                  int height,
@@ -189,33 +189,24 @@ games_preimage_render_cairo_sub (GamesPreimage * preimage,
                                  double xzoom,
                                  double yzoom)
 {
-  cairo_t *cx;
   cairo_matrix_t matrix;
-  gboolean success;
 
   if (!preimage->scalable)
-    return FALSE;
-
-  cx = cairo_create (surface);
+    return;
 
   if (preimage->font_options) {
-    cairo_set_antialias (cx, cairo_font_options_get_antialias (preimage->font_options));
+    cairo_set_antialias (cr, cairo_font_options_get_antialias (preimage->font_options));
 
-    cairo_set_font_options (cx, preimage->font_options);
+    cairo_set_font_options (cr, preimage->font_options);
   }
 
   cairo_matrix_init_identity (&matrix);
   cairo_matrix_scale (&matrix, xzoom, yzoom);
   cairo_matrix_translate (&matrix, xoffset, yoffset);
 
-  cairo_set_matrix (cx, &matrix);
-
-  rsvg_handle_render_cairo_sub (preimage->rsvg_handle, cx, node);
+  cairo_set_matrix (cr, &matrix);
 
-  success = (cairo_status (cx) == CAIRO_STATUS_SUCCESS);
-  cairo_destroy (cx);
-
-  return success;
+  rsvg_handle_render_cairo_sub (preimage->rsvg_handle, cr, node);
 }
 
 /**
@@ -249,6 +240,7 @@ games_preimage_render_sub (GamesPreimage * preimage,
   int rowstride;
   guint8 *data;
   cairo_surface_t *surface;
+  cairo_t *cr;
 
   if (!preimage->scalable)
     return NULL;
@@ -266,14 +258,10 @@ games_preimage_render_sub (GamesPreimage * preimage,
   surface = cairo_image_surface_create_for_data (data,
                                                  CAIRO_FORMAT_ARGB32,
                                                  width, height, rowstride);
-  if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS ||
-      !games_preimage_render_cairo_sub (preimage, surface, node, width, height,
-                                        xoffset, yoffset, xzoom, yzoom)) {
-    cairo_surface_destroy (surface);
-    g_free (data);
-    return NULL;
-  }
-
+  cr = cairo_create (surface);
+  games_preimage_render_cairo_sub (preimage, cr, node, width, height,
+                                   xoffset, yoffset, xzoom, yzoom);
+  cairo_destroy (cr);
   cairo_surface_destroy (surface);
   cairo_pixels_to_pixbuf (data, rowstride, height);
 
diff --git a/libgames-support/games-preimage.h b/libgames-support/games-preimage.h
index 8c821dc..d97877c 100644
--- a/libgames-support/games-preimage.h
+++ b/libgames-support/games-preimage.h
@@ -59,15 +59,15 @@ GdkPixbuf *games_preimage_render_sub (GamesPreimage * preimage,
                                       double yoffset,
                                       double xzoom, double yzoom);
 
-gboolean games_preimage_render_cairo_sub (GamesPreimage * preimage,
-                                          cairo_surface_t *surface,
-                                          const char *node,
-                                          int width,
-                                          int height,
-                                          double xoffset,
-                                          double yoffset,
-                                          double xzoom,
-                                          double yzoom);
+void games_preimage_render_cairo_sub (GamesPreimage * preimage,
+                                      cairo_t *cr,
+                                      const char *node,
+                                      int width,
+                                      int height,
+                                      double xoffset,
+                                      double yoffset,
+                                      double xzoom,
+                                      double yzoom);
 
 gboolean games_preimage_is_scalable (GamesPreimage * preimage);
 



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