/************************************************************************** Popup a label with information about the tile, unit, city, when the user used the middle mouse button on the map. **************************************************************************/ static void popit(GdkEventButton *event, struct tile *ptile) { GtkWidget *p; static struct tmousepos mousepos; struct unit *punit; if (TILE_UNKNOWN != client_tile_get_known(ptile)) { p=gtk_window_new(GTK_WINDOW_POPUP); gtk_widget_set_app_paintable(p, TRUE); gtk_container_set_border_width(GTK_CONTAINER(p), 4); gtk_container_add(GTK_CONTAINER(p), gtk_label_new(popup_info_text(ptile))); punit = find_visible_unit(ptile); if (punit) { mapdeco_set_gotoroute(punit); if (punit->goto_tile) { mapdeco_set_crosshair(punit->goto_tile, TRUE); } } mapdeco_set_crosshair(ptile, TRUE); g_signal_connect(p, "destroy", G_CALLBACK(popupinfo_popdown_callback), NULL); mousepos.x = event->x; mousepos.y = event->y; g_signal_connect(p, "size-allocate", G_CALLBACK(popupinfo_positioning_callback), &mousepos); gtk_widget_show_all(p); gdk_device_grab(event->device, gtk_widget_get_window(p), GDK_OWNERSHIP_NONE, TRUE, GDK_BUTTON_RELEASE_MASK, NULL, event->time); gtk_grab_add(p); g_signal_connect_after(p, "button_release_event", G_CALLBACK(popit_button_release), NULL); } }
/************************************************************************** ... **************************************************************************/ static void popit(int xin, int yin, struct tile *ptile) { Position x, y; int dw, dh; Dimension w, h, b; static struct tile *cross_list[2+1]; struct tile **cross_head = cross_list; int i; struct unit *punit; char *content; static bool is_orders; if (TILE_UNKNOWN != client_tile_get_known(ptile)) { Widget p=XtCreatePopupShell("popupinfo", simpleMenuWidgetClass, map_canvas, NULL, 0); content = (char *) popup_info_text(ptile); /* content is provided to us as a single string with multiple lines, but xaw doens't support multi-line labels. So we break it up. We mangle it in the process, but who cares? It's never going to be used again anyway. */ while (1) { char *end = strchr(content, '\n'); if (end) { *end='\0'; } XtCreateManagedWidget(content, smeBSBObjectClass, p, NULL, 0); if (end) { content = end+1; } else { break; } } punit = find_visible_unit(ptile); is_orders = show_unit_orders(punit); if (punit && punit->goto_tile) { *cross_head = punit->goto_tile; cross_head++; } *cross_head = ptile; cross_head++; xin /= tileset_tile_width(tileset); xin *= tileset_tile_width(tileset); yin /= tileset_tile_height(tileset); yin *= tileset_tile_height(tileset); xin += (tileset_tile_width(tileset) / 2); XtTranslateCoords(map_canvas, xin, yin, &x, &y); dw = XDisplayWidth (display, screen_number); dh = XDisplayHeight (display, screen_number); XtRealizeWidget(p); XtVaGetValues(p, XtNwidth, &w, XtNheight, &h, XtNborderWidth, &b, NULL); w += (2 * b); h += (2 * b); x -= (w / 2); y -= h; if ((x + w) > dw) x = dw - w; if (x < 0) x = 0; if ((y + h) > dh) y = dh - h; if (y < 0) y = 0; XtVaSetValues(p, XtNx, x, XtNy, y, NULL); *cross_head = NULL; for (i = 0; cross_list[i]; i++) { put_cross_overlay_tile(cross_list[i]); } XtAddCallback(p,XtNpopdownCallback,popupinfo_popdown_callback, (XtPointer)&is_orders); XtPopupSpringLoaded(p); } }