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

  1.  
  2. #ifndef _color_h_
  3. #define _color_h_
  4.  
  5.  
  6.  
  7.  
  8.  
  9. /*
  10.  *
  11.  *          Copyright (C) 1994, M. A. Sridhar
  12.  *  
  13.  *
  14.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  15.  *     to copy, modify or distribute this software  as you see fit,
  16.  *     and to use  it  for  any  purpose, provided   this copyright
  17.  *     notice and the following   disclaimer are included  with all
  18.  *     copies.
  19.  *
  20.  *                        DISCLAIMER
  21.  *
  22.  *     The author makes no warranties, either expressed or implied,
  23.  *     with respect  to  this  software, its  quality, performance,
  24.  *     merchantability, or fitness for any particular purpose. This
  25.  *     software is distributed  AS IS.  The  user of this  software
  26.  *     assumes all risks  as to its quality  and performance. In no
  27.  *     event shall the author be liable for any direct, indirect or
  28.  *     consequential damages, even if the  author has been  advised
  29.  *     as to the possibility of such damages.
  30.  *
  31.  */
  32.  
  33.  
  34.  
  35. // Authors:   M. A. Sridhar
  36. //            N. Bhowmik
  37. // Modified:  R. Sampath
  38.  
  39.  
  40. // This encapsulates all platform dependent details of the resource
  41. // Color while providing sufficient functionality to initialize and
  42. // modify colors in a platform independent manner.
  43. // This being a very platform dependent feature, some alternative
  44. // methods that are platform specific are also provided.
  45.  
  46.  
  47. #if defined(__GNUC__)
  48. #pragma interface
  49. #endif
  50.  
  51.  
  52. #include "base/object.h"
  53.  
  54. enum UI_ColorScheme {
  55.     UIColor_Black, UIColor_Green, UIColor_Blue,
  56.     UIColor_Red,   UIColor_White, UIColor_MediumGray
  57. };
  58.  
  59.  
  60. // Native platform's representation of color: a COLORREF under MS/Windows,
  61. // and an XColor under X Windows.
  62.  
  63. #if defined (__MS_WINDOWS__)
  64. #include <windows.h>
  65. #define UI_MAXCOLORS  255
  66.  
  67. typedef COLORREF UI_NativeColorRep;
  68.  
  69. #elif defined (__OS2__)
  70. #define UI_MAXCOLORS 255
  71. typedef long     UI_NativeColorRep;
  72.  
  73. #elif defined (__X_MOTIF__)
  74. #include <X11/Xlib.h>
  75. #define  UI_MAXCOLORS 65535
  76.  
  77. typedef XColor UI_NativeColorRep;
  78. #endif
  79.  
  80.  
  81. class CL_EXPORT UI_Color: public CL_Object {
  82.  
  83. public:
  84.     UI_Color ();
  85.     // Default constuctor: construct a black color.
  86.  
  87.     UI_Color (UI_ColorScheme c);
  88.     // Construct the color defined by the given ColorScheme.
  89.  
  90.     UI_Color (double red, double green, double blue);
  91.     // All parameters should be between 0 and 1. This constructor is
  92.     // platform-independent. All  three zeros corresponds to black, and all
  93.     // 1's to white.
  94.     
  95.     UI_Color (const UI_Color&);
  96.     // Copy constructor.
  97.  
  98.     ~UI_Color () {};
  99.     
  100.     void Red (double red);
  101.     // Set the red intensity of this color. The least amount of red is 0,
  102.     // and the highest is 255.
  103.  
  104.     double Red() const;
  105.  
  106.     void Green (double green) ;
  107.     // Set the green intensity of this color. The least amount of green is 0,
  108.     // and the highest is 255.
  109.  
  110.     double Green() const;
  111.  
  112.     void Blue (double blue) ;
  113.     // Set the blue intensity of this color. The least amount of blue is 0,
  114.     // and the highest is 255.
  115.  
  116.     double Blue() const;
  117.  
  118.     void Set (UI_ColorScheme c);
  119.  
  120.     UI_NativeColorRep& NativeForm () const;
  121.     // However, the following platform specific method may be used 
  122.     // in lieu of the above 
  123.     // [For YACL internal use only.]
  124.  
  125.     
  126.     bool operator==  (const UI_Color& x) const;
  127.  
  128.     bool operator==  (const CL_Object& x) const
  129.         {return *this == ( (const UI_Color &) x); };
  130.  
  131.     void operator=   (const CL_Object& x)
  132.         {*this = ((const UI_Color&) x);};
  133.  
  134.     void operator= (const UI_Color& color);
  135.  
  136.     const char* ClassName () const { return "UI_Color";};
  137.  
  138. protected:
  139.  
  140.          
  141.     UI_NativeColorRep getColorVal (double, double, double);//convenience func
  142.  
  143.     UI_NativeColorRep getAbsVal (UI_ColorScheme);       //convenience func
  144.  
  145.     double _red, _blue, _green;
  146.  
  147.     UI_NativeColorRep _colorVal;
  148.  
  149. };
  150.  
  151. inline double UI_Color::Red() const
  152. {
  153.     return _red;
  154. }
  155.  
  156.  
  157. inline double UI_Color::Green() const
  158. {
  159.     return _green;
  160. }
  161.  
  162.  
  163.  
  164. inline double UI_Color::Blue() const
  165. {
  166.     return _blue;
  167. }
  168.  
  169.  
  170. #endif
  171.