fixing parse error in execcommand
[bbkeys.git] / src / Image.hh
blob6e0b5443c366f1ae12a5a496a0608aca9c454136
1 // Image.hh for Blackbox - an X11 Window manager
2 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
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:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
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.
22 // $Id$
24 #ifndef __Image_hh
25 #define __Image_hh
27 extern "C" {
28 #include <X11/Xlib.h>
29 #include <X11/Xutil.h>
32 #include "Timer.hh"
34 class BImage;
35 class BImageControl;
38 class BColor {
39 private:
40 int allocated;
41 unsigned char red, green, blue;
42 unsigned long pixel;
44 public:
45 BColor(char r = 0, char g = 0, char b = 0)
46 { red = r; green = g; blue = b; pixel = 0; allocated = 0; }
48 inline const int &isAllocated(void) const { return allocated; }
50 inline const unsigned char &getRed(void) const { return red; }
51 inline const unsigned char &getGreen(void) const { return green; }
52 inline const unsigned char &getBlue(void) const { return blue; }
54 inline const unsigned long &getPixel(void) const { return pixel; }
56 inline void setAllocated(int a) { allocated = a; }
57 inline void setRGB(char r, char g, char b) { red = r; green = g; blue = b; }
58 inline void setPixel(unsigned long p) { pixel = p; }
62 class BTexture {
63 private:
64 BColor color, colorTo, hiColor, loColor;
65 unsigned long texture;
67 public:
68 BTexture(void) { texture = 0; }
70 inline BColor *getColor(void) { return &color; }
71 inline BColor *getColorTo(void) { return &colorTo; }
72 inline BColor *getHiColor(void) { return &hiColor; }
73 inline BColor *getLoColor(void) { return &loColor; }
75 inline const unsigned long &getTexture(void) const { return texture; }
77 inline void setTexture(unsigned long t) { texture = t; }
78 inline void addTexture(unsigned long t) { texture |= t; }
82 // bevel options
83 #define BImage_Flat (1l<<1)
84 #define BImage_Sunken (1l<<2)
85 #define BImage_Raised (1l<<3)
87 // textures
88 #define BImage_Solid (1l<<4)
89 #define BImage_Gradient (1l<<5)
91 // gradients
92 #define BImage_Horizontal (1l<<6)
93 #define BImage_Vertical (1l<<7)
94 #define BImage_Diagonal (1l<<8)
95 #define BImage_CrossDiagonal (1l<<9)
96 #define BImage_Rectangle (1l<<10)
97 #define BImage_Pyramid (1l<<11)
98 #define BImage_PipeCross (1l<<12)
99 #define BImage_Elliptic (1l<<13)
101 // bevel types
102 #define BImage_Bevel1 (1l<<14)
103 #define BImage_Bevel2 (1l<<15)
105 // inverted image
106 #define BImage_Invert (1l<<16)
108 // parent relative image
109 #define BImage_ParentRelative (1l<<17)
111 #ifdef INTERLACE
112 // fake interlaced image
113 # define BImage_Interlaced (1l<<18)
114 #endif // INTERLACE
116 #include "BaseDisplay.hh"
117 #include "LinkedList.hh"
120 class BImage {
121 private:
122 BImageControl *control;
124 #ifdef INTERLACE
125 Bool interlaced;
126 #endif // INTERLACE
128 XColor *colors;
130 BColor *from, *to;
131 int red_offset, green_offset, blue_offset, red_bits, green_bits, blue_bits,
132 ncolors, cpc, cpccpc;
133 unsigned char *red, *green, *blue, *red_table, *green_table, *blue_table;
134 unsigned int width, height, *xtable, *ytable;
137 protected:
138 Pixmap renderPixmap(void);
140 XImage *renderXImage(void);
142 void invert(void);
143 void bevel1(void);
144 void bevel2(void);
145 void dgradient(void);
146 void egradient(void);
147 void hgradient(void);
148 void pgradient(void);
149 void rgradient(void);
150 void vgradient(void);
151 void cdgradient(void);
152 void pcgradient(void);
155 public:
156 BImage(BImageControl *, unsigned int, unsigned int);
157 ~BImage(void);
159 Pixmap render(BTexture *);
160 Pixmap render_solid(BTexture *);
161 Pixmap render_gradient(BTexture *);
165 class BImageControl : public TimeoutHandler {
166 private:
167 Bool dither;
168 BaseDisplay *basedisplay;
169 ScreenInfo *screeninfo;
170 #ifdef TIMEDCACHE
171 BTimer *timer;
172 #endif // TIMEDCACHE
174 Colormap root_colormap;
175 Window window;
176 XColor *colors;
177 int colors_per_channel, ncolors, screen_number, screen_depth,
178 bits_per_pixel, red_offset, green_offset, blue_offset,
179 red_bits, green_bits, blue_bits;
180 unsigned char red_color_table[256], green_color_table[256],
181 blue_color_table[256];
182 unsigned int *grad_xbuffer, *grad_ybuffer, grad_buffer_width,
183 grad_buffer_height;
184 unsigned long *sqrt_table, cache_max;
186 typedef struct Cache {
187 Pixmap pixmap;
189 unsigned int count, width, height;
190 unsigned long pixel1, pixel2, texture;
191 } Cache;
193 LinkedList<Cache> *cache;
196 protected:
197 Pixmap searchCache(unsigned int, unsigned int, unsigned long, BColor *,
198 BColor *);
201 public:
202 BImageControl(BaseDisplay *, ScreenInfo *, Bool = False, int = 4,
203 unsigned long = 300000l, unsigned long = 200l);
204 virtual ~BImageControl(void);
206 inline BaseDisplay *getBaseDisplay(void) { return basedisplay; }
208 inline const Bool &doDither(void) { return dither; }
210 inline const Colormap &getColormap(void) const { return root_colormap; }
212 inline ScreenInfo *getScreenInfo(void) { return screeninfo; }
214 inline const Window &getDrawable(void) const { return window; }
216 inline Visual *getVisual(void) { return screeninfo->getVisual(); }
218 inline const int &getBitsPerPixel(void) const { return bits_per_pixel; }
219 inline const int &getDepth(void) const { return screen_depth; }
220 inline const int &getColorsPerChannel(void) const
221 { return colors_per_channel; }
223 unsigned long getColor(const char *);
224 unsigned long getColor(const char *, unsigned char *, unsigned char *,
225 unsigned char *);
226 unsigned long getSqrt(unsigned int);
228 Pixmap renderImage(unsigned int, unsigned int, BTexture *);
230 void installRootColormap(void);
231 void removeImage(Pixmap);
232 void getColorTables(unsigned char **, unsigned char **, unsigned char **,
233 int *, int *, int *, int *, int *, int *);
234 void getXColorTable(XColor **, int *);
235 void getGradientBuffers(unsigned int, unsigned int,
236 unsigned int **, unsigned int **);
237 void setDither(Bool d) { dither = d; }
238 void setColorsPerChannel(int);
239 void parseTexture(BTexture *, const char *);
240 void parseColor(BColor *, const char * = 0);
242 virtual void timeout(void);
246 #endif // __Image_hh