Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

/otk/rendertexture.hh

Go to the documentation of this file.
00001 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
00002 #ifndef __rendertexture_hh
00003 #define __rendertexture_hh
00004 
00005 #include "rendercolor.hh"
00006 
00007 namespace otk {
00008 
00009 //! Superclass for all the Textures
00010 class RenderTexture {
00011 public:
00012   enum ReliefType {
00013     Flat,
00014     Raised,
00015     Sunken
00016   };
00017   enum BevelType {
00018     Bevel1,
00019     Bevel2
00020   };
00021   enum GradientType {
00022     Solid,
00023     Horizontal,
00024     Vertical,
00025     Diagonal,
00026     CrossDiagonal,
00027     PipeCross,
00028     Rectangle,
00029     Pyramid,
00030     Elliptic
00031   };
00032 
00033 private:
00034   int _screen;
00035   
00036   //! If true, the texture is not rendered at all, so all options are ignored
00037   bool _parent_relative;
00038   //! The relief type of the texture
00039   ReliefType _relief;
00040   //! The way the bevel should be drawn
00041   BevelType _bevel;
00042   //! If a flat border is drawn on the outside, ignored for all ReliefType
00043   //! values except ReliefType::Flat
00044   bool _border;
00045   //! The type of gradient to fill the texture with (if any)
00046   GradientType _gradient;
00047   //! If interlace lines should be drawn over the texture
00048   bool _interlaced;
00049 
00050   //! The base color for the texture, the only color when the texture is solid.
00051   //! This must always be defined
00052   const RenderColor *_color;
00053   //! The secondary color for a gradient texture.
00054   //! This is only defined for gradients
00055   const RenderColor *_secondary_color;
00056   //! The shadow color for the bevel. This must be defined if
00057   //! RenderTexture::_relief is not RenderTexture::ReliefType::Flat
00058   const RenderColor *_bevel_dark_color;
00059   //! The light color for the bevel. This must be defined if
00060   //! RenderTexture::_relief is not RenderTexture::ReliefType::Flat
00061   const RenderColor *_bevel_light_color;
00062   //! The color for the flat border if RenderTexture::_border is true. This
00063   //! must be defined if it is true
00064   const RenderColor *_border_color;
00065   //! The color for the interlace lines if RenderTexture. This must be defined
00066   //! if it is true
00067   const RenderColor *_interlace_color;
00068 
00069 public:
00070   RenderTexture(int screen,
00071                 bool parent_relative, ReliefType relief, BevelType bevel,
00072                 bool border, GradientType gradient, bool interlaced,
00073                 const RGB &color,
00074                 const RGB &secondary_color,
00075                 const RGB &border_color,
00076                 const RGB &interlace_color)
00077     : _screen(screen),
00078       _parent_relative(parent_relative),
00079       _relief(relief),
00080       _bevel(bevel),
00081       _border(border),
00082       _gradient(gradient),
00083       _interlaced(interlaced),
00084       _color(new RenderColor(screen, color)),
00085       _secondary_color(new RenderColor(screen, secondary_color)),
00086       _bevel_dark_color(0),
00087       _bevel_light_color(0),
00088       _border_color(new RenderColor(screen, border_color)),
00089       _interlace_color(new RenderColor(screen, interlace_color))
00090   {
00091     if (_relief != Flat) {
00092       unsigned char r, g, b;
00093 
00094       // calculate the light bevel color
00095       r = _color->red() + _color->red() / 2;
00096       g = _color->green() + _color->green() / 2;
00097       b = _color->blue() + _color->blue() / 2;
00098       // watch for wraparound
00099       if (r < _color->red()) r = 0xff;
00100       if (g < _color->green()) g = 0xff;
00101       if (b < _color->blue()) b = 0xff;
00102       _bevel_dark_color = new RenderColor(screen, r, g, b);
00103       
00104       // calculate the dark bevel color
00105       r = _color->red() / 4 + _color->red() / 2;
00106       g = _color->green() / 4 + _color->green() / 2;
00107       b = _color->blue() / 4 + _color->blue() / 2;
00108       _bevel_light_color = new RenderColor(screen, r, g, b);
00109     }
00110     
00111     assert(_relief == Flat || (_bevel_dark_color && _bevel_light_color));
00112     //assert(!_border || _border_color);
00113     //assert(!_interlaced || _interlace_color);
00114     assert(_color);
00115     assert(_secondary_color);
00116     assert(_border_color);
00117     assert(_interlace_color);
00118   }
00119   
00120   virtual ~RenderTexture() {
00121     delete _color;
00122     delete _secondary_color;
00123     if (_bevel_dark_color) delete _bevel_dark_color;
00124     if (_bevel_dark_color) delete _bevel_light_color;
00125     delete _border_color;
00126     delete _interlace_color;
00127   }
00128 
00129   //! If true, the texture is not rendered at all, so all options are ignored
00130   inline bool parentRelative() const { return _parent_relative; }
00131   //! The relief type of the texture
00132   inline ReliefType relief() const { return _relief; }
00133   //! The way the bevel should be drawn
00134   inline BevelType bevel() const { return _bevel; }
00135   //! If a flat border is drawn on the outside, ignored for all ReliefType
00136   //! values except ReliefType::Flat
00137   inline bool border() const { return _border; }
00138   //! The type of gradient to fill the texture with (if any)
00139   inline GradientType gradient() const { return _gradient; }
00140   //! If interlace lines should be drawn over the texture
00141   inline bool interlaced() const { return _interlaced; }
00142 
00143   //! The base color for the texture, the only color when the texture is solid.
00144   //! This must always be defined
00145   inline const RenderColor& color() const { return *_color; }
00146   //! The secondary color for gradient textures.
00147   //! This is only defined for gradients
00148   inline const RenderColor& secondary_color() const
00149     { return *_secondary_color; }
00150   //! The shadow color for the bevel. This must be defined if
00151   //! RenderTexture::_relief is not RenderTexture::ReliefType::Flat
00152   inline const RenderColor& bevelDarkColor() const
00153     { return *_bevel_dark_color; }
00154   //! The light color for the bevel. This must be defined if
00155   //! RenderTexture::)relief is not RenderTexture::ReliefType::Flat
00156   inline const RenderColor& bevelLightColor() const
00157     { return *_bevel_light_color; }
00158   //! The color for the flat border if RenderTexture::_border is true. This
00159   //! must be defined if it is true
00160   inline const RenderColor& borderColor() const { return *_border_color; }
00161   //! The color for the interlace lines if RenderTexture. This must be defined
00162   //! if it is true
00163   inline const RenderColor& interlaceColor() const
00164     { return *_interlace_color; }
00165 };
00166 
00167 }
00168 
00169 #endif // __rendertexture_hh

Generated on Tue Feb 4 22:58:56 2003 for Openbox by doxygen1.3-rc2