summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-11-10 17:25:19 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-11 11:55:43 +0100
commit78ad07c72ed37928020cdbf4842e24690ce35f81 (patch)
treed9bcc9f09c34105f6ffffb6f1e54582b26dd1eaa
parentba5079a489525b3c3e446b1b5fff8f7ca98e97f3 (diff)
downloadsubsurface-78ad07c72ed37928020cdbf4842e24690ce35f81.tar.gz
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. [Dirk Hohndel: changed this to use the right mouse button instead of the left which seemed just terribly unnatural] References ticket 9 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--gtk-gui.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/gtk-gui.c b/gtk-gui.c
index 2fe3f7af9..a34f278b6 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 3:
+ 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 3:
+ 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;
}