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)
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
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);
a_mapcache_uninit ();
a_dems_uninit ();
+ vik_layer_cursors_uninit ();
+ vik_window_cursors_uninit ();
return 0;
}
#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"
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 },
};
#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 },
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 = {
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 );
+}
VikToolMouseFunc click;
VikToolMouseFunc move;
VikToolMouseFunc release;
+ const GdkPixdata *cursor;
};
/* Parameters (for I/O and Properties) */
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
#include "mapcoord.h"
#include "terraserver.h"
+#include "icons/icons.h"
+
/****** MAP TYPES ******/
static GList *__map_types = NULL;
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 = {
#include "osm-traces.h"
#endif
+#include "icons/icons.h"
+
#include <math.h>
#include <string.h>
#include <stdlib.h>
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 ******/
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 );
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;
G_OBJECT_CLASS(parent_class)->finalize(gob);
}
+
static void window_class_init ( VikWindowClass *klass )
{
/* destructor */
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);
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;
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 */
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 ) );
}
}
}
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 );
+}
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)))