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