1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2011 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 #include "gtkcssrgbavalueprivate.h"
22 #include "gtkcssstylepropertyprivate.h"
23 #include "gtkstylecontextprivate.h"
24 #include "gtksymboliccolorprivate.h"
32 gtk_css_value_rgba_free (GtkCssValue *value)
34 g_slice_free (GtkCssValue, value);
38 gtk_css_value_rgba_compute (GtkCssValue *value,
40 GtkStyleProviderPrivate *provider,
41 GtkCssComputedValues *values,
42 GtkCssComputedValues *parent_values,
43 GtkCssDependencies *dependencies)
45 return _gtk_css_value_ref (value);
49 gtk_css_value_rgba_equal (const GtkCssValue *rgba1,
50 const GtkCssValue *rgba2)
52 return gdk_rgba_equal (&rgba1->rgba, &rgba2->rgba);
56 gtk_css_value_rgba_transition (GtkCssValue *start,
63 progress = CLAMP (progress, 0, 1);
64 transition.red = start->rgba.red + (end->rgba.red - start->rgba.red) * progress;
65 transition.green = start->rgba.green + (end->rgba.green - start->rgba.green) * progress;
66 transition.blue = start->rgba.blue + (end->rgba.blue - start->rgba.blue) * progress;
67 transition.alpha = start->rgba.alpha + (end->rgba.alpha - start->rgba.alpha) * progress;
69 return _gtk_css_rgba_value_new_from_rgba (&transition);
73 gtk_css_value_rgba_print (const GtkCssValue *rgba,
76 char *s = gdk_rgba_to_string (&rgba->rgba);
77 g_string_append (string, s);
81 static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
82 gtk_css_value_rgba_free,
83 gtk_css_value_rgba_compute,
84 gtk_css_value_rgba_equal,
85 gtk_css_value_rgba_transition,
86 gtk_css_value_rgba_print
90 _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
94 g_return_val_if_fail (rgba != NULL, NULL);
96 value = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_RGBA);
103 _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba)
105 g_return_val_if_fail (rgba->class == >K_CSS_VALUE_RGBA, NULL);