void
draw_module (int module, char *graphic)
{
    int x, y, xx, yy;
    int row, col;
    
    if (module == 0) {
	row = 0;
	col = 0;
    } else {
	row = module % module_rows;
	col = module / module_rows;
    }

    x = 8 + (col * 24);
    y = 8 + (row * 24);

    hide_mouse ();

    Fgl_putbox (x + mbw->x, y + mbw->y, 16, 16, graphic);
    unhighlight_module_button (module);

    /* Modules we don't have enough tech for are greyed out. */
    if (module_tflag[module] == 0)
    {
	for (yy = -3; yy < 19; yy++)
	    for (xx = -3; xx < 19; xx += 2)
		Fgl_setpixel (x + xx + (yy % 2) + mbw->x,
			      y + yy + mbw->y, white (15));
    }
    redraw_mouse ();
}
Ejemplo n.º 2
0
void
draw_select_button_graphic (int button, char *graphic)
{
    Rect* b = &scr.select_buttons;
    int x, y, xx, yy;
    if (button < NUMOF_SELECT_BUTTONS_DOWN) {
	x = 8;
	y = 8 + (button * 24);
    } else {
	x = 8 + 24;
	y = 8 + ((button - NUMOF_SELECT_BUTTONS_DOWN) * 24);
    }

    Fgl_putbox (x + b->x, y + b->y, 16, 16, graphic);
    unhighlight_select_button (button);
    hide_mouse ();
    if (select_button_tflag[button] == 0)
    {
	for (yy = -3; yy < 19; yy++)
	    for (xx = -3; xx < 19; xx += 2)
		Fgl_setpixel (x + xx + (yy % 2) + b->x,
			      y + yy + b->y, white (15));
    }
    redraw_mouse ();
}
Ejemplo n.º 3
0
/* Adjust the main window origin, and refresh if necessary */
void
adjust_main_origin (int new_origin_x, int new_origin_y, int refresh)
{
    Rect* mw = &scr.main_win;

    if (new_origin_x < 1) {
	new_origin_x = 1;
    } else if (new_origin_x > WORLD_SIDE_LEN - mw->w / 16 - 1) {
	new_origin_x = WORLD_SIDE_LEN - mw->w / 16 - 1;
    }
    if (new_origin_y < 1) {
	new_origin_y = 1;
    } else if (new_origin_y > WORLD_SIDE_LEN - mw->h / 16 - 1) {
	new_origin_y = WORLD_SIDE_LEN - mw->h / 16 - 1;
    }

    if (new_origin_x == main_screen_originx
	&& new_origin_y == main_screen_originy)
    {
	return;
    }

    main_screen_originx = new_origin_x;
    main_screen_originy = new_origin_y;

    if (refresh) {
	request_main_screen ();
	hide_mouse ();
	refresh_main_screen ();
	redraw_mouse ();
    }
}
Ejemplo n.º 4
0
void
select_slow (void)
{
    hide_mouse ();
    pause_flag = 0;
    draw_pause (0);
    slow_flag = 1;
    draw_slow (1);
    med_flag = 0;
    draw_med (0);
    fast_flag = 0;
    draw_fast (0);
    redraw_mouse ();
}
Ejemplo n.º 5
0
void
do_help_buttons (int x, int y)
{
  int i;
  if (numof_help_buttons <= 0)
    return;
  for (i = 0; i < numof_help_buttons; i++)
    if (x > help_button_x[i]
	&& x < (help_button_x[i] + help_button_w[i])
	&& y > help_button_y[i]
	&& y < (help_button_y[i] + help_button_h[i]))
      {
	hide_mouse ();
	draw_help_page (help_button_s[i]);
	redraw_mouse ();
	break;
      }
}
Ejemplo n.º 6
0
static void fb_mouse_move(int dx, int dy)
{
	struct event ev;
	mouse_x += dx;
	mouse_y += dy;
	ev.ev = EV_MOUSE;
	if (mouse_x >= fb_xsize) mouse_x = fb_xsize - 1;
	if (mouse_y >= fb_ysize) mouse_y = fb_ysize - 1;
	if (mouse_x < 0) mouse_x = 0;
	if (mouse_y < 0) mouse_y = 0;
	ev.x = mouse_x;
	ev.y = mouse_y;
	ev.b = B_MOVE;
	if (((last_mouse_buttons & BM_ACT) == B_DOWN || (last_mouse_buttons & BM_ACT) == B_DRAG) &&
	    (last_mouse_buttons & BM_BUTT) < B_WHEELUP) {
		ev.b = (last_mouse_buttons & BM_BUTT) | B_DRAG;
	}
	if (!current_virtual_device) return;
	if (current_virtual_device->mouse_handler) current_virtual_device->mouse_handler(current_virtual_device, ev.x, ev.y, (int)ev.b);
	redraw_mouse();
}
void
highlight_module_button (int module)
{
    int x, y;
    int row, col;

    if (module == 0) {
	row = 0;
	col = 0;
    } else {
	row = module % module_rows;
	col = module / module_rows;
    }

    x = 8 + (col * 24) + mbw->x;
    y = 8 + (row * 24) + mbw->y;

    hide_mouse ();
    draw_small_bezel(x + 1, y + 1,
		     SELECT_BUTTON_WIDTH - 2, SELECT_BUTTON_WIDTH - 2,
		     yellow(0));
    redraw_mouse ();
}
Ejemplo n.º 8
0
void
select_pause (void)
{
    if (pause_flag) {
	/* unpause it */
	if (fast_flag)
	    select_fast ();
	else if (med_flag)
	    select_medium ();
	else if (slow_flag)
	    select_slow ();
	else
	    select_medium ();
    } else {
	/* pause it */
	hide_mouse ();
	pause_flag = 1;
	draw_pause (1);
	draw_slow (0);
	draw_med (0);
	draw_fast (0);
	redraw_mouse ();
    }
}
Ejemplo n.º 9
0
void
draw_help_page (char *helppage)
{
    Rect* mw = &scr.main_win;
    char *helppage_full, *helppage_short;
    int i, y;
    FILE *inf;
    char help_line[MAX_HELP_LINE];

    /* Return pages have arguments.  It is always true that "-2" means "Out" 
       and "-1" means "Back".  Semantics for other arguments depend upon
       the name of the source page (e.g. load game or choose residence). 
       Most of the times (except "Back"), this will exit the help system. */
    if (strncmp (helppage, "return", 6) == 0) {
	sscanf (&(helppage[6]), "%d", &help_return_val);

	/* If "Back" was clicked */
	if (help_return_val == -1 && help_history_count > 1) {
	    strcpy (helppage, help_button_history[help_history_count - 2]);
	    help_history_count -= 2;
	    goto continue_with_help;
	}

	/* XXX: WCK: residential selection is really ugly */
	if (help_history_count > 0 &&
	    strcmp (help_button_history[help_history_count - 1],
		    "res.tmp") == 0)
	{
	    switch (help_return_val) {
	    case (-2):
	    case (-1):
	    case (0):
	    case (1):
		selected_type = CST_RESIDENCE_LL;
		selected_type_cost = get_group_cost (GROUP_RESIDENCE_LL);
		break;
	    case (2):
		selected_type = CST_RESIDENCE_ML;
		selected_type_cost = get_group_cost (GROUP_RESIDENCE_ML);
		break;
	    case (3):
		selected_type = CST_RESIDENCE_HL;
		selected_type_cost = get_group_cost (GROUP_RESIDENCE_HL);
		break;
	    case (4):
		selected_type = CST_RESIDENCE_LH;
		selected_type_cost = get_group_cost (GROUP_RESIDENCE_LH);
		break;
	    case (5):
		selected_type = CST_RESIDENCE_MH;
		selected_type_cost = get_group_cost (GROUP_RESIDENCE_MH);
		break;
	    case (6):
		selected_type = CST_RESIDENCE_HH;
		selected_type_cost = get_group_cost (GROUP_RESIDENCE_HH);
		break;
	    }
	}
	else if (help_history_count > 0 &&
		 strcmp (help_button_history[help_history_count - 1],
			 "menu.hlp") == 0)
	{
	    switch (help_return_val) {
	    case 1:
		save_flag = 1;
		break;
	    case 2:
		prefs_flag = 1;
		break;
	    case 3:
		quit_flag = 1;
		break;
	    }
	}
	else if (help_history_count > 0 && 
		 strcmp (help_button_history[help_history_count - 1],
			 "opening.hlp") == 0)
	{
	    switch (help_return_val)
	    {
	    case (-2):
	    case (-1):
	    case (0):
		/* Random villiage */
		new_city (&main_screen_originx, &main_screen_originy, 1);
		adjust_main_origin (main_screen_originx,main_screen_originy,0);
		break;
	    case (1):
		/* Bare board */
		new_city (&main_screen_originx, &main_screen_originy, 0);
		adjust_main_origin (main_screen_originx,main_screen_originy,0);
		break;
	    case (2):
		/* Network start */
		network_flag = 1;
		break;
	    }
	}
	else if (help_history_count > 0 && 
		 strcmp (help_button_history[help_history_count - 1],
			 "newgame.hlp") == 0)
	{
	    switch (help_return_val)
	    {
	    case (0):
		/* Random villiage */
		new_city (&main_screen_originx, &main_screen_originy, 1);
		adjust_main_origin (main_screen_originx,main_screen_originy,0);
		break;
	    case (1):
		/* Bare board */
		new_city (&main_screen_originx, &main_screen_originy, 0);
		adjust_main_origin (main_screen_originx,main_screen_originy,0);
		break;
	    case (2):
		/* Network start */
		network_flag = 1;
		break;
	    }
	}
	else if (help_history_count > 0 &&
		 strcmp (help_button_history[help_history_count - 1],
			 "openload.hlp") == 0)
	{
	    switch (help_return_val)
	    {
	    case (-2):
	    case (-1):
	    case (0):
		new_city (&main_screen_originx, &main_screen_originy, 1);
		adjust_main_origin (main_screen_originx,main_screen_originy,0);
		break;
	    case (1):
		redraw_mouse ();
		load_opening_city ("good_times.scn");
		adjust_main_origin (main_screen_originx,main_screen_originy,0);
		hide_mouse ();
		break;
	    case (2):
		load_opening_city ("bad_times.scn");
		adjust_main_origin (main_screen_originx,main_screen_originy,0);
		break;
	    case (9):
		load_flag = 1;
		break;
	    }
	}
	else if (help_history_count > 0 &&
		 strcmp (help_button_history[help_history_count - 1],
			 "loadgame.hlp") == 0)
	{
	    switch (help_return_val)
	    {
	    case (1):
		redraw_mouse ();
		load_opening_city ("good_times.scn");
		adjust_main_origin (main_screen_originx,main_screen_originy,0);
		hide_mouse ();
		break;
	    case (2):
		load_opening_city ("bad_times.scn");
		adjust_main_origin (main_screen_originx,main_screen_originy,0);
		break;
	    case (9):
		load_flag = 1;
		break;
	    }
	}
	else if (help_history_count > 0 &&
		 strcmp (help_button_history[help_history_count - 1],
			 "ask-dir.hlp") == 0)
	{
	    if (help_return_val == 1 || help_return_val == -2)
		do_error ("User exited");
	}

	block_help_exit = 0;
	help_flag = 0;
	/* Fix origin */
#ifdef USE_EXPANDED_FONT
	Fgl_setwritemode (WRITEMODE_OVERWRITE | FONT_EXPANDED);
#else
	Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
#endif
	request_main_screen ();
	refresh_main_screen ();
	return;
    }

 continue_with_help:
    /* This buffer is just a copy of helppage.  Sometimes helppage is an 
       entry within help_button_s[], which gets overwritten when the page 
       is parsed. */
    if ((helppage_short = (char*) malloc (strlen(helppage) + 1)) == 0) {
	malloc_failure ();
    }
    strcpy (helppage_short, helppage);

    /* Right click on mini-screen */
    if (strncmp (helppage, "mini-screen.hlp", 15) == 0) {
	draw_big_mini_screen ();
    } else if (strncmp (helppage, "mini-in-main.hlp", 17) == 0) {
	/* do nothing */
    } else {
	/* This buffer is for the full path of the help file.
	   The file might be either in the help directory (most cases),
	   or in the temp directory (dynamically created pages). */
	if ((helppage_full = (char *) malloc (lc_save_dir_len 
					      + strlen (help_path) 
					      + strlen(helppage) + 2)) == 0) {
	    malloc_failure ();
	}

	/* Open the file */
	sprintf (helppage_full, "%s%s", help_path, helppage);
	if ((inf = fopen (helppage_full, "r")) == 0) {
	    sprintf (helppage_full, "%s%c%s", lc_save_dir, 
		     PATH_SLASH, helppage);
	    if ((inf = fopen (helppage_full, "r")) == 0) {
		sprintf (helppage_full, "%s%s", help_path, HELPERRORPAGE);
		if ((inf = fopen (helppage_full, "r")) == 0)
		    do_error ("Help error");
	    }
	}

	/* Parse and render help file */
	numof_help_buttons = 0;
	Fgl_fillbox (mw->x, mw->y, mw->w, mw->h, HELPBACKGROUNDCOLOUR);
	while (feof (inf) == 0) {
	    if (fgets (help_line, MAX_HELP_LINE, inf) == 0)
		break;
	    parse_helpline (help_line);
	}
	fclose (inf);

	/* For ask-dir, we add path info */
	if (strncmp (helppage_short, "ask-dir.hlp", 11) == 0) {
	    parse_helpline ("tcolour 0 255");
	    y = 100;
	    for (i = 0; i < askdir_lines; i++) {
		sprintf (help_line, "text -1 %d %s", y, askdir_path[i]);
		parse_helpline (help_line);
		y += 14;
	    }
	}
	free (helppage_full);
    }

    /* At this point, most of the page has been rendered.  Now we have 
       to draw in the "BACK" and "OUT" buttons.  */
    if (help_history_count > 0) {
	parse_helpline ("tcolour 122 153");
	parse_helpline (_("tbutton 4 387 return-1 BACK"));
    }
    parse_helpline ("tcolour 188 153");
    parse_helpline (_("tbutton 370 387 return-2 OUT"));
    parse_helpline ("tcolour -1 -1");
#if defined (commentout)
    if (help_history_count > 0) {
	parse_helpline ("tcolour 122 153");
	snprintf (help_line, MAX_HELP_LINE, "tbutton %d %d return-1 %s",
		  4, mw->h - 13, _("BACK"));
	parse_helpline (help_line);
    }
    parse_helpline ("tcolour 188 153");
    snprintf (help_line, MAX_HELP_LINE, "tbutton %d %d return-2 %s",
	      mw->w - 34, mw->h - 13, _("OUT"));
    parse_helpline (help_line);
    parse_helpline ("tcolour -1 -1");
#endif

    /* Add help page to history.  If history is going to overflow, 
       throw out oldest page.  */
    strcpy (help_button_history[help_history_count], helppage_short);
    help_history_count++;
    if (help_history_count >= MAX_HELP_HISTORY) {
	for (i = 0; i < (MAX_HELP_HISTORY - 1); i++)
	    strcpy (help_button_history[i], help_button_history[i + 1]);
	help_history_count--;
    }

    free (helppage_short);
}
Ejemplo n.º 10
0
static void fb_gpm_in(void *nic)
{
#ifndef USE_GPM_DX
	static int lx = -1, ly = -1;
#endif
	struct event ev;
	Gpm_Event gev;
	again:
	if (Gpm_GetEvent(&gev) <= 0) {
		unhandle_fb_mouse();
		return;
	}
	/*fprintf(stderr, "%x %x %d %d %d %d\n", gev.type, gev.buttons, gev.dx, gev.dy, gev.wdx, gev.wdy);*/
#ifndef USE_GPM_DX
	if (gev.x != lx || gev.y != ly) {
		mouse_x = (gev.x - 1) * fb_xsize / fb_txt_xsize + fb_xsize / fb_txt_xsize / 2 - 1;
		mouse_y = (gev.y - 1) * fb_ysize / fb_txt_ysize + fb_ysize / fb_txt_ysize / 2 - 1;
		lx = gev.x, ly = gev.y;
	}
#else
	if (gev.dx || gev.dy) {
		if (!((int)gev.type & gpm_smooth)) {
			mouse_x += gev.dx * 8;
			mouse_y += gev.dy * 8;
		}
#ifdef GPM_HAVE_SMOOTH
		else {
			mouse_x += gev.dx;
			mouse_y += gev.dy;
		}
#endif
	}
#endif
	ev.ev = EV_MOUSE;
	if (mouse_x >= fb_xsize) mouse_x = fb_xsize - 1;
	if (mouse_y >= fb_ysize) mouse_y = fb_ysize - 1;
	if (mouse_x < 0) mouse_x = 0;
	if (mouse_y < 0) mouse_y = 0;

	if (!((int)gev.type & gpm_smooth) && (gev.dx || gev.dy)) {
		mouse_x = (mouse_x + 8) / 8 * 8 - 4;
		mouse_y = (mouse_y + 8) / 8 * 8 - 4;
		if (mouse_x >= fb_xsize) mouse_x = fb_xsize - 1;
		if (mouse_y >= fb_ysize) mouse_y = fb_ysize - 1;
		if (mouse_x < 0) mouse_x = 0;
		if (mouse_y < 0) mouse_y = 0;
	}

	ev.x = mouse_x;
	ev.y = mouse_y;
	if (gev.buttons & GPM_B_LEFT) ev.b = B_LEFT;
	else if (gev.buttons & GPM_B_MIDDLE) ev.b = B_MIDDLE;
	else if (gev.buttons & GPM_B_RIGHT) ev.b = B_RIGHT;
	else ev.b = 0;
	if ((int)gev.type & GPM_DOWN) ev.b |= B_DOWN;
	else if ((int)gev.type & GPM_UP) ev.b |= B_UP;
	else if ((int)gev.type & GPM_DRAG) ev.b |= B_DRAG;
	else ev.b |= B_MOVE;

#ifdef HAVE_WDX_WDY
	if ((ev.b & BM_ACT) == B_DRAG || (ev.b & BM_ACT) == B_MOVE) {
		if (gev.wdy < 0) {
			ev.b &= ~BM_BUTT;
			ev.b |= B_WHEELDOWN;
		} else if (gev.wdy > 0) {
			ev.b &= ~BM_BUTT;
			ev.b |= B_WHEELUP;
		}
#if 0
	/* it doesn't work anyway - the exps2 protocol doesn't support it and evdev support in gpm is buggy */
		else if (gev.wdx < 0) {
			ev.b &= ~BM_BUTT;
			ev.b |= B_WHEELRIGHT;
		} else if (gev.wdx > 0) {
			ev.b &= ~BM_BUTT;
			ev.b |= B_WHEELLEFT;
#endif
	}
#endif

#ifndef USE_GPM_DX
	if (fb_msetsize < 0) {
	} else if (fb_msetsize < 10) {
		fb_msetsize++;
	} else if ((ev.b & BM_ACT) == B_MOVE && !(ev.b & BM_BUTT)) {
		fb_mouse_setsize();
		fb_msetsize = -1;
	}
#endif

	if (((ev.b & BM_ACT) == B_MOVE && !(ev.b & BM_BUTT)) || (ev.b & BM_ACT) == B_DRAG) {
		if (can_read(fb_hgpm)) goto again;
	}

	last_mouse_buttons = (int)ev.b;
	if (!current_virtual_device) return;
	if (current_virtual_device->mouse_handler) current_virtual_device->mouse_handler(current_virtual_device, ev.x, ev.y, (int)ev.b);
	redraw_mouse();
}

static int handle_fb_mouse(void)
{
	Gpm_Connect conn;
#ifndef USE_GPM_DX
	int gpm_ver = 0;
	struct winsize ws;
	fb_old_ws_v = 0;
#endif
	fb_hgpm = -1;
#ifndef USE_GPM_DX
	Gpm_GetLibVersion(&gpm_ver);
	fb_msetsize = -1;
	if (gpm_ver >= 11900) {
		int rs;
		EINTRLOOP(rs,ioctl(1, TIOCGWINSZ, &ws));
		if (rs != -1) {
			memcpy(&fb_old_ws, &ws, sizeof(struct winsize));
			fb_old_ws_v = 1;
			ws.ws_row *= 2;
			EINTRLOOP(rs, ioctl(1, TIOCSWINSZ, &ws));
			fb_msetsize = 0;
			memcpy(&fb_new_ws, &ws, sizeof ws);
		}
	}
	get_terminal_size(1, &fb_txt_xsize, &fb_txt_ysize);
#endif
	conn.eventMask = (unsigned short)~0U;
	conn.defaultMask = gpm_smooth;
	conn.minMod = 0;
	conn.maxMod = (unsigned short)~0U;
	if ((fb_hgpm = Gpm_Open(&conn, 0)) < 0) {
		unhandle_fb_mouse();
		return -1;
	}
	set_handlers(fb_hgpm, fb_gpm_in, (void (*)(void *))NULL, (void (*)(void *))NULL, NULL);
#ifdef SIGTSTP
	install_signal_handler(SIGTSTP, (void (*)(void *))sig_tstp, NULL, 0);
#endif
#ifdef SIGCONT
	install_signal_handler(SIGCONT, (void (*)(void *))sig_cont, NULL, 0);
#endif
#ifdef SIGTTIN
	install_signal_handler(SIGTTIN, (void (*)(void *))sig_tstp, NULL, 0);
#endif

	return 0;
}