]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikviewport.c
Fix: Correctly rotate thumbnail images
[andy/viking.git] / src / vikviewport.c
index 8f648ba1b4981ee34f0263127b139685d164648b..6502881953777eba290bfdbf2d226f5a7836a95e 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #define DEFAULT_BACKGROUND_COLOR "#CCCCCC"
 
 #include <gtk/gtk.h>
 
 #define DEFAULT_BACKGROUND_COLOR "#CCCCCC"
 
 #include <gtk/gtk.h>
+#ifdef HAVE_MATH_H
 #include <math.h>
 #include <math.h>
-#include <stdio.h>
+#endif
 
 #include "coords.h"
 #include "vikcoord.h"
 
 #include "coords.h"
 #include "vikcoord.h"
@@ -39,8 +43,6 @@
 
 /* for ALTI_TO_MPP */
 #include "globals.h"
 
 /* for ALTI_TO_MPP */
 #include "globals.h"
-#include "googlemaps.h"
-#include "khmaps.h"
 
 static gdouble EASTING_OFFSET = 500000.0;
 
 
 static gdouble EASTING_OFFSET = 500000.0;
 
@@ -58,8 +60,6 @@ static void viewport_init_ra();
 
 static GObjectClass *parent_class;
 
 
 static GObjectClass *parent_class;
 
-static void viewport_google_rezoom ( VikViewport *vvp );
-
 
 struct _VikViewport {
   GtkDrawingArea drawing_area;
 
 struct _VikViewport {
   GtkDrawingArea drawing_area;
@@ -90,6 +90,11 @@ struct _VikViewport {
   gdouble google_calcy_fact;
   gdouble google_calcx_rev_fact;
   gdouble google_calcy_rev_fact;
   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
 };
 
 static gdouble
@@ -175,7 +180,14 @@ static void viewport_init ( VikViewport *vvp )
   vvp->scale_bg_gc = NULL;
   vvp->draw_scale = TRUE;
   vvp->draw_centermark = TRUE;
   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);
   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 )
 }
 
 GdkColor *vik_viewport_get_background_gdkcolor ( VikViewport *vvp )
@@ -237,6 +249,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 );
   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 );
 }
 
 
 }
 
 
@@ -257,6 +274,13 @@ gboolean vik_viewport_configure ( VikViewport *vvp )
 
   vvp->scr_buffer = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, vvp->width, vvp->height, -1 );
 
 
   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 )
   {
   /* this is down here so it can get a GC (necessary?) */
   if ( ! vvp->background_gc )
   {
@@ -279,6 +303,9 @@ static void viewport_finalize ( GObject *gob )
   if ( vvp->scr_buffer )
     g_object_unref ( G_OBJECT ( vvp->scr_buffer ) );
 
   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 ) );
 
   if ( vvp->alpha_pixbuf )
     g_object_unref ( G_OBJECT ( vvp->alpha_pixbuf ) );
 
@@ -386,6 +413,8 @@ void vik_viewport_draw_scale ( VikViewport *vvp )
     pango_layout_set_text(pl, s, -1);
     vik_viewport_draw_layout(vvp, GTK_WIDGET(&vvp->drawing_area)->style->black_gc,
                           PAD + len + PAD, vvp->height - PAD - 10, pl);
     pango_layout_set_text(pl, s, -1);
     vik_viewport_draw_layout(vvp, GTK_WIDGET(&vvp->drawing_area)->style->black_gc,
                           PAD + len + PAD, vvp->height - PAD - 10, pl);
+    g_object_unref(pl);
+    pl = NULL;
   }
 }
 
   }
 }
 
@@ -462,8 +491,6 @@ void vik_viewport_set_zoom ( VikViewport *vvp, gdouble xympp )
 
   if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_UTM )
     viewport_utm_zone_check(vvp);
 
   if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_UTM )
     viewport_utm_zone_check(vvp);
-  else if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_GOOGLE )
-    viewport_google_rezoom ( vvp );
 }
 
 /* or could do factor */
 }
 
 /* or could do factor */
@@ -475,9 +502,6 @@ void vik_viewport_zoom_in ( VikViewport *vvp )
     vvp->xmpp /= 2;
     vvp->ympp /= 2;
 
     vvp->xmpp /= 2;
     vvp->ympp /= 2;
 
-    if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_GOOGLE )
-      viewport_google_rezoom ( vvp );
-
     viewport_utm_zone_check(vvp);
   }
 }
     viewport_utm_zone_check(vvp);
   }
 }
@@ -490,9 +514,6 @@ void vik_viewport_zoom_out ( VikViewport *vvp )
     vvp->xmpp *= 2;
     vvp->ympp *= 2;
 
     vvp->xmpp *= 2;
     vvp->ympp *= 2;
 
-    if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_GOOGLE )
-      viewport_google_rezoom ( vvp );
-
     viewport_utm_zone_check(vvp);
   }
 }
     viewport_utm_zone_check(vvp);
   }
 }
@@ -520,8 +541,6 @@ void vik_viewport_set_xmpp ( VikViewport *vvp, gdouble xmpp )
     vvp->xmpp = xmpp;
     if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_UTM )
       viewport_utm_zone_check(vvp);
     vvp->xmpp = xmpp;
     if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_UTM )
       viewport_utm_zone_check(vvp);
-    if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_GOOGLE )
-      viewport_google_rezoom ( vvp );
   }
 }
 
   }
 }
 
@@ -531,8 +550,6 @@ void vik_viewport_set_ympp ( VikViewport *vvp, gdouble ympp )
     vvp->ympp = ympp;
     if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_UTM )
       viewport_utm_zone_check(vvp);
     vvp->ympp = ympp;
     if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_UTM )
       viewport_utm_zone_check(vvp);
-    if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_GOOGLE )
-      viewport_google_rezoom ( vvp );
   }
 }
 
   }
 }
 
@@ -676,14 +693,7 @@ void vik_viewport_screen_to_coord ( VikViewport *vvp, int x, int y, VikCoord *co
     coord->mode = VIK_COORD_LATLON;
     if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_EXPEDIA )
       calcxy_rev(&(coord->east_west), &(coord->north_south), x, y, vvp->center.east_west, vvp->center.north_south, vvp->xmpp * ALTI_TO_MPP, vvp->ympp * ALTI_TO_MPP, vvp->width/2, vvp->height/2);
     coord->mode = VIK_COORD_LATLON;
     if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_EXPEDIA )
       calcxy_rev(&(coord->east_west), &(coord->north_south), x, y, vvp->center.east_west, vvp->center.north_south, vvp->xmpp * ALTI_TO_MPP, vvp->ympp * ALTI_TO_MPP, vvp->width/2, vvp->height/2);
-    else if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_GOOGLE ) {
-      /* google */
-      coord->east_west = (x - (vvp->width/2)) * vvp->google_calcx_rev_fact + vvp->center.east_west;
-      coord->north_south = ((vvp->height/2) - y) * vvp->google_calcy_rev_fact + vvp->center.north_south;
-    } else if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_KH ) {
-      coord->east_west = vvp->center.east_west + (180.0 * vvp->xmpp / 65536 / 256 * (x - vvp->width/2));
-      coord->north_south = vvp->center.north_south + (180.0 * vvp->ympp / 65536 / 256 * (vvp->height/2 - y));
-    } else if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_MERCATOR ) {
+    else if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_MERCATOR ) {
       /* FIXMERCATOR */
       coord->east_west = vvp->center.east_west + (180.0 * vvp->xmpp / 65536 / 256 * (x - vvp->width/2));
       coord->north_south = DEMERCLAT ( MERCLAT(vvp->center.north_south) + (180.0 * vvp->ympp / 65536 / 256 * (vvp->height/2 - y)) );
       /* FIXMERCATOR */
       coord->east_west = vvp->center.east_west + (180.0 * vvp->xmpp / 65536 / 256 * (x - vvp->width/2));
       coord->north_south = DEMERCLAT ( MERCLAT(vvp->center.north_south) + (180.0 * vvp->ympp / 65536 / 256 * (vvp->height/2 - y)) );
@@ -730,14 +740,6 @@ void vik_viewport_coord_to_screen ( VikViewport *vvp, const VikCoord *coord, int
     if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_EXPEDIA ) {
       calcxy ( &xx, &yy, center->lon, center->lat, ll->lon, ll->lat, vvp->xmpp * ALTI_TO_MPP, vvp->ympp * ALTI_TO_MPP, vvp->width / 2, vvp->height / 2 );
       *x = xx; *y = yy;
     if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_EXPEDIA ) {
       calcxy ( &xx, &yy, center->lon, center->lat, ll->lon, ll->lat, vvp->xmpp * ALTI_TO_MPP, vvp->ympp * ALTI_TO_MPP, vvp->width / 2, vvp->height / 2 );
       *x = xx; *y = yy;
-    } else if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_GOOGLE ) {
-      /* google */
-      *x = vvp->google_calcx_fact * (ll->lon - center->lon) + (vvp->width/2);
-      *y = vvp->google_calcy_fact * (center->lat - ll->lat) + (vvp->height/2);
-    } else if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_KH ) {
-      /* subtract, convert to KH coords; blow it up by 256 */
-      *x = vvp->width/2 + (65536.0 / 180 / vvp->xmpp * (ll->lon - center->lon))*256.0;
-      *y = vvp->height/2 + (65536.0 / 180 / vvp->ympp * (center->lat - ll->lat))*256.0;
     } else if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_MERCATOR ) {
       /* FIXMERCATOR: Optimize */
       *x = vvp->width/2 + (65536.0 / 180 / vvp->xmpp * (ll->lon - center->lon))*256.0;
     } else if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_MERCATOR ) {
       /* FIXMERCATOR: Optimize */
       *x = vvp->width/2 + (65536.0 / 180 / vvp->xmpp * (ll->lon - center->lon))*256.0;
@@ -991,8 +993,6 @@ void vik_viewport_set_drawmode ( VikViewport *vvp, VikViewportDrawMode drawmode
     viewport_set_coord_mode ( vvp, VIK_COORD_UTM );
   else {
     viewport_set_coord_mode ( vvp, VIK_COORD_LATLON );
     viewport_set_coord_mode ( vvp, VIK_COORD_UTM );
   else {
     viewport_set_coord_mode ( vvp, VIK_COORD_LATLON );
-    if ( drawmode == VIK_VIEWPORT_DRAWMODE_GOOGLE )
-      viewport_google_rezoom ( vvp );
   }
 }
 
   }
 }
 
@@ -1001,12 +1001,35 @@ VikViewportDrawMode vik_viewport_get_drawmode ( VikViewport *vvp )
   return vvp->drawmode;
 }
 
   return vvp->drawmode;
 }
 
-static void viewport_google_rezoom ( VikViewport *vvp )
+/******** 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 )
 {
 {
-  vvp->google_calcx_fact = (GOOGLEMAPS_ZOOM_ONE_MPP * 65536.0 * 0.7716245833877 / vvp->xmpp);
-  vvp->google_calcy_fact = (GOOGLEMAPS_ZOOM_ONE_MPP * 65536.0 / vvp->ympp);
-  vvp->google_calcx_rev_fact = 1 / vvp->google_calcx_fact;
-  vvp->google_calcy_rev_fact = 1 / vvp->google_calcy_fact;
+  return vp->half_drawn;
 }
 
 
 }