diff options
author | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-08-17 13:28:53 +0800 |
---|---|---|
committer | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-08-17 13:28:53 +0800 |
commit | 7c7adbd6aefd1498cd84ee947c52269ce099d347 (patch) | |
tree | 0cf6027e7edf5f7137d519a34769411115e46251 /mbbsd/screen.c | |
parent | 1598828725cc3a14f4e9a1a18b4212ad808a3516 (diff) | |
download | pttbbs-7c7adbd6aefd1498cd84ee947c52269ce099d347.tar pttbbs-7c7adbd6aefd1498cd84ee947c52269ce099d347.tar.gz pttbbs-7c7adbd6aefd1498cd84ee947c52269ce099d347.tar.bz2 pttbbs-7c7adbd6aefd1498cd84ee947c52269ce099d347.tar.lz pttbbs-7c7adbd6aefd1498cd84ee947c52269ce099d347.tar.xz pttbbs-7c7adbd6aefd1498cd84ee947c52269ce099d347.tar.zst pttbbs-7c7adbd6aefd1498cd84ee947c52269ce099d347.zip |
screen_backup() & screen_restore() update:
* automatic allocate memory, save cursor location and backup
* automatic restore screen, cursor location and free memory
* works on screen lessening
* no more crash on screen enlarged
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3051 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/screen.c')
-rw-r--r-- | mbbsd/screen.c | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/mbbsd/screen.c b/mbbsd/screen.c index b7bde5ff..c0a389f2 100644 --- a/mbbsd/screen.c +++ b/mbbsd/screen.c @@ -521,53 +521,60 @@ standend(void) } } -void screen_backup(int len, const screenline_t *bp, screen_backup_t *old) +static size_t screen_backupsize(int len, const screenline_t *bp) { int i; - size_t offset=0; - void *buf = old->raw_memory; + size_t sum = 0; + for(i = 0; i < len; i++) + sum += ((char*)&bp[i].data - (char*)&bp[i]) + bp[i].len; + return sum; +} + +void screen_backup(screen_backup_t *old) +{ + int i; + size_t offset = 0; + void *buf; + screenline_t* bp = big_picture; + + buf = old->raw_memory = malloc(screen_backupsize(t_lines, big_picture)); old->col = t_columns; old->row = t_lines; + getyx(&old->y, &old->x); - for(i=0;i<len;i++) { - memcpy((char*)buf+offset, &bp[i], ((char*)&bp[i].data-(char*)&bp[i])); - offset+=((char*)&bp[i].data-(char*)&bp[i]); - memcpy((char*)buf+offset, &bp[i].data, bp[i].len); - offset+=bp[i].len; - } -} + for(i = 0; i < t_lines; i++) { + /* backup header */ + memcpy((char*)buf + offset, &bp[i], ((char*)&bp[i].data - (char*)&bp[i])); + offset += ((char*)&bp[i].data - (char*)&bp[i]); -size_t screen_backupsize(int len, const screenline_t *bp) -{ - int i; - size_t sum=0; - for(i=0;i<len;i++) - sum+=((char*)&bp[i].data-(char*)&bp[i]) + bp[i].len; - return sum; + /* backup body */ + memcpy((char*)buf + offset, &bp[i].data, bp[i].len); + offset += bp[i].len; + } } -void screen_restore(int len, screenline_t *bp, const screen_backup_t *old) +void screen_restore(const screen_backup_t *old) { int i; size_t offset=0; void *buf = old->raw_memory; + screenline_t* bp = big_picture; + const int len = MIN(old->row, t_lines); - // TODO try to be more user friendly. - if (old->col > t_columns || old->row > t_lines) { - move(1, 0); - clrtobot(); - move(2, 2); - outs("偵測到視窗改變大小,畫面繪製將會暫時失效"); - return; - } + for(i = 0; i < len; i++) { + /* restore header */ + memcpy(&bp[i], (char*)buf + offset, ((char*)&bp[i].data - (char*)&bp[i])); + offset += ((char*)&bp[i].data - (char*)&bp[i]); - for(i=0;i<len;i++) { - memcpy(&bp[i], (char*)buf+offset, ((char*)&bp[i].data-(char*)&bp[i])); - offset+=((char*)&bp[i].data-(char*)&bp[i]); - memcpy(&bp[i].data, (char*)buf+offset, bp[i].len); - offset+=bp[i].len; + /* restore body */ + memcpy(&bp[i].data, (char*)buf + offset, bp[i].len); + offset += bp[i].len; } + + free(old->raw_memory); + move(old->y, old->x); + redoscr(); } /* vim:sw=4 |