2 * draw.h - draw functions header
4 * Copyright © 2007-2009 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>
32 #include "common/array.h"
38 AlignCenter
= (1 << 1),
40 AlignBottom
= (1 << 3),
41 AlignMiddle
= (1 << 5)
44 typedef struct vector_t vector_t
;
47 /** Co-ords of starting point */
50 /** Offset to starting point */
55 typedef struct area_t area_t
;
58 /** Co-ords of upper left corner */
65 #define AREA_LEFT(a) ((a).x)
66 #define AREA_TOP(a) ((a).y)
67 #define AREA_RIGHT(a) ((a).x + (a).width)
68 #define AREA_BOTTOM(a) ((a).y + (a).height)
72 PangoFontDescription
*desc
;
83 cairo_surface_t
*surface
;
89 void draw_context_init(draw_context_t
*, int, int, int,
90 xcb_pixmap_t
, const xcolor_t
*, const xcolor_t
*);
92 /** Wipe a draw context.
93 * \param ctx The draw_context_t to wipe.
96 draw_context_wipe(draw_context_t
*ctx
)
100 g_object_unref(ctx
->layout
);
105 cairo_surface_destroy(ctx
->surface
);
110 cairo_destroy(ctx
->cr
);
115 font_t
*draw_font_new(const char *);
116 void draw_font_delete(font_t
**);
118 bool draw_iso2utf8(const char *, size_t, char **, ssize_t
*);
120 /** Convert a string to UTF-8.
121 * \param str The string to convert.
122 * \param len The string length.
123 * \param dest The destination string that will be allocated.
124 * \param dlen The destination string length allocated, can be NULL.
125 * \return True if the conversion happened, false otherwise. In both case, dest
126 * and dlen will have value and dest have to be free().
129 a_iso2utf8(const char *str
, ssize_t len
, char **dest
, ssize_t
*dlen
)
131 if(draw_iso2utf8(str
, len
, dest
, dlen
))
134 *dest
= a_strdup(str
);
143 PangoAttrList
*attr_list
;
146 } draw_text_context_t
;
148 bool draw_text_context_init(draw_text_context_t
*, const char *, ssize_t
);
149 void draw_text(draw_context_t
*, draw_text_context_t
*, PangoEllipsizeMode
, PangoWrapMode
, alignment_t
, alignment_t
, area_t
);
150 void draw_rectangle(draw_context_t
*, area_t
, float, bool, const color_t
*);
151 void draw_rectangle_gradient(draw_context_t
*, area_t
, float, bool, vector_t
,
152 const color_t
*, const color_t
*, const color_t
*);
154 void draw_graph_setup(draw_context_t
*);
155 void draw_graph(draw_context_t
*, area_t
, int *, int *, int, position_t
, vector_t
,
156 const color_t
*, const color_t
*, const color_t
*);
157 void draw_graph_line(draw_context_t
*, area_t
, int *, int, position_t
, vector_t
,
158 const color_t
*, const color_t
*, const color_t
*);
159 void draw_image(draw_context_t
*, int, int, double, image_t
*);
160 void draw_rotate(draw_context_t
*, xcb_drawable_t
, xcb_drawable_t
, int, int, int, int, double, int, int);
161 area_t
draw_text_extents(draw_text_context_t
*);
162 alignment_t
draw_align_fromstr(const char *, ssize_t
);
163 const char *draw_align_tostr(alignment_t
);
166 draw_text_context_wipe(draw_text_context_t
*pdata
)
171 pango_attr_list_unref(pdata
->attr_list
);
172 p_delete(&pdata
->text
);
177 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80