changeset 335:1f4def71b836 dev-0_9_4

Back to simplistic backbuffer implementation due to laziness.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 20 Jun 2011 04:34:35 +0300
parents 3c7676b2b367
children 1ad1c7bf348c
files nnchat.c
diffstat 1 files changed, 17 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/nnchat.c	Mon Jun 20 03:42:36 2011 +0300
+++ b/nnchat.c	Mon Jun 20 04:34:35 2011 +0300
@@ -380,7 +380,6 @@
         if (*s == '\n') {
             QPUTCH('\n');
             QPUTCH(0);
-//            th_ringbuf_add(win->data, nn_strtuple_new(win->chlen, win->buf));
             th_ringbuf_add(win->data, win->buf);
             win->buf = NULL;
             win->chlen = 0;
@@ -399,32 +398,34 @@
 }
 
 
-void updateMainWin(BOOL force)
+BOOL updateMainWin(BOOL force)
 {
-    int y, w, h, offs;
+    int w, h, offs;
     qringbuf_t *buf;
 
-    if (mainWin == NULL || currWin == NULL) return;
-    if (!force && !currWin->dirty) return;
+    /* Check pointers */
+    if (mainWin == NULL || currWin == NULL)
+        return FALSE;
 
+    /* Check if update is forced or if the window is dirty */
+    if (!force && !currWin->dirty)
+        return FALSE;
+
+    /* Compute how many lines from backbuffer fit on the screen */
     buf = currWin->data;
     getmaxyx(mainWin, h, w);
+
+    /* Clear and redraw window */
     werase(mainWin);
-    
-    h -= 1;
-    offs = ((int) buf->size) - h - currWin->pos;
-    if (offs < 0)
-        offs = 0;
-
-    for (y = 0; y < h && offs < buf->size; offs++) {
-        if (buf->data[offs] != NULL) {
-            printWin(mainWin, (char *) buf->data[offs]);
-        }
-        y = getcury(mainWin);
+    scrollok(mainWin, 1);
+    for (offs = buf->size - h - currWin->pos; offs >= 0 && offs < buf->size - currWin->pos && offs < buf->size; offs++) {
+        if (buf->data[offs] != NULL)
+            printWin(mainWin, buf->data[offs]);
     }
     
     currWin->dirty = FALSE;
     wrefresh(mainWin);
+    return TRUE; 
 }
 
 
@@ -1587,7 +1588,6 @@
                 }
                 c = ERR;
             }
-            
 
             switch (c) {
 #ifdef KEY_RESIZE