[libchamplain] Garbage removal in kinetic scroll & friends



commit e734cac311bf53f61c1a1f0243cba546f3d8d373
Author: Jiří Techet <techet gmail com>
Date:   Fri Apr 12 05:26:33 2013 +0200

    Garbage removal in kinetic scroll & friends

 champlain/champlain-adjustment.c          |  154 +++++++++--------------------
 champlain/champlain-adjustment.h          |   12 +--
 champlain/champlain-kinetic-scroll-view.c |   22 ++--
 champlain/champlain-view.c                |   29 ++----
 champlain/champlain-viewport.c            |   30 ++----
 5 files changed, 75 insertions(+), 172 deletions(-)
---
diff --git a/champlain/champlain-adjustment.c b/champlain/champlain-adjustment.c
index 011ac1e..2579b71 100644
--- a/champlain/champlain-adjustment.c
+++ b/champlain/champlain-adjustment.c
@@ -20,11 +20,8 @@
  * Written by: Chris Lord <chris openedhand com>, inspired by GtkAdjustment
  */
 
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
-#include <glib-object.h>
 #include <clutter/clutter.h>
 
 #include "champlain-adjustment.h"
@@ -42,8 +39,6 @@ struct _ChamplainAdjustmentPrivate
   gdouble upper;
   gdouble value;
   gdouble step_increment;
-  gdouble page_increment;
-  gdouble page_size;
 
   /* For interpolation */
   ClutterTimeline *interpolation;
@@ -63,8 +58,6 @@ enum
   PROP_UPPER,
   PROP_VALUE,
   PROP_STEP_INC,
-  PROP_PAGE_INC,
-  PROP_PAGE_SIZE,
 
   PROP_ELASTIC,
 };
@@ -84,10 +77,6 @@ static void champlain_adjustment_set_upper (ChamplainAdjustment *adjustment,
     gdouble upper);
 static void champlain_adjustment_set_step_increment (ChamplainAdjustment *adjustment,
     gdouble step);
-static void champlain_adjustment_set_page_increment (ChamplainAdjustment *adjustment,
-    gdouble page);
-static void champlain_adjustment_set_page_size (ChamplainAdjustment *adjustment,
-    gdouble size);
 
 static void
 champlain_adjustment_get_property (GObject *object,
@@ -115,14 +104,6 @@ champlain_adjustment_get_property (GObject *object,
       g_value_set_double (value, priv->step_increment);
       break;
 
-    case PROP_PAGE_INC:
-      g_value_set_double (value, priv->page_increment);
-      break;
-
-    case PROP_PAGE_SIZE:
-      g_value_set_double (value, priv->page_size);
-      break;
-
     case PROP_ELASTIC:
       g_value_set_boolean (value, priv->elastic);
       break;
@@ -160,14 +141,6 @@ champlain_adjustment_set_property (GObject *object,
       champlain_adjustment_set_step_increment (adj, g_value_get_double (value));
       break;
 
-    case PROP_PAGE_INC:
-      champlain_adjustment_set_page_increment (adj, g_value_get_double (value));
-      break;
-
-    case PROP_PAGE_SIZE:
-      champlain_adjustment_set_page_size (adj, g_value_get_double (value));
-      break;
-
     case PROP_ELASTIC:
       champlain_adjustment_set_elastic (adj, g_value_get_boolean (value));
       break;
@@ -257,24 +230,6 @@ champlain_adjustment_class_init (ChamplainAdjustmentClass *klass)
           0.0,
           CHAMPLAIN_PARAM_READWRITE));
   g_object_class_install_property (object_class,
-      PROP_PAGE_INC,
-      g_param_spec_double ("page-increment",
-          "Page Increment",
-          "Page increment",
-          -G_MAXDOUBLE,
-          G_MAXDOUBLE,
-          0.0,
-          CHAMPLAIN_PARAM_READWRITE));
-  g_object_class_install_property (object_class,
-      PROP_PAGE_SIZE,
-      g_param_spec_double ("page-size",
-          "Page Size",
-          "Page size",
-          -G_MAXDOUBLE,
-          G_MAXDOUBLE,
-          0.0,
-          CHAMPLAIN_PARAM_READWRITE));
-  g_object_class_install_property (object_class,
       PROP_ELASTIC,
       g_param_spec_boolean ("elastic",
           "Elastic",
@@ -307,17 +262,13 @@ ChamplainAdjustment *
 champlain_adjustment_new (gdouble value,
     gdouble lower,
     gdouble upper,
-    gdouble step_increment,
-    gdouble page_increment,
-    gdouble page_size)
+    gdouble step_increment)
 {
   return g_object_new (CHAMPLAIN_TYPE_ADJUSTMENT,
       "value", value,
       "lower", lower,
       "upper", upper,
       "step-increment", step_increment,
-      "page-increment", page_increment,
-      "page-size", page_size,
       NULL);
 }
 
@@ -345,7 +296,7 @@ champlain_adjustment_set_value (ChamplainAdjustment *adjustment,
 
   if (!priv->elastic)
     value = CLAMP (value, priv->lower, MAX (priv->lower,
-              priv->upper - priv->page_size));
+              priv->upper));
 
   if (priv->value != value)
     {
@@ -369,14 +320,14 @@ champlain_adjustment_clamp_page (ChamplainAdjustment *adjustment,
 
   stop_interpolation (adjustment);
 
-  lower = CLAMP (lower, priv->lower, priv->upper - priv->page_size);
-  upper = CLAMP (upper, priv->lower + priv->page_size, priv->upper);
+  lower = CLAMP (lower, priv->lower, priv->upper);
+  upper = CLAMP (upper, priv->lower, priv->upper);
 
   changed = FALSE;
 
-  if (priv->value + priv->page_size > upper)
+  if (priv->value > upper)
     {
-      priv->value = upper - priv->page_size;
+      priv->value = upper;
       changed = TRUE;
     }
 
@@ -446,39 +397,54 @@ champlain_adjustment_set_step_increment (ChamplainAdjustment *adjustment,
 }
 
 
-static void
-champlain_adjustment_set_page_increment (ChamplainAdjustment *adjustment,
-    gdouble page)
+void
+champlain_adjustment_set_values (ChamplainAdjustment *adjustment,
+    gdouble value,
+    gdouble lower,
+    gdouble upper,
+    gdouble step_increment)
 {
-  ChamplainAdjustmentPrivate *priv = adjustment->priv;
+  ChamplainAdjustmentPrivate *priv;
+  gboolean emit_changed = FALSE;
 
-  if (priv->page_increment != page)
-    {
-      priv->page_increment = page;
+  g_return_if_fail (CHAMPLAIN_IS_ADJUSTMENT (adjustment));
 
-      g_signal_emit (adjustment, signals[CHANGED], 0);
+  priv = adjustment->priv;
 
-      g_object_notify (G_OBJECT (adjustment), "page-increment");
-    }
-}
+  stop_interpolation (adjustment);
 
+  g_object_freeze_notify (G_OBJECT (adjustment));
 
-static void
-champlain_adjustment_set_page_size (ChamplainAdjustment *adjustment,
-    gdouble size)
-{
-  ChamplainAdjustmentPrivate *priv = adjustment->priv;
+  if (priv->lower != lower)
+    {
+      priv->lower = lower;
+      emit_changed = TRUE;
+
+      g_object_notify (G_OBJECT (adjustment), "lower");
+    }
 
-  if (priv->page_size != size)
+  if (priv->upper != upper)
     {
-      priv->page_size = size;
+      priv->upper = upper;
+      emit_changed = TRUE;
 
-      g_signal_emit (adjustment, signals[CHANGED], 0);
+      g_object_notify (G_OBJECT (adjustment), "upper");
+    }
 
-      g_object_notify (G_OBJECT (adjustment), "page_size");
+  if (priv->step_increment != step_increment)
+    {
+      priv->step_increment = step_increment;
+      emit_changed = TRUE;
 
-      champlain_adjustment_clamp_page (adjustment, priv->lower, priv->upper);
+      g_object_notify (G_OBJECT (adjustment), "step-increment");
     }
+
+  champlain_adjustment_set_value (adjustment, value);
+
+  if (emit_changed)
+    g_signal_emit (G_OBJECT (adjustment), signals[CHANGED], 0);
+
+  g_object_thaw_notify (G_OBJECT (adjustment));
 }
 
 
@@ -487,9 +453,7 @@ champlain_adjustment_get_values (ChamplainAdjustment *adjustment,
     gdouble *value,
     gdouble *lower,
     gdouble *upper,
-    gdouble *step_increment,
-    gdouble *page_increment,
-    gdouble *page_size)
+    gdouble *step_increment)
 {
   ChamplainAdjustmentPrivate *priv;
 
@@ -508,12 +472,6 @@ champlain_adjustment_get_values (ChamplainAdjustment *adjustment,
 
   if (step_increment)
     *step_increment = priv->step_increment;
-
-  if (page_increment)
-    *page_increment = priv->page_increment;
-
-  if (page_size)
-    *page_size = priv->page_size;
 }
 
 
@@ -553,28 +511,6 @@ interpolation_completed_cb (ClutterTimeline *timeline,
 }
 
 
-/* Note, there's super-optimal code that does a similar thing in
- * clutter-alpha.c
- *
- * Tried this instead of CLUTTER_ALPHA_SINE_INC, but I think SINE_INC looks
- * better. Leaving code here in case this is revisited.
- */
-/*
-   static guint32
-   bounce_alpha_func (ClutterAlpha *alpha,
-                   gpointer      user_data)
-   {
-   gdouble progress, angle;
-   ClutterTimeline *timeline = clutter_alpha_get_timeline (alpha);
-
-   progress = clutter_timeline_get_progressx (timeline);
-   angle = clutter_qmulx (CFX_PI_2 + CFX_PI_4/2, progress);
-
-   return clutter_sinx (angle) +
-    (CFX_ONE - clutter_sinx (CFX_PI_2 + CFX_PI_4/2));
-   }
- */
-
 void
 champlain_adjustment_interpolate (ChamplainAdjustment *adjustment,
     gdouble value,
@@ -639,8 +575,8 @@ champlain_adjustment_clamp (ChamplainAdjustment *adjustment,
 
   if (priv->value < priv->lower)
     dest = priv->lower;
-  if (priv->value > priv->upper - priv->page_size)
-    dest = priv->upper - priv->page_size;
+  if (priv->value > priv->upper)
+    dest = priv->upper;
 
   if (dest != priv->value)
     {
diff --git a/champlain/champlain-adjustment.h b/champlain/champlain-adjustment.h
index 84ef4e5..0210011 100644
--- a/champlain/champlain-adjustment.h
+++ b/champlain/champlain-adjustment.h
@@ -84,9 +84,7 @@ GType champlain_adjustment_get_type (void) G_GNUC_CONST;
 ChamplainAdjustment *champlain_adjustment_new (gdouble value,
     gdouble lower,
     gdouble upper,
-    gdouble step_increment,
-    gdouble page_increment,
-    gdouble page_size);
+    gdouble step_increment);
 gdouble champlain_adjustment_get_value (ChamplainAdjustment *adjustment);
 void champlain_adjustment_set_value (ChamplainAdjustment *adjustment,
     gdouble value);
@@ -94,16 +92,12 @@ void champlain_adjustment_set_values (ChamplainAdjustment *adjustment,
     gdouble value,
     gdouble lower,
     gdouble upper,
-    gdouble step_increment,
-    gdouble page_increment,
-    gdouble page_size);
+    gdouble step_increment);
 void champlain_adjustment_get_values (ChamplainAdjustment *adjustment,
     gdouble *value,
     gdouble *lower,
     gdouble *upper,
-    gdouble *step_increment,
-    gdouble *page_increment,
-    gdouble *page_size);
+    gdouble *step_increment);
 
 void champlain_adjustment_interpolate (ChamplainAdjustment *adjustment,
     gdouble value,
diff --git a/champlain/champlain-kinetic-scroll-view.c b/champlain/champlain-kinetic-scroll-view.c
index a5f0307..c249a9f 100644
--- a/champlain/champlain-kinetic-scroll-view.c
+++ b/champlain/champlain-kinetic-scroll-view.c
@@ -322,7 +322,7 @@ clamp_adjustments (ChamplainKineticScrollView *scroll)
           gdouble d, value, lower, step_increment;
 
           champlain_adjustment_get_values (hadj, &value, &lower, NULL,
-              &step_increment, NULL, NULL);
+              &step_increment);
           d = (rint ((value - lower) / step_increment) *
                step_increment) + lower;
           champlain_adjustment_set_value (hadj, d);
@@ -338,7 +338,7 @@ clamp_adjustments (ChamplainKineticScrollView *scroll)
           gdouble d, value, lower, step_increment;
 
           champlain_adjustment_get_values (vadj, &value, &lower, NULL,
-              &step_increment, NULL, NULL);
+              &step_increment);
           d = (rint ((value - lower) / step_increment) *
                step_increment) + lower;
           champlain_adjustment_set_value (vadj, d);
@@ -368,7 +368,7 @@ deceleration_new_frame_cb (ClutterTimeline *timeline,
 
   if (priv->child)
     {
-      gdouble value, lower, upper, page_size;
+      gdouble value, lower, upper;
       ChamplainAdjustment *hadjust, *vadjust;
       gint i;
       gboolean stop = TRUE;
@@ -391,16 +391,16 @@ deceleration_new_frame_cb (ClutterTimeline *timeline,
 
       /* Check if we've hit the upper or lower bounds and stop the timeline */
       champlain_adjustment_get_values (hadjust, &value, &lower, &upper,
-          NULL, NULL, &page_size);
-      if (((priv->dx > 0) && (value < upper - page_size)) ||
+          NULL);
+      if (((priv->dx > 0) && (value < upper)) ||
           ((priv->dx < 0) && (value > lower)))
         stop = FALSE;
 
       if (stop)
         {
           champlain_adjustment_get_values (vadjust, &value, &lower, &upper,
-              NULL, NULL, &page_size);
-          if (((priv->dy > 0) && (value < upper - page_size)) ||
+              NULL);
+          if (((priv->dy > 0) && (value < upper)) ||
               ((priv->dy < 0) && (value > lower)))
             stop = FALSE;
         }
@@ -555,7 +555,7 @@ button_release_event_cb (ClutterActor *stage,
                   /* Solving for dx */
                   d = a * priv->dx;
                   champlain_adjustment_get_values (hadjust, &value, &lower, NULL,
-                      &step_increment, NULL, NULL);
+                      &step_increment);
                   d = ((rint (((value + d) - lower) / step_increment) *
                         step_increment) + lower) - value;
                   priv->dx = (d / a);
@@ -563,7 +563,7 @@ button_release_event_cb (ClutterActor *stage,
                   /* Solving for dy */
                   d = a * (priv->dy);
                   champlain_adjustment_get_values (vadjust, &value, &lower, NULL,
-                      &step_increment, NULL, NULL);
+                      &step_increment);
                   d = ((rint (((value + d) - lower) / step_increment) *
                         step_increment) + lower) - value;
                   priv->dy = (d / a);
@@ -581,13 +581,13 @@ button_release_event_cb (ClutterActor *stage,
                   a = (1.0 - 1.0 / pow (y, 4 + 1)) / (1.0 - 1.0 / y);
 
                   champlain_adjustment_get_values (hadjust, &value, &lower, NULL,
-                      &step_increment, NULL, NULL);
+                      &step_increment);
                   d = ((rint ((value - lower) / step_increment) *
                         step_increment) + lower) - value;
                   priv->dx = (d / a);
 
                   champlain_adjustment_get_values (vadjust, &value, &lower, NULL,
-                      &step_increment, NULL, NULL);
+                      &step_increment);
                   d = ((rint ((value - lower) / step_increment) *
                         step_increment) + lower) - value;
                   priv->dy = (d / a);
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index 021f130..d62ebef 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -344,14 +344,14 @@ resize_viewport (ChamplainView *view)
 
   if (priv->zoom_level < 8)
     {
-      lower_x = -priv->viewport_width / 2.0;
-      lower_y = -priv->viewport_height / 2.0;
+      lower_x = 0.0;
+      lower_y = 0.0;
       upper_x = champlain_map_source_get_column_count (priv->map_source, priv->zoom_level) *
         champlain_map_source_get_tile_size (priv->map_source) -
-        priv->viewport_width / 2.0;
+        priv->viewport_width;
       upper_y = champlain_map_source_get_row_count (priv->map_source, priv->zoom_level) *
         champlain_map_source_get_tile_size (priv->map_source) -
-        priv->viewport_height / 2.0;
+        priv->viewport_height;
     }
 
   /*
@@ -362,21 +362,8 @@ resize_viewport (ChamplainView *view)
    */
   g_signal_handlers_block_by_func (priv->viewport, G_CALLBACK (viewport_pos_changed_cb), view);
 
-  g_object_set (hadjust, 
-      "lower", lower_x, 
-      "upper", upper_x,
-      "page-size", 1.0, 
-      "step-increment", 1.0, 
-      "elastic", TRUE, 
-      NULL);
-
-  g_object_set (vadjust, 
-      "lower", lower_y, 
-      "upper", upper_y,
-      "page-size", 1.0, 
-      "step-increment", 1.0, 
-      "elastic", TRUE, 
-      NULL);
+  champlain_adjustment_set_values (hadjust, champlain_adjustment_get_value (hadjust), lower_x, upper_x, 1.0);
+  champlain_adjustment_set_values (vadjust, champlain_adjustment_get_value (vadjust), lower_y, upper_y, 1.0);
 
   g_signal_handlers_unblock_by_func (priv->viewport, G_CALLBACK (viewport_pos_changed_cb), view);
 }
@@ -2213,7 +2200,7 @@ champlain_view_set_deceleration (ChamplainView *view,
   g_return_if_fail (CHAMPLAIN_IS_VIEW (view) &&
       rate < 2.0 && rate > 1.0001);
 
-  g_object_set (view->priv->kinetic_scroll, "deceleration", rate, NULL);
+  g_object_set (view->priv->kinetic_scroll, "decel-rate", rate, NULL);
   g_object_notify (G_OBJECT (view), "deceleration");
 }
 
@@ -2780,7 +2767,7 @@ champlain_view_get_deceleration (ChamplainView *view)
   g_return_val_if_fail (CHAMPLAIN_IS_VIEW (view), 0.0);
 
   gdouble decel = 0.0;
-  g_object_get (view->priv->kinetic_scroll, "deceleration", &decel, NULL);
+  g_object_get (view->priv->kinetic_scroll, "decel-rate", &decel, NULL);
   return decel;
 }
 
diff --git a/champlain/champlain-viewport.c b/champlain/champlain-viewport.c
index f6e1f1e..dd88f55 100644
--- a/champlain/champlain-viewport.c
+++ b/champlain/champlain-viewport.c
@@ -20,9 +20,7 @@
  * Written by: Chris Lord <chris openedhand com>
  */
 
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #include <clutter/clutter.h>
 
@@ -312,20 +310,14 @@ champlain_viewport_get_adjustments (ChamplainViewport *viewport,
       else
         {
           ChamplainAdjustment *adjustment;
-          ClutterActor *stage;
-          guint width, stage_width, increment;
+          guint width;
 
           width = clutter_actor_get_width (CLUTTER_ACTOR (viewport));
-          stage = clutter_actor_get_stage (CLUTTER_ACTOR (viewport));
-          stage_width =  (stage != NULL) ? clutter_actor_get_width (stage) : 1;
-          increment = MAX (1, MIN (stage_width, width));
 
           adjustment = champlain_adjustment_new (priv->x,
                 0,
                 width,
-                1,
-                increment,
-                increment);
+                1);
           champlain_viewport_set_adjustments (viewport,
               adjustment,
               priv->vadjustment);
@@ -340,20 +332,14 @@ champlain_viewport_get_adjustments (ChamplainViewport *viewport,
       else
         {
           ChamplainAdjustment *adjustment;
-          ClutterActor *stage;
-          guint height, stage_height, increment;
+          guint height;
 
           height = clutter_actor_get_height (CLUTTER_ACTOR (viewport));
-          stage = clutter_actor_get_stage (CLUTTER_ACTOR (viewport));
-          stage_height = (stage != NULL) ? clutter_actor_get_height (stage) : 1;
-          increment = MAX (1, MIN (stage_height, height));
 
           adjustment = champlain_adjustment_new (priv->y,
                 0,
                 height,
-                1,
-                increment,
-                increment);
+                1);
           champlain_viewport_set_adjustments (viewport,
               priv->hadjustment,
               adjustment);
@@ -391,6 +377,10 @@ champlain_viewport_set_origin (ChamplainViewport *viewport,
 
   g_object_freeze_notify (G_OBJECT (viewport));
 
+  child = clutter_actor_get_first_child (CLUTTER_ACTOR (viewport));
+  if (child && (x != priv->x || y != priv->y))
+    clutter_actor_set_position (child, -x, -y);
+
   if (x != priv->x)
     {
       priv->x = x;
@@ -412,10 +402,6 @@ champlain_viewport_set_origin (ChamplainViewport *viewport,
     }
 
   g_object_thaw_notify (G_OBJECT (viewport));
-
-  child = clutter_actor_get_first_child (CLUTTER_ACTOR (viewport));
-  if (child)
-    clutter_actor_set_position (child, -x, -y);
 }
 
 


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