awful.client: rename master to getmaster
[awesome.git] / draw.h
blobfc0d4da8d1897db3f7b9aac1a9d95d541e031cf7
1 /*
2 * draw.h - draw functions header
4 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifndef AWESOME_COMMON_DRAW_H
23 #define AWESOME_COMMON_DRAW_H
25 #include <cairo.h>
26 #include <pango/pangocairo.h>
28 #include <xcb/xcb.h>
30 #include "image.h"
31 #include "common/array.h"
32 #include "common/list.h"
33 #include "common/buffer.h"
34 #include "common/xutil.h"
36 typedef struct
38 unsigned initialized : 1;
39 uint32_t pixel;
40 uint16_t red;
41 uint16_t green;
42 uint16_t blue;
43 uint16_t alpha;
44 } xcolor_t;
46 typedef enum
48 AlignLeft = (0),
49 AlignRight = (1),
50 AlignCenter = (1 << 1),
51 AlignTop = (1 << 2),
52 AlignBottom = (1 << 3),
53 AlignFlex = (1 << 4),
54 } alignment_t;
56 typedef struct vector_t vector_t;
57 struct vector_t
59 /** Co-ords of starting point */
60 int16_t x;
61 int16_t y;
62 /** Offset to starting point */
63 int16_t x_offset;
64 int16_t y_offset;
67 typedef struct area_t area_t;
68 struct area_t
70 /** Co-ords of upper left corner */
71 int16_t x;
72 int16_t y;
73 uint16_t width;
74 uint16_t height;
77 DO_ARRAY(area_t, area, DO_NOTHING)
79 #define AREA_LEFT(a) ((a).x)
80 #define AREA_TOP(a) ((a).y)
81 #define AREA_RIGHT(a) ((a).x + (a).width)
82 #define AREA_BOTTOM(a) ((a).y + (a).height)
84 typedef struct
86 PangoFontDescription *desc;
87 int height;
88 } font_t;
90 typedef struct
92 xcb_pixmap_t pixmap;
93 xcb_visualtype_t *visual;
94 uint16_t width;
95 uint16_t height;
96 int phys_screen;
97 uint8_t depth;
98 cairo_t *cr;
99 cairo_surface_t *surface;
100 PangoLayout *layout;
101 xcolor_t fg;
102 xcolor_t bg;
103 } draw_context_t;
105 void draw_context_init(draw_context_t *, int, int, int,
106 xcb_pixmap_t, const xcolor_t *, const xcolor_t *);
108 /** Wipe a draw context.
109 * \param ctx The draw_context_t to wipe.
111 static inline void
112 draw_context_wipe(draw_context_t *ctx)
114 if(ctx->layout)
116 g_object_unref(ctx->layout);
117 ctx->layout = NULL;
119 if(ctx->surface)
121 cairo_surface_destroy(ctx->surface);
122 ctx->surface = NULL;
124 if(ctx->cr)
126 cairo_destroy(ctx->cr);
127 ctx->cr = NULL;
131 font_t *draw_font_new(const char *);
132 void draw_font_delete(font_t **);
134 char * draw_iso2utf8(const char *, size_t);
136 static inline bool
137 a_iso2utf8(char **dest, const char *str, ssize_t len)
139 char *utf8;
140 if((utf8 = draw_iso2utf8(str, len)))
142 *dest = utf8;
143 return true;
145 *dest = a_strdup(str);
146 return false;
149 typedef struct
151 PangoAttrList *attr_list;
152 char *text;
153 ssize_t len;
154 alignment_t align;
155 struct
157 int left, right, top;
158 } margin;
159 struct
161 int top, left;
162 } bg_margin;
163 bool has_bg_color;
164 xcolor_t bg_color;
165 image_t *bg_image;
166 alignment_t bg_align;
167 bool bg_resize;
168 struct
170 int offset;
171 xcolor_t color;
172 } shadow;
173 struct
175 int width;
176 xcolor_t color;
177 } border;
178 } draw_parser_data_t;
180 void draw_text(draw_context_t *, font_t *, PangoEllipsizeMode, PangoWrapMode, area_t, const char *, ssize_t len, draw_parser_data_t *);
181 void draw_rectangle(draw_context_t *, area_t, float, bool, const xcolor_t *);
182 void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t,
183 const xcolor_t *, const xcolor_t *, const xcolor_t *);
185 void draw_graph_setup(draw_context_t *);
186 void draw_graph(draw_context_t *, area_t, int *, int *, int, position_t, vector_t,
187 const xcolor_t *, const xcolor_t *, const xcolor_t *);
188 void draw_graph_line(draw_context_t *, area_t, int *, int, position_t, vector_t,
189 const xcolor_t *, const xcolor_t *, const xcolor_t *);
190 void draw_image(draw_context_t *, int, int, int, image_t *);
191 void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int);
192 area_t draw_text_extents(font_t *, const char *, ssize_t, draw_parser_data_t *);
193 alignment_t draw_align_fromstr(const char *, ssize_t);
194 const char *draw_align_tostr(alignment_t);
196 typedef struct
198 union
200 xcb_alloc_color_cookie_t cookie_hexa;
201 xcb_alloc_named_color_cookie_t cookie_named;
204 uint16_t alpha;
205 xcolor_t *color;
206 bool is_hexa, has_error;
207 const char *colstr;
208 } xcolor_init_request_t;
210 xcolor_init_request_t xcolor_init_unchecked(xcolor_t *, const char *, ssize_t);
211 bool xcolor_init_reply(xcolor_init_request_t);
213 static inline void
214 draw_parser_data_init(draw_parser_data_t *pdata)
216 p_clear(pdata, 1);
219 static inline void
220 draw_parser_data_wipe(draw_parser_data_t *pdata)
222 if(pdata)
224 pango_attr_list_unref(pdata->attr_list);
225 p_delete(&pdata->text);
226 image_unref(&pdata->bg_image);
230 #endif
231 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80