Example #1
0
int term_optionhandler(int k, const struct termopt *o)
{
	int flag = o->flag;
	union val v;
	switch (k) {
	case 0:       break;
	case MVLEFT:  textgfx_flags &= ~flag; break;
	case MVRIGHT: textgfx_flags |=  flag; break;
	case A_BTN:   textgfx_flags ^=  flag; break;
	default:      return 0;
	}
	printmenuitem_options(o->s, (textgfx_flags & flag)!=0);
	if (!k)
		return 1;
	v.integ = flag==MONOCHROME ? 2-k : k-1;
	setoption("term", o->key, v, 0);
#if !NO_BLOCKSTYLES
	if ((textgfx_flags & (WHITE_BG | TT_MONO))==(WHITE_BG | TT_BLOCKS) ||
	    _TT_BLOCKS_BG && (!_WHITE_BG || _MONOCHROME) &&
	    getopt_int("term", "block") == -1)
		textgfx_flags ^= TT_BLOCKS | TT_BLOCKS_BG;
#endif
	reset_block_chars();
	return 3;
}
Example #2
0
void textgfx_init()
{
#ifdef UNIX
	strcpy(_xwin.application_name, "vitetris");
	strcpy(_xwin.application_class, "Vitetris");
#endif
	if (install_allegro(SYSTEM_AUTODETECT, &errno, NULL) != 0)
		exit(1);
#ifdef UNIX
	sigaction(SIGINT, NULL, &allegro_sigint_handler);
	signal(SIGINT, sigint_handler);
#endif
	load_pc8x16_font();
	set_window_title(VITETRIS_VER);
	set_close_button_callback(close_btn);
#ifndef UNIX
	/* Seems to cause seg fault later quite randomly on Linux  */
	int depth = desktop_color_depth();
	if (depth != 0)
		set_color_depth(depth);
#endif
	virt_screen = set_screen(getopt_int("", "fullscreen"));
	lang |= LATIN1;
	if (!font8x16) {
		font8x16 = font;
		textgfx_flags |= ASCII;
	}
	setattr_normal();
#if WIN32 && !ALLEGRO_USE_CONSOLE
	if (exists("stdout.tmp")) {
		FILE *fp;
		freopen("stdout2.tmp", "w", stdout);
		fp = fopen("stdout.tmp", "r");
		if (fp) {
			char line[80];
			int i;
			for (i=0; i < 25 && fgets(line, 80, fp); i++) {
				setcurs(0, i);
				i += printline(line);	
			}
			fclose(fp);
			if (i) {
				refreshscreen();
				if (!strncmp(line, "Press ", 6)) {
					install_keyboard();
					clear_keybuf();
					readkey();
					remove_keyboard();
				}
			}
		}
		freopen("stdout.tmp", "w", stdout);
		delete_file("stdout2.tmp");
	}
#endif
}
Example #3
0
File: main.c Project: gsrr/Python
static void startup(int i)
{
#if XLIB
	in_xterm_init();
#endif
	textgfx_init();
	atexit(textgfx_end);
	init_inputdevs();
#if TERM_RESIZING
	enable_term_resizing();
#endif
	if (!bgdot)
		bgdot = default_bgdot();
	if (in_menu)
		textgfx_entermenu();
#if !TWOPLAYER
	setupgame(1);
#else
	if (i)
		goto setup;
	i = getopt_int("", "mode");
	if (i & MODE_NETWORK)
		i = 3;
	else
		i = 2-!(i & MODE_2PLAYER);
# if NO_MENU
setup:	setupgame(i);
# else
	if (!in_menu)
		goto setup;
	mk_invitfile();
	while (1) {
		i = startupmenu(i);
		if (!i)
			break;
#  ifdef INET
		if (i==3 && !netplaymenu())
			continue;
#  endif
		if (i <= 3) {
setup:			setupgame(i);
#  ifdef INET
			if (i==3 && playerlist_n > 0 && netplaymenu())
				goto setup;
#  endif
		}
		if (i==OPTIONS)
			optionsmenu();
		if (i==HIGHSCORES)
			hiscorelist();
	}
# endif /* !NO_MENU */
#endif	/* TWOPLAYER */
	textgfx_end();
}
Example #4
0
static int op_handler(int k, int *pos)
{
	const struct termopt opt = {ASCII, "CP437 ASCII", "drawing"};
	int i = *pos-2;
	if (i < 0) {
		if (k) {
			clearbox(0, 16, 0, 4);
			inputsetup_box(k-1, 1, 7);
		}
		draw_options_box();
		return 1;
	}
	if (!i) {
		if (k == MVLEFT)
			i = 0;
		else if (k == MVRIGHT)
			i = 1;
		else {
			i = !getopt_int("", "fullscreen");
			if (k == A_BTN)
				i = !i;
			else if (k)
				return 0;
		}
		printmenuitem_options("yes no", i);
		if (k) {
			union val v;
			v.integ = !i;
			setoption("", "fullscreen", v, 0);
		}
		i = 1;
	} else if (i == 1) {
		if (!k) {
			get_xy(&k, &i);
			setcurs(2, i+5);
			putnchars(HLINE, 28);
			help_alt_enter();
			setcurs(k, i);
			k = 0;
		}
		i = term_optionhandler(k, &opt);
	}
#ifndef NO_BLOCKSTYLES
	else
		i = select_blockstyle(k);
#endif
	if (i == 3) {
		draw_tetris_logo(0, 0);
		draw_options_box();
	}
	return i;
}
Example #5
0
static int gm_mode(int k, int *pos)
{
	const char *items[2] = {"A-type", "B-type"};
	union val v;
	int i;
	int ret;
	v.integ = getopt_int("", "mode");
	i = 1-!(v.integ & MODE_BTYPE);
	ret = selectitem(items, 2, &i, k);
	if (ret && k) {
		if (i)
			v.integ |= MODE_BTYPE;
		else
			v.integ &= ~MODE_BTYPE;
		setoption("", "mode", v, 0);
	}
	return ret;
}
Example #6
0
static int init_option(struct fw_stardict_st *st, int argc, char **argv)
{
	int opt;

	memset(st, 0, sizeof(*st));

	if (argc == 1)
		usage(argv[0]);

	while ((opt = getopt(argc, argv, "l:d:i:t:s:m:c:")) != -1) {
		switch (opt) {
			getopt_str('l', st->lang);
			getopt_str('d', st->date);
			getopt_str('i', st->idx);
			getopt_str('t', st->dict);
			getopt_str('s', st->script_file);
			getopt_str('c', st->compress);
			getopt_int('m', st->max_total);
		}
	}

	if (st->lang[0] == 0 || st->date[0] == 0 || st->idx[0] == 0 || st->dict[0] == 0)
		usage(argv[0]);

	if (st->compress[0] == 0)
		strcpy(st->compress, "gzip");

	if (st->script_file[0] && !dashf(st->script_file)) {
		printf("Not found %s\n", st->script_file);
		usage(argv[0]);
	}

	if (!dashf(st->idx)) {
		printf("%s: %s\n", st->idx, strerror(errno));
	}

	if (!dashf(st->dict)) {
		printf("%s: %s\n", st->dict, strerror(errno));
	}

	return 0;
}
Example #7
0
int startup_menu(int i, int x, int y)
{
	union val v;
	const char *menu[7] = {
		"1-Player Game",
		"2-Player Game",
#ifdef INET
		"Netplay",
#endif
		"Mode",
		"-------------",
		"Options",
		"Highscores"
	};
	menuhandler handlers[7] = {0, 0,
#ifdef INET
		0,
#endif
		gm_mode};
	i = openmenu(menu,
#ifdef INET
				1 +
#endif
				6, i, x, y, handlers);
	if (i && i <= 3) {
#ifdef INET
		if (i==3)
			v.integ = MODE_2PLAYER | MODE_NETWORK;
		else
#endif
		v.integ = i;
		v.integ |= getopt_int("", "mode") & MODE_BTYPE;
		setoption("", "mode", v, 0);
	}
	return i;
}