home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / stencil.cxx < prev    next >
C/C++ Source or Header  |  1995-04-04  |  2KB  |  83 lines

  1.  
  2. #if defined(__GNUC__)
  3. #pragma implementation
  4. #endif
  5.  
  6.  
  7.  
  8. #include "base/defs.h"
  9. #include "ui/uidefs.h"
  10. #include "ui/stencil.h"
  11.  
  12.  
  13. UI_Stencil::UI_Stencil (short w, short h)
  14. {
  15.     _width  = maxl (w, 1);
  16.     _height = maxl (h, 1);
  17.     _data   = new char [w * h];
  18. }
  19.  
  20.  
  21. UI_Stencil::UI_Stencil (const char data[], short w, short h)
  22. {
  23.     long size = w * h;
  24.     _width  = maxl (w, 1);
  25.     _height = maxl (h, 1);
  26.     _data   = new char [w * h];
  27.     if (!_data)
  28.         return;
  29.     for (long i = 0; i < size; i++)
  30.         _data[i] = data[i];
  31. }
  32.  
  33. UI_Stencil::UI_Stencil (const UI_Stencil& s)
  34. {
  35.     short w   = s._width;
  36.     short h   = s._height;
  37.     long size = w * h;
  38.     _width  = maxl (w, 1);
  39.     _height = maxl (h, 1);
  40.     _data   = new char [w * h];
  41.     if (!_data)
  42.         return;
  43.     for (long i = 0; i < size; i++)
  44.         _data[i] = s._data[i];
  45. }
  46.  
  47.  
  48. UI_Stencil::~UI_Stencil ()
  49. {
  50.     delete [] _data;
  51. }
  52.  
  53.  
  54. char& UI_Stencil::Byte (short i, short j)
  55. {
  56.     static char c;
  57.     if (!_data)
  58.         return c; // No memory
  59.     if (i >= 0 && i < _height && j >= 0 && j < _width)
  60.         return _data[i * _width + j];
  61.     CL_Error::Warning ("UI_Stencil::Byte : indexes (%d %d) out of "
  62.                        "range (%d %d)", i, j, _width-1, _height-1);
  63.     return c;
  64. }
  65.  
  66.  
  67.  
  68. short UI_Stencil::Bit  (short i, short j) const
  69. {
  70.     if (!_data)
  71.         return 0; // No memory
  72.     if (i >= 0 && i < _height && j >= 0 && j < _width*8) {
  73.         long index = i * _width + (j/8);
  74.         return (_data[index] & (0x0080 >> (j % 8))) ? 1 : 0;
  75.     }
  76.     CL_Error::Warning ("UI_Stencil::Bit : indexes (%d %d) out of "
  77.                        "range (%d %d)", i, j, 8*_width-1, _height-1);
  78.     return 0;
  79. }
  80.  
  81.  
  82.  
  83.