summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Canvas.cpp2
-rw-r--r--src/box.c17
-rw-r--r--src/module.c38
-rw-r--r--src/port.c18
4 files changed, 61 insertions, 14 deletions
diff --git a/src/Canvas.cpp b/src/Canvas.cpp
index 4f081fa..768cecb 100644
--- a/src/Canvas.cpp
+++ b/src/Canvas.cpp
@@ -1080,7 +1080,7 @@ GanvCanvasImpl::port_event(GdkEvent* event, GanvPort* port)
static double control_start_y = 0;
static float control_start_value = 0;
-switch (event->type) {
+ switch (event->type) {
case GDK_BUTTON_PRESS:
if (event->button.button == 1) {
GanvModule* const module = ganv_port_get_module(port);
diff --git a/src/box.c b/src/box.c
index 2390c9d..194a126 100644
--- a/src/box.c
+++ b/src/box.c
@@ -299,26 +299,19 @@ ganv_box_point(GanvItem* item,
// Point is inside the box (distance 0)
if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) {
- GanvItemClass* item_class = GANV_ITEM_CLASS(parent_class);
- double d = item_class->point(item, x, y, cx, cy, actual_item);
- if (*actual_item) {
- return d;
- } else {
- *actual_item = item;
- return 0.0;
- }
+ *actual_item = item;
+ return 0.0;
}
// Point is outside the box
- double dx, dy;
+ double dx = 0.0;
+ double dy = 0.0;
// Find horizontal distance to nearest edge
if (x < x1) {
dx = x1 - x;
} else if (x > x2) {
dx = x - x2;
- } else {
- dx = 0.0;
}
// Find vertical distance to nearest edge
@@ -326,8 +319,6 @@ ganv_box_point(GanvItem* item,
dy = y1 - y;
} else if (y > y2) {
dy = y - y2;
- } else {
- dy = 0.0;
}
return sqrt((dx * dx) + (dy * dy));
diff --git a/src/module.c b/src/module.c
index d3ae675..3bfd378 100644
--- a/src/module.c
+++ b/src/module.c
@@ -569,6 +569,43 @@ ganv_module_move(GanvNode* node,
}
}
+static double
+ganv_module_point(GanvItem* item,
+ double x, double y,
+ int cx, int cy,
+ GanvItem** actual_item)
+{
+ GanvModule* module = GANV_MODULE(item);
+
+ double d = GANV_ITEM_CLASS(parent_class)->point(
+ item, x, y, cx, cy, actual_item);
+
+ if (!*actual_item) {
+ // Point is not inside module at all, no point in checking children
+ return d;
+ }
+
+ FOREACH_PORT(module->impl->ports, p) {
+ GanvItem* const port = GANV_ITEM(*p);
+
+ *actual_item = NULL;
+ d = GANV_ITEM_GET_CLASS(port)->point(
+ port,
+ x - port->x, y - port->y,
+ cx, cy,
+ actual_item);
+
+ if (*actual_item) {
+ // Point is inside a port
+ return d;
+ }
+ }
+
+ // Point is inside module, but not a child port
+ *actual_item = item;
+ return 0.0;
+}
+
static void
ganv_module_class_init(GanvModuleClass* class)
{
@@ -588,6 +625,7 @@ ganv_module_class_init(GanvModuleClass* class)
item_class->update = ganv_module_update;
item_class->draw = ganv_module_draw;
+ item_class->point = ganv_module_point;
node_class->move = ganv_module_move;
node_class->move_to = ganv_module_move_to;
diff --git a/src/port.c b/src/port.c
index da750aa..674be73 100644
--- a/src/port.c
+++ b/src/port.c
@@ -111,6 +111,23 @@ ganv_port_get_property(GObject* object,
}
static void
+ganv_port_draw(GanvItem* item,
+ cairo_t* cr,
+ int cx, int cy,
+ int width, int height)
+{
+ GanvPort* port = GANV_PORT(item);
+
+ GanvItemClass* item_class = GANV_ITEM_CLASS(parent_class);
+ item_class->draw(item, cr, cx, cy, width, height);
+
+ if (port->impl->control) {
+ GanvItem* const rect = GANV_ITEM(port->impl->control->rect);
+ GANV_ITEM_GET_CLASS(rect)->draw(rect, cr, cx, cy, width, height);
+ }
+}
+
+static void
ganv_port_tail_vector(const GanvNode* self,
const GanvNode* head,
double* x,
@@ -238,6 +255,7 @@ ganv_port_class_init(GanvPortClass* class)
object_class->destroy = ganv_port_destroy;
item_class->event = event;
+ item_class->draw = ganv_port_draw;
node_class->tail_vector = ganv_port_tail_vector;
node_class->head_vector = ganv_port_head_vector;