38bcdeb5d225c6e98de12b7c17a6459a03cda209
[dana/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        Ben 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 "version.h"
26
27 #include <X11/Xlib.h> /* some platforms dont include this as needed for Xft */
28 #define _XFT_NO_COMPAT_ /* no Xft 1 API */
29 #include <X11/Xft/Xft.h>
30 #include <glib.h>
31
32 G_BEGIN_DECLS
33
34 typedef union  _RrTextureData      RrTextureData;
35 typedef struct _RrAppearance       RrAppearance;
36 typedef struct _RrSurface          RrSurface;
37 typedef struct _RrFont             RrFont;
38 typedef struct _RrTexture          RrTexture;
39 typedef struct _RrTextureMask      RrTextureMask;
40 typedef struct _RrTextureRGBA      RrTextureRGBA;
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
47 typedef guint32 RrPixel32;
48 typedef guint16 RrPixel16;
49
50 typedef enum {
51     RR_RELIEF_FLAT,
52     RR_RELIEF_RAISED,
53     RR_RELIEF_SUNKEN
54 } RrReliefType;
55
56 typedef enum {
57     RR_BEVEL_1,
58     RR_BEVEL_2
59 } RrBevelType;
60
61 typedef enum {
62     RR_SURFACE_NONE,
63     RR_SURFACE_PARENTREL,
64     RR_SURFACE_SOLID,
65     RR_SURFACE_SPLIT,
66     RR_SURFACE_HORIZONTAL,
67     RR_SURFACE_VERTICAL,
68     RR_SURFACE_DIAGONAL,
69     RR_SURFACE_CROSS_DIAGONAL,
70     RR_SURFACE_PYRAMID,
71     RR_SURFACE_OSX
72 } RrSurfaceColorType;
73
74 typedef enum {
75     RR_TEXTURE_NONE,
76     RR_TEXTURE_MASK,
77     RR_TEXTURE_TEXT,
78     RR_TEXTURE_LINE_ART,
79     RR_TEXTURE_RGBA
80 } RrTextureType;
81
82 typedef enum {
83     RR_JUSTIFY_LEFT,
84     RR_JUSTIFY_CENTER,
85     RR_JUSTIFY_RIGHT
86 } RrJustify;
87
88 struct _RrSurface {
89     RrSurfaceColorType grad;
90     RrReliefType relief;
91     RrBevelType bevel;
92     RrColor *primary;
93     RrColor *secondary;
94     RrColor *border_color;
95     RrColor *bevel_dark; 
96     RrColor *bevel_light;
97     RrColor *interlace_color;
98     gboolean interlaced;
99     gboolean border;
100     RrAppearance *parent;
101     gint parentx;
102     gint parenty;
103     RrPixel32 *pixel_data;
104 };
105
106 struct _RrTextureText {
107     RrFont *font;
108     RrJustify justify;
109     RrColor *color;
110     gchar *string;
111 };
112
113 struct _RrPixmapMask {
114     const RrInstance *inst;
115     Pixmap mask;
116     gint width;
117     gint height;
118     gchar *data;
119 };
120
121 struct _RrTextureMask {
122     RrColor *color;
123     RrPixmapMask *mask;
124 };
125
126 struct _RrTextureRGBA {
127     gint width;
128     gint height;
129     RrPixel32 *data;
130 /* cached scaled so we don't have to scale often */
131     gint cwidth;
132     gint cheight;
133     RrPixel32 *cache;
134 };
135
136 struct _RrTextureLineArt {
137     RrColor *color;
138     gint x1;
139     gint y1;
140     gint x2;
141     gint y2;
142 };
143
144 union _RrTextureData {
145     RrTextureRGBA rgba;
146     RrTextureText text;
147     RrTextureMask mask;
148     RrTextureLineArt lineart;
149 };
150
151 struct _RrTexture {
152     RrTextureType type;
153     RrTextureData data;
154 };
155
156 struct _RrAppearance {
157     const RrInstance *inst;
158
159     RrSurface surface;
160     gint textures;
161     RrTexture *texture;
162     Pixmap pixmap;
163     XftDraw *xftdraw;
164
165     /* cached for internal use */
166     gint w, h;
167 };
168
169 /* these are the same on all endian machines because it seems to be dependant
170    on the endianness of the gfx card, not the cpu. */
171 #define RrDefaultAlphaOffset 24
172 #define RrDefaultRedOffset 16
173 #define RrDefaultGreenOffset 8
174 #define RrDefaultBlueOffset 0
175
176 RrInstance* RrInstanceNew (Display *display, gint screen);
177 void        RrInstanceFree (RrInstance *inst);
178
179 Display* RrDisplay      (const RrInstance *inst);
180 gint     RrScreen       (const RrInstance *inst);
181 Window   RrRootWindow   (const RrInstance *inst);
182 Visual*  RrVisual       (const RrInstance *inst);
183 gint     RrDepth        (const RrInstance *inst);
184 Colormap RrColormap     (const RrInstance *inst);
185 gint     RrRedOffset    (const RrInstance *inst);
186 gint     RrGreenOffset  (const RrInstance *inst);
187 gint     RrBlueOffset   (const RrInstance *inst);
188 gint     RrRedShift     (const RrInstance *inst);
189 gint     RrGreenShift   (const RrInstance *inst);
190 gint     RrBlueShift    (const RrInstance *inst);
191 gint     RrRedMask      (const RrInstance *inst);
192 gint     RrGreenMask    (const RrInstance *inst);
193 gint     RrBlueMask     (const RrInstance *inst);
194
195 RrColor *RrColorNew   (const RrInstance *inst, gint r, gint g, gint b);
196 RrColor *RrColorParse (const RrInstance *inst, gchar *colorname);
197 void     RrColorFree  (RrColor *in);
198
199 gint     RrColorRed   (const RrColor *c);
200 gint     RrColorGreen (const RrColor *c);
201 gint     RrColorBlue  (const RrColor *c);
202 gulong   RrColorPixel (const RrColor *c);
203 GC       RrColorGC    (RrColor *c);
204
205 RrAppearance *RrAppearanceNew  (const RrInstance *inst, gint numtex);
206 RrAppearance *RrAppearanceCopy (RrAppearance *a);
207 void          RrAppearanceFree (RrAppearance *a);
208
209 RrSize *RrFontMeasureString (const RrFont *f, const gchar *str);
210 gint RrFontHeight        (const RrFont *f);
211 gint RrFontMaxCharWidth  (const RrFont *f);
212
213 void RrPaint   (RrAppearance *a, Window win, gint w, gint h);
214 void RrMinsize (RrAppearance *a, gint *w, gint *h);
215 void RrMargins (RrAppearance *a, gint *l, gint *t, gint *r, gint *b);
216
217 gboolean RrPixmapToRGBA(const RrInstance *inst,
218                         Pixmap pmap, Pixmap mask,
219                         gint *w, gint *h, RrPixel32 **data);
220
221 G_END_DECLS
222
223 #endif /*__render_h*/