scroll-bar: Add smooth scrolling support

Do the same for StScrollBar.

https://bugzilla.gnome.org/show_bug.cgi?id=687573
This commit is contained in:
Jasper St. Pierre 2012-11-28 17:27:41 -05:00
parent 06dc12e217
commit f162dd7e87

View File

@ -433,42 +433,57 @@ st_scroll_bar_constructor (GType type,
return obj;
}
static void
adjust_with_direction (StAdjustment *adj,
ClutterScrollDirection direction)
{
gdouble delta;
switch (direction)
{
case CLUTTER_SCROLL_UP:
case CLUTTER_SCROLL_LEFT:
delta = -1.0;
break;
case CLUTTER_SCROLL_RIGHT:
case CLUTTER_SCROLL_DOWN:
delta = 1.0;
break;
case CLUTTER_SCROLL_SMOOTH:
g_assert_not_reached ();
break;
}
st_adjustment_adjust_for_scroll_event (adj, delta);
}
static gboolean
st_scroll_bar_scroll_event (ClutterActor *actor,
ClutterScrollEvent *event)
{
StScrollBarPrivate *priv = ST_SCROLL_BAR (actor)->priv;
gdouble step, value, delta_x, delta_y;
if (priv->adjustment)
{
g_object_get (priv->adjustment,
"step-increment", &step,
"value", &value,
NULL);
}
else
{
return FALSE;
}
if (clutter_event_is_pointer_emulated ((ClutterEvent *) event))
return TRUE;
switch (event->direction)
{
case CLUTTER_SCROLL_SMOOTH:
clutter_event_get_scroll_delta ((ClutterEvent *)event,
&delta_x, &delta_y);
if (fabs (delta_x) > fabs (delta_y))
st_adjustment_set_value (priv->adjustment, value + delta_x);
else
st_adjustment_set_value (priv->adjustment, value + delta_y);
{
gdouble delta_x, delta_y;
clutter_event_get_scroll_delta ((ClutterEvent *)event, &delta_x, &delta_y);
if (priv->vertical)
st_adjustment_adjust_for_scroll_event (priv->adjustment, delta_y);
else
st_adjustment_adjust_for_scroll_event (priv->adjustment, delta_x);
}
break;
case CLUTTER_SCROLL_UP:
case CLUTTER_SCROLL_LEFT:
st_adjustment_set_value (priv->adjustment, value - step);
break;
case CLUTTER_SCROLL_DOWN:
case CLUTTER_SCROLL_LEFT:
case CLUTTER_SCROLL_RIGHT:
st_adjustment_set_value (priv->adjustment, value + step);
adjust_with_direction (priv->adjustment, event->direction);
break;
}