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

  1. //  Module:     Wdw_Disp  (Window Class)
  2. //  Version:    2.11
  3. //
  4. //  Language:   C++ 2.0
  5. //  Environ:    IBM-PC MS-DOS
  6. //
  7. //  Purpose:    Display methods
  8. //
  9. //  Written by: Scott Robert Ladd
  10.  
  11. #include "Str.hpp"
  12. #include "Window.hpp"
  13.  
  14. extern "C"
  15.     {
  16.     #include "string.h"
  17.     #include "stdio.h"
  18.     #include "stddef.h"
  19.     #include "dos.h"
  20.     }
  21.  
  22. // paint entire window
  23. void Window::Paint()
  24.     {
  25.     if (Concealed)
  26.         return;
  27.  
  28.     unsigned int l, c, hpos;
  29.  
  30.     // draw border
  31.     switch (Border)
  32.         {
  33.         case BT_SINGLE :
  34.             Display(-1,-1,BorderColor,'\xDA');
  35.             Display(Length,-1,BorderColor,'\xC0');
  36.             Display(Length,Width,BorderColor,'\xD9');
  37.             Display(-1,Width,BorderColor,'\xBF');
  38.  
  39.             if (Header.Length() == 0)
  40.                 for (c = 0; c < Width; ++c)
  41.                     {
  42.                     Display(-1,c,BorderColor,'\xC4');
  43.                     Display(Length,c,BorderColor,'\xC4');
  44.                     }
  45.             else
  46.                 {
  47.                 hpos = 0;
  48.  
  49.                 for (c = 0; c < Width; ++c)
  50.                     {
  51.                     if (hpos < Header.Length())
  52.                         {
  53.                         Display(-1,c,BorderColor,Header[hpos]);
  54.                         ++hpos;
  55.                         }
  56.                     else
  57.                         Display(-1,c,BorderColor,'\xC4');
  58.  
  59.                     Display(Length,c,BorderColor,'\xC4');
  60.                     }
  61.                 }
  62.  
  63.             for (l = 0; l < Length; ++l)
  64.                 {
  65.                 Display(l,-1,BorderColor,'\xB3');
  66.                 Display(l,Width,BorderColor,'\xB3');
  67.                 }
  68.  
  69.             break;
  70.  
  71.         case BT_DOUBLE :
  72.             Display(-1,-1,BorderColor,'\xC9');
  73.             Display(Length,-1,BorderColor,'\xC8');
  74.             Display(Length,Width,BorderColor,'\xBC');
  75.             Display(-1,Width,BorderColor,'\xBB');
  76.  
  77.             if (Header.Length() == 0)
  78.                 for (c = 0; c < Width; ++c)
  79.                     {
  80.                     Display(-1,c,BorderColor,'\xCD');
  81.                     Display(Length,c,BorderColor,'\xCD');
  82.                     }
  83.             else
  84.                 {
  85.                 hpos = 0;
  86.  
  87.                 for (c = 0; c < Width; ++c)
  88.                     {
  89.                     if (hpos < Header.Length())
  90.                         {
  91.                         Display(-1,c,BorderColor,Header[hpos]);
  92.                         ++hpos;
  93.                         }
  94.                     else
  95.                         Display(-1,c,BorderColor,'\xCD');
  96.  
  97.                     Display(Length,c,BorderColor,'\xCD');
  98.                     }
  99.                 }
  100.  
  101.             for (l = 0; l < Length; ++l)
  102.                 {
  103.                 Display(l,-1,BorderColor,'\xBA');
  104.                 Display(l,Width,BorderColor,'\xBA');
  105.                 }
  106.         }
  107.  
  108.     unsigned int pos;
  109.  
  110.     // display each character in buffer
  111.     for (l = 0; l < Length; ++l)
  112.         for (c = 0; c < Width; ++c)
  113.             {
  114.             pos = l * Width + c;
  115.             Display(l, c, BufferSW[pos].Attribute, BufferSW[pos].Symbol);
  116.             }
  117.  
  118.     // set the cursor position
  119.     SetCursor(CrsLine, CrsCol);
  120.     }
  121.  
  122. // paint one line
  123. void Window::PaintLine(unsigned int line)
  124.     {
  125.     if ((Concealed) || (line > Length))
  126.         return;
  127.  
  128.     unsigned int pos;
  129.  
  130.     // draw just one line of contents
  131.     for (unsigned int c = 0; c < Width; ++c)
  132.         {
  133.         pos = line * Width + c;
  134.         Display(line, c, BufferSW[pos].Attribute, BufferSW[pos].Symbol);
  135.         }
  136.     }
  137.  
  138. // store a character in the window
  139. void Window::PutChar(unsigned int line, unsigned int col,
  140.                      unsigned char attr, char ch)
  141.     {
  142.     if ((line >= Length) || (col >= Width))
  143.         return;
  144.  
  145.     unsigned int pos = line * Width + col;
  146.  
  147.     // store the character...
  148.     BufferSW[pos].Symbol = ch;
  149.  
  150.     // ... and its attribute
  151.     if (attr != 0)
  152.         BufferSW[pos].Attribute = attr;
  153.     else
  154.         BufferSW[pos].Attribute = InsideColor;
  155.     }
  156.  
  157. // store a string in the window
  158. void Window::PutStr(unsigned int line, unsigned int col,
  159.                     unsigned char attr, String & s)
  160.     {
  161.     if ((line >= Length) || (col >= Width))
  162.         return;
  163.  
  164.     if (attr == 0)
  165.         attr = InsideColor;
  166.  
  167.     unsigned char l = line;
  168.     unsigned char c = col;
  169.    
  170.     unsigned int spos = 0;
  171.     unsigned int wpos;
  172.  
  173.     // display text
  174.     while (s[spos] != '\x00')
  175.         {
  176.         wpos = l * Width + c;
  177.  
  178.         BufferSW[wpos].Symbol    = s[spos];
  179.         BufferSW[wpos].Attribute = attr;
  180.  
  181.         if (c == (Width - 1))
  182.             {
  183.             if (!Wrapped)
  184.                 return;
  185.  
  186.             if (l < Length)
  187.                 {
  188.                 c = 0;
  189.                 ++l;
  190.                 }
  191.             else
  192.                 return;
  193.             }
  194.         else
  195.             ++c;
  196.  
  197.         ++spos;
  198.         }
  199.     }
  200.