gnome-games r8474 - trunk/aisleriot



Author: chpe
Date: Tue Jan  6 18:19:47 2009
New Revision: 8474
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8474&view=rev

Log:
Add selection-color property to AisleriotSlotRenderer, and use that
colour to draw the highlighted cards with, instead of getting tinted
textures from the cache.

Modified:
   trunk/aisleriot/board.c
   trunk/aisleriot/slot-renderer.c
   trunk/aisleriot/slot-renderer.h

Modified: trunk/aisleriot/board.c
==============================================================================
--- trunk/aisleriot/board.c	(original)
+++ trunk/aisleriot/board.c	Tue Jan  6 18:19:47 2009
@@ -170,7 +170,7 @@
   Slot *selection_slot;
   int selection_start_card_id;
   GdkRectangle selection_rect;
-  GdkColor selection_colour;
+  ClutterColor selection_colour;
 
   /* Highlight */
   Slot *highlight_slot;
@@ -979,6 +979,9 @@
     slot->slot_renderer = aisleriot_slot_renderer_new (priv->textures, slot);
     g_object_ref_sink (slot->slot_renderer);
 
+    aisleriot_slot_renderer_set_highlight_color (AISLERIOT_SLOT_RENDERER (slot->slot_renderer),
+                                                 &priv->selection_colour);
+
     aisleriot_slot_renderer_set_animation_layer
       (AISLERIOT_SLOT_RENDERER (slot->slot_renderer),
        CLUTTER_CONTAINER (priv->animation_layer));
@@ -2584,7 +2587,10 @@
   AisleriotBoard *board = AISLERIOT_BOARD (widget);
   AisleriotBoardPrivate *priv = board->priv;
   GdkColor *colour = NULL;
+  GdkColor selection_colour;
   gboolean interior_focus;
+  GPtrArray *slots;
+  int i, n_slots;
 
   gtk_widget_style_get (widget,
                         "focus-line-width", &priv->focus_line_width,
@@ -2603,16 +2609,32 @@
   priv->interior_focus = interior_focus != FALSE;
 
   if (colour != NULL) {
-    priv->selection_colour = *colour;
+    selection_colour = *colour;
     gdk_color_free (colour);
   } else {
-    const GdkColor default_colour = { 0, 0 /* red */, 0 /* green */, 0xaa00 /* blue */};
+    const GdkColor default_selection_colour = { 0, 0 /* red */, 0 /* green */, 0xaa00 /* blue */};
 
-    priv->selection_colour = default_colour;
+    selection_colour = default_selection_colour;
   }
 
   games_card_images_set_selection_color (priv->images,
-                                         &priv->selection_colour);
+                                         &selection_colour);
+
+  /* Update the existing slots */
+  priv->selection_colour.red   = selection_colour.red   >> 8;
+  priv->selection_colour.green = selection_colour.green >> 8;
+  priv->selection_colour.blue  = selection_colour.blue  >> 8;
+  priv->selection_colour.alpha = 0;
+
+  slots = aisleriot_game_get_slots (priv->game);
+  n_slots = slots->len;
+  for (i = 0; i < n_slots; ++i) {
+    Slot *slot = slots->pdata[i];
+
+    if (slot->slot_renderer)
+      aisleriot_slot_renderer_set_highlight_color (AISLERIOT_SLOT_RENDERER (slot->slot_renderer),
+                                                   &priv->selection_colour);
+  }
 
   GTK_WIDGET_CLASS (aisleriot_board_parent_class)->style_set (widget, previous_style);
 }

Modified: trunk/aisleriot/slot-renderer.c
==============================================================================
--- trunk/aisleriot/slot-renderer.c	(original)
+++ trunk/aisleriot/slot-renderer.c	Tue Jan  6 18:19:47 2009
@@ -45,6 +45,8 @@
 
 static void completed_cb (AisleriotSlotRenderer *srend);
 
+static const ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
+
 G_DEFINE_TYPE (AisleriotSlotRenderer, aisleriot_slot_renderer,
                CLUTTER_TYPE_ACTOR);
 
@@ -60,6 +62,7 @@
 
   Slot *slot;
 
+  ClutterColor highlight_color;
   gboolean show_highlight;
   gint highlight_start;
 
@@ -85,6 +88,7 @@
   PROP_CACHE,
   PROP_SLOT,
   PROP_HIGHLIGHT,
+  PROP_HIGHLIGHT_COLOR,
   PROP_REVEALED_CARD,
   PROP_ANIMATION_LAYER
 };
@@ -92,6 +96,7 @@
 static void
 aisleriot_slot_renderer_class_init (AisleriotSlotRendererClass *klass)
 {
+  static const ClutterColor default_highlight_color = { 0, 0, 0xaa, 0xff };
   GObjectClass *gobject_class = (GObjectClass *) klass;
   ClutterActorClass *actor_class = (ClutterActorClass *) klass;
   GParamSpec *pspec;
@@ -130,6 +135,15 @@
                             G_PARAM_STATIC_BLURB);
   g_object_class_install_property (gobject_class, PROP_HIGHLIGHT, pspec);
 
+  pspec = clutter_param_spec_color ("highlight-color", NULL, NULL,
+                                    &default_highlight_color,
+                                    G_PARAM_WRITABLE |
+                                    G_PARAM_STATIC_NAME |
+                                    G_PARAM_STATIC_NICK |
+                                    G_PARAM_STATIC_BLURB |
+                                    G_PARAM_CONSTRUCT);
+  g_object_class_install_property (gobject_class, PROP_HIGHLIGHT_COLOR, pspec);
+
   pspec = g_param_spec_int ("revealed-card", NULL, NULL,
                             -1, G_MAXINT, 0,
                             G_PARAM_WRITABLE |
@@ -248,6 +262,11 @@
                                              g_value_get_int (value));
       break;
 
+    case PROP_HIGHLIGHT_COLOR:
+      aisleriot_slot_renderer_set_highlight_color (srend,
+                                                   g_value_get_boxed (value));
+      break;
+
     case PROP_REVEALED_CARD:
       aisleriot_slot_renderer_set_revealed_card (srend,
                                                  g_value_get_int (value));
@@ -288,6 +307,7 @@
                           aisleriot_slot_renderer_get_animation_layer (srend));
       break;
 
+    case PROP_HIGHLIGHT_COLOR:
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -300,17 +320,12 @@
 {
   AisleriotSlotRendererPrivate *priv = srend->priv;
   Card card = CARD (priv->slot->cards->data[card_num]);
-  gboolean is_highlighted;
   CoglHandle cogl_tex;
   guint tex_width, tex_height;
   int cardx, cardy;
-  static const ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
-
-  is_highlighted = priv->show_highlight && (card_num >= priv->highlight_start);
+  const ClutterColor *color;
 
-  cogl_tex = games_card_textures_cache_get_card_texture (priv->cache,
-                                                    card,
-                                                    is_highlighted);
+  cogl_tex = games_card_textures_cache_get_card_texture (priv->cache, card, FALSE);
 
   tex_width = cogl_texture_get_width (cogl_tex);
   tex_height = cogl_texture_get_height (cogl_tex);
@@ -319,7 +334,13 @@
                                   FALSE,
                                   &cardx, &cardy);
 
-  cogl_color (&white);
+  if (priv->show_highlight && (card_num >= priv->highlight_start)) {
+    color = &priv->highlight_color;
+  } else {
+    color = &white;
+  }
+
+  cogl_color (color);
   cogl_texture_rectangle (cogl_tex,
                           CLUTTER_INT_TO_FIXED (cardx),
                           CLUTTER_INT_TO_FIXED (cardy),
@@ -349,14 +370,18 @@
   if (priv->slot->cards->len <= priv->animations->len) {
     CoglHandle cogl_tex;
     guint tex_width, tex_height;
-    static const ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
 
     cogl_tex = games_card_textures_cache_get_slot_texture (priv->cache,
                                                       priv->show_highlight);
     tex_width = cogl_texture_get_width (cogl_tex);
     tex_height = cogl_texture_get_height (cogl_tex);
 
-    cogl_color (&white);
+    if (priv->show_highlight) {
+      cogl_color (&priv->highlight_color);
+    } else {
+      cogl_color (&white);
+    }
+
     cogl_texture_rectangle (cogl_tex,
                             0, 0,
                             CLUTTER_INT_TO_FIXED (tex_width),
@@ -408,6 +433,23 @@
   g_object_notify (G_OBJECT (srend), "highlight");
 }
 
+void
+aisleriot_slot_renderer_set_highlight_color (AisleriotSlotRenderer *srend,
+                                             const ClutterColor *color)
+{
+  AisleriotSlotRendererPrivate *priv = srend->priv;
+
+  g_return_if_fail (color != NULL);
+
+  if (clutter_color_equal (color, &priv->highlight_color))
+    return;
+
+  priv->highlight_color = *color;
+  priv->highlight_color.alpha = 0xff;
+
+  g_object_notify (G_OBJECT (srend), "highlight-color");
+}
+
 gint
 aisleriot_slot_renderer_get_revealed_card (AisleriotSlotRenderer *srend)
 {

Modified: trunk/aisleriot/slot-renderer.h
==============================================================================
--- trunk/aisleriot/slot-renderer.h	(original)
+++ trunk/aisleriot/slot-renderer.h	Tue Jan  6 18:19:47 2009
@@ -79,6 +79,9 @@
                                             gint hightlight_start);
 guint aisleriot_slot_renderer_get_highlight (AisleriotSlotRenderer *srend);
 
+void aisleriot_slot_renderer_set_highlight_color (AisleriotSlotRenderer *srend,
+                                                  const ClutterColor *color);
+
 void aisleriot_slot_renderer_set_revealed_card (AisleriotSlotRenderer *srend,
                                                 gint revealed_card);
 gint aisleriot_slot_renderer_get_revealed_card (AisleriotSlotRenderer *srend);



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