* hildon-pannable-area.c: Added the overshoot property and removed the OVERSHOOT...
authorAlejandro G. Castro <alex@igalia.com>
Tue, 3 Jun 2008 10:26:38 +0000 (10:26 +0000)
committerAlejandro G. Castro <alex@igalia.com>
Tue, 3 Jun 2008 10:26:38 +0000 (10:26 +0000)
(hildon_pannable_area_scroll): replaced OVERSHOOT define with
overshoot property.

(hildon_pannable_area_class_init): Installed the new property.

* hildon-pannable-area-example.c: Added a sawtooth function, this
way it is easier to check the movement in the pannable.
(get_sawtooth_label): Added this function.
(main): Now we get the labels from the new get_sawtooth_label
function.

ChangeLog
examples/hildon-pannable-area-example.c
src/hildon-pannable-area.c

index 28559e0..78d51b6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2008-06-03 Alejandro G. Castro <alex@igalia.com>
+
+       * hildon-pannable-area.c: Added the overshoot property and removed
+       the OVERSHOOT define. Fixed an indent style error.
+       (hildon_pannable_area_motion_notify_cb):        
+       (hildon_pannable_area_get_property):
+       (hildon_pannable_area_set_property): Add overshoot property.
+       
+       (hildon_pannable_area_scroll): replaced OVERSHOOT define with
+       overshoot property.
+       
+       (hildon_pannable_area_class_init): Installed the new property.  
+
+       * hildon-pannable-area-example.c: Added a sawtooth function, this
+       way it is easier to check the movement in the pannable.
+       (get_sawtooth_label): Added this function.
+       (main): Now we get the labels from the new get_sawtooth_label
+       function.
+       
 2008-05-26  Alberto Garcia  <agarcia@igalia.com>
 
        * src/hildon-app-menu.h
index c165911..89cb46e 100644 (file)
@@ -36,6 +36,28 @@ on_button_clicked (GtkWidget *widget, gpointer data)
     g_debug ("Button %d clicked", GPOINTER_TO_INT (data));
 }
 
+
+static void
+get_sawtooth_label (gchar **label, guint num)
+{
+  static gchar *sawtooth = NULL;
+  gchar *label_aux, *sawtooth_aux;
+  
+  if (num % 30 != 0) {
+    sawtooth_aux = g_strconcat (" ", sawtooth, NULL);
+    g_free (sawtooth);
+    
+    sawtooth = sawtooth_aux;
+  } else {
+    sawtooth = g_strdup (" ");
+  }
+  
+  label_aux = g_strconcat (sawtooth, *label, NULL);
+  g_free (*label);
+  
+  *label = label_aux;
+}
+
 int
 main (int argc, char **args)
 {
@@ -61,7 +83,11 @@ main (int argc, char **args)
     vbox = GTK_VBOX (gtk_vbox_new (FALSE, 1));
     for (i = 0; i < 30; i++) {
             gchar *label = g_strdup_printf ("Button number %d", i);
-            GtkWidget *but = gtk_button_new_with_label (label);
+            GtkWidget *but = NULL;
+
+            get_sawtooth_label (&label, i);
+
+            but = gtk_button_new_with_label (label);
             gtk_box_pack_start (GTK_BOX (vbox), but, TRUE, TRUE, 0);
             g_signal_connect (G_OBJECT (but), "clicked", G_CALLBACK (on_button_clicked), GINT_TO_POINTER (i));
             g_free (label);
@@ -78,6 +104,9 @@ main (int argc, char **args)
     for (i = 0; i < 100; i++) {
             GtkTreeIter iter;
             gchar *label = g_strdup_printf ("Row number %d", i);
+            
+            get_sawtooth_label (&label, i);
+
             gtk_list_store_append (store, &iter);
             gtk_list_store_set (store, &iter, TEXT_COLUMN, label, -1);
             g_free (label);
index d7086b0..559d7fc 100644 (file)
 /* TODO:
  * todo items should be marked with a number and a relative position in the code where they are relevant.
  * 
- * 1  - Make OVERSHOOT a property, the default of this property is half of the pannable-area height
+ * 1  - Make OVERSHOOT a property, the default of this property is half of the pannable-area height (DONE), the property has a fixed default, we can't calculate the height in class_init
  * 2  - Add method of scrolling to the selected element of a treeview and have it align to half way point
  * 3  - Add a property for initial scrolling of the widget, so it scrolls on realize
  * 4  - Add a method of removing children from the alignment, gtk-container-remove override?
  * 5  - Remove elasticity if it is no longer required?
  * 6  x Reduce calls to queue_resize to improve performance
  * 7  - Make 'fast' factor a property
- * 8  - Strip out g_print/g_debug calls
- * 9  - Scroll policies
- * 10 - Delay click mode (only send synthetic clicks on mouse-up, as in previous
+ * 8  - Replace // comments with / * comments
+ * 9  - Strip out g_print/g_debug calls
+ * 10 - Scroll policies
+ * 11 - Delay click mode (only send synthetic clicks on mouse-up, as in previous
  *      versions.
- * 11 - 'Physical' mode for acceleration scrolling
+ * 12 - 'Physical' mode for acceleration scrolling
  */
 
 #define SMOOTH_FACTOR 0.85
 #define FORCE 5
 #define ELASTICITY 0.2
-#define OVERSHOOT 150
 
 #include <gdk/gdkx.h>
 #include "hildon-pannable-area.h"
 
 G_DEFINE_TYPE (HildonPannableArea, hildon_pannable_area, GTK_TYPE_BIN)
 #define PANNABLE_AREA_PRIVATE(o) \
-    (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_PANNABLE_AREA,       \
-                                  HildonPannableAreaPrivate))
-     typedef struct _HildonPannableAreaPrivate HildonPannableAreaPrivate;
-
-     struct _HildonPannableAreaPrivate {
-       HildonPannableAreaMode mode;
-       GdkWindow *event_window;
-       gdouble x;              /* Used to store mouse co-ordinates of the first or */
-       gdouble y;              /* previous events in a press-motion pair */
-       gdouble ex;             /* Used to store mouse co-ordinates of the last */
-       gdouble ey;             /* motion event in acceleration mode */
-       gboolean enabled;
-       gboolean clicked;
-       guint32 last_time;      /* Last event time, to stop infinite loops */
-       gint last_type;
-       gboolean moved;
-       gdouble vmin;
-       gdouble vmax;
-       gdouble decel;
-       guint sps;
-       gdouble vel_x;
-       gdouble vel_y;
-       GdkWindow *child;
-       gint ix;                        /* Initial click mouse co-ordinates */
-       gint iy;
-       gint cx;                        /* Initial click child window mouse co-ordinates */
-       gint cy;
-       guint idle_id;
-       gint overshot_dist_x;
-       gint overshot_dist_y;
-       gint overshooting_y;
-       gint overshooting_x;
-
-       GtkWidget *align;
-       gboolean hscroll;
-       gboolean vscroll;
-       GdkRectangle hscroll_rect;
-       GdkRectangle vscroll_rect;
-       guint area_width;
-
-       GtkAdjustment *hadjust;
-       GtkAdjustment *vadjust;
-
-       gdouble click_x;
-       gdouble click_y;
-
-       guint event_mode;
-
-       HildonPannableAreaIndicatorMode vindicator_mode;
-       HildonPannableAreaIndicatorMode hindicator_mode;
-
-     };
-
-     enum {
-       PROP_ENABLED = 1,
-       PROP_MODE,
-       PROP_VELOCITY_MIN,
-       PROP_VELOCITY_MAX,
-       PROP_DECELERATION,
-       PROP_SPS,
-       PROP_VINDICATOR,
-       PROP_HINDICATOR,
-
-     };
-
-     static GdkWindow *hildon_pannable_area_get_topmost (GdkWindow * window,
-                                                        gint x, gint y,
-                                                        gint * tx, gint * ty)
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), HILDON_TYPE_PANNABLE_AREA, \
+                                HildonPannableAreaPrivate))
+typedef struct _HildonPannableAreaPrivate HildonPannableAreaPrivate;
+
+struct _HildonPannableAreaPrivate {
+  HildonPannableAreaMode mode;
+  GdkWindow *event_window;
+  gdouble x;           /* Used to store mouse co-ordinates of the first or */
+  gdouble y;           /* previous events in a press-motion pair */
+  gdouble ex;          /* Used to store mouse co-ordinates of the last */
+  gdouble ey;          /* motion event in acceleration mode */
+  gboolean enabled;
+  gboolean clicked;
+  guint32 last_time;   /* Last event time, to stop infinite loops */
+  gint last_type;
+  gboolean moved;
+  gdouble vmin;
+  gdouble vmax;
+  gdouble decel;
+  guint sps;
+  gdouble vel_x;
+  gdouble vel_y;
+  GdkWindow *child;
+  gint ix;                     /* Initial click mouse co-ordinates */
+  gint iy;
+  gint cx;                     /* Initial click child window mouse co-ordinates */
+  gint cy;
+  guint idle_id;
+  gint overshot_dist_x;
+  gint overshot_dist_y;
+  gint overshooting_y;
+  gint overshooting_x;
+  gint overshoot;
+  
+  GtkWidget *align;
+  gboolean hscroll;
+  gboolean vscroll;
+  GdkRectangle hscroll_rect;
+  GdkRectangle vscroll_rect;
+  guint area_width;
+  
+  GtkAdjustment *hadjust;
+  GtkAdjustment *vadjust;
+  
+  gdouble click_x;
+  gdouble click_y;
+  
+  guint event_mode;
+  
+  HildonPannableAreaIndicatorMode vindicator_mode;
+  HildonPannableAreaIndicatorMode hindicator_mode;
+  
+};
+
+enum {
+  PROP_ENABLED = 1,
+  PROP_MODE,
+  PROP_VELOCITY_MIN,
+  PROP_VELOCITY_MAX,
+  PROP_DECELERATION,
+  PROP_SPS,
+  PROP_VINDICATOR,
+  PROP_HINDICATOR,
+  PROP_OVERSHOOT
+};
+
+static GdkWindow *hildon_pannable_area_get_topmost (GdkWindow * window,
+                                                    gint x, gint y,
+                                                    gint * tx, gint * ty)
 {
   /* Find the GdkWindow at the given point, by recursing from a given
    * parent GdkWindow. Optionally return the co-ordinates transformed
@@ -414,7 +415,7 @@ hildon_pannable_area_scroll (HildonPannableArea * area, gdouble x, gdouble y,
         if ((!priv->clicked) && (priv->vel_y > 0) &&
             (priv->mode == HILDON_PANNABLE_AREA_MODE_AUTO)) {
           priv->overshooting_y = 1;
-          priv->overshot_dist_y = MIN (priv->overshot_dist_y + priv->vel_y, OVERSHOOT);
+          priv->overshot_dist_y = MIN (priv->overshot_dist_y + priv->vel_y, priv->overshoot);
           gtk_widget_queue_resize (GTK_WIDGET (area));
         }
       } else if (v > priv->vadjust->upper - priv->vadjust->page_size) {
@@ -425,7 +426,7 @@ hildon_pannable_area_scroll (HildonPannableArea * area, gdouble x, gdouble y,
         if ((!priv->clicked) && (priv->vel_y < 0) &&
             (priv->mode == HILDON_PANNABLE_AREA_MODE_AUTO)) {
           priv->overshooting_y = 1;
-          priv->overshot_dist_y = MAX (priv->overshot_dist_y + priv->vel_y, -1*OVERSHOOT);
+          priv->overshot_dist_y = MAX (priv->overshot_dist_y + priv->vel_y, -1*priv->overshoot);
           gtk_widget_queue_resize (GTK_WIDGET (area));
         }
       } else if (sy) {
@@ -444,32 +445,32 @@ hildon_pannable_area_scroll (HildonPannableArea * area, gdouble x, gdouble y,
         if (priv->overshot_dist_y > 0) {
           if ((priv->overshooting_y < 3) && (priv->vel_y > 0)) {
             priv->overshooting_y++;
-            priv->vel_y = ((gdouble)priv->overshot_dist_y/OVERSHOOT) * priv->vel_y;
+            priv->vel_y = ((gdouble)priv->overshot_dist_y/priv->overshoot) * priv->vel_y;
 
           } else if ((priv->overshooting_y >= 3) && (priv->vel_y > 0)) {
             priv->vel_y *= -1;
             priv->overshooting_y--;
           } else if ((priv->overshooting_y > 1) && (priv->vel_y < 0)) {
             priv->overshooting_y--;
-            priv->vel_y = ((gdouble)priv->overshot_dist_y/OVERSHOOT) * priv->vel_y;
+            priv->vel_y = ((gdouble)priv->overshot_dist_y/priv->overshoot) * priv->vel_y;
           }             
-          priv->overshot_dist_y = MIN (priv->overshot_dist_y + priv->vel_y, OVERSHOOT);
+          priv->overshot_dist_y = MIN (priv->overshot_dist_y + priv->vel_y, priv->overshoot);
           if (priv->overshot_dist_y < 0) priv->overshot_dist_y = 0;
           gtk_widget_queue_resize (GTK_WIDGET (area));
 
         } else if (priv->overshot_dist_y < 0) {
           if ((priv->overshooting_y < 3) && (priv->vel_y < 0)) {
             priv->overshooting_y++;
-            priv->vel_y = ((gdouble)priv->overshot_dist_y/OVERSHOOT) * priv->vel_y * -1;
+            priv->vel_y = ((gdouble)priv->overshot_dist_y/priv->overshoot) * priv->vel_y * -1;
 
           } else if ((priv->overshooting_y >= 3) && (priv->vel_y < 0)) {
             priv->vel_y *= -1;
             priv->overshooting_y--;
           } else if ((priv->overshooting_y > 1) && (priv->vel_y > 0)) {
             priv->overshooting_y--;
-            priv->vel_y = ((gdouble)priv->overshot_dist_y/OVERSHOOT) * priv->vel_y * -1;
+            priv->vel_y = ((gdouble)priv->overshot_dist_y/priv->overshoot) * priv->vel_y * -1;
           }
-          priv->overshot_dist_y = MAX (priv->overshot_dist_y + priv->vel_y, -1*OVERSHOOT);
+          priv->overshot_dist_y = MAX (priv->overshot_dist_y + priv->vel_y, -1*priv->overshoot);
           if (priv->overshot_dist_y > 0) priv->overshot_dist_y = 0;
           gtk_widget_queue_resize (GTK_WIDGET (area));
 
@@ -630,21 +631,21 @@ hildon_pannable_area_motion_notify_cb (GtkWidget * widget,
 
       /* Overshooting while the finger is down */
       if (priv->overshot_dist_y > 0) {
-       priv->overshot_dist_y = CLAMP (priv->overshot_dist_y + y, 0, OVERSHOOT);
+       priv->overshot_dist_y = CLAMP (priv->overshot_dist_y + y, 0, priv->overshoot);
        gtk_widget_queue_resize (GTK_WIDGET (area));
       } else if (priv->overshot_dist_y < 0) {
-       priv->overshot_dist_y = CLAMP (priv->overshot_dist_y + y, -1 * OVERSHOOT, 0);
+       priv->overshot_dist_y = CLAMP (priv->overshot_dist_y + y, -1 * priv->overshoot, 0);
        gtk_widget_queue_resize (GTK_WIDGET (area));
       } else {
        v = priv->vadjust->value - y;
 
        if (v < priv->vadjust->lower) {
           priv->overshooting_y = 1;
-         priv->overshot_dist_y = MIN (priv->overshot_dist_y + y, OVERSHOOT);
+         priv->overshot_dist_y = MIN (priv->overshot_dist_y + y, priv->overshoot);
          gtk_widget_queue_resize (GTK_WIDGET (area));
         } else if (v > priv->vadjust->upper - priv->vadjust->page_size) {
           priv->overshooting_y = 1;
-         priv->overshot_dist_y = MAX (priv->overshot_dist_y + y, -1 * OVERSHOOT);
+         priv->overshot_dist_y = MAX (priv->overshot_dist_y + y, -1 * priv->overshoot);
          gtk_widget_queue_resize (GTK_WIDGET (area));
        } else {
          hildon_pannable_area_scroll (area, x, y, NULL, NULL);
@@ -912,6 +913,10 @@ hildon_pannable_area_get_property (GObject * object, guint property_id,
   case PROP_HINDICATOR:
     g_value_set_enum (value, priv->hindicator_mode);
     break;
+  case PROP_OVERSHOOT:
+    g_value_set_int (value, priv->overshoot);
+    break;
+
 
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -959,6 +964,9 @@ hildon_pannable_area_set_property (GObject * object, guint property_id,
   case PROP_HINDICATOR:
     priv->hindicator_mode = g_value_get_enum (value);
     break;
+  case PROP_OVERSHOOT:
+    priv->overshoot = g_value_get_int (value);
+    break;
 
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -1067,7 +1075,7 @@ hildon_pannable_area_map (GtkWidget * widget)
 
   if (priv->mode == HILDON_PANNABLE_AREA_MODE_AUTO) {
     // TODO 3: This should only be active if this hint has been set
-    //priv->overshot_dist_y = OVERSHOOT;
+    //priv->overshot_dist_y = priv->overshoot;
 
     //priv->vel_y = priv->vmax * 0.1;
 
@@ -1273,6 +1281,15 @@ hildon_pannable_area_class_init (HildonPannableAreaClass * klass)
                                                      G_PARAM_READWRITE |
                                                      G_PARAM_CONSTRUCT));
 
+  g_object_class_install_property (object_class,
+                                  PROP_OVERSHOOT,
+                                  g_param_spec_int ("overshoot",
+                                                     "Overshoot distance",
+                                                     "Space we allow the widget to pass over its limits when hitting the edges.",
+                                                     G_MININT, G_MAXINT, 150,
+                                                     G_PARAM_READWRITE |
+                                                     G_PARAM_CONSTRUCT));
+
   gtk_widget_class_install_style_property (widget_class,
                                           g_param_spec_uint
                                           ("indicator-width",