+gboolean draw_buf_done = TRUE;
+
+static gboolean draw_buf(gpointer data)
+{
+ gpointer *pass_along = data;
+ gdk_threads_enter();
+ gdk_draw_drawable (pass_along[0], pass_along[1],
+ pass_along[2], 0, 0, 0, 0, -1, -1);
+ draw_buf_done = TRUE;
+ gdk_threads_leave();
+ return FALSE;
+}
+
+
+/* Mouse event handlers ************************************************************************/
+
+static void draw_click (VikWindow *vw, GdkEventButton *event)
+{
+
+ /* middle button pressed. we reserve all middle button and scroll events
+ * for panning and zooming; tools only get left/right/movement
+ */
+ if ( event->button == 2) {
+ /* set panning origin */
+ vw->pan_x = (gint) event->x;
+ vw->pan_y = (gint) event->y;
+ }
+ else {
+ toolbox_click(vw->vt, event);
+ }
+}
+
+static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
+{
+ static VikCoord coord;
+ static struct UTM utm;
+ static struct LatLon ll;
+ static char pointer_buf[36];
+
+ 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 );
+ vik_statusbar_set_message ( vw->viking_vs, 4, pointer_buf );
+
+ if ( vw->pan_x != -1 ) {
+ vik_viewport_pan_sync ( vw->viking_vvp, event->x - vw->pan_x, event->y - vw->pan_y );
+ }
+}
+
+static void draw_release ( VikWindow *vw, GdkEventButton *event )
+{
+ if ( event->button == 2 ) { /* move / pan */
+ if ( ABS(vw->pan_x - event->x) <= 1 && ABS(vw->pan_y - event->y) <= 1 )
+ vik_viewport_set_center_screen ( vw->viking_vvp, vw->pan_x, vw->pan_y );
+ else
+ vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2 - event->x + vw->pan_x,
+ vik_viewport_get_height(vw->viking_vvp)/2 - event->y + vw->pan_y );
+ draw_update ( vw );
+ vw->pan_x = vw->pan_y = -1;
+ }
+ else {
+ toolbox_release(vw->vt, 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);
+ draw_update(vw);
+}
+
+
+
+/********************************************************************************
+ ** Ruler tool code
+ ********************************************************************************/