]> Dogcows Code - chaz/openbox/blob - obrender/render.h
This patch implements support for icons in user-defined menus into Openbox
[chaz/openbox] / obrender / render.h
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 render.h for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6 Copyright (c) 2003 Derek Foreman
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 See the COPYING file for a copy of the GNU General Public License.
19 */
20
21 #ifndef __render_h
22 #define __render_h
23
24 #include <X11/Xlib.h> /* some platforms dont include this as needed for Xft */
25 #include <pango/pangoxft.h>
26 #include <glib.h>
27
28 G_BEGIN_DECLS
29
30 #include "obrender/geom.h"
31 #include "obrender/version.h"
32
33 typedef union _RrTextureData RrTextureData;
34 typedef struct _RrAppearance RrAppearance;
35 typedef struct _RrSurface RrSurface;
36 typedef struct _RrFont RrFont;
37 typedef struct _RrTexture RrTexture;
38 typedef struct _RrTextureMask RrTextureMask;
39 typedef struct _RrTextureRGBA RrTextureRGBA;
40 typedef struct _RrTextureImage RrTextureImage;
41 typedef struct _RrTextureText RrTextureText;
42 typedef struct _RrTextureLineArt RrTextureLineArt;
43 typedef struct _RrPixmapMask RrPixmapMask;
44 typedef struct _RrInstance RrInstance;
45 typedef struct _RrColor RrColor;
46 typedef struct _RrImage RrImage;
47 typedef struct _RrImagePic RrImagePic;
48 typedef struct _RrImageCache RrImageCache;
49
50 typedef guint32 RrPixel32;
51 typedef guint16 RrPixel16;
52 typedef guchar RrPixel8;
53
54 typedef enum {
55 RR_RELIEF_FLAT,
56 RR_RELIEF_RAISED,
57 RR_RELIEF_SUNKEN
58 } RrReliefType;
59
60 typedef enum {
61 RR_BEVEL_1,
62 RR_BEVEL_2
63 } RrBevelType;
64
65 typedef enum {
66 RR_SURFACE_NONE,
67 RR_SURFACE_PARENTREL,
68 RR_SURFACE_SOLID,
69 RR_SURFACE_SPLIT_VERTICAL,
70 RR_SURFACE_HORIZONTAL,
71 RR_SURFACE_VERTICAL,
72 RR_SURFACE_DIAGONAL,
73 RR_SURFACE_CROSS_DIAGONAL,
74 RR_SURFACE_PYRAMID,
75 RR_SURFACE_MIRROR_HORIZONTAL
76 } RrSurfaceColorType;
77
78 typedef enum {
79 RR_TEXTURE_NONE,
80 RR_TEXTURE_MASK,
81 RR_TEXTURE_TEXT,
82 RR_TEXTURE_LINE_ART,
83 RR_TEXTURE_RGBA,
84 RR_TEXTURE_IMAGE
85 } RrTextureType;
86
87 typedef enum {
88 RR_JUSTIFY_LEFT,
89 RR_JUSTIFY_CENTER,
90 RR_JUSTIFY_RIGHT
91 } RrJustify;
92
93 /* Put middle first so it's the default */
94 typedef enum {
95 RR_ELLIPSIZE_MIDDLE,
96 RR_ELLIPSIZE_NONE,
97 RR_ELLIPSIZE_START,
98 RR_ELLIPSIZE_END
99 } RrEllipsizeMode;
100
101 typedef enum {
102 RR_FONTWEIGHT_LIGHT,
103 RR_FONTWEIGHT_NORMAL,
104 RR_FONTWEIGHT_SEMIBOLD,
105 RR_FONTWEIGHT_BOLD,
106 RR_FONTWEIGHT_ULTRABOLD
107 } RrFontWeight;
108
109 typedef enum {
110 RR_FONTSLANT_NORMAL,
111 RR_FONTSLANT_ITALIC,
112 RR_FONTSLANT_OBLIQUE
113 } RrFontSlant;
114
115 struct _RrSurface {
116 RrSurfaceColorType grad;
117 RrReliefType relief;
118 RrBevelType bevel;
119 RrColor *primary;
120 RrColor *secondary;
121 RrColor *border_color;
122 RrColor *bevel_dark;
123 RrColor *bevel_light;
124 RrColor *interlace_color;
125 gboolean interlaced;
126 gboolean border;
127 RrAppearance *parent;
128 gint parentx;
129 gint parenty;
130 RrPixel32 *pixel_data;
131 gint bevel_dark_adjust; /* 0-255, default is 64 */
132 gint bevel_light_adjust; /* 0-255, default is 128 */
133 RrColor *split_primary;
134 RrColor *split_secondary;
135 };
136
137 struct _RrTextureText {
138 RrFont *font;
139 RrJustify justify;
140 RrColor *color;
141 const gchar *string;
142 gint shadow_offset_x;
143 gint shadow_offset_y;
144 RrColor *shadow_color;
145 gboolean shortcut; /*!< Underline a character */
146 guint shortcut_pos; /*!< Position in bytes of the character to underline */
147 RrEllipsizeMode ellipsize;
148 gboolean flow; /* allow multiple lines. must set maxwidth below */
149 gint maxwidth;
150 guchar shadow_alpha; /* at the bottom to improve alignment */
151 };
152
153 struct _RrPixmapMask {
154 const RrInstance *inst;
155 Pixmap mask;
156 gint width;
157 gint height;
158 gchar *data;
159 };
160
161 struct _RrTextureMask {
162 RrColor *color;
163 RrPixmapMask *mask;
164 };
165
166 struct _RrTextureRGBA {
167 gint width;
168 gint height;
169 gint alpha;
170 RrPixel32 *data;
171 /* size and position to draw at (if these are zero, then it will be
172 drawn to fill the entire texture */
173 gint tx;
174 gint ty;
175 gint twidth;
176 gint theight;
177 };
178
179 struct _RrTextureImage {
180 RrImage *image;
181 gint alpha;
182 /* size and position to draw at (if these are zero, then it will be
183 drawn to fill the entire texture */
184 gint tx;
185 gint ty;
186 gint twidth;
187 gint theight;
188 };
189
190 struct _RrTextureLineArt {
191 RrColor *color;
192 gint x1;
193 gint y1;
194 gint x2;
195 gint y2;
196 };
197
198 union _RrTextureData {
199 RrTextureRGBA rgba;
200 RrTextureImage image;
201 RrTextureText text;
202 RrTextureMask mask;
203 RrTextureLineArt lineart;
204 };
205
206 struct _RrTexture {
207 /* If changing the type of a texture, you should DEFINITELY call
208 RrAppearanceClearTextures() first! */
209 RrTextureType type;
210 RrTextureData data;
211 };
212
213 struct _RrAppearance {
214 const RrInstance *inst;
215
216 RrSurface surface;
217 gint textures;
218 RrTexture *texture;
219 Pixmap pixmap;
220 XftDraw *xftdraw;
221
222 /* cached for internal use */
223 gint w, h;
224 };
225
226 /*! Holds a RGBA image picture */
227 struct _RrImagePic {
228 gint width, height;
229 RrPixel32 *data;
230 /* The sum of all the pixels. This is used to compare pictures if their
231 hashes match. */
232 gint sum;
233 };
234
235 typedef void (*RrImageDestroyFunc)(RrImage *image);
236
237 /*! An RrImage is a sort of meta-image. It can contain multiple versions of
238 an image at different sizes, which may or may not be completely different
239 pictures */
240 struct _RrImage {
241 gint ref;
242 RrImageCache *cache;
243
244 /*! An array of "originals", that is of RrPictures that have been added
245 to the image in various sizes, and that have not been resized. These
246 are explicitly added to the RrImage. */
247 RrImagePic **original;
248 gint n_original;
249 /*! An array of "resized" pictures. When an "original" RrPicture
250 needs to be resized for drawing, it is saved in here so that it doesn't
251 need to be resized again. These are automatically added to the
252 RrImage. */
253 RrImagePic **resized;
254 gint n_resized;
255
256 /* This function (if not NULL) will be called just before destroying
257 RrImage. */
258 RrImageDestroyFunc destroy_func;
259 };
260
261 /* these are the same on all endian machines because it seems to be dependant
262 on the endianness of the gfx card, not the cpu. */
263 #define RrDefaultAlphaOffset 24
264 #define RrDefaultRedOffset 16
265 #define RrDefaultGreenOffset 8
266 #define RrDefaultBlueOffset 0
267
268 #define RrDefaultFontFamily "arial,sans"
269 #define RrDefaultFontSize 8
270 #define RrDefaultFontWeight RR_FONTWEIGHT_NORMAL
271 #define RrDefaultFontSlant RR_FONTSLANT_NORMAL
272
273 RrInstance* RrInstanceNew (Display *display, gint screen);
274 void RrInstanceFree (RrInstance *inst);
275
276 Display* RrDisplay (const RrInstance *inst);
277 gint RrScreen (const RrInstance *inst);
278 Window RrRootWindow (const RrInstance *inst);
279 Visual* RrVisual (const RrInstance *inst);
280 gint RrDepth (const RrInstance *inst);
281 Colormap RrColormap (const RrInstance *inst);
282 gint RrRedOffset (const RrInstance *inst);
283 gint RrGreenOffset (const RrInstance *inst);
284 gint RrBlueOffset (const RrInstance *inst);
285 gint RrRedShift (const RrInstance *inst);
286 gint RrGreenShift (const RrInstance *inst);
287 gint RrBlueShift (const RrInstance *inst);
288 gint RrRedMask (const RrInstance *inst);
289 gint RrGreenMask (const RrInstance *inst);
290 gint RrBlueMask (const RrInstance *inst);
291
292 RrColor *RrColorNew (const RrInstance *inst, gint r, gint g, gint b);
293 RrColor *RrColorParse (const RrInstance *inst, gchar *colorname);
294 void RrColorFree (RrColor *in);
295
296 gint RrColorRed (const RrColor *c);
297 gint RrColorGreen (const RrColor *c);
298 gint RrColorBlue (const RrColor *c);
299 gulong RrColorPixel (const RrColor *c);
300 GC RrColorGC (RrColor *c);
301
302 RrAppearance *RrAppearanceNew (const RrInstance *inst, gint numtex);
303 RrAppearance *RrAppearanceCopy (RrAppearance *a);
304 void RrAppearanceFree (RrAppearance *a);
305 void RrAppearanceRemoveTextures(RrAppearance *a);
306 void RrAppearanceAddTextures(RrAppearance *a, gint numtex);
307 /*! Always call this when changing the type of a texture in an appearance */
308 void RrAppearanceClearTextures(RrAppearance *a);
309
310 RrFont *RrFontOpen (const RrInstance *inst, const gchar *name,
311 gint size, RrFontWeight weight, RrFontSlant slant);
312 RrFont *RrFontOpenDefault (const RrInstance *inst);
313 void RrFontClose (RrFont *f);
314 RrSize *RrFontMeasureString (const RrFont *f, const gchar *str,
315 gint shadow_offset_x, gint shadow_offset_y,
316 gboolean flow, gint maxwidth);
317 gint RrFontHeight (const RrFont *f, gint shadow_offset_y);
318 gint RrFontMaxCharWidth (const RrFont *f);
319
320 /* Paint into the appearance. The old pixmap is returned (if there was one). It
321 is the responsibility of the caller to call XFreePixmap on the return when
322 it is non-null. */
323 Pixmap RrPaintPixmap (RrAppearance *a, gint w, gint h);
324 void RrPaint (RrAppearance *a, Window win, gint w, gint h);
325 void RrMinSize (RrAppearance *a, gint *w, gint *h);
326 gint RrMinWidth (RrAppearance *a);
327 /* For text textures, if flow is TRUE, then the string must be set before
328 calling this, otherwise it doesn't need to be */
329 gint RrMinHeight (RrAppearance *a);
330 void RrMargins (RrAppearance *a, gint *l, gint *t, gint *r, gint *b);
331
332 gboolean RrPixmapToRGBA(const RrInstance *inst,
333 Pixmap pmap, Pixmap mask,
334 gint *w, gint *h, RrPixel32 **data);
335
336 /*! Create a new image cache for RrImages.
337 @param max_resized_saved The number of resized copies of an image to save
338 */
339 RrImageCache* RrImageCacheNew(gint max_resized_saved);
340 void RrImageCacheRef(RrImageCache *self);
341 void RrImageCacheUnref(RrImageCache *self);
342
343 /*! Finds an image in the cache, if it is already in there */
344 RrImage* RrImageCacheFind(RrImageCache *self,
345 RrPixel32 *data, gint w, gint h);
346
347 RrImage* RrImageNew(RrImageCache *cache);
348 void RrImageRef(RrImage *im);
349 void RrImageUnref(RrImage *im);
350
351 void RrImageAddPicture(RrImage *im, RrPixel32 *data, gint w, gint h);
352 void RrImageRemovePicture(RrImage *im, gint w, gint h);
353
354 G_END_DECLS
355
356 #endif /*__render_h*/
This page took 0.051871 seconds and 5 git commands to generate.