home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / screen / scrn02 / zoomdemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-27  |  2.6 KB  |  88 lines

  1. /* zoomdemo.c - Demo for scrn_xxx direct screen write functions */
  2.  
  3.  
  4.  
  5. #include "stdio.h"
  6. #include "stdlib.h"
  7. #include "video.h"    /* direct screen write definitions */
  8.  
  9. char *convert(int);
  10.  
  11. #define LINT_ARGS 1    /* enable type checking of library functions */
  12.  
  13. #define LEFT    0
  14. #define RIGHT    79
  15. #define TOP    0
  16. #define BOTTOM    21
  17. #define TYPE    1        /* LINE TYPE */
  18.     
  19. char mainbuf[4000];        /* to hold initial screen save */    
  20. char scrbuf[4000];        /* to hold all other screen saves */
  21.  
  22. void main()
  23. {
  24.     SCRN sc;        /* make a struct of type SCRN */
  25.     int color;        /* user chioce */
  26.     int row, col;        /* to save initial cursor */
  27.     register i;        /* for loop */
  28.     char *bits;        /* pointer to converted string */
  29.  
  30.     scrn_init(&sc);                       /* _must_ initialize structure */
  31.     vid_get_cur(&row, &col);       /* save real cursor position */    
  32.     scrn_save(0, 79, 0, 24, mainbuf, &sc);  /* save whole screen */
  33.  
  34.  
  35.       while (1) {    /* let's loop like we did last night... */ 
  36.   
  37.     scrn_pos(23,0, &sc);        /* logical cursor position */
  38.     scrn_color(BLUE, WHITE, &sc);    /* sets attribute for all subsequent */
  39.                                           /* screen writes, or until changed  */ 
  40.  
  41.     color = 0;            /* make sure nothing strange happens */
  42.     scrn_puts("Type a number:         (0 = exit)", &sc);
  43.     vid_set_cur(23,15);
  44.     scanf("%d", &color);        /* get user choice */
  45.     bits = convert(color);        /* get binary equiv in string bits */
  46.     
  47.     if (!color) {        /* exit if color = 0 */
  48.       scrn_restore(0,79,0,24,mainbuf,&sc); /* restore whole screen */
  49.       vid_set_cur(row-1,col);          /* and real cursor - 1 */
  50.       return;                  /* and exit */    
  51.       }
  52.  
  53.     scrn_attrib(color, &sc);     /* reset color to user choice */
  54.     scrn_wzoom(LEFT, RIGHT, TOP, BOTTOM, scrbuf,TYPE,&sc); /* zoooooommmmm!!! */
  55.  
  56.     for (i = TOP+1; i < BOTTOM; i++) {   /* write something interesting */
  57.       scrn_pos(i,10, &sc);             /* inside the window           */
  58.       scrn_puts("Attribute byte set to ", &sc);
  59.       scrn_puts(bits, &sc);
  60.       }
  61.     
  62.      } /* bottom of loop */              
  63. }
  64.  
  65.  
  66. char *convert(dec)  /* convert a decimal to binary and return in a string */
  67.  int dec;
  68.  {
  69.      char *bits = "000000000000000000000000";     
  70.      char *tempstr;
  71.      char itoabuf[20];
  72.      int i;
  73.  
  74.      tempstr = (char *)itoa(dec, itoabuf, 2);    /* convert dec to bin */
  75.  
  76.      bits += 8;                /* pad it with zeros */    
  77.      while (*tempstr)             
  78.     *bits++ = *tempstr++;
  79.  
  80.      *bits = NULL;            /* null terminate the string */
  81.  
  82.      for (i = 0; i < 8; i++)        /* point bits at last 8 digits */
  83.     bits--;
  84.     
  85.      return( bits );
  86.  }
  87.     
  88.