]> git.street.me.uk Git - andy/viking.git/commitdiff
Cursors!
authorEvan Battaglia <gtoevan@gmx.net>
Sun, 7 Oct 2007 21:01:58 +0000 (21:01 +0000)
committerEvan Battaglia <gtoevan@gmx.net>
Sun, 7 Oct 2007 21:01:58 +0000 (21:01 +0000)
23 files changed:
ChangeLog
src/icons/Makefile.am
src/icons/cursor_addtr.png [new file with mode: 0644]
src/icons/cursor_addwp.png [new file with mode: 0644]
src/icons/cursor_demdl.png [new file with mode: 0644]
src/icons/cursor_edtr.png [new file with mode: 0644]
src/icons/cursor_edwp.png [new file with mode: 0644]
src/icons/cursor_geomove.png [new file with mode: 0644]
src/icons/cursor_geozoom.png [new file with mode: 0644]
src/icons/cursor_iscissors.png [new file with mode: 0644]
src/icons/cursor_mapdl.png [new file with mode: 0644]
src/icons/cursor_ruler.png [new file with mode: 0644]
src/icons/cursor_showpic.png [new file with mode: 0644]
src/icons/cursor_zoom.png [new file with mode: 0644]
src/main.c
src/vikdemlayer.c
src/vikgeoreflayer.c
src/viklayer.c
src/viklayer.h
src/vikmapslayer.c
src/viktrwlayer.c
src/vikwindow.c
src/vikwindow.h

index e1aa0183c322337c1ac0ca11e8cf4732d6e59c77..b2a87905c3bbd05db06b88a69dc198f974945530 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2007-10-07
 Evan Battaglia <gtoevan@gmx.net>:
        * Scroll zoom keeps cursor over same spot on map (like Google, QLandKarte)
+       * Cursors for tools.
 
 Quy Tonthat <qtonthat@gmail.com>:
        * Correctly calculate position (based on time instead of distance)
index ff2f1aa0cb2aacdc18129c37edbcdcf9173f9342..d93f409f2309131adf455b225b168ab6ef2464b0 100644 (file)
@@ -95,7 +95,20 @@ ICONS = \
   zoom_18.png \
   iscissors_18.png
 
-ALL_ICONS = $(ICONS) $(WAYPOINT_ICONS)
+CURSORS = \
+  cursor_addtr.png \
+  cursor_edtr.png \
+  cursor_geozoom.png \
+  cursor_ruler.png \
+  cursor_addwp.png \
+  cursor_edwp.png \
+  cursor_iscissors.png \
+  cursor_showpic.png \
+  cursor_demdl.png \
+  cursor_geomove.png \
+  cursor_mapdl.png
+
+ALL_ICONS = $(ICONS) $(WAYPOINT_ICONS) $(CURSORS)
 EXTRA_DIST = $(ALL_ICONS)
 
 BUILT_SOURCES = $(EXTRA_DIST:%.png=%.png_h) icons.h
diff --git a/src/icons/cursor_addtr.png b/src/icons/cursor_addtr.png
new file mode 100644 (file)
index 0000000..5bd4d59
Binary files /dev/null and b/src/icons/cursor_addtr.png differ
diff --git a/src/icons/cursor_addwp.png b/src/icons/cursor_addwp.png
new file mode 100644 (file)
index 0000000..b3fe726
Binary files /dev/null and b/src/icons/cursor_addwp.png differ
diff --git a/src/icons/cursor_demdl.png b/src/icons/cursor_demdl.png
new file mode 100644 (file)
index 0000000..c03b52b
Binary files /dev/null and b/src/icons/cursor_demdl.png differ
diff --git a/src/icons/cursor_edtr.png b/src/icons/cursor_edtr.png
new file mode 100644 (file)
index 0000000..4b28d30
Binary files /dev/null and b/src/icons/cursor_edtr.png differ
diff --git a/src/icons/cursor_edwp.png b/src/icons/cursor_edwp.png
new file mode 100644 (file)
index 0000000..d8f1f8f
Binary files /dev/null and b/src/icons/cursor_edwp.png differ
diff --git a/src/icons/cursor_geomove.png b/src/icons/cursor_geomove.png
new file mode 100644 (file)
index 0000000..09a8a73
Binary files /dev/null and b/src/icons/cursor_geomove.png differ
diff --git a/src/icons/cursor_geozoom.png b/src/icons/cursor_geozoom.png
new file mode 100644 (file)
index 0000000..dfe1987
Binary files /dev/null and b/src/icons/cursor_geozoom.png differ
diff --git a/src/icons/cursor_iscissors.png b/src/icons/cursor_iscissors.png
new file mode 100644 (file)
index 0000000..2f5b072
Binary files /dev/null and b/src/icons/cursor_iscissors.png differ
diff --git a/src/icons/cursor_mapdl.png b/src/icons/cursor_mapdl.png
new file mode 100644 (file)
index 0000000..df20a9e
Binary files /dev/null and b/src/icons/cursor_mapdl.png differ
diff --git a/src/icons/cursor_ruler.png b/src/icons/cursor_ruler.png
new file mode 100644 (file)
index 0000000..1c34ad8
Binary files /dev/null and b/src/icons/cursor_ruler.png differ
diff --git a/src/icons/cursor_showpic.png b/src/icons/cursor_showpic.png
new file mode 100644 (file)
index 0000000..c97f41a
Binary files /dev/null and b/src/icons/cursor_showpic.png differ
diff --git a/src/icons/cursor_zoom.png b/src/icons/cursor_zoom.png
new file mode 100644 (file)
index 0000000..243849d
Binary files /dev/null and b/src/icons/cursor_zoom.png differ
index ad4bcabb0e1ceee32a38ca85e0a287c6f6b10d13..664ebc74ee7495373b21db6d65ac85b8464db26f 100644 (file)
@@ -127,6 +127,8 @@ int main( int argc, char *argv[] )
 
   a_mapcache_init ();
   a_background_init ();
+  vik_layer_cursors_init ();
+  vik_window_cursors_init ();
 
   /* Set the icon */
   main_icon = gdk_pixbuf_from_pixdata(&viking_icon, FALSE, NULL);
@@ -148,6 +150,8 @@ int main( int argc, char *argv[] )
 
   a_mapcache_uninit ();
   a_dems_uninit ();
+  vik_layer_cursors_uninit ();
+  vik_window_cursors_uninit ();
 
   return 0;
 }
index 26ac23de31daddf250501466517e36d669edaabb..824d184a054db60b30c94353fd7d02d523489cdd 100644 (file)
@@ -45,6 +45,8 @@
 #include "dem.h"
 #include "dems.h"
 
+#include "icons/icons.h"
+
 #define MAPS_CACHE_DIR maps_layer_default_dir()
 
 #define SRTM_CACHE_TEMPLATE "%ssrtm3-%s%s%c%02d%c%03d.hgt.zip"
@@ -107,7 +109,8 @@ static gboolean dem_layer_download_click ( VikDEMLayer *vdl, GdkEventButton *eve
 
 static VikToolInterface dem_tools[] = {
   { "DEM Download/Import", (VikToolConstructorFunc) dem_layer_download_create, NULL, NULL, NULL,
-    (VikToolMouseFunc) dem_layer_download_click, NULL,  (VikToolMouseFunc) dem_layer_download_release },
+    (VikToolMouseFunc) dem_layer_download_click, NULL,  (VikToolMouseFunc) dem_layer_download_release,
+    &cursor_demdl },
 };
 
 
index 4ba541a86b2b128697ad60041431a51bb181ec03..ec370b5ef1e8ba91747ea73bfc077b1286b95319 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "icons/icons.h"
+
 VikLayerParam georef_layer_params[] = {
   { "image", VIK_LAYER_PARAM_STRING, VIK_LAYER_NOT_IN_PROPERTIES },
   { "corner_easting", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_NOT_IN_PROPERTIES },
@@ -57,10 +59,12 @@ static gboolean georef_layer_zoom_press ( VikGeorefLayer *vgl, GdkEventButton *e
 
 static VikToolInterface georef_tools[] = {
   { "Georef Move Map", (VikToolConstructorFunc) georef_layer_move_create, NULL, NULL, NULL,
-    (VikToolMouseFunc) georef_layer_move_press, NULL, (VikToolMouseFunc) georef_layer_move_release },
+    (VikToolMouseFunc) georef_layer_move_press, NULL, (VikToolMouseFunc) georef_layer_move_release,
+    &cursor_geomove },
 
   { "Georef Zoom Tool", (VikToolConstructorFunc) georef_layer_zoom_create, NULL, NULL, NULL,
-    (VikToolMouseFunc) georef_layer_zoom_press, NULL, NULL },
+    (VikToolMouseFunc) georef_layer_zoom_press, NULL, NULL,
+    &cursor_geozoom },
 };
 
 VikLayerInterface vik_georef_layer_interface = {
index 83547187c9e5e361c22e29cbf6573bd1849444a3..d7a6c0472fa75cfcb52cb7887d7dd52ee2fd889b 100644 (file)
@@ -743,3 +743,55 @@ static gboolean layer_properties_factory ( VikLayer *vl, VikViewport *vp )
     return FALSE;
   }
 }
+
+static GdkCursor ***layers_cursors;
+
+GdkCursor *vik_layer_get_tool_cursor ( gint layer_id, gint tool_id )
+{
+  if ( layer_id >= VIK_LAYER_NUM_TYPES )
+    return NULL;
+  if ( tool_id >= vik_layer_interfaces[layer_id]->tools_count )
+    return NULL;
+  return layers_cursors[layer_id][tool_id];
+}
+
+void vik_layer_cursors_init()
+{
+  gint i, j;
+  layers_cursors = g_malloc ( sizeof(GdkCursor **) * VIK_LAYER_NUM_TYPES );
+  for ( i = 0 ; i < VIK_LAYER_NUM_TYPES; i++ ) {
+    if ( vik_layer_interfaces[i]->tools_count ) {
+      layers_cursors[i] = g_malloc ( sizeof(GdkCursor *) *  vik_layer_interfaces[i]->tools_count );
+      for ( j = 0; j < vik_layer_interfaces[i]->tools_count; j++ ) {
+        if ( vik_layer_interfaces[i]->tools[j].cursor ) {
+          const GdkPixdata *cursor_pixdata = vik_layer_interfaces[i]->tools[j].cursor;
+          GError *cursor_load_err = NULL;
+          GdkPixbuf *cursor_pixbuf = gdk_pixbuf_from_pixdata (cursor_pixdata, FALSE, &cursor_load_err);
+          /* TODO: settable offeset */
+          GdkCursor *cursor = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 3, 3 );
+          layers_cursors[i][j] = cursor;
+
+          g_object_unref ( G_OBJECT(cursor_pixbuf) );
+        }
+        else
+          layers_cursors[i][j] = NULL;
+      }
+    } else
+      layers_cursors[i] = NULL;
+  }
+}
+
+void vik_layer_cursors_uninit()
+{
+  gint i, j;
+  for ( i = 0 ; i < VIK_LAYER_NUM_TYPES; i++ ) {
+    if ( vik_layer_interfaces[i]->tools_count ) {
+      for ( j = 0; j < vik_layer_interfaces[i]->tools_count; j++ ) {
+        if ( layers_cursors[i][j] )
+          gdk_cursor_unref ( layers_cursors[i][j] );
+      }
+      g_free ( layers_cursors[i] );
+    }
+  }
+  g_free ( layers_cursors );
+}
index cfb5a5ee52ff0abb2c54e61db2ae5fb2edb5b045..26ce446400230726a88b94c4774657c6bf076d0a 100644 (file)
@@ -97,6 +97,7 @@ struct _VikToolInterface {
   VikToolMouseFunc click;
   VikToolMouseFunc move;
   VikToolMouseFunc release;
+  const GdkPixdata *cursor;
 };
 
 /* Parameters (for I/O and Properties) */
@@ -328,4 +329,11 @@ VikLayer *vik_layer_get_and_reset_trigger();
 void vik_layer_emit_update_secondary ( VikLayer *vl ); /* to be called by aggregate layer only. doesn't set the trigger */
 void vik_layer_emit_update_although_invisible ( VikLayer *vl );
 
+GdkCursor *vik_layer_get_tool_cursor ( gint layer_id, gint tool_id );
+void vik_layer_cursors_init();
+void vik_layer_cursors_uninit();
+
+
+
+
 #endif
index a1ee1a5b0399414fbf2355840636d6082b9d2796..519441535dae843c2ddc711edb5b09b587a6412d 100644 (file)
@@ -58,6 +58,8 @@
 #include "mapcoord.h"
 #include "terraserver.h"
 
+#include "icons/icons.h"
+
 /****** MAP TYPES ******/
 
 static GList *__map_types = NULL;
@@ -114,7 +116,8 @@ enum { PARAM_MAPTYPE=0, PARAM_CACHE_DIR, PARAM_ALPHA, PARAM_AUTODOWNLOAD, PARAM_
 
 static VikToolInterface maps_tools[] = {
   { "Maps Download", (VikToolConstructorFunc) maps_layer_download_create, NULL, NULL, NULL,  
-    (VikToolMouseFunc) maps_layer_download_click, NULL,  (VikToolMouseFunc) maps_layer_download_release },
+    (VikToolMouseFunc) maps_layer_download_click, NULL,  (VikToolMouseFunc) maps_layer_download_release,
+    &cursor_mapdl },
 };
 
 VikLayerInterface vik_maps_layer_interface = {
index 3f665b8a4434b94d708c34543bed32f9f96b4b61..b6c815f55d02d724d69f22909b9e4d39fc0034cf 100644 (file)
@@ -44,6 +44,8 @@
 #include "osm-traces.h"
 #endif
 
+#include "icons/icons.h"
+
 #include <math.h>
 #include <string.h>
 #include <stdlib.h>
@@ -268,26 +270,26 @@ static void track_convert ( const gchar *name, VikTrack *tr, VikCoordMode *dest_
 
 static VikToolInterface trw_layer_tools[] = {
   { "Create Waypoint", (VikToolConstructorFunc) tool_new_waypoint_create,    NULL, NULL, NULL, 
-    (VikToolMouseFunc) tool_new_waypoint_click,    NULL, NULL },
+    (VikToolMouseFunc) tool_new_waypoint_click,    NULL, NULL, &cursor_addwp },
 
   { "Create Track",    (VikToolConstructorFunc) tool_new_track_create,       NULL, NULL, NULL, 
-    (VikToolMouseFunc) tool_new_track_click,       NULL, NULL },
+    (VikToolMouseFunc) tool_new_track_click,       NULL, NULL, &cursor_addtr },
 
   { "Edit Waypoint",   (VikToolConstructorFunc) tool_edit_waypoint_create,   NULL, NULL, NULL, 
     (VikToolMouseFunc) tool_edit_waypoint_click,   
     (VikToolMouseFunc) tool_edit_waypoint_move,
-    (VikToolMouseFunc) tool_edit_waypoint_release },
+    (VikToolMouseFunc) tool_edit_waypoint_release, &cursor_edwp },
 
   { "Edit Trackpoint", (VikToolConstructorFunc) tool_edit_trackpoint_create, NULL, NULL, NULL, 
     (VikToolMouseFunc) tool_edit_trackpoint_click,
     (VikToolMouseFunc) tool_edit_trackpoint_move,
-    (VikToolMouseFunc) tool_edit_trackpoint_release },
+    (VikToolMouseFunc) tool_edit_trackpoint_release, &cursor_edtr },
 
   { "Show Picture",    (VikToolConstructorFunc) tool_show_picture_create,    NULL, NULL, NULL, 
-    (VikToolMouseFunc) tool_show_picture_click,    NULL, NULL },
+    (VikToolMouseFunc) tool_show_picture_click,    NULL, NULL, &cursor_showpic },
 
   { "Magic Scissors",  (VikToolConstructorFunc) tool_magic_scissors_create,  NULL, NULL, NULL,
-    (VikToolMouseFunc) tool_magic_scissors_click, NULL, NULL },
+    (VikToolMouseFunc) tool_magic_scissors_click, NULL, NULL, &cursor_iscissors },
 };
 
 /****** PARAMETERS ******/
index eae61d96c6ff198ea4a825d22f2e1b9e97fd50db..1b098ab1e2741cc7a2f3b7eb737c5a14ee524edb 100644 (file)
@@ -62,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 );
@@ -169,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;
@@ -228,6 +232,7 @@ static void window_finalize ( GObject *gob )
   G_OBJECT_CLASS(parent_class)->finalize(gob);
 }
 
+
 static void window_class_init ( VikWindowClass *klass )
 {
   /* destructor */
@@ -285,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);
@@ -377,6 +382,13 @@ void vik_window_set_redraw_trigger(VikLayer *vl)
   vw->trigger = vl;
 }
 
+static void window_configure_event ( VikWindow *vw )
+{
+  g_print ("debug\n");
+  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;
@@ -1089,9 +1101,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 */
@@ -1101,6 +1115,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 ) );
        }
       }
     }
@@ -1928,3 +1943,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 );
+}
index 24d20f57e71fa78d646ccc16da911856e4dd4176..d7b32d56711f91c0eae64ad7b1937589fae8a53f 100644 (file)
@@ -57,6 +57,10 @@ void vik_window_selected_layer(VikWindow *vw, struct _VikLayer *vl);
 struct _VikViewport * vik_window_viewport(VikWindow *vw);
 void vik_window_set_redraw_trigger(struct _VikLayer *vl);
 
+void vik_window_cursors_init();
+void vik_window_cursors_uninit();
+
+
 G_END_DECLS
 
 #define VIK_WINDOW_FROM_WIDGET(x) VIK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(x)))