a_datasource_gc_init();
#endif
- vik_layer_cursors_init ();
- vik_window_cursors_init ();
-
/* Set the icon */
main_icon = gdk_pixbuf_from_pixdata(&viking_icon, FALSE, NULL);
gtk_window_set_default_icon(main_icon);
a_mapcache_uninit ();
a_dems_uninit ();
a_preferences_uninit ();
- vik_layer_cursors_uninit ();
- vik_window_cursors_uninit ();
return 0;
}
static VikToolInterface dem_tools[] = {
{ N_("DEM Download/Import"), (VikToolConstructorFunc) dem_layer_download_create, NULL, NULL, NULL,
(VikToolMouseFunc) dem_layer_download_click, NULL, (VikToolMouseFunc) dem_layer_download_release,
- (VikToolKeyFunc) NULL, &cursor_demdl },
+ (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_demdl },
};
static VikToolInterface georef_tools[] = {
{ N_("Georef Move Map"), (VikToolConstructorFunc) georef_layer_move_create, NULL, NULL, NULL,
(VikToolMouseFunc) georef_layer_move_press, NULL, (VikToolMouseFunc) georef_layer_move_release,
- (VikToolKeyFunc) NULL, &cursor_geomove },
+ (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_geomove },
{ N_("Georef Zoom Tool"), (VikToolConstructorFunc) georef_layer_zoom_create, NULL, NULL, NULL,
(VikToolMouseFunc) georef_layer_zoom_press, NULL, NULL,
- (VikToolKeyFunc) NULL, &cursor_geozoom },
+ (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_geozoom },
};
VikLayerInterface vik_georef_layer_interface = {
}
}
-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 move;
VikToolMouseFunc release;
VikToolKeyFunc key_press; /* return FALSE if we don't use the key press -- should return AFLSE most of the time if we want any shortcuts / UI keybindings to work! use sparingly. */
- const GdkPixdata *cursor;
+ GdkCursorType cursor_type;
+ const GdkPixdata *cursor_data;
+ const GdkCursor *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
static VikToolInterface maps_tools[] = {
{ N_("Maps Download"), (VikToolConstructorFunc) maps_layer_download_create, NULL, NULL, NULL,
(VikToolMouseFunc) maps_layer_download_click, NULL, (VikToolMouseFunc) maps_layer_download_release,
- (VikToolKeyFunc) NULL, &cursor_mapdl },
+ (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_mapdl },
};
VikLayerInterface vik_maps_layer_interface = {
static VikToolInterface trw_layer_tools[] = {
{ N_("Create Waypoint"), (VikToolConstructorFunc) tool_new_waypoint_create, NULL, NULL, NULL,
- (VikToolMouseFunc) tool_new_waypoint_click, NULL, NULL, (VikToolKeyFunc) NULL, &cursor_addwp },
+ (VikToolMouseFunc) tool_new_waypoint_click, NULL, NULL, (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_addwp },
{ N_("Create Track"), (VikToolConstructorFunc) tool_new_track_create, NULL, NULL, NULL,
(VikToolMouseFunc) tool_new_track_click, (VikToolMouseFunc) tool_new_track_move, NULL,
- (VikToolKeyFunc) tool_new_track_key_press, &cursor_addtr },
+ (VikToolKeyFunc) tool_new_track_key_press, GDK_CURSOR_IS_PIXMAP, &cursor_addtr },
{ N_("Begin Track"), (VikToolConstructorFunc) tool_begin_track_create, NULL, NULL, NULL,
- (VikToolMouseFunc) tool_begin_track_click, NULL, NULL, (VikToolKeyFunc) NULL, &cursor_begintr },
+ (VikToolMouseFunc) tool_begin_track_click, NULL, NULL, (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_begintr },
{ N_("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, (VikToolKeyFunc) NULL, &cursor_edwp },
+ (VikToolMouseFunc) tool_edit_waypoint_release, (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_edwp },
{ N_("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, (VikToolKeyFunc) NULL, &cursor_edtr },
+ (VikToolMouseFunc) tool_edit_trackpoint_release, (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_edtr },
{ N_("Show Picture"), (VikToolConstructorFunc) tool_show_picture_create, NULL, NULL, NULL,
- (VikToolMouseFunc) tool_show_picture_click, NULL, NULL, (VikToolKeyFunc) NULL, &cursor_showpic },
+ (VikToolMouseFunc) tool_show_picture_click, NULL, NULL, (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_showpic },
{ N_("Magic Scissors"), (VikToolConstructorFunc) tool_magic_scissors_create, NULL, NULL, NULL,
- (VikToolMouseFunc) tool_magic_scissors_click, NULL, NULL, (VikToolKeyFunc) NULL, &cursor_iscissors },
+ (VikToolMouseFunc) tool_magic_scissors_click, NULL, NULL, (VikToolKeyFunc) NULL, GDK_CURSOR_IS_PIXMAP, &cursor_iscissors },
};
enum { TOOL_CREATE_WAYPOINT=0, TOOL_CREATE_TRACK, TOOL_BEGIN_TRACK, TOOL_EDIT_WAYPOINT, TOOL_EDIT_TRACKPOINT, TOOL_SHOW_PICTURE, NUM_TOOLS };
#include "dems.h"
#include "print.h"
#include "preferences.h"
+#include "icons/icons.h"
#include <stdlib.h>
#include <math.h>
static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type );
static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name);
static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name);
+static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name);
static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event);
static void toolbox_move (toolbox_tools_t *vt, GdkEventButton *event);
static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event);
static gchar *tool_names[NUMBER_OF_TOOLS] = { N_("Pan"), N_("Zoom"), N_("Ruler") };
-GdkCursor *vw_cursor_pan = NULL;
-GdkCursor *vw_cursor_zoom = NULL;
-GdkCursor *vw_cursor_ruler = NULL;
-
GType vik_window_get_type (void)
{
static GType vw_type = 0;
static void window_configure_event ( VikWindow *vw )
{
- static first = 1;
+ static int first = 1;
draw_redraw ( vw );
if (first) {
// This is a hack to set the cursor corresponding to the first tool
// FIXME find the correct way to initialize both tool and its cursor
+ const GdkCursor *cursor = NULL;
first = 0;
- gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_pan );
+ cursor = toolbox_get_cursor(vw->vt, "Pan");
+ /* We set cursor, even if it is NULL: it resets to default */
+ gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, cursor );
}
}
(VikToolActivationFunc) ruler_deactivate,
(VikToolMouseFunc) ruler_click,
(VikToolMouseFunc) ruler_move,
- (VikToolMouseFunc) ruler_release };
+ (VikToolMouseFunc) ruler_release,
+ NULL,
+ GDK_CURSOR_IS_PIXMAP,
+ &cursor_ruler };
/*** end ruler code ********************************************************/
(VikToolActivationFunc) NULL,
(VikToolMouseFunc) zoomtool_click,
(VikToolMouseFunc) zoomtool_move,
- (VikToolMouseFunc) zoomtool_release };
+ (VikToolMouseFunc) zoomtool_release,
+ NULL,
+ GDK_CURSOR_IS_PIXMAP,
+ &cursor_zoom };
/*** end zoom code ********************************************************/
/********************************************************************************
(VikToolActivationFunc) NULL,
(VikToolMouseFunc) pantool_click,
(VikToolMouseFunc) pantool_move,
- (VikToolMouseFunc) pantool_release };
+ (VikToolMouseFunc) pantool_release,
+ NULL,
+ GDK_FLEUR };
/*** end pan code ********************************************************/
static void draw_pan_cb ( GtkAction *a, VikWindow *vw )
vt->active_tool = tool;
}
+static const GdkCursor *toolbox_get_cursor(toolbox_tools_t *vt, const gchar *tool_name)
+{
+ int tool = toolbox_get_tool(vt, tool_name);
+ toolbox_tool_t *t = &vt->tools[tool];
+ if (t->ti.cursor == NULL) {
+ if (t->ti.cursor_type == GDK_CURSOR_IS_PIXMAP && t->ti.cursor_data != NULL) {
+ GError *cursor_load_err = NULL;
+ GdkPixbuf *cursor_pixbuf = gdk_pixbuf_from_pixdata (t->ti.cursor_data, FALSE, &cursor_load_err);
+ /* TODO: settable offeset */
+ t->ti.cursor = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 3, 3 );
+ g_object_unref ( G_OBJECT(cursor_pixbuf) );
+ } else {
+ t->ti.cursor = gdk_cursor_new ( t->ti.cursor_type );
+ }
+ }
+ return t->ti.cursor;
+}
+
static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event)
{
VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
{
/* White Magic, my friends ... White Magic... */
int layer_id, tool_id;
+ const GdkCursor *cursor = NULL;
toolbox_activate(vw->vt, gtk_action_get_name(a));
+ cursor = toolbox_get_cursor(vw->vt, gtk_action_get_name(a));
+ /* We set cursor, even if it is NULL: it resets to default */
+ gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, cursor );
+
if (!strcmp(gtk_action_get_name(a), "Pan")) {
vw->current_tool = TOOL_PAN;
- gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_pan );
}
else 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 = layer_id;
vw->tool_tool_id = tool_id;
- gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vik_layer_get_tool_cursor ( layer_id, tool_id ) );
}
}
}
-#include "icons/icons.h"
static struct {
const GdkPixdata *data;
gchar *stock_id;
}
}
-void vik_window_cursors_init()
-{
- GdkPixbuf *cursor_pixbuf;
- GError *cursor_load_err;
-
- vw_cursor_pan = gdk_cursor_new(GDK_FLEUR);
-
- 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_pan );
- 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();
-
void vik_window_enable_layer_tool ( VikWindow *vw, gint layer_id, gint tool_id );
G_END_DECLS