]> icculus.org git repositories - dana/openbox.git/blob - render2/render.h
improve expose handling for alpha children
[dana/openbox.git] / render2 / render.h
1 #ifndef __render_h__
2 #define __render_h__
3
4 #include <glib.h>
5 #include <X11/Xlib.h>
6
7 /* instances */
8
9 struct RrInstance;
10
11 /*! Returns a struct to be used when calling members of the library.
12   If the library fails to initialize, NULL is returned.
13   @param display The X Display to use.
14   @param screen The number of the screen to use.
15 */
16 struct RrInstance *RrInstanceNew(Display *display,
17                                  int screen);
18
19 /*! Destroys an instance of the library. The instance should not be used after
20   calling this function.
21   @param inst The instance to destroy.
22 */
23 void RrInstanceFree(struct RrInstance *inst);
24
25 int RrInstanceDepth(struct RrInstance *inst);
26 Colormap RrInstanceColormap(struct RrInstance *inst);
27 Visual *RrInstanceVisual(struct RrInstance *inst);
28
29 /* colors */
30
31 /*! A Color (including alpha component) for the Render library. This should be
32   treated as an opaque data type, and be accessed only via the available
33   functions. */
34 struct RrColor {
35     /*! The red component. */
36     float r;
37     /*! The green component. */
38     float g;
39     /*! The blue component. */
40     float b;
41     /*! The alpha component. */
42     float a;
43 };
44
45 /*! Returns if an RrColor is non-opaque */
46 #define RrColorHasAlpha(c) ((c).a > 0.0000001)
47
48 /*! Sets the values of all components for an RrColor */
49 #define RrColorSet(c, w, x, y, z) (c)->r = (w), (c)->g = (x), \
50                                   (c)->b = (y), (c)->a = z
51
52
53 /*! Gets color values from a colorname.
54   @param inst An instance of the library
55   @param colorname The name of the color.
56   @param ret The RrColor to set the colorvalues in.
57   @return nonzero if the colorname could be parsed; on error, it returns zero.
58 */
59 int RrColorParse(struct RrInstance *inst, const char *colorname,
60                  struct RrColor *ret);
61
62 /* fonts */
63
64 struct RrFont;
65
66 struct RrFont *RrFontOpen(struct RrInstance *inst, const char *fontstring);
67 void RrFontClose(struct RrFont *font);
68
69 int RrFontMeasureString(struct RrFont *font, const char *string);
70 int RrFontHeight(struct RrFont *font);
71 int RrFontMaxCharWidth(struct RrFont *font);
72
73 /* surfaces */
74
75 struct RrSurface;
76
77 enum RrSurfaceType {
78     RR_SURFACE_NONE,
79     RR_SURFACE_PLANAR,
80     RR_SURFACE_NONPLANAR
81 };
82
83 /*! Create a new RrSurface prototype that can't render. A prototype can be
84  copied to a new RrSurface that can render. */
85 struct RrSurface *RrSurfaceNewProto(enum RrSurfaceType type,
86                                     int numtex);
87 /*! Create a new top-level RrSurface for a Window. The new RrSurface defaults
88   to a non-visible state.*/
89 struct RrSurface *RrSurfaceNew(struct RrInstance *inst,
90                                enum RrSurfaceType type,
91                                Window win,
92                                int numtex);
93 /*! Create a new RrSurface which is a child of another. The new RrSurface
94   defaults to a visible state. */
95 struct RrSurface *RrSurfaceNewChild(enum RrSurfaceType type,
96                                     struct RrSurface *parent,
97                                     int numtex);
98 /*! Destroys an RrSurface. */
99 void RrSurfaceFree(struct RrSurface *sur);
100
101 /*! Copy an RrSurface, setting the dest surface to be identical to the source
102  surface. */
103 void RrSurfaceCopy(struct RrSurface *dest,
104                    struct RrSurface *src);
105
106 void RrSurfaceSetArea(struct RrSurface *sur,
107                       int x,
108                       int y,
109                       int w,
110                       int h);
111 void RrSurfaceSetPos(struct RrSurface *sur,
112                      int x,
113                      int y);
114 void RrSurfaceSetSize(struct RrSurface *sur,
115                       int w,
116                       int h);
117
118 Window RrSurfaceWindow(struct RrSurface *sur);
119
120 void RrSurfaceShow(struct RrSurface *sur);
121 void RrSurfaceHide(struct RrSurface *sur);
122 int RrSurfaceVisible(struct RrSurface *sur);
123
124 void RrSurfaceMinSize(struct RrSurface *sur,
125                       int *w,
126                       int *h);
127
128 /*! Shape a surface to its children. This is not done implicitly inside the
129   library at *any* time. You must call this for each surface you want to
130   shape, when you want to update it. This means when you resize the surface
131   or change its base shape, or move/resize any of its children, you will need
132   to call this explicitly. Also, please note that you must call it on the
133   children surfaces first and work your way up to the top level surface for it
134   to function properly.
135 */
136 void RrSurfaceShape(struct RrSurface *sur);
137
138 /*! Set the base shape for a surface. To clear the base, pass 0 for all
139   of the arguments (except for the surface of course!)
140 */
141 void RrSurfaceShapeSetBase(struct RrSurface *sur,
142                            Window base,
143                            int x,
144                            int y);
145
146 /* planar surfaces */
147
148 /*! The options available for the background of an RrSurface */
149 enum RrSurfaceColorType {
150     /*! No rendering on the surface background, its contents will be
151       undefined. */
152     RR_PLANAR_NONE,
153     /*! Solid color fill. */
154     RR_PLANAR_SOLID,
155     /*! Horizontal gradient. */
156     RR_PLANAR_HORIZONTAL,
157     /*! Vertical gradient. */
158     RR_PLANAR_VERTICAL,
159     /*! Diagonal (TL->BR) gradient. */
160     RR_PLANAR_DIAGONAL,
161     /*! Cross-Diagonal (TR->BL) gradient. */
162     RR_PLANAR_CROSSDIAGONAL,
163     /*! Pipecross gradient. */
164     RR_PLANAR_PIPECROSS,
165     /*! Rectangle gradient. */
166     RR_PLANAR_RECTANGLE,
167     /*! Pyramid gradient. */
168     RR_PLANAR_PYRAMID
169 };
170
171 enum RrBevelType {
172     RR_SUNKEN_OUTER = -2,
173     RR_SUNKEN_INNER = -1,
174     RR_BEVEL_NONE   =  0,
175     RR_RAISED_INNER =  1,
176     RR_RAISED_OUTER =  2
177 };
178
179 void RrPlanarSet(struct RrSurface *sur,
180                  enum RrSurfaceColorType type,
181                  enum RrBevelType bevel,
182                  struct RrColor *primary,
183                  struct RrColor *secondary,
184                  int borderwidth,
185                  struct RrColor *border);
186
187 /* textures */
188
189 enum RrLayout {
190     RR_TOP_LEFT,
191     RR_TOP,
192     RR_TOP_RIGHT,
193     RR_LEFT,
194     RR_CENTER,
195     RR_RIGHT,
196     RR_BOTTOM_LEFT,
197     RR_BOTTOM,
198     RR_BOTTOM_RIGHT
199 };
200
201 #ifndef __LONG64
202 typedef long RrData32;
203 #else
204 typedef int RrData32;
205 #endif
206
207 void RrTextureSetRGBA(struct RrSurface *sur,
208                       int texnum,
209                       RrData32 *data,
210                       int x,
211                       int y,
212                       int w,
213                       int h);
214 void RrTextureSetText(struct RrSurface *sur,
215                       int texnum,
216                       struct RrFont *font,
217                       enum RrLayout layout,
218                       struct RrColor *color,
219                       const char *text);
220 void RrTextureSetNone(struct RrSurface *sur,
221                       int texnum);
222
223 /* drawing */
224
225 /*! Paints the surface, and optionally all its children */
226 void RrPaint(struct RrSurface *sur, int recurse_always);
227
228 void RrExpose(struct RrInstance *inst, XExposeEvent *e);
229
230 #endif