]> icculus.org git repositories - dana/openbox.git/blob - render2/render.h
add painting
[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 /* initialization */
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 *RrInit(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 RrDestroy(struct RrInstance *inst);
24
25
26 /* colors */
27
28 /*! A Color (including alpha component) for the Render library. This should be
29   treated as an opaque data type, and be accessed only via the available
30   functions. */
31 struct RrColor {
32     /*! The red component. */
33     float r;
34     /*! The green component. */
35     float g;
36     /*! The blue component. */
37     float b;
38     /*! The alpha component. */
39     float a;
40 };
41
42 /*! Returns the red component for an RrColor */
43 #define RrColorRed(c) (c).r
44 /*! Returns the green component for an RrColor */
45 #define RrColorGreen(c) (c).g
46 /*! Returns the blue component for an RrColor */
47 #define RrColorBlue(c) (c).b
48 /*! Returns the alpha component for an RrColor */
49 #define RrColorAlpha(c) (c).a
50 /*! Returns if an RrColor is non-opaque */
51 #define RrColorHasAlpha(c) ((c).a > 0.0000001)
52
53 /*! Sets the values of all components for an RrColor */
54 #define RrColorSet(c, w, x, y, z) (c)->r = (w), (c)->g = (x), \
55                                   (c)->b = (y), (c)->a = z
56
57
58 /*! Gets color values from a colorname.
59   @param inst An instance of the library
60   @param colorname The name of the color.
61   @param ret The RrColor to set the colorvalues in.
62   @return nonzero if the colorname could be parsed; on error, it returns zero.
63 */
64 int RrColorParse(struct RrInstance *inst, const char *colorname,
65                  struct RrColor *ret);
66
67 /* fonts */
68
69 struct RrFont;
70
71 struct RrFont *RrFontOpen(struct RrInstance *inst, const char *fontstring);
72 void RrFontClose(struct RrFont *font);
73
74 int RrFontMeasureString(struct RrFont *font, const char *string);
75 int RrFontHeight(struct RrFont *font);
76 int RrFontMaxCharWidth(struct RrFont *font);
77
78 /* surfaces */
79
80 struct RrSurface;
81
82 enum RrSurfaceType {
83     RR_SURFACE_PLANAR,
84     RR_SURFACE_NONPLANAR
85 };
86
87 /*! The options available for the background of an RrSurface */
88 enum RrSurfaceColorType {
89     /*! No rendering on the surface background, its contents will be
90       undefined. */
91     RR_SURFACE_NONE,
92     /*! Solid color fill. */
93     RR_SURFACE_SOLID,
94     /*! Horizontal gradient. */
95     RR_SURFACE_HORIZONTAL,
96     /*! Vertical gradient. */
97     RR_SURFACE_VERTICAL,
98     /*! Diagonal (TL->BR) gradient. */
99     RR_SURFACE_DIAGONAL,
100     /*! Cross-Diagonal (TR->BL) gradient. */
101     RR_SURFACE_CROSSDIAGONAL,
102     /*! Pipecross gradient. */
103     RR_SURFACE_PIPECROSS,
104     /*! Rectangle gradient. */
105     RR_SURFACE_RECTANGLE,
106     /*! Pyramid gradient. */
107     RR_SURFACE_PYRAMID
108 };
109
110 /*! Create a new RrSurface prototype that can't render. A prototype can be
111  copied to a new RrSurface that can render. */
112 struct RrSurface *RrSurfaceNewProto(enum RrSurfaceType type,
113                                     int numtex);
114 /*! Create a new top-level RrSurface for a Window. */
115 struct RrSurface *RrSurfaceNew(struct RrInstance *inst,
116                                enum RrSurfaceType type,
117                                Window win,
118                                int numtex);
119 /*! Create a new RrSurface which is a child of another. */
120 struct RrSurface *RrSurfaceNewChild(enum RrSurfaceType type,
121                                     struct RrSurface *parent,
122                                     int numtex);
123 /*! Copy an RrSurface, creating a new top-level RrSurface for a Window. */
124 struct RrSurface *RrSurfaceCopy(struct RrInstance *inst,
125                                 struct RrSurface *sur,
126                                 Window win);
127 /*! Copy an RrSurface, creating a nwe RrSurface which is a child of another. */
128 struct RrSurface *RrSurfaceCopyChild(struct RrSurface *sur,
129                                      struct RrSurface *parent);
130 void RrSurfaceFree(struct RrSurface *sur);
131
132 void RrSurfaceSetArea(struct RrSurface *sur,
133                       int x,
134                       int y,
135                       int w,
136                       int h);
137
138 Window RrSurfaceWindow(struct RrSurface *sur);
139
140 /* textures */
141
142 enum RrLayout {
143     RR_TOP_LEFT,
144     RR_TOP,
145     RR_TOP_RIGHT,
146     RR_LEFT,
147     RR_CENTER,
148     RR_RIGHT,
149     RR_BOTTOM_LEFT,
150     RR_BOTTOM,
151     RR_BOTTOM_RIGHT
152 };
153
154 #ifndef __LONG64
155 typedef long RrData32;
156 #else
157 typedef int RrData32;
158 #endif
159
160 void RrTextureSetRGBA(struct RrSurface *sur,
161                       int texnum,
162                       RrData32 *data,
163                       int x,
164                       int y,
165                       int w,
166                       int h);
167 void RrTextureSetText(struct RrSurface *sur,
168                       int texnum,
169                       struct RrFont *font,
170                       enum RrLayout layout,
171                       const char *text);
172
173 /* drawing */
174
175 /*! Paints the surface, and all its children */
176 void RrSurfacePaint(struct RrSurface *sur);
177 /*! Paints the surface, and all its children, but only in the given area. */
178 void RrSurfacePaintArea(struct RrSurface *sur,
179                         int x,
180                         int y,
181                         int w,
182                         int h);
183
184 #endif