[monet/monet-xml] mn-style: draw rectangles using an inner stroke



commit e0a248859b0b6c97f79cbde422dffbefc15925c0
Author: Thomas Wood <thomas wood intel com>
Date:   Sun Jun 13 15:12:31 2010 +0100

    mn-style: draw rectangles using an inner stroke

 monet-gtk/monet.xml |   22 +++++++++++-----------
 monet/mn-style.c    |   32 ++++++++++++++++++++++----------
 2 files changed, 33 insertions(+), 21 deletions(-)
---
diff --git a/monet-gtk/monet.xml b/monet-gtk/monet.xml
index 2f57df9..0e6caaf 100644
--- a/monet-gtk/monet.xml
+++ b/monet-gtk/monet.xml
@@ -1,40 +1,40 @@
 <monet>
 <widget type="button">
-  <rect x="0.5" y="0.5" width="-1" height="-1" stroke-width="1" stroke="#988c7c" corner-radius="4">
+  <rect x="0" y="0" width="-1" height="-1" stroke-width="1" stroke="#988c7c" corner-radius="4">
     <gradient x1="0" y1="0" x2="0" y1="50">
       <stop color="#fcfbfa" position="1"/>
       <stop color="#e7e2da" position="0"/>
     </gradient>
   </rect>
-  <rect x="1.5" y="1.5" width="-3" height="-3" stroke-width="1" stroke="#fff" corner-radius="3"></rect>
+  <rect x="1" y="1" width="-3" height="-3" stroke-width="1" stroke="#fff" corner-radius="3"></rect>
 </widget>
 
 <widget type="button" state="active">
-  <rect x="0.5" y="0.5" width="-1" height="-1" stroke-width="1" stroke="#988c7c" corner-radius="4">
+  <rect x="0" y="0" width="-1" height="-1" stroke-width="1" stroke="#988c7c" corner-radius="4">
     <gradient x1="0" y1="0" x2="0" y1="50">
       <stop color="#fcfbfa" position="0"/>
       <stop color="#e7e2da" position="1"/>
     </gradient>
   </rect>
-  <rect x="1.5" y="1.5" width="-3" height="-3" stroke-width="1" stroke="#fff" corner-radius="3"></rect>
+  <rect x="1" y="1" width="-3" height="-3" stroke-width="1" stroke="#fff" corner-radius="3"></rect>
 </widget>
 
 <widget type="entry">
-  <line x1="0.5" y1="0.5" y2="-0.5" x1="0.5" stroke="#999" stroke-width="1"/>
-  <line x1="0.5" y1="0.5" y2="0.5" x1="-0.5" stroke="#999" stroke-width="1"/>
+  <line x1="0" y1="0" y2="-1" x1="0" stroke="#999" stroke-width="1"/>
+  <line x1="0" y1="0" y2="0" x1="-1" stroke="#999" stroke-width="1"/>
 
-  <line x1="-0.5" y1="0.5" y2="-0.5" x1="-0.5" stroke="#fff" stroke-width="1"/>
-  <line x1="-0.5" y1="-0.5" y2="-0.5" x1="0.5" stroke="#fff" stroke-width="1"/>
+  <line x1="-1" y1="0" y2="-1" x1="-1" stroke="#fff" stroke-width="1"/>
+  <line x1="-1" y1="-1" y2="-1" x1="0" stroke="#fff" stroke-width="1"/>
 
-  <rect x="1.5" y="1.5" width="-3" height="-3" stroke="#ccc" stroke-width="1"/>
+  <rect x="1" y="1" width="-3" height="-3" stroke="#ccc" stroke-width="1"/>
 </widget>
 
 <widget type="radio">
-  <circle cx="5.5" cy="5.5" r="5" stroke="#000" stroke-width="1"/>
+  <circle cx="5" cy="5" r="5" stroke="#000" stroke-width="1"/>
 </widget>
 
 <widget type="check">
-  <rect x="0.5" y="0.5" width="-2" height="-2" stroke="#000" stroke-width="1"/>
+  <rect x="0" y="0" width="-2" height="-2" stroke="#000" stroke-width="1"/>
 </widget>
 
 </monet>
diff --git a/monet/mn-style.c b/monet/mn-style.c
index be1f7b3..019a7cc 100644
--- a/monet/mn-style.c
+++ b/monet/mn-style.c
@@ -164,6 +164,7 @@ mn_style_draw_ops (MnStyle   *style,
       MnLineOp *line;
       gdouble w, h;
       gdouble x_1, y_1, x_2, y_2;
+      gdouble offset;
 
       /* set generic options */
       cairo_set_line_width (cr, op->stroke_width);
@@ -173,6 +174,8 @@ mn_style_draw_ops (MnStyle   *style,
         case MN_RECT:
           rect = (MnRectangleOp *) o->data;
 
+          offset = op->stroke_width / 2;
+
           if (rect->width <= 0)
             w = width + rect->width;
           else
@@ -184,23 +187,32 @@ mn_style_draw_ops (MnStyle   *style,
             h = rect->height;
 
           if (rect->radius == 0)
-            cairo_rectangle (cr, rect->x, rect->y, w, h);
+            cairo_rectangle (cr, rect->x + offset, rect->y + offset,
+                             w - offset * 2, h - offset * 2);
           else
             {
               /* switch to co-ordinate space */
               w--; h--;
 
-              cairo_arc (cr, rect->x + rect->radius, rect->y + rect->radius,
+              cairo_arc (cr,
+                         rect->x + rect->radius + offset,
+                         rect->y + rect->radius + offset,
                          rect->radius, M_PI, M_PI * 1.5);
-              cairo_arc (cr, rect->x + w - rect->radius,
-                         rect->y + rect->radius, rect->radius, M_PI * 1.5, 0);
-              cairo_arc (cr, rect->x + w - rect->radius,
-                         rect->y + h - rect->radius, rect->radius,
-                         0, M_PI * 0.5);
-              cairo_arc (cr, rect->x + rect->radius,
-                         rect->y + h - rect->radius,
+              cairo_arc (cr,
+                         rect->x + w - rect->radius - offset,
+                         rect->y + rect->radius + offset,
+                         rect->radius, M_PI * 1.5, 0);
+              cairo_arc (cr,
+                         rect->x + w - rect->radius - offset,
+                         rect->y + h - rect->radius - offset,
+                         rect->radius, 0, M_PI * 0.5);
+              cairo_arc (cr,
+                         rect->x + rect->radius + offset,
+                         rect->y + h - rect->radius - offset,
                          rect->radius, M_PI * 0.5, M_PI);
-              cairo_line_to (cr, rect->x, rect->y + rect->radius);
+              cairo_line_to (cr,
+                             rect->x + offset,
+                             rect->y + rect->radius + offset);
             }
           break;
 



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