[monet/monet-xml] Add support for rounded corners on rectangles
- From: Thomas Wood <thos src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [monet/monet-xml] Add support for rounded corners on rectangles
- Date: Sun, 9 May 2010 17:34:51 +0000 (UTC)
commit 4ab5d5f44796c4554a7a8981b68e64f6729a1b91
Author: Thomas Wood <thomas wood intel com>
Date: Wed May 5 12:08:34 2010 +0100
Add support for rounded corners on rectangles
monet-gtk/monet.xml | 4 ++--
monet/mn-config.c | 2 ++
monet/mn-config.h | 2 ++
monet/mn-style.c | 20 +++++++++++++++++++-
4 files changed, 25 insertions(+), 3 deletions(-)
---
diff --git a/monet-gtk/monet.xml b/monet-gtk/monet.xml
index 6982d1e..b439aa5 100644
--- a/monet-gtk/monet.xml
+++ b/monet-gtk/monet.xml
@@ -1,12 +1,12 @@
<monet>
<widget type="button">
- <rect x="0.5" y="0.5" width="-1" height="-1" stroke-width="1" stroke="#988c7c">
+ <rect x="0.5" y="0.5" 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"></rect>
+ <rect x="1.5" y="1.5" width="-3" height="-3" stroke-width="1" stroke="#fff" corner-radius="3"></rect>
</widget>
<widget type="entry">
diff --git a/monet/mn-config.c b/monet/mn-config.c
index 0167077..12ab5ea 100644
--- a/monet/mn-config.c
+++ b/monet/mn-config.c
@@ -153,6 +153,8 @@ widget_start_element (GMarkupParseContext *context,
((MnDrawingOp*) op)->stroke_width = g_ascii_strtod (attribute_values[i], NULL);
else if (!strcmp (*attr_n, "fill"))
((MnDrawingOp*)op)->fill = cairo_pattern_from_paint (attribute_values[i]);
+ else if (!strcmp (*attr_n, "corner-radius"))
+ op->radius = g_ascii_strtod (attribute_values[i], NULL);
}
*ops = g_slist_append (*ops, op);
diff --git a/monet/mn-config.h b/monet/mn-config.h
index 008a9b8..1f606b1 100644
--- a/monet/mn-config.h
+++ b/monet/mn-config.h
@@ -57,6 +57,8 @@ typedef struct
double y;
double width;
double height;
+
+ double radius;
} MnRectangleOp;
typedef struct
diff --git a/monet/mn-style.c b/monet/mn-style.c
index ade90aa..b6ffdbe 100644
--- a/monet/mn-style.c
+++ b/monet/mn-style.c
@@ -166,7 +166,25 @@ mn_style_draw_ops (MnStyle *style,
else
h = rect->height;
- cairo_rectangle (cr, rect->x, rect->y, w, h);
+ if (rect->radius == 0)
+ cairo_rectangle (cr, rect->x, rect->y, w, h);
+ else
+ {
+ /* switch to co-ordinate space */
+ w--; h--;
+
+ cairo_arc (cr, rect->x + rect->radius, rect->y + rect->radius,
+ 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,
+ rect->radius, M_PI * 0.5, M_PI);
+ cairo_line_to (cr, rect->x, rect->y + rect->radius);
+ }
break;
case MN_CIRCLE:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]