Release Clutter 1.11.4 (snapshot)
[profile/ivi/clutter.git] / clutter / clutter-cairo.c
1 /*
2  * Clutter.
3  *
4  * An OpenGL based 'interactive canvas' library.
5  *
6  * Copyright (C) 2012 Intel Corporation
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 /**
23  * SECTION:clutter-cairo
24  * @Title: Cairo integration
25  * @Short_Description: Functions for interoperating with Cairo
26  *
27  * Clutter provides some utility functions for using Cairo.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include "clutter-cairo.h"
35 #include "clutter-color.h"
36
37 /**
38  * clutter_cairo_set_source_color:
39  * @cr: a Cairo context
40  * @color: a #ClutterColor
41  *
42  * Utility function for setting the source color of @cr using
43  * a #ClutterColor. This function is the equivalent of:
44  *
45  * |[
46  *   cairo_set_source_rgba (cr,
47  *                          color->red / 255.0,
48  *                          color->green / 255.0,
49  *                          color->blue / 255.0,
50  *                          color->alpha / 255.0);
51  * ]|
52  *
53  * Since: 1.0
54  */
55 void
56 clutter_cairo_set_source_color (cairo_t            *cr,
57                                 const ClutterColor *color)
58 {
59   g_return_if_fail (cr != NULL);
60   g_return_if_fail (color != NULL);
61
62   if (color->alpha == 0xff)
63     cairo_set_source_rgb (cr,
64                           color->red / 255.0,
65                           color->green / 255.0,
66                           color->blue / 255.0);
67   else
68     cairo_set_source_rgba (cr,
69                            color->red / 255.0,
70                            color->green / 255.0,
71                            color->blue / 255.0,
72                            color->alpha / 255.0);
73 }
74
75 /**
76  * clutter_cairo_clear:
77  * @cr: a Cairo context
78  *
79  * Utility function to clear a Cairo context.
80  *
81  * Since: 1.12
82  */
83 void
84 clutter_cairo_clear (cairo_t *cr)
85 {
86   cairo_save (cr);
87
88   cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
89   cairo_paint (cr);
90
91   cairo_restore (cr);
92 }