static gboolean _view_map_motion_notify_callback(GtkWidget *w, GdkEventMotion *e, dt_view_t *self) { dt_map_t *lib = (dt_map_t*)self->data; const int ts = 64; if(lib->start_drag && lib->selected_image > 0) { for(GSList *iter = lib->images; iter != NULL; iter = iter->next) { dt_map_image_t *entry = (dt_map_image_t*)iter->data; OsmGpsMapImage *image = entry->image; if(entry->imgid == lib->selected_image) { osm_gps_map_image_remove(lib->map, image); break; } } lib->start_drag = FALSE; GtkTargetList *targets = gtk_target_list_new(target_list_all, n_targets_all); dt_mipmap_buffer_t buf; dt_mipmap_size_t mip = dt_mipmap_cache_get_matching_size(darktable.mipmap_cache, ts, ts); dt_mipmap_cache_read_get(darktable.mipmap_cache, &buf, lib->selected_image, mip, DT_MIPMAP_BLOCKING); if(buf.buf) { uint8_t *scratchmem = dt_mipmap_cache_alloc_scratchmem(darktable.mipmap_cache); uint8_t *buf_decompressed = dt_mipmap_cache_decompress(&buf, scratchmem); uint8_t *rgbbuf = g_malloc((buf.width+2)*(buf.height+2)*3); memset(rgbbuf, 64, (buf.width+2)*(buf.height+2)*3); for(int i=1; i<=buf.height; i++) for(int j=1; j<=buf.width; j++) for(int k=0; k<3; k++) rgbbuf[(i*(buf.width+2)+j)*3+k] = buf_decompressed[((i-1)*buf.width+j-1)*4+2-k]; int w=ts, h=ts; if(buf.width < buf.height) w = (buf.width*ts)/buf.height; // portrait else h = (buf.height*ts)/buf.width; // landscape GdkPixbuf *source = gdk_pixbuf_new_from_data(rgbbuf, GDK_COLORSPACE_RGB, FALSE, 8, (buf.width+2), (buf.height+2), (buf.width+2)*3, NULL, NULL); GdkPixbuf *scaled = gdk_pixbuf_scale_simple(source, w, h, GDK_INTERP_HYPER); GdkDragContext * context = gtk_drag_begin(GTK_WIDGET(lib->map), targets, GDK_ACTION_COPY, 1, (GdkEvent*)e); gtk_drag_set_icon_pixbuf(context, scaled, 0, 0); if(source) g_object_unref(source); if(scaled) g_object_unref(scaled); g_free(rgbbuf); } dt_mipmap_cache_read_release(darktable.mipmap_cache, &buf); gtk_target_list_unref(targets); return TRUE; } return FALSE; }
static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data) { OsmGpsMapPoint coord; float lat, lon; OsmGpsMap *map = OSM_GPS_MAP(widget); OsmGpsMapTrack *othertrack = OSM_GPS_MAP_TRACK(user_data); if (event->type == GDK_3BUTTON_PRESS) { if (event->button == 1) { if (g_last_image) osm_gps_map_image_remove (map, g_last_image); } if (event->button == 3) { osm_gps_map_track_remove(map, othertrack); } } if (event->type == GDK_2BUTTON_PRESS) { osm_gps_map_convert_screen_to_geographic(map, event->x, event->y, &coord); osm_gps_map_point_get_degrees(&coord, &lat, &lon); if (event->button == 1) { osm_gps_map_gps_add (map, lat, lon, g_random_double_range(0,360)); } if (event->button == 3) { osm_gps_map_track_add_point(othertrack, &coord); } } if (event->type == GDK_BUTTON_PRESS) { if (event->button == 2) { osm_gps_map_convert_screen_to_geographic(map, event->x, event->y, &coord); osm_gps_map_point_get_degrees(&coord, &lat, &lon); g_last_image = osm_gps_map_image_add ( map, lat, lon, g_star_image); } } return FALSE; }