[gnome-games] libgames-support: Add games_preimage_render_cairo



commit 023f71046d3274462fb80f8cb8da5669eee9ed3a
Author: Christian Persch <chpe gnome org>
Date:   Fri Aug 13 16:22:20 2010 +0200

    libgames-support: Add games_preimage_render_cairo

 libgames-support/games-preimage.c |   51 +++++++++++++++++++++++++++++++++++++
 libgames-support/games-preimage.h |    7 ++++-
 2 files changed, 57 insertions(+), 1 deletions(-)
---
diff --git a/libgames-support/games-preimage.c b/libgames-support/games-preimage.c
index 6df11f9..8c3c8a5 100644
--- a/libgames-support/games-preimage.c
+++ b/libgames-support/games-preimage.c
@@ -27,6 +27,9 @@
 #include <glib.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
+/* For gdkcairo */
+#include <gdk/gdk.h>
+
 #ifdef HAVE_RSVG
 #include <librsvg/rsvg.h>
 #include <librsvg/rsvg-cairo.h>
@@ -121,6 +124,54 @@ games_preimage_render (GamesPreimage * preimage, gint width, gint height)
   return pixbuf;
 }
 
+/**
+ * games_preimage_render_cairo:
+ * @preimage:
+ * @cr:
+ * @width: the desired width
+ * @height: the desired height
+ *
+ * Renders from @preimage's image at the specified
+ * @width and @height to @cr.
+*/
+void
+games_preimage_render_cairo (GamesPreimage * preimage,
+                             cairo_t *cr,
+                             gint width,
+                             gint height)
+{
+  g_return_if_fail (width > 0 && height > 0);
+  g_return_if_fail (preimage != NULL);
+
+#ifdef HAVE_RSVG
+  if (preimage->scalable) {     /* Render vector image */
+    games_preimage_render_cairo_sub (preimage,
+                                     cr,
+                                     NULL,
+                                     width,
+                                     height,
+                                     0.0, 0.0,
+                                     ((double) width) /
+                                     ((double) preimage->width),
+                                     ((double) height) /
+                                     ((double) preimage->height));
+  } else
+#endif /* HAVE_RSVG */
+  {
+    GdkPixbuf *pixbuf;
+
+    /* FIXMEchpe: we don't really need this fallback anymore */
+    /* Render raster image */
+    pixbuf = gdk_pixbuf_scale_simple (preimage->pixbuf,
+                                      width, height, GDK_INTERP_BILINEAR);
+
+    cairo_save (cr);
+    gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+    cairo_paint (cr);
+    cairo_restore (cr);
+  }
+}
+
 #ifdef HAVE_RSVG
 
 /* This routine is copied from librsvg:
diff --git a/libgames-support/games-preimage.h b/libgames-support/games-preimage.h
index d97877c..8ec2398 100644
--- a/libgames-support/games-preimage.h
+++ b/libgames-support/games-preimage.h
@@ -49,7 +49,12 @@ void games_preimage_set_font_options (GamesPreimage * preimage,
                                       const cairo_font_options_t *font_options);
 
 GdkPixbuf *games_preimage_render (GamesPreimage * preimage,
-                                  gint width, gint height);
+                                  gint width,
+                                  gint height);
+void games_preimage_render_cairo (GamesPreimage * preimage,
+                                  cairo_t *cr,
+                                  gint width,
+                                  gint height);
 
 GdkPixbuf *games_preimage_render_sub (GamesPreimage * preimage,
                                       const char *node,



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