void HorizontalLine::Draw() { if (!area->w || Width() == 0) return; //TODO and throw an exception/log a warning? if (Width() <= 1) { mvwadd_wch(area->w, 0, 0, H()); } else { mvwadd_wch(area->w, 0, 0, HBegin()); for (int i = 1; i < Width()-1; i++) { mvwadd_wch(area->w, 0, i, H()); } mvwadd_wch(area->w, 0, Width()-1, HEnd()); } }
/* * mvadd_wch -- * Add the wide character to stdscr at the given location. */ int mvadd_wch(int y, int x, const cchar_t *wch) { #ifndef HAVE_WCHAR return ERR; #else return mvwadd_wch(stdscr, y, x, wch); #endif /* HAVE_WCHAR */ }
static int MvWAddCh(WINDOW *win, int y, int x, chtype ch) { int code; cchar_t tmp_cchar; if (ConvertCh(ch, &tmp_cchar)) { code = mvwadd_wch(win, y, x, &tmp_cchar); } else { code = mvwaddch(win, y, x, ch); } return code; }
WINDOW* window_create_shadow(WINDOW *window,WINDOW *window_below) { /* WINDOW *window_below; */ extern WINDOW *SCREEN_WINDOW; WINDOW *shadow_window; gint width,height; gint beg_x,beg_y; gint x,y; #ifdef _VIPER_WIDE cchar_t wcval; wchar_t wch; attr_t attrs; short color_pair; #else chtype char_attr; #endif if(window==NULL) return window; getmaxyx(window,height,width); getbegyx(window,beg_y,beg_x); if(window_below==NULL) window_below=SCREEN_WINDOW; shadow_window=newwin(height,width,beg_y+1,beg_x+1); for(y=0;y<height;y++) { for(x=0;x<width;x++) { #ifdef _VIPER_WIDE mvwin_wch(window_below,beg_y+y+1,beg_x+x+1,&wcval); getcchar(&wcval,&wch,&attrs,&color_pair,NULL); setcchar(&wcval,&wch,attrs, viper_color_pair(COLOR_WHITE,COLOR_BLACK),NULL); mvwadd_wch(shadow_window,y,x,&wcval); #else char_attr=mvwinch(window_below,beg_y+y+1,beg_x+x+1); mvwaddch(shadow_window,y,x,char_attr & A_CHARTEXT); if((char_attr & A_ALTCHARSET)==A_ALTCHARSET) mvwchgat(shadow_window,y,x,1,A_NORMAL | A_ALTCHARSET, viper_color_pair(COLOR_WHITE,COLOR_BLACK),NULL); else mvwchgat(shadow_window,y,x,1,A_NORMAL, viper_color_pair(COLOR_WHITE,COLOR_BLACK),NULL); #endif } } return shadow_window; }
/* Unconditionally write a single wide character to a window at the given coordinates without a refresh. Currently only used for the map. */ static void write_wchar(WINDOW *win, int x, int y, nethack_char nch) { static cchar_t wide = {0}; static boolean init = false; if (!init) { wide.attr = 0; int i; for (i = 0; i < CCHARW_MAX; i++) wide.chars[i] = 0; init = true; } curses_toggle_color_attr(win, nch.color, nch.attr, ON); wide.chars[0] = nch.ch; mvwadd_wch(win, y, x, &wide); curses_toggle_color_attr(win, nch.color, nch.attr, OFF); }
/* * __wgetn_wstr -- * The actual implementation. * Note that we include a trailing L'\0' for safety, so str will contain * at most n - 1 other characters. */ int __wgetn_wstr(WINDOW *win, wchar_t *wstr, int n) { wchar_t *ostr, ec, kc, sc[ 2 ]; int oldx, remain; wint_t wc; cchar_t cc; ostr = wstr; if ( erasewchar( &ec ) == ERR ) return ERR; if ( killwchar( &kc ) == ERR ) return ERR; sc[ 0 ] = ( wchar_t )btowc( ' ' ); sc[ 1 ] = L'\0'; setcchar( &cc, sc, win->wattr, 0, NULL ); oldx = win->curx; remain = n - 1; while (wget_wch(win, &wc) != ERR && wc != L'\n' && wc != L'\r') { #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "__wgetn_wstr: win %p, char 0x%x, remain %d\n", win, wc, remain); #endif *wstr = wc; touchline(win, win->cury, 1); if (wc == ec || wc == KEY_BACKSPACE || wc == KEY_LEFT) { *wstr = L'\0'; if (wstr != ostr) { if ((wchar_t)wc == ec) { mvwadd_wch(win, win->cury, win->curx, &cc); wmove(win, win->cury, win->curx - 1); } if (wc == KEY_BACKSPACE || wc == KEY_LEFT) { /* getch() displays the key sequence */ mvwadd_wch(win, win->cury, win->curx - 1, &cc); mvwadd_wch(win, win->cury, win->curx - 2, &cc); wmove(win, win->cury, win->curx - 1); } wstr--; if (n != -1) { /* We're counting chars */ remain++; } } else { /* str == ostr */ if (wc == KEY_BACKSPACE || wc == KEY_LEFT) /* getch() displays the other keys */ mvwadd_wch(win, win->cury, win->curx - 1, &cc); wmove(win, win->cury, oldx); } } else if (wc == kc) { *wstr = L'\0'; if (wstr != ostr) { /* getch() displays the kill character */ mvwadd_wch(win, win->cury, win->curx - 1, &cc); /* Clear the characters from screen and str */ while (wstr != ostr) { mvwadd_wch(win, win->cury, win->curx - 1, &cc); wmove(win, win->cury, win->curx - 1); wstr--; if (n != -1) /* We're counting chars */ remain++; } mvwadd_wch(win, win->cury, win->curx - 1, &cc); wmove(win, win->cury, win->curx - 1); } else /* getch() displays the kill character */ mvwadd_wch( win, win->cury, oldx, &cc ); wmove(win, win->cury, oldx); } else if (wc >= KEY_MIN && wc <= KEY_MAX) { /* get_wch() displays these characters */ mvwadd_wch( win, win->cury, win->curx - 1, &cc ); wmove(win, win->cury, win->curx - 1); } else { if (remain) { wstr++; remain--; } else { mvwadd_wch(win, win->cury, win->curx - 1, &cc); wmove(win, win->cury, win->curx - 1); } } } if (wc == ERR) { *wstr = L'\0'; return ERR; } *wstr = L'\0'; return OK; }
/* Month draw */ void month_draw(void) { const char *name = month_to_string(SEL.month); const int start = start_of_month(SEL.year, SEL.month); const int days = days_in_month(SEL.year, SEL.month); const int weeks = weeks_in_month(SEL.year, SEL.month); const int hdr = COMPACT ? 3 : 4; const float midpt = (float)COLS/2.0 - (strlen(name) + 1 + 4)/2.0; const float hstep = (float)(COLS-1)/7.0; const float vstep = (float)(LINES-2-hdr+COMPACT)/weeks; /* Load cal data */ cal_load(SEL.year, SEL.month, 0, days); /* Print Header */ if (COMPACT) wattron(win, A_REVERSE | A_BOLD); if (COMPACT) mvwhline(win, 0, 0, ' ' | A_REVERSE | A_BOLD, COLS); if (COMPACT) mvwhline(win, 1, 0, ' ' | A_REVERSE | A_BOLD, COLS); mvwprintw(win, 0, midpt, "%s %d", name, SEL.year); for (int d = 0; d < 7; d++) { const char *str = hstep >= 10 ? day_to_string(d+SUN) : day_to_str(d+SUN); mvwprintw(win, 1, ROUND(1+d*hstep), "%s", str); } if (COMPACT) wattroff(win, A_REVERSE | A_BOLD); if (!COMPACT) mvwhline(win, 2, 0, ACS_HLINE, COLS); /* Print days */ for (int d = 0; d < days; d++) { int row = (start + d) / 7; int col = (start + d) % 7; if (d == SEL.day) wattron(win, A_BOLD); mvwprintw(win, ROUND(hdr+row*vstep), ROUND(1+col*hstep), "%d", d+1); if (d == SEL.day) wattroff(win, A_BOLD); } /* Print events */ event_t *event = EVENTS; for (int d = 0; d < days; d++) { int y = ROUND(hdr+(((start + d) / 7) )*vstep); int e = ROUND(hdr+(((start + d) / 7)+1)*vstep)-2; int x = ROUND(1 +(((start + d) % 7) )*hstep)+3; int w = ROUND(1 +(((start + d) % 7)+1)*hstep)-x-1; while (event && before(&event->start, SEL.year, SEL.month, d, 24, 0)) { if (!before(&event->start, SEL.year, SEL.month, d, 0, 0)){ if (y == e) mvwhline(win, y, x-3, ACS_DARROW, 2); if (y <= e) event_line(win, event, y, x, w, 0); y++; } event = event->next; } } /* Print lines */ for (int w = 1; w < weeks; w++) mvwhline(win, ROUND(hdr-1+w*vstep), 1, ACS_HLINE, COLS-2); for (int d = 1; d < 7; d++) { int top = d >= start ? 0 : 1; int bot = d <= (start+days-1)%7+1 ? weeks : weeks-1; mvwvline(win, ROUND(hdr+top*vstep), ROUND(d*hstep), ACS_VLINE, (bot-top)*vstep); for (int w = 1; w < weeks; w++) { int chr = w == top ? ACS_TTEE : w == bot ? ACS_BTEE : ACS_PLUS; mvwaddch(win, ROUND(hdr-1+w*vstep), ROUND(d*hstep), chr); } } /* Draw today */ int col = day_of_week(SEL.year, SEL.month, SEL.day); int row = (start+SEL.day) / 7; int l = ROUND((col+0)*hstep); int r = ROUND((col+1)*hstep); int t = ROUND((row+0)*vstep+hdr-1); int b = ROUND((row+1)*vstep+hdr-1); mvwvline_set(win, t, l, WACS_T_VLINE, b-t); mvwvline_set(win, t, r, WACS_T_VLINE, b-t); mvwhline_set(win, t, l, WACS_T_HLINE, r-l); mvwhline_set(win, b, l, WACS_T_HLINE, r-l); mvwadd_wch(win, t, l, WACS_T_ULCORNER); mvwadd_wch(win, t, r, WACS_T_URCORNER); mvwadd_wch(win, b, l, WACS_T_LLCORNER); mvwadd_wch(win, b, r, WACS_T_LRCORNER); }