home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / ipxlib / video.c < prev   
Encoding:
C/C++ Source or Header  |  1994-06-01  |  9.0 KB  |  193 lines

  1. // VIDEO.C -- Video routines for IPXTEST
  2. // by Allen Brunson  06/01/94
  3.  
  4.  
  5. #ifdef _MSC_VER        // If a Microsoft compiler
  6. #include <graph.h>     // _settextcursor(), _settextcolor()
  7. #include <memory.h>    // memset()
  8. #else                  // If a Borland compiler
  9. #include <mem.h>       // memset()
  10. #endif
  11.  
  12. #include <conio.h>     // cputs(), gettextinfo()
  13. #include <string.h>    // strlen()
  14. #include "ipxtest.h"   // IPXtest-specific defines
  15.  
  16.  
  17. /****************************************************************************/
  18. /*                                                                          */
  19. /***  Screen data                                                         ***/
  20. /*                                                                          */
  21. /****************************************************************************/
  22.  
  23. byte cols, rows;                                   // Screen size
  24. byte iCol, iRow;                                   // Input window cursor pos
  25. byte mCol, mRow;                                   // Main window cursor pos
  26.  
  27. char strBlank[MAXCOLS + 1];                        // Blank line string
  28.  
  29.  
  30. /****************************************************************************/
  31. /*                                                                          */
  32. /***  message()                                                           ***/
  33. /*                                                                          */
  34. /****************************************************************************
  35.  
  36. This procedure prints a message to the upper screen window.                 */
  37.  
  38. void message(char *str)                            // Begin message()
  39.   {
  40.     if (strlen(str) > cols - 2)                    // If string is too
  41.       str[cols - 2] = 0;                           //  long, truncate it
  42.  
  43.     cursorOff();                                   // Turn off cursor
  44.  
  45.     if (mRow == rows - 1) vidScroll();             // Scroll if at bottom
  46.  
  47.     gotoxy(mCol, mRow); cputs(str); mRow++;        // Print string
  48.  
  49.     gotoxy(iCol, iRow);
  50.     cursorOn();                                    // Turn on cursor
  51.   }                                                // End message()
  52.  
  53.  
  54. /****************************************************************************/
  55. /*                                                                          */
  56. /***  vidCLS()                                                            ***/
  57. /*                                                                          */
  58. /****************************************************************************
  59.  
  60. This procedure clears the upper window.                                     */
  61.  
  62. void vidCLS(void)                                  // Begin vidCLS()
  63.   {
  64.     word i;                                        // Loop counter
  65.  
  66.     cursorOff();                                   // Turn off the cursor
  67.  
  68.     for (i = 2; i <= (unsigned) rows - 2; i++)     // Loop for all rows
  69.       {
  70.         gotoxy(2, i);                              // Go to a row
  71.         cputs(strBlank);                           // Blank it
  72.       }
  73.  
  74.     gotoxy(iCol, iRow);                            // Go to input window
  75.     cursorOn();                                    // Turn on cursor
  76.  
  77.     mCol = 2; mRow = 2;                            // Set new position
  78.   }                                                // End vidCLS()
  79.  
  80.  
  81. /****************************************************************************/
  82. /*                                                                          */
  83. /***  vidScroll()                                                         ***/
  84. /*                                                                          */
  85. /****************************************************************************
  86.  
  87. This procedure scrolls the main text window up one row.                     */
  88.  
  89. void vidScroll(void)                               // Begin vidScroll()
  90.   {
  91.     #ifdef __TURBOC__                              // If a Borland compiler
  92.  
  93.     word buf[MAXCOLS - 2];                         // Screen buffer
  94.     word i;                                        // Loop counter
  95.  
  96.     for (i = 2; i <= rows - 3; i++)                // Loop for all rows in
  97.       {                                            //  window except last
  98.         gettext(2, i+1, cols - 1, i+1, buf);       // Get a row
  99.         puttext(2, i, cols - 1, i, buf);           // Print it one row up
  100.       }
  101.  
  102.     gotoxy(2, rows - 2); cputs(strBlank);          // Blank line at bottom
  103.  
  104.     mRow--;                                        // Move up one row
  105.  
  106.     #else                                          // If a Microsoft compiler
  107.  
  108.     vidCLS();                                      // Just clear the screen
  109.  
  110.     #endif
  111.   }                                                // End vidScroll()
  112.  
  113.  
  114. /****************************************************************************/
  115. /*                                                                          */
  116. /***  vidStart()                                                          ***/
  117. /*                                                                          */
  118. /****************************************************************************
  119.  
  120. This procedure sets up the screen.                                          */
  121.  
  122. void vidStart(void)                                // Begin vidStart()
  123.   {
  124.     word row, col;                                 // Screen pos
  125.     #ifdef __TURBOC__                              // If a Borland compiler
  126.     struct text_info textInfo;                     // Screen info struct
  127.     #else                                          // If a Microsoft compiler
  128.     struct _videoconfig vconfig;
  129.     #endif
  130.  
  131.     #ifdef __TURBOC__                              // If a Borland compiler
  132.     textbackground(cBACKGRND);                     // Set background color
  133.     textcolor(cFOREGRND);                          // Set foreground color
  134.     gettextinfo(&textInfo);                        // Get screen info
  135.     rows = textInfo.screenheight;                  // Save rows
  136.     cols = textInfo.screenwidth;                   // Save cols
  137.     clrscr();                                      // Clear the screen
  138.     #else                                          // If a Microsoft compiler
  139.     _getvideoconfig(&vconfig);                     // Get screen info
  140.     rows = (word) vconfig.numtextrows;             // Saven rows
  141.     cols = (word) vconfig.numtextcols;             // Save cols
  142.     _clearscreen(_GCLEARSCREEN);                   // Clear the screen
  143.     #endif
  144.        
  145.     cursorOff();                                   // Turn off cursor
  146.  
  147.     if (cols > MAXCOLS) cols = MAXCOLS;            // Clip col count
  148.  
  149.     iRow = rows; iCol = 2;                         // Set starting input pos
  150.     mRow = 2;    mCol = 2;                         // Set main window pos
  151.  
  152.     memset(strBlank, ' ', cols - 2);               // Fill it with spaces
  153.  
  154.     row = 1; col = 1;  gotoxy(col, row);           // Start at upper left
  155.     putch(218);                                    // Draw upper left corner
  156.     for ( ; col < cols - 1; col++) putch(196);     // Draw top line
  157.     putch(191);                                    // Draw upper right corner
  158.  
  159.     for (row = 2, col = 1; row < rows - 1; row++)  // Loop to draw sides
  160.       {
  161.         gotoxy(col, row); putch(179);              // Draw left side
  162.         gotoxy(cols, row); putch(179);             // Draw right side
  163.       }
  164.  
  165.     gotoxy(col, row); putch(192);                  // Draw lower left corner
  166.     for ( ; col < cols - 1; col++) putch(196);     // Draw bottom line
  167.     putch(217);                                    // Draw lower right corner
  168.  
  169.     cprintf(">");                                  // Print input prompt
  170.  
  171.     gotoxy(iCol, iRow);                            // Go to input window
  172.     cursorOn();                                    // Turn on cursor
  173.   }                                                // End vidStart()
  174.  
  175.  
  176. /****************************************************************************/
  177. /*                                                                          */
  178. /***  vidStop()                                                           ***/
  179. /*                                                                          */
  180. /****************************************************************************
  181.  
  182. This procedure restores the screen to its original state.                   */
  183.  
  184. void vidStop(void)                                 // Begin vidStop()
  185.   { 
  186.     #ifdef _MSC_VER                                // If Microsoft compiler
  187.     _clearscreen(_GCLEARSCREEN);                   // Clear the screen
  188.     #else                                          // If Borland compiler
  189.     clrscr();                                      // Clear the screen
  190.     #endif
  191.     cursorOn();                                    // Set normal cursor
  192.   }                                                // End vidStop()
  193.