summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/circle.c49
-rw-r--r--src/ganv_test.c9
-rw-r--r--src/port.c1
-rw-r--r--src/text.c4
4 files changed, 63 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;
+}
diff --git a/src/ganv_test.c b/src/ganv_test.c
index 97de437..31359e2 100644
--- a/src/ganv_test.c
+++ b/src/ganv_test.c
@@ -56,6 +56,15 @@ main(int argc, char** argv)
GanvCanvas* canvas = ganv_canvas_new(1024, 768);
gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(canvas));
+ GanvCircle* circle = ganv_circle_new(canvas,
+ "x", 400.0,
+ "y", 400.0,
+ "draggable", TRUE,
+ "label", "state",
+ "radius", 32.0,
+ NULL);
+ ganv_item_show(GANV_ITEM(circle));
+
GanvModule* module = ganv_module_new(canvas,
"x", 10.0,
"y", 10.0,
diff --git a/src/port.c b/src/port.c
index e134e55..3b9ba69 100644
--- a/src/port.c
+++ b/src/port.c
@@ -124,6 +124,7 @@ ganv_port_draw(GanvItem* item,
{
GanvPort* port = GANV_PORT(item);
+ // Draw Box
GanvItemClass* item_class = GANV_ITEM_CLASS(parent_class);
item_class->draw(item, cr, cx, cy, width, height);
diff --git a/src/text.c b/src/text.c
index ca9a126..d5779c4 100644
--- a/src/text.c
+++ b/src/text.c
@@ -301,6 +301,10 @@ ganv_text_draw(GanvItem* item,
double wy = impl->coords.y;
ganv_item_i2w(item, &wx, &wy);
+ if (impl->needs_layout) {
+ ganv_text_layout(text);
+ }
+
// Round to the nearest pixel so text isn't blurry
wx = lrint(wx);
wy = lrint(wy);