home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CTECHAPP.ZIP / WINDOWS.ZIP / SCREEN.CPP < prev    next >
C/C++ Source or Header  |  1990-03-01  |  5KB  |  228 lines

  1. //  Module:     Screen  (MS-DOS Text Video Display Class)
  2. //  Version:    1.10
  3. //
  4. //  Language:   C++ 2.0
  5. //  Environ:    MS-DOS w/monochrome or color text display
  6. //
  7. //  Purpose:    Provides a class for manipulating a text display.
  8. //
  9. //  WARNING!    To drastically improve the speed of this class, NO RANGE
  10. //              CHECKING is done! Invalid line/column values may cause
  11. //              portions of non-video memory to be corrupted!
  12. //
  13. //  Written by: Scott Robert Ladd
  14.  
  15. #include "Screen.hpp"
  16. #include "Str.hpp"
  17.  
  18. extern "C"
  19.     {
  20.     #include "dos.h"
  21.     }
  22.  
  23. // assign values to static class members
  24. unsigned int  Screen::Width        = 0;
  25. unsigned int  Screen::Length       = 0;
  26. unsigned int  Screen::BaseAdr      = 0;
  27. unsigned int  Screen::CursorShape  = 0;
  28. int           Screen::CursorHidden = 0;
  29.  
  30. Screen Display;
  31.  
  32. // constructor
  33. Screen::Screen()
  34.     {
  35.     ++HowMany;
  36.  
  37.     if (HowMany > 1)
  38.         return;
  39.  
  40.     union REGS regs;
  41.  
  42.     regs.h.ah = 0x0f;
  43.  
  44.     int86(0x10,®s,®s);
  45.  
  46.     if (regs.h.al == 0x07)
  47.         BaseAdr = 0xB000;
  48.     else
  49.         BaseAdr = 0xB800;
  50.  
  51.     Width = (int) regs.h.ah;
  52.  
  53.     regs.x.ax = 0x1130;
  54.     regs.h.bh = 0;
  55.     regs.x.dx = 0;
  56.  
  57.     int86(0x10,®s,®s);
  58.  
  59.     Length = regs.x.dx + 1;
  60.  
  61.     if (Length == 1)
  62.         Length = 25;
  63.  
  64.     Clear();
  65.  
  66.     CursorHidden = 0;
  67.     }
  68.  
  69. // destructor
  70. Screen::~Screen()
  71.     {
  72.     --HowMany;
  73.  
  74.     if (HowMany > 0)
  75.         return;
  76.  
  77.     Clear();
  78.  
  79.     CursorSetPos(0,0);
  80.     }
  81.  
  82. // access methods
  83. void Screen::Dimensions(unsigned int & wid, unsigned int & len)
  84.     {
  85.     wid = Width;
  86.     len = Length;
  87.     }
  88.  
  89. // cursor methods
  90. void Screen::CursorHide()
  91.     {
  92.     if (CursorHidden)
  93.         return;
  94.  
  95.     union REGS regs;
  96.  
  97.     regs.h.ah = 3;
  98.     regs.h.bh = 0;
  99.  
  100.     int86(0x10,®s,®s);
  101.  
  102.     CursorShape = regs.x.cx;
  103.  
  104.     regs.h.ah = 1;
  105.     regs.x.cx = 0x2000;
  106.  
  107.     int86(0x10,®s,®s);
  108.  
  109.     CursorHidden = 1;
  110.     }
  111.  
  112. void Screen::CursorUnhide()
  113.     {
  114.     if (!CursorHidden)
  115.         return;
  116.  
  117.     union REGS regs;
  118.  
  119.     regs.h.ah = 1;
  120.     regs.x.cx = CursorShape;
  121.  
  122.     int86(0x10,®s,®s);
  123.  
  124.     CursorHidden = 0;
  125.     }
  126.  
  127. void Screen::CursorSetPos(unsigned int line, unsigned int col)
  128.     {
  129.     union REGS regs;
  130.  
  131.     regs.h.ah = 2;
  132.     regs.h.bh = 0;
  133.     regs.h.dh = line;
  134.     regs.h.dl = col;
  135.  
  136.     int86(0x10,®s,®s);
  137.     }
  138.  
  139. void Screen::CursorGetPos(unsigned int & line, unsigned int & col)
  140.     {
  141.     union REGS regs;
  142.  
  143.     regs.h.ah = 3;
  144.     regs.h.bh = 0;
  145.  
  146.     int86(0x10,®s,®s);
  147.  
  148.     line = regs.h.dh;
  149.     col  = regs.h.dl;
  150.     }
  151.  
  152. // display a text string method
  153. void Screen::PutStr(unsigned int line, unsigned int col,
  154.                     unsigned char attr, String & str)
  155.     {
  156.     for (unsigned int i = 0; str[i] != '\000'; ++i)
  157.         PutChar(line, col + i, attr, str[i]);
  158.     }
  159.  
  160.  
  161.  
  162. // box display methods
  163. void Screen::DrawBox(unsigned int topLine, unsigned int leftCol,
  164.                      unsigned int btmLine, unsigned int rightCol,
  165.                      unsigned char attr, BoxType typeBox)
  166.     {
  167.     if ((typeBox == BT_NONE) || (leftCol >= rightCol) || (topLine >= btmLine))
  168.         return;
  169.  
  170.     char v, h;
  171.  
  172.     switch (typeBox)
  173.         {
  174.         case BT_SINGLE:
  175.             v = '\xB3';
  176.             h = '\xC4';
  177.             PutChar(topLine, leftCol,  attr, '\xDA');
  178.             PutChar(topLine, rightCol, attr, '\xBF');
  179.             PutChar(btmLine, leftCol,  attr, '\xC0');
  180.             PutChar(btmLine, rightCol, attr, '\xD9');
  181.             break;
  182.         case BT_DOUBLE:
  183.             v = '\xBA';
  184.             h = '\xCD';
  185.             PutChar(topLine, leftCol,  attr, '\xC9');
  186.             PutChar(topLine, rightCol, attr, '\xBB');
  187.             PutChar(btmLine, leftCol,  attr, '\xC8');
  188.             PutChar(btmLine, rightCol, attr, '\xBC');
  189.             break;
  190.         case BT_SOLID:
  191.             v = '\xDB';
  192.             h = '\xDB';
  193.             PutChar(topLine, leftCol,  attr, '\xDB');
  194.             PutChar(topLine, rightCol, attr, '\xDB');
  195.             PutChar(btmLine, leftCol,  attr, '\xDB');
  196.             PutChar(btmLine, rightCol, attr, '\xDB');
  197.         }
  198.  
  199.     for (int c = leftCol + 1; c < rightCol; ++c)
  200.         {
  201.         PutChar(topLine, c, attr, h);
  202.         PutChar(btmLine, c, attr, h);
  203.         }
  204.  
  205.     for (int l = topLine + 1; l < btmLine; ++l)
  206.         {
  207.         PutChar(l, leftCol,  attr, v);
  208.         PutChar(l, rightCol, attr, v);
  209.         }
  210.     }
  211.  
  212.  
  213. // screen clearing methods
  214. void Screen::Clear()
  215.     {
  216.     for (int l = 0; l < Length; ++l)
  217.         {
  218.         for (int c = 0; c < Width; ++c)
  219.             PutChar(l,c,7,' ');
  220.         }
  221.     }
  222.  
  223. void Screen::ClearLine(unsigned int line, unsigned int col)
  224.     {
  225.     for (int c = col; c < Width; ++c)
  226.         PutChar(line,c,7,' ');
  227.     }
  228.