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"
31 gtk_css_value_rgba_free (GtkCssValue *value)
33 g_slice_free (GtkCssValue, value);
37 gtk_css_value_rgba_compute (GtkCssValue *value,
39 GtkStyleProviderPrivate *provider,
40 GtkCssComputedValues *values,
41 GtkCssComputedValues *parent_values,
42 GtkCssDependencies *dependencies)
44 return _gtk_css_value_ref (value);
48 gtk_css_value_rgba_equal (const GtkCssValue *rgba1,
49 const GtkCssValue *rgba2)
51 return gdk_rgba_equal (&rgba1->rgba, &rgba2->rgba);
55 gtk_css_value_rgba_transition (GtkCssValue *start,
62 progress = CLAMP (progress, 0, 1);
63 transition.red = start->rgba.red + (end->rgba.red - start->rgba.red) * progress;
64 transition.green = start->rgba.green + (end->rgba.green - start->rgba.green) * progress;
65 transition.blue = start->rgba.blue + (end->rgba.blue - start->rgba.blue) * progress;
66 transition.alpha = start->rgba.alpha + (end->rgba.alpha - start->rgba.alpha) * progress;
68 return _gtk_css_rgba_value_new_from_rgba (&transition);
72 gtk_css_value_rgba_print (const GtkCssValue *rgba,
75 char *s = gdk_rgba_to_string (&rgba->rgba);
76 g_string_append (string, s);
80 static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
81 gtk_css_value_rgba_free,
82 gtk_css_value_rgba_compute,
83 gtk_css_value_rgba_equal,
84 gtk_css_value_rgba_transition,
85 gtk_css_value_rgba_print
89 _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
93 g_return_val_if_fail (rgba != NULL, NULL);
95 value = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_RGBA);
102 _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba)
104 g_return_val_if_fail (rgba->class == >K_CSS_VALUE_RGBA, NULL);