We found the scroll down command for a window--winsertln. That works fine.
We thought that curses didn't support scrolling the other way so we
wrote a loop to redraw the material. That worked but it is slow
and causes jerky motion of the screen.
We later found the wscrl(-1) facility but it doesn't seem to work.
Instead of scrolling the contents of the window, it moves the whole window
down on the screen.
Here is a test program. What are we doing wrong?
#include <curses.h>
main (){
WINDOW *z;
/* create new window */
/* initialize the window with initial data */
/* set current_line_on_screen
currrent_line_of_list */
/* do logic in program */
FILE *debug;
int z1;
debug=fopen("debug.out","w");
initscr();
z=newwin(5,80,0,0);
box(z,'|','_');
keypad(z,TRUE);
clear();
savetty();
raw();
nonl();
wmove(z,1,1);
wprintw(z,"abc");
wmove(z,2,2);
wprintw(z,"def");
wmove(z,3,3);
wprintw(z,"ghi");
noecho();
z1=wgetch(z);
scrollok(z,TRUE);
idlok(z,TRUE);
while ((z1 == KEY_UP) || (z1==KEY_DOWN)) {
z1=wgetch(z);
wscrl(z,-1);
}
fprintf(debug,"non arrow hit %x\n",z1);
fclose(debug);
printf("non arrow hit %x\n",z1);
endwin();
}
: We thought that curses didn't support scrolling the other way so we
: wrote a loop to redraw the material. That worked but it is slow
: and causes jerky motion of the screen.
: We later found the wscrl(-1) facility but it doesn't seem to work.
: Instead of scrolling the contents of the window, it moves the whole window
: down on the screen.
: Here is a test program. What are we doing wrong?
Hum... wscrl() seems to work for both up and down. Where the confusion
might be is that "contents of the window" == "whole window". Just because
box() is used on a window doesn't mean that the box itself is not
part of the window's contents.
Hopefully I've understood you question and the modifications I've
made to your test program will clear things up.
#include <curses.h>
main (){
WINDOW *w,*z,*zz;
/* create new window */
/* initialize the window with initial data */
/* set current_line_on_screen
currrent_line_of_list */
/* do logic in program */
FILE *debug;
int i,z1;
debug=fopen("debug.out","w");
initscr();
zz=newwin(16,80,0,0);
z=subwin(zz,14,78,1,1);
w=newwin(5,80,16,0);
box(zz,'|','_');
box(w,'w','w');
wrefresh(w);
wrefresh(zz);
keypad(z,TRUE);
clear();
savetty();
raw();
nonl();
for (i=0;i< 14 ; i++) {
wmove(z,i,i);
wprintw(z,"abc");
}
noecho();
z1=wgetch(z);
scrollok(z,TRUE);
idlok(z,TRUE);
while ((z1 == KEY_UP) || (z1==KEY_DOWN)) {
if (z1 == KEY_UP) wscrl(z,-1);
if (z1 == KEY_DOWN) wscrl(z,1);
z1=wgetch(z);
}
fprintf(debug,"non arrow hit %x\n",z1);
fclose(debug);
printf("non arrow hit %x\n",z1);
endwin();
}
--
Dave Katleman (No opinions but my own need apply)
katl...@eng.sun.com
What platform are you using? I can't find wscrl() in SunOS 4.1.3 nor
HPUX 9.0 curses.
I use a pad when I want to do scrolling. Pads allow you to specify
what part of a window you want displayed. Scrolling can be done by
moving this "view window" up and down. Take this code for example:
foo() {
WINDOW *pad;
int y = 0;
pad = newpad( 1024, 80);
prefresh( pad, y, 0, 0, LINES-1, COLS-1);
.
.
.
/* scroll up */
y--;
prefresh( pad, y, 0, 0, LINES-1, COLS-1);
.
.
.
/* scroll down */
y++;
prefresh( pad, y, 0, 0, LINES-1, COLS-1);
.
.
.
}
Hope this helps.
MikeB
I use wscrl to scroll up and down too, but on machines that doesn't
support wscrl, I uses use the following macro to simulate wscrl,
#define wscrl(win,direction) \
{ \
if (direction) /* Move up */ \
scroll(win) \
else \
{ \
wmove(win,0,0); \
winsertln(win); \
} \
wrefresh(win); \
}
--
-['dzen:kinz]-
<Detail in URL=http://www.iscs.nus.sg/~chngsunp>