[PATCH] Initial not-so-pretty profile zoom support

Linus Torvalds torvalds at linux-foundation.org
Sun Nov 11 02:19:56 PST 2012


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Sat, 10 Nov 2012 17:25:19 +0100
Subject: [PATCH] Initial not-so-pretty profile zoom support

You can press the left mouse-button on the profile and drag the mouse
around to zoom in on a specific area. Releasing the mouse button unzooms.

Yeah, everybody wants rubber-banding, but I have reached the end of my
willingness to fight gtk for more details. Some day.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

No it's not wonderful, but it does kind of work. And even if we don't end 
up keeping this zoom model, the mouse event infrastructure would likely be 
useful for any improved rubber-banding model too.

diff --git a/gtk-gui.c b/gtk-gui.c
index 2fe3f7af909e..38b285fbaaea 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -1313,6 +1313,8 @@ static gboolean profile_tooltip (GtkWidget *widget, gint x, gint y,
 	return FALSE; /* don't show tooltip */
 }
 
+static int zoom_x = -1, zoom_y = -1;
+
 static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
 {
 	struct dive *dive = current_dive;
@@ -1332,6 +1334,11 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer
 	init_profile_background(&gc);
 	cairo_paint(gc.cr);
 
+	if (zoom_x >= 0) {
+		cairo_translate(gc.cr, -zoom_x, -zoom_y);
+		cairo_scale(gc.cr, 2.0, 2.0);
+	}
+
 	if (dive) {
 		if (tooltip_rects) {
 			free(tooltip_rects);
@@ -1345,6 +1352,44 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer
 	return FALSE;
 }
 
+gboolean clicked(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
+{
+	switch (event->button) {
+	case 1:
+		zoom_x = event->x;
+		zoom_y = event->y;
+		break;
+	default:
+		return TRUE;
+	}
+	gtk_widget_queue_draw(widget);
+	return TRUE;
+}
+
+gboolean released(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
+{
+	switch (event->button) {
+	case 1:
+		zoom_x = zoom_y = -1;
+		break;
+	default:
+		return TRUE;
+	}
+	gtk_widget_queue_draw(widget);
+	return TRUE;
+}
+
+gboolean motion(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
+{
+	if (zoom_x < 0)
+		return TRUE;
+
+	zoom_x = event->x;
+	zoom_y = event->y;
+	gtk_widget_queue_draw(widget);
+	return TRUE;
+}
+
 GtkWidget *dive_profile_widget(void)
 {
 	GtkWidget *da;
@@ -1352,6 +1397,10 @@ GtkWidget *dive_profile_widget(void)
 	da = gtk_drawing_area_new();
 	gtk_widget_set_size_request(da, 350, 250);
 	g_signal_connect(da, "expose_event", G_CALLBACK(expose_event), NULL);
+	g_signal_connect(da, "button-press-event", G_CALLBACK(clicked), NULL);
+	g_signal_connect(da, "button-release-event", G_CALLBACK(released), NULL);
+	g_signal_connect(da, "motion-notify-event", G_CALLBACK(motion), NULL);
+	gtk_widget_add_events(da, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK);
 
 	return da;
 }


More information about the subsurface mailing list