[accounts-dialog] Use rounded rectangles, not hyperellipses



commit 132b7afed69ce17dae5c85f28142d1005f9baf04
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Mar 1 15:37:01 2010 -0500

    Use rounded rectangles, not hyperellipses

 src/um-user.c  |   65 +++----------------------------------------------------
 src/um-utils.c |   43 +++++++++++++++++++++++++++++++++++++
 src/um-utils.h |    7 ++++++
 3 files changed, 54 insertions(+), 61 deletions(-)
---
diff --git a/src/um-user.c b/src/um-user.c
index 756e3c9..eb7062a 100644
--- a/src/um-user.c
+++ b/src/um-user.c
@@ -38,6 +38,8 @@
 
 #include "um-user.h"
 #include "um-account-type.h"
+#include "um-utils.h"
+
 
  #define UM_USER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UM_TYPE_USER, UmUserClass))
  #define UM_IS_USER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UM_TYPE_USER))
@@ -375,63 +377,6 @@ check_user_file (const char *filename,
         return TRUE;
 }
 
-static void
-curved_rectangle (cairo_t *cr,
-                  double   x0,
-                  double   y0,
-                  double   width,
-                  double   height,
-                  double   radius)
-{
-        double x1;
-        double y1;
-
-        x1 = x0 + width;
-        y1 = y0 + height;
-
-        if (width < FLT_EPSILON || height < FLT_EPSILON) {
-                return;
-        }
-
-        if (width / 2 < radius) {
-                if (height / 2 < radius) {
-                        cairo_move_to  (cr, x0, (y0 + y1) / 2);
-                        cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1) / 2, y0);
-                        cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1) / 2);
-                        cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0) / 2, y1);
-                        cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1) / 2);
-                } else {
-                        cairo_move_to  (cr, x0, y0 + radius);
-                        cairo_curve_to (cr, x0, y0, x0, y0, (x0 + x1) / 2, y0);
-                        cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
-                        cairo_line_to (cr, x1, y1 - radius);
-                        cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0) / 2, y1);
-                        cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - radius);
-                }
-        } else {
-                if (height / 2 < radius) {
-                        cairo_move_to  (cr, x0, (y0 + y1) / 2);
-                        cairo_curve_to (cr, x0, y0, x0 , y0, x0 + radius, y0);
-                        cairo_line_to (cr, x1 - radius, y0);
-                        cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1) / 2);
-                        cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
-                        cairo_line_to (cr, x0 + radius, y1);
-                        cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1) / 2);
-                } else {
-                        cairo_move_to  (cr, x0, y0 + radius);
-                        cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
-                        cairo_line_to (cr, x1 - radius, y0);
-                        cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
-                        cairo_line_to (cr, x1, y1 - radius);
-                        cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
-                        cairo_line_to (cr, x0 + radius, y1);
-                        cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - radius);
-                }
-        }
-
-        cairo_close_path (cr);
-}
-
 static cairo_surface_t *
 surface_from_pixbuf (GdkPixbuf *pixbuf)
 {
@@ -562,7 +507,7 @@ frame_pixbuf (GdkPixbuf *source)
 
         w = gdk_pixbuf_get_width (source) + frame_width * 2;
         h = gdk_pixbuf_get_height (source) + frame_width * 2;
-        radius = w / 3.0;
+        radius = w / 10;
 
         dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
                                TRUE,
@@ -587,9 +532,7 @@ frame_pixbuf (GdkPixbuf *source)
         cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0);
         cairo_fill (cr);
 
-        curved_rectangle (cr, frame_width, frame_width,
-                          w - frame_width * 2, h - frame_width * 2,
-                          radius);
+        rounded_rectangle (cr, 1.0, 0.5, 0.5, radius, w - 1, h - 1);
         cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.3);
         cairo_fill_preserve (cr);
 
diff --git a/src/um-utils.c b/src/um-utils.c
index a9e1dc8..6d81fe4 100644
--- a/src/um-utils.c
+++ b/src/um-utils.c
@@ -326,3 +326,46 @@ popup_menu_below_button (GtkMenu   *menu,
         *push_in = TRUE;
 }
 
+void
+rounded_rectangle (cairo_t *cr,
+                   gdouble  aspect,
+                   gdouble  x,
+                   gdouble  y,
+                   gdouble  corner_radius,
+                   gdouble  width,
+                   gdouble  height)
+{
+        gdouble radius;
+        gdouble degrees;
+
+        radius = corner_radius / aspect;
+        degrees = G_PI / 180.0;
+
+        cairo_new_sub_path (cr);
+        cairo_arc (cr,
+                   x + width - radius,
+                   y + radius,
+                   radius,
+                   -90 * degrees,
+                   0 * degrees);
+        cairo_arc (cr,
+                   x + width - radius,
+                   y + height - radius,
+                   radius,
+                   0 * degrees,
+                   90 * degrees);
+        cairo_arc (cr,
+                   x + radius,
+                   y + height - radius,
+                   radius,
+                   90 * degrees,
+                   180 * degrees);
+        cairo_arc (cr,
+                   x + radius,
+                   y + radius,
+                   radius,
+                   180 * degrees,
+                   270 * degrees);
+        cairo_close_path (cr);
+}
+
diff --git a/src/um-utils.h b/src/um-utils.h
index c87cf58..c3b8a66 100644
--- a/src/um-utils.h
+++ b/src/um-utils.h
@@ -43,6 +43,13 @@ void     popup_menu_below_button          (GtkMenu     *menu,
                                            gboolean    *push_in,
                                            GtkWidget   *button);
 
+void     rounded_rectangle                (cairo_t     *cr,
+                                           gdouble      aspect,
+                                           gdouble      x,
+                                           gdouble      y,
+                                           gdouble      corner_radius,
+                                           gdouble      width,
+                                           gdouble      height);
 
 G_END_DECLS
 



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