]> Dogcows Code - chaz/openbox/blob - obrender/render.h
add _NUM_TYPES to obrender enums, to allow enumeration of the enum values
[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 RR_RELIEF_NUM_TYPES
59 } RrReliefType;
60
61 typedef enum {
62 RR_BEVEL_1,
63 RR_BEVEL_2,
64 RR_BEVEL_NUM_TYPES
65 } RrBevelType;
66
67 typedef enum {
68 RR_SURFACE_NONE,
69 RR_SURFACE_PARENTREL,
70 RR_SURFACE_SOLID,
71 RR_SURFACE_SPLIT_VERTICAL,
72 RR_SURFACE_HORIZONTAL,
73 RR_SURFACE_VERTICAL,
74 RR_SURFACE_DIAGONAL,
75 RR_SURFACE_CROSS_DIAGONAL,
76 RR_SURFACE_PYRAMID,
77 RR_SURFACE_MIRROR_HORIZONTAL,
78 RR_SURFACE_NUM_TYPES
79 } RrSurfaceColorType;
80
81 typedef enum {
82 RR_TEXTURE_NONE,
83 RR_TEXTURE_MASK,
84 RR_TEXTURE_TEXT,
85 RR_TEXTURE_LINE_ART,
86 RR_TEXTURE_RGBA,
87 RR_TEXTURE_IMAGE,
88 RR_TEXTURE_NUM_TYPES
89 } RrTextureType;
90
91 typedef enum {
92 RR_JUSTIFY_LEFT,
93 RR_JUSTIFY_CENTER,
94 RR_JUSTIFY_RIGHT,
95 RR_JUSITFY_NUM_TYPES
96 } RrJustify;
97
98 /* Put middle first so it's the default */
99 typedef enum {
100 RR_ELLIPSIZE_MIDDLE,
101 RR_ELLIPSIZE_NONE,
102 RR_ELLIPSIZE_START,
103 RR_ELLIPSIZE_END,
104 RR_ELLIPSIZE_NUM_TYPES
105 } RrEllipsizeMode;
106
107 typedef enum {
108 RR_FONTWEIGHT_LIGHT,
109 RR_FONTWEIGHT_NORMAL,
110 RR_FONTWEIGHT_SEMIBOLD,
111 RR_FONTWEIGHT_BOLD,
112 RR_FONTWEIGHT_ULTRABOLD,
113 RR_FONTWEIGHT_NUM_TYPES
114 } RrFontWeight;
115
116 typedef enum {
117 RR_FONTSLANT_NORMAL,
118 RR_FONTSLANT_ITALIC,
119 RR_FONTSLANT_OBLIQUE,
120 RR_FONTSLANT_NUM_TYPES
121 } RrFontSlant;
122
123 struct _RrSurface {
124 RrSurfaceColorType grad;
125 RrReliefType relief;
126 RrBevelType bevel;
127 RrColor *primary;
128 RrColor *secondary;
129 RrColor *border_color;
130 RrColor *bevel_dark;
131 RrColor *bevel_light;
132 RrColor *interlace_color;
133 gboolean interlaced;
134 gboolean border;
135 RrAppearance *parent;
136 gint parentx;
137 gint parenty;
138 RrPixel32 *pixel_data;
139 gint bevel_dark_adjust; /* 0-255, default is 64 */
140 gint bevel_light_adjust; /* 0-255, default is 128 */
141 RrColor *split_primary;
142 RrColor *split_secondary;
143 };
144
145 struct _RrTextureText {
146 RrFont *font;
147 RrJustify justify;
148 RrColor *color;
149 const gchar *string;
150 gint shadow_offset_x;
151 gint shadow_offset_y;
152 RrColor *shadow_color;
153 gboolean shortcut; /*!< Underline a character */
154 guint shortcut_pos; /*!< Position in bytes of the character to underline */
155 RrEllipsizeMode ellipsize;
156 gboolean flow; /* allow multiple lines. must set maxwidth below */
157 gint maxwidth;
158 guchar shadow_alpha; /* at the bottom to improve alignment */
159 };
160
161 struct _RrPixmapMask {
162 const RrInstance *inst;
163 Pixmap mask;
164 gint width;
165 gint height;
166 gchar *data;
167 };
168
169 struct _RrTextureMask {
170 RrColor *color;
171 RrPixmapMask *mask;
172 };
173
174 struct _RrTextureRGBA {
175 gint width;
176 gint height;
177 gint alpha;
178 RrPixel32 *data;
179 /* size and position to draw at (if these are zero, then it will be
180 drawn to fill the entire texture */
181 gint tx;
182 gint ty;
183 gint twidth;
184 gint theight;
185 };
186
187 struct _RrTextureImage {
188 RrImage *image;
189 gint alpha;
190 /* size and position to draw at (if these are zero, then it will be
191 drawn to fill the entire texture */
192 gint tx;
193 gint ty;
194 gint twidth;
195 gint theight;
196 };
197
198 struct _RrTextureLineArt {
199 RrColor *color;
200 gint x1;
201 gint y1;
202 gint x2;
203 gint y2;
204 };
205
206 union _RrTextureData {
207 RrTextureRGBA rgba;
208 RrTextureImage image;
209 RrTextureText text;
210 RrTextureMask mask;
211 RrTextureLineArt lineart;
212 };
213
214 struct _RrTexture {
215 /* If changing the type of a texture, you should DEFINITELY call
216 RrAppearanceClearTextures() first! */
217 RrTextureType type;
218 RrTextureData data;
219 };
220
221 struct _RrAppearance {
222 const RrInstance *inst;
223
224 RrSurface surface;
225 gint textures;
226 RrTexture *texture;
227 Pixmap pixmap;
228 XftDraw *xftdraw;
229
230 /* cached for internal use */
231 gint w, h;
232 };
233
234 /*! Holds a RGBA image picture */
235 struct _RrImagePic {
236 gint width, height;
237 RrPixel32 *data;
238 /* The sum of all the pixels. This is used to compare pictures if their
239 hashes match. */
240 gint sum;
241 /* The name of the image. This is used to determine
242 if the named image already is loaded. May be NULL if the image
243 was not loaded from disk. */
244 gchar *name;
245 };
246
247 typedef void (*RrImageDestroyFunc)(RrImage *image, gpointer data);
248
249 /*! An RrImage is a sort of meta-image. It can contain multiple versions of
250 an image at different sizes, which may or may not be completely different
251 pictures */
252 struct _RrImage {
253 gint ref;
254 RrImageCache *cache;
255
256 /*! An array of "originals", that is of RrPictures that have been added
257 to the image in various sizes, and that have not been resized. These
258 are explicitly added to the RrImage. */
259 RrImagePic **original;
260 gint n_original;
261 /*! An array of "resized" pictures. When an "original" RrPicture
262 needs to be resized for drawing, it is saved in here so that it doesn't
263 need to be resized again. These are automatically added to the
264 RrImage. */
265 RrImagePic **resized;
266 gint n_resized;
267
268 /* This function (if not NULL) will be called just before destroying
269 RrImage. */
270 RrImageDestroyFunc destroy_func;
271 gpointer destroy_data;
272 };
273
274 /* these are the same on all endian machines because it seems to be dependant
275 on the endianness of the gfx card, not the cpu. */
276 #define RrDefaultAlphaOffset 24
277 #define RrDefaultRedOffset 16
278 #define RrDefaultGreenOffset 8
279 #define RrDefaultBlueOffset 0
280
281 #define RrDefaultFontFamily "arial,sans"
282 #define RrDefaultFontSize 8
283 #define RrDefaultFontWeight RR_FONTWEIGHT_NORMAL
284 #define RrDefaultFontSlant RR_FONTSLANT_NORMAL
285
286 RrInstance* RrInstanceNew (Display *display, gint screen);
287 void RrInstanceFree (RrInstance *inst);
288
289 Display* RrDisplay (const RrInstance *inst);
290 gint RrScreen (const RrInstance *inst);
291 Window RrRootWindow (const RrInstance *inst);
292 Visual* RrVisual (const RrInstance *inst);
293 gint RrDepth (const RrInstance *inst);
294 Colormap RrColormap (const RrInstance *inst);
295 gint RrRedOffset (const RrInstance *inst);
296 gint RrGreenOffset (const RrInstance *inst);
297 gint RrBlueOffset (const RrInstance *inst);
298 gint RrRedShift (const RrInstance *inst);
299 gint RrGreenShift (const RrInstance *inst);
300 gint RrBlueShift (const RrInstance *inst);
301 gint RrRedMask (const RrInstance *inst);
302 gint RrGreenMask (const RrInstance *inst);
303 gint RrBlueMask (const RrInstance *inst);
304
305 RrColor *RrColorNew (const RrInstance *inst, gint r, gint g, gint b);
306 RrColor *RrColorParse (const RrInstance *inst, gchar *colorname);
307 void RrColorFree (RrColor *in);
308
309 gint RrColorRed (const RrColor *c);
310 gint RrColorGreen (const RrColor *c);
311 gint RrColorBlue (const RrColor *c);
312 gulong RrColorPixel (const RrColor *c);
313 GC RrColorGC (RrColor *c);
314
315 RrAppearance *RrAppearanceNew (const RrInstance *inst, gint numtex);
316 RrAppearance *RrAppearanceCopy (RrAppearance *a);
317 void RrAppearanceFree (RrAppearance *a);
318 void RrAppearanceRemoveTextures(RrAppearance *a);
319 void RrAppearanceAddTextures(RrAppearance *a, gint numtex);
320 /*! Always call this when changing the type of a texture in an appearance */
321 void RrAppearanceClearTextures(RrAppearance *a);
322
323 RrFont *RrFontOpen (const RrInstance *inst, const gchar *name,
324 gint size, RrFontWeight weight, RrFontSlant slant);
325 RrFont *RrFontOpenDefault (const RrInstance *inst);
326 void RrFontClose (RrFont *f);
327 /*! Returns an RrSize, that was allocated with g_slice_new(). Use g_slice_free() to
328 free it. */
329 RrSize *RrFontMeasureString (const RrFont *f, const gchar *str,
330 gint shadow_offset_x, gint shadow_offset_y,
331 gboolean flow, gint maxwidth);
332 gint RrFontHeight (const RrFont *f, gint shadow_offset_y);
333 gint RrFontMaxCharWidth (const RrFont *f);
334
335 /* Paint into the appearance. The old pixmap is returned (if there was one). It
336 is the responsibility of the caller to call XFreePixmap on the return when
337 it is non-null. */
338 Pixmap RrPaintPixmap (RrAppearance *a, gint w, gint h);
339 void RrPaint (RrAppearance *a, Window win, gint w, gint h);
340 void RrMinSize (RrAppearance *a, gint *w, gint *h);
341 gint RrMinWidth (RrAppearance *a);
342 /* For text textures, if flow is TRUE, then the string must be set before
343 calling this, otherwise it doesn't need to be */
344 gint RrMinHeight (RrAppearance *a);
345 void RrMargins (RrAppearance *a, gint *l, gint *t, gint *r, gint *b);
346
347 gboolean RrPixmapToRGBA(const RrInstance *inst,
348 Pixmap pmap, Pixmap mask,
349 gint *w, gint *h, RrPixel32 **data);
350
351 /*! Create a new image cache for RrImages.
352 @param max_resized_saved The number of resized copies of an image to save
353 */
354 RrImageCache* RrImageCacheNew(gint max_resized_saved);
355 void RrImageCacheRef(RrImageCache *self);
356 void RrImageCacheUnref(RrImageCache *self);
357
358 /*! Finds an image in the cache, if it is already in there */
359 RrImage* RrImageCacheFind(RrImageCache *self,
360 RrPixel32 *data, gint w, gint h);
361 /*! Finds an image in the cache, by searching for the name of the image */
362 RrImage* RrImageCacheFindName(RrImageCache *self,
363 const gchar *name);
364
365 RrImage* RrImageNew(RrImageCache *cache);
366 void RrImageRef(RrImage *im);
367 void RrImageUnref(RrImage *im);
368
369 void RrImageAddPicture(RrImage *im, const RrPixel32 *data, gint w, gint h);
370 /*! Adds a picture by name, from a file on disk.
371 @name Can be a full path to an image, or it can be a name as per the
372 freedesktop.org icon spec. */
373 gboolean RrImageAddPictureName(RrImage *im, const gchar *name);
374 void RrImageRemovePicture(RrImage *im, gint w, gint h);
375
376 G_END_DECLS
377
378 #endif /*__render_h*/
This page took 0.048399 seconds and 5 git commands to generate.