home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / df3os2.zip / SCREEN.CPP < prev    next >
C/C++ Source or Header  |  1993-11-13  |  4KB  |  159 lines

  1. // ----------- screen.cpp
  2. //
  3. // modified for OS/2 operation - jw21sep93
  4.  
  5. #include <string.h>
  6. #include "desktop.h"
  7.  
  8.  
  9. Screen::Screen()
  10.     {
  11.     // Get current display configuration
  12.  
  13.     mi.cb = sizeof(mi);
  14.     VioGetMode(&mi, 0);
  15.     width  = mi.col;
  16.     height = mi.row;
  17.     }
  18.  
  19.  
  20. // --------- scroll the screen d: 1 = up, 0 = dn
  21.  
  22. void Screen::Scroll(Rect &rc, int d, int fg, int bg)
  23.     {
  24.     char    cell[2];
  25.  
  26.     cell[0] = SPACECHAR;
  27.     cell[1] = clr(fg,bg);
  28.  
  29.     desktop.mouse().Hide();
  30.  
  31.     if (d == 1 )
  32.         {
  33.         VioScrollUp((USHORT)rc.Top(), 
  34.                     (USHORT)rc.Left(), 
  35.                     (USHORT)rc.Bottom(), 
  36.                     (USHORT)rc.Right(), 
  37.                     1, 
  38.                     (PBYTE16)&cell, 
  39.                     0);
  40.         }
  41.     else
  42.         {
  43.         VioScrollDn((USHORT)rc.Top(), 
  44.                     (USHORT)rc.Left(), 
  45.                     (USHORT)rc.Bottom(), 
  46.                     (USHORT)rc.Right(), 
  47.                     1, 
  48.                     (PBYTE16)&cell, 
  49.                     0);
  50.         }
  51.     desktop.mouse().Show();
  52.     }
  53.  
  54.  
  55. // -------- read a character of video memory
  56.  
  57. unsigned int Screen::GetVideoChar(int x, int y)
  58.     {
  59.     USHORT c;
  60.     USHORT cb = 2;
  61.  
  62.     desktop.mouse().Hide();
  63.     VioReadCellStr((char *) &c, &cb, (USHORT)y, (USHORT)x, 0);
  64.     desktop.mouse().Show();
  65.     return (unsigned int) c;
  66.     }
  67.  
  68.  
  69. // -------- write a character of video memory
  70. void Screen::PutVideoChar(int x, int y, unsigned int c)
  71.     {
  72.     if (x >= 0 && x < width && y >= 0 && y < height)    
  73.         {
  74.         desktop.mouse().Hide();
  75.         VioWrtCellStr((char *) &c, 2, (USHORT)y, (USHORT)x, 0);
  76.         desktop.mouse().Show();
  77.         }
  78.     }
  79.  
  80. // --------- Write a string to video memory
  81.  
  82. void Screen::WriteVideoString(const char *s, int x, int y, int fg, int bg)
  83.     {
  84.     if (x >= 0 && x < width && y >= 0 && y < height)
  85.         {
  86.         int   len = strlen(s);
  87.         char *ln  = new char[len*2];
  88.         char *cp1 = ln;
  89.  
  90.         unsigned char col = clr(fg,bg);
  91.  
  92.         while (*s)    
  93.             {
  94.             *cp1++ = (*s & 0xFF);
  95.             *cp1++ = col;
  96.             s++;
  97.             }
  98.         if (x + len >= width)
  99.             {
  100.             len = width - x;
  101.             }
  102.         desktop.mouse().Hide();
  103.         VioWrtCellStr(ln, (USHORT)(len*2), (USHORT)y, (USHORT)x, 0);
  104.         desktop.mouse().Show();
  105.         delete [] ln;
  106.         }
  107.     }
  108.  
  109.  
  110. // -- read a rectangle of video memory into a save buffer
  111. void Screen::GetBuffer(Rect &rc, char *bf)
  112.     {
  113.     if ((rc.Left() < width) && (rc.Top() < height))
  114.         {
  115.         int ht = rc.Bottom()-rc.Top()+1;
  116.         int row = rc.Top();
  117.         int cb =  (rc.Right()-rc.Left()+1) * 2;
  118.     
  119.         desktop.mouse().Hide();
  120.         while (ht--)    
  121.             {
  122.             VioReadCellStr(bf, 
  123.                            (USHORT *)&cb, 
  124.                            (USHORT)row, 
  125.                            (USHORT)rc.Left(), 
  126.                            0);
  127.  
  128.             bf = (char *)bf + cb;
  129.             row++;
  130.             }
  131.         desktop.mouse().Show();
  132.         }
  133.     }
  134.  
  135. // -- write a rectangle of video memory from a save buffer
  136. void Screen::PutBuffer(Rect &rc, char *bf)
  137.     {
  138.     if ((rc.Left() < width) && (rc.Top() < height))
  139.         {
  140.         int ht  = rc.Bottom()-rc.Top()+1;
  141.         int cb  = (rc.Right()-rc.Left()+1) * 2;
  142.         int row = rc.Top();
  143.         
  144.         desktop.mouse().Hide();
  145.         while (ht--)    
  146.             {
  147.             VioWrtCellStr(bf, 
  148.                           (USHORT)cb, 
  149.                           (USHORT)row, 
  150.                           (USHORT)rc.Left(), 
  151.                           0);
  152.             bf += cb;
  153.             row++;
  154.             }
  155.         desktop.mouse().Show();
  156.         }
  157.     }
  158.  
  159.