/* approximate update cost */ static int update_cost(NCURSES_CH_T * from, NCURSES_CH_T * to) { int cost = 0; int i; for (i = TEXTWIDTH; i > 0; i--) if (!(CharEq(*from++, *to++))) cost++; return cost; }
static int update_cost_from_blank(NCURSES_CH_T * to) { int cost = 0; int i; NCURSES_CH_T blank = blankchar; if (back_color_erase) SetPair(blank, GetPair(stdscr->_nc_bkgd)); for (i = TEXTWIDTH; i > 0; i--) if (!(CharEq(blank, *to++))) cost++; return cost; }
pnoutrefresh(WINDOW *win, int pminrow, int pmincol, int sminrow, int smincol, int smaxrow, int smaxcol) { NCURSES_SIZE_T i, j; NCURSES_SIZE_T m, n; NCURSES_SIZE_T pmaxrow; NCURSES_SIZE_T pmaxcol; SCREEN *sp; #if USE_SCROLL_HINTS const int my_len = 2; /* parameterize the threshold for hardscroll */ NCURSES_SIZE_T displaced; bool wide; #endif T((T_CALLED("pnoutrefresh(%p, %d, %d, %d, %d, %d, %d)"), (void *) win, pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)); if (win == 0) returnCode(ERR); if (!(win->_flags & _ISPAD)) returnCode(ERR); sp = _nc_screen_of(win); /* negative values are interpreted as zero */ if (pminrow < 0) pminrow = 0; if (pmincol < 0) pmincol = 0; if (sminrow < 0) sminrow = 0; if (smincol < 0) smincol = 0; pmaxrow = pminrow + smaxrow - sminrow; pmaxcol = pmincol + smaxcol - smincol; T((" pminrow + smaxrow - sminrow %ld, win->_maxy %ld", (long) pmaxrow, (long) win->_maxy)); T((" pmincol + smaxcol - smincol %ld, win->_maxx %ld", (long) pmaxcol, (long) win->_maxx)); /* * Trim the caller's screen size back to the actual limits. */ if (pmaxrow > win->_maxy) { smaxrow -= (pmaxrow - win->_maxy); pmaxrow = pminrow + smaxrow - sminrow; } if (pmaxcol > win->_maxx) { smaxcol -= (pmaxcol - win->_maxx); pmaxcol = pmincol + smaxcol - smincol; } if (smaxrow >= screen_lines(sp) || smaxcol >= screen_columns(sp) || sminrow > smaxrow || smincol > smaxcol) returnCode(ERR); T(("pad being refreshed")); #if USE_SCROLL_HINTS if (win->_pad._pad_y >= 0) { displaced = pminrow - win->_pad._pad_y - (sminrow - win->_pad._pad_top); T(("pad being shifted by %d line(s)", displaced)); } else displaced = 0; #endif /* * For pure efficiency, we'd want to transfer scrolling information * from the pad to newscr whenever the window is wide enough that * its update will dominate the cost of the update for the horizontal * band of newscr that it occupies. Unfortunately, this threshold * tends to be complex to estimate, and in any case scrolling the * whole band and rewriting the parts outside win's image would look * really ugly. So. What we do is consider the pad "wide" if it * either (a) occupies the whole width of newscr, or (b) occupies * all but at most one column on either vertical edge of the screen * (this caters to fussy people who put boxes around full-screen * windows). Note that changing this formula will not break any code, * merely change the costs of various update cases. */ #if USE_SCROLL_HINTS wide = (smincol < my_len && smaxcol > (NewScreen(sp)->_maxx - my_len)); #endif for (i = pminrow, m = sminrow + win->_yoffset; i <= pmaxrow && m <= NewScreen(sp)->_maxy; i++, m++) { register struct ldat *nline = &NewScreen(sp)->_line[m]; register struct ldat *oline = &win->_line[i]; for (j = pmincol, n = smincol; j <= pmaxcol; j++, n++) { NCURSES_CH_T ch = oline->text[j]; #if USE_WIDEC_SUPPORT /* * Special case for leftmost character of the displayed area. * Only half of a double-width character may be visible. */ if (j == pmincol && j > 0 && isWidecExt(ch)) { SetChar(ch, L(' '), AttrOf(oline->text[j - 1])); } #endif if (!CharEq(ch, nline->text[n])) { nline->text[n] = ch; CHANGED_CELL(nline, n); } } #if USE_SCROLL_HINTS if (wide) { int nind = m + displaced; if (oline->oldindex < 0 || nind < sminrow || nind > smaxrow) { nind = _NEWINDEX; } else if (displaced) { register struct ldat *pline = &CurScreen(sp)->_line[nind]; for (j = 0; j <= my_len; j++) { int k = NewScreen(sp)->_maxx - j; if (pline->text[j] != nline->text[j] || pline->text[k] != nline->text[k]) { nind = _NEWINDEX; break; } } } nline->oldindex = nind; } #endif /* USE_SCROLL_HINTS */ oline->firstchar = oline->lastchar = _NOCHANGE; if_USE_SCROLL_HINTS(oline->oldindex = i); } /* * Clean up debris from scrolling or resizing the pad, so we do not * accidentally pick up the index value during the next call to this * procedure. The only rows that should have an index value are those * that are displayed during this cycle. */ #if USE_SCROLL_HINTS for (i = pminrow - 1; (i >= 0) && (win->_line[i].oldindex >= 0); i--) win->_line[i].oldindex = _NEWINDEX; for (i = pmaxrow + 1; (i <= win->_maxy) && (win->_line[i].oldindex >= 0); i++) win->_line[i].oldindex = _NEWINDEX; #endif win->_begx = smincol; win->_begy = sminrow; if (win->_clear) { win->_clear = FALSE; NewScreen(sp)->_clear = TRUE; } /* * Use the pad's current position, if it will be visible. * If not, don't do anything; it's not an error. */ if (win->_leaveok == FALSE && win->_cury >= pminrow && win->_curx >= pmincol && win->_cury <= pmaxrow && win->_curx <= pmaxcol) { NewScreen(sp)->_cury = win->_cury - pminrow + win->_begy + win->_yoffset; NewScreen(sp)->_curx = win->_curx - pmincol + win->_begx; } NewScreen(sp)->_leaveok = win->_leaveok; win->_flags &= ~_HASMOVED; /* * Update our cache of the line-numbers that we displayed from the pad. * We will use this on subsequent calls to this function to derive * values to stuff into 'oldindex[]' -- for scrolling optimization. */ win->_pad._pad_y = pminrow; win->_pad._pad_x = pmincol; win->_pad._pad_top = sminrow; win->_pad._pad_left = smincol; win->_pad._pad_bottom = smaxrow; win->_pad._pad_right = smaxcol; returnCode(OK); }
copywin(const WINDOW *src, WINDOW *dst, int sminrow, int smincol, int dminrow, int dmincol, int dmaxrow, int dmaxcol, int over) { int rc = ERR; int sx, sy, dx, dy; bool touched; attr_t bk; attr_t mask; T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"), src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over)); if (src && dst) { _nc_lock_global(curses); bk = AttrOf(dst->_nc_bkgd); mask = ~(attr_t) ((bk & A_COLOR) ? A_COLOR : 0); /* make sure rectangle exists in source */ if ((sminrow + dmaxrow - dminrow) <= (src->_maxy + 1) && (smincol + dmaxcol - dmincol) <= (src->_maxx + 1)) { T(("rectangle exists in source")); /* make sure rectangle fits in destination */ if (dmaxrow <= dst->_maxy && dmaxcol <= dst->_maxx) { T(("rectangle fits in destination")); for (dy = dminrow, sy = sminrow; dy <= dmaxrow; sy++, dy++) { touched = FALSE; for (dx = dmincol, sx = smincol; dx <= dmaxcol; sx++, dx++) { if (over) { if ((CharOf(src->_line[sy].text[sx]) != L(' ')) && (!CharEq(dst->_line[dy].text[dx], src->_line[sy].text[sx]))) { dst->_line[dy].text[dx] = src->_line[sy].text[sx]; SetAttr(dst->_line[dy].text[dx], ((AttrOf(src->_line[sy].text[sx]) & mask) | bk)); touched = TRUE; } } else { if (!CharEq(dst->_line[dy].text[dx], src->_line[sy].text[sx])) { dst->_line[dy].text[dx] = src->_line[sy].text[sx]; touched = TRUE; } } } if (touched) { touchline(dst, dminrow, (dmaxrow - dminrow + 1)); } } T(("finished copywin")); rc = OK; } } _nc_unlock_global(curses); } returnCode(rc); }