Exemple #1
0
/*
 * assume_default_colors --
 *	Set the default foreground and background colours.
 */
int
assume_default_colors(short fore, short back)
{
	/* Swap red/blue and yellow/cyan */
	if (_cursesi_screen->color_type == COLOR_OTHER) {
		switch (fore) {
		case COLOR_RED:
			fore = COLOR_BLUE;
			break;
		case COLOR_BLUE:
			fore = COLOR_RED;
			break;
		case COLOR_YELLOW:
			fore = COLOR_CYAN;
			break;
		case COLOR_CYAN:
			fore = COLOR_YELLOW;
			break;
		}
		switch (back) {
		case COLOR_RED:
			back = COLOR_BLUE;
			break;
		case COLOR_BLUE:
			back = COLOR_RED;
			break;
		case COLOR_YELLOW:
			back = COLOR_CYAN;
			break;
		case COLOR_CYAN:
			back = COLOR_YELLOW;
			break;
		}
	}
	__default_pair.fore = fore;
	__default_pair.back = back;
	__default_pair.flags = __USED;

	if (COLOR_PAIRS) {
		_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].fore = fore;
		_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].back = back;
		_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].flags = __USED;
	}

	/*
	 * If we've already called start_color(), make sure all instances
	 * of the curses default colour pair are dirty.
	 */
	if (__using_color)
		__change_pair(PAIR_NUMBER(__default_color));

	return(OK);
}
Exemple #2
0
gint viper_form_driver(FORM *form,gint request,guint32 flags,
   chtype active,chtype normal,gshort cursor_color)
{
   WINDOW   *window;
   chtype   eraser;
   chtype   temp_ch;
   gint     x,y;
   gint     retval;
   gshort   fg,bg;

   if(form==NULL) return ERR;
   
   if(form_sub(form)!=form_win(form)) window=form_sub(form);
   else window=form_win(form);

   getyx(window,y,x);
   eraser=field_back(current_field(form));
   mvwchgat(window,y,x,1,(eraser & A_ATTRIBUTES),
      PAIR_NUMBER(eraser & A_COLOR),NULL);
   
   retval=form_driver(form,request);

   if(flags & FORM_COLORIZE) 
      viper_form_colorize(form,active,normal,active,normal);

   if(flags & FORM_CURSOR_NONE) return retval;

   temp_ch=termattrs();
   if((flags & FORM_CURSOR_ULINE) && !(temp_ch & A_UNDERLINE)) return ERR;
   
   getyx(window,y,x);
   temp_ch=field_fore(current_field(form));
   if(flags & FORM_CURSOR_ULINE)
      mvwchgat(window,y,x,1,(temp_ch & A_ATTRIBUTES) | A_UNDERLINE,
         PAIR_NUMBER(temp_ch & A_COLOR),NULL);
   else
   {
      pair_content(PAIR_NUMBER(temp_ch & A_COLOR),&fg,&bg);
      if(cursor_color!=-1)
      {
         bg=cursor_color;
         mvwchgat(window,y,x,1,A_NORMAL,viper_color_pair(fg,bg),NULL);
      }
      else mvwchgat(window,y,x,1,A_REVERSE,viper_color_pair(fg,bg),NULL);
   }
   
   return E_OK;
}
Exemple #3
0
// int mvwscanw (WINDOW *,int,int, NCURSES_CONST char *,...) {}
// int napms (int) {}
// WINDOW *newpad (int,int) {}
// SCREEN *newterm (NCURSES_CONST char *,FILE *,FILE *) {}
WINDOW *newwin(int num_lines, int num_columns, int begy, int begx)
{
	int i;

	/* Use next statically allocated window. */
	// TODO: Error handling.
	// TODO: WINDOWLIST?
	WINDOW *win = &window_list[window_count++];

	// bool is_pad = (flags & _ISPAD);

	// TODO: Checks.

	win->_cury = 0;
	win->_curx = 0;
	win->_maxy = num_lines - 1;
	win->_maxx = num_columns - 1;
	win->_begy = begy;
	win->_begx = begx;
	// win->_yoffset = SP->_topstolen;

	win->_line = ldat_list[ldat_count++];

	/* FIXME: Is this right? Should the window attributes be normal? */
	win->_color = PAIR_NUMBER(0);
	win->_attrs = A_NORMAL;

	for (i = 0; i < num_lines; i++)
		win->_line[i].text =
		     (NCURSES_CH_T *)&linebuf_list[linebuf_count++];

	return win;
}
Exemple #4
0
static char *
decode_cchar(char *source, cchar_t *fillin, cchar_t *target)
{
    int color;
    attr_t attr = fillin->attr;
    wchar_t chars[CCHARW_MAX];
    int append = 0;
    int value = 0;

    T(("decode_cchar  '%s'", source));
    *target = blank;
#if NCURSES_EXT_COLORS
    color = fillin->ext_color;
#else
    color = (int) PAIR_NUMBER(attr);
#endif
    source = decode_attr(source, &attr, &color);
    memset(chars, 0, sizeof(chars));
    source = decode_char(source, &value);
    chars[0] = (wchar_t) value;
    /* handle combining characters */
    while (source[0] == MARKER && source[1] == APPEND) {
	source += 2;
	source = decode_char(source, &value);
	if (++append < CCHARW_MAX) {
	    chars[append] = (wchar_t) value;
	}
    }
    setcchar(target, chars, attr, (short) color, NULL);
    return source;
}
Exemple #5
0
void gettext(int left, int top, int right, int bottom, unsigned char *dest)
{
    int orig_y, orig_x;
    getyx(stdscr, orig_y, orig_x);
    for (int y = top - 1; y <= bottom - 1; y++)
    {
        for (int x = left - 1; x <= right - 1; x++)
        {
            // FIXME make this not crap
            // FIXME make it handle attributes too
            wchar_t w;
            mvinnwstr(y, x, &w, 1);
            for (unsigned int i = 0; i < 256; i++)
            {
                if (cp437[i] == w)
                {
                    *dest++ = w;
                }
            }
            *dest = PAIR_NUMBER(inch() & A_COLOR) - 1;
            if (*dest > WHITE)
                *dest = MAGENTA;
            if (inch() & A_BOLD)
                *dest += DARKGRAY;
            dest++;
        }
    }
    move(orig_y, orig_x);
}
Exemple #6
0
static chtype
merge_colors(chtype foreground, chtype background)
{
    chtype result = foreground;
    if ((foreground & A_COLOR) != (background & A_COLOR)) {
	short fg_f, bg_f;
	short fg_b, bg_b;
	short fg_pair = (short) PAIR_NUMBER(foreground);
	short bg_pair = (short) PAIR_NUMBER(background);

	if (pair_content(fg_pair, &fg_f, &bg_f) != ERR
	    && pair_content(bg_pair, &fg_b, &bg_b) != ERR) {
	    result &= ~A_COLOR;
	    result |= dlg_color_pair(fg_f, bg_b);
	}
    }
    return result;
}
Exemple #7
0
SCM
gucu_slk_attr ()
{
  attr_t rendition, attributes;
  short color_pair_number;
  rendition = slk_attr ();
  attributes = rendition;
  attributes &= A_ATTRIBUTES ^ A_COLOR;
  color_pair_number = PAIR_NUMBER (rendition & A_COLOR);

  return scm_list_2 (_scm_from_attr (attributes),
		     scm_from_short (color_pair_number));
}
Exemple #8
0
static char *
decode_chtype(char *source, chtype fillin, chtype *target)
{
    attr_t attr = ChAttrOf(fillin);
    int color = PAIR_NUMBER((int) attr);
    int value;

    T(("decode_chtype '%s'", source));
    source = decode_attr(source, &attr, &color);
    source = decode_char(source, &value);
    *target = (ChCharOf(value) | attr | (chtype) COLOR_PAIR(color));
    /* FIXME - ignore combining characters */
    return source;
}
Exemple #9
0
static void _set_attr(chtype ch)
{
    ch &= (A_COLOR|A_BOLD|A_BLINK|A_REVERSE);

    if (oldch != ch)
    {
        short newfg, newbg;

        if (SP->mono)
            return;

        PDC_pair_content(PAIR_NUMBER(ch), &newfg, &newbg);

        newfg |= (ch & A_BOLD) ? 8 : 0;
        newbg |= (ch & A_BLINK) ? 8 : 0;

        if (ch & A_REVERSE)
        {
            short tmp = newfg;
            newfg = newbg;
            newbg = tmp;
        }

        if (newfg != foregr)
        {
            SDL_SetPalette(pdc_font, SDL_LOGPAL,
                           pdc_color + newfg, pdc_flastc, 1);
            foregr = newfg;
        }

        if (newbg != backgr)
        {
            if (newbg == -1)
                SDL_SetColorKey(pdc_font, SDL_SRCCOLORKEY, 0);
            else
            {
                if (backgr == -1)
                    SDL_SetColorKey(pdc_font, 0, 0);

                SDL_SetPalette(pdc_font, SDL_LOGPAL,
                               pdc_color + newbg, 0, 1);
            }

            backgr = newbg;
        }

        oldch = ch;
    }
}
Exemple #10
0
slk_attron(const chtype attr)
{
    T((T_CALLED("slk_attron(%s)"), _traceattr(attr)));

    if (SP != 0 && SP->_slk != 0) {
	TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP->_slk->attr))));
	AddAttr(SP->_slk->attr, attr);
	if ((attr & A_COLOR) != 0) {
	    SetPair(SP->_slk->attr, PAIR_NUMBER(attr));
	}
	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP->_slk->attr))));
	returnCode(OK);
    } else
	returnCode(ERR);
}
Exemple #11
0
int wattr_get(WINDOW *win, attr_t *attrs, short *color_pair, void *opts)
{
    PDC_LOG(("wattr_get() - called\n"));

    if (!win)
        return ERR;

    if (attrs)
        *attrs = win->_attrs & (A_ATTRIBUTES & ~A_COLOR);

    if (color_pair)          /* BJG */
        *color_pair = (short)PAIR_NUMBER(win->_attrs);

    return OK;
}
Exemple #12
0
static void viper_kmio_show_mouse(MEVENT *mouse_event)
{
   extern VIPER      *viper;
   extern WINDOW     *SCREEN_WINDOW;
   WINDOW            *screen_window;
   static chtype     color;
   gshort            fg,bg;

   screen_window=SCREEN_WINDOW;

   if(viper->console_mouse==NULL)
   {
      viper->console_mouse=newwin(1,1,0,0);
      color=mvwinch(screen_window,0,0);
      pair_content(PAIR_NUMBER(color & A_COLOR),&fg,&bg);
      if(bg==COLOR_RED || bg==COLOR_YELLOW || bg==COLOR_MAGENTA)
         color=VIPER_COLORS(COLOR_CYAN,COLOR_CYAN);
      if(bg==COLOR_CYAN || bg==COLOR_BLUE)
         color=VIPER_COLORS(COLOR_YELLOW,COLOR_YELLOW);
   }

   if(mouse_event!=NULL)
   {
      color=mvwinch(screen_window,mouse_event->y,mouse_event->x);
      pair_content(PAIR_NUMBER(color & A_COLOR),&fg,&bg);
      if(bg==COLOR_RED || bg==COLOR_YELLOW || bg==COLOR_MAGENTA) 
         color=VIPER_COLORS(COLOR_CYAN,COLOR_CYAN);
      else
         color=VIPER_COLORS(COLOR_YELLOW,COLOR_YELLOW);
      mvwin(viper->console_mouse,mouse_event->y,mouse_event->x);
   }

   mvwaddch(viper->console_mouse,0,0,' ' | color);

   return;
}
NCURSES_SP_NAME(slk_attron) (NCURSES_SP_DCLx const chtype attr)
{
    T((T_CALLED("slk_attron(%p,%s)"), (void *) SP_PARM, _traceattr(attr)));

    if (SP_PARM != 0 && SP_PARM->_slk != 0) {
	TR(TRACE_ATTRS, ("... current %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
	AddAttr(SP_PARM->_slk->attr, attr);
	if ((attr & A_COLOR) != 0) {
	    SetPair(SP_PARM->_slk->attr, PAIR_NUMBER(attr));
	}
	TR(TRACE_ATTRS, ("new attribute is %s", _tracech_t(CHREF(SP_PARM->_slk->attr))));
	returnCode(OK);
    } else
	returnCode(ERR);
}
Exemple #14
0
/*
 * __set_color --
 *	Set terminal foreground and background colours.
 */
void
__set_color( /*ARGSUSED*/ WINDOW *win, attr_t attr)
{
	(void)win;
	short	pair;

	if ((curscr->wattr & __COLOR) == (attr & __COLOR))
		return;

	pair = PAIR_NUMBER((u_int32_t)attr);
	switch (_cursesi_screen->color_type) {
	/* Set ANSI forground and background colours */
	case COLOR_ANSI:
		if (_cursesi_screen->colour_pairs[pair].fore < 0 ||
		    _cursesi_screen->colour_pairs[pair].back < 0)
			__unset_color(curscr);
		if (_cursesi_screen->colour_pairs[pair].fore >= 0)
			tputs(tiparm(t_set_a_foreground(_cursesi_screen->term),
			    (int)_cursesi_screen->colour_pairs[pair].fore),
			    0, __cputchar);
		if (_cursesi_screen->colour_pairs[pair].back >= 0)
			tputs(tiparm(t_set_a_background(_cursesi_screen->term),
			    (int)_cursesi_screen->colour_pairs[pair].back),
			    0, __cputchar);
		break;
	case COLOR_HP:
		/* XXX: need to support HP style */
		break;
	case COLOR_TEK:
		/* XXX: need to support Tek style */
		break;
	case COLOR_OTHER:
		if (_cursesi_screen->colour_pairs[pair].fore < 0 ||
		    _cursesi_screen->colour_pairs[pair].back < 0)
			__unset_color(curscr);
		if (_cursesi_screen->colour_pairs[pair].fore >= 0)
			tputs(tiparm(t_set_foreground(_cursesi_screen->term),
			    (int)_cursesi_screen->colour_pairs[pair].fore),
			    0, __cputchar);
		if (_cursesi_screen->colour_pairs[pair].back >= 0)
			tputs(tiparm(t_set_background(_cursesi_screen->term),
			    (int)_cursesi_screen->colour_pairs[pair].back),
			    0, __cputchar);
		break;
	}
	curscr->wattr &= ~__COLOR;
	curscr->wattr |= attr & __COLOR;
}
Exemple #15
0
/*
 * drawGauge() draws a progress bar
 */
void
drawGauge(void *o, void* w)
{
    Obj *obj = OBJ(o);
    int percent;
    int fillwidth;
    int rc;
    WINDOW *win = Window(w);
    int x = WX(w),
	y = WY(w);
    char bfr[5];

    if (obj == 0 || obj->Class != O_GAUGE)
	return;

    percent = obj->content ? *((int*)(obj->content)) : 0;

    fillwidth = (obj->width * percent) / 100;

    rc = _nd_drawObjCommon(o, w);
    _nd_adjustXY(rc, o, &x, &y);
    
    /* clear the gauge area */
    wmove(win, y, x);
    setcolor(win, WINDOW_COLOR);
    waddnstr(win, rillyrillylongblankstring, obj->width);

    if (obj->width > 4) {
	/* draw the percentage in the middle of the progress bar,
	 * appropriately shaded */
	sprintf(bfr, "%d%%", percent);

	wmove(win, y, x + ((obj->width-strlen(bfr))/2) );
	waddstr(win, bfr);
    }

#if WITH_NCURSES
    /* highlight the progress bar as appropriate */
    mvwchgat(win, y, x, fillwidth, A_REVERSE, PAIR_NUMBER(WINDOW_COLOR), 0);
#else
    wstandout(win);
    for (rc = 0; rc < fillwidth; rc++)
	mvwaddch(win, y, x+rc, mvwinch(win, y, x+rc));
    wstandend(win);
#endif

} /* drawGauge */
Exemple #16
0
int main(void)
{
	int c,p;

	initscr();
	start_color();

	init_pair(1,COLOR_RED,COLOR_WHITE);

	c = COLOR_PAIR(1);
	p = PAIR_NUMBER(c);
	printw("COLOR_PAIR(1) = %d\n",c);
	printw("PAIR_NUMBER(%d) = %d\n",c,p);
	refresh();
	getch();

	endwin();
	return 0;
}
Exemple #17
0
int
mvwchgat(WINDOW *win , int y, int x, int count, attr_t attr, short color,
    const void *opts)
{
	__LINE *lp;
	__LDATA *lc;

	if (x < 0 || y < 0)
		return (ERR);
	if (x >= win->maxx || y >= win->maxy)
		return (ERR);

	attr = (attr & ~__COLOR) | COLOR_PAIR(color);

	if (count < 0 || count > win->maxx - x)
		count = win->maxx - x;

#ifdef DEBUG
	__CTRACE(__CTRACE_ATTR, "mvwchgat: x: %d y: %d count: %d attr: 0x%x "
		 "color pair %d\n", x, y, count, (attr & ~__COLOR),
		 PAIR_NUMBER(color));
#endif
	lp = win->alines[y];
	lc = &lp->line[x];

	if (x + win->ch_off < *lp->firstchp)
		*lp->firstchp = x + win->ch_off;
	if (x + win->ch_off + count > *lp->lastchp)
		*lp->lastchp = x + win->ch_off + count;

	while (count-- > 0) {
		lp->flags |= __ISDIRTY;
#ifdef HAVE_WCHAR
		lc->attr = (lc->attr & ~WA_ATTRIBUTES) | attr;
#else
		lc->attr = attr;
#endif
		++lc;
	}

	return OK;
}
Exemple #18
0
static void
encode_attr(char *target, attr_t source, attr_t prior)
{
    source &= ~A_CHARTEXT;
    prior &= ~A_CHARTEXT;

    *target = '\0';
    if (source != prior) {
	size_t n;
	bool first = TRUE;

	*target++ = MARKER;
	*target++ = L_CURL;

	for (n = 0; n < SIZEOF(scr_attrs); ++n) {
	    if ((source & scr_attrs[n].attr) != 0 ||
		((source & ALL_BUT_COLOR) == 0 &&
		 (scr_attrs[n].attr == A_NORMAL))) {
		if (first) {
		    first = FALSE;
		} else {
		    *target++ = '|';
		}
		strcpy(target, scr_attrs[n].name);
		target += strlen(target);
	    }
	}
	if ((source & A_COLOR) != (prior & A_COLOR)) {
	    if (!first)
		*target++ = '|';
	    sprintf(target, "C%d", PAIR_NUMBER((int) source));
	    target += strlen(target);
	}

	*target++ = R_CURL;
	*target = '\0';
    }
}
Exemple #19
0
int getcchar(const cchar_t *wcval, wchar_t *wch, attr_t *attrs,
             short *color_pair, void *opts)
{
    if (!wcval)
        return ERR;

    if (wch)
    {
        if (!attrs || !color_pair)
            return ERR;

        *wch = (wchar_t)(*wcval & A_CHARTEXT);
        *attrs = (*wcval & (A_ATTRIBUTES & ~A_COLOR));
        *color_pair = (short)( PAIR_NUMBER(*wcval & A_COLOR));

        if (*wch)
            *++wch = L'\0';

        return OK;
    }
    else
        return ((*wcval & A_CHARTEXT) != L'\0');
}
void
dump_window(WINDOW *w)
{
    wgetch(w);
    if (dumpfp != 0) {
	int y, x;
	int oldy, oldx;
	int maxy, maxx;
	int pass;
	char *cvec = 0;
	char *avec = 0;
	char *pvec = 0;
	int ccnt = 0;
	int acnt = 0;
	int pcnt = 0;
	int endy = -1;
	int endx = -1;

	fprintf(dumpfp, "Window %p\n", (void *) w);

	getyx(w, oldy, oldx);
	getmaxyx(w, maxy, maxx);
	fprintf(dumpfp, "size     (%dx%d)\n", maxy, maxx);
	getbegyx(w, y, x);
	fprintf(dumpfp, "begin    (%dx%d)\n", maxy, maxx);
	getyx(w, y, x);
	fprintf(dumpfp, "position (%d,%d)\n", y, x);

	if (maxy > 0 && maxx > 0) {
	    for (pass = 0; pass < 2; ++pass) {
		for (y = 0; y < maxy; ++y) {

		    if (cvec)
			memset(cvec, 0, (size_t) maxx + 1);
		    if (avec)
			memset(avec, 0, (size_t) maxx + 1);
		    if (pvec)
			memset(pvec, 0, (size_t) maxx + 1);

		    for (x = 0; x < maxx; ++x) {
			chtype data = mvwinch(w, y, x);
			chtype temp;
			char cc = (char) ((data & 0xff) ? (data & 0xff) : ' ');
			char aa;
			char pp;

			temp = ((data & A_ATTRIBUTES) & (~A_COLOR));
			if (temp) {
			    if (temp & A_ALTCHARSET) {
				aa = (temp & A_BOLD) ? 'A' : 'a';
			    } else if (temp & A_STANDOUT) {
				aa = (temp & A_BOLD) ? 'S' : 's';
			    } else if (temp & A_REVERSE) {
				aa = (temp & A_BOLD) ? 'R' : 'r';
			    } else if (temp & A_UNDERLINE) {
				aa = (temp & A_BOLD) ? 'U' : 'u';
			    } else {
				aa = (temp & A_BOLD) ? 'b' : '?';
			    }
			} else {
			    aa = ' ';
			}
			if (data & A_COLOR) {
			    if (PAIR_NUMBER((int) data) < 8) {
				pp = (char) ('0' + PAIR_NUMBER((int) data));
			    } else {
				pp = '*';
			    }
			} else {
			    pp = ' ';
			}

			if (pass) {
			    if (cvec)
				cvec[x] = cc;
			    if (avec)
				avec[x] = aa;
			    if (pvec)
				pvec[x] = pp;
			} else {
			    if (cc != ' ' || aa != ' ' || pp != ' ') {
				if (endx < x)
				    endx = x;
				if (endy < y)
				    endy = y;
			    }
			    ccnt += (cc != ' ');
			    acnt += (aa != ' ');
			    pcnt += (pp != ' ');
			}
		    }
		    if (pass) {
			fprintf(dumpfp, "%3d", y + 1);
			if (cvec)
			    fprintf(dumpfp, "\tc|%.*s|\n", maxx, cvec);
			if (avec)
			    fprintf(dumpfp, "\ta|%.*s|\n", maxx, avec);
			if (pvec)
			    fprintf(dumpfp, "\tp|%.*s|\n", maxx, pvec);
		    }
		}
		if (pass) {
		    free(cvec);
		    free(avec);
		    free(pvec);
		} else {
		    fprintf(dumpfp, "%d cells with characters\n", ccnt);
		    fprintf(dumpfp, "%d cells with video-attributes\n", acnt);
		    fprintf(dumpfp, "%d cells with color-attributes\n", pcnt);
		    if (endy < 0 || endx < 0)
			break;
		    /* reduce the dump a little, ignore really blank cells */
		    maxx = endx + 1;
		    maxy = endy + 1;
		    if (ccnt)
			cvec = malloc((size_t) maxx + 1);
		    if (acnt)
			avec = malloc((size_t) maxx + 1);
		    if (pcnt)
			pvec = malloc((size_t) maxx + 1);
		}
	    }
	}
	wmove(w, oldy, oldx);
    }
}
static void
draw_status(struct nh_player_info *pi, nh_bool threeline)
{
    char buf[ui_flags.mapwidth];
    int i, j, k;

    if (!statuswin)
        return;

    if (ui_flags.statusheight < 2) {
        werase(statuswin);
        return;
    }

    /* penultimate line */
    wmove(statuswin, (threeline ? 1 : 0), 0);
    draw_bar(15, pi->hp, pi->hpmax, TRUE);
    wprintw(statuswin, " Def:%d %s:%d", 10 - pi->ac,
            pi->monnum == pi->cur_monnum ? "Xp" : "HD", pi->level);
    if (threeline && pi->monnum == pi->cur_monnum) {
        /* keep this synced with newuexp in exper.c */
        long newuexp = 10L * (1L << pi->level);

        if (pi->level >= 10)
            newuexp = 10000L * (1L << (pi->level - 10));
        if (pi->level >= 20)
            newuexp = 10000000L * ((long)(pi->level - 19));
        wprintw(statuswin, "(%ld)", newuexp - pi->xp);
    }
    wprintw(statuswin, " %s", pi->level_desc);
    wclrtoeol(statuswin);

    /* last line */
    wmove(statuswin, (threeline ? 2 : 1), 0);
    draw_bar(15, pi->en, pi->enmax, FALSE);
    wprintw(statuswin, " %c%ld S:%ld T:%ld", pi->coinsym, pi->gold, pi->score,
            pi->moves);
    if (getcurx(statuswin) > 0)
        wclrtoeol(statuswin);

    /* status */
    int mainframe_color = CLR_GRAY;
    j = getmaxx(statuswin) + 1;
    for (i = 0; i < pi->nr_items; i++) {
        int color = CLR_WHITE, colorattr;

        j -= strlen(pi->statusitems[i]) + 1;
        for (k = 0; statuscolors[k].name; k++) {
            if (!strcmp(pi->statusitems[i], statuscolors[k].name)) {
                color = statuscolors[k].color;
                if (statuscolors[k].framecolor != -1)
                    mainframe_color = statuscolors[k].framecolor;
                break;
            }
        }
        colorattr = curses_color_attr(color, 0);
        wmove(statuswin, (threeline ? 2 : 1), j);
        wattron(statuswin, colorattr);
        wprintw(statuswin, "%s", pi->statusitems[i]);
        wattroff(statuswin, colorattr);
    }

    /* frame color */
    if (pi->hp * 7 <= pi->hpmax)
        mainframe_color = CLR_ORANGE;
    else if (pi->hp * 3 <= pi->hpmax)
        mainframe_color = CLR_RED;

    if (ui_flags.current_followmode != FM_PLAY)
        mainframe_color = CLR_BLACK;     /* a hint that we can't write */

    /* We change the frame color via palette manipulation, because it's awkward
       to correctly redraw otherwise. However, we don't want to do color
       mapping logic here. So we copy an existing palette entry. */
    uncursed_color fgcode, bgcode;
    pair_content(PAIR_NUMBER(curses_color_attr(mainframe_color, 0)),
                 &fgcode, &bgcode);
    init_pair(MAINFRAME_PAIR, fgcode, bgcode);

    /* name */
    if (threeline) {
        sprintf(buf, "%.12s the %s %s", pi->plname,
                (pi->align == A_CHAOTIC) ? "Chaotic" :
                (pi->align == A_NEUTRAL) ? "Neutral" :
                "Lawful", pi->rank);
        wmove(statuswin, 0, 0);
    } else {
        sprintf(buf, "%.12s, %s", pi->plname, pi->rank);
        wmove(statuswin, 0, getmaxx(statuswin) - strlen(buf));
    }
    wprintw(statuswin, "%s", buf);
    if (getcurx(statuswin) > 0)
        wclrtoeol(statuswin);

    /* abilities (in threeline mode) "In:18 Wi:18 Ch:18" = 17 chars */
    if (threeline) {
        wmove(statuswin, 0, getmaxx(statuswin) - (pi->st == 18 ? 20 : 17));
        wprintw(statuswin, "Dx:%-2d Co:%-2d St:%-2d", pi->dx, pi->co, pi->st);
        if (pi->st == 18 && pi->st_extra == 100)
            wprintw(statuswin, "/**");
        else if (pi->st == 18)
            wprintw(statuswin, "/%02d", pi->st_extra);
        wmove(statuswin, 1, getmaxx(statuswin) - (pi->st == 18 ? 20 : 17));
        wprintw(statuswin, "In:%-2d Wi:%-2d Ch:%-2d", pi->in, pi->wi, pi->ch);
    }
}
Exemple #22
0
 void _nc_toggle_attr_off (attr_t *S, attr_t at)
{
 { if (PAIR_NUMBER(at) > 0) { (*S) &= ~(at|((((1UL) << 8) - 1UL) << ((0) + 8))); } else { (*S) &= ~(at); } ;};
}
	return OK;
}

/**
 * Get attributes and colour pair information
 *
 * @v *win	window to obtain information from
 * @v *attrs	address in which to store attributes
 * @v *pair	address in which to store colour pair
 * @v *opts	undefined (for future implementation)
 * @ret rc	return status cude
 */
int wattr_get ( WINDOW *win, attr_t *attrs, short *pair, 
		void *opts __unused ) {
	*attrs = win->attrs & A_ATTRIBUTES;
	*pair = PAIR_NUMBER ( win->attrs );
	return OK;
}

/**
 * Turn off attributes in a window
 *
 * @v *win	subject window
 * @v attrs	attributes to toggle
 * @v *opts	undefined (for future implementation)
 * @ret rc	return status code
 */
int wattr_off ( WINDOW *win, attr_t attrs, 
		void *opts __unused ) {
	wattroff( win, attrs );
	return OK;
Exemple #24
0
 void _nc_toggle_attr_on (attr_t *S, attr_t at)
{
 { if (PAIR_NUMBER(at) > 0) { (*S) = ((*S) & ALL_BUT_COLOR) | (at); } else { (*S) |= (at); } ;};
}
Exemple #25
0
/*
 * start_color --
 *	Initialise colour support.
 */
int
start_color(void)
{
	int			 i;
	attr_t			 temp_nc;
	struct __winlist	*wlp;
	WINDOW			*win;
	int			 y, x;

	if (has_colors() == FALSE)
		return(ERR);

	/* Max colours and colour pairs */
	if (max_colors == -1)
		COLORS = 0;
	else {
		COLORS = max_colors > MAX_COLORS ? MAX_COLORS : max_colors;
		if (max_pairs == -1) {
			COLOR_PAIRS = 0;
			COLORS = 0;
		} else {
			COLOR_PAIRS = ((unsigned int)max_pairs > MAX_PAIRS - 1 ?
			    MAX_PAIRS - 1 : max_pairs);
			 /* Use the last colour pair for curses default. */
			__default_color = COLOR_PAIR(MAX_PAIRS - 1);
		}
	}
	if (!COLORS)
		return (ERR);

	_cursesi_screen->COLORS = COLORS;
	_cursesi_screen->COLOR_PAIRS = COLOR_PAIRS;

	/* Reset terminal colour and colour pairs. */
	if (orig_colors != NULL)
		tputs(orig_colors, 0, __cputchar);
	if (orig_pair != NULL) {
		tputs(orig_pair, 0, __cputchar);
		curscr->wattr &= _cursesi_screen->mask_op;
	}

	/* Type of colour manipulation - ANSI/TEK/HP/other */
	if (set_a_foreground != NULL && set_a_background != NULL)
		_cursesi_screen->color_type = COLOR_ANSI;
	else if (initialize_pair != NULL)
		_cursesi_screen->color_type = COLOR_HP;
	else if (initialize_color != NULL)
		_cursesi_screen->color_type = COLOR_TEK;
	else if (set_foreground != NULL && set_background != NULL)
		_cursesi_screen->color_type = COLOR_OTHER;
	else
		return(ERR);		/* Unsupported colour method */

	/*
	 * Attributes that cannot be used with color.
	 * Store these in an attr_t for wattrset()/wattron().
	 */
	_cursesi_screen->nca = __NORMAL;
	if (no_color_video != -1) {
		temp_nc = (attr_t) t_no_color_video(_cursesi_screen->term);
		if (temp_nc & 0x0001)
			_cursesi_screen->nca |= __STANDOUT;
		if (temp_nc & 0x0002)
			_cursesi_screen->nca |= __UNDERSCORE;
		if (temp_nc & 0x0004)
			_cursesi_screen->nca |= __REVERSE;
		if (temp_nc & 0x0008)
			_cursesi_screen->nca |= __BLINK;
		if (temp_nc & 0x0010)
			_cursesi_screen->nca |= __DIM;
		if (temp_nc & 0x0020)
			_cursesi_screen->nca |= __BOLD;
		if (temp_nc & 0x0040)
			_cursesi_screen->nca |= __BLANK;
		if (temp_nc & 0x0080)
			_cursesi_screen->nca |= __PROTECT;
		if (temp_nc & 0x0100)
			_cursesi_screen->nca |= __ALTCHARSET;
	}

	/* Set up initial 8 colours */
	if (COLORS >= COLOR_BLACK)
		(void) init_color(COLOR_BLACK, 0, 0, 0);
	if (COLORS >= COLOR_RED)
		(void) init_color(COLOR_RED, 1000, 0, 0);
	if (COLORS >= COLOR_GREEN)
		(void) init_color(COLOR_GREEN, 0, 1000, 0);
	if (COLORS >= COLOR_YELLOW)
		(void) init_color(COLOR_YELLOW, 1000, 1000, 0);
	if (COLORS >= COLOR_BLUE)
		(void) init_color(COLOR_BLUE, 0, 0, 1000);
	if (COLORS >= COLOR_MAGENTA)
		(void) init_color(COLOR_MAGENTA, 1000, 0, 1000);
	if (COLORS >= COLOR_CYAN)
		(void) init_color(COLOR_CYAN, 0, 1000, 1000);
	if (COLORS >= COLOR_WHITE)
		(void) init_color(COLOR_WHITE, 1000, 1000, 1000);

	/* Initialise other colours */
	for (i = 8; i < COLORS; i++) {
		_cursesi_screen->colours[i].red = 0;
		_cursesi_screen->colours[i].green = 0;
		_cursesi_screen->colours[i].blue = 0;
		_cursesi_screen->colours[i].flags = 0;
	}

	/* Initialise pair 0 to default colours. */
	_cursesi_screen->colour_pairs[0].fore = -1;
	_cursesi_screen->colour_pairs[0].back = -1;
	_cursesi_screen->colour_pairs[0].flags = 0;

	/* Initialise user colour pairs to default (white on black) */
	for (i = 0; i < COLOR_PAIRS; i++) {
		_cursesi_screen->colour_pairs[i].fore = COLOR_WHITE;
		_cursesi_screen->colour_pairs[i].back = COLOR_BLACK;
		_cursesi_screen->colour_pairs[i].flags = 0;
	}

	/* Initialise default colour pair. */
	_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].fore =
	    __default_pair.fore;
	_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].back =
	    __default_pair.back;
	_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].flags =
	    __default_pair.flags;

	__using_color = 1;

	/* Set all positions on all windows to curses default colours. */
	for (wlp = _cursesi_screen->winlistp; wlp != NULL; wlp = wlp->nextp) {
		win = wlp->winp;
		if (wlp->winp != __virtscr && wlp->winp != curscr) {
			/* Set color attribute on other windows */
			win->battr |= __default_color;
			for (y = 0; y < win->maxy; y++) {
				for (x = 0; x < win->maxx; x++) {
					win->alines[y]->line[x].attr &= ~__COLOR;
					win->alines[y]->line[x].attr |= __default_color;
				}
			}
			__touchwin(win);
		}
	}

	return(OK);
}
EIF_INTEGER c_ecurses_pair_number (EIF_INTEGER n)
{
    return  PAIR_NUMBER ((int) n);
};
Exemple #27
0
char *_traceattr2(int bufnum, attr_t newmode)
{
char	*buf = _nc_trace_buf(bufnum, BUFSIZ);
char	*tmp = buf;
static const	struct {unsigned int val; const char *name;}
names[] =
    {
	{ A_STANDOUT,		"A_STANDOUT" },
	{ A_UNDERLINE,		"A_UNDERLINE" },
	{ A_REVERSE,		"A_REVERSE" },
	{ A_BLINK,		"A_BLINK" },
	{ A_DIM,		"A_DIM" },
	{ A_BOLD,		"A_BOLD" },
	{ A_ALTCHARSET,		"A_ALTCHARSET" },
	{ A_INVIS,		"A_INVIS" },
	{ A_PROTECT,		"A_PROTECT" },
	{ A_CHARTEXT,		"A_CHARTEXT" },
	{ A_NORMAL,		"A_NORMAL" },
	{ A_COLOR,		"A_COLOR" },
    },
colors[] =
    {
	{ COLOR_BLACK,		"COLOR_BLACK" },
	{ COLOR_RED,		"COLOR_RED" },
	{ COLOR_GREEN,		"COLOR_GREEN" },
	{ COLOR_YELLOW,		"COLOR_YELLOW" },
	{ COLOR_BLUE,		"COLOR_BLUE" },
	{ COLOR_MAGENTA,	"COLOR_MAGENTA" },
	{ COLOR_CYAN,		"COLOR_CYAN" },
	{ COLOR_WHITE,		"COLOR_WHITE" },
    };
size_t n;
unsigned save_nc_tracing = _nc_tracing;
	_nc_tracing = 0;

	strcpy(tmp++, "{");

	for (n = 0; n < SIZEOF(names); n++) {
		if ((newmode & names[n].val) != 0) {
			if (buf[1] != '\0')
				strcat(tmp, "|");
			strcat(tmp, names[n].name);
			tmp += strlen(tmp);

			if (names[n].val == A_COLOR)
			{
				short pairnum = PAIR_NUMBER(newmode);
				short fg, bg;
	
				if (pair_content(pairnum, &fg, &bg) == OK)
					(void) sprintf(tmp,
						"{%d = {%s, %s}}",
						pairnum,
						COLOR_OF(fg),
						COLOR_OF(bg)
						);
				else
					(void) sprintf(tmp, "{%d}", pairnum);
			}
		}
	}
	if (AttrOf(newmode) == A_NORMAL) {
		if (buf[1] != '\0')
			strcat(tmp, "|");
		strcat(tmp, "A_NORMAL");
	}

	_nc_tracing = save_nc_tracing;
	return (strcat(buf,"}"));
}
Exemple #28
0
void
vidupdate(chtype newmode, chtype oldmode, int (*outc)(char))
{
	bool color_terminal = (cur_term->_pairs_tbl) ? TRUE : FALSE;
	chtype oldvideo = (oldmode & A_ATTRIBUTES) & ~A_COLOR;
	chtype newvideo = (newmode & A_ATTRIBUTES) & ~A_COLOR;
	int  _change_video(chtype, chtype, int (*)(char));
	void _change_color(short, int (*)(char));

	/* if colors are used, extract the color related information from */
	/* the old and new modes and then erase color-pairs fields in	*/
	/* both arguments.						*/

	if (color_terminal) {
		/* LINTED */
		short oldcolor = (short) PAIR_NUMBER(oldmode & A_COLOR);
		/* LINTED */
		short newcolor = (short) PAIR_NUMBER(newmode & A_COLOR);
		chtype turn_off = A_COLOR;

		/* erase information about video attributes that could not */
		/* have been used with colors				   */

		if (oldcolor == 0)
			oldvideo &= ~turn_off;

		if (no_color_video != -1)
			turn_off |= (((chtype) no_color_video) << 16);

		if (oldcolor != 0)
			oldvideo &= ~turn_off;


		/* if the new mode contains color information, then first  */
		/* deal with video attributes, and then with colors.  This */
		/* way color information will overwrite video information. */

		if (newcolor != 0) {
			/* erase information about video attributes that */
			/* should not be used with colors		 */

			newvideo &= ~turn_off;

			/* if the new and the old video modes became 	*/
			/* the same don't bother with them		*/

			if (newvideo != oldvideo) {
				if ((_change_video(newvideo, oldvideo,
				    outc)) == -1) {
					_Color_pair *cur_pair =
					    &cur_term->_cur_pair;
					oldcolor = -1;
					cur_pair->background =
					    cur_pair->foreground = -1;
				}
			}
			if (newcolor != oldcolor)
				_change_color(newcolor, outc);
		}

		/* new mode doesn't contain any color information.  Deal */
		/* with colors first (possibly turning of the colors that */
		/* were contained in the oldmode, and then deal with video. */
		/* This way video attributes will overwrite colors.	*/

		else {
			if (newcolor != oldcolor)
				_change_color(newcolor, outc);
			if (newvideo != oldvideo)
				(void) _change_video(newvideo, oldvideo, outc);
		}
	} else
		(void) _change_video(newvideo, oldvideo, outc);
}
Exemple #29
0
_traceattr2(int bufnum, attr_t newmode)
{
    char *buf = _nc_trace_buf(bufnum, BUFSIZ);
    char temp[80];
    static const struct {
	unsigned int val;
	const char *name;
    } names[] =
    {
	/* *INDENT-OFF* */
	{ A_STANDOUT,		"A_STANDOUT" },
	{ A_UNDERLINE,		"A_UNDERLINE" },
	{ A_REVERSE,		"A_REVERSE" },
	{ A_BLINK,		"A_BLINK" },
	{ A_DIM,		"A_DIM" },
	{ A_BOLD,		"A_BOLD" },
	{ A_ALTCHARSET,		"A_ALTCHARSET" },
	{ A_INVIS,		"A_INVIS" },
	{ A_PROTECT,		"A_PROTECT" },
	{ A_CHARTEXT,		"A_CHARTEXT" },
	{ A_NORMAL,		"A_NORMAL" },
	{ A_COLOR,		"A_COLOR" },
	/* *INDENT-ON* */

    }
#ifndef USE_TERMLIB
    ,
	colors[] =
    {
	/* *INDENT-OFF* */
	{ COLOR_BLACK,		"COLOR_BLACK" },
	{ COLOR_RED,		"COLOR_RED" },
	{ COLOR_GREEN,		"COLOR_GREEN" },
	{ COLOR_YELLOW,		"COLOR_YELLOW" },
	{ COLOR_BLUE,		"COLOR_BLUE" },
	{ COLOR_MAGENTA,	"COLOR_MAGENTA" },
	{ COLOR_CYAN,		"COLOR_CYAN" },
	{ COLOR_WHITE,		"COLOR_WHITE" },
	/* *INDENT-ON* */

    }
#endif /* !USE_TERMLIB */
    ;
    size_t n;
    unsigned save_nc_tracing = _nc_tracing;
    _nc_tracing = 0;

    strcpy(buf, l_brace);

    for (n = 0; n < SIZEOF(names); n++) {
	if ((newmode & names[n].val) != 0) {
	    if (buf[1] != '\0')
		buf = _nc_trace_bufcat(bufnum, "|");
	    buf = _nc_trace_bufcat(bufnum, names[n].name);

	    if (names[n].val == A_COLOR) {
		short pairnum = PAIR_NUMBER(newmode);
#ifdef USE_TERMLIB
		/* pair_content lives in libncurses */
		(void) sprintf(temp, "{%d}", pairnum);
#else
		short fg, bg;

		if (pair_content(pairnum, &fg, &bg) == OK) {
		    (void) sprintf(temp,
				   "{%d = {%s, %s}}",
				   pairnum,
				   COLOR_OF(fg),
				   COLOR_OF(bg));
		} else {
		    (void) sprintf(temp, "{%d}", pairnum);
		}
#endif
		buf = _nc_trace_bufcat(bufnum, temp);
	    }
	}
    }
    if (ChAttrOf(newmode) == A_NORMAL) {
	if (buf[1] != '\0')
	    (void) _nc_trace_bufcat(bufnum, "|");
	(void) _nc_trace_bufcat(bufnum, "A_NORMAL");
    }

    _nc_tracing = save_nc_tracing;
    return (_nc_trace_bufcat(bufnum, r_brace));
}
Exemple #30
0
		// if (_nc_waddch_nosync(win, ch) == ERR) {
		// 	code = ERR;
		// 	break;
		// }
	}

	if (win->_line[win->_cury].lastchar == _NOCHANGE ||
			win->_line[win->_cury].lastchar < win->_curx)
		win->_line[win->_cury].lastchar = win->_curx;

	return code;
}
int wattr_on(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
{
	if (at & A_COLOR)
		win->_color = PAIR_NUMBER(at);
	// toggle_attr_on(WINDOW_ATTRS(win), at);
	return OK;
}
int wattr_off(WINDOW *win, attr_t at, void *opts GCC_UNUSED)
{
	if (at & A_COLOR)
		win->_color = 0;
	// toggle_attr_off(WINDOW_ATTRS(win), at);
	return 0;
}
// int wbkgd (WINDOW *, chtype) {}
void wbkgdset(WINDOW *win, chtype ch) { /* TODO */ }

int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs,
		chtype tl, chtype tr, chtype bl, chtype br)