Hi,
I wanted a way to move a region of a ClutterCairoTexture to a new
location within the texture. I created
clutter_cairo_texture_move_region() which is attached.
My purpose for this is to make side-scrolling graphs; if there is a
better way to do this I'm all ears!
Thanks!
-- Christian
From 43bad801bd5232ba076848000c02983a11f5fad6 Mon Sep 17 00:00:00 2001
From: Christian Hergert ch...@dronelabs.com
Date: Tue, 2 Mar 2010 02:00:46 -0800
Subject: [PATCH] Add clutter_cairo_texture_move_region.
Provides support for moving a region of a clutter texture to
another region of the texture.
---
clutter/clutter-cairo-texture.c | 54 +++
clutter/clutter-cairo-texture.h | 10 ++-
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/clutter/clutter-cairo-texture.c b/clutter/clutter-cairo-texture.c
index 88cf5d8..e678a9b 100644
--- a/clutter/clutter-cairo-texture.c
+++ b/clutter/clutter-cairo-texture.c
@@ -761,3 +761,57 @@ clutter_cairo_texture_clear (ClutterCairoTexture *self)
memset (priv-cr_surface_data, 0, priv-height * priv-rowstride);
}
+
+/**
+ * clutter_cairo_texture_move_region:
+ * @self: a #ClutterCairoTexture.
+ * @src_x: upper left coordinate to use from source data.
+ * @src_y: upper left coordinate to use from source data.
+ * @dst_x: upper left destination horizontal coordinate.
+ * @dst_y: upper left destination vertical coordinate.
+ * @width: width of the source region.
+ * @height: height of the source region.
+ *
+ * Moves a rectangular region of the texture to a new location within the
+ * texture. The existing region is left in place.
+ *
+ * Since: 1.2
+ */
+void
+clutter_cairo_texture_move_region (ClutterCairoTexture *self,
+ guintsrc_x,
+ guintsrc_y,
+ guintwidth,
+ guintheight,
+ guintdst_x,
+ guintdst_y)
+{
+ ClutterCairoTexturePrivate *priv;
+ CoglHandle cogl_texture;
+
+ g_return_if_fail (CLUTTER_IS_CAIRO_TEXTURE (self));
+ g_return_if_fail (width 0);
+ g_return_if_fail (height 0);
+
+ priv = self-priv;
+
+ if (!priv-cr_surface_data)
+return;
+
+ if (dst_x + width priv-width)
+width = priv-width - dst_x;
+
+ if (dst_y + height priv-height)
+height = priv-height - dst_y;
+
+ cogl_texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (self));
+ cogl_texture_set_region (cogl_texture,
+ src_x, src_y,
+ dst_x, dst_y,
+ width, height,
+ priv-width, priv-height,
+ CLUTTER_CAIRO_TEXTURE_PIXEL_FORMAT,
+ priv-rowstride,
+ priv-cr_surface_data);
+ clutter_actor_queue_redraw (CLUTTER_ACTOR (self));
+}
diff --git a/clutter/clutter-cairo-texture.h b/clutter/clutter-cairo-texture.h
index 675adfa..7368260 100644
--- a/clutter/clutter-cairo-texture.h
+++ b/clutter/clutter-cairo-texture.h
@@ -96,11 +96,17 @@ void clutter_cairo_texture_set_surface_size (ClutterCairoTexture *self,
void clutter_cairo_texture_get_surface_size (ClutterCairoTexture *self,
guint *width,
guint *height);
-
+void clutter_cairo_texture_move_region (ClutterCairoTexture *self,
+ guintsrc_x,
+ guintsrc_y,
+ guintwidth,
+ guintheight,
+ guintdst_x,
+ guintdst_y);
void clutter_cairo_texture_clear(ClutterCairoTexture *self);
void clutter_cairo_set_source_color (cairo_t *cr,
- const ClutterColor *color);
+ const ClutterColor *color);
G_END_DECLS
--
1.7.0