1 // Transparent.hh for FbTk - Fluxbox Toolkit
2 // Copyright (c) 2003 Henrik Kinnunen (fluxgen at fluxbox dot org)
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21 
22 // $Id: Transparent.hh 3932 2005-04-10 18:18:14Z simonb $
23 
24 #ifndef FBTK_TRANSPARENT_HH
25 #define FBTK_TRANSPARENT_HH
26 
27 #include <X11/Xlib.h>
28 
29 namespace FbTk {
30 
31 /// renders to drawable together with an alpha mask
32 class Transparent {
33 public:
34     Transparent(Drawable source, Drawable dest, unsigned char alpha, int screen_num);
35     ~Transparent();
36     /// sets alpha value
37     void setAlpha(unsigned char alpha);
38     /// sets source drawable
39     void setSource(Drawable src, int screen_num);
40     /// sets destination drawable
41     void setDest(Drawable dest, int screen_num);
42     void freeDest();
43     /**
44        renders to dest from src with specified coordinates and size
45     */
46     void render(int src_x, int src_y,
47                 int dest_x, int dest_y,
48                 unsigned int width, unsigned int height) const;
49 
alpha() const50     unsigned char alpha() const { return m_alpha; }
dest() const51     Drawable dest() const { return m_dest; }
source() const52     Drawable source() const { return m_source; }
53 
54     static bool haveComposite(bool for_real = false);
haveRender()55     static bool haveRender() { if (!s_init) init(); return s_render; }
56     static void usePseudoTransparent(bool no_composite);
57 
58 private:
59     void freeAlpha();
60     void allocAlpha(unsigned char newval);
61     unsigned long m_alpha_pic;
62     unsigned long m_src_pic;
63     unsigned long m_dest_pic;
64     Drawable m_source, m_dest;
65     unsigned char m_alpha;
66 
67     static bool s_init;
68     static bool s_render; ///< wheter we have RENDER support
69     static bool s_composite; ///< wheter we have Composite support
70     static void init();
71 };
72 
73 }; // end namespace  FbTk
74 
75 #endif // FBTK_TRANSPARENT_HH
76 
77