home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / tvme30.zip / MAPCOLOR.CPP < prev    next >
C/C++ Source or Header  |  1995-08-02  |  2KB  |  62 lines

  1. // File    : MAPCOLOR.CPP
  2. // Author  : Eric Woodruff,  CIS ID: 72134,1150
  3. // Updated : Mon 03/13/95 11:18:38
  4. // Note    : Hereby declared public domain
  5. // Compiler: Borland C++ 3.1 to 4.xx
  6. //
  7. // NOTICE:
  8. // All Borland International copyrights remain in effect as this is
  9. // only a replacement function and an extension to the normal Turbo Vision
  10. // code.  I make no claim of ownership or copyright to this code.
  11. // Although the basic concept is derived from Turbo Vision's mapColor(),
  12. // this code is entirely of my own creation.
  13. //
  14.  
  15. #define Uses_TView
  16. #define Uses_TGroup
  17. #define Uses_TVCOLR     // Get size of default palette (cpDefSize).
  18. #include <tv.h>
  19.  
  20. #if !defined(cpDefSize)
  21. // Use this if you choose not to modify the Turbo Vision files.
  22. #include <tvcolr.h>
  23. #endif
  24.  
  25. // ****************************************************************************
  26. // Provide proper mapping for the extended colors.  If an extended color is
  27. // referenced, the attribute is retrieved directly from the main application
  28. // palette instead of mapping it onto any subsequent owning views.
  29. uchar TView::mapColor(uchar color)
  30. {
  31.     TPalette *p;
  32.     TView *cur;
  33.  
  34.     for(cur = this; cur ; cur = cur->owner)
  35.     {
  36.         p = &cur->getPalette();
  37.         if(p->data[0])
  38.         {
  39.             // It's an error to try and exceed the palette length.
  40.             if(color > p->data[0])
  41.                 return errorAttr;         // Mistake. Return error color.
  42.  
  43.             if(p->data[color] > cpDefSize && cur->owner)
  44.             {
  45.                 color = p->data[color];    // Get index.
  46.  
  47.                 while(cur->owner)          // Move to base palette.
  48.                     cur = cur->owner;
  49.  
  50.                 // Retrieve color from base application palette.
  51.                 p = &cur->getPalette();
  52.                 color = p->data[color];
  53.                 break;
  54.             }
  55.  
  56.             color = p->data[color];    // Map onto owner.
  57.         }
  58.     }
  59.  
  60.     return color;
  61. }
  62.