gnome-games r8160 - trunk/aisleriot



Author: jclinton
Date: Tue Oct 21 19:46:54 2008
New Revision: 8160
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8160&view=rev

Log:
Added a property to AisleriotSlotRenderer to set the highlight start
card. G_MAXUINT means no highlight. Updated
slot_update_card_images_full to use this.

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 Oct 21 19:46:54 2008
@@ -250,7 +250,7 @@
                                           Slot *slot);
 static void slot_update_card_images_full (AisleriotBoard *board,
                                           Slot *slot,
-                                          int highlight_start_card_id);
+                                          guint highlight_start_card_id);
 
 #ifndef HAVE_HILDON 
 
@@ -685,7 +685,7 @@
       gdk_window_invalidate_rect (widget->window, &priv->selection_rect, FALSE);
 
       /* Clear selection card images */
-      slot_update_card_images_full (board, priv->selection_slot, G_MAXINT);
+      slot_update_card_images_full (board, priv->selection_slot, G_MAXUINT);
     }
 
     priv->selection_slot = NULL;
@@ -1012,7 +1012,7 @@
 static void
 slot_update_card_images_full (AisleriotBoard *board,
                               Slot *slot,
-                              int highlight_start_card_id)
+                              guint highlight_start_card_id)
 {
   AisleriotBoardPrivate *priv = board->priv;
   ClutterActor *stage
@@ -1032,7 +1032,9 @@
                            slot->slot_renderer, NULL);
   }
 
-  clutter_actor_queue_redraw (slot->slot_renderer);
+  aisleriot_slot_renderer_set_highlight
+    (AISLERIOT_SLOT_RENDERER (slot->slot_renderer),
+     priv->show_highlight ? highlight_start_card_id : G_MAXUINT);
 }
 
 static void
@@ -1040,7 +1042,7 @@
                          Slot *slot)
 {
   AisleriotBoardPrivate *priv = board->priv;
-  int highlight_start_card_id = G_MAXINT;
+  int highlight_start_card_id = G_MAXUINT;
 
   if (G_UNLIKELY (slot == priv->highlight_slot &&
                   priv->show_highlight)) {
@@ -1384,7 +1386,7 @@
     /* It's ok to call this directly here, since the old highlight_slot cannot
      * have been the same as the current selection_slot!
      */
-    slot_update_card_images_full (board, old_slot, G_MAXINT);
+    slot_update_card_images_full (board, old_slot, G_MAXUINT);
   }
 
   if (!cards_are_droppable (board, slot))

Modified: trunk/aisleriot/slot-renderer.c
==============================================================================
--- trunk/aisleriot/slot-renderer.c	(original)
+++ trunk/aisleriot/slot-renderer.c	Tue Oct 21 19:46:54 2008
@@ -53,7 +53,7 @@
   AisleriotCardCache *cache;
   Slot *slot;
   gboolean show_highlight;
-  guint highlight_start_card_id;
+  guint highlight_start;
 };
 
 enum
@@ -61,7 +61,8 @@
   PROP_0,
 
   PROP_CACHE,
-  PROP_SLOT
+  PROP_SLOT,
+  PROP_HIGHLIGHT
 };
 
 static void
@@ -96,6 +97,16 @@
                                 G_PARAM_STATIC_BLURB);
   g_object_class_install_property (gobject_class, PROP_SLOT, pspec);
 
+  pspec = g_param_spec_uint ("highlight", NULL, NULL,
+                             0, G_MAXUINT, 0,
+                             G_PARAM_WRITABLE |
+                             G_PARAM_READABLE |
+                             G_PARAM_CONSTRUCT_ONLY |
+                             G_PARAM_STATIC_NAME |
+                             G_PARAM_STATIC_NICK |
+                             G_PARAM_STATIC_BLURB);
+  g_object_class_install_property (gobject_class, PROP_HIGHLIGHT, pspec);
+
   g_type_class_add_private (klass, sizeof (AisleriotSlotRendererPrivate));
 }
 
@@ -106,7 +117,7 @@
 
   priv = self->priv = AISLERIOT_SLOT_RENDERER_GET_PRIVATE (self);
 
-  priv->highlight_start_card_id = G_MAXUINT;
+  priv->highlight_start = G_MAXUINT;
 }
 
 static void
@@ -171,6 +182,11 @@
       priv->slot = g_value_get_pointer (value);
       break;
 
+    case PROP_HIGHLIGHT:
+      aisleriot_slot_renderer_set_highlight (srend,
+                                             g_value_get_uint (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -183,8 +199,18 @@
                                       GValue *value,
                                       GParamSpec *pspec)
 {
-  /* All properties are write-only */
-  G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  AisleriotSlotRenderer *srend = AISLERIOT_SLOT_RENDERER (object);
+
+  switch (property_id) {
+    case PROP_HIGHLIGHT:
+      g_value_set_uint (value,
+                        aisleriot_slot_renderer_get_highlight (srend));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+  }
 }
 
 static void
@@ -230,7 +256,7 @@
     CoglHandle cogl_tex;
     guint tex_width, tex_height;
 
-    is_highlighted = (i >= priv->highlight_start_card_id);
+    is_highlighted = priv->show_highlight && (i >= priv->highlight_start);
 
     cogl_tex = aisleriot_card_cache_get_card_texture (priv->cache,
                                                       card,
@@ -250,3 +276,25 @@
     cardy += priv->slot->pixeldy;
   }
 }
+
+guint
+aisleriot_slot_renderer_get_highlight (AisleriotSlotRenderer *srend)
+{
+  g_return_val_if_fail (AISLERIOT_IS_SLOT_RENDERER (srend), 0);
+
+  return srend->priv->highlight_start;
+}
+
+void
+aisleriot_slot_renderer_set_highlight (AisleriotSlotRenderer *srend,
+                                       guint highlight)
+{
+  AisleriotSlotRendererPrivate *priv = srend->priv;
+
+  g_return_if_fail (AISLERIOT_IS_SLOT_RENDERER (srend));
+
+  priv->highlight_start = highlight;
+  priv->show_highlight = priv->highlight_start != G_MAXUINT;
+
+  clutter_actor_queue_redraw (CLUTTER_ACTOR (srend));
+}

Modified: trunk/aisleriot/slot-renderer.h
==============================================================================
--- trunk/aisleriot/slot-renderer.h	(original)
+++ trunk/aisleriot/slot-renderer.h	Tue Oct 21 19:46:54 2008
@@ -68,6 +68,10 @@
 ClutterActor *aisleriot_slot_renderer_new (AisleriotCardCache *cache,
                                            Slot *slot);
 
+void aisleriot_slot_renderer_set_highlight (AisleriotSlotRenderer *srend,
+                                            guint hightlight_start);
+guint aisleriot_slot_renderer_get_highlight (AisleriotSlotRenderer *srend);
+
 G_END_DECLS
 
 #endif /* __AISLERIOT_SLOT_RENDERER_H__ */



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