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 GtkStyleContext *context)
42 return _gtk_css_value_ref (value);
46 gtk_css_value_rgba_equal (const GtkCssValue *rgba1,
47 const GtkCssValue *rgba2)
49 return gdk_rgba_equal (&rgba1->rgba, &rgba2->rgba);
53 gtk_css_value_rgba_transition (GtkCssValue *start,
59 progress = CLAMP (progress, 0, 1);
60 transition.red = start->rgba.red + (end->rgba.red - start->rgba.red) * progress;
61 transition.green = start->rgba.green + (end->rgba.green - start->rgba.green) * progress;
62 transition.blue = start->rgba.blue + (end->rgba.blue - start->rgba.blue) * progress;
63 transition.alpha = start->rgba.alpha + (end->rgba.alpha - start->rgba.alpha) * progress;
65 return _gtk_css_rgba_value_new_from_rgba (&transition);
69 gtk_css_value_rgba_print (const GtkCssValue *rgba,
72 char *s = gdk_rgba_to_string (&rgba->rgba);
73 g_string_append (string, s);
77 static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
78 gtk_css_value_rgba_free,
79 gtk_css_value_rgba_compute,
80 gtk_css_value_rgba_equal,
81 gtk_css_value_rgba_transition,
82 gtk_css_value_rgba_print
86 _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
90 g_return_val_if_fail (rgba != NULL, NULL);
92 value = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_RGBA);
99 _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba)
101 g_return_val_if_fail (rgba->class == >K_CSS_VALUE_RGBA, NULL);