1 /*
2 * Copyright (C) 2019 Alexandros Theodotou <alex at zrythm dot org>
3 *
4 * This file is part of ZPlugins
5 *
6 * ZPlugins is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * ZPlugins is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Affero Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __Z_TOOLKIT_ZTK_CAIRO_H__
21 #define __Z_TOOLKIT_ZTK_CAIRO_H__
22
23 #include <math.h>
24
25 /**
26 * @param aspect Aspect ratio.
27 * @param corner_radius Corner curvature radius.
28 */
29 static inline void
ztk_cairo_rounded_rectangle(cairo_t * cr,double x,double y,double width,double height,double aspect,double corner_radius)30 ztk_cairo_rounded_rectangle (
31 cairo_t * cr,
32 double x,
33 double y,
34 double width,
35 double height,
36 double aspect,
37 double corner_radius)
38 {
39 double radius = corner_radius / aspect;
40 double degrees = M_PI / 180.0;
41
42 cairo_new_sub_path (cr);
43 cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
44 cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
45 cairo_arc (cr, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
46 cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
47 cairo_close_path (cr);
48 }
49
50 #endif
51