summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-04-22 04:31:38 +0000
committerDavid Robillard <d@drobilla.net>2012-04-22 04:31:38 +0000
commit6dcf465e422f5b3c96c06b98f870bf86222fcac9 (patch)
tree352817cc71b3431b9d5409b796b7704677108726 /src
parent550044fd2f09d8b1345564ab88e5156e1e5cafc7 (diff)
downloadganv-6dcf465e422f5b3c96c06b98f870bf86222fcac9.tar.gz
ganv-6dcf465e422f5b3c96c06b98f870bf86222fcac9.tar.bz2
ganv-6dcf465e422f5b3c96c06b98f870bf86222fcac9.zip
Fix wonky port sizes when restoring a patch.
git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@4230 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/module.c65
-rw-r--r--src/port.c32
2 files changed, 37 insertions, 60 deletions
diff --git a/src/module.c b/src/module.c
index 6cfcde9..4b319bc 100644
--- a/src/module.c
+++ b/src/module.c
@@ -333,8 +333,8 @@ resize_horiz(GanvModule* module)
if (p->impl->is_input) {
y = header_height + 2.0 + (i * (h + 2.0));
++i;
- ganv_box_set_width(pbox, m.input_width);
ganv_node_move_to(pnode, 0.0, y);
+ ganv_box_set_width(pbox, m.input_width);
last_was_input = TRUE;
ganv_canvas_for_each_edge_to(
@@ -344,10 +344,8 @@ resize_horiz(GanvModule* module)
y = header_height + 2.0 + (i * (h + 2.0));
++i;
}
+ ganv_node_move_to(pnode, m.width - m.output_width, y);
ganv_box_set_width(pbox, m.output_width);
- ganv_node_move_to(pnode,
- m.width - ganv_box_get_width(pbox),
- y);
last_was_input = FALSE;
ganv_canvas_for_each_edge_from(
@@ -511,7 +509,8 @@ static void
ganv_module_add_port(GanvModule* module,
GanvPort* port)
{
- GanvModuleImpl* impl = module->impl;
+ GanvCanvas* canvas = GANV_CANVAS(GANV_ITEM(module)->canvas);
+ GanvModuleImpl* impl = module->impl;
const double width = ganv_port_get_natural_width(port);
if (port->impl->is_input && width > impl->widest_input) {
@@ -522,56 +521,48 @@ ganv_module_add_port(GanvModule* module,
impl->must_resize = TRUE;
}
-#if 0
-
double port_x, port_y;
// Place vertically
- if (canvas()->direction() == Canvas::HORIZONTAL) {
- if (gobj()->ports->len != 0) {
- const Port* const last_port = *back();
- port_y = last_port->get_y() + last_port->get_height() + 1;
+ if (canvas->direction == GANV_DIRECTION_RIGHT) {
+ if (impl->ports->len != 0) {
+ const GanvPort* const last_port = g_ptr_array_index(
+ impl->ports, impl->ports->len - 1);
+ port_y = ganv_box_get_y2(GANV_BOX(last_port)) + 2.0;
} else {
- port_y = 2.0 + title_height();
+ double title_w, title_h;
+ title_size(module, &title_w, &title_h);
+ port_y = title_h + 2.0;
}
} else {
- if (p->is_input()) {
+ if (port->impl->is_input) {
port_y = 0.0;
} else {
- port_y = get_height() - get_empty_port_depth();
+ port_y = ganv_box_get_height(GANV_BOX(module))
+ - ganv_module_get_empty_port_depth(module);
}
}
// Place horizontally
Metrics m;
- calculate_metrics(m);
+ measure(module, &m);
- set_width(m.width);
- if (p->is_input()) {
- p->set_width(m.input_width);
- port_x = 0;
+ ganv_box_set_width(GANV_BOX(module), m.width);
+ if (port->impl->is_input) {
+ port_x = 0.0;
+ ganv_node_move_to(GANV_NODE(port), port_x, port_y);
+ ganv_box_set_width(GANV_BOX(port), m.input_width);
} else {
- p->set_width(m.output_width);
- port_x = m.width - p->get_width();
+ port_x = m.width - m.output_width;
+ ganv_node_move_to(GANV_NODE(port), port_x, port_y);
+ ganv_box_set_width(GANV_BOX(port), m.output_width);
}
- p->move_to(port_x, port_y);
-
- g_ptr_array_add(gobj()->ports, p->gobj());
- if (canvas()->direction() == Canvas::HORIZONTAL) {
- set_height(p->get_y() + p->get_height() + 1);
- }
-
- place_title();
-#endif
- impl->must_resize = TRUE;
-
g_ptr_array_add(impl->ports, port);
- //if (canvas()->direction() == Canvas::HORIZONTAL) {
- // set_height(p->get_y() + p->get_height() + 1);
- //}
-
- GanvCanvas* canvas = GANV_CANVAS(GANV_ITEM(module)->canvas);
+ if (canvas->direction == GANV_DIRECTION_RIGHT) {
+ ganv_box_set_height(GANV_BOX(module),
+ ganv_box_get_y2(GANV_BOX(port)) + 1.0);
+ }
place_title(module, canvas->direction);
ganv_item_request_update(GANV_ITEM(module));
diff --git a/src/port.c b/src/port.c
index 45376e2..f377b79 100644
--- a/src/port.c
+++ b/src/port.c
@@ -195,8 +195,10 @@ ganv_port_resize(GanvNode* self)
"height", &label_h,
NULL);
- ganv_box_set_width(&port->box, label_w + (PORT_LABEL_HPAD * 2.0));
- ganv_box_set_height(&port->box, label_h + (PORT_LABEL_VPAD * 2.0));
+ ganv_box_set_width(&port->box, MAX(ganv_box_get_width(&port->box),
+ label_w + (PORT_LABEL_HPAD * 2.0)));
+ ganv_box_set_height(&port->box, MAX(ganv_box_get_height(&port->box),
+ label_h + (PORT_LABEL_VPAD * 2.0)));
ganv_item_set(GANV_ITEM(node->impl->label),
"x", PORT_LABEL_HPAD,
@@ -319,19 +321,6 @@ ganv_port_new(GanvModule* module,
node->impl->draggable = FALSE;
node->impl->border_width = 1.0;
- GanvCanvas* canvas = GANV_CANVAS(item->canvas);
- if (!node->impl->label) {
- const double depth = ganv_module_get_empty_port_depth(module);
- const double breadth = ganv_module_get_empty_port_breadth(module);
- if (canvas->direction == GANV_DIRECTION_RIGHT) {
- ganv_box_set_width(box, depth);
- ganv_box_set_height(box, breadth);
- } else {
- ganv_box_set_width(box, breadth);
- ganv_box_set_height(box, depth);
- }
- }
-
return port;
}
@@ -458,18 +447,15 @@ ganv_port_set_control_max(GanvPort* port,
double
ganv_port_get_natural_width(const GanvPort* port)
{
- /*
- Canvas* const canvas = _module->canvas();
- if (canvas->direction() == Canvas::VERTICAL) {
- return _module->empty_port_breadth();
- } else*/
- if (port->box.node.impl->label) {
+ GanvCanvas* const canvas = GANV_CANVAS(GANV_ITEM(port)->canvas);
+ if (canvas->direction == GANV_DIRECTION_DOWN) {
+ return ganv_module_get_empty_port_breadth(ganv_port_get_module(port));
+ } else if (port->box.node.impl->label) {
double label_w;
g_object_get(port->box.node.impl->label, "width", &label_w, NULL);
return label_w + (PORT_LABEL_HPAD * 2.0);
} else {
- //return _module->empty_port_depth();
- return 4.0;
+ return ganv_module_get_empty_port_depth(ganv_port_get_module(port));
}
}