/*************************************************************************** ... ***************************************************************************/ void create_overlay_unit(struct canvas *pcanvas, struct unit_type *punittype) { int x1, x2, y1, y2; int width, height; struct sprite *sprite = get_unittype_sprite(tileset, punittype); sprite_get_bounding_box(sprite, &x1, &y1, &x2, &y2); if (pcanvas->type == CANVAS_PIXBUF) { width = gdk_pixbuf_get_width(pcanvas->v.pixbuf); height = gdk_pixbuf_get_height(pcanvas->v.pixbuf); gdk_pixbuf_fill(pcanvas->v.pixbuf, 0x00000000); } else { if (pcanvas->type == CANVAS_PIXCOMM) { gtk_pixcomm_clear(pcanvas->v.pixcomm); } /* Guess */ width = tileset_full_tile_width(tileset); height = tileset_full_tile_height(tileset); } /* Finally, put a picture of the unit in the tile */ canvas_put_sprite(pcanvas, 0, 0, sprite, (x2 + x1 - width) / 2, (y1 + y2 - height) / 2, tileset_full_tile_width(tileset) - (x2 + x1 - width) / 2, tileset_full_tile_height(tileset) - (y1 + y2 - height) / 2); }
/*************************************************************************** ... ***************************************************************************/ Pixmap create_overlay_unit(const struct unit_type *punittype) { Pixmap pm; enum color_std bg_color; pm=XCreatePixmap(display, root_window, tileset_full_tile_width(tileset), tileset_full_tile_height(tileset), display_depth); /* Give tile a background color, based on the type of unit */ /* Should there be colors like COLOR_MAPVIEW_LAND etc? -ev */ switch (unit_color_type(punittype)) { case UNIT_BG_LAND: bg_color = COLOR_OVERVIEW_LAND; break; case UNIT_BG_SEA: bg_color = COLOR_OVERVIEW_OCEAN; break; case UNIT_BG_HP_LOSS: case UNIT_BG_AMPHIBIOUS: bg_color = COLOR_OVERVIEW_MY_UNIT; break; case UNIT_BG_FLYING: bg_color = COLOR_OVERVIEW_ENEMY_CITY; break; default: bg_color = COLOR_OVERVIEW_UNKNOWN; break; } XSetForeground(display, fill_bg_gc, get_color(tileset, bg_color)->color.pixel); XFillRectangle(display, pm, fill_bg_gc, 0,0, tileset_full_tile_width(tileset), tileset_full_tile_height(tileset)); /* If we're using flags, put one on the tile */ if(!solid_color_behind_units) { struct sprite *flag = get_nation_flag_sprite(tileset, nation_of_player(client.conn.playing)); XSetClipOrigin(display, civ_gc, 0,0); XSetClipMask(display, civ_gc, flag->mask); XCopyArea(display, flag->pixmap, pm, civ_gc, 0,0, flag->width,flag->height, 0,0); XSetClipMask(display, civ_gc, None); } /* Finally, put a picture of the unit in the tile */ /* if(i<utype_count()) */ { struct sprite *s = get_unittype_sprite(tileset, punittype, direction8_invalid()); XSetClipOrigin(display,civ_gc,0,0); XSetClipMask(display,civ_gc,s->mask); XCopyArea(display, s->pixmap, pm, civ_gc, 0,0, s->width,s->height, 0,0 ); XSetClipMask(display,civ_gc,None); } return(pm); }
/************************************************************************** Called to fill unit_below pixmaps. They are on the left of the screen that shows all of the inactive units in the current tile. It may be called again if the tileset changes. **************************************************************************/ void fill_unit_below_pixmaps(void) { long i; for (i = 0; i < num_units_below; i++) { /* XtVaSetValues(unit_below_canvas[i], XtNwidth, tileset_full_tile_width(tileset), XtNheight, tileset_full_tile_height(tileset), NULL); */ unit_below_pixmap[i] = XCreatePixmap(display, XtWindow(overview_canvas), tileset_full_tile_width(tileset), tileset_full_tile_height(tileset), display_depth); } }
/**************************************************************** popup the dialog 10% inside the main-window *****************************************************************/ void unit_select_dialog_popup(struct tile *ptile) { int i,n,r; char buffer[512]; Arg args[4]; int nargs; Widget unit_select_all_command, unit_select_close_command; Widget firstcolumn=0,column=0; Pixel bg; struct unit *unit_list[unit_list_size(ptile->units)]; XtSetSensitive(main_form, FALSE); unit_select_dialog_shell = I_T(XtCreatePopupShell("unitselectdialogshell", transientShellWidgetClass, toplevel, NULL, 0)); unit_select_form = XtVaCreateManagedWidget("unitselectform", formWidgetClass, unit_select_dialog_shell, NULL); XtVaGetValues(unit_select_form, XtNbackground, &bg, NULL); XSetForeground(display, fill_bg_gc, bg); n = MIN(MAX_SELECT_UNITS, unit_list_size(ptile->units)); r = number_of_rows(n); fill_tile_unit_list(ptile, unit_list); for(i=0; i<n; i++) { struct unit *punit = unit_list[i]; struct unit_type *punittemp=unit_type(punit); struct city *pcity; struct canvas store; if(!(i%r)) { nargs=0; if(i) { XtSetArg(args[nargs], XtNfromHoriz, column); nargs++;} column = XtCreateManagedWidget("column", formWidgetClass, unit_select_form, args, nargs); if(!i) firstcolumn=column; } unit_select_ids[i]=punit->id; pcity = player_city_by_number(client_player(), punit->homecity); fc_snprintf(buffer, sizeof(buffer), "%s(%s)\n%s", utype_name_translation(punittemp), pcity ? city_name(pcity) : "", unit_activity_text(punit)); unit_select_pixmaps[i]=XCreatePixmap(display, XtWindow(map_canvas), tileset_full_tile_width(tileset), tileset_full_tile_height(tileset), display_depth); XFillRectangle(display, unit_select_pixmaps[i], fill_bg_gc, 0, 0, tileset_full_tile_width(tileset), tileset_full_tile_height(tileset)); store.pixmap = unit_select_pixmaps[i]; put_unit(punit, &store, 0, 0); nargs=0; XtSetArg(args[nargs], XtNbitmap, (XtArgVal)unit_select_pixmaps[i]);nargs++; XtSetArg(args[nargs], XtNsensitive, can_unit_do_activity(punit, ACTIVITY_IDLE));nargs++; if(i%r) { XtSetArg(args[nargs], XtNfromVert, unit_select_commands[i-1]); nargs++; } unit_select_commands[i]=XtCreateManagedWidget("unitselectcommands", commandWidgetClass, column, args, nargs); nargs=0; XtSetArg(args[nargs], XtNlabel, (XtArgVal)buffer); nargs++; XtSetArg(args[nargs], XtNfromHoriz, unit_select_commands[i]); nargs++; if(i%r) { XtSetArg(args[nargs], XtNfromVert, unit_select_commands[i-1]); nargs++; } unit_select_labels[i]=XtCreateManagedWidget("unitselectlabels", labelWidgetClass, column, args, nargs); XtAddCallback(unit_select_commands[i], XtNdestroyCallback,free_bitmap_destroy_callback, NULL); XtAddCallback(unit_select_commands[i], XtNcallback, unit_select_callback, NULL); } unit_select_no=i; unit_select_close_command = I_L(XtVaCreateManagedWidget("unitselectclosecommand", commandWidgetClass, unit_select_form, XtNfromVert, firstcolumn, NULL)); unit_select_all_command = I_L(XtVaCreateManagedWidget("unitselectallcommand", commandWidgetClass, unit_select_form, XtNfromVert, firstcolumn, NULL)); XtAddCallback(unit_select_close_command, XtNcallback, unit_select_callback, NULL); XtAddCallback(unit_select_all_command, XtNcallback, unit_select_all_callback, NULL); xaw_set_relative_position(toplevel, unit_select_dialog_shell, 15, 10); XtPopup(unit_select_dialog_shell, XtGrabNone); }
/************************************************************************** ... **************************************************************************/ void setup_widgets(void) { long i; int econ_label_count=10, econ_label_space=1; main_form = XtVaCreateManagedWidget("mainform", formWidgetClass, toplevel, NULL); menu_form = XtVaCreateManagedWidget("menuform", formWidgetClass, main_form, NULL); setup_menus(menu_form); /* main_vpane= XtVaCreateManagedWidget("mainvpane", panedWidgetClass, main_form, NULL); below_menu_form = XtVaCreateManagedWidget("belowmenuform", formWidgetClass, main_vpane, NULL); */ below_menu_form = XtVaCreateManagedWidget("belowmenuform", formWidgetClass, main_form, NULL); left_column_form = XtVaCreateManagedWidget("leftcolumnform", formWidgetClass, below_menu_form, NULL); map_form = XtVaCreateManagedWidget("mapform", formWidgetClass, below_menu_form, NULL); bottom_form = XtVaCreateManagedWidget("bottomform", formWidgetClass, /*main_vpane,*/ main_form, NULL); overview_canvas = XtVaCreateManagedWidget("overviewcanvas", xfwfcanvasWidgetClass, left_column_form, "exposeProc", (XtArgVal)overview_canvas_expose, "exposeProcData", (XtArgVal)NULL, NULL); info_command = XtVaCreateManagedWidget("infocommand", commandWidgetClass, left_column_form, XtNfromVert, (XtArgVal)overview_canvas, NULL); /* Don't put the citizens in here yet because not loaded yet */ for(i=0;i<econ_label_count;i++) { econ_label[i] = XtVaCreateManagedWidget("econlabels", commandWidgetClass, left_column_form, XtNwidth, tileset_small_sprite_width(tileset), XtNheight, tileset_small_sprite_height(tileset), i?XtNfromHoriz:NULL, i?econ_label[i-1]:NULL, XtNhorizDistance, econ_label_space, NULL); } bulb_label = XtVaCreateManagedWidget("bulblabel", labelWidgetClass, left_column_form, NULL); sun_label = XtVaCreateManagedWidget("sunlabel", labelWidgetClass, left_column_form, NULL); flake_label = XtVaCreateManagedWidget("flakelabel", labelWidgetClass, left_column_form, NULL); government_label = XtVaCreateManagedWidget("governmentlabel", labelWidgetClass, left_column_form, NULL); timeout_label = XtVaCreateManagedWidget("timeoutlabel", labelWidgetClass, left_column_form, NULL); turn_done_button = I_LW(XtVaCreateManagedWidget("turndonebutton", commandWidgetClass, left_column_form, XtNwidth, econ_label_count* (tileset_small_sprite_width(tileset)+econ_label_space), NULL)); unit_info_label = XtVaCreateManagedWidget("unitinfolabel", labelWidgetClass, left_column_form, NULL); unit_pix_canvas = XtVaCreateManagedWidget("unitpixcanvas", pixcommWidgetClass, left_column_form, XtNwidth, tileset_full_tile_width(tileset), XtNheight, tileset_full_tile_height(tileset), NULL); for(i=0; i<num_units_below; i++) { char unit_below_name[32]; my_snprintf(unit_below_name, sizeof(unit_below_name), "unitbelowcanvas%ld", i); unit_below_canvas[i] = XtVaCreateManagedWidget(unit_below_name, pixcommWidgetClass, left_column_form, XtNwidth, tileset_full_tile_width(tileset), XtNheight, tileset_full_tile_height(tileset), NULL); XtAddCallback(unit_below_canvas[i], XtNcallback, unit_icon_callback, (XtPointer)i); } more_arrow_label = XtVaCreateManagedWidget("morearrowlabel", labelWidgetClass, left_column_form, XtNfromHoriz, (XtArgVal)unit_below_canvas[num_units_below-1], NULL); map_vertical_scrollbar = XtVaCreateManagedWidget("mapvertiscrbar", scrollbarWidgetClass, map_form, NULL); map_canvas = XtVaCreateManagedWidget("mapcanvas", xfwfcanvasWidgetClass, map_form, "exposeProc", (XtArgVal)map_canvas_expose, "exposeProcData", (XtArgVal)NULL, NULL); map_horizontal_scrollbar = XtVaCreateManagedWidget("maphorizscrbar", scrollbarWidgetClass, map_form, NULL); outputwindow_text= I_SW(XtVaCreateManagedWidget("outputwindowtext", asciiTextWidgetClass, bottom_form, NULL)); inputline_text= XtVaCreateManagedWidget("inputlinetext", asciiTextWidgetClass, bottom_form, NULL); }