mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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>
This commit is contained in:
parent
ba5079a489
commit
78ad07c72e
1 changed files with 49 additions and 0 deletions
49
gtk-gui.c
49
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue