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>
32 #include "common/array.h"
39 /** Padding at bottom */
41 /** Padding at left */
43 /** Padding at right */
51 AlignCenter
= (1 << 1),
53 AlignBottom
= (1 << 3),
55 AlignFixed
= (1 << 5),
56 AlignMiddle
= (1 << 6)
59 typedef struct vector_t vector_t
;
62 /** Co-ords of starting point */
65 /** Offset to starting point */
70 typedef struct area_t area_t
;
73 /** Co-ords of upper left corner */
80 DO_ARRAY(area_t
, area
, DO_NOTHING
)
82 #define AREA_LEFT(a) ((a).x)
83 #define AREA_TOP(a) ((a).y)
84 #define AREA_RIGHT(a) ((a).x + (a).width)
85 #define AREA_BOTTOM(a) ((a).y + (a).height)
89 PangoFontDescription
*desc
;
96 xcb_visualtype_t
*visual
;
102 cairo_surface_t
*surface
;
108 void draw_context_init(draw_context_t
*, int, int, int,
109 xcb_pixmap_t
, const xcolor_t
*, const xcolor_t
*);
111 /** Wipe a draw context.
112 * \param ctx The draw_context_t to wipe.
115 draw_context_wipe(draw_context_t
*ctx
)
119 g_object_unref(ctx
->layout
);
124 cairo_surface_destroy(ctx
->surface
);
129 cairo_destroy(ctx
->cr
);
134 font_t
*draw_font_new(const char *);
135 void draw_font_delete(font_t
**);
137 bool draw_iso2utf8(const char *, size_t, char **, ssize_t
*);
139 /** Convert a string to UTF-8.
140 * \param str The string to convert.
141 * \param len The string length.
142 * \param dest The destination string that will be allocated.
143 * \param dlen The destination string length allocated, can be NULL.
144 * \return True if the conversion happened, false otherwise. In both case, dest
145 * and dlen will have value and dest have to be free().
148 a_iso2utf8(const char *str
, ssize_t len
, char **dest
, ssize_t
*dlen
)
150 if(draw_iso2utf8(str
, len
, dest
, dlen
))
153 *dest
= a_strdup(str
);
162 PangoAttrList
*attr_list
;
165 } draw_text_context_t
;
167 bool draw_text_context_init(draw_text_context_t
*, const char *, ssize_t
);
168 void draw_text(draw_context_t
*, draw_text_context_t
*, PangoEllipsizeMode
, PangoWrapMode
, alignment_t
, padding_t
*, area_t
, area_t
*);
169 void draw_rectangle(draw_context_t
*, area_t
, float, bool, const color_t
*);
170 void draw_rectangle_gradient(draw_context_t
*, area_t
, float, bool, vector_t
,
171 const color_t
*, const color_t
*, const color_t
*);
173 void draw_graph_setup(draw_context_t
*);
174 void draw_graph(draw_context_t
*, area_t
, int *, int *, int, position_t
, vector_t
,
175 const color_t
*, const color_t
*, const color_t
*);
176 void draw_graph_line(draw_context_t
*, area_t
, int *, int, position_t
, vector_t
,
177 const color_t
*, const color_t
*, const color_t
*);
178 void draw_image(draw_context_t
*, int, int, double, image_t
*);
179 void draw_rotate(draw_context_t
*, xcb_drawable_t
, xcb_drawable_t
, int, int, int, int, double, int, int);
180 area_t
draw_text_extents(draw_text_context_t
*);
181 alignment_t
draw_align_fromstr(const char *, ssize_t
);
182 const char *draw_align_tostr(alignment_t
);
185 draw_text_context_wipe(draw_text_context_t
*pdata
)
190 pango_attr_list_unref(pdata
->attr_list
);
191 p_delete(&pdata
->text
);
196 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80