home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / pccurs14.zoo / pccurses.4 / update.c < prev   
C/C++ Source or Header  |  1990-01-20  |  9KB  |  255 lines

  1. /****************************************************************/
  2. /* Doupdate() routine of the PCcurses package            */
  3. /*                                */
  4. /****************************************************************/
  5. /* This version of curses is based on ncurses, a curses version    */
  6. /* originally written by Pavel Curtis at Cornell University.    */
  7. /* I have made substantial changes to make it run on IBM PC's,    */
  8. /* and therefore consider myself free to make it public domain.    */
  9. /*                Bjorn Larsson (bl@infovox.se)    */
  10. /****************************************************************/
  11. /* 1.4:  Use of short wherever possible. Portability        */
  12. /*     improvements. Superflous parameter in            */
  13. /*     cursescattr() removed. Clearscreen() changed        */
  14. /*     so curses is guaranteed to know where the psy-        */
  15. /*     sical cursor is at all times:            900114    */
  16. /* 1.3:     MSC -W3, Turbo'C' -w -w-pro checkes:        881005    */
  17. /* 1.2:     Changed call sequence to cursesio.[c,asm], Thanks    */
  18. /*     to S. Creps. Rcsid[] string for maintenance:    881002    */
  19. /* 1.0:     Release:                    870515    */
  20. /****************************************************************/
  21.  
  22. #include <curses.h>
  23. #include <curspriv.h>
  24.  
  25. static void clrupdate();        /* fwd declaration */
  26. static bool transformline();
  27. static void clearscreen();
  28. static void gotoxy();
  29. static void Putchar();
  30.  
  31. char _curses_update_rcsid[] = "@(#)update.c     v.1.4  - 900114";
  32.  
  33. static WINDOW    *twin;            /* used by many routines */
  34.  
  35. static    char     atrtab[64] =        /* attribute encoding table. */
  36.   {                    /* feel free to edit if your */
  37.   (char)7,    /* NORMAL (0) */    /* display board supports all */
  38.   (char)0x87,    /* BLINK */        /* possible combinations */
  39.   (char)0,    /* BLANK */
  40.   (char)0,    /* BLINK & BLANK */
  41.   (char)0xf,    /* BOLD */
  42.   (char)0x8f,    /* BOLD & BLINK */
  43.   (char)0,    /* BOLD & BLANK */
  44.   (char)0,    /* BOLD & BLINK & BLANK */
  45.   (char)0x70,    /* REVERSE (8) */
  46.   (char)0xf0,    /* REVERSE & BLINK */
  47.   (char)0,    /* REVERSE & BLANK */
  48.   (char)0,    /* REVERSE & BLINK & BLANK */
  49.   (char)0x78,    /* REVERSE & BOLD */
  50.   (char)0xf8,    /* REVERSE & BOLD & BLINK */
  51.   (char)0,    /* REVERSE & BOLD & BLANK */
  52.   (char)0,    /* REVERSE & BOLD & BLINK & BLANK */
  53.   (char)0xf,    /* STANDOUT (10) */
  54.   (char)0x8f,    /* STANDOUT & BLINK */
  55.   (char)0,    /* STANDOUT & BLANK */
  56.   (char)0,    /* STANDOUT & BLINK & BLANK */
  57.   (char)0xf,    /* STANDOUT & BOLD */
  58.   (char)0x8f,    /* STANDOUT & BOLD & BLINK */
  59.   (char)0,    /* STANDOUT & BOLD & BLANK */
  60.   (char)0,    /* STANDOUT & BOLD & BLINK & BLANK */
  61.   (char)0x70,    /* STANDOUT & REVERSE (18) */
  62.   (char)0xf0,    /* STANDOUT & REVERSE & BLINK */
  63.   (char)0,    /* STANDOUT & REVERSE & BLANK */
  64.   (char)0,    /* STANDOUT & REVERSE & BLINK & BLANK */
  65.   (char)0x70,    /* STANDOUT & REVERSE & BOLD */
  66.   (char)0xf0,    /* STANDOUT & REVERSE & BOLD & BLINK */
  67.   (char)0,    /* STANDOUT & REVERSE & BOLD & BLANK */
  68.   (char)0,    /* STANDOUT & REVERSE & BOLD & BLINK & BLANK */
  69.   (char)1,    /* UNDERLINE (20) */
  70.   (char)0x81,    /* UNDERLINE & BLINK */
  71.   (char)0,    /* UNDERLINE & BLANK */
  72.   (char)0,    /* UNDERLINE & BLINK & BLANK */
  73.   (char)9,    /* UNDERLINE & BOLD */
  74.   (char)0x89,    /* UNDERLINE & BOLD & BLINK */
  75.   (char)0,    /* UNDERLINE & BOLD & BLANK */
  76.   (char)0,    /* UNDERLINE & BOLD & BLINK & BLANK */
  77.   (char)0x70,    /* UNDERLINE & REVERSE (28) */
  78.   (char)0xf0,    /* UNDERLINE & REVERSE & BLINK */
  79.   (char)0,    /* UNDERLINE & REVERSE & BLANK */
  80.   (char)0,    /* UNDERLINE & REVERSE & BLINK & BLANK */
  81.   (char)0x79,    /* UNDERLINE & REVERSE & BOLD */
  82.   (char)0xf9,    /* UNDERLINE & REVERSE & BOLD & BLINK */
  83.   (char)0,    /* UNDERLINE & REVERSE & BOLD & BLANK */
  84.   (char)0,    /* UNDERLINE & REVERSE & BOLD & BLINK & BLANK */
  85.   (char)9,    /* UNDERLINE & STANDOUT (30) */
  86.   (char)0x89,    /* UNDERLINE & STANDOUT & BLINK */
  87.   (char)0,    /* UNDERLINE & STANDOUT & BLANK */
  88.   (char)0,    /* UNDERLINE & STANDOUT & BLINK & BLANK */
  89.   (char)9,    /* UNDERLINE & STANDOUT & BOLD */
  90.   (char)0x89,    /* UNDERLINE & STANDOUT & BOLD & BLINK */
  91.   (char)0,    /* UNDERLINE & STANDOUT & BOLD & BLANK */
  92.   (char)0,    /* UNDERLINE & STANDOUT & BOLD & BLINK & BLANK */
  93.   (char)0x70,    /* UNDERLINE & STANDOUT & REVERSE (38) */
  94.   (char)0xf0,    /* UNDERLINE & STANDOUT & REVERSE & BLINK */
  95.   (char)0,    /* UNDERLINE & STANDOUT & REVERSE & BLANK */
  96.   (char)0,    /* UNDERLINE & STANDOUT & REVERSE & BLINK & BLANK */
  97.   (char)0x70,    /* UNDERLINE & STANDOUT & REVERSE & BOLD */
  98.   (char)0xf0,    /* UNDERLINE & STANDOUT & REVERSE & BOLD & BLINK */
  99.   (char)0,    /* UNDERLINE & STANDOUT & REVERSE & BOLD & BLANK */
  100.   (char)0,    /* UNDERLINE & STANDOUT & REVERSE & BOLD & BLINK & BLANK */
  101.   };
  102.  
  103. /****************************************************************/
  104. /* Doupdate() updates the physical screen to look like _curs-   */
  105. /* var.tmpwin if curscr is not 'Clear-marked'. Otherwise it    */
  106. /* updates the screen to look like curscr.            */
  107. /****************************************************************/
  108.  
  109. void doupdate()
  110.   {
  111.   short     i;
  112.  
  113.   twin   = _cursvar.tmpwin;
  114.   if (curscr->_clear)
  115.     clrupdate(curscr);
  116.   else
  117.     {
  118.     if (twin->_clear)
  119.       clrupdate(twin);
  120.     else
  121.       {
  122.       for (i=0; i < LINES; i++)
  123.     if (twin->_minchng[i] != _NO_CHANGE)
  124.       if (transformline(i))
  125.         break;
  126.       } /* else */
  127.     } /* else */
  128.   curscr->_curx = twin->_curx;
  129.   curscr->_cury = twin->_cury;
  130.   gotoxy(curscr->_cury, curscr->_curx);
  131.   } /* doupdate */
  132.  
  133. /****************************************************************/
  134. /* Clrupdate(scr) updates the screen by clearing it and then    */
  135. /* redraw it in it's entirety. If _cursvar.refrbrk is TRUE, and    */
  136. /* there is pending input characters, the update will be pre-    */
  137. /* maturely terminated.                        */
  138. /****************************************************************/
  139.  
  140. static void clrupdate(scr)
  141.   WINDOW    *scr;
  142.   {
  143.   short        *src;
  144.   short        *dst;
  145.   short         i;
  146.   short         j;
  147.   static WINDOW    *w;
  148.  
  149.   w = curscr;
  150.  
  151.   if (scr != w)                /* copy scr to curscr */
  152.     {
  153.     for (i=0; i < LINES; i++)
  154.       {
  155.       src = scr->_line[i];
  156.       dst = w->_line[i];
  157.       for (j=0; j < COLS; j++)
  158.     *dst++ = *src++;
  159.       } /* for */
  160.     } /* if */
  161.   clearscreen();            /* clear physical screen */
  162.   scr->_clear = FALSE;
  163.   for (i=0; i < LINES; i++)        /* update physical screen */
  164.     {
  165.     src = w->_line[i];
  166.     for(j=0; j < COLS; j++)
  167.       {
  168.       if (*src != (' ' | ATR_NRM))
  169.     {
  170.     gotoxy(i,j);
  171.     Putchar(*src);
  172.     } /* if */
  173.       src++;
  174.       } /* for */
  175.     if(_cursvar.refrbrk && _cursespendch())
  176.       return;
  177.     } /* for */
  178.   } /* clrupdate */
  179.  
  180. /****************************************************************/
  181. /* Transformline() updates the given physical line to look    */
  182. /* like the corresponding line in _cursvar.tmpwin. Transform-    */
  183. /* line returns 1 if premature refresh end is allowed, and    */
  184. /* there is an input character pending.                */
  185. /****************************************************************/
  186.  
  187. static bool transformline(lineno)
  188.   register int    lineno;
  189.   {
  190.   short        *dstp;
  191.   short        *srcp;
  192.   short         x;
  193.   short         endx;
  194.  
  195.   x    = twin->_minchng[lineno];
  196.   endx = twin->_maxchng[lineno];
  197.   dstp = curscr->_line[lineno] + x;
  198.   srcp = twin->_line[lineno] + x;
  199.   
  200.   for( ; x <= endx; x++)
  201.     {
  202.     if(*dstp != *srcp)
  203.       {
  204.       gotoxy(lineno,x);
  205.       Putchar(*srcp);
  206.       } /* if */
  207.     *dstp++ = *srcp++;
  208.     } /* for */
  209.   twin->_minchng[lineno] = _NO_CHANGE;
  210.   twin->_maxchng[lineno] = _NO_CHANGE;
  211.   return ((bool)(_cursvar.refrbrk && _cursespendch()));
  212.   } /* transformline */
  213.  
  214. /****************************************************************/
  215. /* Clearscreen() clears the physical screen and puts the cursor    */
  216. /* in the home position.                    */
  217. /****************************************************************/
  218.  
  219. static void clearscreen()
  220.   {
  221.   _cursesscroll(0,0,LINES-1,COLS-1,0,atrtab[0]);
  222.   _cursescursor(0,0);
  223.   _cursvar.cursrow = 0;
  224.   _cursvar.curscol = 0;
  225.   } /* clearscreen */
  226.  
  227. /****************************************************************/
  228. /* Gotoxy() moves the physical cursor to the desired address on    */
  229. /* the screen. We don't optimize here - on a PC, it takes more    */
  230. /* time to optimize than to do things directly.            */
  231. /****************************************************************/
  232.  
  233. static void gotoxy(row,col)
  234.   int row, col;
  235.   {
  236.   if((_cursvar.cursrow == row) && (_cursvar.curscol == col))
  237.     return;
  238.   _cursescursor(row,col);
  239.   _cursvar.cursrow = row;
  240.   _cursvar.curscol = col;
  241.   } /* gotoxy */
  242.  
  243. /****************************************************************/
  244. /* Putchar() writes a character, with attributes, to the physi-    */
  245. /* cal screen, but avoids writing to the lower right screen    */
  246. /* position.                            */
  247. /****************************************************************/
  248.  
  249. static void Putchar(ch)
  250.   int ch;
  251.   {
  252.   if ((_cursvar.cursrow < LINES) || (_cursvar.curscol < COLS))
  253.     _cursescattr(ch,atrtab[(ch >> 8) & 0x3f]);
  254.   } /* Putchar */
  255.