[cairo-commit] cairo-demo/png ChangeLog,1.14,1.15 bevels.c,1.1,1.2

Carl Worth commit at pdx.freedesktop.org
Mon Oct 18 14:11:47 PDT 2004


Committed by: cworth

Update of /cvs/cairo/cairo-demo/png
In directory gabe:/tmp/cvs-serv2859

Modified Files:
	ChangeLog bevels.c 
Log Message:

        (draw_bevels): Add sample radio buttons to demonstrate that
        circles work as well as rectangles.


Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/ChangeLog,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- ChangeLog	18 Oct 2004 14:43:47 -0000	1.14
+++ ChangeLog	18 Oct 2004 21:11:44 -0000	1.15
@@ -1,6 +1,8 @@
 2004-10-18  Carl Worth  <cworth at cworth.org>
 
 	* bevels.c: Add bevel example showing lines of 1-pixel width.
+	(draw_bevels): Add sample radio buttons to demonstrate that
+	circles work as well as rectangles.
 
 2004-09-10  Carl Worth  <cworth at brudder.east.isi.edu>
 

Index: bevels.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/png/bevels.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- bevels.c	18 Oct 2004 14:43:47 -0000	1.1
+++ bevels.c	18 Oct 2004 21:11:44 -0000	1.2
@@ -56,8 +56,8 @@
 
 #include "write_png.h"
 
-#define WIDTH 60
-#define HEIGHT 60
+#define WIDTH 100
+#define HEIGHT 70
 #define STRIDE (WIDTH * 4)
 
 char image[STRIDE*HEIGHT];
@@ -121,19 +121,68 @@
 }
 
 static void
+bevel_circle (cairo_t *cr, int x, int y, int width)
+{
+    double radius = (width-1)/2.0 - 0.5;
+
+    cairo_save (cr);
+
+    cairo_set_line_width (cr, 1);
+
+    /* Highlight */
+    set_hex_color (cr, HI_COLOR_1);
+    cairo_arc (cr, x+radius+1.5, y+radius+1.5, radius,
+	       0, 2* M_PI);
+    cairo_close_path (cr);
+    cairo_stroke (cr);
+
+    /* Lowlight */
+    set_hex_color (cr, LO_COLOR_1);
+    cairo_arc (cr, x+radius+0.5, y+radius+0.5, radius,
+	       0, 2 * M_PI);
+    cairo_stroke (cr);
+
+    cairo_restore (cr);
+}
+
+/* Slightly smaller than specified to match interior size of bevel_box */
+static void
 flat_box (cairo_t *cr, int x, int y, int width, int height)
 {
     cairo_save (cr);
 
     /* Fill background */
     set_hex_color (cr, HI_COLOR_1);
-    cairo_rectangle (cr, x, y, width, height);
+    cairo_rectangle (cr, x+1, y+1, width-2, height-2);
     cairo_fill (cr);
 
     /* Stroke outline */
     cairo_set_line_width (cr, 1.0);
     set_hex_color (cr, BLACK);
-    cairo_rectangle (cr, x + 0.5, y + 0.5, width - 1, height - 1);
+    cairo_rectangle (cr, x + 1.5, y + 1.5, width - 3, height - 3);
+    cairo_stroke (cr);
+
+    cairo_restore (cr);
+}
+
+static void
+flat_circle (cairo_t *cr, int x, int y, int width)
+{
+    cairo_save (cr);
+
+    double radius = (width - 1) / 2.0;
+
+    /* Fill background */
+    set_hex_color (cr, HI_COLOR_1);
+    cairo_arc (cr, x+radius+0.5, y+radius+0.5, radius-1,
+	       0, 2 * M_PI);
+    cairo_fill (cr);
+
+    /* Fill background */
+    cairo_set_line_width (cr, 1.0);
+    set_hex_color (cr, BLACK);
+    cairo_arc (cr, x+radius+0.5, y+radius+0.5, radius-1,
+	       0, 2 * M_PI);
     cairo_stroke (cr);
 
     cairo_restore (cr);
@@ -186,18 +235,45 @@
     cairo_restore (cr);
 }
 
+#define RADIO_SIZE CHECK_BOX_SIZE
+#define RADIO_DOT_COLOR BLACK
+static void
+radio_button (cairo_t *cr, int x, int y, checked_status_t checked)
+{
+
+    cairo_save (cr);
+
+    bevel_circle (cr, x, y, RADIO_SIZE);
+
+    if (checked) {
+	set_hex_color (cr, RADIO_DOT_COLOR);
+	cairo_arc (cr,
+		   x + (RADIO_SIZE-1) / 2.0,
+		   y + (RADIO_SIZE-1) / 2.0,
+		   (RADIO_SIZE-1) / 2.0 - 3,
+		   0, 2 * M_PI);
+	cairo_fill (cr);
+    }
+
+    cairo_restore (cr);
+}
+
 static void
 draw_bevels (cairo_t *cr, int width, int height)
 {
-    int check_room = (width - 20) / 2;
+    int check_room = (width - 20) / 3;
     int check_pad = (check_room - CHECK_BOX_SIZE) / 2;
 
     groovy_box (cr, 5, 5, width - 10, height - 10);
 
-    check_box (cr, 10 + check_pad, 10 + check_pad, UNCHECKED);
-    check_box (cr, 10 + check_pad, 10 + check_room + check_pad, CHECKED);
-    flat_box (cr, 10 + check_room + check_pad + 1, 10 + check_pad + 1,
-	      CHECK_BOX_SIZE-2, CHECK_BOX_SIZE-2);
+    check_box (cr, 10+check_pad, 10+check_pad, UNCHECKED);
+    check_box (cr, check_room+10+check_pad, 10+check_pad, CHECKED);
+    flat_box (cr, 2 * check_room+10+check_pad, 10+check_pad,
+	      CHECK_BOX_SIZE, CHECK_BOX_SIZE);
+
+    radio_button (cr, 10+check_pad, check_room+10+check_pad, UNCHECKED);
+    radio_button (cr, check_room+10+check_pad, check_room+10+check_pad, CHECKED);
+    flat_circle (cr, 2 * check_room+10+check_pad, check_room+10+check_pad, CHECK_BOX_SIZE);
 }
 
 int




More information about the cairo-commit mailing list