From 353f70e3cedd324102d64943ac0523500c8a63b5 Mon Sep 17 00:00:00 2001 From: Gio Lucas Torres Date: Tue, 18 Jun 2024 21:02:41 +0200 Subject: [PATCH] Support to draw variable rounded rectangles with Cairo --- c_src/device/cairo/cairo_script_ops.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/c_src/device/cairo/cairo_script_ops.c b/c_src/device/cairo/cairo_script_ops.c index ee1f807..b3ecc92 100644 --- a/c_src/device/cairo/cairo_script_ops.c +++ b/c_src/device/cairo/cairo_script_ops.c @@ -141,6 +141,30 @@ void script_ops_draw_rrect(void* v_ctx, do_fill_stroke(p_ctx, fill, stroke); } +void script_ops_draw_rrectv(void *v_ctx, + float w, + float h, + float ulr, + float urr, + float lrr, + float llr, + bool fill, bool stroke) +{ + if (g_opts.debug_mode) { + log_script_ops_draw_rrectv(log_prefix, __func__, log_level_info, + w, h, ulr, urr, lrr, llr, fill, stroke); + } + + scenic_cairo_ctx_t* p_ctx = (scenic_cairo_ctx_t*)v_ctx; + cairo_arc(p_ctx->cr, 0 + ulr, 0 + ulr, ulr, 2 * (M_PI / 2), 3 * (M_PI / 2)); + cairo_arc(p_ctx->cr, w - urr, 0 + urr, urr, 3 * (M_PI / 2), 4 * (M_PI / 2)); + cairo_arc(p_ctx->cr, w - lrr, h - lrr, lrr, 0 * (M_PI / 2), 1 * (M_PI / 2)); + cairo_arc(p_ctx->cr, 0 + llr, h - llr, llr, 1 * (M_PI / 2), 2 * (M_PI / 2)); + cairo_close_path(p_ctx->cr); + + do_fill_stroke(p_ctx, fill, stroke); +} + void script_ops_draw_arc(void* v_ctx, float radius, float radians,