2012-04-02 01:25:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2012 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: Benjamin Otte <otte@gnome.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-09-16 16:45:17 +00:00
|
|
|
#include <math.h>
|
2012-04-02 01:25:30 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gtkcssimagecrossfadeprivate.h"
|
|
|
|
|
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2021-01-27 02:10:47 +00:00
|
|
|
#include "gtkcssimagefallbackprivate.h"
|
|
|
|
#include "gtkcsscolorvalueprivate.h"
|
|
|
|
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
typedef struct _CrossFadeEntry CrossFadeEntry;
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
struct _CrossFadeEntry
|
|
|
|
{
|
|
|
|
double progress;
|
2019-03-30 15:02:58 +00:00
|
|
|
gboolean has_progress;
|
2019-03-26 16:39:07 +00:00
|
|
|
GtkCssImage *image;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkCssImageCrossFade, gtk_css_image_cross_fade, GTK_TYPE_CSS_IMAGE)
|
|
|
|
|
|
|
|
static void
|
|
|
|
cross_fade_entry_clear (gpointer data)
|
|
|
|
{
|
|
|
|
CrossFadeEntry *entry = data;
|
|
|
|
|
|
|
|
g_clear_object (&entry->image);
|
|
|
|
}
|
|
|
|
|
2019-03-30 15:02:58 +00:00
|
|
|
static void
|
|
|
|
gtk_css_image_cross_fade_recalculate_progress (GtkCssImageCrossFade *self)
|
|
|
|
{
|
|
|
|
double total_progress;
|
|
|
|
guint n_no_progress;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
total_progress = 0.0;
|
|
|
|
n_no_progress = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < self->images->len; i++)
|
|
|
|
{
|
|
|
|
CrossFadeEntry *entry = &g_array_index (self->images, CrossFadeEntry, i);
|
|
|
|
|
|
|
|
if (entry->has_progress)
|
|
|
|
total_progress += entry->progress;
|
|
|
|
else
|
|
|
|
n_no_progress++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_no_progress)
|
|
|
|
{
|
|
|
|
double progress;
|
|
|
|
if (total_progress >= 1.0)
|
|
|
|
{
|
|
|
|
progress = 0.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
progress = (1.0 - total_progress) / n_no_progress;
|
|
|
|
total_progress = 1.0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < self->images->len; i++)
|
|
|
|
{
|
|
|
|
CrossFadeEntry *entry = &g_array_index (self->images, CrossFadeEntry, i);
|
|
|
|
|
|
|
|
if (!entry->has_progress)
|
|
|
|
entry->progress = progress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self->total_progress = total_progress;
|
|
|
|
}
|
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
static void
|
|
|
|
gtk_css_image_cross_fade_add (GtkCssImageCrossFade *self,
|
2019-03-30 15:02:58 +00:00
|
|
|
gboolean has_progress,
|
2019-03-26 16:39:07 +00:00
|
|
|
double progress,
|
|
|
|
GtkCssImage *image)
|
|
|
|
{
|
|
|
|
CrossFadeEntry entry;
|
|
|
|
|
2019-03-30 15:02:58 +00:00
|
|
|
entry.has_progress = has_progress;
|
2019-03-26 16:39:07 +00:00
|
|
|
entry.progress = progress;
|
|
|
|
entry.image = image;
|
|
|
|
g_array_append_val (self->images, entry);
|
2019-03-30 15:02:58 +00:00
|
|
|
|
|
|
|
gtk_css_image_cross_fade_recalculate_progress (self);
|
2019-03-26 16:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkCssImageCrossFade *
|
|
|
|
gtk_css_image_cross_fade_new_empty (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_CSS_IMAGE_CROSS_FADE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: The following is not correct, it should actually run the
|
|
|
|
* CSS sizing algorithm for every child, not just query height and
|
|
|
|
* width independently.
|
|
|
|
*/
|
2012-04-02 01:25:30 +00:00
|
|
|
static int
|
|
|
|
gtk_css_image_cross_fade_get_width (GtkCssImage *image)
|
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
GtkCssImageCrossFade *self = GTK_CSS_IMAGE_CROSS_FADE (image);
|
|
|
|
double sum_width, sum_progress;
|
|
|
|
guint i;
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
sum_width = 0.0;
|
|
|
|
sum_progress = 0.0;
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
for (i = 0; i < self->images->len; i++)
|
2012-04-02 01:25:30 +00:00
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
CrossFadeEntry *entry = &g_array_index (self->images, CrossFadeEntry, i);
|
|
|
|
int image_width;
|
|
|
|
|
|
|
|
image_width = _gtk_css_image_get_width (entry->image);
|
|
|
|
if (image_width == 0)
|
|
|
|
continue;
|
|
|
|
sum_width += image_width * entry->progress;
|
|
|
|
sum_progress += entry->progress;
|
2012-04-02 01:25:30 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
if (sum_progress <= 0.0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ceil (sum_width / sum_progress);
|
2012-04-02 01:25:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gtk_css_image_cross_fade_get_height (GtkCssImage *image)
|
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
GtkCssImageCrossFade *self = GTK_CSS_IMAGE_CROSS_FADE (image);
|
|
|
|
double sum_height, sum_progress;
|
|
|
|
guint i;
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
sum_height = 0.0;
|
|
|
|
sum_progress = 0.0;
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
for (i = 0; i < self->images->len; i++)
|
2012-04-02 01:25:30 +00:00
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
CrossFadeEntry *entry = &g_array_index (self->images, CrossFadeEntry, i);
|
|
|
|
int image_height;
|
|
|
|
|
|
|
|
image_height = _gtk_css_image_get_height (entry->image);
|
|
|
|
if (image_height == 0)
|
|
|
|
continue;
|
|
|
|
sum_height += image_height * entry->progress;
|
|
|
|
sum_progress += entry->progress;
|
2012-04-02 01:25:30 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
if (sum_progress <= 0.0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ceil (sum_height / sum_progress);
|
2012-04-02 01:25:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-31 23:22:39 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_image_cross_fade_equal (GtkCssImage *image1,
|
|
|
|
GtkCssImage *image2)
|
|
|
|
{
|
|
|
|
GtkCssImageCrossFade *cross_fade1 = GTK_CSS_IMAGE_CROSS_FADE (image1);
|
|
|
|
GtkCssImageCrossFade *cross_fade2 = GTK_CSS_IMAGE_CROSS_FADE (image2);
|
2019-03-26 16:39:07 +00:00
|
|
|
guint i;
|
2012-10-31 23:22:39 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
if (cross_fade1->images->len != cross_fade2->images->len)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < cross_fade1->images->len; i++)
|
|
|
|
{
|
|
|
|
CrossFadeEntry *entry1 = &g_array_index (cross_fade1->images, CrossFadeEntry, i);
|
|
|
|
CrossFadeEntry *entry2 = &g_array_index (cross_fade2->images, CrossFadeEntry, i);
|
|
|
|
|
|
|
|
if (entry1->progress != entry2->progress ||
|
|
|
|
!_gtk_css_image_equal (entry1->image, entry2->image))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2012-10-31 23:22:39 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 00:15:00 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_image_cross_fade_is_dynamic (GtkCssImage *image)
|
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
GtkCssImageCrossFade *self = GTK_CSS_IMAGE_CROSS_FADE (image);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < self->images->len; i++)
|
|
|
|
{
|
|
|
|
CrossFadeEntry *entry = &g_array_index (self->images, CrossFadeEntry, i);
|
2018-02-28 00:15:00 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
if (gtk_css_image_is_dynamic (entry->image))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2018-02-28 00:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkCssImage *
|
|
|
|
gtk_css_image_cross_fade_get_dynamic_image (GtkCssImage *image,
|
|
|
|
gint64 monotonic_time)
|
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
GtkCssImageCrossFade *self = GTK_CSS_IMAGE_CROSS_FADE (image);
|
|
|
|
GtkCssImageCrossFade *result;
|
|
|
|
guint i;
|
2018-02-28 00:15:00 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
result = gtk_css_image_cross_fade_new_empty ();
|
2018-02-28 00:15:00 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
for (i = 0; i < self->images->len; i++)
|
|
|
|
{
|
|
|
|
CrossFadeEntry *entry = &g_array_index (self->images, CrossFadeEntry, i);
|
2018-02-28 00:15:00 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
gtk_css_image_cross_fade_add (result,
|
2019-03-30 15:02:58 +00:00
|
|
|
entry->has_progress,
|
2019-03-26 16:39:07 +00:00
|
|
|
entry->progress,
|
|
|
|
gtk_css_image_get_dynamic_image (entry->image, monotonic_time));
|
|
|
|
}
|
2018-02-28 00:15:00 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
return GTK_CSS_IMAGE (result);
|
2018-02-28 00:15:00 +00:00
|
|
|
}
|
|
|
|
|
2012-04-02 01:25:30 +00:00
|
|
|
static void
|
2016-12-17 07:07:29 +00:00
|
|
|
gtk_css_image_cross_fade_snapshot (GtkCssImage *image,
|
|
|
|
GtkSnapshot *snapshot,
|
|
|
|
double width,
|
|
|
|
double height)
|
2012-04-02 01:25:30 +00:00
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
GtkCssImageCrossFade *self = GTK_CSS_IMAGE_CROSS_FADE (image);
|
|
|
|
double remaining;
|
|
|
|
guint i, n_cross_fades;
|
|
|
|
|
|
|
|
if (self->total_progress < 1.0)
|
|
|
|
{
|
|
|
|
n_cross_fades = self->images->len;
|
|
|
|
remaining = 1.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n_cross_fades = self->images->len - 1;
|
|
|
|
remaining = self->total_progress;
|
|
|
|
}
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
for (i = 0; i < n_cross_fades; i++)
|
|
|
|
{
|
|
|
|
CrossFadeEntry *entry = &g_array_index (self->images, CrossFadeEntry, i);
|
2017-01-12 21:00:38 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
gtk_snapshot_push_cross_fade (snapshot, 1.0 - entry->progress / remaining);
|
|
|
|
remaining -= entry->progress;
|
|
|
|
gtk_css_image_snapshot (entry->image, snapshot, width, height);
|
|
|
|
gtk_snapshot_pop (snapshot);
|
|
|
|
}
|
2017-01-12 21:00:38 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
if (n_cross_fades < self->images->len)
|
|
|
|
{
|
|
|
|
CrossFadeEntry *entry = &g_array_index (self->images, CrossFadeEntry, self->images->len - 1);
|
|
|
|
gtk_css_image_snapshot (entry->image, snapshot, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_cross_fades; i++)
|
|
|
|
{
|
|
|
|
gtk_snapshot_pop (snapshot);
|
|
|
|
}
|
2012-04-02 01:25:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-03-30 11:04:51 +00:00
|
|
|
parse_progress (GtkCssParser *parser,
|
|
|
|
gpointer option_data,
|
|
|
|
gpointer user_data)
|
2012-04-02 01:25:30 +00:00
|
|
|
{
|
2019-03-30 11:04:51 +00:00
|
|
|
double *progress = option_data;
|
|
|
|
GtkCssValue *number;
|
|
|
|
|
|
|
|
number = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_PERCENT | GTK_CSS_POSITIVE_ONLY);
|
|
|
|
if (number == NULL)
|
|
|
|
return FALSE;
|
|
|
|
*progress = _gtk_css_number_value_get (number, 1);
|
|
|
|
_gtk_css_value_unref (number);
|
2019-03-26 16:39:07 +00:00
|
|
|
|
2019-03-30 11:04:51 +00:00
|
|
|
if (*progress > 1.0)
|
2012-04-02 01:25:30 +00:00
|
|
|
{
|
2020-05-06 07:56:52 +00:00
|
|
|
gtk_css_parser_error_value (parser, "Percentages over 100%% are not allowed. Given value: %f", *progress);
|
2012-04-02 01:25:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-03-30 11:04:51 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2019-03-30 11:04:51 +00:00
|
|
|
static gboolean
|
|
|
|
parse_image (GtkCssParser *parser,
|
|
|
|
gpointer option_data,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkCssImage **image = option_data;
|
|
|
|
|
2021-01-27 02:10:47 +00:00
|
|
|
if (_gtk_css_image_can_parse (parser))
|
|
|
|
*image = _gtk_css_image_new_parse (parser);
|
|
|
|
else if (gtk_css_color_value_can_parse (parser))
|
|
|
|
{
|
|
|
|
GtkCssValue *color;
|
|
|
|
|
|
|
|
color = _gtk_css_color_value_parse (parser);
|
|
|
|
if (color == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*image = _gtk_css_image_fallback_new_for_color (color);
|
|
|
|
}
|
|
|
|
else
|
2012-04-02 01:25:30 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2019-03-30 11:04:51 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-03-26 16:39:07 +00:00
|
|
|
|
2019-03-30 11:04:51 +00:00
|
|
|
static guint
|
|
|
|
gtk_css_image_cross_fade_parse_arg (GtkCssParser *parser,
|
|
|
|
guint arg,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkCssImageCrossFade *self = data;
|
|
|
|
double progress = -1.0;
|
|
|
|
GtkCssImage *image = NULL;
|
|
|
|
GtkCssParseOption options[] =
|
2012-04-02 01:25:30 +00:00
|
|
|
{
|
2021-01-27 02:10:47 +00:00
|
|
|
{ (void *)gtk_css_number_value_can_parse, parse_progress, &progress },
|
2019-03-30 11:04:51 +00:00
|
|
|
{ NULL, parse_image, &image },
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!gtk_css_parser_consume_any (parser, options, G_N_ELEMENTS (options), self))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
g_assert (image != NULL);
|
|
|
|
|
2019-03-30 15:02:58 +00:00
|
|
|
if (progress < 0.0)
|
|
|
|
gtk_css_image_cross_fade_add (self, FALSE, 0.0, image);
|
|
|
|
else
|
|
|
|
gtk_css_image_cross_fade_add (self, TRUE, progress, image);
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2019-03-30 11:04:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_image_cross_fade_parse (GtkCssImage *image,
|
|
|
|
GtkCssParser *parser)
|
|
|
|
{
|
|
|
|
if (!gtk_css_parser_has_function (parser, "cross-fade"))
|
2012-04-02 01:25:30 +00:00
|
|
|
{
|
2019-04-09 03:40:50 +00:00
|
|
|
gtk_css_parser_error_syntax (parser, "Expected 'cross-fade('");
|
2012-04-02 01:25:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-03-30 11:04:51 +00:00
|
|
|
return gtk_css_parser_consume_function (parser, 1, G_MAXUINT, gtk_css_image_cross_fade_parse_arg, image);
|
2012-04-02 01:25:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_css_image_cross_fade_print (GtkCssImage *image,
|
|
|
|
GString *string)
|
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
GtkCssImageCrossFade *self = GTK_CSS_IMAGE_CROSS_FADE (image);
|
|
|
|
guint i;
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2012-09-14 00:06:14 +00:00
|
|
|
g_string_append (string, "cross-fade(");
|
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
for (i = 0; i < self->images->len; i++)
|
2012-09-14 00:06:14 +00:00
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
CrossFadeEntry *entry = &g_array_index (self->images, CrossFadeEntry, i);
|
|
|
|
|
|
|
|
if (i > 0)
|
2019-03-30 15:02:58 +00:00
|
|
|
g_string_append_printf (string, ", ");
|
|
|
|
if (entry->has_progress)
|
|
|
|
g_string_append_printf (string, "%g%% ", entry->progress * 100.0);
|
2019-03-26 16:39:07 +00:00
|
|
|
_gtk_css_image_print (entry->image, string);
|
2012-09-14 00:06:14 +00:00
|
|
|
}
|
2019-03-26 16:39:07 +00:00
|
|
|
|
2012-04-02 01:25:30 +00:00
|
|
|
g_string_append (string, ")");
|
|
|
|
}
|
|
|
|
|
2016-09-06 10:37:47 +00:00
|
|
|
static GtkCssImage *
|
2017-10-31 03:31:46 +00:00
|
|
|
gtk_css_image_cross_fade_compute (GtkCssImage *image,
|
|
|
|
guint property_id,
|
|
|
|
GtkStyleProvider *provider,
|
|
|
|
GtkCssStyle *style,
|
|
|
|
GtkCssStyle *parent_style)
|
2016-09-06 10:37:47 +00:00
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
GtkCssImageCrossFade *self = GTK_CSS_IMAGE_CROSS_FADE (image);
|
|
|
|
GtkCssImageCrossFade *result;
|
|
|
|
guint i;
|
2016-09-06 10:37:47 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
result = gtk_css_image_cross_fade_new_empty ();
|
2016-09-06 10:37:47 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
for (i = 0; i < self->images->len; i++)
|
|
|
|
{
|
|
|
|
CrossFadeEntry *entry = &g_array_index (self->images, CrossFadeEntry, i);
|
2016-09-06 10:37:47 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
gtk_css_image_cross_fade_add (result,
|
2019-03-30 15:02:58 +00:00
|
|
|
entry->has_progress,
|
2019-03-26 16:39:07 +00:00
|
|
|
entry->progress,
|
|
|
|
_gtk_css_image_compute (entry->image, property_id, provider, style, parent_style));
|
|
|
|
}
|
2016-09-06 10:37:47 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
return GTK_CSS_IMAGE (result);
|
2016-09-06 10:37:47 +00:00
|
|
|
}
|
|
|
|
|
2012-04-02 01:25:30 +00:00
|
|
|
static void
|
|
|
|
gtk_css_image_cross_fade_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkCssImageCrossFade *cross_fade = GTK_CSS_IMAGE_CROSS_FADE (object);
|
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
g_clear_pointer (&cross_fade->images, g_array_unref);
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
G_OBJECT_CLASS (gtk_css_image_cross_fade_parent_class)->dispose (object);
|
2012-04-02 01:25:30 +00:00
|
|
|
}
|
|
|
|
|
2020-01-11 13:38:49 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_css_image_cross_fade_is_computed (GtkCssImage *image)
|
|
|
|
{
|
|
|
|
GtkCssImageCrossFade *cross_fade = GTK_CSS_IMAGE_CROSS_FADE (image);
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < cross_fade->images->len; i++)
|
|
|
|
{
|
|
|
|
const CrossFadeEntry *entry = &g_array_index (cross_fade->images, CrossFadeEntry, i);
|
|
|
|
if (!gtk_css_image_is_computed (entry->image))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-04-02 01:25:30 +00:00
|
|
|
static void
|
2019-03-26 16:39:07 +00:00
|
|
|
gtk_css_image_cross_fade_class_init (GtkCssImageCrossFadeClass *klass)
|
2012-04-02 01:25:30 +00:00
|
|
|
{
|
|
|
|
GtkCssImageClass *image_class = GTK_CSS_IMAGE_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
image_class->get_width = gtk_css_image_cross_fade_get_width;
|
|
|
|
image_class->get_height = gtk_css_image_cross_fade_get_height;
|
2018-02-28 00:15:00 +00:00
|
|
|
image_class->compute = gtk_css_image_cross_fade_compute;
|
2012-10-31 23:22:39 +00:00
|
|
|
image_class->equal = gtk_css_image_cross_fade_equal;
|
2016-12-17 07:07:29 +00:00
|
|
|
image_class->snapshot = gtk_css_image_cross_fade_snapshot;
|
2018-02-28 00:15:00 +00:00
|
|
|
image_class->is_dynamic = gtk_css_image_cross_fade_is_dynamic;
|
|
|
|
image_class->get_dynamic_image = gtk_css_image_cross_fade_get_dynamic_image;
|
2012-04-02 01:25:30 +00:00
|
|
|
image_class->parse = gtk_css_image_cross_fade_parse;
|
|
|
|
image_class->print = gtk_css_image_cross_fade_print;
|
2020-01-11 13:38:49 +00:00
|
|
|
image_class->is_computed = gtk_css_image_cross_fade_is_computed;
|
2012-04-02 01:25:30 +00:00
|
|
|
|
|
|
|
object_class->dispose = gtk_css_image_cross_fade_dispose;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-26 16:39:07 +00:00
|
|
|
gtk_css_image_cross_fade_init (GtkCssImageCrossFade *self)
|
2012-04-02 01:25:30 +00:00
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
self->images = g_array_new (FALSE, FALSE, sizeof (CrossFadeEntry));
|
|
|
|
g_array_set_clear_func (self->images, cross_fade_entry_clear);
|
2012-04-02 01:25:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkCssImage *
|
|
|
|
_gtk_css_image_cross_fade_new (GtkCssImage *start,
|
|
|
|
GtkCssImage *end,
|
|
|
|
double progress)
|
|
|
|
{
|
2019-03-26 16:39:07 +00:00
|
|
|
GtkCssImageCrossFade *self;
|
2012-04-02 01:25:30 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (start == NULL || GTK_IS_CSS_IMAGE (start), NULL);
|
|
|
|
g_return_val_if_fail (end == NULL || GTK_IS_CSS_IMAGE (end), NULL);
|
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
self = gtk_css_image_cross_fade_new_empty ();
|
|
|
|
|
2012-04-02 01:25:30 +00:00
|
|
|
if (start)
|
2019-03-30 15:02:58 +00:00
|
|
|
gtk_css_image_cross_fade_add (self, TRUE, 1.0 - progress, g_object_ref (start));
|
2012-04-02 01:25:30 +00:00
|
|
|
if (end)
|
2019-03-30 15:02:58 +00:00
|
|
|
gtk_css_image_cross_fade_add (self, TRUE, progress, g_object_ref (end));
|
2012-04-02 01:25:30 +00:00
|
|
|
|
2019-03-26 16:39:07 +00:00
|
|
|
return GTK_CSS_IMAGE (self);
|
2012-04-02 01:25:30 +00:00
|
|
|
}
|
|
|
|
|