home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OWLINC.PAK / COLOR.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  4KB  |  127 lines

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