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