1 /* LUA - a LUA scriptable GTK+ engine
2  * Copyright (C) 2006 Daniel Borgmann <daniel.borgmann@gmail.com>
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.1 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, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Project contact: <gnome-themes-list@gnome.org>
19  *
20  */
21 
22 
23 #include "draw_utils.h"
24 
25 static void
rounded_rectangle(cairo_t * cr,gdouble x,gdouble y,gdouble w,gdouble h,gdouble radius,gboolean tl,gboolean tr,gboolean bl,gboolean br)26 rounded_rectangle (cairo_t *cr,
27                    gdouble x, gdouble y, gdouble w, gdouble h, gdouble radius,
28                    gboolean tl, gboolean tr, gboolean bl, gboolean br)
29 {
30 	if (tl)
31 		cairo_move_to (cr, x+radius, y);
32 	else
33 		cairo_move_to (cr, x, y);
34 
35 	if (tr)
36 		cairo_arc (cr, x+w-radius, y+radius, radius, G_PI * 1.5, G_PI * 2);
37 	else
38 		cairo_line_to (cr, x+w, y);
39 
40 	if (br)
41 		cairo_arc (cr, x+w-radius, y+h-radius, radius, 0, G_PI * 0.5);
42 	else
43 		cairo_line_to (cr, x+w, y+h);
44 
45 	if (bl)
46 		cairo_arc (cr, x+radius,   y+h-radius, radius, G_PI * 0.5, G_PI);
47 	else
48 		cairo_line_to (cr, x, y+h);
49 
50 	if (tl)
51 		cairo_arc (cr, x+radius,   y+radius,   radius, G_PI, G_PI * 1.5);
52 	else
53 		cairo_line_to (cr, x, y);
54 }
55 
56 void
draw_rectangle(cairo_t * cr,gdouble x,gdouble y,gdouble width,gdouble height,gdouble radius,gboolean tl,gboolean tr,gboolean bl,gboolean br,gboolean filled)57 draw_rectangle (cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height,
58                 gdouble radius, gboolean tl, gboolean tr, gboolean bl, gboolean br,
59                 gboolean filled)
60 {
61 	if (radius)
62 		rounded_rectangle (cr, x, y, width, height, radius, tl, tr, bl, br);
63 	else
64 		cairo_rectangle (cr, x, y, width, height);
65 
66 	if (filled)
67 		cairo_fill (cr);
68 	else
69 		cairo_stroke (cr);
70 }
71