key: move grabbing code to window
[awesome.git] / draw.h
blob29260d0ef28d2bf529c7ef6c7336648a927907e4
1 /*
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
25 #include <cairo.h>
26 #include <pango/pangocairo.h>
28 #include <xcb/xcb.h>
30 #include "image.h"
31 #include "color.h"
32 #include "common/array.h"
34 typedef enum
36 AlignLeft = (0),
37 AlignRight = (1),
38 AlignCenter = (1 << 1),
39 AlignTop = (1 << 2),
40 AlignBottom = (1 << 3),
41 AlignMiddle = (1 << 5)
42 } alignment_t;
44 typedef struct vector_t vector_t;
45 struct vector_t
47 /** Co-ords of starting point */
48 int16_t x;
49 int16_t y;
50 /** Offset to starting point */
51 int16_t x_offset;
52 int16_t y_offset;
55 typedef struct area_t area_t;
56 struct area_t
58 /** Co-ords of upper left corner */
59 int16_t x;
60 int16_t y;
61 uint16_t width;
62 uint16_t height;
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)
70 typedef struct
72 PangoFontDescription *desc;
73 int height;
74 } font_t;
76 typedef struct
78 xcb_pixmap_t pixmap;
79 uint16_t width;
80 uint16_t height;
81 int phys_screen;
82 cairo_t *cr;
83 cairo_surface_t *surface;
84 PangoLayout *layout;
85 xcolor_t fg;
86 xcolor_t bg;
87 } draw_context_t;
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.
95 static inline void
96 draw_context_wipe(draw_context_t *ctx)
98 if(ctx->layout)
100 g_object_unref(ctx->layout);
101 ctx->layout = NULL;
103 if(ctx->surface)
105 cairo_surface_destroy(ctx->surface);
106 ctx->surface = NULL;
108 if(ctx->cr)
110 cairo_destroy(ctx->cr);
111 ctx->cr = NULL;
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().
128 static inline bool
129 a_iso2utf8(const char *str, ssize_t len, char **dest, ssize_t *dlen)
131 if(draw_iso2utf8(str, len, dest, dlen))
132 return true;
134 *dest = a_strdup(str);
135 if(dlen)
136 *dlen = len;
138 return false;
141 typedef struct
143 PangoAttrList *attr_list;
144 char *text;
145 ssize_t len;
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);
165 static inline void
166 draw_text_context_wipe(draw_text_context_t *pdata)
168 if(pdata)
170 if(pdata->attr_list)
171 pango_attr_list_unref(pdata->attr_list);
172 p_delete(&pdata->text);
176 #endif
177 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80