Fix the color widget's cairo arc draw calls
authorPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 10 Feb 2011 16:11:37 +0000 (17:11 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 10 Feb 2011 16:13:24 +0000 (17:13 +0100)
src/led-color-widgets.vala

index 7fc0770..ab7d4e7 100644 (file)
@@ -42,43 +42,49 @@ class LedColorWidget : Gtk.DrawingArea {
                var ctx = Gdk.cairo_create (window);
                int height = allocation.height;
                int width = allocation.width;
-               double radius = Math.fmin (width * 0.4, height * 0.4);
+               double radius = int.min (width, height) * 0.4;
 
                ctx.rectangle (event.area.x, event.area.y, event.area.width, event.area.height);
                ctx.clip ();
 
                ctx.new_path ();
-               ctx.arc (width / 2.0, height / 2.0, Math.fmin (width, height) / 2.0, 0, 2 * Math.PI);
-
+               ctx.translate (width / 2.0, height / 2.0);
+               ctx.arc (0, 0, radius * 1.25, 0, 2 * Math.PI);
                ctx.clip ();
 
                ctx.set_operator (Cairo.Operator.ADD);
 
                if (LedColor.R in color) {
+                       ctx.save ();
                        ctx.set_source_rgb (1.0, 0, 0);
                        ctx.new_path ();
-                       ctx.arc (width / 2.0 + radius / 3.2 * Math.cos (270 * Math.PI / 180.0),
-                                height / 2.0 + radius / 3.2 * Math.sin (270 * Math.PI / 180.0),
-                                radius, 0, 2 * Math.PI);
+                       ctx.translate (radius / 3.2 * Math.cos (270 * Math.PI / 180.0),
+                                      radius / 3.2 * Math.sin (270 * Math.PI / 180.0));
+                       ctx.arc (0, 0, radius, 0, 2 * Math.PI);
                        ctx.fill ();
+                       ctx.restore ();
                }
 
                if (LedColor.G in color) {
+                       ctx.save ();
                        ctx.set_source_rgb (0, 1.0, 0);
                        ctx.new_path ();
-                       ctx.arc (width / 2.0 + radius / 3.2 * Math.cos (150 * Math.PI / 180.0),
-                                height / 2.0 + radius / 3.2 * Math.sin (150 * Math.PI / 180.0),
-                                radius, 0, 2 * Math.PI);
+                       ctx.translate (radius / 3.2 * Math.cos (150 * Math.PI / 180.0),
+                                      radius / 3.2 * Math.sin (150 * Math.PI / 180.0));
+                       ctx.arc (0, 0, radius, 0, 2 * Math.PI);
                        ctx.fill ();
+                       ctx.restore ();
                }
 
                if (LedColor.B in color) {
+                       ctx.save ();
                        ctx.set_source_rgb (0, 0, 1.0);
                        ctx.new_path ();
-                       ctx.arc (width / 2.0 + radius / 3.2 * Math.cos (30 * Math.PI / 180.0),
-                                height / 2.0 + radius / 3.2 * Math.sin (30 * Math.PI / 180.0),
-                                radius, 0, 2 * Math.PI);
+                       ctx.translate (radius / 3.2 * Math.cos (30 * Math.PI / 180.0),
+                                      radius / 3.2 * Math.sin (30 * Math.PI / 180.0));
+                       ctx.arc (0, 0, radius, 0, 2 * Math.PI);
                        ctx.fill ();
+                       ctx.restore ();
                }
 
                return true;