/*************************************************************************** ... ***************************************************************************/ 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); }
/************************************************************************** Entry point for GUI specific portion. Called from client_main() **************************************************************************/ void ui_main(int argc, char *argv[]) { int i; struct sprite *icon; parse_options(argc, argv); /* include later - pain to see the warning at every run */ XtSetLanguageProc(NULL, NULL, NULL); toplevel = XtVaAppInitialize( &app_context, /* Application context */ "Freeciv", /* application class name */ #ifdef UNUSED cmd_options, XtNumber(cmd_options), #else NULL, 0, #endif /* command line option list */ &argc, argv, /* command line args */ &fallback_resources[1], /* for missing app-defaults file */ XtNallowShellResize, True, NULL); XtGetApplicationResources(toplevel, &appResources, resources, XtNumber(resources), NULL, 0); /* XSynchronize(display, 1); XSetErrorHandler(myerr);*/ if(appResources.version==NULL) { freelog(LOG_FATAL, _("No version number in resources.")); freelog(LOG_FATAL, _("You probably have an old (circa V1.0)" " Freeciv resource file somewhere.")); exit(EXIT_FAILURE); } /* TODO: Use capabilities here instead of version numbers */ if (0 != strncmp(appResources.version, VERSION_STRING, strlen(appResources.version))) { freelog(LOG_FATAL, _("Game version does not match Resource version.")); freelog(LOG_FATAL, _("Game version: %s - Resource version: %s"), VERSION_STRING, appResources.version); freelog(LOG_FATAL, _("You might have an old Freeciv resourcefile" " in /usr/lib/X11/app-defaults")); exit(EXIT_FAILURE); } if(!appResources.gotAppDefFile) { freelog(LOG_NORMAL, _("Using fallback resources - which is OK")); } display = XtDisplay(toplevel); screen_number=XScreenNumberOfScreen(XtScreen(toplevel)); display_depth=DefaultDepth(display, screen_number); root_window=DefaultRootWindow(display); display_color_type=get_visual(); if(display_color_type!=COLOR_DISPLAY) { freelog(LOG_FATAL, _("Only color displays are supported for now...")); /* exit(EXIT_FAILURE); */ } { XGCValues values; char **missing_charset_list_return; int missing_charset_count_return; char *def_string_return; char *city_names_font, *city_productions_font_name; values.graphics_exposures = False; civ_gc = XCreateGC(display, root_window, GCGraphicsExposures, &values); city_names_font = mystrdup("-*-*-*-*-*-*-14-*"); city_productions_font_name = mystrdup("-*-*-*-*-*-*-14-*"); main_font_set = XCreateFontSet(display, city_names_font, &missing_charset_list_return, &missing_charset_count_return, &def_string_return); if (!main_font_set) { freelog(LOG_FATAL, _("Unable to open fontset: %s"), city_names_font); freelog(LOG_FATAL, _("Doing 'xset fp rehash' may temporarily solve a problem.")); exit(EXIT_FAILURE); } for (i = 0; i < missing_charset_count_return; i++) { freelog(LOG_ERROR, _("Font for charset %s is lacking"), missing_charset_list_return[i]); } values.foreground = get_color(tileset, COLOR_MAPVIEW_CITYTEXT)->color.pixel; values.background = get_color(tileset, COLOR_MAPVIEW_UNKNOWN)->color.pixel; font_gc= XCreateGC(display, root_window, GCForeground|GCBackground|GCGraphicsExposures, &values); prod_font_set = XCreateFontSet(display, city_productions_font_name, &missing_charset_list_return, &missing_charset_count_return, &def_string_return); if (!prod_font_set) { freelog(LOG_FATAL, _("Unable to open fontset: %s"), city_productions_font_name); freelog(LOG_FATAL, _("Doing 'xset fp rehash' may temporarily solve a problem.")); exit(EXIT_FAILURE); } for (i = 0; i < missing_charset_count_return; i++) { freelog(LOG_ERROR, _("Font for charset %s is lacking"), missing_charset_list_return[i]); } values.foreground = get_color(tileset, COLOR_MAPVIEW_CITYTEXT)->color.pixel; values.background = get_color(tileset, COLOR_MAPVIEW_UNKNOWN)->color.pixel; prod_font_gc= XCreateGC(display, root_window, GCForeground|GCBackground|GCGraphicsExposures, &values); values.line_width = BORDER_WIDTH; values.line_style = LineOnOffDash; values.cap_style = CapNotLast; values.join_style = JoinMiter; values.fill_style = FillSolid; border_line_gc = XCreateGC(display, root_window, GCGraphicsExposures|GCLineWidth|GCLineStyle |GCCapStyle|GCJoinStyle|GCFillStyle, &values); values.foreground = 0; values.background = 0; fill_bg_gc= XCreateGC(display, root_window, GCForeground|GCBackground|GCGraphicsExposures, &values); values.fill_style=FillStippled; fill_tile_gc= XCreateGC(display, root_window, GCForeground|GCBackground|GCFillStyle|GCGraphicsExposures, &values); } { char d1[]={0x03,0x0c,0x03,0x0c}; char d2[]={0x08,0x02,0x08,0x02}; gray50 = XCreateBitmapFromData(display, root_window, d1, 4, 4); gray25 = XCreateBitmapFromData(display, root_window, d2, 4, 4); } /* 135 below is rough value (could be more intelligent) --dwp */ num_units_below = 135 / tileset_full_tile_width(tileset); num_units_below = MIN(num_units_below,MAX_NUM_UNITS_BELOW); num_units_below = MAX(num_units_below,1); /* do setup_widgets before loading the rest of graphics to ensure that setup_widgets() has enough colors available: (on 256-colour systems) */ setup_widgets(); tileset_init(tileset); tileset_load_tiles(tileset); load_intro_gfx(); load_cursors(); /* FIXME: what about the mask? */ icon = get_icon_sprite(tileset, ICON_FREECIV); XtVaSetValues(toplevel, XtNiconPixmap, icon->pixmap, NULL); XtSetKeyboardFocus(bottom_form, inputline_text); XtSetKeyboardFocus(below_menu_form, map_canvas); InitializeActions(app_context); /* Do this outside setup_widgets() so after tiles are loaded */ fill_econ_label_pixmaps(); XtAddCallback(map_horizontal_scrollbar, XtNjumpProc, scrollbar_jump_callback, NULL); XtAddCallback(map_vertical_scrollbar, XtNjumpProc, scrollbar_jump_callback, NULL); XtAddCallback(map_horizontal_scrollbar, XtNscrollProc, scrollbar_scroll_callback, NULL); XtAddCallback(map_vertical_scrollbar, XtNscrollProc, scrollbar_scroll_callback, NULL); XtAddCallback(turn_done_button, XtNcallback, end_turn_callback, NULL); XtAppAddWorkProc(app_context, toplevel_work_proc, NULL); XtRealizeWidget(toplevel); x_interval_id = XtAppAddTimeOut(app_context, TIMER_INTERVAL, timer_callback, NULL); init_mapcanvas_and_overview(); fill_unit_below_pixmaps(); set_indicator_icons(client_research_sprite(), client_warming_sprite(), client_cooling_sprite(), client_government_sprite()); wm_delete_window = XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", 0); XSetWMProtocols(display, XtWindow(toplevel), &wm_delete_window, 1); XtOverrideTranslations(toplevel, XtParseTranslationTable ("<Message>WM_PROTOCOLS: msg-quit-freeciv()")); XtSetSensitive(toplevel, FALSE); XtAppMainLoop(app_context); }