Update drag_motion() to scroll the routing window
The routing window will be scrolled relative to the position of the mouse within the window so all sources/sinks can be reached when dragging.
This commit is contained in:
@@ -40,6 +40,44 @@ static void drag_motion(
|
|||||||
|
|
||||||
card->drag_x = x;
|
card->drag_x = x;
|
||||||
card->drag_y = y;
|
card->drag_y = y;
|
||||||
|
|
||||||
|
// Retrieve the scrolled window and its child
|
||||||
|
GtkWindow *win = GTK_WINDOW(card->window_routing);
|
||||||
|
GtkScrolledWindow *sw = GTK_SCROLLED_WINDOW(gtk_window_get_child(win));
|
||||||
|
GtkWidget *child = gtk_scrolled_window_get_child(sw);
|
||||||
|
|
||||||
|
// Get horizontal and vertical adjustments for the scrolled window
|
||||||
|
GtkAdjustment *hadj = gtk_scrolled_window_get_hadjustment(sw);
|
||||||
|
GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(sw);
|
||||||
|
|
||||||
|
// Calculate the total scrollable width and height
|
||||||
|
double w = gtk_adjustment_get_upper(hadj) -
|
||||||
|
gtk_adjustment_get_page_size(hadj);
|
||||||
|
double h = gtk_adjustment_get_upper(vadj) -
|
||||||
|
gtk_adjustment_get_page_size(vadj);
|
||||||
|
|
||||||
|
// Determine the relative size of the scrollable area
|
||||||
|
double rel_w = gtk_adjustment_get_upper(hadj) - gtk_widget_get_allocated_width(GTK_WIDGET(sw)) + gtk_widget_get_allocated_width(child);
|
||||||
|
double rel_h = gtk_adjustment_get_upper(vadj) - gtk_widget_get_allocated_height(GTK_WIDGET(sw)) + gtk_widget_get_allocated_height(child);
|
||||||
|
|
||||||
|
// Add margin
|
||||||
|
rel_w -= 100;
|
||||||
|
rel_h -= 100;
|
||||||
|
x -= 50;
|
||||||
|
y -= 50;
|
||||||
|
if (x < 0) x = 0;
|
||||||
|
if (y < 0) y = 0;
|
||||||
|
if (x > rel_w) x = rel_w;
|
||||||
|
if (y > rel_h) y = rel_h;
|
||||||
|
|
||||||
|
// Calculate new scroll positions based on mouse coordinates
|
||||||
|
double new_hpos = (x / rel_w) * w;
|
||||||
|
double new_vpos = (y / rel_h) * h;
|
||||||
|
|
||||||
|
// Update the scrolled window's position
|
||||||
|
gtk_adjustment_set_value(vadj, new_vpos);
|
||||||
|
gtk_adjustment_set_value(hadj, new_hpos);
|
||||||
|
|
||||||
gtk_widget_queue_draw(card->drag_line);
|
gtk_widget_queue_draw(card->drag_line);
|
||||||
gtk_widget_queue_draw(card->routing_lines);
|
gtk_widget_queue_draw(card->routing_lines);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user