diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-03-17 16:13:02 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-03-17 16:15:36 -0700 |
commit | bfa37c3cac22949323bb6a5dfb23557638d20757 (patch) | |
tree | 52e35d78c4c0f3a52d2593291eab510dd0cd95f5 | |
parent | a094b2b88a21a7161def15ad0a730f79a8c83f09 (diff) | |
download | subsurface-bfa37c3cac22949323bb6a5dfb23557638d20757.tar.gz |
First step towards a context menu in the profile view
This is completely bogus as all it does is print out the corresponding
time for the spot we right-clicked on the profile. But that at least shows
that the infrastructure is working as intended...
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | display.h | 1 | ||||
-rw-r--r-- | gtk-gui.c | 31 | ||||
-rw-r--r-- | profile.c | 12 |
3 files changed, 44 insertions, 0 deletions
@@ -50,6 +50,7 @@ extern struct divecomputer *select_dc(struct divecomputer *main); extern void init_profile_background(struct graphics_context *gc); extern void attach_tooltip(int x, int y, int w, int h, const char *text); extern void get_plot_details(struct graphics_context *gc, int time, char *buf, size_t bufsize); +extern int x_to_time(double x); struct options { enum { PRETTY, TABLE, TWOPERPAGE } type; @@ -1959,6 +1959,34 @@ static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer return TRUE; } +static void add_gas_change_cb(GtkWidget *menuitem, gpointer data) +{ + double *x = data; + printf("x = %d:%02u\n", FRACTION(x_to_time(*x), 60)); +} + +static void popup_profile_menu(GtkWidget *widget, GdkEventButton *event) +{ + GtkWidget *menu, *menuitem, *image; + static double x; + + if (!event || !current_dive) + return; + x = event->x; + menu = gtk_menu_new(); + menuitem = gtk_image_menu_item_new_with_label(_("Add gas change event here")); + image = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); + g_signal_connect(menuitem, "activate", G_CALLBACK(add_gas_change_cb), &x); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + + gtk_widget_show_all(menu); + + gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, + event->button, gtk_get_current_event_time()); + +} + static gboolean clicked(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { switch (event->button) { @@ -1967,6 +1995,9 @@ static gboolean clicked(GtkWidget *widget, GdkEventButton *event, gpointer user_ zoom_y = event->y; zoom_factor = 2.5; break; + case 3: + popup_profile_menu(widget, event); + break; default: return TRUE; } @@ -141,6 +141,15 @@ static const color_t profile_color[] = { #define SCALEY(gc,y) (((y)-gc->topy)/(gc->bottomy-gc->topy)*gc->maxy) #define SCALE(gc,x,y) SCALEX(gc,x),SCALEY(gc,y) +/* keep the last used gc around so we can invert the SCALEX calculation in + * order to calculate a time value for an x coordinate */ +static struct graphics_context last_gc; +int x_to_time(double x) +{ + int seconds = (x - last_gc.drawing_area.x) / last_gc.maxx * (last_gc.rightx - last_gc.leftx) + last_gc.leftx; + return (seconds > 0) ? seconds : 0; +} + static void move_to(struct graphics_context *gc, double x, double y) { cairo_move_to(gc->cr, SCALE(gc, x, y)); @@ -700,6 +709,9 @@ static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi gc->leftx = 0; gc->rightx = maxtime; gc->topy = 0; gc->bottomy = 1.0; + + last_gc = *gc; + set_source_rgba(gc, TIME_GRID); cairo_set_line_width_scaled(gc->cr, 2); |