From 5bf4223acabc3889b5371c517b08db78f508e03f Mon Sep 17 00:00:00 2001 From: Marvin W Date: Mon, 7 Apr 2025 15:28:51 +0200 Subject: Add Cairo fallback for GTK<4.14 --- .../file_transmission_progress.vala | 25 ++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'main/src/ui') diff --git a/main/src/ui/conversation_content_view/file_transmission_progress.vala b/main/src/ui/conversation_content_view/file_transmission_progress.vala index a69b547f..711e0822 100644 --- a/main/src/ui/conversation_content_view/file_transmission_progress.vala +++ b/main/src/ui/conversation_content_view/file_transmission_progress.vala @@ -76,30 +76,37 @@ namespace Dino.Ui { } } +#if GTK_4_14 private static extern Gsk.Path create_progress_arc(Gsk.Path circle, float percentage); +#endif public override void snapshot(Gtk.Snapshot snapshot) { base.snapshot(snapshot); - if (state == State.DOWNLOADING || state == State.UPLOADING) { + if ((state == State.DOWNLOADING || state == State.UPLOADING) && progress_animation.value > 0.01) { Gdk.RGBA fg_color = get_color(); get_style_context().lookup_color("accent_color", out fg_color); float radius = float.max(int.min(get_width(), get_height()) / 2, 1); float line_width = (float) LINE_WIDTH; - var stroke = new Gsk.Stroke(line_width); - stroke.set_line_cap(Gsk.LineCap.ROUND); - snapshot.translate({get_width() / 2, get_height() / 2}); - +#if GTK_4_14 var builder = new Gsk.PathBuilder(); builder.add_circle({0, 0}, radius - line_width / 2); var circle_path = builder.to_path(); - if (progress_animation.value > 0.01) { - var arc_path = create_progress_arc(circle_path, (float) progress_animation.value); - snapshot.append_stroke(arc_path, stroke, fg_color); - } + var stroke = new Gsk.Stroke(line_width); + stroke.set_line_cap(Gsk.LineCap.ROUND); + var arc_path = create_progress_arc(circle_path, (float) progress_animation.value); + snapshot.append_stroke(arc_path, stroke, fg_color); +#else + var context = snapshot.append_cairo({{-radius, -radius}, {radius*2, radius*2}}); + context.set_line_cap(Cairo.LineCap.ROUND); + context.set_line_width(line_width); + context.set_source_rgba(fg_color.red, fg_color.green, fg_color.blue, fg_color.alpha); + context.arc(0, 0, radius - line_width / 2, -0.5 * Math.PI, (progress_animation.value - 0.25) * 2 * Math.PI); + context.stroke(); +#endif } } -- cgit v1.3