void BoardView::draw_cursors(std::unordered_map<int32_t, CursorData>& cursors)
	{
		int width, height;
		getyx((WINDOW*)main, height, width);

		for (auto iterator = cursors.cbegin(); iterator != cursors.cend(); iterator++)
		{
			int x = iterator->second.x - cursor.offset_x;
			int y = iterator->second.y - cursor.offset_y;

			if (x < 0 || y < 0)
				continue;

			if (x >= width || y >= height)
				continue;

			wattron(main, COLOR_PAIR(iterator->second.color));

			if (wmove(main, y, 3*x) != ERR)
				waddwstr(main, L"[");
			if (wmove(main, y, 3*x+2) != ERR)
				waddwstr(main, L"]");

			wattroff(main, COLOR_PAIR(iterator->second.color));
		}
	}
Exemple #2
0
static void
legend(WINDOW *win, int level, Options state, wchar_t *buffer, int length)
{
    NCURSES_CONST char *showstate;

    switch (state) {
    default:
    case oDefault:
	showstate = "";
	break;
    case oMove:
	showstate = " (mvXXX)";
	break;
    case oWindow:
	showstate = " (winXXX)";
	break;
    case oMoveWindow:
	showstate = " (mvwinXXX)";
	break;
    }

    wmove(win, 0, 0);
    wprintw(win,
	    "The Strings/Chars displays should match.  Enter any characters, except:\n");
    wprintw(win,
	    "down-arrow or ^N to repeat on next line, 'w' for inner window, 'q' to exit.\n");
    wclrtoeol(win);
    wprintw(win, "Level %d,%s inserted %d characters <", level,
	    showstate, length);
    waddwstr(win, buffer);
    waddstr(win, ">");
}
Exemple #3
0
int t_wprint(WINDOW *win, t_char *fmt, ...)
{
	wchar_t buf[MAX_PRINT_LEN];
	va_list args;
	va_start(args, fmt);
	vswprintf(buf, MAX_PRINT_LEN, fmt, args);
	va_end(args);

	return waddwstr(win, buf);
}
Exemple #4
0
int t_vwprint(WINDOW *win, t_char *fmt, va_list args)
{
	wchar_t buf[MAX_PRINT_LEN];
	vswprintf(buf, MAX_PRINT_LEN, fmt, args);
	return waddwstr(win, buf);
}
Exemple #5
0
int
mvwaddwstr(WINDOW *win, int y, int x, wchar_t *ws)
{
	return ((wmove(win, y, x) == ERR ? ERR : waddwstr(win, ws)));
}
Exemple #6
0
static int
test_get_wstr(int level, char **argv, WINDOW *strwin)
{
    WINDOW *txtbox = 0;
    WINDOW *txtwin = 0;
    FILE *fp;
    int ch;
    int rc;
    int txt_x = 0, txt_y = 0;
    int base_y;
    int flavor = 0;
    int limit = getmaxx(strwin) - 5;
    int actual;
    wint_t buffer[MAX_COLS];

    if (argv[level] == 0) {
	beep();
	return FALSE;
    }

    if (level > 1) {
	txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
	box(txtbox, 0, 0);
	wnoutrefresh(txtbox);

	txtwin = derwin(txtbox,
			getmaxy(txtbox) - 2,
			getmaxx(txtbox) - 2,
			1, 1);
	base_y = 0;
    } else {
	txtwin = stdscr;
	base_y = BASE_Y;
    }

    keypad(txtwin, TRUE);	/* enable keyboard mapping */
    (void) cbreak();		/* take input chars one at a time, no wait for \n */
    (void) noecho();		/* don't echo input */

    txt_y = base_y;
    txt_x = 0;
    wmove(txtwin, txt_y, txt_x);

    if ((fp = fopen(argv[level], "r")) != 0) {
	while ((ch = fgetc(fp)) != EOF) {
	    if (waddch(txtwin, UChar(ch)) != OK) {
		break;
	    }
	}
	fclose(fp);
    } else {
	wprintw(txtwin, "Cannot open:\n%s", argv[1]);
    }

    wmove(txtwin, txt_y, txt_x);
    actual = ShowFlavor(strwin, txtwin, flavor, limit);
    while (!Quit(ch = mvwgetch(txtwin, txt_y, txt_x))) {
	switch (ch) {
	case KEY_DOWN:
	case 'j':
	    if (txt_y < getmaxy(txtwin) - 1) {
		MovePrompt(txtwin, actual, ++txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;
	case KEY_UP:
	case 'k':
	    if (txt_y > base_y) {
		MovePrompt(txtwin, actual, --txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;
	case KEY_LEFT:
	case 'h':
	    if (txt_x > 0) {
		MovePrompt(txtwin, actual, txt_y, --txt_x);
	    } else {
		beep();
	    }
	    break;
	case KEY_RIGHT:
	case 'l':
	    if (txt_x < getmaxx(txtwin) - 1) {
		MovePrompt(txtwin, actual, txt_y, ++txt_x);
	    } else {
		beep();
	    }
	    break;

	case 'w':
	    test_get_wstr(level + 1, argv, strwin);
	    if (txtbox != 0) {
		touchwin(txtbox);
		wnoutrefresh(txtbox);
	    } else {
		touchwin(txtwin);
		wnoutrefresh(txtwin);
	    }
	    break;

	case '-':
	    if (limit > 0) {
		actual = ShowFlavor(strwin, txtwin, flavor, --limit);
		MovePrompt(txtwin, actual, txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;

	case '+':
	    actual = ShowFlavor(strwin, txtwin, flavor, ++limit);
	    MovePrompt(txtwin, actual, txt_y, txt_x);
	    break;

	case '<':
	    if (flavor > 0) {
		actual = ShowFlavor(strwin, txtwin, --flavor, limit);
		MovePrompt(txtwin, actual, txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;

	case '>':
	    if (flavor + 1 < eMaxFlavor) {
		actual = ShowFlavor(strwin, txtwin, ++flavor, limit);
		MovePrompt(txtwin, actual, txt_y, txt_x);
	    } else {
		beep();
	    }
	    break;

	case ':':
	    actual = ShowFlavor(strwin, txtwin, flavor, limit);
	    *buffer = '\0';
	    rc = ERR;
	    echo();
	    (void) wattrset(txtwin, A_REVERSE);
	    switch (flavor) {
	    case eGetStr:
		if (txtwin != stdscr) {
		    wmove(txtwin, txt_y, txt_x);
		    rc = wget_wstr(txtwin, buffer);
		} else {
		    move(txt_y, txt_x);
		    rc = get_wstr(buffer);
		}
		break;
	    case eGetNStr:
		if (txtwin != stdscr) {
		    wmove(txtwin, txt_y, txt_x);
		    rc = wgetn_wstr(txtwin, buffer, limit);
		} else {
		    move(txt_y, txt_x);
		    rc = getn_wstr(buffer, limit);
		}
		break;
	    case eMvGetStr:
		if (txtwin != stdscr) {
		    rc = mvwget_wstr(txtwin, txt_y, txt_x, buffer);
		} else {
		    rc = mvget_wstr(txt_y, txt_x, buffer);
		}
		break;
	    case eMvGetNStr:
		if (txtwin != stdscr) {
		    rc = mvwgetn_wstr(txtwin, txt_y, txt_x, buffer, limit);
		} else {
		    rc = mvgetn_wstr(txt_y, txt_x, buffer, limit);
		}
		break;
	    case eMaxFlavor:
		break;
	    }
	    noecho();
	    (void) wattrset(txtwin, A_NORMAL);
	    wprintw(strwin, "%d", rc);
	    (void) waddwstr(strwin, (wchar_t *) buffer);
	    wnoutrefresh(strwin);
	    break;
	default:
	    beep();
	    break;
	}
	doupdate();
    }
    if (level > 1) {
	delwin(txtwin);
	delwin(txtbox);
    }
    return TRUE;
}