build: man path is now configurable
[awesome.git] / common / draw.h
blobdd0a43080323158b79c261384efd7d1481ac186f
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 "common/array.h"
31 #include "common/list.h"
32 #include "common/buffer.h"
34 typedef struct
36 unsigned initialized : 1;
37 uint32_t pixel;
38 uint16_t red;
39 uint16_t green;
40 uint16_t blue;
41 uint16_t alpha;
42 } xcolor_t;
44 typedef enum
46 AlignLeft = 0,
47 AlignRight,
48 AlignCenter,
49 AlignFlex,
50 AlignAuto
51 } alignment_t;
53 typedef struct vector_t vector_t;
54 struct vector_t
56 /** Co-ords of starting point */
57 int16_t x;
58 int16_t y;
59 /** Offset to starting point */
60 int16_t x_offset;
61 int16_t y_offset;
64 typedef struct area_t area_t;
65 struct area_t
67 /** Co-ords of upper left corner */
68 int16_t x;
69 int16_t y;
70 uint16_t width;
71 uint16_t height;
74 DO_ARRAY(area_t, area, DO_NOTHING)
76 #define AREA_LEFT(a) ((a).x)
77 #define AREA_TOP(a) ((a).y)
78 #define AREA_RIGHT(a) ((a).x + (a).width)
79 #define AREA_BOTTOM(a) ((a).y + (a).height)
81 static inline bool
82 area_intersect_area(area_t a, area_t b)
84 return (b.x < a.x + a.width
85 && b.x + b.width > a.x
86 && b.y < a.y + a.height
87 && b.y + b.height > a.y);
90 static inline area_t
91 area_get_intersect_area(area_t a, area_t b)
93 area_t g;
95 g.x = MAX(a.x, b.x);
96 g.y = MAX(a.y, b.y);
97 g.width = MIN(a.x + a.width, b.x + b.width) - g.x;
98 g.height = MIN(a.y + a.height, b.y + b.height) - g.y;
100 return g;
103 typedef struct
105 PangoFontDescription *desc;
106 int height;
107 } font_t;
109 typedef struct
111 xcb_connection_t *connection;
112 xcb_pixmap_t pixmap;
113 xcb_visualtype_t *visual;
114 int width;
115 int height;
116 int phys_screen;
117 int depth;
118 cairo_t *cr;
119 cairo_surface_t *surface;
120 PangoLayout *layout;
121 xcolor_t fg;
122 xcolor_t bg;
123 } draw_context_t;
125 typedef struct
127 void *data;
128 size_t width;
129 size_t height;
130 } draw_image_t;
132 draw_context_t *
133 draw_context_new(xcb_connection_t *, int, int, int, xcb_drawable_t,
134 const xcolor_t *, const xcolor_t*);
136 /** Delete a draw context.
137 * \param ctx The draw_context_t to delete.
139 static inline void
140 draw_context_delete(draw_context_t **ctx)
142 if(*ctx)
144 if((*ctx)->layout)
145 g_object_unref((*ctx)->layout);
146 if((*ctx)->surface)
147 cairo_surface_destroy((*ctx)->surface);
148 if((*ctx)->cr)
149 cairo_destroy((*ctx)->cr);
150 p_delete(ctx);
154 font_t *draw_font_new(xcb_connection_t *, int, const char *);
155 void draw_font_delete(font_t **);
157 char * draw_iso2utf8(const char *, size_t);
159 static inline bool
160 a_iso2utf8(char **dest, const char *str, ssize_t len)
162 char *utf8;
163 if((utf8 = draw_iso2utf8(str, len)))
165 *dest = utf8;
166 return true;
168 *dest = a_strdup(str);
169 return false;
172 typedef struct
174 xcb_connection_t *connection;
175 int phys_screen;
176 buffer_t text;
177 alignment_t align;
178 struct
180 int left, right;
181 } margin;
182 bool has_bg_color;
183 xcolor_t bg_color;
184 draw_image_t *bg_image;
185 alignment_t bg_align;
186 bool bg_resize;
187 struct
189 int offset;
190 xcolor_t color;
191 } shadow;
192 struct
194 int width;
195 xcolor_t color;
196 } border;
197 } draw_parser_data_t;
199 void draw_parser_data_init(draw_parser_data_t *);
200 void draw_parser_data_wipe(draw_parser_data_t *);
202 bool draw_text_markup_expand(draw_parser_data_t *, const char *, ssize_t);
204 void draw_text(draw_context_t *, font_t *, area_t, const char *, ssize_t len, draw_parser_data_t *);
205 void draw_rectangle(draw_context_t *, area_t, float, bool, const xcolor_t *);
206 void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t,
207 const xcolor_t *, const xcolor_t *, const xcolor_t *);
209 void draw_graph_setup(draw_context_t *);
210 void draw_graph(draw_context_t *, area_t, int *, int *, int, position_t, vector_t,
211 const xcolor_t *, const xcolor_t *, const xcolor_t *);
212 void draw_graph_line(draw_context_t *, area_t, int *, int, position_t, vector_t,
213 const xcolor_t *, const xcolor_t *, const xcolor_t *);
214 draw_image_t *draw_image_new(const char *);
215 void draw_image_delete(draw_image_t **);
216 void draw_image(draw_context_t *, int, int, int, draw_image_t *);
217 void draw_image_from_argb_data(draw_context_t *, int, int, int, int, int, unsigned char *);
218 void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int);
219 area_t draw_text_extents(xcb_connection_t *, int, font_t *, const char *, ssize_t, draw_parser_data_t *);
220 alignment_t draw_align_fromstr(const char *, ssize_t);
221 const char *draw_align_tostr(alignment_t);
223 typedef struct
225 union
227 xcb_alloc_color_cookie_t cookie_hexa;
228 xcb_alloc_named_color_cookie_t cookie_named;
231 uint16_t alpha;
232 xcolor_t *color;
233 bool is_hexa, has_error;
234 const char *colstr;
235 } xcolor_init_request_t;
237 xcolor_init_request_t xcolor_init_unchecked(xcb_connection_t *, xcolor_t *, int,
238 const char *, ssize_t);
240 bool xcolor_init_reply(xcb_connection_t *, xcolor_init_request_t);
242 void area_array_remove(area_array_t *, area_t);
244 #endif
245 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80