home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 19.ddi / OWLINC.PAK / COLOR.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  3.9 KB  |  127 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1992, 1993 by Borland International
  3. //   include\owl\color.h
  4. //   Definition of color classes
  5. //----------------------------------------------------------------------------
  6. #if !defined(__OWL_COLOR_H)
  7. #define __OWL_COLOR_H
  8.  
  9. #if !defined(__OWL_OWLDEFS_H)
  10.   #include <owl\owldefs.h>
  11. #endif
  12.  
  13. long _OWLFUNC NColors(WORD bitCount);
  14. WORD _OWLFUNC NBits(long colors);
  15.  
  16. #define OWLRGB(r,g,b)\
  17.  ((COLORREF)(((BYTE)(WORD)(r)|((WORD)(g)<<8))|(((DWORD)(BYTE)(WORD)(b))<<16)))
  18.  
  19. class _OWLCLASS TColor {
  20.   public:
  21.     TColor() : Value(0) {}
  22.     TColor(COLORREF value) : Value(value) {}
  23.     TColor(long value) : Value((COLORREF)value) {}
  24.     TColor(int r, int g, int b) : Value(OWLRGB(r,g,b)) {}
  25.     TColor(int r, int g, int b, int f) : Value(((DWORD)f<<24) | OWLRGB(r,g,b)) {}
  26.     TColor(int index) : Value(PALETTEINDEX(index)) {}
  27.     TColor(const PALETTEENTRY far& pe) : Value(OWLRGB(pe.peRed,pe.peGreen,pe.peBlue)) {}
  28.     TColor(const RGBQUAD far& q) : Value(OWLRGB(q.rgbRed,q.rgbGreen,q.rgbBlue)) {}
  29.     TColor(const RGBTRIPLE far& t) : Value(OWLRGB(t.rgbtRed,t.rgbtGreen,t.rgbtBlue)) {}
  30.  
  31.     // Type Conversion Operators
  32.     operator      COLORREF() const {return Value;}
  33.  
  34.     BOOL operator ==(const TColor& clrVal) const {return Value==clrVal;}
  35.  
  36.     int           Index() const {return (int)Value & 0xFFFF;}
  37.     TColor        Rgb() const {return Value & 0x00FFFFFFUL;}
  38.     TColor        PalIndex() const {return (COLORREF)Index() | 0x01000000UL;}
  39.     TColor        PalRelative() const {return Rgb() | 0x02000000UL;}
  40.  
  41.     BYTE          Red() const {return (BYTE)(WORD)Value;}
  42.     BYTE          Green() const {return ((BYTE)(WORD)(((WORD)Value) >> 8));}
  43.     BYTE          Blue() const {return ((BYTE)(WORD)(Value>>16));}
  44.     BYTE          Flags() const {return (BYTE)(WORD)(Value>>24);}
  45.  
  46.     static const TColor  Black;
  47.     static const TColor  LtGray;
  48.     static const TColor  Gray;
  49.     static const TColor  LtRed;
  50.     static const TColor  LtGreen;
  51.     static const TColor  LtYellow;
  52.     static const TColor  LtBlue;
  53.     static const TColor  LtMagenta;
  54.     static const TColor  LtCyan;
  55.     static const TColor  White;
  56.  
  57.   protected:
  58.     COLORREF    Value;          // the color value type (not a struct)
  59. };
  60.  
  61. class TPaletteEntry : public tagPALETTEENTRY {
  62.   public:
  63.     TPaletteEntry(int r, int g, int b, int f = 0);
  64.     TPaletteEntry(TColor c);
  65. };
  66.  
  67. class TRgbQuad : public tagRGBQUAD {
  68.   public:
  69.     TRgbQuad(int r, int g, int b);
  70.     TRgbQuad(TColor c);
  71.     TRgbQuad(const RGBQUAD far& q) {*(RGBQUAD*)this = q;}
  72. };
  73.  
  74. class TRgbTriple : public tagRGBTRIPLE {
  75.   public:
  76.     TRgbTriple(int r, int g, int b);
  77.     TRgbTriple(TColor c);
  78.     TRgbTriple(const RGBTRIPLE far& t) {*(RGBTRIPLE*)this = t;}
  79. };
  80.  
  81.  
  82. //----------------------------------------------------------------------------
  83. // Inlines
  84. //----------------------------------------------------------------------------
  85.  
  86. inline TPaletteEntry::TPaletteEntry(int r, int g, int b, int f) {
  87.   peRed = (BYTE)(WORD)r;
  88.   peGreen = (BYTE)(WORD)g;
  89.   peBlue = (BYTE)(WORD)b;
  90.   peFlags = (BYTE)(WORD)f;
  91. }
  92.  
  93. inline TPaletteEntry::TPaletteEntry(TColor c) {
  94.   peRed = c.Red();
  95.   peGreen = c.Green();
  96.   peBlue = c.Blue();
  97.   peFlags = c.Flags();
  98. }
  99.  
  100. inline TRgbQuad::TRgbQuad(int r, int g, int b) {
  101.   rgbRed = (BYTE)(WORD)r;
  102.   rgbGreen = (BYTE)(WORD)g;
  103.   rgbBlue = (BYTE)(WORD)b;
  104.   rgbReserved = 0;
  105. }
  106.  
  107. inline TRgbQuad::TRgbQuad(TColor c) {
  108.   rgbRed = c.Red();
  109.   rgbGreen = c.Green();
  110.   rgbBlue = c.Blue();
  111.   rgbReserved = 0;
  112. }
  113.  
  114. inline TRgbTriple::TRgbTriple(int r, int g, int b) {
  115.   rgbtRed = (BYTE)(WORD)r;
  116.   rgbtGreen = (BYTE)(WORD)g;
  117.   rgbtBlue = (BYTE)(WORD)b;
  118. }
  119.  
  120. inline TRgbTriple::TRgbTriple(TColor c) {
  121.   rgbtRed = c.Red();
  122.   rgbtGreen = c.Green();
  123.   rgbtBlue = c.Blue();
  124. }
  125.  
  126. #endif  // __OWL_COLOR_H
  127.