示例#1
0
/*
 * Initialization function for an X Athena Widget module to Angband
 *
 * We should accept "-d<dpy>" requests in the "argv" array.  XXX XXX XXX
 */
errr init_xaw(int argc, char *argv[])
{
	int i;
	Widget topLevel;
	Display *dpy;

	cptr dpy_name = "";


#ifdef USE_GRAPHICS

	char filename[1024];

	int pict_wid = 0;
	int pict_hgt = 0;

#ifdef USE_TRANSPARENCY

	char *TmpData;
#endif /* USE_TRANSPARENCY */

#endif /* USE_GRAPHICS */

	/* Parse args */
	for (i = 1; i < argc; i++)
	{
		if (prefix(argv[i], "-d"))
		{
			dpy_name = &argv[i][2];
			continue;
		}

#ifdef USE_GRAPHICS
		if (prefix(argv[i], "-s"))
		{
			smoothRescaling = FALSE;
			continue;
		}
#endif /* USE_GRAPHICS */

		if (prefix(argv[i], "-n"))
		{
			num_term = atoi(&argv[i][2]);
			if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA;
			else if (num_term < 1) num_term = 1;
			continue;
		}

		plog_fmt("Ignoring option: %s", argv[i]);
	}


	/* Attempt to open the local display */
	dpy = XOpenDisplay(dpy_name);

	/* Failure -- assume no X11 available */
	if (!dpy) return (-1);

	/* Close the local display */
	XCloseDisplay(dpy);


#ifdef USE_XAW_LANG

	/* Support locale processing */
	XtSetLanguageProc(NULL, NULL, NULL);

#endif /* USE_XAW_LANG */


	/* Initialize the toolkit */
	topLevel = XtAppInitialize(&appcon, "Angband", NULL, 0, &argc, argv,
	                           fallback, NULL, 0);


	/* Initialize the windows */
	for (i = 0; i < num_term; i++)
	{
		term_data *td = &data[i];

		term_data_init(td, topLevel, 1024, termNames[i],
		               (i == 0) ? specialArgs : defaultArgs,
		               TERM_FALLBACKS, i);

		angband_term[i] = Term;
	}

	/* Activate the "Angband" window screen */
	Term_activate(&data[0].t);

	/* Raise the "Angband" window */
	term_raise(&data[0]);


#ifdef USE_GRAPHICS

	/* Try graphics */
	if (arg_graphics)
	{
		/* Try the "16x16.bmp" file */
		path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/16x16.bmp");

		/* Use the "16x16.bmp" file if it exists */
		if (0 == fd_close(fd_open(filename, O_RDONLY)))
		{
			/* Use graphics */
			use_graphics = TRUE;

			use_transparency = TRUE;

			pict_wid = pict_hgt = 16;

			ANGBAND_GRAF = "new";
		}
		else
		{
			/* Try the "8x8.bmp" file */
			path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/8x8.bmp");

			/* Use the "8x8.bmp" file if it exists */
			if (0 == fd_close(fd_open(filename, O_RDONLY)))
			{
				/* Use graphics */
				use_graphics = TRUE;

				pict_wid = pict_hgt = 8;

				ANGBAND_GRAF = "old";
			}
		}
	}

	/* Load graphics */
	if (use_graphics)
	{
		/* Hack -- Get the Display */
		term_data *td = &data[0];
		Widget widget = (Widget)(td->widget);
		Display *dpy = XtDisplay(widget);

		XImage *tiles_raw;

		/* Load the graphical tiles */
		tiles_raw = ReadBMP(dpy, filename);

		/* Initialize the windows */
		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];

			term *t = &td->t;

			t->pict_hook = Term_pict_xaw;

			t->higher_pict = TRUE;

			/* Resize tiles */
			td->widget->angband.tiles =
			ResizeImage(dpy, tiles_raw,
			            pict_wid, pict_hgt,
			            td->widget->angband.fontwidth,
			            td->widget->angband.fontheight);
		}

#ifdef USE_TRANSPARENCY
		/* Initialize the transparency temp storage*/
		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];
			int ii, jj;
			int depth = DefaultDepth(dpy, DefaultScreen(dpy));
			Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy));
			int total;


			/* Determine total bytes needed for image */
			ii = 1;
			jj = (depth - 1) >> 2;
			while (jj >>= 1) ii <<= 1;
			total = td->widget->angband.fontwidth *
				 td->widget->angband.fontheight * ii;


			TmpData = (char *)malloc(total);

			td->widget->angband.TmpImage = XCreateImage(dpy,
				visual,depth,
				ZPixmap, 0, TmpData,
				td->widget->angband.fontwidth,
			        td->widget->angband.fontheight, 8, 0);

		}
#endif /* USE_TRANSPARENCY */


		/* Free tiles_raw? XXX XXX */
	}

#endif /* USE_GRAPHICS */

	/* Success */
	return (0);
}
示例#2
0
/*
 * Initialization function for an "X11" module to Angband
 */
errr init_x11(int argc, char **argv)
{
	int i;

	cptr dpy_name = "";

	int num_term = 1;

#ifdef USE_GRAPHICS

	cptr bitmap_file = "";
	char filename[1024];

	int pict_wid = 0;
	int pict_hgt = 0;

	char *TmpData;

#endif /* USE_GRAPHICS */


	/* Parse args */
	for (i = 1; i < argc; i++)
	{
		if (prefix(argv[i], "-d"))
		{
			dpy_name = &argv[i][2];
			continue;
		}

#ifdef USE_GRAPHICS
		if (prefix(argv[i], "-s"))
		{
			smoothRescaling = FALSE;
			continue;
		}

		if (prefix(argv[i], "-o"))
		{
			arg_graphics = GRAPHICS_ORIGINAL;
			continue;
		}

		if (prefix(argv[i], "-a"))
		{
			arg_graphics = GRAPHICS_ADAM_BOLT;
			continue;
		}

		if (prefix(argv[i], "-g"))
		{
			smoothRescaling = FALSE;
			arg_graphics = GRAPHICS_DAVID_GERVAIS;
			continue;
		}

		if (prefix(argv[i], "-b"))
		{
			use_bigtile = TRUE;
			continue;
		}

#endif /* USE_GRAPHICS */

		if (prefix(argv[i], "-n"))
		{
			num_term = atoi(&argv[i][2]);
			if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA;
			else if (num_term < 1) num_term = 1;
			continue;
		}

		plog_fmt("Ignoring option: %s", argv[i]);
	}


	/* Init the Metadpy if possible */
	if (Metadpy_init_name(dpy_name)) return (-1);


	/* Prepare cursor color */
	MAKE(xor, infoclr);
	Infoclr_set(xor);
	Infoclr_init_ppn(Metadpy->fg, Metadpy->bg, "xor", 0);


	/* Prepare normal colors */
	for (i = 0; i < 256; ++i)
	{
		Pixell pixel;

		MAKE(clr[i], infoclr);

		Infoclr_set(clr[i]);

		/* Acquire Angband colors */
		color_table[i][0] = angband_color_table[i][0];
		color_table[i][1] = angband_color_table[i][1];
		color_table[i][2] = angband_color_table[i][2];
		color_table[i][3] = angband_color_table[i][3];

		/* Default to monochrome */
		pixel = ((i == 0) ? Metadpy->bg : Metadpy->fg);

		/* Handle color */
		if (Metadpy->color)
		{
			/* Create pixel */
			pixel = create_pixel(Metadpy->dpy,
			                     color_table[i][1],
			                     color_table[i][2],
			                     color_table[i][3]);
		}

		/* Initialize the color */
		Infoclr_init_ppn(pixel, Metadpy->bg, "cpy", 0);
	}


	/* Initialize the windows */
	for (i = 0; i < num_term; i++)
	{
		term_data *td = &data[i];

		/* Initialize the term_data */
		term_data_init(td, i);

		/* Save global entry */
		angband_term[i] = Term;
	}

	/* Raise the "Angband" window */
	Infowin_set(data[0].win);
	Infowin_raise();

	/* Activate the "Angband" window screen */
	Term_activate(&data[0].t);


#ifdef USE_GRAPHICS

	/* Try graphics */
	switch (arg_graphics)
	{
	case GRAPHICS_ADAM_BOLT:
		/* Use tile graphics of Adam Bolt */
		bitmap_file = "16x16.bmp";

		/* Try the "16x16.bmp" file */
		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Use the "16x16.bmp" file if it exists */
		if (0 == fd_close(fd_open(filename, O_RDONLY)))
		{
			/* Use graphics */
			use_graphics = TRUE;
			use_transparency = TRUE;

			pict_wid = pict_hgt = 16;

			ANGBAND_GRAF = "new";

			break;
		}
		/* Fall through */

	case GRAPHICS_ORIGINAL:
		/* Use original tile graphics */
		bitmap_file = "8x8.bmp";

		/* Try the "8x8.bmp" file */
		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Use the "8x8.bmp" file if it exists */
		if (0 == fd_close(fd_open(filename, O_RDONLY)))
		{
			/* Use graphics */
			use_graphics = TRUE;

			pict_wid = pict_hgt = 8;

			ANGBAND_GRAF = "old";
			break;
		}
		break;

	case GRAPHICS_DAVID_GERVAIS:
		/* Use tile graphics of David Gervais */
		bitmap_file = "32x32.bmp";

		/* Use graphics */
		use_graphics = TRUE;
		use_transparency = TRUE;

		pict_wid = pict_hgt = 32;

		ANGBAND_GRAF = "david";
		break;
	}

	/* Load graphics */
	if (use_graphics)
	{
		Display *dpy = Metadpy->dpy;

		XImage *tiles_raw;

		/* Initialize */
		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];
			td->tiles = NULL;
		}

		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Load the graphical tiles */
		tiles_raw = ReadBMP(dpy, filename);

		if (tiles_raw)
		{
			/* Initialize the windows */
			for (i = 0; i < num_term; i++)
			{
				int j;
				bool same = FALSE;

				term_data *td = &data[i];
				term_data *o_td = NULL;

				term *t = &td->t;

				/* Graphics hook */
				t->pict_hook = Term_pict_x11;

				/* Use graphics sometimes */
				t->higher_pict = TRUE;

				/* Look for another term with same font size */
				for (j = 0; j < i; j++)
				{
					o_td = &data[j];

					if ((td->fnt->twid == o_td->fnt->twid) && (td->fnt->hgt == o_td->fnt->hgt))
					{
						same = TRUE;
						break;
					}
				}

				if (!same)
				{
					/* Resize tiles */
					td->tiles = ResizeImage(dpy, tiles_raw,
					                        pict_wid, pict_hgt,
					                        td->fnt->twid, td->fnt->hgt);
				}
				else
				{
					/* Use same graphics */
					td->tiles = o_td->tiles;
				}
			}

			/* Free tiles_raw */
			FREE(tiles_raw);
		}
                        
		/* Initialize the transparency masks */
		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];
			int ii, jj;
			int depth = DefaultDepth(dpy, DefaultScreen(dpy));
			Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy));
			int total;


			/* Determine total bytes needed for image */
			ii = 1;
			jj = (depth - 1) >> 2;
			while (jj >>= 1) ii <<= 1;
			total = td->fnt->twid * td->fnt->hgt * ii;


			TmpData = (char *)malloc(total);

			td->TmpImage = XCreateImage(dpy,visual,depth,
				ZPixmap, 0, TmpData,
				td->fnt->twid, td->fnt->hgt, 32, 0);

		}
	}

#endif /* USE_GRAPHICS */


	/* Success */
	return (0);
}
示例#3
0
/*
 * Prepare "curses" for use by the file "term.c"
 *
 * Installs the "hook" functions defined above, and then activates
 * the main screen "term", which clears the screen and such things.
 *
 * Someone should really check the semantics of "initscr()"
 */
errr init_gcu(int argc, char *argv[])
{
   int i;

   int num_term = 4, next_win = 0;
   char path[1024];

   /* Unused */
   (void)argc;
   (void)argv;


#ifdef USE_SOUND

   /* Build the "sound" path */
   path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");

   /* Allocate the path */
   ANGBAND_DIR_XTRA_SOUND = string_make(path);

#endif

   /* Extract the normal keymap */
   keymap_norm_prepare();

#if defined(USG)
   /* Initialize for USG Unix */
   if (initscr() == NULL) return (-1);
#else
   /* Initialize for others systems */
   if (initscr() == (WINDOW*)ERR) return (-1);
#endif

   /* Activate hooks */
   quit_aux = hook_quit;
   core_aux = hook_quit;

   /* Hack -- Require large screen, or Quit with message */
   i = ((LINES < 24) || (COLS < 80));
   if (i) quit("Angband needs an 80x24 'curses' screen");


#ifdef A_COLOR

   /*** Init the Color-pairs and set up a translation table ***/

   /* Do we have color, and enough color, available? */
   can_use_color = ((start_color() != ERR) && has_colors() &&
		    (COLORS >= 8) && (COLOR_PAIRS >= 8));

#ifdef REDEFINE_COLORS
	/* Can we change colors? */
	can_fix_color = (can_use_color && can_change_color() &&
			 (COLORS >= 16) && (COLOR_PAIRS > 8));
#endif

   /* Attempt to use customized colors */
   if (can_fix_color)
   {
      /* Prepare the color pairs */
      for (i = 1; i <= 63; i++)
      {
	 /* Reset the color */
	 if (init_pair(i, (i - 1) % 8, (i - 1) / 8) == ERR)
	 {
	    quit("Color pair init failed");
	 }

	/* Set up the colormap */
	colortable[i - 1] = (COLOR_PAIR(i) | A_NORMAL);
	colortable[i + 7] = (COLOR_PAIR(i) | A_BRIGHT);

	/* XXX XXX XXX Take account of "gamma correction" */

	/* Prepare the "Angband Colors" */
	Term_xtra_gcu_react();
      }
   }
   /* Attempt to use colors */
   else if (can_use_color)
   {
		/* Color-pair 0 is *always* WHITE on BLACK */

		/* Prepare the color pairs */
		init_pair(1, COLOR_RED,     COLOR_BLACK);
		init_pair(2, COLOR_GREEN,   COLOR_BLACK);
		init_pair(3, COLOR_YELLOW,  COLOR_BLACK);
		init_pair(4, COLOR_BLUE,    COLOR_BLACK);
		init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
		init_pair(6, COLOR_CYAN,    COLOR_BLACK);
		init_pair(7, COLOR_BLACK,   COLOR_BLACK);

		/* Prepare the "Angband Colors" -- Bright white is too bright */
		/* Changed in Drangband. Cyan as grey sucks -- -TM- */
		colortable[0] = (COLOR_PAIR(7) | A_NORMAL);	/* Black */
		colortable[1] = (COLOR_PAIR(0) | A_BRIGHT);	/* White */
		colortable[2] = (COLOR_PAIR(0) | A_NORMAL);	/* Grey XXX */
		colortable[3] = (COLOR_PAIR(1) | A_BRIGHT);	/* Orange XXX */
		colortable[4] = (COLOR_PAIR(1) | A_NORMAL);	/* Red */
		colortable[5] = (COLOR_PAIR(2) | A_NORMAL);	/* Green */
		colortable[6] = (COLOR_PAIR(4) | A_NORMAL);	/* Blue */
		colortable[7] = (COLOR_PAIR(3) | A_NORMAL);	/* Umber */
		colortable[8] = (COLOR_PAIR(7) | A_BRIGHT);	/* Dark-grey XXX */
		colortable[9] = (COLOR_PAIR(0) | A_NORMAL);	/* Light-grey XXX */
		colortable[10] = (COLOR_PAIR(5) | A_NORMAL);	/* Purple */
		colortable[11] = (COLOR_PAIR(3) | A_BRIGHT);	/* Yellow */
		colortable[12] = (COLOR_PAIR(5) | A_BRIGHT);	/* Light Red XXX */
		colortable[13] = (COLOR_PAIR(2) | A_BRIGHT);	/* Light Green */
		colortable[14] = (COLOR_PAIR(4) | A_BRIGHT);	/* Light Blue */
		colortable[15] = (COLOR_PAIR(3) | A_NORMAL);	/* Light Umber XXX */

   }

#endif

#ifdef USE_SOUND
   /* Handle "arg_sound" */
   if (use_sound != arg_sound)
   {
      /* Initialize (if needed) */
      if (arg_sound && !init_sound())
      {
	 /* Warning */
	 plog("Cannot initialize sound!");

	 /* Cannot enable */
	 arg_sound = FALSE;
      }

      /* Change setting */
      use_sound = arg_sound;
   }
#endif

#ifdef USE_GRAPHICS

   /* Try graphics */
   if (arg_graphics)
   {
      /* if USE_NCURSES_ACS is defined, we can do something with graphics in curses! */
#ifdef USE_NCURSES_ACS
      use_graphics = TRUE;
#endif
   }

#endif /* USE_GRAPHICS */



   /*** Low level preparation ***/

#ifdef USE_GETCH

   /* Paranoia -- Assume no waiting */
   nodelay(stdscr, FALSE);

#endif

   /* Prepare */
   cbreak();
   noecho();
   nonl();
   raw();

   /* Extract the game keymap */
   keymap_game_prepare();


   /*** Now prepare the term(s) ***/
   for (i = 0; i < num_term; i++)
   {
      int rows, cols;
      int y, x;

      switch (i)
      {
	 /* Upper left */
	 case 0: rows = 24;
	    cols = 80;
	    y = x = 0;
	    break;
	 /* Lower left */
	 case 1: rows = LINES - 25;
	    cols = 80;
	    y = 24;
	    x = 0;
	    break;
	 /* Upper right */
	 case 2: rows = 24;
	    cols = COLS - 81;
	    y = 0;
	    x = 81;
	    break;
	 /* Lower right */
	 case 3: rows = LINES - 25;
	    cols = COLS - 81;
	    y = 24;
	    x = 81;
	    break;
	 /* XXX */
	 default: rows = cols = 0;
	     y = x = 0;
	     break;
      }

      /* No non-windows */
      if (rows <= 0 || cols <= 0) continue;

      /* Initialize */
      term_data_init(&data[next_win], rows, cols, y, x);

      /* Store */
      angband_term[next_win] = Term;

      next_win++;
   }

   /* Activate the "Angband" window screen */
   Term_activate(&data[0].t);

   /* Store */
   term_screen = &data[0].t;

   /* Success */
   return (0);
}
/*
 * Initialization function for an X Athena Widget module to Angband
 *
 * We should accept "-d<dpy>" requests in the "argv" array.  XXX XXX XXX
 */
errr init_xaw(int argc, char **argv)
{
	int i;
	Widget topLevel;
	Display *dpy;

	cptr dpy_name = "";


#ifdef USE_GRAPHICS

	cptr bitmap_file = "";
	char filename[1024];

	int pict_wid = 0;
	int pict_hgt = 0;

	char *TmpData;

#endif /* USE_GRAPHICS */

	/* Parse args */
	for (i = 1; i < argc; i++)
	{
		if (prefix(argv[i], "-d"))
		{
			dpy_name = &argv[i][2];
			continue;
		}

#ifdef USE_GRAPHICS
		if (prefix(argv[i], "-s"))
		{
			smoothRescaling = FALSE;
			continue;
		}

		if (prefix(argv[i], "-o"))
		{
			arg_graphics = GRAPHICS_ORIGINAL;
			continue;
		}

		if (prefix(argv[i], "-a"))
		{
			arg_graphics = GRAPHICS_ADAM_BOLT;
			continue;
		}

		if (prefix(argv[i], "-g"))
		{
			smoothRescaling = FALSE;
			arg_graphics = GRAPHICS_DAVID_GERVAIS;
			continue;
		}

		if (prefix(argv[i], "-b"))
		{
			use_bigtile = TRUE;
			continue;
		}

#endif /* USE_GRAPHICS */

		if (prefix(argv[i], "-n"))
		{
			num_term = atoi(&argv[i][2]);
			if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA;
			else if (num_term < 1) num_term = 1;
			continue;
		}

		plog_fmt("Ignoring option: %s", argv[i]);
	}


	/* Attempt to open the local display */
	dpy = XOpenDisplay(dpy_name);

	/* Failure -- assume no X11 available */
	if (!dpy) return (-1);

	/* Close the local display */
	XCloseDisplay(dpy);


#ifdef USE_XAW_LANG

	/* Support locale processing */
	XtSetLanguageProc(NULL, NULL, NULL);

#endif /* USE_XAW_LANG */


	/* Initialize the toolkit */
	topLevel = XtAppInitialize(&appcon, "Angband", NULL, 0, &argc, argv,
	                           fallback, NULL, 0);


	/* Initialize the windows */
	for (i = 0; i < num_term; i++)
	{
		term_data *td = &data[i];

		term_data_init(td, topLevel, 1024, termNames[i],
		               (i == 0) ? specialArgs : defaultArgs,
		               TERM_FALLBACKS, i);

		angband_term[i] = Term;
	}

	/* Activate the "Angband" window screen */
	Term_activate(&data[0].t);

	/* Raise the "Angband" window */
	term_raise(&data[0]);


#ifdef USE_GRAPHICS

	/* Try graphics */
	switch (arg_graphics)
	{
	case GRAPHICS_ADAM_BOLT:
		/* Use tile graphics of Adam Bolt */
		bitmap_file = "16x16.bmp";

		/* Try the "16x16.bmp" file */
		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Use the "16x16.bmp" file if it exists */
		if (0 == fd_close(fd_open(filename, O_RDONLY)))
		{
			/* Use graphics */
			use_graphics = GRAPHICS_ADAM_BOLT;
			use_transparency = TRUE;

			pict_wid = pict_hgt = 16;

			ANGBAND_GRAF = "new";

			break;
		}
		/* Fall through */

	case GRAPHICS_ORIGINAL:
		/* Use original tile graphics */
		bitmap_file = "8x8.bmp";

		/* Try the "8x8.bmp" file */
		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Use the "8x8.bmp" file if it exists */
		if (0 == fd_close(fd_open(filename, O_RDONLY)))
		{
			/* Use graphics */
			use_graphics = GRAPHICS_ORIGINAL;

			pict_wid = pict_hgt = 8;

			ANGBAND_GRAF = "old";
			break;
		}
		break;

	case GRAPHICS_DAVID_GERVAIS:
		/* Use tile graphics of David Gervais */
		bitmap_file = "32x32.bmp";

		/* Use graphics */
		use_graphics = GRAPHICS_DAVID_GERVAIS;
		use_transparency = TRUE;

		pict_wid = pict_hgt = 32;

		ANGBAND_GRAF = "david";
		break;
	}

	/* Load graphics */
	if (use_graphics)
	{
		/* Hack -- Get the Display */
		term_data *td = &data[0];
		Widget widget = (Widget)(td->widget);
		Display *dpy = XtDisplay(widget);

		XImage *tiles_raw;

		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];
			td->widget->angband.tiles = NULL;
		}

		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Load the graphical tiles */
		tiles_raw = ReadBMP(dpy, filename);

		if (tiles_raw)
		{
			/* Initialize the windows */
			for (i = 0; i < num_term; i++)
			{
				int j;
				bool same = FALSE;

				term_data *td = &data[i];
				term_data *o_td = NULL;

				term *t = &td->t;

				t->pict_hook = Term_pict_xaw;

				t->higher_pict = TRUE;

				/* Look for another term with same font size */
				for (j = 0; j < i; j++)
				{
					o_td = &data[j];

					if ((td->widget->angband.tilewidth == o_td->widget->angband.tilewidth) &&
					    (td->widget->angband.fontheight == o_td->widget->angband.fontheight))
					{
						same = TRUE;
						break;
					}
				}

				if (!same)
				{
					/* Resize tiles */
					td->widget->angband.tiles = ResizeImage(dpy, tiles_raw,
					                                        pict_wid, pict_hgt,
					                                        td->widget->angband.tilewidth,
					                                        td->widget->angband.fontheight);
				}
				else
				{
					/* Use same graphics */
					td->widget->angband.tiles = o_td->widget->angband.tiles;
				}
			}

			/* Free tiles_raw */
			FREE(tiles_raw);
		}

		/* Initialize the transparency temp storage */
		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];
			int ii, jj;
			int depth = DefaultDepth(dpy, DefaultScreen(dpy));
			Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy));
			int total;


			/* Determine total bytes needed for image */
			ii = 1;
			jj = (depth - 1) >> 2;
			while (jj >>= 1) ii <<= 1;
			total = td->widget->angband.tilewidth *
			        td->widget->angband.fontheight * ii;


			TmpData = (char *)malloc(total);

			td->widget->angband.TmpImage = XCreateImage(dpy,
				visual,depth,
				ZPixmap, 0, TmpData,
				td->widget->angband.tilewidth,
			        td->widget->angband.fontheight, 8, 0);
		}
	}

#endif /* USE_GRAPHICS */

	/* Success */
	return (0);
}
示例#5
0
/*
 * Prepare "curses" for use by the file "term.c"
 *
 * Installs the "hook" functions defined above, and then activates
 * the main screen "term", which clears the screen and such things.
 *
 * Someone should really check the semantics of "initscr()"
 */
errr init_gcu(int argc, char *argv[])
{
   int i;
   char path[1024];

#ifdef USE_SOUND

   /* Build the "sound" path */
   path_build(path, sizeof(path), ANGBAND_DIR_XTRA, "sound");

   /* Allocate the path */
   ANGBAND_DIR_XTRA_SOUND = z_string_make(path);

#endif

   /* Extract the normal keymap */
   keymap_norm_prepare();

   if (!getenv("ESCDELAY"))
       putenv("ESCDELAY=20");

#if defined(USG)
   /* Initialize for USG Unix */
   if (initscr() == NULL) return (-1);
#else
   /* Initialize for others systems */
   if (initscr() == (WINDOW*)ERR) return (-1);
#endif

   /* Activate hooks */
   quit_aux = hook_quit;
   core_aux = hook_quit;

   /* Hack -- Require large screen, or Quit with message */
   i = ((LINES < 27) || (COLS < 80));
   if (i) quit("Angband needs an 80x27 'curses' screen");


#ifdef A_COLOR

   /*** Init the Color-pairs and set up a translation table ***/

   /* Do we have color, and enough color, available? */
   can_use_color = ((start_color() != ERR) && has_colors() &&
		    (COLORS >= 8) && (COLOR_PAIRS >= 8));

#ifdef REDEFINE_COLORS
	/* Can we change colors? */
	can_fix_color = (can_use_color && can_change_color() &&
			 (COLORS >= 16) && (COLOR_PAIRS > 8));
#endif

#ifdef HAVE_USE_DEFAULT_COLORS
    /* Should we use curses' "default color" */
    if (use_default_colors() == OK) bg_color = -1;
#endif

   /* Attempt to use colors */
   if (can_use_color)
   {
		/* Color-pair 0 is *always* WHITE on BLACK */

		/* Prepare the color pairs */
        init_pair(1, COLOR_RED,     bg_color);
        init_pair(2, COLOR_GREEN,   bg_color);
        init_pair(3, COLOR_YELLOW,  bg_color);
        init_pair(4, COLOR_BLUE,    bg_color);
        init_pair(5, COLOR_MAGENTA, bg_color);
        init_pair(6, COLOR_CYAN,    bg_color);
        init_pair(7, COLOR_BLACK,   bg_color);

		/* Prepare the "Angband Colors" -- Bright white is too bright */
		/* Changed in Drangband. Cyan as grey sucks -- -TM- */
		colortable[0] = (COLOR_PAIR(7) | A_NORMAL);	/* Black */
		colortable[1] = (COLOR_PAIR(0) | A_BRIGHT);	/* White */
		colortable[2] = (COLOR_PAIR(0) | A_NORMAL);	/* Grey XXX */
		colortable[3] = (COLOR_PAIR(1) | A_BRIGHT);	/* Orange XXX */
		colortable[4] = (COLOR_PAIR(1) | A_NORMAL);	/* Red */
		colortable[5] = (COLOR_PAIR(2) | A_NORMAL);	/* Green */
		colortable[6] = (COLOR_PAIR(4) | A_NORMAL);	/* Blue */
		colortable[7] = (COLOR_PAIR(3) | A_NORMAL);	/* Umber */
		colortable[8] = (COLOR_PAIR(7) | A_BRIGHT);	/* Dark-grey XXX */
		colortable[9] = (COLOR_PAIR(0) | A_NORMAL);	/* Light-grey XXX */
		colortable[10] = (COLOR_PAIR(5) | A_NORMAL);	/* Purple */
		colortable[11] = (COLOR_PAIR(3) | A_BRIGHT);	/* Yellow */
		colortable[12] = (COLOR_PAIR(5) | A_BRIGHT);	/* Light Red XXX */
		colortable[13] = (COLOR_PAIR(2) | A_BRIGHT);	/* Light Green */
		colortable[14] = (COLOR_PAIR(4) | A_BRIGHT);	/* Light Blue */
		colortable[15] = (COLOR_PAIR(3) | A_NORMAL);	/* Light Umber XXX */

   }

#endif

#ifdef USE_SOUND
   /* Handle "arg_sound" */
   if (use_sound != arg_sound)
   {
      /* Initialize (if needed) */
      if (arg_sound && !init_sound())
      {
	 /* Warning */
	 plog("Cannot initialize sound!");

	 /* Cannot enable */
	 arg_sound = FALSE;
      }

      /* Change setting */
      use_sound = arg_sound;
   }
#endif

#ifdef USE_GRAPHICS

   /* Try graphics */
   if (arg_graphics)
   {
      /* if USE_NCURSES_ACS is defined, we can do something with graphics in curses! */
#ifdef USE_NCURSES_ACS
      use_graphics = TRUE;
#endif
   }

#endif /* USE_GRAPHICS */



   /*** Low level preparation ***/

#ifdef USE_GETCH

   /* Paranoia -- Assume no waiting */
   nodelay(stdscr, FALSE);

#endif

   /* Prepare */
   cbreak();
   noecho();
   nonl();
   raw();

   /* Extract the game keymap */
   keymap_game_prepare();

   /* Parse Args and Prepare the Terminals. Rectangles are specified
      as Width x Height, right? The game will allow you to have two
      strips of extra terminals, one on the right and one on the bottom.
      The map terminal will than fit in as big as possible in the remaining
      space.

      Examples:
        poschengband -mgcu -- -right 30x27,* -bottom *x7 will layout as

        Term-0: Map (COLS-30)x(LINES-7) | Term-1: 30x27
        --------------------------------|----------------------
        <----Term-3: (COLS-30)x7------->| Term-2: 30x(LINES-27)

        poschengband -mgcu -- -bottom *x7 -right 30x27,* will layout as

        Term-0: Map (COLS-30)x(LINES-7) | Term-2: 30x27
                                        |------------------------------
                                        | Term-3: 30x(LINES-27)
        ---------------------------------------------------------------
        <----------Term-1: (COLS)x7----------------------------------->

        Notice the effect on the bottom terminal by specifying its argument
        second or first. Notice the sequence numbers for the various terminals
        as you will have to blindly configure them in the window setup screen.
    */
    {
        int  spacer_cx = 1;
        int  spacer_cy = 1;
        int  min_cy = 3;
        int  min_cx = 10;
        int  right_cx = 0;
        int  right_cys[10] = {0};
        int  right_ct = 0;
        int  bottom_cy = 0;
        int  bottom_cxs[10] = {0};
        int  bottom_ct = 0;
        bool right_first = TRUE;
        int  map_cx, map_cy;
        int  next_win = 0;

        for (i = 1; i < argc; i++)
        {
            if (strcmp(argv[i], "-b") == 0)
            {
                term_data_init(&data[0], LINES, COLS, 0, 0);
                angband_term[0] = Term;
                break;
            }
            else if (strcmp(argv[i], "-right") == 0)
            {
                cptr arg, tmp;

                if (!bottom_cy)
                    right_first = TRUE;

                i++;
                if (i >= argc)
                    quit("Missing size specifier for -right");

                arg = argv[i];
                tmp = strchr(arg, 'x');
                if (!tmp)
                    quit("Expected something like -right 60x27,* for two right hand terminals of 60 columns, the first 27 lines and the second whatever is left.");
                right_cx = atoi(arg);
                tmp++;
                right_ct = _parse_size_list(tmp, right_cys, 10);
            }
            else if (strcmp(argv[i], "-bottom") == 0)
            {
                cptr arg, tmp;

                if (!right_cx)
                    right_first = FALSE;

                i++;
                if (i >= argc)
                    quit("Missing size specifier for -bottom");

                arg = argv[i];
                tmp = strchr(arg, 'x');
                if (!tmp)
                    quit("Expected something like -bottom *x7 for a single bottom terminal of 7 lines using as many columns as are available.");
                tmp++;
                bottom_cy = atoi(tmp);
                bottom_ct = _parse_size_list(arg, bottom_cxs, 10);
            }
        }

        if (right_cx)
            map_cx = COLS - (right_cx + spacer_cx);
        else
            map_cx = COLS;

        if (bottom_cy)
            map_cy = LINES - (bottom_cy + spacer_cy);
        else
            map_cy = LINES;

        if (map_cx < 80 || map_cy < 27)
            quit(format("Failed: PosChengband needs an 80x27 map screen, not %dx%d", map_cx, map_cy));

        /* Map Window: Upper Left */
        term_data_init(&data[next_win], map_cy, map_cx, 0, 0);
        angband_term[next_win] = Term;
        next_win++;

        /* Right Hand Strip */
        if (right_first)
        {
            int cy_remaining = LINES;
            int x = map_cx + spacer_cx;
            int y = 0;

            for (i = 0; i < right_ct; i++)
            {
                int cy = right_cys[i];

                if (!cy) break;

                if (cy > cy_remaining)
                    cy = cy_remaining;

                if (cy > min_cy)
                {
                    term_data_init(&data[next_win], cy, right_cx, y, x);
                    angband_term[next_win] = Term;
                    next_win++;

                    y += cy + spacer_cy;
                    cy_remaining -= cy + spacer_cy;
                }
            }
        }

        /* Bottom Strip */
        {
            int cx_remaining = COLS;
            int x = 0;
            int y = map_cy + spacer_cy;

            if (right_first)
                cx_remaining -= (right_cx + spacer_cx);

            for (i = 0; i < bottom_ct; i++)
            {
                int cx = bottom_cxs[i];

                if (!cx) break;

                if (cx > cx_remaining)
                    cx = cx_remaining;

                if (cx > min_cx)
                {
                    term_data_init(&data[next_win], bottom_cy, cx, y, x);
                    angband_term[next_win] = Term;
                    next_win++;

                    x += cx + spacer_cx;
                    cx_remaining -= cx + spacer_cx;
                }
            }
        }

        /* Right Hand Strip: TODO: Refactor this code duplication!
           But note that if the user specifies -right before bottom,
           then the terminal sequence numbers should reflect this fact! */
        if (!right_first)
        {
            int cy_remaining = LINES - bottom_cy;
            int x = map_cx + spacer_cx;
            int y = 0;

            for (i = 0; i < right_ct; i++)
            {
                int cy = right_cys[i];

                if (!cy) break;

                if (cy > cy_remaining)
                    cy = cy_remaining;

                if (cy > min_cy)
                {
                    term_data_init(&data[next_win], cy, right_cx, y, x);
                    angband_term[next_win] = Term;
                    next_win++;

                    y += cy + spacer_cy;
                    cy_remaining -= cy + spacer_cy;
                }
            }
        }
    }

   /* Activate the "Angband" window screen */
   Term_activate(&data[0].t);

   /* Store */
   term_screen = &data[0].t;

#ifdef USE_GETCH
   /* Title screen (news.txt) won't draw otherwise for some reason ... */
   wrefresh(stdscr);
#endif

   /* Success */
   return (0);
}