[gimp] app: add gimp_cairo_rounded_rectangle()



commit a6001f1941d5ed17033828fa9768f5d12ade49cc
Author: Ell <ell_se yahoo com>
Date:   Wed Mar 7 05:32:25 2018 -0500

    app: add gimp_cairo_rounded_rectangle()
    
    ... which draws a rectangle with rounded corners.

 app/core/gimp-cairo.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++++
 app/core/gimp-cairo.h |    6 +++++
 2 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimp-cairo.c b/app/core/gimp-cairo.c
index 40b19fc..9814235 100644
--- a/app/core/gimp-cairo.c
+++ b/app/core/gimp-cairo.c
@@ -35,6 +35,9 @@
 #include "gimp-cairo.h"
 
 
+#define REV (2.0 * G_PI)
+
+
 static cairo_user_data_key_t surface_data_key = { 0, };
 
 
@@ -125,6 +128,63 @@ gimp_cairo_arc (cairo_t *cr,
 }
 
 void
+gimp_cairo_rounded_rectangle (cairo_t *cr,
+                              gdouble  x,
+                              gdouble  y,
+                              gdouble  width,
+                              gdouble  height,
+                              gdouble  corner_radius)
+{
+  g_return_if_fail (cr != NULL);
+
+  if (width < 0.0)
+    {
+      x     += width;
+      width  = -width;
+    }
+
+  if (height < 0.0)
+    {
+      y      += height;
+      height  = -height;
+    }
+
+  corner_radius = CLAMP (corner_radius, 0.0, MIN (width, height) / 2.0);
+
+  cairo_new_sub_path (cr);
+
+  cairo_arc     (cr,
+                 x + corner_radius, y + corner_radius,
+                 corner_radius,
+                 0.50 * REV, 0.75 * REV);
+  cairo_line_to (cr,
+                 x + width - corner_radius, y);
+
+  cairo_arc     (cr,
+                 x + width - corner_radius, y + corner_radius,
+                 corner_radius,
+                 0.75 * REV, 1.00 * REV);
+  cairo_line_to (cr,
+                 x + width, y + height - corner_radius);
+
+  cairo_arc     (cr,
+                 x + width - corner_radius, y + height - corner_radius,
+                 corner_radius,
+                 0.00 * REV, 0.25 * REV);
+  cairo_line_to (cr,
+                 x + corner_radius, y + height);
+
+  cairo_arc     (cr,
+                 x + corner_radius, y + height - corner_radius,
+                 corner_radius,
+                 0.25 * REV, 0.50 * REV);
+  cairo_line_to (cr,
+                 x, y + corner_radius);
+
+  cairo_close_path (cr);
+}
+
+void
 gimp_cairo_segments (cairo_t     *cr,
                      GimpSegment *segs,
                      gint         n_segs)
diff --git a/app/core/gimp-cairo.h b/app/core/gimp-cairo.h
index bdcc236..0c56500 100644
--- a/app/core/gimp-cairo.h
+++ b/app/core/gimp-cairo.h
@@ -37,6 +37,12 @@ void              gimp_cairo_arc                    (cairo_t         *cr,
                                                      gdouble          radius,
                                                      gdouble          start_angle,
                                                      gdouble          slice_angle);
+void              gimp_cairo_rounded_rectangle      (cairo_t         *cr,
+                                                     gdouble          x,
+                                                     gdouble          y,
+                                                     gdouble          width,
+                                                     gdouble          height,
+                                                     gdouble          corner_radius);
 void              gimp_cairo_segments               (cairo_t         *cr,
                                                      GimpSegment     *segs,
                                                      gint             n_segs);


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