Example #1
0
/**************************************************************************
...
**************************************************************************/
void map_canvas_expose(Widget w, XEvent *event, Region exposed, 
		       void *client_data)
{
  Dimension width, height;
  bool map_resized;

  XtVaGetValues(w, XtNwidth, &width, XtNheight, &height, NULL);

  map_resized = map_canvas_resized(width, height);

  if (!can_client_change_view()) {
    if (!intro_gfx_sprite) {
      load_intro_gfx();
    }
    if (height != scaled_intro_pixmap_height
        || width != scaled_intro_pixmap_width) {
      if (scaled_intro_pixmap) {
	XFreePixmap(display, scaled_intro_pixmap);
      }

      scaled_intro_pixmap=x_scale_pixmap(intro_gfx_sprite->pixmap,
					 intro_gfx_sprite->width,
					 intro_gfx_sprite->height, 
					 width, height, root_window);
      scaled_intro_pixmap_width=width;
      scaled_intro_pixmap_height=height;
    }

    if(scaled_intro_pixmap)
       XCopyArea(display, scaled_intro_pixmap, XtWindow(map_canvas),
		 civ_gc,
		 event->xexpose.x, event->xexpose.y,
		 event->xexpose.width, event->xexpose.height,
		 event->xexpose.x, event->xexpose.y);
    return;
  }
  if(scaled_intro_pixmap) {
    XFreePixmap(display, scaled_intro_pixmap);
    scaled_intro_pixmap=0; scaled_intro_pixmap_height=0;
  }

  if (map_exists() && !map_resized) {
    /* First we mark the area to be updated as dirty.  Then we unqueue
     * any pending updates, to make sure only the most up-to-date data
     * is written (otherwise drawing bugs happen when old data is copied
     * to screen).  Then we draw all changed areas to the screen. */
    unqueue_mapview_updates(FALSE);
    XCopyArea(display, mapview.store->pixmap, XtWindow(map_canvas),
	      civ_gc,
	      event->xexpose.x, event->xexpose.y,
	      event->xexpose.width, event->xexpose.height,
	      event->xexpose.x, event->xexpose.y);
  }
  refresh_overview_canvas();
}
Example #2
0
/**************************************************************************
...
**************************************************************************/
void x_main(int argc, char *argv[])
{
  int i;
  Pixmap icon_pixmap; 
  XtTranslations TextFieldTranslations;

  /* include later - pain to see the warning at every run */
  /* XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL); */

  toplevel = XtVaAppInitialize(
	       &app_context,       /* Application context */
	       "Freeciv",          /* application class name */
	       NULL, 0,            /* command line option list */
	       &argc, argv,        /* command line args */
	       fallback_resources, /* for missing app-defaults file */
	       XtNallowShellResize, True,
	       NULL);              /* terminate varargs list */

  XtGetApplicationResources(toplevel, &appResources, resources,
                            XtNumber(resources), NULL, 0);
  
  display = XtDisplay(toplevel);
  screen_number=XScreenNumberOfScreen(XtScreen(toplevel));
  display_depth=DefaultDepth(display, screen_number);
  root_window=DefaultRootWindow(display);

  if(appResources.usingFallback) {
    log(LOG_NORMAL, "Application defaults file wasn't found. Using fallback resources");
  }
  
/*  XSynchronize(display, 1); 
  XSetErrorHandler(myerr);*/
 
  display_color_type=get_visual(); 
  if(display_color_type!=COLOR_DISPLAY) {
    log(LOG_FATAL, "only color displays are supported for now...");
    /*    exit(1); */
  }
  
  icon_pixmap = XCreateBitmapFromData(display,
				      RootWindowOfScreen(XtScreen(toplevel)),
				      freeciv_bits,
				      freeciv_width, freeciv_height );
  XtVaSetValues(toplevel, XtNiconPixmap, icon_pixmap, NULL);

  civ_gc = XCreateGC(display, root_window, 0, NULL);

  {
    XGCValues values;
    values.foreground = 0;
    values.background = 0;
    fill_bg_gc= XCreateGC(display, root_window, 
			  GCForeground | GCBackground, &values);
  }

  init_color_system();
  
  load_intro_gfx(); 
  load_tile_gfx();
  
  setup_widgets();
  
  XtSetKeyboardFocus(bottom_form, inputline_text);
  XtSetKeyboardFocus(below_menu_form, map_canvas);
  
  TextFieldTranslations = XtParseTranslationTable  /*BLAH!*/
		("<Key>Return: inputline-return()");
  XtOverrideTranslations(inputline_text, TextFieldTranslations);

  XtAppAddActions(app_context, Actions, XtNumber(Actions));

  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);

  XtRealizeWidget(toplevel);

  x_input_id=XtAppAddInput(app_context, aconnection.sock, 
			   (XtPointer) XtInputReadMask,
			   (XtInputCallbackProc) get_net_input, NULL);

  x_interval_id=XtAppAddTimeOut(app_context, 500,
				(XtTimerCallbackProc)timer_callback, NULL);

  map_canvas_store=XCreatePixmap(display, XtWindow(map_canvas), 
				 510, 300, display_depth);
  map_canvas_store_twidth=510/30;
  map_canvas_store_theight=300/30;


  overview_canvas_store_width=2*80;
  overview_canvas_store_height=2*50;

  overview_canvas_store=XCreatePixmap(display, XtWindow(overview_canvas), 
				      overview_canvas_store_width,
				      overview_canvas_store_height, 
				      display_depth);

  XSetForeground(display, fill_bg_gc, colors_standard[COLOR_STD_WHITE]);
  XFillRectangle(display, overview_canvas_store, fill_bg_gc, 0, 0, 
		 overview_canvas_store_width, overview_canvas_store_height);

  
  single_tile_pixmap_width=30;
  single_tile_pixmap_height=30;

  
  single_tile_pixmap=XCreatePixmap(display, XtWindow(overview_canvas), 
				   single_tile_pixmap_width,
				   single_tile_pixmap_height,
				   display_depth);


  for(i=0; i<4; i++)
    unit_below_pixmap[i]=XCreatePixmap(display, XtWindow(overview_canvas), 
				       30, 30, display_depth);  
  
  set_bulp_sol_goverment(0, 0, 0);
  XtAppMainLoop(app_context);
}
Example #3
0
/**************************************************************************
  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);
}