1 /* Public Domain Curses */
5 RCSID("$Id: refresh.c,v 1.56 2008/07/13 16:08:18 wmcbrine Exp $")
7 /*man-start**************************************************************
13 int wrefresh(WINDOW *win);
14 int wnoutrefresh(WINDOW *win);
16 int redrawwin(WINDOW *win);
17 int wredrawln(WINDOW *win, int beg_line, int num_lines);
20 wrefresh() copies the named window to the physical terminal
21 screen, taking into account what is already there in order to
22 optimize cursor movement. refresh() does the same, using stdscr.
23 These routines must be called to get any output on the terminal,
24 as other routines only manipulate data structures. Unless
25 leaveok() has been enabled, the physical cursor of the terminal
26 is left at the location of the window's cursor.
28 wnoutrefresh() and doupdate() allow multiple updates with more
29 efficiency than wrefresh() alone. wrefresh() works by first
30 calling wnoutrefresh(), which copies the named window to the
31 virtual screen. It then calls doupdate(), which compares the
32 virtual screen to the physical screen and does the actual
33 update. A series of calls to wrefresh() will result in
34 alternating calls to wnoutrefresh() and doupdate(), causing
35 several bursts of output to the screen. By first calling
36 wnoutrefresh() for each window, it is then possible to call
39 In PDCurses, redrawwin() is equivalent to touchwin(), and
40 wredrawln() is the same as touchline(). In some other curses
41 implementations, there's a subtle distinction, but it has no
45 All functions return OK on success and ERR on error.
47 Portability X/Open BSD SYS V
55 **man-end****************************************************************/
59 int wnoutrefresh(WINDOW
*win
)
61 int begy
, begx
; /* window's place on screen */
64 PDC_LOG(("wnoutrefresh() - called: win=%p\n", win
));
66 if ( !win
|| (win
->_flags
& (_PAD
|_SUBPAD
)) )
72 for (i
= 0, j
= begy
; i
< win
->_maxy
; i
++, j
++)
74 if (win
->_firstch
[i
] != _NO_CHANGE
)
76 chtype
*src
= win
->_y
[i
];
77 chtype
*dest
= curscr
->_y
[j
] + begx
;
79 int first
= win
->_firstch
[i
]; /* first changed */
80 int last
= win
->_lastch
[i
]; /* last changed */
82 /* ignore areas on the outside that are marked as changed,
85 while (first
<= last
&& src
[first
] == dest
[first
])
88 while (last
>= first
&& src
[last
] == dest
[last
])
91 /* if any have really changed... */
95 memcpy(dest
+ first
, src
+ first
,
96 (last
- first
+ 1) * sizeof(chtype
));
101 if (first
< curscr
->_firstch
[j
] ||
102 curscr
->_firstch
[j
] == _NO_CHANGE
)
103 curscr
->_firstch
[j
] = first
;
105 if (last
> curscr
->_lastch
[j
])
106 curscr
->_lastch
[j
] = last
;
109 win
->_firstch
[i
] = _NO_CHANGE
; /* updated now */
112 win
->_lastch
[i
] = _NO_CHANGE
; /* updated now */
120 curscr
->_cury
= win
->_cury
+ begy
;
121 curscr
->_curx
= win
->_curx
+ begx
;
132 PDC_LOG(("doupdate() - called\n"));
137 if (isendwin()) /* coming back after endwin() called */
141 SP
->alive
= TRUE
; /* so isendwin() result is correct */
144 clearall
= curscr
->_clear
;
146 for (y
= 0; y
< SP
->lines
; y
++)
148 PDC_LOG(("doupdate() - Transforming line %d of %d: %s\n",
149 y
, SP
->lines
, (curscr
->_firstch
[y
] != _NO_CHANGE
) ?
152 if (clearall
|| curscr
->_firstch
[y
] != _NO_CHANGE
)
156 chtype
*src
= curscr
->_y
[y
];
157 chtype
*dest
= pdc_lastscr
->_y
[y
];
166 first
= curscr
->_firstch
[y
];
167 last
= curscr
->_lastch
[y
];
170 while (first
<= last
)
174 /* build up a run of changed cells; if two runs are
175 separated by a single unchanged cell, ignore the
179 len
= last
- first
+ 1;
181 while (first
+ len
<= last
&&
182 (src
[first
+ len
] != dest
[first
+ len
] ||
183 (len
&& first
+ len
< last
&&
184 src
[first
+ len
+ 1] != dest
[first
+ len
+ 1])
189 /* update the screen, and pdc_lastscr */
193 PDC_transform_line(y
, first
, len
, src
+ first
);
194 memcpy(dest
+ first
, src
+ first
, len
* sizeof(chtype
));
198 /* skip over runs of unchanged cells */
200 while (first
<= last
&& src
[first
] == dest
[first
])
204 curscr
->_firstch
[y
] = _NO_CHANGE
;
205 curscr
->_lastch
[y
] = _NO_CHANGE
;
209 curscr
->_clear
= FALSE
;
212 PDC_gotoyx(curscr
->_cury
, curscr
->_curx
);
214 SP
->cursrow
= curscr
->_cury
;
215 SP
->curscol
= curscr
->_curx
;
220 int wrefresh(WINDOW
*win
)
224 PDC_LOG(("wrefresh() - called\n"));
226 if ( !win
|| (win
->_flags
& (_PAD
|_SUBPAD
)) )
229 save_clear
= win
->_clear
;
232 curscr
->_clear
= TRUE
;
236 if (save_clear
&& win
->_maxy
== SP
->lines
&& win
->_maxx
== SP
->cols
)
237 curscr
->_clear
= TRUE
;
244 PDC_LOG(("refresh() - called\n"));
246 return wrefresh(stdscr
);
249 int wredrawln(WINDOW
*win
, int start
, int num
)
253 PDC_LOG(("wredrawln() - called: win=%p start=%d num=%d\n",
256 if (!win
|| start
> win
->_maxy
|| start
+ num
> win
->_maxy
)
259 for (i
= start
; i
< start
+ num
; i
++)
261 win
->_firstch
[i
] = 0;
262 win
->_lastch
[i
] = win
->_maxx
- 1;
268 int redrawwin(WINDOW
*win
)
270 PDC_LOG(("redrawwin() - called: win=%p\n", win
));
275 return wredrawln(win
, 0, win
->_maxy
);