X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/119f63a0bab39b86f73676969b07fc86978a1329..442764a47cb13303e9724e93339b5ddd67e43b5d:/src/vikwindow.c?ds=sidebyside diff --git a/src/vikwindow.c b/src/vikwindow.c index 724dd9de..f2d7129e 100644 --- a/src/vikwindow.c +++ b/src/vikwindow.c @@ -22,8 +22,10 @@ #include "background.h" #include "acquire.h" #include "datasources.h" +#include "googlesearch.h" +#include "dems.h" -#define VIKING_TITLE " - Viking " VIKING_VERSION " " VIKING_VERSION_NAME " " VIKING_URL +#define VIKING_TITLE " - Viking" #include #include @@ -40,6 +42,8 @@ #define make_dir(dir) mkdir(dir,0777) #endif +#define VIKING_WINDOW_WIDTH 1000 +#define VIKING_WINDOW_HEIGHT 800 #define DRAW_IMAGE_DEFAULT_WIDTH 1280 #define DRAW_IMAGE_DEFAULT_HEIGHT 1024 #define DRAW_IMAGE_DEFAULT_SAVE_AS_PNG TRUE @@ -58,6 +62,7 @@ static void newwindow_cb ( GtkAction *a, VikWindow *vw ); static gboolean delete_event( VikWindow *vw ); +static void window_configure_event ( VikWindow *vw ); static void draw_sync ( VikWindow *vw ); static void draw_redraw ( VikWindow *vw ); static void draw_scroll ( VikWindow *vw, GdkEventScroll *event ); @@ -79,7 +84,9 @@ static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw ); typedef struct { VikToolInterface ti; gpointer state; + gint layer_type; } toolbox_tool_t; +#define TOOL_LAYER_TYPE_NONE -1 typedef struct { int active_tool; @@ -90,7 +97,7 @@ typedef struct { static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw ); static toolbox_tools_t* toolbox_create(VikWindow *vw); -static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti); +static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type ); static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name); static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name); static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event); @@ -106,6 +113,7 @@ static void register_vik_icons (GtkIconFactory *icon_factory); static void load_file ( GtkAction *a, VikWindow *vw ); static gboolean save_file_as ( GtkAction *a, VikWindow *vw ); static gboolean save_file ( GtkAction *a, VikWindow *vw ); +static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw ); static gboolean window_save ( VikWindow *vw ); struct _VikWindow { @@ -135,9 +143,14 @@ struct _VikWindow { gboolean modified; GtkWidget *open_dia, *save_dia; + GtkWidget *save_img_dia, *save_img_dir_dia; gboolean only_updating_coord_mode_ui; /* hack for a bug in GTK */ GtkUIManager *uim; + + /* half-drawn update */ + VikLayer *trigger; + VikCoord trigger_center; }; enum { @@ -157,6 +170,9 @@ static guint window_signals[VW_LAST_SIGNAL] = { 0 }; static gchar *tool_names[NUMBER_OF_TOOLS] = { "Zoom", "Ruler", "Pan" }; +GdkCursor *vw_cursor_zoom = NULL; +GdkCursor *vw_cursor_ruler = NULL; + GType vik_window_get_type (void) { static GType vw_type = 0; @@ -181,6 +197,11 @@ GType vik_window_get_type (void) return vw_type; } +VikViewport * vik_window_viewport(VikWindow *vw) +{ + return(vw->viking_vvp); +} + void vik_window_selected_layer(VikWindow *vw, VikLayer *vl) { int i, j, tool_count; @@ -211,6 +232,7 @@ static void window_finalize ( GObject *gob ) G_OBJECT_CLASS(parent_class)->finalize(gob); } + static void window_class_init ( VikWindowClass *klass ) { /* destructor */ @@ -268,7 +290,7 @@ static void window_init ( VikWindow *vw ) g_signal_connect (G_OBJECT (vw), "delete_event", G_CALLBACK (delete_event), NULL); g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "expose_event", G_CALLBACK(draw_sync), vw); - g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "configure_event", G_CALLBACK(draw_redraw), vw); + g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "configure_event", G_CALLBACK(window_configure_event), vw); gtk_widget_add_events ( GTK_WIDGET(vw->viking_vvp), GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK ); g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "scroll_event", G_CALLBACK(draw_scroll), vw); g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_press_event", G_CALLBACK(draw_click), vw); @@ -276,7 +298,7 @@ static void window_init ( VikWindow *vw ) g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "motion_notify_event", G_CALLBACK(draw_mouse_motion), vw); g_signal_connect_swapped (G_OBJECT(vw->viking_vlp), "update", G_CALLBACK(draw_update), vw); - gtk_window_set_default_size ( GTK_WINDOW(vw), 1000, 800); + gtk_window_set_default_size ( GTK_WINDOW(vw), VIKING_WINDOW_WIDTH, VIKING_WINDOW_HEIGHT); hpaned = gtk_hpaned_new (); gtk_paned_add1 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vlp) ); @@ -291,6 +313,8 @@ static void window_init ( VikWindow *vw ) vw->open_dia = NULL; vw->save_dia = NULL; + vw->save_img_dia = NULL; + vw->save_img_dir_dia = NULL; } VikWindow *vik_window_new () @@ -300,7 +324,11 @@ VikWindow *vik_window_new () static gboolean delete_event( VikWindow *vw ) { +#ifdef VIKING_PROMPT_IF_MODIFIED if ( vw->modified ) +#else + if (0) +#endif { GtkDialog *dia; dia = GTK_DIALOG ( gtk_message_dialog_new ( GTK_WINDOW(vw), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, @@ -348,11 +376,40 @@ static void draw_status ( VikWindow *vw ) vik_statusbar_set_message ( vw->viking_vs, 2, zoom_level ); } +void vik_window_set_redraw_trigger(VikLayer *vl) +{ + VikWindow *vw = VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl)); + vw->trigger = vl; +} + +static void window_configure_event ( VikWindow *vw ) +{ + draw_redraw ( vw ); + gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_zoom ); +} + static void draw_redraw ( VikWindow *vw ) { + VikCoord old_center = vw->trigger_center; + vw->trigger_center = *(vik_viewport_get_center(vw->viking_vvp)); + VikLayer *new_trigger = vw->trigger; + vw->trigger = NULL; + VikLayer *old_trigger = VIK_LAYER(vik_viewport_get_trigger(vw->viking_vvp)); + + if ( ! new_trigger ) + ; /* do nothing -- have to redraw everything. */ + else if ( (old_trigger != new_trigger) || !vik_coord_equals(&old_center, &vw->trigger_center) ) + vik_viewport_set_trigger ( vw->viking_vvp, new_trigger ); /* todo: set to half_drawn mode if new trigger is above old */ + else + vik_viewport_set_half_drawn ( vw->viking_vvp, TRUE ); + + /* actually draw */ vik_viewport_clear ( vw->viking_vvp); vik_layers_panel_draw_all ( vw->viking_vlp ); vik_viewport_draw_scale ( vw->viking_vvp ); + vik_viewport_draw_centermark ( vw->viking_vvp ); + + vik_viewport_set_half_drawn ( vw->viking_vvp, FALSE ); /* just in case. */ } gboolean draw_buf_done = TRUE; @@ -393,13 +450,17 @@ static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event) static struct UTM utm; static struct LatLon ll; static char pointer_buf[36]; + gint16 alt; toolbox_move(vw->vt, (GdkEventButton *)event); vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord ); vik_coord_to_utm ( &coord, &utm ); a_coords_utm_to_latlon ( &utm, &ll ); - g_snprintf ( pointer_buf, 36, "Cursor: %f %f", ll.lat, ll.lon ); + if ((alt = a_dems_get_elev_by_coord(&coord)) != VIK_DEM_INVALID_ELEVATION) + g_snprintf ( pointer_buf, 36, "Cursor: %f %f %dm", ll.lat, ll.lon, alt ); + else + g_snprintf ( pointer_buf, 36, "Cursor: %f %f", ll.lat, ll.lon ); vik_statusbar_set_message ( vw->viking_vs, 4, pointer_buf ); if ( vw->pan_x != -1 ) { @@ -425,10 +486,44 @@ static void draw_release ( VikWindow *vw, GdkEventButton *event ) static void draw_scroll (VikWindow *vw, GdkEventScroll *event) { - if ( event->direction == GDK_SCROLL_UP ) - vik_viewport_zoom_in (vw->viking_vvp); - else - vik_viewport_zoom_out(vw->viking_vvp); + if ( event->state == GDK_CONTROL_MASK ) { + /* control == pan up & down */ + if ( event->direction == GDK_SCROLL_UP ) + vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp)/3 ); + else + vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp)*2/3 ); + } else if ( event->state & GDK_SHIFT_MASK ) { + /* control-shift == pan left & right */ + if ( event->direction == GDK_SCROLL_UP ) + vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/3, vik_viewport_get_height(vw->viking_vvp)/2 ); + else + vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)*2/3, vik_viewport_get_height(vw->viking_vvp)/2 ); + } else { + if ( event->direction == GDK_SCROLL_UP ) { + /* make sure mouse is still over the same point on the map when we zoom */ + VikCoord coord; + gint x, y; + gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2; + gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2; + vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord ); + vik_viewport_zoom_in (vw->viking_vvp); + vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y ); + vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x), + center_y + (y - event->y) ); + } + else { + VikCoord coord; + gint x, y; + gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2; + gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2; + vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord ); + vik_viewport_zoom_out(vw->viking_vvp); + vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y ); + vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x), + center_y + (y - event->y) ); + } + } + draw_update(vw); } @@ -761,6 +856,19 @@ static VikToolInterface zoom_tool = (VikToolMouseFunc) zoomtool_release }; /*** end ruler code ********************************************************/ +static void draw_pan_cb ( GtkAction *a, VikWindow *vw ) +{ + if (!strcmp(gtk_action_get_name(a), "PanNorth")) { + vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, 0 ); + } else if (!strcmp(gtk_action_get_name(a), "PanEast")) { + vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp), vik_viewport_get_height(vw->viking_vvp)/2 ); + } else if (!strcmp(gtk_action_get_name(a), "PanSouth")) { + vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp) ); + } else if (!strcmp(gtk_action_get_name(a), "PanWest")) { + vik_viewport_set_center_screen ( vw->viking_vvp, 0, vik_viewport_get_height(vw->viking_vvp)/2 ); + } + draw_update ( vw ); +} static void draw_zoom_cb ( GtkAction *a, VikWindow *vw ) @@ -816,7 +924,7 @@ void draw_goto_cb ( GtkAction *a, VikWindow *vw ) return; } else { - fprintf(stderr, "Houston we have a problem\n"); + g_critical("Houston we have a problem\n"); return; } @@ -892,16 +1000,17 @@ static toolbox_tools_t* toolbox_create(VikWindow *vw) vt->active_tool = -1; vt->vw = vw; if (!vw->viking_vvp) { - printf("Error: no viewport found.\n"); + g_critical("no viewport found."); exit(1); } return vt; } -static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti) +static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type ) { vt->tools = g_renew(toolbox_tool_t, vt->tools, vt->n_tools+1); vt->tools[vt->n_tools].ti = *vti; + vt->tools[vt->n_tools].layer_type = layer_type; if (vti->create) { vt->tools[vt->n_tools].state = vti->create(vt->vw, vt->vw->viking_vvp); } @@ -929,7 +1038,7 @@ static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name) VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp ); if (tool == vt->n_tools) { - printf("panic: trying to activate a non-existent tool... \n"); + g_critical("trying to activate a non-existent tool..."); exit(1); } /* is the tool already active? */ @@ -952,7 +1061,9 @@ static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event) { VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp ); if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.click) { - vt->tools[vt->active_tool].ti.click(vl, event, vt->tools[vt->active_tool].state); + gint ltype = vt->tools[vt->active_tool].layer_type; + if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) ) + vt->tools[vt->active_tool].ti.click(vl, event, vt->tools[vt->active_tool].state); } } @@ -960,15 +1071,19 @@ static void toolbox_move (toolbox_tools_t *vt, GdkEventButton *event) { VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp ); if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.move) { - vt->tools[vt->active_tool].ti.move(vl, event, vt->tools[vt->active_tool].state); + gint ltype = vt->tools[vt->active_tool].layer_type; + if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) ) + vt->tools[vt->active_tool].ti.move(vl, event, vt->tools[vt->active_tool].state); } } static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event) { VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp ); - if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.release) { - vt->tools[vt->active_tool].ti.release(vl, event, vt->tools[vt->active_tool].state); + if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.release ) { + gint ltype = vt->tools[vt->active_tool].layer_type; + if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) ) + vt->tools[vt->active_tool].ti.release(vl, event, vt->tools[vt->active_tool].state); } } /** End tool management ************************************/ @@ -985,9 +1100,11 @@ static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw ) if (!strcmp(gtk_action_get_name(a), "Zoom")) { vw->current_tool = TOOL_ZOOM; + gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_zoom ); } else if (!strcmp(gtk_action_get_name(a), "Ruler")) { vw->current_tool = TOOL_RULER; + gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_ruler ); } else { /* TODO: only enable tools from active layer */ @@ -997,6 +1114,7 @@ static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw ) vw->current_tool = TOOL_LAYER; vw->tool_layer_id = i; vw->tool_tool_id = j; + gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vik_layer_get_tool_cursor ( i, j ) ); } } } @@ -1023,6 +1141,22 @@ static void window_set_filename ( VikWindow *vw, const gchar *filename ) } } +GtkWidget *vik_window_get_drawmode_button ( VikWindow *vw, VikViewportDrawMode mode ) +{ + GtkWidget *mode_button; + gchar *buttonname; + switch ( mode ) { + case VIK_VIEWPORT_DRAWMODE_UTM: buttonname = "/ui/MainMenu/View/ModeUTM"; break; + case VIK_VIEWPORT_DRAWMODE_EXPEDIA: buttonname = "/ui/MainMenu/View/ModeExpedia"; break; + case VIK_VIEWPORT_DRAWMODE_GOOGLE: buttonname = "/ui/MainMenu/View/ModeGoogle"; break; + case VIK_VIEWPORT_DRAWMODE_MERCATOR: buttonname = "/ui/MainMenu/View/ModeMercator"; break; + default: buttonname = "/ui/MainMenu/View/ModeKH"; + } + mode_button = gtk_ui_manager_get_widget ( vw->uim, buttonname ); + g_assert ( mode_button ); + return mode_button; +} + void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean change_filename ) { switch ( a_file_load ( vik_layers_panel_get_top_layer(vw->viking_vlp), vw->viking_vvp, filename ) ) @@ -1033,27 +1167,26 @@ void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean chang case 1: { GtkWidget *mode_button; - gchar *buttonname; if ( change_filename ) window_set_filename ( vw, filename ); - switch ( vik_viewport_get_drawmode ( vw->viking_vvp ) ) { - case VIK_VIEWPORT_DRAWMODE_UTM: buttonname = "/ui/MainMenu/View/ModeUTM"; break; - case VIK_VIEWPORT_DRAWMODE_EXPEDIA: buttonname = "/ui/MainMenu/View/ModeExpedia"; break; - case VIK_VIEWPORT_DRAWMODE_GOOGLE: buttonname = "/ui/MainMenu/View/ModeGoogle"; break; - default: buttonname = "/ui/MainMenu/View/ModeKH"; - } - mode_button = gtk_ui_manager_get_widget ( vw->uim, buttonname ); - g_assert ( mode_button ); + mode_button = vik_window_get_drawmode_button ( vw, vik_viewport_get_drawmode ( vw->viking_vvp ) ); vw->only_updating_coord_mode_ui = TRUE; /* if we don't set this, it will change the coord to UTM if we click Lat/Lon. I don't know why. */ gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button), TRUE ); vw->only_updating_coord_mode_ui = FALSE; vik_layers_panel_change_coord_mode ( vw->viking_vlp, vik_viewport_get_coord_mode ( vw->viking_vvp ) ); + + mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowScale" ); + g_assert ( mode_button ); + gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_scale(vw->viking_vvp) ); + + mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowCenterMark" ); + g_assert ( mode_button ); + gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_centermark(vw->viking_vvp) ); } default: draw_update ( vw ); } } - static void load_file ( GtkAction *a, VikWindow *vw ) { gboolean newwindow; @@ -1064,7 +1197,7 @@ static void load_file ( GtkAction *a, VikWindow *vw ) newwindow = FALSE; } else { - fprintf(stderr, "Houston we got a problem\n"); + g_critical("Houston we got a problem\n"); return; } @@ -1078,7 +1211,11 @@ static void load_file ( GtkAction *a, VikWindow *vw ) if ( gtk_dialog_run ( GTK_DIALOG(vw->open_dia) ) == GTK_RESPONSE_OK ) { gtk_widget_hide ( vw->open_dia ); +#ifdef VIKING_PROMPT_IF_MODIFIED if ( (vw->modified || vw->filename) && newwindow ) +#else + if ( vw->filename && newwindow ) +#endif g_signal_emit ( G_OBJECT(vw), window_signals[VW_OPENWINDOW_SIGNAL], 0, gtk_file_selection_get_selections (GTK_FILE_SELECTION(vw->open_dia) ) ); else { gchar **files = gtk_file_selection_get_selections (GTK_FILE_SELECTION(vw->open_dia) ); @@ -1151,10 +1288,17 @@ static void acquire_from_google ( GtkAction *a, VikWindow *vw ) a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_google_interface ); } +#ifdef VIK_CONFIG_GEOCACHES static void acquire_from_gc ( GtkAction *a, VikWindow *vw ) { a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gc_interface ); } +#endif + +static void goto_address( GtkAction *a, VikWindow *vw) +{ + a_google_search(vw, vw->viking_vlp, vw->viking_vvp); +} static void clear_cb ( GtkAction *a, VikWindow *vw ) { @@ -1169,6 +1313,16 @@ static void window_close ( GtkAction *a, VikWindow *vw ) gtk_widget_destroy ( GTK_WIDGET(vw) ); } +static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw ) +{ + if (save_file( NULL, vw)) { + window_close( NULL, vw); + return(TRUE); + } + else + return(FALSE); +} + static void zoom_to_cb ( GtkAction *a, VikWindow *vw ) { gdouble xmpp = vik_viewport_get_xmpp ( vw->viking_vvp ), ympp = vik_viewport_get_ympp ( vw->viking_vvp ); @@ -1203,7 +1357,7 @@ static void save_image_file ( VikWindow *vw, const gchar *fn, guint w, guint h, gdk_pixbuf_save ( pixbuf_to_save, fn, save_as_png ? "png" : "jpeg", &error, NULL ); if (error) { - fprintf(stderr, "Unable to write to file %s: %s", fn, error->message ); + g_warning("Unable to write to file %s: %s", fn, error->message ); g_error_free (error); } g_object_unref ( G_OBJECT(pixbuf_to_save) ); @@ -1246,7 +1400,7 @@ static void save_image_dir ( VikWindow *vw, const gchar *fn, guint w, guint h, g { for ( x = 1; x <= tiles_w; x++ ) { - g_snprintf ( name_of_file, size, "%s%cy%d-x%d.%s", fn, VIKING_FILE_SEP, y, x, save_as_png ? "png" : "jpg" ); + g_snprintf ( name_of_file, size, "%s%cy%d-x%d.%s", fn, G_DIR_SEPARATOR, y, x, save_as_png ? "png" : "jpg" ); utm = utm_orig; if ( tiles_w & 0x1 ) utm.easting += ((gdouble)x - ceil(((gdouble)tiles_w)/2)) * (w*zoom); @@ -1267,7 +1421,7 @@ static void save_image_dir ( VikWindow *vw, const gchar *fn, guint w, guint h, g gdk_pixbuf_save ( pixbuf_to_save, name_of_file, save_as_png ? "png" : "jpeg", &error, NULL ); if (error) { - fprintf(stderr, "Unable to write to file %s: %s", name_of_file, error->message ); + g_warning("Unable to write to file %s: %s", name_of_file, error->message ); g_error_free (error); } @@ -1333,7 +1487,7 @@ static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_im GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, - 0 ); + NULL ); GtkWidget *width_label, *width_spin, *height_label, *height_spin; GtkWidget *png_radio, *jpeg_radio; GtkWidget *current_window_button; @@ -1438,42 +1592,46 @@ static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_im static void draw_to_image_file_cb ( GtkAction *a, VikWindow *vw ) { - GtkWidget *file_selector; const gchar *fn; - file_selector = gtk_file_selection_new ("Save Image"); + if (!vw->save_img_dia) { + vw->save_img_dia = gtk_file_selection_new ("Save Image"); + gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dia), GTK_WINDOW(vw) ); + gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dia), TRUE ); + } - while ( gtk_dialog_run ( GTK_DIALOG(file_selector) ) == GTK_RESPONSE_OK ) + while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dia) ) == GTK_RESPONSE_OK ) { - fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(file_selector) ); - if ( access ( fn, F_OK ) != 0 || a_dialog_overwrite ( GTK_WINDOW(file_selector), "The file \"%s\" exists, do you wish to overwrite it?", a_file_basename ( fn ) ) ) + fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(vw->save_img_dia) ); + if ( access ( fn, F_OK ) != 0 || a_dialog_overwrite ( GTK_WINDOW(vw->save_img_dia), "The file \"%s\" exists, do you wish to overwrite it?", a_file_basename ( fn ) ) ) { - gtk_widget_hide ( file_selector ); draw_to_image_file ( vw, fn, TRUE ); break; } } - gtk_widget_destroy ( file_selector ); + gtk_widget_hide ( vw->save_img_dia ); } static void draw_to_image_dir_cb ( GtkAction *a, VikWindow *vw ) { - GtkWidget *file_selector; const gchar *fn; - file_selector = gtk_file_selection_new ("Choose a name for a new directory to hold images"); + if (!vw->save_img_dir_dia) { + vw->save_img_dir_dia = gtk_file_selection_new ("Choose a name for a new directory to hold images"); + gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dir_dia), GTK_WINDOW(vw) ); + gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dir_dia), TRUE ); + } - while ( gtk_dialog_run ( GTK_DIALOG(file_selector) ) == GTK_RESPONSE_OK ) + while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dir_dia) ) == GTK_RESPONSE_OK ) { - fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(file_selector) ); + fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(vw->save_img_dir_dia) ); if ( access ( fn, F_OK ) == 0 ) - a_dialog_info_msg_extra ( GTK_WINDOW(file_selector), "The file %s exists. Please choose a name for a new directory to hold images in that does not exist.", a_file_basename(fn) ); + a_dialog_info_msg_extra ( GTK_WINDOW(vw->save_img_dir_dia), "The file %s exists. Please choose a name for a new directory to hold images in that does not exist.", a_file_basename(fn) ); else { - gtk_widget_hide ( file_selector ); draw_to_image_file ( vw, fn, FALSE ); break; } } - gtk_widget_destroy ( file_selector ); + gtk_widget_hide ( vw->save_img_dir_dia ); } /* really a misnomer: changes coord mode (actual coordinates) AND/OR draw mode (viewport only) */ @@ -1496,7 +1654,7 @@ static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWin drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR; } else { - fprintf(stderr, "Houston, we got a problem!\n"); + g_critical("Houston, we got a problem!\n"); return; } @@ -1519,7 +1677,19 @@ static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWin static void set_draw_scale ( GtkAction *a, VikWindow *vw ) { - vik_viewport_set_draw_scale ( vw->viking_vvp, !vik_viewport_get_draw_scale(vw->viking_vvp) ); + GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowScale" ); + g_assert(check_box); + gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box)); + vik_viewport_set_draw_scale ( vw->viking_vvp, state ); + draw_update ( vw ); +} + +static void set_draw_centermark ( GtkAction *a, VikWindow *vw ) +{ + GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowCenterMark" ); + g_assert(check_box); + gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box)); + vik_viewport_set_draw_centermark ( vw->viking_vvp, state ); draw_update ( vw ); } @@ -1550,6 +1720,7 @@ static GtkActionEntry entries[] = { { "Edit", NULL, "_Edit", 0, 0, 0 }, { "View", NULL, "_View", 0, 0, 0 }, { "SetZoom", NULL, "_Zoom", 0, 0, 0 }, + { "SetPan", NULL, "_Pan", 0, 0, 0 }, { "Layers", NULL, "_Layers", 0, 0, 0 }, { "Tools", NULL, "_Tools", 0, 0, 0 }, { "Help", NULL, "_Help", 0, 0, 0 }, @@ -1560,13 +1731,17 @@ static GtkActionEntry entries[] = { { "Acquire", NULL, "A_cquire", 0, 0, 0 }, { "AcquireGPS", NULL, "From _GPS", NULL, "Transfer data from a GPS device", (GCallback)acquire_from_gps }, { "AcquireGoogle", NULL, "Google _Directions", NULL, "Get driving directions from Google", (GCallback)acquire_from_google }, +#ifdef VIK_CONFIG_GEOCACHES { "AcquireGC", NULL, "Geo_caches", NULL, "Get Geocaches from geocaching.com", (GCallback)acquire_from_gc }, +#endif { "Save", GTK_STOCK_SAVE, "_Save", "S", "Save the file", (GCallback)save_file }, { "SaveAs", GTK_STOCK_SAVE_AS, "Save _As", NULL, "Save the file under different name", (GCallback)save_file_as }, { "GenImg", GTK_STOCK_CLEAR, "_Generate Image File", NULL, "Save a snapshot of the workspace into a file", (GCallback)draw_to_image_file_cb }, { "GenImgDir", GTK_STOCK_DND_MULTIPLE, "Generate _Directory of Images", NULL, "FIXME:IMGDIR", (GCallback)draw_to_image_dir_cb }, { "Exit", GTK_STOCK_QUIT, "E_xit", "W", "Exit the program", (GCallback)window_close }, + { "SaveExit", GTK_STOCK_QUIT, "Save and Exit", NULL, "Save and Exit the program", (GCallback)save_file_and_exit }, + { "GoogleMapsSearch", GTK_STOCK_GO_FORWARD, "Go To Google Maps location", NULL, "Go to address/place using Google Maps search", (GCallback)goto_address }, { "GotoLL", GTK_STOCK_QUIT, "_Go to Lat\\/Lon...", NULL, "Go to arbitrary lat\\/lon coordinate", (GCallback)draw_goto_cb }, { "GotoUTM", GTK_STOCK_QUIT, "Go to UTM...", NULL, "Go to arbitrary UTM coordinate", (GCallback)draw_goto_cb }, { "SetBGColor",GTK_STOCK_SELECT_COLOR, "Set Background Color...", NULL, NULL, (GCallback)set_bg_color }, @@ -1583,6 +1758,10 @@ static GtkActionEntry entries[] = { { "Zoom32", NULL, "32", NULL, NULL, (GCallback)draw_zoom_cb }, { "Zoom64", NULL, "64", NULL, NULL, (GCallback)draw_zoom_cb }, { "Zoom128", NULL, "128", NULL, NULL, (GCallback)draw_zoom_cb }, + { "PanNorth", NULL, "Pan North", "Up", NULL, (GCallback)draw_pan_cb }, + { "PanEast", NULL, "Pan East", "Right", NULL, (GCallback)draw_pan_cb }, + { "PanSouth", NULL, "Pan South", "Down", NULL, (GCallback)draw_pan_cb }, + { "PanWest", NULL, "Pan West", "Left", NULL, (GCallback)draw_pan_cb }, { "BGJobs", GTK_STOCK_EXECUTE, "Background _Jobs", NULL, NULL, (GCallback)a_background_show_window }, { "Cut", GTK_STOCK_CUT, "Cu_t", NULL, NULL, (GCallback)menu_cut_layer_cb }, @@ -1611,6 +1790,7 @@ static GtkRadioActionEntry tool_entries[] = { static GtkToggleActionEntry toggle_entries[] = { { "ShowScale", NULL, "Show Scale", NULL, NULL, (GCallback)set_draw_scale, TRUE }, + { "ShowCenterMark", NULL, "Show Center Mark", NULL, NULL, (GCallback)set_draw_centermark, TRUE }, }; #include "menu.xml.h" @@ -1629,8 +1809,8 @@ static void window_create_ui( VikWindow *window ) uim = gtk_ui_manager_new (); window->uim = uim; - toolbox_add_tool(window->vt, &ruler_tool); - toolbox_add_tool(window->vt, &zoom_tool); + toolbox_add_tool(window->vt, &ruler_tool, TOOL_LAYER_TYPE_NONE); + toolbox_add_tool(window->vt, &zoom_tool, TOOL_LAYER_TYPE_NONE); error = NULL; if (!(mid = gtk_ui_manager_add_ui_from_string (uim, menu_xml, -1, &error))) { @@ -1641,7 +1821,7 @@ static void window_create_ui( VikWindow *window ) action_group = gtk_action_group_new ("MenuActions"); gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), window); gtk_action_group_add_toggle_actions (action_group, toggle_entries, G_N_ELEMENTS (toggle_entries), window); - gtk_action_group_add_radio_actions (action_group, mode_entries, G_N_ELEMENTS (mode_entries), 0, (GCallback)window_change_coord_mode_cb, window); + gtk_action_group_add_radio_actions (action_group, mode_entries, G_N_ELEMENTS (mode_entries), 4, (GCallback)window_change_coord_mode_cb, window); icon_factory = gtk_icon_factory_new (); gtk_icon_factory_add_default (icon_factory); @@ -1695,7 +1875,7 @@ static void window_create_ui( VikWindow *window ) vik_layer_get_interface(i)->tools[j].name, GTK_UI_MANAGER_TOOLITEM, FALSE); - toolbox_add_tool(window->vt, &(vik_layer_get_interface(i)->tools[j])); + toolbox_add_tool(window->vt, &(vik_layer_get_interface(i)->tools[j]), i); radio->name = vik_layer_get_interface(i)->tools[j].name; radio->stock_id = vik_layer_get_interface(i)->tools[j].name, @@ -1737,11 +1917,13 @@ static struct { { &edtr_18, "Edit Trackpoint" }, { &addwp_18, "Create Waypoint" }, { &edwp_18, "Edit Waypoint" }, + { &iscissors_18, "Magic Scissors" }, { &zoom_18, "vik-icon-zoom" }, { &ruler_18, "vik-icon-ruler" }, { &geozoom_18, "Georef Zoom Tool" }, { &geomove_18, "Georef Move Map" }, { &mapdl_18, "Maps Download" }, + { &demdl_18, "DEM Download/Import" }, { &showpic_18, "Show Picture" }, }; @@ -1760,3 +1942,25 @@ register_vik_icons (GtkIconFactory *icon_factory) gtk_icon_set_unref (icon_set); } } + +void vik_window_cursors_init() +{ + GdkPixbuf *cursor_pixbuf; + GError *cursor_load_err; + + cursor_pixbuf = gdk_pixbuf_from_pixdata (&cursor_zoom, FALSE, &cursor_load_err); + vw_cursor_zoom = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 6, 6 ); + + g_object_unref ( G_OBJECT(cursor_pixbuf) ); + + cursor_pixbuf = gdk_pixbuf_from_pixdata (&cursor_ruler, FALSE, &cursor_load_err); + vw_cursor_ruler = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 6, 6 ); + + g_object_unref ( G_OBJECT(cursor_pixbuf) ); +} + +void vik_window_cursors_uninit() +{ + gdk_cursor_unref ( vw_cursor_zoom ); + gdk_cursor_unref ( vw_cursor_ruler ); +}