Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
cairo.h
Go to the documentation of this file.
1// clang-format off
2// SPDX-FileCopyrightText: © 2019-2020, 2022 Alexandros Theodotou <alex@zrythm.org>
3// SPDX-License-Identifier: LicenseRef-ZrythmLicense
4// clang-format on
5
12#ifndef __UTILS_CAIRO_H__
13#define __UTILS_CAIRO_H__
14
15#include "gtk_wrapper.h"
16
17typedef struct Dictionary Dictionary;
18
36
37#define CAIRO_CACHES (gZrythm->cairo_caches)
38
42#define Z_CAIRO_FONT "Bold 9"
43
48#define Z_CAIRO_TEXT_PADDING 2
49
50#if 0
51void
52z_cairo_draw_selection_with_color (
53 cairo_t * cr,
54 GdkRGBA * color,
55 double start_x,
56 double start_y,
57 double offset_x,
58 double offset_y);
59
60void
61z_cairo_draw_selection (
62 cairo_t * cr,
63 double start_x,
64 double start_y,
65 double offset_x,
66 double offset_y);
67#endif
68
69void
70z_cairo_draw_horizontal_line (
71 cairo_t * cr,
72 double y,
73 double from_x,
74 double to_x,
75 double line_width,
76 double alpha);
77
78void
79z_cairo_draw_vertical_line (
80 cairo_t * cr,
81 double x,
82 double from_y,
83 double to_y,
84 double line_width);
85
90static inline void
91z_cairo_rounded_rectangle (
92 cairo_t * cr,
93 double x,
94 double y,
95 double width,
96 double height,
97 double aspect,
98 double corner_radius)
99{
100 double radius = corner_radius / aspect;
101 double degrees = G_PI / 180.0;
102
103 cairo_new_sub_path (cr);
104 cairo_arc (
105 cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
106 cairo_arc (
107 cr, x + width - radius, y + height - radius, radius, 0 * degrees,
108 90 * degrees);
109 cairo_arc (
110 cr, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
111 cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
112 cairo_close_path (cr);
113}
114
115#define z_cairo_get_text_extents_for_widget( \
116 _widget, _layout, _text, _width, _height) \
117 _z_cairo_get_text_extents_for_widget ( \
118 (GtkWidget *) _widget, _layout, _text, _width, _height)
119
130void
132 GtkWidget * widget,
133 PangoLayout * layout,
134 const char * text,
135 int * width,
136 int * height);
137
141#define z_cairo_draw_text(cr, widget, layout, text) \
142 z_cairo_draw_text_full ( \
143 cr, widget, layout, text, Z_CAIRO_TEXT_PADDING, Z_CAIRO_TEXT_PADDING)
144
149void
151 cairo_t * cr,
152 GtkWidget * widget,
153 PangoLayout * layout,
154 const char * text,
155 int start_x,
156 int start_y);
157
161static inline void
162z_cairo_diamond (cairo_t * cr, double x, double y, double width, double height)
163{
164 cairo_move_to (cr, x, height / 2);
165 cairo_line_to (cr, width / 2, y);
166 cairo_line_to (cr, width, height / 2);
167 cairo_line_to (cr, width / 2, height);
168 cairo_line_to (cr, x, height / 2);
169 cairo_close_path (cr);
170}
171
175cairo_surface_t *
176z_cairo_get_surface_from_icon_name (const char * icon_name, int size, int scale);
177
182PangoLayout *
184 GtkWidget * widget,
185 const char * font,
186 PangoEllipsizeMode ellipsize_mode,
187 int ellipsize_padding);
188
193PangoLayout *
195 GtkWidget * widget,
196 PangoFontDescription * descr,
197 PangoEllipsizeMode ellipsize_mode,
198 int ellipsize_padding);
199
203PangoLayout *
205
217void
219 cairo_t ** cr_cache,
220 cairo_surface_t ** surface_cache,
221 int width,
222 int height,
223 cairo_t * new_cr);
224
226z_cairo_caches_new (void);
227
228void
229z_cairo_caches_free (CairoCaches * self);
230
235#endif
void z_cairo_reset_caches(cairo_t **cr_cache, cairo_surface_t **surface_cache, int width, int height, cairo_t *new_cr)
Resets a surface and cairo_t with a new surface and cairo_t based on the given rectangle and cairo_t.
cairo_surface_t * z_cairo_get_surface_from_icon_name(const char *icon_name, int size, int scale)
Returns a surface for the icon name.
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.
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_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.
PangoLayout * 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.
PangoLayout * z_cairo_create_default_pango_layout(GtkWidget *widget)
Creates a PangoLayout with default settings.
Caches for cairo.
Definition cairo.h:29
Dictionary * icon_surface_dict
Icon surface dictionary: icon name: cairo_surface_t.
Definition cairo.h:34