From: Pierre-Luc Beaudoin Date: Sat, 16 May 2009 19:10:54 +0000 (-0400) Subject: Port Tidy to Clutter 0.9 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4861c5d917d937cd4c7f0406f529c8ff2c4f0b2f;p=libchamplain Port Tidy to Clutter 0.9 --- diff --git a/tidy/tidy-adjustment.c b/tidy/tidy-adjustment.c index 3e14a53..ee73dc7 100644 --- a/tidy/tidy-adjustment.c +++ b/tidy/tidy-adjustment.c @@ -25,9 +25,7 @@ #endif #include -#include -#include -#include +#include #include "tidy-adjustment.h" #include "tidy-marshal.h" @@ -39,19 +37,19 @@ G_DEFINE_TYPE (TidyAdjustment, tidy_adjustment, G_TYPE_OBJECT) struct _TidyAdjustmentPrivate { - ClutterFixed lower; - ClutterFixed upper; - ClutterFixed value; - ClutterFixed step_increment; - ClutterFixed page_increment; - ClutterFixed page_size; + gdouble lower; + gdouble upper; + gdouble value; + gdouble step_increment; + gdouble page_increment; + gdouble page_size; /* For interpolation */ ClutterTimeline *interpolation; - ClutterFixed dx; - ClutterFixed old_position; - ClutterFixed new_position; - + gdouble dx; + gdouble old_position; + gdouble new_position; + /* For elasticity */ gboolean elastic; ClutterAlpha *bounce_alpha; @@ -67,7 +65,7 @@ enum PROP_STEP_INC, PROP_PAGE_INC, PROP_PAGE_SIZE, - + PROP_ELASTIC, }; @@ -102,29 +100,29 @@ tidy_adjustment_get_property (GObject *object, switch (prop_id) { case PROP_LOWER: - g_value_set_double (value, CLUTTER_FIXED_TO_DOUBLE (priv->lower)); + g_value_set_double (value, priv->lower); break; case PROP_UPPER: - g_value_set_double (value, CLUTTER_FIXED_TO_DOUBLE (priv->upper)); + g_value_set_double (value, priv->upper); break; case PROP_VALUE: - g_value_set_double (value, CLUTTER_FIXED_TO_DOUBLE (priv->value)); + g_value_set_double (value, priv->value); break; case PROP_STEP_INC: - g_value_set_double (value, CLUTTER_FIXED_TO_DOUBLE (priv->step_increment)); + g_value_set_double (value, priv->step_increment); break; case PROP_PAGE_INC: - g_value_set_double (value, CLUTTER_FIXED_TO_DOUBLE (priv->page_increment)); + g_value_set_double (value, priv->page_increment); break; case PROP_PAGE_SIZE: - g_value_set_double (value, CLUTTER_FIXED_TO_DOUBLE (priv->page_size)); + g_value_set_double (value, priv->page_size); break; - + case PROP_ELASTIC: g_value_set_boolean (value, priv->elastic); break; @@ -168,7 +166,7 @@ tidy_adjustment_set_property (GObject *object, case PROP_PAGE_SIZE: tidy_adjustment_set_page_size (adj, g_value_get_double (value)); break; - + case PROP_ELASTIC: tidy_adjustment_set_elastic (adj, g_value_get_boolean (value)); break; @@ -188,7 +186,7 @@ stop_interpolation (TidyAdjustment *adjustment) clutter_timeline_stop (priv->interpolation); g_object_unref (priv->interpolation); priv->interpolation = NULL; - + if (priv->bounce_alpha) { g_object_unref (priv->bounce_alpha); @@ -321,64 +319,22 @@ tidy_adjustment_new (gdouble value, NULL); } -TidyAdjustment * -tidy_adjustment_newx (ClutterFixed value, - ClutterFixed lower, - ClutterFixed upper, - ClutterFixed step_increment, - ClutterFixed page_increment, - ClutterFixed page_size) -{ - TidyAdjustment *retval; - TidyAdjustmentPrivate *priv; - - retval = g_object_new (TIDY_TYPE_ADJUSTMENT, NULL); - priv = retval->priv; - - priv->value = value; - priv->lower = lower; - priv->upper = upper; - priv->step_increment = step_increment; - priv->page_increment = page_increment; - priv->page_size = page_size; - - return retval; -} - -ClutterFixed -tidy_adjustment_get_valuex (TidyAdjustment *adjustment) -{ - TidyAdjustmentPrivate *priv; - - g_return_val_if_fail (TIDY_IS_ADJUSTMENT (adjustment), 0); - - priv = adjustment->priv; - - if (adjustment->priv->interpolation) - { - return MAX (priv->lower, MIN (priv->upper - priv->page_size, - adjustment->priv->new_position)); - } - else - return adjustment->priv->value; -} - gdouble tidy_adjustment_get_value (TidyAdjustment *adjustment) { g_return_val_if_fail (TIDY_IS_ADJUSTMENT (adjustment), 0.0); - return CLUTTER_FIXED_TO_FLOAT (adjustment->priv->value); + return adjustment->priv->value; } void -tidy_adjustment_set_valuex (TidyAdjustment *adjustment, - ClutterFixed value) +tidy_adjustment_set_value (TidyAdjustment *adjustment, + double value) { TidyAdjustmentPrivate *priv; - + g_return_if_fail (TIDY_IS_ADJUSTMENT (adjustment)); - + priv = adjustment->priv; stop_interpolation (adjustment); @@ -395,31 +351,24 @@ tidy_adjustment_set_valuex (TidyAdjustment *adjustment, } void -tidy_adjustment_set_value (TidyAdjustment *adjustment, - gdouble value) -{ - tidy_adjustment_set_valuex (adjustment, CLUTTER_FLOAT_TO_FIXED (value)); -} - -void -tidy_adjustment_clamp_pagex (TidyAdjustment *adjustment, - ClutterFixed lower, - ClutterFixed upper) +tidy_adjustment_clamp_page (TidyAdjustment *adjustment, + double lower, + double upper) { gboolean changed; TidyAdjustmentPrivate *priv; - + g_return_if_fail (TIDY_IS_ADJUSTMENT (adjustment)); - + priv = adjustment->priv; - + stop_interpolation (adjustment); lower = CLAMP (lower, priv->lower, priv->upper - priv->page_size); upper = CLAMP (upper, priv->lower + priv->page_size, priv->upper); - + changed = FALSE; - + if (priv->value + priv->page_size > upper) { priv->value = upper - priv->page_size; @@ -431,37 +380,26 @@ tidy_adjustment_clamp_pagex (TidyAdjustment *adjustment, priv->value = lower; changed = TRUE; } - + if (changed) g_object_notify (G_OBJECT (adjustment), "value"); } -void -tidy_adjustment_clamp_page (TidyAdjustment *adjustment, - gdouble lower, - gdouble upper) -{ - tidy_adjustment_clamp_pagex (adjustment, - CLUTTER_FLOAT_TO_FIXED (lower), - CLUTTER_FLOAT_TO_FIXED (upper)); -} - static void tidy_adjustment_set_lower (TidyAdjustment *adjustment, gdouble lower) { TidyAdjustmentPrivate *priv = adjustment->priv; - ClutterFixed value = CLUTTER_FLOAT_TO_FIXED (lower); - - if (priv->lower != value) + + if (priv->lower != lower) { - priv->lower = value; + priv->lower = lower; g_signal_emit (adjustment, signals[CHANGED], 0); g_object_notify (G_OBJECT (adjustment), "lower"); - tidy_adjustment_clamp_pagex (adjustment, priv->lower, priv->upper); + tidy_adjustment_clamp_page (adjustment, priv->lower, priv->upper); } } @@ -470,17 +408,16 @@ tidy_adjustment_set_upper (TidyAdjustment *adjustment, gdouble upper) { TidyAdjustmentPrivate *priv = adjustment->priv; - ClutterFixed value = CLUTTER_FLOAT_TO_FIXED (upper); - - if (priv->upper != value) + + if (priv->upper != upper) { - priv->upper = value; + priv->upper = upper; g_signal_emit (adjustment, signals[CHANGED], 0); g_object_notify (G_OBJECT (adjustment), "upper"); - - tidy_adjustment_clamp_pagex (adjustment, priv->lower, priv->upper); + + tidy_adjustment_clamp_page (adjustment, priv->lower, priv->upper); } } @@ -489,11 +426,10 @@ tidy_adjustment_set_step_increment (TidyAdjustment *adjustment, gdouble step) { TidyAdjustmentPrivate *priv = adjustment->priv; - ClutterFixed value = CLUTTER_FLOAT_TO_FIXED (step); - - if (priv->step_increment != value) + + if (priv->step_increment != step) { - priv->step_increment = value; + priv->step_increment = step; g_signal_emit (adjustment, signals[CHANGED], 0); @@ -506,11 +442,10 @@ tidy_adjustment_set_page_increment (TidyAdjustment *adjustment, gdouble page) { TidyAdjustmentPrivate *priv = adjustment->priv; - ClutterFixed value = CLUTTER_FLOAT_TO_FIXED (page); - if (priv->page_increment != value) + if (priv->page_increment != page) { - priv->page_increment = value; + priv->page_increment = page; g_signal_emit (adjustment, signals[CHANGED], 0); @@ -523,40 +458,39 @@ tidy_adjustment_set_page_size (TidyAdjustment *adjustment, gdouble size) { TidyAdjustmentPrivate *priv = adjustment->priv; - ClutterFixed value = CLUTTER_FLOAT_TO_FIXED (size); - if (priv->page_size != value) + if (priv->page_size != size) { - priv->page_size = value; + priv->page_size = size; g_signal_emit (adjustment, signals[CHANGED], 0); g_object_notify (G_OBJECT (adjustment), "page_size"); - tidy_adjustment_clamp_pagex (adjustment, priv->lower, priv->upper); + tidy_adjustment_clamp_page (adjustment, priv->lower, priv->upper); } } void tidy_adjustment_set_valuesx (TidyAdjustment *adjustment, - ClutterFixed value, - ClutterFixed lower, - ClutterFixed upper, - ClutterFixed step_increment, - ClutterFixed page_increment, - ClutterFixed page_size) + gdouble value, + gdouble lower, + gdouble upper, + gdouble step_increment, + gdouble page_increment, + gdouble page_size) { TidyAdjustmentPrivate *priv; gboolean emit_changed = FALSE; - + g_return_if_fail (TIDY_IS_ADJUSTMENT (adjustment)); - + priv = adjustment->priv; - + stop_interpolation (adjustment); emit_changed = FALSE; - + g_object_freeze_notify (G_OBJECT (adjustment)); if (priv->lower != lower) @@ -598,8 +532,8 @@ tidy_adjustment_set_valuesx (TidyAdjustment *adjustment, g_object_notify (G_OBJECT (adjustment), "page-size"); } - - tidy_adjustment_set_valuex (adjustment, value); + + tidy_adjustment_set_value (adjustment, value); if (emit_changed) g_signal_emit (G_OBJECT (adjustment), signals[CHANGED], 0); @@ -607,39 +541,21 @@ tidy_adjustment_set_valuesx (TidyAdjustment *adjustment, g_object_thaw_notify (G_OBJECT (adjustment)); } -void -tidy_adjustment_set_values (TidyAdjustment *adjustment, - gdouble value, - gdouble lower, - gdouble upper, - gdouble step_increment, - gdouble page_increment, - gdouble page_size) -{ - tidy_adjustment_set_valuesx (adjustment, - CLUTTER_FLOAT_TO_FIXED (value), - CLUTTER_FLOAT_TO_FIXED (lower), - CLUTTER_FLOAT_TO_FIXED (upper), - CLUTTER_FLOAT_TO_FIXED (step_increment), - CLUTTER_FLOAT_TO_FIXED (page_increment), - CLUTTER_FLOAT_TO_FIXED (page_size)); -} - void tidy_adjustment_get_valuesx (TidyAdjustment *adjustment, - ClutterFixed *value, - ClutterFixed *lower, - ClutterFixed *upper, - ClutterFixed *step_increment, - ClutterFixed *page_increment, - ClutterFixed *page_size) + gdouble *value, + gdouble *lower, + gdouble *upper, + gdouble *step_increment, + gdouble *page_increment, + gdouble *page_size) { TidyAdjustmentPrivate *priv; - + g_return_if_fail (TIDY_IS_ADJUSTMENT (adjustment)); - + priv = adjustment->priv; - + if (lower) *lower = priv->lower; @@ -647,7 +563,7 @@ tidy_adjustment_get_valuesx (TidyAdjustment *adjustment, *upper = priv->upper; if (value) - *value = tidy_adjustment_get_valuex (adjustment); + *value = tidy_adjustment_get_value (adjustment); if (step_increment) *step_increment = priv->step_increment; @@ -669,28 +585,28 @@ tidy_adjustment_get_values (TidyAdjustment *adjustment, gdouble *page_size) { TidyAdjustmentPrivate *priv; - + g_return_if_fail (TIDY_IS_ADJUSTMENT (adjustment)); - + priv = adjustment->priv; - + if (lower) - *lower = CLUTTER_FIXED_TO_DOUBLE (priv->lower); + *lower = priv->lower; if (upper) - *upper = CLUTTER_FIXED_TO_DOUBLE (priv->upper); + *upper = priv->upper; if (value) - *value = CLUTTER_FIXED_TO_DOUBLE (tidy_adjustment_get_valuex (adjustment)); + *value = tidy_adjustment_get_value (adjustment); if (step_increment) - *step_increment = CLUTTER_FIXED_TO_DOUBLE (priv->step_increment); + *step_increment = priv->step_increment; if (page_increment) - *page_increment = CLUTTER_FIXED_TO_DOUBLE (priv->page_increment); + *page_increment = priv->page_increment; if (page_size) - *page_size = CLUTTER_FIXED_TO_DOUBLE (priv->page_size); + *page_size = priv->page_size; } static void @@ -703,18 +619,16 @@ interpolation_new_frame_cb (ClutterTimeline *timeline, priv->interpolation = NULL; if (priv->elastic && priv->bounce_alpha) { - gdouble progress = clutter_alpha_get_alpha (priv->bounce_alpha) / - (gdouble)CLUTTER_ALPHA_MAX_ALPHA; - gdouble dx = CLUTTER_FIXED_TO_FLOAT (priv->old_position) + - CLUTTER_FIXED_TO_FLOAT (priv->new_position - priv->old_position) * + gdouble progress = clutter_alpha_get_alpha (priv->bounce_alpha) / 1; + gdouble dx = priv->old_position + + (priv->new_position - priv->old_position) * progress; tidy_adjustment_set_value (adjustment, dx); } else - tidy_adjustment_set_valuex (adjustment, + tidy_adjustment_set_value (adjustment, priv->old_position + - clutter_qmulx (CLUTTER_INT_TO_FIXED (frame_num), - priv->dx)); + frame_num * priv->dx); priv->interpolation = timeline; } @@ -725,7 +639,7 @@ interpolation_completed_cb (ClutterTimeline *timeline, TidyAdjustmentPrivate *priv = adjustment->priv; stop_interpolation (adjustment); - tidy_adjustment_set_valuex (adjustment, + tidy_adjustment_set_value (adjustment, priv->new_position); } @@ -740,7 +654,7 @@ static guint32 bounce_alpha_func (ClutterAlpha *alpha, gpointer user_data) { - ClutterFixed progress, angle; + gdouble progress, angle; ClutterTimeline *timeline = clutter_alpha_get_timeline (alpha); progress = clutter_timeline_get_progressx (timeline); @@ -752,8 +666,8 @@ bounce_alpha_func (ClutterAlpha *alpha, */ void -tidy_adjustment_interpolatex (TidyAdjustment *adjustment, - ClutterFixed value, +tidy_adjustment_interpolate (TidyAdjustment *adjustment, + gdouble value, guint n_frames, guint fps) { @@ -763,22 +677,20 @@ tidy_adjustment_interpolatex (TidyAdjustment *adjustment, if (n_frames <= 1) { - tidy_adjustment_set_valuex (adjustment, value); + tidy_adjustment_set_value (adjustment, value); return; } priv->old_position = priv->value; priv->new_position = value; - priv->dx = clutter_qdivx (priv->new_position - priv->old_position, - CLUTTER_INT_TO_FIXED (n_frames)); + priv->dx = (priv->new_position - priv->old_position) * n_frames; priv->interpolation = clutter_timeline_new (n_frames, fps); - + if (priv->elastic) priv->bounce_alpha = clutter_alpha_new_full (priv->interpolation, - CLUTTER_ALPHA_SINE_INC, - NULL, NULL); - + CLUTTER_EASE_OUT_SINE); + g_signal_connect (priv->interpolation, "new-frame", G_CALLBACK (interpolation_new_frame_cb), @@ -787,20 +699,8 @@ tidy_adjustment_interpolatex (TidyAdjustment *adjustment, "completed", G_CALLBACK (interpolation_completed_cb), adjustment); - - clutter_timeline_start (priv->interpolation); -} -void -tidy_adjustment_interpolate (TidyAdjustment *adjustment, - gdouble value, - guint n_frames, - guint fps) -{ - tidy_adjustment_interpolatex (adjustment, - CLUTTER_FLOAT_TO_FIXED (value), - n_frames, - fps); + clutter_timeline_start (priv->interpolation); } gboolean @@ -823,25 +723,25 @@ tidy_adjustment_clamp (TidyAdjustment *adjustment, guint fps) { TidyAdjustmentPrivate *priv = adjustment->priv; - ClutterFixed dest = priv->value; - + gdouble dest = priv->value; + if (priv->value < priv->lower) dest = priv->lower; if (priv->value > priv->upper - priv->page_size) dest = priv->upper - priv->page_size; - + if (dest != priv->value) { if (interpolate) - tidy_adjustment_interpolatex (adjustment, + tidy_adjustment_interpolate (adjustment, dest, n_frames, fps); else - tidy_adjustment_set_valuex (adjustment, dest); - + tidy_adjustment_set_value (adjustment, dest); + return TRUE; } - + return FALSE; } diff --git a/tidy/tidy-adjustment.h b/tidy/tidy-adjustment.h index 98f531e..3215354 100644 --- a/tidy/tidy-adjustment.h +++ b/tidy/tidy-adjustment.h @@ -24,7 +24,7 @@ #define __TIDY_ADJUSTMENT_H__ #include -#include +#include G_BEGIN_DECLS @@ -50,7 +50,7 @@ struct _TidyAdjustment { /*< private >*/ GObject parent_instance; - + TidyAdjustmentPrivate *priv; }; @@ -77,24 +77,12 @@ TidyAdjustment *tidy_adjustment_new (gdouble value, gdouble step_increment, gdouble page_increment, gdouble page_size); -TidyAdjustment *tidy_adjustment_newx (ClutterFixed value, - ClutterFixed lower, - ClutterFixed upper, - ClutterFixed step_increment, - ClutterFixed page_increment, - ClutterFixed page_size); gdouble tidy_adjustment_get_value (TidyAdjustment *adjustment); -ClutterFixed tidy_adjustment_get_valuex (TidyAdjustment *adjustment); void tidy_adjustment_set_value (TidyAdjustment *adjustment, gdouble value); -void tidy_adjustment_set_valuex (TidyAdjustment *adjustment, - ClutterFixed value); void tidy_adjustment_clamp_page (TidyAdjustment *adjustment, gdouble lower, gdouble upper); -void tidy_adjustment_clamp_pagex (TidyAdjustment *adjustment, - ClutterFixed lower, - ClutterFixed upper); void tidy_adjustment_set_values (TidyAdjustment *adjustment, gdouble value, gdouble lower, @@ -102,13 +90,6 @@ void tidy_adjustment_set_values (TidyAdjustment *adjustment, gdouble step_increment, gdouble page_increment, gdouble page_size); -void tidy_adjustment_set_valuesx (TidyAdjustment *adjustment, - ClutterFixed value, - ClutterFixed lower, - ClutterFixed upper, - ClutterFixed step_increment, - ClutterFixed page_increment, - ClutterFixed page_size); void tidy_adjustment_get_values (TidyAdjustment *adjustment, gdouble *value, gdouble *lower, @@ -116,22 +97,11 @@ void tidy_adjustment_get_values (TidyAdjustment *adjustment, gdouble *step_increment, gdouble *page_increment, gdouble *page_size); -void tidy_adjustment_get_valuesx (TidyAdjustment *adjustment, - ClutterFixed *value, - ClutterFixed *lower, - ClutterFixed *upper, - ClutterFixed *step_increment, - ClutterFixed *page_increment, - ClutterFixed *page_size); void tidy_adjustment_interpolate (TidyAdjustment *adjustment, gdouble value, guint n_frames, guint fps); -void tidy_adjustment_interpolatex (TidyAdjustment *adjustment, - ClutterFixed value, - guint n_frames, - guint fps); gboolean tidy_adjustment_get_elastic (TidyAdjustment *adjustment); void tidy_adjustment_set_elastic (TidyAdjustment *adjustment, diff --git a/tidy/tidy-finger-scroll.c b/tidy/tidy-finger-scroll.c index aad9634..0980cb7 100644 --- a/tidy/tidy-finger-scroll.c +++ b/tidy/tidy-finger-scroll.c @@ -45,16 +45,16 @@ struct _TidyFingerScrollPrivate { /* Scroll mode */ TidyFingerScrollMode mode; - + GArray *motion_buffer; guint last_motion; - + /* Variables for storing acceleration information for kinetic mode */ ClutterTimeline *deceleration_timeline; - ClutterUnit dx; - ClutterUnit dy; - ClutterFixed decel_rate; - + gdouble dx; + gdouble dy; + gdouble decel_rate; + }; enum { @@ -68,14 +68,14 @@ tidy_finger_scroll_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { TidyFingerScrollPrivate *priv = TIDY_FINGER_SCROLL (object)->priv; - + switch (property_id) { case PROP_MODE : g_value_set_enum (value, priv->mode); break; case PROP_DECEL_RATE : - g_value_set_double (value, CLUTTER_FIXED_TO_FLOAT (priv->decel_rate)); + g_value_set_double (value, priv->decel_rate); break; case PROP_BUFFER : g_value_set_uint (value, priv->motion_buffer->len); @@ -90,7 +90,7 @@ tidy_finger_scroll_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { TidyFingerScrollPrivate *priv = TIDY_FINGER_SCROLL (object)->priv; - + switch (property_id) { case PROP_MODE : @@ -98,7 +98,7 @@ tidy_finger_scroll_set_property (GObject *object, guint property_id, g_object_notify (object, "mode"); break; case PROP_DECEL_RATE : - priv->decel_rate = CLUTTER_FLOAT_TO_FIXED (g_value_get_double (value)); + priv->decel_rate = g_value_get_double (value); g_object_notify (object, "decel-rate"); break; case PROP_BUFFER : @@ -121,7 +121,7 @@ tidy_finger_scroll_dispose (GObject *object) g_object_unref (priv->deceleration_timeline); priv->deceleration_timeline = NULL; } - + G_OBJECT_CLASS (tidy_finger_scroll_parent_class)->dispose (object); } @@ -131,7 +131,7 @@ tidy_finger_scroll_finalize (GObject *object) TidyFingerScrollPrivate *priv = TIDY_FINGER_SCROLL (object)->priv; g_array_free (priv->motion_buffer, TRUE); - + G_OBJECT_CLASS (tidy_finger_scroll_parent_class)->finalize (object); } @@ -164,8 +164,8 @@ tidy_finger_scroll_class_init (TidyFingerScrollClass *klass) "Rate at which the view " "will decelerate in " "kinetic mode.", - CLUTTER_FIXED_TO_FLOAT (CFX_ONE + CFX_MIN), - CLUTTER_FIXED_TO_FLOAT (CFX_MAX), + G_MINFLOAT + 1, + G_MAXFLOAT, 1.1, G_PARAM_READWRITE)); @@ -185,7 +185,7 @@ motion_event_cb (ClutterActor *actor, TidyFingerScroll *scroll) { ClutterUnit x, y; - + TidyFingerScrollPrivate *priv = scroll->priv; if (clutter_actor_transform_stage_point (actor, @@ -196,27 +196,27 @@ motion_event_cb (ClutterActor *actor, TidyFingerScrollMotion *motion; ClutterActor *child = tidy_scroll_view_get_child (TIDY_SCROLL_VIEW(scroll)); - + if (child) { - ClutterFixed dx, dy; + gdouble dx, dy; TidyAdjustment *hadjust, *vadjust; - + tidy_scrollable_get_adjustments (TIDY_SCROLLABLE (child), &hadjust, &vadjust); motion = &g_array_index (priv->motion_buffer, TidyFingerScrollMotion, priv->last_motion); - dx = CLUTTER_UNITS_TO_FIXED(motion->x - x) + - tidy_adjustment_get_valuex (hadjust); - dy = CLUTTER_UNITS_TO_FIXED(motion->y - y) + - tidy_adjustment_get_valuex (vadjust); - - tidy_adjustment_set_valuex (hadjust, dx); - tidy_adjustment_set_valuex (vadjust, dy); + dx = (motion->x - x) + + tidy_adjustment_get_value (hadjust); + dy = (motion->y - y) + + tidy_adjustment_get_value (vadjust); + + tidy_adjustment_set_value (hadjust, dx); + tidy_adjustment_set_value (vadjust, dy); } - + priv->last_motion ++; if (priv->last_motion == priv->motion_buffer->len) { @@ -224,7 +224,7 @@ motion_event_cb (ClutterActor *actor, g_array_set_size (priv->motion_buffer, priv->last_motion); priv->last_motion --; } - + motion = &g_array_index (priv->motion_buffer, TidyFingerScrollMotion, priv->last_motion); motion->x = x; @@ -239,36 +239,36 @@ static void clamp_adjustments (TidyFingerScroll *scroll) { ClutterActor *child = tidy_scroll_view_get_child (TIDY_SCROLL_VIEW (scroll)); - + if (child) { guint fps, n_frames; TidyAdjustment *hadj, *vadj; gboolean snap; - + tidy_scrollable_get_adjustments (TIDY_SCROLLABLE (child), &hadj, &vadj); - + /* FIXME: Hard-coded value here */ fps = clutter_get_default_frame_rate (); n_frames = fps / 6; - + snap = TRUE; if (tidy_adjustment_get_elastic (hadj)) snap = !tidy_adjustment_clamp (hadj, TRUE, n_frames, fps); - + /* Snap to the nearest step increment on hadjustment */ if (snap) { gdouble d, value, lower, step_increment; - + tidy_adjustment_get_values (hadj, &value, &lower, NULL, &step_increment, NULL, NULL); d = (rint ((value - lower) / step_increment) * step_increment) + lower; tidy_adjustment_set_value (hadj, d); } - + snap = TRUE; if (tidy_adjustment_get_elastic (vadj)) snap = !tidy_adjustment_clamp (vadj, TRUE, n_frames, fps); @@ -277,7 +277,7 @@ clamp_adjustments (TidyFingerScroll *scroll) if (snap) { gdouble d, value, lower, step_increment; - + tidy_adjustment_get_values (vadj, &value, &lower, NULL, &step_increment, NULL, NULL); d = (rint ((value - lower) / step_increment) * @@ -303,37 +303,37 @@ deceleration_new_frame_cb (ClutterTimeline *timeline, { TidyFingerScrollPrivate *priv = scroll->priv; ClutterActor *child = tidy_scroll_view_get_child (TIDY_SCROLL_VIEW(scroll)); - + if (child) { - ClutterFixed value, lower, upper, page_size; + gdouble value, lower, upper, page_size; TidyAdjustment *hadjust, *vadjust; gint i; gboolean stop = TRUE; - + tidy_scrollable_get_adjustments (TIDY_SCROLLABLE (child), &hadjust, &vadjust); - + for (i = 0; i < clutter_timeline_get_delta (timeline, NULL); i++) { - tidy_adjustment_set_valuex (hadjust, + tidy_adjustment_set_value (hadjust, priv->dx + - tidy_adjustment_get_valuex (hadjust)); - tidy_adjustment_set_valuex (vadjust, + tidy_adjustment_get_value (hadjust)); + tidy_adjustment_set_value (vadjust, priv->dy + - tidy_adjustment_get_valuex (vadjust)); - priv->dx = clutter_qdivx (priv->dx, priv->decel_rate); - priv->dy = clutter_qdivx (priv->dy, priv->decel_rate); + tidy_adjustment_get_value (vadjust)); + priv->dx = (priv->dx / priv->decel_rate); + priv->dy = (priv->dy / priv->decel_rate); } - + /* Check if we've hit the upper or lower bounds and stop the timeline */ tidy_adjustment_get_valuesx (hadjust, &value, &lower, &upper, NULL, NULL, &page_size); if (((priv->dx > 0) && (value < upper - page_size)) || ((priv->dx < 0) && (value > lower))) stop = FALSE; - + if (stop) { tidy_adjustment_get_valuesx (vadjust, &value, &lower, &upper, @@ -342,7 +342,7 @@ deceleration_new_frame_cb (ClutterTimeline *timeline, ((priv->dy < 0) && (value > lower))) stop = FALSE; } - + if (stop) { clutter_timeline_stop (timeline); @@ -363,20 +363,20 @@ button_release_event_cb (ClutterActor *actor, if (event->button != 1) return FALSE; - + g_signal_handlers_disconnect_by_func (actor, motion_event_cb, scroll); g_signal_handlers_disconnect_by_func (actor, button_release_event_cb, scroll); - + clutter_ungrab_pointer (); if ((priv->mode == TIDY_FINGER_SCROLL_MODE_KINETIC) && (child)) { ClutterUnit x, y; - + if (clutter_actor_transform_stage_point (actor, CLUTTER_UNITS_FROM_DEVICE(event->x), CLUTTER_UNITS_FROM_DEVICE(event->y), @@ -387,10 +387,10 @@ button_release_event_cb (ClutterActor *actor, TidyAdjustment *hadjust, *vadjust; glong time_diff; gint i; - + /* Get time delta */ g_get_current_time (&release_time); - + /* Get average position/time of last x mouse events */ priv->last_motion ++; x_origin = y_origin = 0; @@ -399,7 +399,7 @@ button_release_event_cb (ClutterActor *actor, { TidyFingerScrollMotion *motion = &g_array_index (priv->motion_buffer, TidyFingerScrollMotion, i); - + /* FIXME: This doesn't guard against overflows - Should * either fix that, or calculate the correct maximum * value for the buffer size @@ -409,15 +409,11 @@ button_release_event_cb (ClutterActor *actor, motion_time.tv_sec += motion->time.tv_sec; motion_time.tv_usec += motion->time.tv_usec; } - x_origin = CLUTTER_UNITS_FROM_FIXED ( - clutter_qdivx (CLUTTER_UNITS_TO_FIXED (x_origin), - CLUTTER_INT_TO_FIXED (priv->last_motion))); - y_origin = CLUTTER_UNITS_FROM_FIXED ( - clutter_qdivx (CLUTTER_UNITS_TO_FIXED (y_origin), - CLUTTER_INT_TO_FIXED (priv->last_motion))); + x_origin = x_origin / priv->last_motion; + y_origin = y_origin / priv->last_motion; motion_time.tv_sec /= priv->last_motion; motion_time.tv_usec /= priv->last_motion; - + if (motion_time.tv_sec == release_time.tv_sec) time_diff = release_time.tv_usec - motion_time.tv_usec; else @@ -428,31 +424,22 @@ button_release_event_cb (ClutterActor *actor, and this causes a division by 0 when computing 'frac'. This check avoids this error. */ - if (time_diff == 0) - { - g_print ("Preventing a division by 0 (%d / %d).\n", - CLUTTER_FLOAT_TO_FIXED (time_diff/1000.0), - CLUTTER_FLOAT_TO_FIXED (1000.0/60.0) - ); - } - else + if (time_diff != 0) { /* Work out the fraction of 1/60th of a second that has elapsed */ - frac = clutter_qdivx (CLUTTER_FLOAT_TO_FIXED (time_diff/1000.0), - CLUTTER_FLOAT_TO_FIXED (1000.0/60.0)); + frac = (time_diff/1000.0) / (1000.0/60.0); + /* See how many units to move in 1/60th of a second */ - priv->dx = CLUTTER_UNITS_FROM_FIXED(clutter_qdivx ( - CLUTTER_UNITS_TO_FIXED(x_origin - x), frac)); - priv->dy = CLUTTER_UNITS_FROM_FIXED(clutter_qdivx ( - CLUTTER_UNITS_TO_FIXED(y_origin - y), frac)); + priv->dx = (x_origin - x) / frac; + priv->dy = (y_origin - y) / frac; /* Get adjustments to do step-increment snapping */ tidy_scrollable_get_adjustments (TIDY_SCROLLABLE (child), &hadjust, &vadjust); - if (ABS(CLUTTER_UNITS_TO_INT(priv->dx)) > 1 || - ABS(CLUTTER_UNITS_TO_INT(priv->dy)) > 1) + if (ABS(priv->dx) > 1 || + ABS(priv->dy) > 1) { gdouble value, lower, step_increment, d, a, x, y, n; @@ -469,8 +456,8 @@ button_release_event_cb (ClutterActor *actor, * As z = 1, this will cause stops to be slightly abrupt - * add a constant 15 frames to compensate. */ - x = CLUTTER_FIXED_TO_FLOAT (MAX(ABS(priv->dx), ABS(priv->dy))); - y = CLUTTER_FIXED_TO_FLOAT (priv->decel_rate); + x = MAX(ABS(priv->dx), ABS(priv->dy)); + y = priv->decel_rate; n = logf (x) / logf (y) + 15.0; /* Now we have n, adjust dx/dy so that we finish on a step @@ -497,20 +484,20 @@ button_release_event_cb (ClutterActor *actor, a = (1.0 - 1.0 / pow (y, n + 1)) / (1.0 - 1.0 / y); /* Solving for dx */ - d = a * CLUTTER_UNITS_TO_FLOAT (priv->dx); + d = a * priv->dx; tidy_adjustment_get_values (hadjust, &value, &lower, NULL, &step_increment, NULL, NULL); d = ((rint (((value + d) - lower) / step_increment) * step_increment) + lower) - value; - priv->dx = CLUTTER_UNITS_FROM_FLOAT (d / a); + priv->dx = (d / a); /* Solving for dy */ - d = a * CLUTTER_UNITS_TO_FLOAT (priv->dy); + d = a * (priv->dy); tidy_adjustment_get_values (vadjust, &value, &lower, NULL, &step_increment, NULL, NULL); d = ((rint (((value + d) - lower) / step_increment) * step_increment) + lower) - value; - priv->dy = CLUTTER_UNITS_FROM_FLOAT (d / a); + priv->dy = (d / a); priv->deceleration_timeline = clutter_timeline_new ((gint)n, 60); } @@ -521,20 +508,20 @@ button_release_event_cb (ClutterActor *actor, /* Start a short effects timeline to snap to the nearest step * boundary (see equations above) */ - y = CLUTTER_FIXED_TO_FLOAT (priv->decel_rate); + y = priv->decel_rate; a = (1.0 - 1.0 / pow (y, 4 + 1)) / (1.0 - 1.0 / y); tidy_adjustment_get_values (hadjust, &value, &lower, NULL, &step_increment, NULL, NULL); d = ((rint ((value - lower) / step_increment) * step_increment) + lower) - value; - priv->dx = CLUTTER_UNITS_FROM_FLOAT (d / a); + priv->dx = (d / a); tidy_adjustment_get_values (vadjust, &value, &lower, NULL, &step_increment, NULL, NULL); d = ((rint ((value - lower) / step_increment) * step_increment) + lower) - value; - priv->dy = CLUTTER_UNITS_FROM_FLOAT (d / a); + priv->dy = (d / a); priv->deceleration_timeline = clutter_timeline_new (4, 60); } @@ -553,18 +540,18 @@ button_release_event_cb (ClutterActor *actor, if (priv->last_motion <= 1) moved = FALSE; priv->last_motion = 0; - + if (!decelerating) { clamp_adjustments (scroll); } - + /* Pass through events to children. * FIXME: this probably breaks click-count. */ if (moved == FALSE) clutter_event_put ((ClutterEvent *)event); - + return TRUE; } @@ -583,7 +570,7 @@ after_event_cb (TidyFingerScroll *scroll) button_release_event_cb, scroll); } - + return FALSE; } @@ -593,16 +580,16 @@ captured_event_cb (ClutterActor *actor, TidyFingerScroll *scroll) { TidyFingerScrollPrivate *priv = scroll->priv; - + if (event->type == CLUTTER_BUTTON_PRESS) { TidyFingerScrollMotion *motion; ClutterButtonEvent *bevent = (ClutterButtonEvent *)event; - + /* Reset motion buffer */ priv->last_motion = 0; motion = &g_array_index (priv->motion_buffer, TidyFingerScrollMotion, 0); - + if ((bevent->button == 1) && (clutter_actor_transform_stage_point (actor, CLUTTER_UNITS_FROM_DEVICE(bevent->x), @@ -610,16 +597,16 @@ captured_event_cb (ClutterActor *actor, &motion->x, &motion->y))) { g_get_current_time (&motion->time); - + if (priv->deceleration_timeline) { clutter_timeline_stop (priv->deceleration_timeline); g_object_unref (priv->deceleration_timeline); priv->deceleration_timeline = NULL; } - + clutter_grab_pointer (actor); - + /* Add a high priority idle to check the grab after the event * emission is finished. */ @@ -627,7 +614,7 @@ captured_event_cb (ClutterActor *actor, (GSourceFunc)after_event_cb, scroll, NULL); - + g_signal_connect (actor, "motion-event", G_CALLBACK (motion_event_cb), @@ -638,7 +625,7 @@ captured_event_cb (ClutterActor *actor, scroll); } } - + return FALSE; } @@ -647,19 +634,19 @@ tidy_finger_scroll_init (TidyFingerScroll *self) { ClutterActor *scrollbar; TidyFingerScrollPrivate *priv = self->priv = FINGER_SCROLL_PRIVATE (self); - + priv->motion_buffer = g_array_sized_new (FALSE, TRUE, sizeof (TidyFingerScrollMotion), 3); g_array_set_size (priv->motion_buffer, 3); - priv->decel_rate = CLUTTER_FLOAT_TO_FIXED (1.1f); - + priv->decel_rate = 1.1f; + clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE); g_signal_connect (CLUTTER_ACTOR (self), "captured-event", G_CALLBACK (captured_event_cb), self); - - + + } ClutterActor * @@ -673,9 +660,9 @@ void tidy_finger_scroll_stop (TidyFingerScroll *scroll) { TidyFingerScrollPrivate *priv; - + g_return_if_fail (TIDY_IS_FINGER_SCROLL (scroll)); - + priv = scroll->priv; if (priv->deceleration_timeline) diff --git a/tidy/tidy-scroll-view.h b/tidy/tidy-scroll-view.h index e01a72b..aabc4d2 100644 --- a/tidy/tidy-scroll-view.h +++ b/tidy/tidy-scroll-view.h @@ -24,7 +24,7 @@ #define __TIDY_SCROLL_VIEW_H__ #include -#include +#include G_BEGIN_DECLS diff --git a/tidy/tidy-scrollable.h b/tidy/tidy-scrollable.h index 4710897..367e589 100644 --- a/tidy/tidy-scrollable.h +++ b/tidy/tidy-scrollable.h @@ -24,7 +24,7 @@ #define __TIDY_SCROLLABLE_H__ #include -#include +#include "tidy-adjustment.h" G_BEGIN_DECLS @@ -39,7 +39,7 @@ typedef struct _TidyScrollableInterface TidyScrollableInterface; struct _TidyScrollableInterface { GTypeInterface parent; - + void (* set_adjustments) (TidyScrollable *scrollable, TidyAdjustment *hadjustment, TidyAdjustment *vadjustment); diff --git a/tidy/tidy-viewport.c b/tidy/tidy-viewport.c index 47dddf0..1064b1e 100644 --- a/tidy/tidy-viewport.c +++ b/tidy/tidy-viewport.c @@ -54,10 +54,10 @@ struct _TidyViewportPrivate ClutterUnit x; ClutterUnit y; ClutterUnit z; - + TidyAdjustment *hadjustment; TidyAdjustment *vadjustment; - + gboolean sync_adjustments; }; @@ -80,21 +80,21 @@ tidy_viewport_get_property (GObject *object, GParamSpec *pspec) { TidyAdjustment *adjustment; - + TidyViewportPrivate *priv = TIDY_VIEWPORT (object)->priv; switch (prop_id) { case PROP_X_ORIGIN: - g_value_set_int (value, CLUTTER_UNITS_TO_DEVICE (priv->x)); + g_value_set_int (value, priv->x); break; case PROP_Y_ORIGIN: - g_value_set_int (value, CLUTTER_UNITS_TO_DEVICE (priv->y)); + g_value_set_int (value, priv->y); break; case PROP_Z_ORIGIN: - g_value_set_int (value, CLUTTER_UNITS_TO_DEVICE (priv->z)); + g_value_set_int (value, priv->z); break; case PROP_HADJUST : @@ -106,7 +106,7 @@ tidy_viewport_get_property (GObject *object, scrollable_get_adjustments (TIDY_SCROLLABLE (object), NULL, &adjustment); g_value_set_object (value, adjustment); break; - + case PROP_SYNC_ADJUST : g_value_set_boolean (value, priv->sync_adjustments); break; @@ -129,21 +129,21 @@ tidy_viewport_set_property (GObject *object, switch (prop_id) { case PROP_X_ORIGIN: - tidy_viewport_set_originu (viewport, + tidy_viewport_set_origin (viewport, g_value_get_int (value), priv->y, priv->z); break; case PROP_Y_ORIGIN: - tidy_viewport_set_originu (viewport, + tidy_viewport_set_origin (viewport, priv->x, g_value_get_int (value), priv->z); break; case PROP_Z_ORIGIN: - tidy_viewport_set_originu (viewport, + tidy_viewport_set_origin (viewport, priv->x, priv->y, g_value_get_int (value)); @@ -206,15 +206,15 @@ static void tidy_viewport_paint (ClutterActor *self) { TidyViewportPrivate *priv = TIDY_VIEWPORT (self)->priv; - + cogl_push_matrix (); - - cogl_translatex (CLUTTER_UNITS_TO_FIXED (priv->x) * -1, - CLUTTER_UNITS_TO_FIXED (priv->y) * -1, - CLUTTER_UNITS_TO_FIXED (priv->z) * -1); - + + cogl_translate ((priv->x) * -1.0, + (priv->y) * -1.0, + (priv->z) * -1.0); + CLUTTER_ACTOR_CLASS (tidy_viewport_parent_class)->paint (self); - + cogl_pop_matrix (); } @@ -230,8 +230,8 @@ tidy_viewport_allocate (ClutterActor *self, const ClutterActorBox *box, gboolean absolute_origin_changed) { - ClutterFixed prev_value; - + CoglFixed prev_value; + TidyViewportPrivate *priv = TIDY_VIEWPORT (self)->priv; /* Chain up */ @@ -245,23 +245,23 @@ tidy_viewport_allocate (ClutterActor *self, { g_object_set (G_OBJECT (priv->hadjustment), "lower", 0.0, - "upper", CLUTTER_UNITS_TO_FLOAT (box->x2 - box->x1), + "upper", (box->x2 - box->x1), NULL); - + /* Make sure value is clamped */ - prev_value = tidy_adjustment_get_valuex (priv->hadjustment); - tidy_adjustment_set_valuex (priv->hadjustment, prev_value); + prev_value = tidy_adjustment_get_value (priv->hadjustment); + tidy_adjustment_set_value (priv->hadjustment, prev_value); } - + if (priv->vadjustment) { g_object_set (G_OBJECT (priv->vadjustment), "lower", 0.0, - "upper", CLUTTER_UNITS_TO_FLOAT (box->y2 - box->y1), + "upper", (box->y2 - box->y1), NULL); - - prev_value = tidy_adjustment_get_valuex (priv->vadjustment); - tidy_adjustment_set_valuex (priv->vadjustment, prev_value); + + prev_value = tidy_adjustment_get_value (priv->vadjustment); + tidy_adjustment_set_value (priv->vadjustment, prev_value); } } } @@ -277,11 +277,11 @@ tidy_viewport_class_init (TidyViewportClass *klass) gobject_class->get_property = tidy_viewport_get_property; gobject_class->set_property = tidy_viewport_set_property; gobject_class->dispose = tidy_viewport_dispose; - + actor_class->paint = tidy_viewport_paint; actor_class->pick = tidy_viewport_pick; actor_class->allocate = tidy_viewport_allocate; - + g_object_class_install_property (gobject_class, PROP_X_ORIGIN, g_param_spec_int ("x-origin", @@ -320,7 +320,7 @@ tidy_viewport_class_init (TidyViewportClass *klass) "viewport size", TRUE, G_PARAM_READWRITE)); - + g_object_class_override_property (gobject_class, PROP_HADJUST, "hadjustment"); @@ -336,12 +336,12 @@ hadjustment_value_notify_cb (TidyAdjustment *adjustment, TidyViewport *viewport) { TidyViewportPrivate *priv = viewport->priv; - ClutterFixed value; + gdouble value; + + value = tidy_adjustment_get_value (adjustment); - value = tidy_adjustment_get_valuex (adjustment); - - tidy_viewport_set_originu (viewport, - CLUTTER_UNITS_FROM_FIXED (value), + tidy_viewport_set_origin (viewport, + value, priv->y, priv->z); } @@ -351,13 +351,13 @@ vadjustment_value_notify_cb (TidyAdjustment *adjustment, GParamSpec *arg1, TidyViewport *viewport) { TidyViewportPrivate *priv = viewport->priv; - ClutterFixed value; + gdouble value; - value = tidy_adjustment_get_valuex (adjustment); - - tidy_viewport_set_originu (viewport, + value = tidy_adjustment_get_value (adjustment); + + tidy_viewport_set_origin (viewport, priv->x, - CLUTTER_UNITS_FROM_FIXED (value), + value, priv->z); } @@ -367,7 +367,7 @@ scrollable_set_adjustments (TidyScrollable *scrollable, TidyAdjustment *vadjustment) { TidyViewportPrivate *priv = TIDY_VIEWPORT (scrollable)->priv; - + if (hadjustment != priv->hadjustment) { if (priv->hadjustment) @@ -377,7 +377,7 @@ scrollable_set_adjustments (TidyScrollable *scrollable, scrollable); g_object_unref (priv->hadjustment); } - + if (hadjustment) { g_object_ref (hadjustment); @@ -385,7 +385,7 @@ scrollable_set_adjustments (TidyScrollable *scrollable, G_CALLBACK (hadjustment_value_notify_cb), scrollable); } - + priv->hadjustment = hadjustment; } @@ -398,7 +398,7 @@ scrollable_set_adjustments (TidyScrollable *scrollable, scrollable); g_object_unref (priv->vadjustment); } - + if (vadjustment) { g_object_ref (vadjustment); @@ -406,7 +406,7 @@ scrollable_set_adjustments (TidyScrollable *scrollable, G_CALLBACK (vadjustment_value_notify_cb), scrollable); } - + priv->vadjustment = vadjustment; } } @@ -417,11 +417,11 @@ scrollable_get_adjustments (TidyScrollable *scrollable, TidyAdjustment **vadjustment) { TidyViewportPrivate *priv; - + g_return_if_fail (TIDY_IS_VIEWPORT (scrollable)); - + priv = ((TidyViewport *)scrollable)->priv; - + if (hadjustment) { if (priv->hadjustment) @@ -429,25 +429,25 @@ scrollable_get_adjustments (TidyScrollable *scrollable, else { TidyAdjustment *adjustment; - ClutterFixed width, stage_width, increment; - - width = CLUTTER_UNITS_TO_FIXED(clutter_actor_get_widthu (CLUTTER_ACTOR(scrollable))); - stage_width = CLUTTER_UNITS_TO_FIXED(clutter_actor_get_widthu (clutter_stage_get_default ())); - increment = MAX (CFX_ONE, MIN(stage_width, width)); - - adjustment = tidy_adjustment_newx (CLUTTER_UNITS_TO_FIXED(priv->x), - 0, - width, - CFX_ONE, - increment, - increment); + guint width, stage_width, increment; + + width = clutter_actor_get_width (CLUTTER_ACTOR(scrollable)); + stage_width = clutter_actor_get_width (clutter_stage_get_default ()); + increment = MAX (1, MIN(stage_width, width)); + + adjustment = tidy_adjustment_new (priv->x, + 0, + width, + 1, + increment, + increment); scrollable_set_adjustments (scrollable, adjustment, priv->vadjustment); *hadjustment = adjustment; } } - + if (vadjustment) { if (priv->vadjustment) @@ -455,18 +455,18 @@ scrollable_get_adjustments (TidyScrollable *scrollable, else { TidyAdjustment *adjustment; - ClutterFixed height, stage_height, increment; - - height = CLUTTER_UNITS_TO_FIXED(clutter_actor_get_heightu (CLUTTER_ACTOR(scrollable))); - stage_height = CLUTTER_UNITS_TO_FIXED(clutter_actor_get_heightu (clutter_stage_get_default ())); - increment = MAX (CFX_ONE, MIN(stage_height, height)); - - adjustment = tidy_adjustment_newx (CLUTTER_UNITS_TO_FIXED(priv->y), - 0, - height, - CFX_ONE, - increment, - increment); + guint height, stage_height, increment; + + height = clutter_actor_get_height (CLUTTER_ACTOR(scrollable)); + stage_height = clutter_actor_get_height (clutter_stage_get_default ()); + increment = MAX (1, MIN(stage_height, height)); + + adjustment = tidy_adjustment_new (priv->y, + 0, + height, + 1, + increment, + increment); scrollable_set_adjustments (scrollable, priv->hadjustment, adjustment); @@ -489,10 +489,10 @@ clip_notify_cb (ClutterActor *actor, { gint width, height; TidyViewportPrivate *priv = self->priv; - + if (!priv->sync_adjustments) return; - + if (!clutter_actor_has_clip (actor)) { if (priv->hadjustment) @@ -501,12 +501,12 @@ clip_notify_cb (ClutterActor *actor, g_object_set (priv->vadjustment, "page-size", (gdouble)1.0, NULL); return; } - + clutter_actor_get_clip (actor, NULL, NULL, &width, &height); if (priv->hadjustment) g_object_set (priv->hadjustment, "page-size", (gdouble)width, NULL); - + if (priv->vadjustment) g_object_set (priv->vadjustment, "page-size", (gdouble)height, NULL); } @@ -515,9 +515,9 @@ static void tidy_viewport_init (TidyViewport *self) { self->priv = VIEWPORT_PRIVATE (self); - + self->priv->sync_adjustments = TRUE; - + g_signal_connect (self, "notify::clip", G_CALLBACK (clip_notify_cb), self); } @@ -529,27 +529,27 @@ tidy_viewport_new (void) } void -tidy_viewport_set_originu (TidyViewport *viewport, - ClutterUnit x, - ClutterUnit y, - ClutterUnit z) +tidy_viewport_set_origin (TidyViewport *viewport, + gint x, + gint y, + gint z) { TidyViewportPrivate *priv; - + g_return_if_fail (TIDY_IS_VIEWPORT (viewport)); - + priv = viewport->priv; g_object_freeze_notify (G_OBJECT (viewport)); - + if (x != priv->x) { priv->x = x; g_object_notify (G_OBJECT (viewport), "x-origin"); - + if (priv->hadjustment) - tidy_adjustment_set_valuex (priv->hadjustment, - CLUTTER_UNITS_TO_FIXED (x)); + tidy_adjustment_set_value (priv->hadjustment, + x); } if (y != priv->y) @@ -558,8 +558,8 @@ tidy_viewport_set_originu (TidyViewport *viewport, g_object_notify (G_OBJECT (viewport), "y-origin"); if (priv->vadjustment) - tidy_adjustment_set_valuex (priv->vadjustment, - CLUTTER_UNITS_TO_FIXED (y)); + tidy_adjustment_set_value (priv->vadjustment, + y); } if (z != priv->z) @@ -567,38 +567,24 @@ tidy_viewport_set_originu (TidyViewport *viewport, priv->z = z; g_object_notify (G_OBJECT (viewport), "z-origin"); } - + g_object_thaw_notify (G_OBJECT (viewport)); clutter_actor_queue_redraw (CLUTTER_ACTOR (viewport)); } void -tidy_viewport_set_origin (TidyViewport *viewport, - gint x, - gint y, - gint z) -{ - g_return_if_fail (TIDY_IS_VIEWPORT (viewport)); - - tidy_viewport_set_originu (viewport, - CLUTTER_UNITS_FROM_DEVICE (x), - CLUTTER_UNITS_FROM_DEVICE (y), - CLUTTER_UNITS_FROM_DEVICE (z)); -} - -void -tidy_viewport_get_originu (TidyViewport *viewport, - ClutterUnit *x, - ClutterUnit *y, - ClutterUnit *z) +tidy_viewport_get_origin (TidyViewport *viewport, + gint *x, + gint *y, + gint *z) { TidyViewportPrivate *priv; - + g_return_if_fail (TIDY_IS_VIEWPORT (viewport)); - + priv = viewport->priv; - + if (x) *x = priv->x; @@ -608,25 +594,3 @@ tidy_viewport_get_originu (TidyViewport *viewport, if (z) *z = priv->z; } - -void -tidy_viewport_get_origin (TidyViewport *viewport, - gint *x, - gint *y, - gint *z) -{ - TidyViewportPrivate *priv; - - g_return_if_fail (TIDY_IS_VIEWPORT (viewport)); - - priv = viewport->priv; - - if (x) - *x = CLUTTER_UNITS_TO_DEVICE (priv->x); - - if (y) - *y = CLUTTER_UNITS_TO_DEVICE (priv->y); - - if (z) - *z = CLUTTER_UNITS_TO_DEVICE (priv->z); -} diff --git a/tidy/tidy-viewport.h b/tidy/tidy-viewport.h index 2278367..b94ecd7 100644 --- a/tidy/tidy-viewport.h +++ b/tidy/tidy-viewport.h @@ -24,7 +24,7 @@ #define __TIDY_VIEWPORT_H__ #include -#include +#include G_BEGIN_DECLS @@ -42,7 +42,7 @@ typedef struct _TidyViewportClass TidyViewportClass; struct _TidyViewport { ClutterGroup parent; - + TidyViewportPrivate *priv; }; @@ -55,25 +55,15 @@ GType tidy_viewport_get_type (void) G_GNUC_CONST; ClutterActor * tidy_viewport_new (void); -void tidy_viewport_set_originu (TidyViewport *viewport, - ClutterUnit x, - ClutterUnit y, - ClutterUnit z); - void tidy_viewport_set_origin (TidyViewport *viewport, gint x, gint y, gint z); -void tidy_viewport_get_originu (TidyViewport *viewport, - ClutterUnit *x, - ClutterUnit *y, - ClutterUnit *z); - void tidy_viewport_get_origin (TidyViewport *viewport, - gint *x, - gint *y, - gint *z); + gfloat *x, + gfloat *y, + gfloat *z); void tidy_viewport_stop (TidyViewport *viewport); G_END_DECLS