From 4cdd7331a69e2f714b440644bd36334031cfbccc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 13 Dec 2011 21:35:54 +0000 Subject: Make items responsible for drawing their own children. git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@3868 a436a847-0d15-0410-975c-d299462d15a1 --- src/module.c | 21 +++++++++++++++++++++ src/node.c | 6 ++---- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/module.c b/src/module.c index a6fe461..d3ae675 100644 --- a/src/module.c +++ b/src/module.c @@ -525,6 +525,26 @@ ganv_module_update(GanvItem* item, int flags) item_class->update(item, flags); } +static void +ganv_module_draw(GanvItem* item, + cairo_t* cr, + int cx, int cy, + int width, int height) +{ + GanvModule* module = GANV_MODULE(item); + + // Draw box and label + if (GANV_ITEM_CLASS(parent_class)->draw) { + (*GANV_ITEM_CLASS(parent_class)->draw)(item, cr, cx, cy, width, height); + } + + // Draw ports + FOREACH_PORT(module->impl->ports, p) { + GANV_ITEM_GET_CLASS(GANV_ITEM(*p))->draw( + GANV_ITEM(*p), cr, cx, cy, width, height); + } +} + static void ganv_module_move_to(GanvNode* node, double x, @@ -567,6 +587,7 @@ ganv_module_class_init(GanvModuleClass* class) object_class->destroy = ganv_module_destroy; item_class->update = ganv_module_update; + item_class->draw = ganv_module_draw; node_class->move = ganv_module_move; node_class->move_to = ganv_module_move_to; diff --git a/src/node.c b/src/node.c index 96bc039..489293d 100644 --- a/src/node.c +++ b/src/node.c @@ -108,11 +108,9 @@ ganv_node_draw(GanvItem* item, int cx, int cy, int width, int height) { - if (GANV_ITEM_CLASS(parent_class)->draw) { - (*GANV_ITEM_CLASS(parent_class)->draw)(item, cr, cx, cy, width, height); - } - GanvNode* node = GANV_NODE(item); + + // Draw label if (node->impl->label) { GanvItem* label_item = GANV_ITEM(node->impl->label); GANV_ITEM_GET_CLASS(label_item)->draw(label_item, cr, cx, cy, width, height); -- cgit v1.2.1