[sysprof/wip/gtk4-port: 23/132] cellrendererduration: inline rounded rectangle




commit 94296ea1a94d0bd6146834354933b19420192906
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 28 13:03:02 2021 -0700

    cellrendererduration: inline rounded rectangle
    
    We can just embed this instead of relying on dazzle, and inline it at
    the same time.

 src/libsysprof-ui/sysprof-cell-renderer-duration.c | 50 +++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
---
diff --git a/src/libsysprof-ui/sysprof-cell-renderer-duration.c 
b/src/libsysprof-ui/sysprof-cell-renderer-duration.c
index d1cebda6..94576227 100644
--- a/src/libsysprof-ui/sysprof-cell-renderer-duration.c
+++ b/src/libsysprof-ui/sysprof-cell-renderer-duration.c
@@ -55,6 +55,54 @@ G_DEFINE_TYPE_WITH_PRIVATE (SysprofCellRendererDuration, sysprof_cell_renderer_d
 
 static GParamSpec *properties [N_PROPS];
 
+static inline void
+rounded_rectangle (cairo_t            *cr,
+                   const GdkRectangle *rect,
+                   int                 x_radius,
+                   int                 y_radius)
+{
+  int x;
+  int y;
+  int width;
+  int height;
+  int x1, x2;
+  int y1, y2;
+  int xr1, xr2;
+  int yr1, yr2;
+
+  g_assert (cr);
+  g_assert (rect);
+
+  x = rect->x;
+  y = rect->y;
+  width = rect->width;
+  height = rect->height;
+
+  x1 = x;
+  x2 = x1 + width;
+  y1 = y;
+  y2 = y1 + height;
+
+  x_radius = MIN (x_radius, width / 2.0);
+  y_radius = MIN (y_radius, width / 2.0);
+
+  xr1 = x_radius;
+  xr2 = x_radius / 2.0;
+  yr1 = y_radius;
+  yr2 = y_radius / 2.0;
+
+  cairo_move_to (cr, x1 + xr1, y1);
+  cairo_line_to (cr, x2 - xr1, y1);
+  cairo_curve_to (cr, x2 - xr2, y1, x2, y1 + yr2, x2, y1 + yr1);
+  cairo_line_to (cr, x2, y2 - yr1);
+  cairo_curve_to (cr, x2, y2 - yr2, x2 - xr2, y2, x2 - xr1, y2);
+  cairo_line_to (cr, x1 + xr1, y2);
+  cairo_curve_to (cr, x1 + xr2, y2, x1, y2 - yr2, x1, y2 - yr1);
+  cairo_line_to (cr, x1, y1 + yr1);
+  cairo_curve_to (cr, x1, y1 + yr2, x1 + xr2, y1, x1 + xr1, y1);
+  cairo_close_path (cr);
+}
+
 static void
 sysprof_cell_renderer_duration_render (GtkCellRenderer      *renderer,
                                        cairo_t              *cr,
@@ -108,7 +156,7 @@ sysprof_cell_renderer_duration_render (GtkCellRenderer      *renderer,
 
   if (r.width > 3)
     {
-      dzl_cairo_rounded_rectangle (cr, &r, 2, 2);
+      rounded_rectangle (cr, &r, 2, 2);
       cairo_fill (cr);
     }
   else if (r.width > 1)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]