Ejemplo n.º 1
0
static GtkBitmask *
gtk_css_transition_set_values (GtkStyleAnimation    *animation,
                               GtkBitmask           *changed,
                               gint64                for_time_us,
                               GtkCssComputedValues *values)
{
  GtkCssTransition *transition = GTK_CSS_TRANSITION (animation);
  GtkCssValue *value;
  double progress;

  if (transition->start_time >= for_time_us)
    value = _gtk_css_value_ref (transition->start);
  else if (transition->end_time <= for_time_us)
    value = _gtk_css_value_ref (transition->end);
  else
    {
      progress = (double) (for_time_us - transition->start_time) / (transition->end_time - transition->start_time);
      progress = _gtk_css_ease_value_transform (transition->ease, progress);

      value = _gtk_css_value_transition (transition->start,
                                         transition->end,
                                         progress);
      if (value == NULL)
        value = _gtk_css_value_ref (transition->end);
    }

  _gtk_css_computed_values_set_value (values, transition->property, value, NULL);
  _gtk_css_value_unref (value);

  return _gtk_bitmask_set (changed, transition->property, TRUE);
}
Ejemplo n.º 2
0
static GtkCssValue *
gtk_css_value_bg_size_transition (GtkCssValue *start,
                                  GtkCssValue *end,
                                  guint        property_id,
                                  double       progress)
{
  GtkCssValue *x, *y;

  if (start->cover)
    return end->cover ? _gtk_css_value_ref (end) : NULL;
  if (start->contain)
    return end->contain ? _gtk_css_value_ref (end) : NULL;

  if ((start->x != NULL) ^ (end->x != NULL) ||
      (start->y != NULL) ^ (end->y != NULL))
    return NULL;

  if (start->x)
    {
      x = _gtk_css_value_transition (start->x, end->x, property_id, progress);
      if (x == NULL)
        return NULL;
    }
  else
    x = NULL;

  if (start->y)
    {
      y = _gtk_css_value_transition (start->y, end->y, property_id, progress);
      if (y == NULL)
        {
          _gtk_css_value_unref (x);
          return NULL;
        }
    }
  else
    y = NULL;

  return _gtk_css_bg_size_value_new (x, y);
}
Ejemplo n.º 3
0
static GtkCssImage *
gtk_css_image_radial_transition (GtkCssImage *start_image,
                                 GtkCssImage *end_image,
                                 guint        property_id,
                                 double       progress)
{
    GtkCssImageRadial *start, *end, *result;
    guint i;

    start = GTK_CSS_IMAGE_RADIAL (start_image);

    if (end_image == NULL)
        return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress);

    if (!GTK_IS_CSS_IMAGE_RADIAL (end_image))
        return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress);

    end = GTK_CSS_IMAGE_RADIAL (end_image);

    if (start->repeating != end->repeating ||
            start->stops->len != end->stops->len ||
            start->size != end->size ||
            start->circle != end->circle)
        return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress);

    result = g_object_new (GTK_TYPE_CSS_IMAGE_RADIAL, NULL);
    result->repeating = start->repeating;
    result->circle = start->circle;
    result->size = start->size;

    result->position = _gtk_css_value_transition (start->position, end->position, property_id, progress);
    if (result->position == NULL)
        goto fail;

    if (start->sizes[0] && end->sizes[0])
    {
        result->sizes[0] = _gtk_css_value_transition (start->sizes[0], end->sizes[0], property_id, progress);
        if (result->sizes[0] == NULL)
            goto fail;
    }
    else
        result->sizes[0] = 0;

    if (start->sizes[1] && end->sizes[1])
    {
        result->sizes[1] = _gtk_css_value_transition (start->sizes[1], end->sizes[1], property_id, progress);
        if (result->sizes[1] == NULL)
            goto fail;
    }
    else
        result->sizes[1] = 0;

    for (i = 0; i < start->stops->len; i++)
    {
        GtkCssImageRadialColorStop stop, *start_stop, *end_stop;

        start_stop = &g_array_index (start->stops, GtkCssImageRadialColorStop, i);
        end_stop = &g_array_index (end->stops, GtkCssImageRadialColorStop, i);

        if ((start_stop->offset != NULL) != (end_stop->offset != NULL))
            goto fail;

        if (start_stop->offset == NULL)
        {
            stop.offset = NULL;
        }
        else
        {
            stop.offset = _gtk_css_value_transition (start_stop->offset,
                          end_stop->offset,
                          property_id,
                          progress);
            if (stop.offset == NULL)
                goto fail;
        }

        stop.color = _gtk_css_value_transition (start_stop->color,
                                                end_stop->color,
                                                property_id,
                                                progress);
        if (stop.color == NULL)
        {
            if (stop.offset)
                _gtk_css_value_unref (stop.offset);
            goto fail;
        }

        g_array_append_val (result->stops, stop);
    }

    return GTK_CSS_IMAGE (result);

fail:
    g_object_unref (result);
    return GTK_CSS_IMAGE_CLASS (_gtk_css_image_radial_parent_class)->transition (start_image, end_image, property_id, progress);
}
Ejemplo n.º 4
0
static GtkCssValue *
gtk_css_value_shadows_transition (GtkCssValue *start,
                                  GtkCssValue *end,
                                  guint        property_id,
                                  double       progress)
{
  guint i, len;
  GtkCssValue **values;

  /* catches the important case of 2 none values */
  if (start == end)
    return _gtk_css_value_ref (start);

  if (start->len > end->len)
    len = start->len;
  else
    len = end->len;

  values = g_newa (GtkCssValue *, len);

  for (i = 0; i < MIN (start->len, end->len); i++)
    {
      values[i] = _gtk_css_value_transition (start->values[i], end->values[i], property_id, progress);
      if (values[i] == NULL)
        {
          while (i--)
            _gtk_css_value_unref (values[i]);
          return NULL;
        }
    }
  if (start->len > end->len)
    {
      for (; i < len; i++)
        {
          GtkCssValue *fill = _gtk_css_shadow_value_new_for_transition (start->values[i]);
          values[i] = _gtk_css_value_transition (start->values[i], fill, property_id, progress);
          _gtk_css_value_unref (fill);

          if (values[i] == NULL)
            {
              while (i--)
                _gtk_css_value_unref (values[i]);
              return NULL;
            }
        }
    }
  else
    {
      for (; i < len; i++)
        {
          GtkCssValue *fill = _gtk_css_shadow_value_new_for_transition (end->values[i]);
          values[i] = _gtk_css_value_transition (fill, end->values[i], property_id, progress);
          _gtk_css_value_unref (fill);

          if (values[i] == NULL)
            {
              while (i--)
                _gtk_css_value_unref (values[i]);
              return NULL;
            }
        }
    }

  return gtk_css_shadows_value_new (values, len);
}
Ejemplo n.º 5
0
static GtkCssImage *
gtk_css_image_linear_transition (GtkCssImage *start_image,
                                 GtkCssImage *end_image,
                                 guint        property_id,
                                 double       progress)
{
  GtkCssImageLinear *start, *end, *result;
  guint i;

  start = GTK_CSS_IMAGE_LINEAR (start_image);

  if (end_image == NULL)
    return GTK_CSS_IMAGE_CLASS (_gtk_css_image_linear_parent_class)->transition (start_image, end_image, property_id, progress);

  if (!GTK_IS_CSS_IMAGE_LINEAR (end_image))
    return GTK_CSS_IMAGE_CLASS (_gtk_css_image_linear_parent_class)->transition (start_image, end_image, property_id, progress);

  end = GTK_CSS_IMAGE_LINEAR (end_image);

  if ((start->repeating != end->repeating)
      || (start->stops->len != end->stops->len))
    return GTK_CSS_IMAGE_CLASS (_gtk_css_image_linear_parent_class)->transition (start_image, end_image, property_id, progress);

  result = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL);
  result->repeating = start->repeating;

  if (start->side != end->side)
    goto fail;

  result->side = start->side;
  if (result->side == 0)
    result->angle = _gtk_css_value_transition (start->angle, end->angle, property_id, progress);
  if (result->angle == NULL)
    goto fail;
  
  for (i = 0; i < start->stops->len; i++)
    {
      GtkCssImageLinearColorStop stop, *start_stop, *end_stop;

      start_stop = &g_array_index (start->stops, GtkCssImageLinearColorStop, i);
      end_stop = &g_array_index (end->stops, GtkCssImageLinearColorStop, i);

      if ((start_stop->offset != NULL) != (end_stop->offset != NULL))
        goto fail;

      if (start_stop->offset == NULL)
        {
          stop.offset = NULL;
        }
      else
        {
          stop.offset = _gtk_css_value_transition (start_stop->offset,
                                                   end_stop->offset,
                                                   property_id,
                                                   progress);
          if (stop.offset == NULL)
            goto fail;
        }

      stop.color = _gtk_css_value_transition (start_stop->color,
                                              end_stop->color,
                                              property_id,
                                              progress);
      if (stop.color == NULL)
        {
          if (stop.offset)
            _gtk_css_value_unref (stop.offset);
          goto fail;
        }

      g_array_append_val (result->stops, stop);
    }

  return GTK_CSS_IMAGE (result);

fail:
  g_object_unref (result);
  return GTK_CSS_IMAGE_CLASS (_gtk_css_image_linear_parent_class)->transition (start_image, end_image, property_id, progress);
}