]> icculus.org git repositories - mikachu/openbox.git/blob - otk/rendertexture.hh
import config
[mikachu/openbox.git] / otk / rendertexture.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __rendertexture_hh
3 #define __rendertexture_hh
4
5 #include "rendercolor.hh"
6
7 namespace otk {
8
9 //! Superclass for all the Textures
10 class RenderTexture {
11 public:
12   enum ReliefType {
13     Flat,
14     Raised,
15     Sunken
16   };
17   enum BevelType {
18     Bevel1,
19     Bevel2
20   };
21   enum GradientType {
22     Solid,
23     Horizontal,
24     Vertical,
25     Diagonal,
26     CrossDiagonal,
27     PipeCross,
28     Rectangle,
29     Pyramid,
30     Elliptic
31   };
32
33 private:
34   int _screen;
35   
36   //! If true, the texture is not rendered at all, so all options are ignored
37   bool _parent_relative;
38   //! The relief type of the texture
39   ReliefType _relief;
40   //! The way the bevel should be drawn
41   BevelType _bevel;
42   //! If a flat border is drawn on the outside, ignored for all ReliefType
43   //! values except ReliefType::Flat
44   bool _border;
45   //! The type of gradient to fill the texture with (if any)
46   GradientType _gradient;
47   //! If interlace lines should be drawn over the texture
48   bool _interlaced;
49
50   //! The base color for the texture, the only color when the texture is solid.
51   //! This must always be defined
52   const RenderColor *_color;
53   //! The secondary color for a gradient texture.
54   //! This is only defined for gradients
55   const RenderColor *_secondary_color;
56   //! The shadow color for the bevel. This must be defined if
57   //! RenderTexture::_relief is not RenderTexture::ReliefType::Flat
58   const RenderColor *_bevel_dark_color;
59   //! The light color for the bevel. This must be defined if
60   //! RenderTexture::_relief is not RenderTexture::ReliefType::Flat
61   const RenderColor *_bevel_light_color;
62   //! The color for the flat border if RenderTexture::_border is true. This
63   //! must be defined if it is true
64   const RenderColor *_border_color;
65   //! The color for the interlace lines if RenderTexture. This must be defined
66   //! if it is true
67   const RenderColor *_interlace_color;
68
69 public:
70   RenderTexture(int screen,
71                 bool parent_relative, ReliefType relief, BevelType bevel,
72                 bool border, GradientType gradient, bool interlaced,
73                 const RGB &color,
74                 const RGB &secondary_color,
75                 const RGB &border_color,
76                 const RGB &interlace_color)
77     : _screen(screen),
78       _parent_relative(parent_relative),
79       _relief(relief),
80       _bevel(bevel),
81       _border(border),
82       _gradient(gradient),
83       _interlaced(interlaced),
84       _color(new RenderColor(screen, color)),
85       _secondary_color(new RenderColor(screen, secondary_color)),
86       _bevel_dark_color(0),
87       _bevel_light_color(0),
88       _border_color(new RenderColor(screen, border_color)),
89       _interlace_color(new RenderColor(screen, interlace_color))
90   {
91     if (_relief != Flat) {
92       unsigned char r, g, b;
93
94       // calculate the light bevel color
95       r = _color->red() + _color->red() / 2;
96       g = _color->green() + _color->green() / 2;
97       b = _color->blue() + _color->blue() / 2;
98       // watch for wraparound
99       if (r < _color->red()) r = 0xff;
100       if (g < _color->green()) g = 0xff;
101       if (b < _color->blue()) b = 0xff;
102       _bevel_dark_color = new RenderColor(screen, r, g, b);
103       
104       // calculate the dark bevel color
105       r = _color->red() / 4 + _color->red() / 2;
106       g = _color->green() / 4 + _color->green() / 2;
107       b = _color->blue() / 4 + _color->blue() / 2;
108       _bevel_light_color = new RenderColor(screen, r, g, b);
109     }
110     
111     assert(_relief == Flat || (_bevel_dark_color && _bevel_light_color));
112     //assert(!_border || _border_color);
113     //assert(!_interlaced || _interlace_color);
114     assert(_color);
115     assert(_secondary_color);
116     assert(_border_color);
117     assert(_interlace_color);
118   }
119   
120   virtual ~RenderTexture() {
121     delete _color;
122     delete _secondary_color;
123     if (_bevel_dark_color) delete _bevel_dark_color;
124     if (_bevel_dark_color) delete _bevel_light_color;
125     delete _border_color;
126     delete _interlace_color;
127   }
128
129   //! If true, the texture is not rendered at all, so all options are ignored
130   inline bool parentRelative() const { return _parent_relative; }
131   //! The relief type of the texture
132   inline ReliefType relief() const { return _relief; }
133   //! The way the bevel should be drawn
134   inline BevelType bevel() const { return _bevel; }
135   //! If a flat border is drawn on the outside, ignored for all ReliefType
136   //! values except ReliefType::Flat
137   inline bool border() const { return _border; }
138   //! The type of gradient to fill the texture with (if any)
139   inline GradientType gradient() const { return _gradient; }
140   //! If interlace lines should be drawn over the texture
141   inline bool interlaced() const { return _interlaced; }
142
143   //! The base color for the texture, the only color when the texture is solid.
144   //! This must always be defined
145   inline const RenderColor& color() const { return *_color; }
146   //! The secondary color for gradient textures.
147   //! This is only defined for gradients
148   inline const RenderColor& secondary_color() const
149     { return *_secondary_color; }
150   //! The shadow color for the bevel. This must be defined if
151   //! RenderTexture::_relief is not RenderTexture::ReliefType::Flat
152   inline const RenderColor& bevelDarkColor() const
153     { return *_bevel_dark_color; }
154   //! The light color for the bevel. This must be defined if
155   //! RenderTexture::)relief is not RenderTexture::ReliefType::Flat
156   inline const RenderColor& bevelLightColor() const
157     { return *_bevel_light_color; }
158   //! The color for the flat border if RenderTexture::_border is true. This
159   //! must be defined if it is true
160   inline const RenderColor& borderColor() const { return *_border_color; }
161   //! The color for the interlace lines if RenderTexture. This must be defined
162   //! if it is true
163   inline const RenderColor& interlaceColor() const
164     { return *_interlace_color; }
165 };
166
167 }
168
169 #endif // __rendertexture_hh