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