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 #define AREA_LEFT(a) ((a).x)
81 #define AREA_TOP(a) ((a).y)
82 #define AREA_RIGHT(a) ((a).x + (a).width)
83 #define AREA_BOTTOM(a) ((a).y + (a).height)
87 PangoFontDescription
*desc
;
94 xcb_visualtype_t
*visual
;
100 cairo_surface_t
*surface
;
106 void draw_context_init(draw_context_t
*, int, int, int,
107 xcb_pixmap_t
, const xcolor_t
*, const xcolor_t
*);
109 /** Wipe a draw context.
110 * \param ctx The draw_context_t to wipe.
113 draw_context_wipe(draw_context_t
*ctx
)
117 g_object_unref(ctx
->layout
);
122 cairo_surface_destroy(ctx
->surface
);
127 cairo_destroy(ctx
->cr
);
132 font_t
*draw_font_new(const char *);
133 void draw_font_delete(font_t
**);
135 bool draw_iso2utf8(const char *, size_t, char **, ssize_t
*);
137 /** Convert a string to UTF-8.
138 * \param str The string to convert.
139 * \param len The string length.
140 * \param dest The destination string that will be allocated.
141 * \param dlen The destination string length allocated, can be NULL.
142 * \return True if the conversion happened, false otherwise. In both case, dest
143 * and dlen will have value and dest have to be free().
146 a_iso2utf8(const char *str
, ssize_t len
, char **dest
, ssize_t
*dlen
)
148 if(draw_iso2utf8(str
, len
, dest
, dlen
))
151 *dest
= a_strdup(str
);
160 PangoAttrList
*attr_list
;
163 } draw_text_context_t
;
165 bool draw_text_context_init(draw_text_context_t
*, const char *, ssize_t
);
166 void draw_text(draw_context_t
*, draw_text_context_t
*, PangoEllipsizeMode
, PangoWrapMode
, alignment_t
, padding_t
*, area_t
, area_t
*);
167 void draw_rectangle(draw_context_t
*, area_t
, float, bool, const color_t
*);
168 void draw_rectangle_gradient(draw_context_t
*, area_t
, float, bool, vector_t
,
169 const color_t
*, const color_t
*, const color_t
*);
171 void draw_graph_setup(draw_context_t
*);
172 void draw_graph(draw_context_t
*, area_t
, int *, int *, int, position_t
, vector_t
,
173 const color_t
*, const color_t
*, const color_t
*);
174 void draw_graph_line(draw_context_t
*, area_t
, int *, int, position_t
, vector_t
,
175 const color_t
*, const color_t
*, const color_t
*);
176 void draw_image(draw_context_t
*, int, int, double, image_t
*);
177 void draw_rotate(draw_context_t
*, xcb_drawable_t
, xcb_drawable_t
, int, int, int, int, double, int, int);
178 area_t
draw_text_extents(draw_text_context_t
*);
179 alignment_t
draw_align_fromstr(const char *, ssize_t
);
180 const char *draw_align_tostr(alignment_t
);
183 draw_text_context_wipe(draw_text_context_t
*pdata
)
188 pango_attr_list_unref(pdata
->attr_list
);
189 p_delete(&pdata
->text
);
194 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80