/* handles the mouse button being released inside the drawing area calls the apropriate tool function, or none */ static gint button_release_event(GtkWidget *widget, GdkEventButton *event ) { double x, y; if (deleting_placename) { do_delete_placename(current_place); return TRUE; } if (adding_placename) { x = pix_x_to_map(event->x)*map->config.resolution; y = pix_y_to_map(event->y)*map->config.resolution; start_add_placename(x, y); return TRUE; } if (adding_door) { x = pix_x_to_map(event->x)*map->config.resolution; y = pix_y_to_map(event->y)*map->config.resolution; if (adding_door == 2) start_add_door(x, y); else finish_add_door(x, y); return TRUE; } if (event->button == 1 && tmp_pixmap != NULL) switch(utensil) { case CARMEN_MAP_RECTANGLE: creating_rectangle(widget, 2, event->x, event->y); break; case CARMEN_MAP_CROP: cropping(widget, 2, event->x, event->y); break; case CARMEN_MAP_LINE: creating_line(2, event->x, event->y); break; case CARMEN_MAP_MOVER: move(2, event->x, event->y); default: break; } redraw(); return 1; }
/* handles the mouse moving in the drawing area only calls the appropriate tool function if the mouse button is down. always sets the cursor to the appropriate symbol */ static gint motion_notify_event( GtkWidget *widget, GdkEventMotion *event ) { int x, y; GdkModifierType state; static char label_buffer[255]; static carmen_map_point_t map_point; static carmen_world_point_t world_point; gtk_propagate_event(GTK_WIDGET(vrule), (GdkEvent *)event); gtk_propagate_event(GTK_WIDGET(hrule), (GdkEvent *)event); map_to_tmp(); if (event->is_hint) gdk_window_get_pointer (event->window, &x, &y, &state); else { x = event->x; y = event->y; state = event->state; } map_point.x = pix_x_to_map(x); map_point.y = pix_y_to_map(y); map_point.map = map; carmen_map_to_world(&map_point, &world_point); sprintf(label_buffer, "X: %6.2f Y: %6.2f", world_point.pose.x, world_point.pose.y); gtk_label_set_text(GTK_LABEL(coords_label), label_buffer); if (tmp_pixmap == NULL) return TRUE; if (deleting_placename) { handle_deleting_placename_move(map_point.x, map_point.y); } else if ((state & GDK_BUTTON1_MASK)) { switch(utensil) { case CARMEN_MAP_BRUSH: draw_brush (widget, x, y); x = x/mult - brush_size + .5; y = y/mult - brush_size + .5; break; case CARMEN_MAP_RECTANGLE: creating_rectangle(widget, 1, x, y); break; case CARMEN_MAP_CROP: cropping(widget, 1, x, y); break; case CARMEN_MAP_LINE: creating_line(1, x, y); break; case CARMEN_MAP_EYEDROPPER: sample(x, y); break; case CARMEN_MAP_MOVER: move(1, x, y); default: break; } } redraw(); return TRUE; }
* functions to do the actual drawing on the pixmap and float * map * *********************************************************************/ /* draws a square of size 2 * brush_size on a side onto the pixmap and the map */ void draw_brush( GtkWidget *widget __attribute__ ((unused)), gdouble pix_x, gdouble pix_y) { int x_left, y_top, x, y; GdkRectangle update_rect; gdk_gc_set_foreground (drawing_gc, &color); x_left = pix_x_to_map(pix_x) - brush_size + .5; y_top = pix_y_to_map(pix_y) + brush_size + .5; update_rect.x = map_x_to_map_pix(x_left) + 1.0; update_rect.y = map_y_to_map_pix(y_top ) + 1.0; update_rect.width = map_x_to_map_pix((double)(x_left) + brush_size * 2.0) - update_rect.x + 1.0; if(update_rect.width < 1) update_rect.width = 1; update_rect.height = map_y_to_map_pix((double)(y_top ) - brush_size * 2.0) - update_rect.y + 1.0; if(update_rect.height < 1) update_rect.height = 1; gdk_draw_rectangle (map_pixmap, drawing_gc, TRUE, update_rect.x, update_rect.y,