diff options
-rw-r--r-- | ganv/canvas-base.h | 6 | ||||
-rw-r--r-- | src/Canvas.cpp | 8 | ||||
-rw-r--r-- | src/canvas-base.c | 20 |
3 files changed, 32 insertions, 2 deletions
diff --git a/ganv/canvas-base.h b/ganv/canvas-base.h index 3b7477c..caef50d 100644 --- a/ganv/canvas-base.h +++ b/ganv/canvas-base.h @@ -205,10 +205,14 @@ int ganv_item_grab(GanvItem* item, unsigned int event_mask, */ void ganv_item_ungrab(GanvItem* item, guint32 etime); -/* Convert from item coordinate to world coordinates. +/* Convert from item coordinates to world coordinates. */ void ganv_item_i2w(GanvItem* item, double* x, double* y); +/* Convert from world coordinates to item coordinates. + */ +void ganv_item_w2i(GanvItem* item, double* x, double* y); + /* Used to send all of the keystroke events to a specific item as well as * GDK_FOCUS_CHANGE events. */ diff --git a/src/Canvas.cpp b/src/Canvas.cpp index c70aaf3..ca28025 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -1408,7 +1408,13 @@ GanvCanvasImpl::port_event(GdkEvent* event, GanvPort* port) case GDK_BUTTON_PRESS: if (event->button.button == 1) { GanvModule* const module = ganv_port_get_module(port); - if (module && port->impl->is_input && port->impl->control) { + double port_x = event->button.x; + double port_y = event->button.y; + ganv_item_w2i(GANV_ITEM(port), &port_x, &port_y); + + if (module && port->impl->control && + (port->impl->is_input || + port_x < ganv_box_get_width(GANV_BOX(port)) / 2.0)) { if (port->impl->control->is_toggle) { if (port->impl->control->value >= 0.5) { ganv_port_set_control_value_internal(port, 0.0); diff --git a/src/canvas-base.c b/src/canvas-base.c index afd81b6..8d8b8d1 100644 --- a/src/canvas-base.c +++ b/src/canvas-base.c @@ -599,6 +599,26 @@ ganv_item_i2w_pair(GanvItem* item, double* x1, double* y1, double* x2, double* y *y2 += off_y; } +/** + * ganv_item_w2i: + * @item: A canvas item. + * @x: X coordinate to convert (input/output value). + * @y: Y coordinate to convert (input/output value). + * + * Converts a coordinate pair from world coordinates to item-relative + * coordinates. + **/ +void +ganv_item_w2i(GanvItem* item, double* x, double* y) +{ + double off_x; + double off_y; + ganv_item_i2w_offset(item, &off_x, &off_y); + + *x -= off_x; + *y -= off_y; +} + /* Returns whether the item is an inferior of or is equal to the parent. */ static gboolean is_descendant(GanvItem* item, GanvItem* parent) |