home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dokpr1.zip / color.h < prev    next >
C/C++ Source or Header  |  1995-08-07  |  5KB  |  122 lines

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *                                                                        *
  4.  *          This code is copyright (c) 1994                               *
  5.  *                     Athena Design, Inc.                                *
  6.  *                                                                        *
  7.  *                                                                        *
  8.  *                ALL RIGHTS RESERVED                                     *
  9.  *                                                                        *
  10.  *                                                                        *
  11.  *                                                                        *
  12.  *                                                                        *
  13.  *                                                                        *
  14.  **************************************************************************/
  15.  
  16. // dpr was here
  17. /*
  18.     this is the header file for the color model on Mesa.
  19.     Each color consists of two integers.  The first is of the format:
  20.     (16777216 * pat) + (r * 65536) + (g * 256) + b
  21.     if pat != 0, then pat specifies the pattern that is overlayed on the
  22.     color represented in the second it.  If that color has a pattern of
  23.     255, then it is assumed to be clear.
  24.  
  25.     2-27-94 dpp
  26.  
  27.     94-09-04 dpp changed MColor so that it does not have a constructor, but has
  28.         init() and free() methods
  29. */
  30.  
  31. #ifndef _MH_color
  32.  
  33. #define _MH_color
  34.  
  35. class MStream;
  36.  
  37. class MColor {
  38.     public:
  39.     void init(int t) {pCol = t; bkgCol = 0;};
  40.     void init(const MColor *cp) {pCol = cp -> pCol; bkgCol = cp -> bkgCol;};
  41.     void free() {};
  42.     void init() {};
  43.     void set(int t) {pCol = t; bkgCol = 0;};
  44.     void set(MColor c) {*this = c;};
  45.     void set(const MColor *cp) {*this = *cp;};
  46.     void set(int r,int g,int b) {pCol = r * 65536 + g * 256 + b; bkgCol = 0;};
  47.     unsigned int getRed() { return ( ( pCol & 0xFF0000 )/65536 ); }
  48.     unsigned int getGreen()    { return ( ( pCol & 0x00FF00 )/256 ); }
  49.     unsigned int getBlue()    { return ( pCol & 0x0000FF ); }
  50.  
  51.     unsigned int getBkgRed() { return ( ( bkgCol & 0xFF0000 )/65536 ); }
  52.     unsigned int getBkgGreen()    { return ( ( bkgCol & 0x00FF00 )/256 ); }
  53.     unsigned int getBkgBlue()    { return ( bkgCol & 0x0000FF ); }
  54.     // set a color to a named color string
  55.     int set(const char *);
  56.  
  57.     int getRGB() {return pCol & 0xffffff;};
  58.     int getColor() {return pCol;};
  59.     int getPattern() {return pCol >> 24;};
  60.     int getBkgRGB() {return bkgCol & 0xffffff;};
  61.     int getBkgPattern() {return bkgCol >> 24;};
  62.     int operator==(const MColor &c) const
  63.         {if (pCol == c.pCol && bkgCol == c.bkgCol) return 1; else return 0;};
  64.     int operator!=(const MColor &c) const
  65.         {if (pCol != c.pCol || bkgCol != c.bkgCol) return 1; else return 0;};
  66.  
  67.     int operator>(const MColor &c) const
  68.         {if (pCol > c.pCol || (pCol == c.pCol && bkgCol > c.bkgCol)) return 1; else return 0;};
  69.     int operator>=(const MColor &c) const
  70.         {if (pCol > c.pCol || (pCol == c.pCol && bkgCol >= c.bkgCol)) return 1; else return 0;};
  71.     int operator<(const MColor &c) const
  72.         {if (pCol < c.pCol || (pCol == c.pCol && bkgCol < c.bkgCol)) return 1; else return 0;};
  73.     int operator<=(const MColor &c) const
  74.         {if (pCol < c.pCol || (pCol == c.pCol && bkgCol <= c.bkgCol)) return 1; else return 0;};
  75.  
  76.     void read(MStream *);
  77.     void write(MStream *) const;
  78.  
  79.     // average between the solid portion of the two colors
  80.     void average(MColor);
  81.  
  82.     void init(MStream *sp) {read(sp);};
  83.  
  84.     // locate an index into a palette, or return the closest match...
  85.     int getColorFromPalette( MColor *palette, int numInPalette );
  86.     
  87.     private:
  88.     unsigned int pCol,bkgCol;
  89. };
  90.  
  91. const int MCOL_LTGRAY = 0x00cccccc;
  92. const int MCOL_DKGRAY = 0x00555555;
  93. const int MCOL_GRAY   = 0x00808080;
  94. const int MCOL_BLACK = 0;
  95. const int MCOL_WHITE = 0xffffff;
  96. const int MCOL_RED = 0x00ff0000;
  97. const int MCOL_GREEN = 0x0000ff00;
  98. const int MCOL_BLUE = 0xff;
  99. const int MCOL_CYAN = (MCOL_GREEN | MCOL_BLUE);
  100. const int MCOL_YELLOW = (MCOL_RED | MCOL_GREEN);
  101. const int MCOL_MAGENTA = (MCOL_RED | MCOL_BLUE);
  102.  
  103. #ifdef M2Z
  104. #define MCOL_3D_LIGHT  WinQuerySysColor(HWND_DESKTOP,SYSCLR_BUTTONLIGHT,0)
  105. #define MCOL_3D_DARK  WinQuerySysColor(HWND_DESKTOP,SYSCLR_BUTTONDARK,0)
  106. #define MCOL_BUTTONFACE WinQuerySysColor(HWND_DESKTOP,SYSCLR_BUTTONMIDDLE,0)
  107. #define MCOL_DIALOGBACK WinQuerySysColor(HWND_DESKTOP,SYSCLR_DIALOGBACKGROUND,0)
  108. #define MCOL_BUTTONTEXT WinQuerySysColor(HWND_DESKTOP,SYSCLR_MENUTEXT,0)
  109.  
  110. #else
  111. //FIXMEMAC
  112. //FIXMENT
  113. #define MCOL_3D_LIGHT MCOL_WHITE
  114. #define MCOL_3D_DARK  MCOL_DKGRAY
  115. #define MCOL_BUTTONFACE MCOL_LTGRAY
  116. #define MCOL_DIALOGBACK MCOL_LTGRAY
  117. #define MCOL_BUTTONTEXT MCOL_BLACK
  118. #endif
  119.  
  120. // ifndef _MH_color
  121. #endif
  122.