static TEG_STATUS canvas_create_countries( GnomeCanvasGroup *group) { int i=0; for(i=0;i<CONT_CANT;i++) G_cont_create(i,group); for(i=0;i<COUNTRIES_CANT;i++) { G_country_create(i); G_country_draw(i); G_country_draw_ejer(i); } /* Pone a los ejercitos arriba de todo */ #if 0 for(i=0;i<n;i++) { if( G_countries[i].ellip_item) gnome_canvas_item_raise_to_top ( G_countries[i].ellip_item ); if( G_countries[i].text_item) gnome_canvas_item_raise_to_top ( G_countries[i].text_item ); } #endif return TEG_STATUS_SUCCESS; }
void ghack_map_print_glyph(GtkObject *win, guint x, guint y, GdkImlibImage *im, gpointer data) { GnomeCanvasGroup *group; int i = y * COLNO + x; int glyph = glyph_at(x, y); GnomeCanvasImage *canvas_image = GNOME_CANVAS_IMAGE(ghack_map.map[i]); group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)); gnome_canvas_item_set(GNOME_CANVAS_ITEM(canvas_image), "image", im, NULL); gnome_canvas_item_show(GNOME_CANVAS_ITEM(canvas_image)); canvas_image = GNOME_CANVAS_IMAGE(ghack_map.overlay[i]); if (x == u.ux && y == u.uy) ghack_map_cliparound(NULL, x, y, NULL); if (glyph_is_pet(glyph) #ifdef TEXTCOLOR && iflags.hilite_pet #endif ) { gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(canvas_image)); gnome_canvas_item_show(GNOME_CANVAS_ITEM(canvas_image)); } else { gnome_canvas_item_hide(GNOME_CANVAS_ITEM(canvas_image)); } }
void ghack_map_cursor_to(GtkWidget *win, int x, int y, gpointer data) { GnomeCanvasGroup *group; static GnomeCanvasRE *cursor = NULL; double x1, y1, x2, y2; float hp; guint r, g, b; x1 = x * ghack_glyph_width() - 1; y1 = y * ghack_glyph_height() - 1; x2 = x1 + ghack_glyph_width() + 2; y2 = y1 + ghack_glyph_height() + 2; hp = u.mtimedone ? (u.mhmax ? (float) u.mh / u.mhmax : 1) : (u.uhpmax ? (float) u.uhp / u.uhpmax : 1); r = 255; g = (hp >= 0.75) ? 255 : (hp >= 0.25 ? 255 * 2 * (hp - 0.25) : 0); b = (hp >= 0.75) ? 255 * 4 * (hp - 0.75) : (hp >= 0.25 ? 0 : 255 * 4 * (0.25 - hp)); group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)); if (!cursor) { cursor = GNOME_CANVAS_RE(gnome_canvas_item_new( group, gnome_canvas_rect_get_type(), "width_units", 1.0, NULL)); } gnome_canvas_item_set(GNOME_CANVAS_ITEM(cursor), "outline_color_rgba", GNOME_CANVAS_COLOR(r, g, b), "x1", x1, "y1", y1, "x2", x2, "y2", y2, NULL); gnome_canvas_item_raise_to_top(GNOME_CANVAS_ITEM(cursor)); gnome_canvas_item_show(GNOME_CANVAS_ITEM(cursor)); }
static gboolean bst_canvas_link_child_event (GnomeCanvasItem *item, GdkEvent *event) { BstCanvasLink *clink; GtkWidget *widget = GTK_WIDGET (item->canvas); gboolean handled = FALSE; clink = BST_CANVAS_LINK (item); switch (event->type) { case GDK_ENTER_NOTIFY: if (!GTK_WIDGET_HAS_FOCUS (widget)) gtk_widget_grab_focus (widget); handled = TRUE; break; case GDK_LEAVE_NOTIFY: handled = TRUE; break; case GDK_KEY_PRESS: switch (event->key.keyval) { case 'L': gnome_canvas_item_lower (item, 1); GNOME_CANVAS_NOTIFY (item); break; case 'l': gnome_canvas_item_lower_to_bottom (item); GNOME_CANVAS_NOTIFY (item); break; case 'R': gnome_canvas_item_raise (item, 1); GNOME_CANVAS_NOTIFY (item); break; case 'r': gnome_canvas_item_raise_to_top (item); GNOME_CANVAS_NOTIFY (item); break; } handled = TRUE; break; case GDK_KEY_RELEASE: handled = TRUE; break; default: break; } return handled; }
static void bst_canvas_link_update (BstCanvasLink *clink) { GnomeCanvasItem *item = GNOME_CANVAS_ITEM (clink); if (clink->line) { gdouble start_x = 0, start_y = 0, end_x = 10, end_y = 10; if (clink->ocsource) { bst_canvas_source_ochannel_pos (clink->ocsource, clink->ochannel, &start_x, &start_y); gnome_canvas_item_w2i (item, &start_x, &start_y); } if (clink->icsource) { bst_canvas_source_ichannel_pos (clink->icsource, clink->ichannel, &end_x, &end_y); gnome_canvas_item_w2i (item, &end_x, &end_y); } GnomeCanvasPoints *gpoints = gnome_canvas_points_new (2); gpoints->coords[0] = start_x; gpoints->coords[1] = start_y; gpoints->coords[2] = end_x; gpoints->coords[3] = end_y; g_object_set (clink->line, "points", gpoints, NULL); gnome_canvas_points_free (gpoints); } if (clink->tag_start) gnome_canvas_item_raise_to_top (clink->tag_start); if (clink->tag_end) gnome_canvas_item_raise_to_top (clink->tag_end); if (clink->ocsource && clink->icsource) gnome_canvas_item_keep_above (GNOME_CANVAS_ITEM (clink), GNOME_CANVAS_ITEM (clink->ocsource), GNOME_CANVAS_ITEM (clink->icsource)); bst_canvas_link_adjust_tags (clink); bst_canvas_link_adjust_arrow (clink); }
static gint zenity_move_clothes_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) { static double x, y; double new_x, new_y; static int dragging; double item_x, item_y; /* set item_[xy] to the event x,y position in the parent's * item-relative coordinates */ item_x = event->button.x; item_y = event->button.y; gnome_canvas_item_w2i (item->parent, &item_x, &item_y); switch (event->type) { case GDK_BUTTON_PRESS: x = item_x; y = item_y; gnome_canvas_item_ungrab (item, event->button.time); gnome_canvas_item_raise_to_top (item); dragging = TRUE; break; case GDK_MOTION_NOTIFY: if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { new_x = item_x; new_y = item_y; gnome_canvas_item_move (item, new_x - x, new_y - y); x = new_x; y = new_y; } break; case GDK_BUTTON_RELEASE: gnome_canvas_item_ungrab (item, event->button.time); dragging = FALSE; break; default: break; } return FALSE; }
static int itemRaise( Tcl_Interp *interp, int objc, Tcl_Obj * const objv[], CanvasParams *param, GPtrArray *items, int isRaise ) { int k; int position = 0; if( objc == 4 ) { if( Tcl_GetIntFromObj( interp, objv[3], &position ) != TCL_OK ) return TCL_ERROR; if( position == 0 ) return TCL_OK; if( position < 0 ) { position *= -1; isRaise = !isRaise; } } else if( objc > 4 ) { Tcl_WrongNumArgs( interp, 3, objv, "?position?" ); return TCL_ERROR; } if( items != NULL ) { for( k = 0; k < items->len; ++k ) { Gnocl_CanvasItemInfo *info = GET_INFO( items, k ); if( isRaise ) { /* TODO: with libgnomecanvas-2.2.1 raise_to_top works exactly once */ if( objc == 3 ) gnome_canvas_item_raise_to_top( info->item ); else gnome_canvas_item_raise( info->item, position ); } else { if( objc == 3 ) gnome_canvas_item_lower_to_bottom( info->item ); else gnome_canvas_item_lower( info->item, position ); } } } return TCL_OK; }
static gboolean bst_canvas_source_child_event (BstCanvasSource *csource, GdkEvent *event, GnomeCanvasItem *child) { GnomeCanvasItem *item = GNOME_CANVAS_ITEM (csource); GtkWidget *widget = GTK_WIDGET (item->canvas); gboolean handled = FALSE; csource = BST_CANVAS_SOURCE (item); switch (event->type) { case GDK_ENTER_NOTIFY: if (!GTK_WIDGET_HAS_FOCUS (widget)) gtk_widget_grab_focus (widget); handled = TRUE; break; case GDK_LEAVE_NOTIFY: handled = TRUE; break; case GDK_KEY_PRESS: switch (event->key.keyval) { case 'L': case 'l': gnome_canvas_item_lower_to_bottom (item); GNOME_CANVAS_NOTIFY (item); break; case 'R': case 'r': gnome_canvas_item_raise_to_top (item); GNOME_CANVAS_NOTIFY (item); break; } handled = TRUE; break; case GDK_KEY_RELEASE: handled = TRUE; break; default: break; } return handled; }
// Function to read from player; will be called when GTK is idle gboolean player_read_func(gpointer* arg) { int i; static int count=0; pose_t robot_pose; gui_data_t* gui_data = (gui_data_t*)arg; static struct timeval lastdump = {0, 0}; static struct timeval lastmapupdate = {0, 0}; static player_pose2d_t lastwaypt[MAX_NUM_ROBOTS]; static player_pose2d_t lastgoal[MAX_NUM_ROBOTS]; struct timeval curr; double diff; gboolean onmap; int peek; if(!count) { memset(lastwaypt,0,sizeof(lastwaypt)); memset(lastgoal,0,sizeof(lastgoal)); } // update map if(mapupdatefreq) { gettimeofday(&curr,NULL); diff = (curr.tv_sec + curr.tv_usec/1e6) - (lastmapupdate.tv_sec + lastmapupdate.tv_usec/1e6); if(diff >= 1.0/mapupdatefreq) { update_map(gui_data); lastmapupdate = curr; } } peek = playerc_mclient_peek(gui_data->mclient,10); if(peek < 0) { //fprintf(stderr, "Error on peek\n"); //gtk_main_quit(); return(TRUE); } else if(peek == 0) return(TRUE); // read new data if(playerc_mclient_read(gui_data->mclient,-1) <= 0) { //fprintf(stderr, "Error on read\n"); //gtk_main_quit(); return(TRUE); } for(i=0;i<gui_data->num_robots;i++) { int have_robot = 0; // Try to get the pose from the planner if(gui_data->planners[i] && gui_data->planners[i]->info.fresh) { robot_pose.px = gui_data->planners[i]->px; robot_pose.py = gui_data->planners[i]->py; robot_pose.pa = gui_data->planners[i]->pa; have_robot = 1; } // Fall back on getting the pose from the localizer else if(gui_data->localizes[i] && gui_data->localizes[i]->info.fresh && gui_data->localizes[i]->hypoth_count) { robot_pose.px = gui_data->localizes[i]->hypoths[0].mean.px; robot_pose.py = gui_data->localizes[i]->hypoths[0].mean.py; robot_pose.pa = gui_data->localizes[i]->hypoths[0].mean.pa; have_robot = 1; } // If we got the robot's pose from somewhere if(have_robot) { // is the robot localized within the map? onmap = (robot_pose.px >= gui_data->mapdev->origin[0]) && (robot_pose.px < (gui_data->mapdev->origin[0] + (gui_data->mapdev->width * gui_data->mapdev->resolution))) && (robot_pose.py >= gui_data->mapdev->origin[1]) && (robot_pose.py < (gui_data->mapdev->origin[1] + (gui_data->mapdev->height * gui_data->mapdev->resolution))); // if it's off the map, put it in the middle if(!onmap) robot_pose.px = robot_pose.py = 0.0; // don't draw the new pose if the user is in the middle of moving the // robot if(!robot_moving_p || (robot_moving_idx != i)) { // also don't draw it if the pose hasn't changed since last time if((gui_data->robot_poses[i].px != robot_pose.px) || (gui_data->robot_poses[i].py != robot_pose.py) || (gui_data->robot_poses[i].pa != robot_pose.pa)) { move_item(gui_data->robot_items[i],robot_pose,1); // If we have a localizer, retrieve and draw particle cloud if(showparticlesp && gui_data->localizes[i]) { playerc_localize_get_particles(gui_data->localizes[i]); draw_particles(gui_data,i); } // If we have a localizer retrive and draw uncertainty ellipsis if(showuncertaintyp && gui_data->localizes[i]) { draw_uncertainty(gui_data,i); } } } // regardless, store this pose for comparison on next iteration gui_data->robot_poses[i] = robot_pose; // If we have a planner if(gui_data->planners[i]) { // If the current goal or waypoint changed, get the whole list // of waypoints again if((lastwaypt[i].px != gui_data->planners[i]->wx) || (lastwaypt[i].py != gui_data->planners[i]->wy) || (lastwaypt[i].pa != gui_data->planners[i]->wa) || (lastgoal[i].px != gui_data->planners[i]->gx) || (lastgoal[i].py != gui_data->planners[i]->gy) || (lastgoal[i].pa != gui_data->planners[i]->ga)) { if(get_waypoints) { if(playerc_planner_get_waypoints(gui_data->planners[i]) < 0) { fprintf(stderr, "error while getting waypoints for robot %d\n", i); } else { draw_waypoints(gui_data,i); } } else draw_goal(gui_data,i); // Cache goal and waypoint info lastwaypt[i].px = gui_data->planners[i]->wx; lastwaypt[i].py = gui_data->planners[i]->wy; lastwaypt[i].pa = gui_data->planners[i]->wa; lastgoal[i].px = gui_data->planners[i]->gx; lastgoal[i].py = gui_data->planners[i]->gy; lastgoal[i].pa = gui_data->planners[i]->ga; } } // Reset freshness flag(s) if(gui_data->planners[i]) gui_data->planners[i]->info.fresh = 0; if(gui_data->localizes[i]) gui_data->localizes[i]->info.fresh = 0; } // raise the robot's canvas item, so that the user can select it if(gui_data->localizes[i] || gui_data->planners[i]) { gnome_canvas_item_raise_to_top(gui_data->robot_items[i]); } } // dump screenshot if(dumpp) { gettimeofday(&curr,NULL); diff = (curr.tv_sec + curr.tv_usec/1e6) - (lastdump.tv_sec + lastdump.tv_usec/1e6); if(diff >= 1.0/dumpfreq) { dump_screenshot(gui_data); lastdump = curr; } } count++; return(TRUE); }
/* Checks if there is a canvas_node per each node. If not, one canvas_node * must be created and initiated */ static gint check_new_node (node_t * node, GtkWidget * canvas) { canvas_node_t *new_canvas_node; GnomeCanvasGroup *group; if (!node) return FALSE; if (display_node (node) && !g_tree_lookup (canvas_nodes, &node->node_id)) { new_canvas_node = g_malloc (sizeof (canvas_node_t)); g_assert(new_canvas_node); new_canvas_node->canvas_node_id = node->node_id; /* Create a new group to hold the node and its labels */ group = gnome_canvas_root (GNOME_CANVAS (canvas)); group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (group, GNOME_TYPE_CANVAS_GROUP, "x", 100.0, "y", 100.0, NULL)); addref_canvas_obj(G_OBJECT (group)); new_canvas_node->group_item = group; new_canvas_node->node_item = gnome_canvas_item_new (group, GNOME_TYPE_CANVAS_ELLIPSE, "x1", 0.0, "x2", 0.0, "y1", 0.0, "y2", 0.0, "fill_color", "white", "outline_color", "black", "width_pixels", 0, NULL); addref_canvas_obj(G_OBJECT (new_canvas_node->node_item)); new_canvas_node->text_item = gnome_canvas_item_new (group, GNOME_TYPE_CANVAS_TEXT, "text", node->name->str, "x", 0.0, "y", 0.0, "anchor", GTK_ANCHOR_CENTER, "font", pref.fontname, "fill_color", pref.text_color, NULL); addref_canvas_obj(G_OBJECT (new_canvas_node->text_item)); gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM (new_canvas_node->text_item)); g_signal_connect (G_OBJECT (new_canvas_node->group_item), "event", (GtkSignalFunc) node_item_event, new_canvas_node); if (!new_canvas_node->node_item || !new_canvas_node->text_item) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, _("Canvas node null")); /* * We hide them until we are sure that they will get a proper position * in reposition_nodes */ gnome_canvas_item_hide (new_canvas_node->node_item); gnome_canvas_item_hide (new_canvas_node->text_item); new_canvas_node->is_new = TRUE; new_canvas_node->shown = TRUE; g_tree_insert (canvas_nodes, &new_canvas_node->canvas_node_id, new_canvas_node); g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, _("Creating canvas_node: %s. Number of nodes %d"), node->name->str, g_tree_nnodes (canvas_nodes)); need_reposition = TRUE; } return FALSE; /* False to keep on traversing */ } /* check_new_node */