Zrythm
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
10#ifndef __UTILS_CAIRO_H__
11#define __UTILS_CAIRO_H__
12
13#include <gtk/gtk.h>
14
15typedef struct Dictionary Dictionary;
16
34
35#define CAIRO_CACHES (ZRYTHM->cairo_caches)
36
40#define Z_CAIRO_FONT "Bold 9"
41
46#define Z_CAIRO_TEXT_PADDING 2
47
48#if 0
49void
50z_cairo_draw_selection_with_color (
51 cairo_t * cr,
52 GdkRGBA * color,
53 double start_x,
54 double start_y,
55 double offset_x,
56 double offset_y);
57
58void
59z_cairo_draw_selection (
60 cairo_t * cr,
61 double start_x,
62 double start_y,
63 double offset_x,
64 double offset_y);
65#endif
66
67void
68z_cairo_draw_horizontal_line (
69 cairo_t * cr,
70 double y,
71 double from_x,
72 double to_x,
73 double line_width,
74 double alpha);
75
76void
77z_cairo_draw_vertical_line (
78 cairo_t * cr,
79 double x,
80 double from_y,
81 double to_y,
82 double line_width);
83
88static inline void
89z_cairo_rounded_rectangle (
90 cairo_t * cr,
91 double x,
92 double y,
93 double width,
94 double height,
95 double aspect,
96 double corner_radius)
97{
98 double radius = corner_radius / aspect;
99 double degrees = G_PI / 180.0;
100
101 cairo_new_sub_path (cr);
102 cairo_arc (
103 cr, x + width - radius, y + radius, radius, -90 * degrees,
104 0 * degrees);
105 cairo_arc (
106 cr, x + width - radius, y + height - radius, radius,
107 0 * degrees, 90 * degrees);
108 cairo_arc (
109 cr, x + radius, y + height - radius, radius, 90 * degrees,
110 180 * degrees);
111 cairo_arc (
112 cr, x + radius, y + radius, radius, 180 * degrees,
113 270 * degrees);
114 cairo_close_path (cr);
115}
116
117#define z_cairo_get_text_extents_for_widget( \
118 _widget, _layout, _text, _width, _height) \
119 _z_cairo_get_text_extents_for_widget ( \
120 (GtkWidget *) _widget, _layout, _text, _width, _height)
121
132void
134 GtkWidget * widget,
135 PangoLayout * layout,
136 const char * text,
137 int * width,
138 int * height);
139
143#define z_cairo_draw_text(cr, widget, layout, text) \
144 z_cairo_draw_text_full ( \
145 cr, widget, layout, text, Z_CAIRO_TEXT_PADDING, \
146 Z_CAIRO_TEXT_PADDING)
147
152void
154 cairo_t * cr,
155 GtkWidget * widget,
156 PangoLayout * layout,
157 const char * text,
158 int start_x,
159 int start_y);
160
164static inline void
165z_cairo_diamond (
166 cairo_t * cr,
167 double x,
168 double y,
169 double width,
170 double height)
171{
172 cairo_move_to (cr, x, height / 2);
173 cairo_line_to (cr, width / 2, y);
174 cairo_line_to (cr, width, height / 2);
175 cairo_line_to (cr, width / 2, height);
176 cairo_line_to (cr, x, height / 2);
177 cairo_close_path (cr);
178}
179
183cairo_surface_t *
185 const char * icon_name,
186 int size,
187 int scale);
188
193PangoLayout *
195 GtkWidget * widget,
196 const char * font,
197 PangoEllipsizeMode ellipsize_mode,
198 int ellipsize_padding);
199
204PangoLayout *
206 GtkWidget * widget,
207 PangoFontDescription * descr,
208 PangoEllipsizeMode ellipsize_mode,
209 int ellipsize_padding);
210
214PangoLayout *
216
228void
230 cairo_t ** cr_cache,
231 cairo_surface_t ** surface_cache,
232 int width,
233 int height,
234 cairo_t * new_cr);
235
237z_cairo_caches_new (void);
238
239void
240z_cairo_caches_free (CairoCaches * self);
241
246#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:27
Dictionary * icon_surface_dict
Icon surface dictionary: icon name: cairo_surface_t.
Definition cairo.h:32