summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext/utils.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2011-02-08 23:42:45 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2011-02-08 23:42:45 +0000
commit4ed504acd729fedb76aaa3b534dfd2b43082b5bb (patch)
tree822e8ac2d637391313ec3fed2ac0bba071c6cd02 /libs/gtkmm2ext/utils.cc
parent6be6041b719532ba6fa5e59e78f95cd464faf6e0 (diff)
added Gtkmm2ext::rounded_rectangle() cairo pseudo-method
git-svn-id: svn://localhost/ardour2/branches/3.0@8787 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/gtkmm2ext/utils.cc')
-rw-r--r--libs/gtkmm2ext/utils.cc82
1 files changed, 82 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/utils.cc b/libs/gtkmm2ext/utils.cc
index df79e535a7..878d5402af 100644
--- a/libs/gtkmm2ext/utils.cc
+++ b/libs/gtkmm2ext/utils.cc
@@ -386,3 +386,85 @@ Gtkmm2ext::container_clear (Gtk::Container& c)
c.remove (**child);
}
}
+
+#if 1
+void
+Gtkmm2ext::rounded_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r)
+{
+ /* renders small shapes better than most others */
+
+/* A****BQ
+ H C
+ * *
+ G D
+ F****E
+*/
+ context->move_to(x+r,y); // Move to A
+ context->line_to(x+w-r,y); // Straight line to B
+ context->curve_to(x+w,y,x+w,y,x+w,y+r); // Curve to C, Control points are both at Q
+ context->line_to(x+w,y+h-r); // Move to D
+ context->curve_to(x+w,y+h,x+w,y+h,x+w-r,y+h); // Curve to E
+ context->line_to(x+r,y+h); // Line to F
+ context->curve_to(x,y+h,x,y+h,x,y+h-r); // Curve to G
+ context->line_to(x,y+r); // Line to H
+ context->curve_to(x,y,x,y,x+r,y); // Curve to A
+}
+
+#else
+
+void
+Gtkmm2ext::rounded_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double width, double height, double radius)
+{
+ /* doesn't render small shapes well at all, and does not absolutely honor width & height */
+
+ double x0 = x+radius/2.0;
+ double y0 = y+radius/2.0;
+ double rect_width = width - radius;
+ double rect_height = height - radius;
+
+ context->save();
+
+ double x1=x0+rect_width;
+ double y1=y0+rect_height;
+
+ if (rect_width/2<radius) {
+ if (rect_height/2<radius) {
+ context->move_to (x0, (y0 + y1)/2);
+ context->curve_to (x0 ,y0, x0, y0, (x0 + x1)/2, y0);
+ context->curve_to (x1, y0, x1, y0, x1, (y0 + y1)/2);
+ context->curve_to (x1, y1, x1, y1, (x1 + x0)/2, y1);
+ context->curve_to (x0, y1, x0, y1, x0, (y0 + y1)/2);
+ } else {
+ context->move_to (x0, y0 + radius);
+ context->curve_to (x0 ,y0, x0, y0, (x0 + x1)/2, y0);
+ context->curve_to (x1, y0, x1, y0, x1, y0 + radius);
+ context->line_to (x1 , y1 - radius);
+ context->curve_to (x1, y1, x1, y1, (x1 + x0)/2, y1);
+ context->curve_to (x0, y1, x0, y1, x0, y1- radius);
+ }
+ } else {
+ if (rect_height/2<radius) {
+ context->move_to (x0, (y0 + y1)/2);
+ context->curve_to (x0 , y0, x0 , y0, x0 + radius, y0);
+ context->line_to (x1 - radius, y0);
+ context->curve_to (x1, y0, x1, y0, x1, (y0 + y1)/2);
+ context->curve_to (x1, y1, x1, y1, x1 - radius, y1);
+ context->line_to (x0 + radius, y1);
+ context->curve_to (x0, y1, x0, y1, x0, (y0 + y1)/2);
+ } else {
+ context->move_to (x0, y0 + radius);
+ context->curve_to (x0 , y0, x0 , y0, x0 + radius, y0);
+ context->line_to (x1 - radius, y0);
+ context->curve_to (x1, y0, x1, y0, x1, y0 + radius);
+ context->line_to (x1 , y1 - radius);
+ context->curve_to (x1, y1, x1, y1, x1 - radius, y1);
+ context->line_to (x0 + radius, y1);
+ context->curve_to (x0, y1, x0, y1, x0, y1- radius);
+ }
+ }
+
+ context->close_path ();
+ context->restore();
+}
+
+#endif