[gnome-games] aisleriot: Add card-overhang style property



commit 80a35d7c07be06a3bb436c661e9254f2ce59293c
Author: Christian Persch <chpe gnome org>
Date:   Sun Jan 3 18:07:17 2010 +0100

    aisleriot: Add card-overhang style property
    
    Add a style property that controls how much of a card is allowed to hang
    off of the bottom of the screen, unseen, in expanded slots.

 aisleriot/ar-clutter-embed.c |   19 ++++++++++++++++++-
 aisleriot/ar-style-private.h |    3 +++
 aisleriot/ar-style.c         |   35 +++++++++++++++++++++++++++++++++++
 aisleriot/ar-style.h         |    2 ++
 aisleriot/board.c            |   19 +++++++++++--------
 5 files changed, 69 insertions(+), 9 deletions(-)
---
diff --git a/aisleriot/ar-clutter-embed.c b/aisleriot/ar-clutter-embed.c
index 21dc499..edee8db 100644
--- a/aisleriot/ar-clutter-embed.c
+++ b/aisleriot/ar-clutter-embed.c
@@ -273,7 +273,7 @@ ar_clutter_embed_style_set (GtkWidget *widget,
   ClutterColor selection_color;
   int focus_line_width, focus_padding;
   gboolean interior_focus;
-  double card_slot_ratio;
+  double card_slot_ratio, card_overhang;
 
   GTK_WIDGET_CLASS (ar_clutter_embed_parent_class)->style_set (widget, previous_style);
 
@@ -284,6 +284,7 @@ ar_clutter_embed_style_set (GtkWidget *widget,
                         "focus-line-width", &focus_line_width,
                         "focus-padding", &focus_padding,
                         "card-slot-ratio", &card_slot_ratio,
+                        "card-overhang", &card_overhang,
                         "selection-color", &color,
                         NULL);
 
@@ -311,6 +312,12 @@ ar_clutter_embed_style_set (GtkWidget *widget,
     g_object_notify (style_object, AR_STYLE_PROP_CARD_SLOT_RATIO);
   }
 
+  if (style_priv->card_overhang != card_overhang) {
+    style_priv->card_overhang = card_overhang;
+
+    g_object_notify (style_object, AR_STYLE_PROP_CARD_OVERHANG);
+  }
+
   if (color != NULL) {
     _ar_clutter_color_from_gdk_color (&selection_color, color);
     gdk_color_free (color);
@@ -511,6 +518,16 @@ ar_clutter_embed_class_init (ArClutterEmbedClass *klass)
                           0.1, 1.0, DEFAULT_CARD_SLOT_RATIO,
                           G_PARAM_READWRITE |
                           G_PARAM_STATIC_STRINGS));
+
+  /**
+   * ArClutterEmbed:card-overhang:
+  */
+  gtk_widget_class_install_style_property
+    (widget_class,
+     g_param_spec_double ("card-overhang", NULL, NULL,
+                          0.0, 1.0, DEFAULT_CARD_OVERHANG,
+                          G_PARAM_READWRITE |
+                          G_PARAM_STATIC_STRINGS));
 }
 
 /* public API */
diff --git a/aisleriot/ar-style-private.h b/aisleriot/ar-style-private.h
index e40b51a..4ca7340 100644
--- a/aisleriot/ar-style-private.h
+++ b/aisleriot/ar-style-private.h
@@ -31,6 +31,8 @@ static const GdkColor default_selection_color = { 0, 0 /* red */, 0 /* green */,
 #endif
 #endif /* !DEFAULT_CARD_SLOT_RATIO */
 
+#define DEFAULT_CARD_OVERHANG (0.8)
+
 struct _ArStylePrivate
 {
   GamesCardTheme* card_theme;
@@ -38,6 +40,7 @@ struct _ArStylePrivate
   ClutterColor selection_color;
 
   double card_slot_ratio;
+  double card_overhang;
 
   int dnd_drag_threshold;
   int double_click_time;
diff --git a/aisleriot/ar-style.c b/aisleriot/ar-style.c
index 182304e..2b3c8ac 100644
--- a/aisleriot/ar-style.c
+++ b/aisleriot/ar-style.c
@@ -33,6 +33,7 @@ enum
   PROP_FOCUS_LINE_WIDTH,
   PROP_FOCUS_PADDING,
   PROP_INTERIOR_FOCUS,
+  PROP_CARD_OVERHANG,
   PROP_RTL,
   PROP_SELECTION_COLOR,
   PROP_TOUCHSCREEN_MODE,
@@ -53,6 +54,7 @@ ar_style_init (ArStyle *style)
 
   _ar_clutter_color_from_gdk_color (&priv->selection_color, &default_selection_color);
   priv->card_slot_ratio = DEFAULT_CARD_SLOT_RATIO;
+  priv->card_overhang = DEFAULT_CARD_OVERHANG;
   priv->dnd_drag_threshold = 8;
   priv->double_click_time = 250;
   priv->focus_line_width = 1;
@@ -130,6 +132,10 @@ ar_style_get_property (GObject    *object,
       g_value_set_boolean (value, ar_style_get_interior_focus (style));
       break;
 
+    case PROP_CARD_OVERHANG:
+      g_value_set_double (value, ar_style_get_card_overhang (style));
+      break;
+
     case PROP_RTL:
       g_value_set_boolean (value, ar_style_get_rtl (style));
       break;
@@ -178,6 +184,7 @@ ar_style_set_property (GObject      *object,
     case PROP_FOCUS_LINE_WIDTH:
     case PROP_FOCUS_PADDING:
     case PROP_INTERIOR_FOCUS:
+    case PROP_CARD_OVERHANG:
     case PROP_RTL:
     case PROP_SELECTION_COLOR:
     case PROP_TOUCHSCREEN_MODE:
@@ -280,6 +287,20 @@ ar_style_class_init (ArStyleClass *klass)
                            G_PARAM_READABLE |
                            G_PARAM_STATIC_STRINGS));
 
+  /**
+   * ArStyle:card-overhang:
+   *
+   * This controls how much of a card is allowed to hang off of the bottom
+   * of the screen. If set to %0.0, the last card is always fully visible.
+   */
+  g_object_class_install_property
+    (object_class,
+     PROP_CARD_OVERHANG,
+     g_param_spec_double (AR_STYLE_PROP_CARD_OVERHANG, NULL, NULL,
+                          0.0, 1.0, DEFAULT_CARD_OVERHANG,
+                          G_PARAM_READABLE |
+                          G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_property
     (object_class,
      PROP_RTL,
@@ -577,6 +598,20 @@ ar_style_get_card_slot_ratio (ArStyle *style)
 }
 
 /**
+ * ar_style_get_card_overhang:
+ * @style: an #ArStyle
+ *
+ * Returns:
+ */
+double
+ar_style_get_card_overhang (ArStyle *style)
+{
+  ArStylePrivate *priv = style->priv;
+
+  return priv->card_overhang;
+}
+
+/**
  * ar_style_get_selection_color:
  * @style: an #ArStyle
  * @color: location to store the color
diff --git a/aisleriot/ar-style.h b/aisleriot/ar-style.h
index d1505af..db52c48 100644
--- a/aisleriot/ar-style.h
+++ b/aisleriot/ar-style.h
@@ -56,6 +56,7 @@ ArStyle* ar_style_new (void);
 
 #define AR_STYLE_PROP_CARD_SLOT_RATIO     "card-slot-prop"
 #define AR_STYLE_PROP_CARD_THEME          "card-theme"
+#define AR_STYLE_PROP_CARD_OVERHANG       "card-overhang"
 #define AR_STYLE_PROP_CLICK_TO_MOVE       "click-to-move"
 #define AR_STYLE_PROP_DND_DRAG_THRESHOLD  "dnd-drag-threshold"
 #define AR_STYLE_PROP_DOUBLE_CLICK_TIME   "double-click-time"
@@ -94,6 +95,7 @@ int ar_style_get_focus_line_width   (ArStyle *style);
 int ar_style_get_focus_padding      (ArStyle *style);
 
 double ar_style_get_card_slot_ratio (ArStyle *style);
+double ar_style_get_card_overhang   (ArStyle *style);
 
 void ar_style_get_selection_color  (ArStyle *style,
                                     ClutterColor * const color);
diff --git a/aisleriot/board.c b/aisleriot/board.c
index 0adee3d..190db3e 100644
--- a/aisleriot/board.c
+++ b/aisleriot/board.c
@@ -50,16 +50,15 @@
 #define ENABLE_KEYNAV
 #endif /* !HAVE_HILDON */
 
-/* The minimum size for the playing area. Almost completely arbitrary. */
-#define BOARD_MIN_WIDTH 300
-#define BOARD_MIN_HEIGHT 200
-
 /* The limits for how much overlap there is between cards and
  * how much is allowed to slip off the bottom or right.
  */
 #define MIN_DELTA (0.05)
 #define MAX_DELTA (0.2)
-#define MAX_OVERHANG (0.2)
+
+/* The minimum size for the playing area. Almost completely arbitrary. */
+#define BOARD_MIN_WIDTH 300
+#define BOARD_MIN_HEIGHT 200
 
 #define DOUBLE_TO_INT_CEIL(d) ((int) (d + 0.5))
 
@@ -629,7 +628,7 @@ slot_update_geometry (AisleriotBoard *board,
 #else
       y_from_bottom = ((double) (allocation_height - slot->rect.y)) / ((double) priv->card_size.height);
 #endif
-      dy = (y_from_bottom - MAX_OVERHANG) / n_cards;
+      dy = (y_from_bottom - (1.0 - ar_style_get_card_overhang (priv->style))) / n_cards;
       dy = CLAMP (dy, MIN_DELTA, max_dy);
     } else if (slot->expanded_right) {
       if (priv->is_rtl) {
@@ -639,7 +638,7 @@ slot_update_geometry (AisleriotBoard *board,
           max_dx = slot->expansion.dx;
 
         x_from_left = ((double) slot->rect.x) / ((double) priv->card_size.width) + 1.0;
-        dx = (x_from_left - MAX_OVERHANG) / n_cards;
+        dx = (x_from_left - (1.0 - ar_style_get_card_overhang (priv->style))) / n_cards;
         dx = CLAMP (dx, MIN_DELTA, max_dx);
 
         slot->pixeldx = DOUBLE_TO_INT_CEIL (- dx * priv->card_size.width);
@@ -656,7 +655,7 @@ slot_update_geometry (AisleriotBoard *board,
 #else
         x_from_right = ((double) (allocation_width - slot->rect.x)) / ((double) priv->card_size.width);
 #endif
-        dx = (x_from_right - MAX_OVERHANG) / n_cards;
+        dx = (x_from_right - (1.0 - ar_style_get_card_overhang (priv->style))) / n_cards;
         dx = CLAMP (dx, MIN_DELTA, max_dx);
 
         pixeldx = slot->pixeldx = DOUBLE_TO_INT_CEIL (dx * priv->card_size.width);        
@@ -2160,6 +2159,10 @@ aisleriot_board_sync_style (ArStyle *style,
     priv->card_slot_ratio = card_slot_ratio;
   }
 
+  if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_CARD_OVERHANG)) {
+    update_geometry |= TRUE;
+  }
+
   if (pspec_name == NULL || pspec_name == I_(AR_STYLE_PROP_INTERIOR_FOCUS)) {
     gboolean interior_focus;
 



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