]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssrgbavalue.c
GtkImageAccessible: add a private struct
[~andy/gtk] / gtk / gtkcssrgbavalue.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2011 Red Hat, Inc.
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 #include "config.h"
19
20 #include "gtkcssrgbavalueprivate.h"
21
22 #include "gtkcssstylepropertyprivate.h"
23 #include "gtkstylecontextprivate.h"
24 #include "gtksymboliccolorprivate.h"
25
26 struct _GtkCssValue {
27   GTK_CSS_VALUE_BASE
28   GdkRGBA rgba;
29 };
30
31 static void
32 gtk_css_value_rgba_free (GtkCssValue *value)
33 {
34   g_slice_free (GtkCssValue, value);
35 }
36
37 static GtkCssValue *
38 gtk_css_value_rgba_compute (GtkCssValue             *value,
39                             guint                    property_id,
40                             GtkStyleProviderPrivate *provider,
41                             GtkCssComputedValues    *values,
42                             GtkCssComputedValues    *parent_values,
43                             GtkCssDependencies      *dependencies)
44 {
45   return _gtk_css_value_ref (value);
46 }
47
48 static gboolean
49 gtk_css_value_rgba_equal (const GtkCssValue *rgba1,
50                           const GtkCssValue *rgba2)
51 {
52   return gdk_rgba_equal (&rgba1->rgba, &rgba2->rgba);
53 }
54
55 static GtkCssValue *
56 gtk_css_value_rgba_transition (GtkCssValue *start,
57                                GtkCssValue *end,
58                                guint        property_id,
59                                double       progress)
60 {
61   GdkRGBA transition;
62
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;
68
69   return _gtk_css_rgba_value_new_from_rgba (&transition);
70 }
71
72 static void
73 gtk_css_value_rgba_print (const GtkCssValue *rgba,
74                           GString           *string)
75 {
76   char *s = gdk_rgba_to_string (&rgba->rgba);
77   g_string_append (string, s);
78   g_free (s);
79 }
80
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
87 };
88
89 GtkCssValue *
90 _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
91 {
92   GtkCssValue *value;
93
94   g_return_val_if_fail (rgba != NULL, NULL);
95
96   value = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_RGBA);
97   value->rgba = *rgba;
98
99   return value;
100 }
101
102 const GdkRGBA *
103 _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba)
104 {
105   g_return_val_if_fail (rgba->class == &GTK_CSS_VALUE_RGBA, NULL);
106
107   return &rgba->rgba;
108 }