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
26 #include <pango/pangocairo.h>
31 #include "common/array.h"
38 /** Padding at bottom */
40 /** Padding at left */
42 /** Padding at right */
48 unsigned initialized
: 1;
60 AlignCenter
= (1 << 1),
62 AlignBottom
= (1 << 3),
64 AlignFixed
= (1 << 5),
67 typedef struct vector_t vector_t
;
70 /** Co-ords of starting point */
73 /** Offset to starting point */
78 typedef struct area_t area_t
;
81 /** Co-ords of upper left corner */
88 DO_ARRAY(area_t
, area
, DO_NOTHING
)
90 #define AREA_LEFT(a) ((a).x)
91 #define AREA_TOP(a) ((a).y)
92 #define AREA_RIGHT(a) ((a).x + (a).width)
93 #define AREA_BOTTOM(a) ((a).y + (a).height)
97 PangoFontDescription
*desc
;
104 xcb_visualtype_t
*visual
;
110 cairo_surface_t
*surface
;
116 void draw_context_init(draw_context_t
*, int, int, int,
117 xcb_pixmap_t
, const xcolor_t
*, const xcolor_t
*);
119 /** Wipe a draw context.
120 * \param ctx The draw_context_t to wipe.
123 draw_context_wipe(draw_context_t
*ctx
)
127 g_object_unref(ctx
->layout
);
132 cairo_surface_destroy(ctx
->surface
);
137 cairo_destroy(ctx
->cr
);
142 font_t
*draw_font_new(const char *);
143 void draw_font_delete(font_t
**);
145 bool draw_iso2utf8(const char *, size_t, char **, ssize_t
*);
147 /** Convert a string to UTF-8.
148 * \param str The string to convert.
149 * \param len The string length.
150 * \param dest The destination string that will be allocated.
151 * \param dlen The destination string length allocated, can be NULL.
152 * \return True if the conversion happened, false otherwise. In both case, dest
153 * and dlen will have value and dest have to be free().
156 a_iso2utf8(const char *str
, ssize_t len
, char **dest
, ssize_t
*dlen
)
158 if(draw_iso2utf8(str
, len
, dest
, dlen
))
161 *dest
= a_strdup(str
);
170 PangoAttrList
*attr_list
;
173 } draw_text_context_t
;
175 bool draw_text_context_init(draw_text_context_t
*, const char *, ssize_t
);
176 void draw_text(draw_context_t
*, draw_text_context_t
*, PangoEllipsizeMode
, PangoWrapMode
, alignment_t
, padding_t
*, area_t
, area_t
*);
177 void draw_rectangle(draw_context_t
*, area_t
, float, bool, const xcolor_t
*);
178 void draw_rectangle_gradient(draw_context_t
*, area_t
, float, bool, vector_t
,
179 const xcolor_t
*, const xcolor_t
*, const xcolor_t
*);
181 void draw_graph_setup(draw_context_t
*);
182 void draw_graph(draw_context_t
*, area_t
, int *, int *, int, position_t
, vector_t
,
183 const xcolor_t
*, const xcolor_t
*, const xcolor_t
*);
184 void draw_graph_line(draw_context_t
*, area_t
, int *, int, position_t
, vector_t
,
185 const xcolor_t
*, const xcolor_t
*, const xcolor_t
*);
186 void draw_image(draw_context_t
*, int, int, double, image_t
*);
187 void draw_rotate(draw_context_t
*, xcb_drawable_t
, xcb_drawable_t
, int, int, int, int, double, int, int);
188 area_t
draw_text_extents(draw_text_context_t
*);
189 alignment_t
draw_align_fromstr(const char *, ssize_t
);
190 const char *draw_align_tostr(alignment_t
);
196 xcb_alloc_color_cookie_t cookie_hexa
;
197 xcb_alloc_named_color_cookie_t cookie_named
;
202 bool is_hexa
, has_error
;
204 } xcolor_init_request_t
;
206 xcolor_init_request_t
xcolor_init_unchecked(xcolor_t
*, const char *, ssize_t
);
207 bool xcolor_init_reply(xcolor_init_request_t
);
210 draw_text_context_wipe(draw_text_context_t
*pdata
)
215 pango_attr_list_unref(pdata
->attr_list
);
216 p_delete(&pdata
->text
);
221 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80