X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/c933487f83cac2eddfcf14fed44cc8524b9b387e..de2fc9aa9e8db8e0258c8328161c6b5eda176a0a:/src/vikviewport.c diff --git a/src/vikviewport.c b/src/vikviewport.c index fe2815cb..fd2ea74b 100644 --- a/src/vikviewport.c +++ b/src/vikviewport.c @@ -28,10 +28,10 @@ #include #include -#include #include "coords.h" #include "vikcoord.h" +#include "vikwindow.h" #include "vikviewport.h" #include "mapcoord.h" @@ -89,6 +89,11 @@ struct _VikViewport { gdouble google_calcy_fact; gdouble google_calcx_rev_fact; gdouble google_calcy_rev_fact; + + /* trigger stuff */ + gpointer trigger; + GdkPixmap *snapshot_buffer; + gboolean half_drawn; }; static gdouble @@ -148,7 +153,8 @@ static void viewport_class_init ( VikViewportClass *klass ) VikViewport *vik_viewport_new () { - return VIK_VIEWPORT ( g_object_new ( VIK_VIEWPORT_TYPE, NULL ) ); + VikViewport *vv = VIK_VIEWPORT ( g_object_new ( VIK_VIEWPORT_TYPE, NULL ) ); + return vv; } static void viewport_init ( VikViewport *vvp ) @@ -158,10 +164,11 @@ static void viewport_init ( VikViewport *vvp ) /* TODO: not static */ vvp->xmpp = 4.0; vvp->ympp = 4.0; - vvp->coord_mode = VIK_COORD_UTM; - vvp->drawmode = VIK_VIEWPORT_DRAWMODE_UTM; - vvp->center.north_south = 0; - vvp->center.east_west = -166021; + vvp->coord_mode = VIK_COORD_LATLON; + vvp->drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR; + vvp->center.mode = VIK_COORD_LATLON; + vvp->center.north_south = 40.714490; + vvp->center.east_west = -74.007130; vvp->center.utm_zone = 31; vvp->center.utm_letter = 'N'; vvp->scr_buffer = NULL; @@ -172,7 +179,14 @@ static void viewport_init ( VikViewport *vvp ) vvp->scale_bg_gc = NULL; vvp->draw_scale = TRUE; vvp->draw_centermark = TRUE; + + vvp->trigger = NULL; + vvp->snapshot_buffer = NULL; + vvp->half_drawn = FALSE; + g_signal_connect (G_OBJECT(vvp), "configure_event", G_CALLBACK(vik_viewport_configure), NULL); + + GTK_WIDGET_SET_FLAGS(vvp, GTK_CAN_FOCUS); /* allow VVP to have focus -- enabling key events, etc */ } GdkColor *vik_viewport_get_background_gdkcolor ( VikViewport *vvp ) @@ -234,6 +248,11 @@ void vik_viewport_configure_manually ( VikViewport *vvp, gint width, guint heigh if ( vvp->scr_buffer ) g_object_unref ( G_OBJECT ( vvp->scr_buffer ) ); vvp->scr_buffer = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, vvp->width, vvp->height, -1 ); + + /* TODO trigger: only if this is enabled !!! */ + if ( vvp->snapshot_buffer ) + g_object_unref ( G_OBJECT ( vvp->snapshot_buffer ) ); + vvp->snapshot_buffer = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, vvp->width, vvp->height, -1 ); } @@ -254,6 +273,13 @@ gboolean vik_viewport_configure ( VikViewport *vvp ) vvp->scr_buffer = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, vvp->width, vvp->height, -1 ); + /* TODO trigger: only if enabled! */ + if ( vvp->snapshot_buffer ) + g_object_unref ( G_OBJECT ( vvp->snapshot_buffer ) ); + + vvp->snapshot_buffer = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, vvp->width, vvp->height, -1 ); + /* TODO trigger */ + /* this is down here so it can get a GC (necessary?) */ if ( ! vvp->background_gc ) { @@ -276,6 +302,9 @@ static void viewport_finalize ( GObject *gob ) if ( vvp->scr_buffer ) g_object_unref ( G_OBJECT ( vvp->scr_buffer ) ); + if ( vvp->snapshot_buffer ) + g_object_unref ( G_OBJECT ( vvp->snapshot_buffer ) ); + if ( vvp->alpha_pixbuf ) g_object_unref ( G_OBJECT ( vvp->alpha_pixbuf ) ); @@ -401,17 +430,22 @@ void vik_viewport_draw_centermark ( VikViewport *vvp ) if ( !vvp->draw_centermark ) return; - int len = 50; + const int len = 30; + const int gap = 4; int center_x = vvp->width/2; int center_y = vvp->height/2; GdkGC * black_gc = GTK_WIDGET(&vvp->drawing_area)->style->black_gc; /* white back ground */ - vik_viewport_draw_line(vvp, vvp->scale_bg_gc, center_x - len, center_y, center_x + len, center_y); - vik_viewport_draw_line(vvp, vvp->scale_bg_gc, center_x, center_y - len, center_x, center_y + len); + vik_viewport_draw_line(vvp, vvp->scale_bg_gc, center_x - len, center_y, center_x - gap, center_y); + vik_viewport_draw_line(vvp, vvp->scale_bg_gc, center_x + gap, center_y, center_x + len, center_y); + vik_viewport_draw_line(vvp, vvp->scale_bg_gc, center_x, center_y - len, center_x, center_y - gap); + vik_viewport_draw_line(vvp, vvp->scale_bg_gc, center_x, center_y + gap, center_x, center_y + len); /* black fore ground */ - vik_viewport_draw_line(vvp, black_gc, center_x - len, center_y, center_x + len, center_y); - vik_viewport_draw_line(vvp, black_gc, center_x, center_y - len, center_x, center_y + len); + vik_viewport_draw_line(vvp, black_gc, center_x - len, center_y, center_x - gap, center_y); + vik_viewport_draw_line(vvp, black_gc, center_x + gap, center_y, center_x + len, center_y); + vik_viewport_draw_line(vvp, black_gc, center_x, center_y - len, center_x, center_y - gap); + vik_viewport_draw_line(vvp, black_gc, center_x, center_y + gap, center_x, center_y + len); } @@ -1000,3 +1034,72 @@ static void viewport_google_rezoom ( VikViewport *vvp ) vvp->google_calcx_rev_fact = 1 / vvp->google_calcx_fact; vvp->google_calcy_rev_fact = 1 / vvp->google_calcy_fact; } + +/******** triggering *******/ +void vik_viewport_set_trigger ( VikViewport *vp, gpointer trigger ) +{ + vp->trigger = trigger; +} + +gpointer vik_viewport_get_trigger ( VikViewport *vp ) +{ + return vp->trigger; +} + +void vik_viewport_snapshot_save ( VikViewport *vp ) +{ + gdk_draw_drawable ( vp->snapshot_buffer, vp->background_gc, vp->scr_buffer, 0, 0, 0, 0, -1, -1 ); +} + +void vik_viewport_snapshot_load ( VikViewport *vp ) +{ + gdk_draw_drawable ( vp->scr_buffer, vp->background_gc, vp->snapshot_buffer, 0, 0, 0, 0, -1, -1 ); +} + +void vik_viewport_set_half_drawn(VikViewport *vp, gboolean half_drawn) +{ + vp->half_drawn = half_drawn; +} + +gboolean vik_viewport_get_half_drawn( VikViewport *vp ) +{ + return vp->half_drawn; +} + + +const gchar *vik_viewport_get_drawmode_name(VikViewport *vv, VikViewportDrawMode mode) + { + const gchar *name = NULL; + VikWindow *vw = NULL; + GtkWidget *mode_button; + GtkWidget *label; + + vw = VIK_WINDOW_FROM_WIDGET(vv); + mode_button = vik_window_get_drawmode_button(vw, mode); + label = gtk_bin_get_child(GTK_BIN(mode_button)); + + name = gtk_label_get_text ( GTK_LABEL(label) ); + + return name; + +} + +void vik_viewport_get_min_max_lat_lon ( VikViewport *vp, gdouble *min_lat, gdouble *max_lat, gdouble *min_lon, gdouble *max_lon ) +{ + VikCoord tleft, tright, bleft, bright; + + vik_viewport_screen_to_coord ( vp, 0, 0, &tleft ); + vik_viewport_screen_to_coord ( vp, vik_viewport_get_width(vp), 0, &tright ); + vik_viewport_screen_to_coord ( vp, 0, vik_viewport_get_height(vp), &bleft ); + vik_viewport_screen_to_coord ( vp, vp->width, vp->height, &bright ); + + vik_coord_convert(&tleft, VIK_COORD_LATLON); + vik_coord_convert(&tright, VIK_COORD_LATLON); + vik_coord_convert(&bleft, VIK_COORD_LATLON); + vik_coord_convert(&bright, VIK_COORD_LATLON); + + *max_lat = MAX(tleft.north_south, tright.north_south); + *min_lat = MIN(bleft.north_south, bright.north_south); + *max_lon = MAX(tright.east_west, bright.east_west); + *min_lon = MIN(tleft.east_west, bleft.east_west); +}