[gnome-games] gnometris: restore pixel-level precision to the block renderer
- From: Jason Clinton <jclinton src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games] gnometris: restore pixel-level precision to the block renderer
- Date: Thu, 27 Aug 2009 23:52:57 +0000 (UTC)
commit 0e3de87138d0494b61af804f621a1d3d036c9e83
Author: Jason D. Clinton <me jasonclinton com>
Date: Thu Aug 27 18:51:26 2009 -0500
gnometris: restore pixel-level precision to the block renderer
gnometris/blockops.cpp | 2 +-
gnometris/blocks-cache.cpp | 74 ++++++++++++++++++++++++++++++++++++++-----
gnometris/blocks-cache.h | 5 +++
gnometris/preview.cpp | 5 ++-
4 files changed, 75 insertions(+), 11 deletions(-)
---
diff --git a/gnometris/blockops.cpp b/gnometris/blockops.cpp
index d632bf1..0d40567 100644
--- a/gnometris/blockops.cpp
+++ b/gnometris/blockops.cpp
@@ -695,7 +695,6 @@ BlockOps::rescaleBlockPos ()
if (cell->actor) {
clutter_actor_set_position (CLUTTER_ACTOR(cell->actor),
x*(cell_width), y*(cell_height));
-
clutter_texture_set_cogl_texture (CLUTTER_TEXTURE(cell->actor),
blocks_cache_get_block_texture_by_id (cache, cell->color));
}
@@ -716,6 +715,7 @@ BlockOps::rescaleField ()
if (!cache)
cache = blocks_cache_new ();
blocks_cache_set_theme (cache, themeID);
+ blocks_cache_set_size (cache, cell_width);
if (background) {
clutter_actor_set_size (CLUTTER_ACTOR(background), width, height);
diff --git a/gnometris/blocks-cache.cpp b/gnometris/blocks-cache.cpp
index c13fd1a..c619560 100644
--- a/gnometris/blocks-cache.cpp
+++ b/gnometris/blocks-cache.cpp
@@ -32,6 +32,7 @@
struct _BlocksCachePrivate
{
guint theme;
+ guint size;
CoglHandle *colours;
@@ -44,7 +45,8 @@ struct _BlocksCachePrivate
enum
{
PROP_0,
- PROP_THEME
+ PROP_THEME,
+ PROP_SIZE
};
/* This is an invalid value for a CoglHandle, and distinct from COGL_INVALID_HANDLE */
@@ -162,6 +164,10 @@ blocks_cache_set_property (GObject *self,
blocks_cache_set_theme (cache, g_value_get_uint (value));
break;
+ case PROP_SIZE:
+ blocks_cache_set_size (cache, g_value_get_uint (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec);
break;
@@ -181,6 +187,10 @@ blocks_cache_get_property (GObject *self,
g_value_set_object (value, GUINT_TO_POINTER(blocks_cache_get_theme (cache)));
break;
+ case PROP_SIZE:
+ g_value_set_object (value, GUINT_TO_POINTER(blocks_cache_get_size (cache)));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec);
break;
@@ -208,6 +218,15 @@ blocks_cache_class_init (BlocksCacheClass *klass)
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
g_object_class_install_property (gobject_class, PROP_THEME, pspec);
+
+ pspec = g_param_spec_uint ("size", NULL, NULL,
+ 0, 2048, 32,
+ static_cast<GParamFlags>(G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+ g_object_class_install_property (gobject_class, PROP_SIZE, pspec);
}
/* Public API */
@@ -263,6 +282,44 @@ blocks_cache_get_theme (BlocksCache *cache)
}
/**
+ * blocks_cache_set_size:
+ * @cache:
+ * @size:
+ *
+ * Sets the block size.
+ */
+void
+blocks_cache_set_size (BlocksCache *cache,
+ guint size)
+{
+ BlocksCachePrivate *priv = cache->priv;
+
+ g_return_if_fail (IS_BLOCKS_CACHE (cache));
+
+ if (priv->size == size)
+ return;
+
+ blocks_cache_clear (cache);
+
+ priv->size = size;
+ g_object_notify (G_OBJECT (cache), "size");
+}
+
+/**
+ * blocks_cache_get_size:
+ * @cache:
+ *
+ * Returns: the the block size of @cache
+ */
+guint
+blocks_cache_get_size (BlocksCache *cache)
+{
+ g_return_val_if_fail (IS_BLOCKS_CACHE (cache), NULL);
+
+ return cache->priv->size;
+}
+
+/**
* blocks_cache_get_block_texture_by_id:
* @cache:
* @colour:
@@ -287,11 +344,11 @@ blocks_cache_get_block_texture_by_id (BlocksCache *cache,
}
if (handle == COGL_INVALID_HANDLE) {
- guint rowstride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, 32);
- guchar *cr_surface_data = static_cast<guchar*>(g_malloc0 (32 * rowstride));
- cairo_surface_t *cr_surface = cairo_image_surface_create_for_data (cr_surface_data,
- CAIRO_FORMAT_ARGB32,
- 32, 32, rowstride); /*FIXME for pixel-level precision*/
+ guint rowstride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, priv->size);
+ guchar *cr_surface_data = static_cast<guchar*>(g_malloc0 (priv->size * rowstride));
+ cairo_surface_t *cr_surface =
+ cairo_image_surface_create_for_data (cr_surface_data, CAIRO_FORMAT_ARGB32,
+ priv->size, priv->size, rowstride);
LOG_CACHE_MISS (cache);
@@ -303,12 +360,11 @@ blocks_cache_get_block_texture_by_id (BlocksCache *cache,
return COGL_INVALID_HANDLE;
}
- cairo_scale (cr, 1.0 * 32, 1.0 * 32);
+ cairo_scale (cr, 1.0 * priv->size, 1.0 * priv->size);
renderer->drawCell (cr, colour);
cairo_destroy (cr);
- handle = cogl_texture_new_from_data (32,
- 32,
+ handle = cogl_texture_new_from_data (priv->size, priv->size,
COGL_TEXTURE_NONE,
CLUTTER_CAIRO_TEXTURE_PIXEL_FORMAT,
COGL_PIXEL_FORMAT_ANY,
diff --git a/gnometris/blocks-cache.h b/gnometris/blocks-cache.h
index 491213e..bae6f8a 100644
--- a/gnometris/blocks-cache.h
+++ b/gnometris/blocks-cache.h
@@ -57,6 +57,11 @@ void blocks_cache_set_theme (BlocksCache *cache,
guint blocks_cache_get_theme (BlocksCache *cache);
+void blocks_cache_set_size (BlocksCache *cache,
+ guint size);
+
+guint blocks_cache_get_size (BlocksCache *cache);
+
CoglHandle blocks_cache_get_block_texture_by_id (BlocksCache *cache,
guint colour);
diff --git a/gnometris/preview.cpp b/gnometris/preview.cpp
index 3d609ed..7aa7017 100644
--- a/gnometris/preview.cpp
+++ b/gnometris/preview.cpp
@@ -94,7 +94,7 @@ Preview::setTheme (guint id)
if (!cache)
cache = blocks_cache_new ();
blocks_cache_set_theme (cache, themeID);
-
+ previewBlock (blocknr, color);
}
void
@@ -135,6 +135,9 @@ Preview::resize(GtkWidget *widget, GtkAllocation *allocation, Preview *preview)
{
preview->width = allocation->width;
preview->height = allocation->height;
+ if (!preview->cache)
+ preview->cache = blocks_cache_new ();
+ blocks_cache_set_size (preview->cache, PREVIEW_SIZE*4);
clutter_actor_set_anchor_point (preview->piece, PREVIEW_SIZE*10, PREVIEW_SIZE*10);
clutter_actor_set_position (CLUTTER_ACTOR(preview->piece), PREVIEW_SIZE*10, PREVIEW_SIZE*10);
preview->previewBlock (preview->blocknr, preview->color);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]