Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
cairo.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2020, 2022 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
9
10#ifndef __UTILS_CAIRO_H__
11#define __UTILS_CAIRO_H__
12
13#include "common/utils/pango.h"
14#include "gui/backend/gtk_widgets/gtk_wrapper.h"
15
16class Color;
17
23
27#define Z_CAIRO_FONT "Bold 9"
28
32#define Z_CAIRO_TEXT_PADDING 2
33
34void
35z_cairo_draw_horizontal_line (
36 cairo_t * cr,
37 double y,
38 double from_x,
39 double to_x,
40 double line_width,
41 double alpha);
42
43void
44z_cairo_draw_vertical_line (
45 cairo_t * cr,
46 double x,
47 double from_y,
48 double to_y,
49 double line_width);
50
55static inline void
56z_cairo_rounded_rectangle (
57 cairo_t * cr,
58 double x,
59 double y,
60 double width,
61 double height,
62 double aspect,
63 double corner_radius)
64{
65 double radius = corner_radius / aspect;
66 double degrees = G_PI / 180.0;
67
68 cairo_new_sub_path (cr);
69 cairo_arc (
70 cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
71 cairo_arc (
72 cr, x + width - radius, y + height - radius, radius, 0 * degrees,
73 90 * degrees);
74 cairo_arc (
75 cr, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
76 cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
77 cairo_close_path (cr);
78}
79
80#define z_cairo_get_text_extents_for_widget( \
81 _widget, _layout, _text, _width, _height) \
82 _z_cairo_get_text_extents_for_widget ( \
83 (GtkWidget *) _widget, _layout, _text, _width, _height)
84
95void
97 GtkWidget * widget,
98 PangoLayout * layout,
99 const char * text,
100 int * width,
101 int * height);
102
106#define z_cairo_draw_text(cr, widget, layout, text) \
107 z_cairo_draw_text_full ( \
108 cr, widget, layout, text, Z_CAIRO_TEXT_PADDING, Z_CAIRO_TEXT_PADDING)
109
114void
116 cairo_t * cr,
117 GtkWidget * widget,
118 PangoLayout * layout,
119 const char * text,
120 int start_x,
121 int start_y);
122
126static inline void
127z_cairo_diamond (cairo_t * cr, double x, double y, double width, double height)
128{
129 cairo_move_to (cr, x, height / 2);
130 cairo_line_to (cr, width / 2, y);
131 cairo_line_to (cr, width, height / 2);
132 cairo_line_to (cr, width / 2, height);
133 cairo_line_to (cr, x, height / 2);
134 cairo_close_path (cr);
135}
136
141PangoLayoutUniquePtr
143 GtkWidget * widget,
144 const char * font,
145 PangoEllipsizeMode ellipsize_mode,
146 int ellipsize_padding);
147
152PangoLayoutUniquePtr
154 GtkWidget * widget,
155 PangoFontDescription * descr,
156 PangoEllipsizeMode ellipsize_mode,
157 int ellipsize_padding);
158
162PangoLayout *
164
165void
166z_cairo_set_source_color (cairo_t * cr, Color color);
167
171
172#endif
PangoLayoutUniquePtr z_cairo_create_pango_layout_from_string(GtkWidget *widget, const char *font, PangoEllipsizeMode ellipsize_mode, int ellipsize_padding)
Creates a PangoLayout to be cached in widgets based on the given settings.
void z_cairo_draw_text_full(cairo_t *cr, GtkWidget *widget, PangoLayout *layout, const char *text, int start_x, int start_y)
Draws the given text using the given font starting at the given position.
PangoLayoutUniquePtr z_cairo_create_pango_layout_from_description(GtkWidget *widget, PangoFontDescription *descr, PangoEllipsizeMode ellipsize_mode, int ellipsize_padding)
Creates a PangoLayout to be cached in widgets based on the given settings.
void _z_cairo_get_text_extents_for_widget(GtkWidget *widget, PangoLayout *layout, const char *text, int *width, int *height)
Gets the width of the given text in pixels for the given widget.
PangoLayout * z_cairo_create_default_pango_layout(GtkWidget *widget)
Creates a PangoLayout with default settings.