summaryrefslogtreecommitdiffstats
path: root/src/circle.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-01-12 00:07:26 +0000
committerDavid Robillard <d@drobilla.net>2013-01-12 00:07:26 +0000
commit3d9771152b9fd27bea66cbba3af2fbbb79ccf68e (patch)
tree481bcd81215a77e1a76bea2a2c2dd4b9d97b8b8a /src/circle.c
parente4831db229641ee88ad8a2c1e0d82d7d3442e96b (diff)
downloadganv-3d9771152b9fd27bea66cbba3af2fbbb79ccf68e.tar.gz
ganv-3d9771152b9fd27bea66cbba3af2fbbb79ccf68e.tar.bz2
ganv-3d9771152b9fd27bea66cbba3af2fbbb79ccf68e.zip
Fix text on circles.
git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@4926 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/circle.c')
-rw-r--r--src/circle.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/circle.c b/src/circle.c
index 1d1e032..11c389f 100644
--- a/src/circle.c
+++ b/src/circle.c
@@ -94,6 +94,28 @@ ganv_circle_get_property(GObject* object,
}
}
+static void
+ganv_circle_resize(GanvNode* self)
+{
+ GanvNode* node = GANV_NODE(self);
+
+ if (node->impl->label) {
+ if (node->impl->label->impl->needs_layout) {
+ ganv_text_layout(node->impl->label);
+ }
+
+ // Center label
+ ganv_item_set(GANV_ITEM(node->impl->label),
+ "x", node->impl->label->impl->coords.width / -2.0,
+ "y", node->impl->label->impl->coords.height / -2.0,
+ NULL);
+ }
+
+ if (parent_class->resize) {
+ parent_class->resize(self);
+ }
+}
+
static gboolean
ganv_circle_is_within(const GanvNode* self,
double x1,
@@ -249,6 +271,7 @@ ganv_circle_draw(GanvItem* item,
int x, int y,
int width, int height)
{
+ GanvNode* node = GANV_NODE(item);
GanvCircle* circle = GANV_CIRCLE(item);
GanvCircleImpl* impl = circle->impl;
@@ -281,6 +304,16 @@ ganv_circle_draw(GanvItem* item,
cairo_set_dash(cr, &dash_length, 1, circle->node.impl->dash_offset);
}
cairo_stroke(cr);
+
+ // Draw label
+ if (node->impl->label) {
+ GanvItem* label_item = GANV_ITEM(node->impl->label);
+
+ if (label_item->object.flags & GANV_ITEM_VISIBLE) {
+ GANV_ITEM_GET_CLASS(label_item)->draw(
+ label_item, cr, cx, cy, width, height);
+ }
+ }
}
static double
@@ -333,6 +366,7 @@ ganv_circle_class_init(GanvCircleClass* klass)
object_class->destroy = ganv_circle_destroy;
+ node_class->resize = ganv_circle_resize;
node_class->is_within = ganv_circle_is_within;
node_class->tail_vector = ganv_circle_tail_vector;
node_class->head_vector = ganv_circle_head_vector;
@@ -342,3 +376,18 @@ ganv_circle_class_init(GanvCircleClass* klass)
item_class->point = ganv_circle_point;
item_class->draw = ganv_circle_draw;
}
+
+GanvCircle*
+ganv_circle_new(GanvCanvas* canvas,
+ const char* first_property_name, ...)
+{
+ GanvCircle* circle = GANV_CIRCLE(
+ g_object_new(ganv_circle_get_type(), "canvas", canvas, NULL));
+
+ va_list args;
+ va_start(args, first_property_name);
+ g_object_set_valist(G_OBJECT(circle), first_property_name, args);
+ va_end(args);
+
+ return circle;
+}