]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssrgbavalue.c
stylecontext: Do invalidation on first resize container
[~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
25 struct _GtkCssValue {
26   GTK_CSS_VALUE_BASE
27   GdkRGBA rgba;
28 };
29
30 static void
31 gtk_css_value_rgba_free (GtkCssValue *value)
32 {
33   g_slice_free (GtkCssValue, value);
34 }
35
36 static GtkCssValue *
37 gtk_css_value_rgba_compute (GtkCssValue             *value,
38                             guint                    property_id,
39                             GtkStyleProviderPrivate *provider,
40                             GtkCssComputedValues    *values,
41                             GtkCssComputedValues    *parent_values,
42                             GtkCssDependencies      *dependencies)
43 {
44   return _gtk_css_value_ref (value);
45 }
46
47 static gboolean
48 gtk_css_value_rgba_equal (const GtkCssValue *rgba1,
49                           const GtkCssValue *rgba2)
50 {
51   return gdk_rgba_equal (&rgba1->rgba, &rgba2->rgba);
52 }
53
54 static GtkCssValue *
55 gtk_css_value_rgba_transition (GtkCssValue *start,
56                                GtkCssValue *end,
57                                guint        property_id,
58                                double       progress)
59 {
60   GdkRGBA transition;
61
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;
67
68   return _gtk_css_rgba_value_new_from_rgba (&transition);
69 }
70
71 static void
72 gtk_css_value_rgba_print (const GtkCssValue *rgba,
73                           GString           *string)
74 {
75   char *s = gdk_rgba_to_string (&rgba->rgba);
76   g_string_append (string, s);
77   g_free (s);
78 }
79
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
86 };
87
88 GtkCssValue *
89 _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
90 {
91   GtkCssValue *value;
92
93   g_return_val_if_fail (rgba != NULL, NULL);
94
95   value = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_RGBA);
96   value->rgba = *rgba;
97
98   return value;
99 }
100
101 const GdkRGBA *
102 _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba)
103 {
104   g_return_val_if_fail (rgba->class == &GTK_CSS_VALUE_RGBA, NULL);
105
106   return &rgba->rgba;
107 }