change codename
[awesome.git] / draw.h
bloba2763941a4f5f7b10f1857929b9f176f585ebcf6
1 /*
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
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 /** Padding type */
35 typedef struct
37 /** Padding at top */
38 int top;
39 /** Padding at bottom */
40 int bottom;
41 /** Padding at left */
42 int left;
43 /** Padding at right */
44 int right;
45 } padding_t;
47 typedef enum
49 AlignLeft = (0),
50 AlignRight = (1),
51 AlignCenter = (1 << 1),
52 AlignTop = (1 << 2),
53 AlignBottom = (1 << 3),
54 AlignFlex = (1 << 4),
55 AlignFixed = (1 << 5),
56 AlignMiddle = (1 << 6)
57 } alignment_t;
59 typedef struct vector_t vector_t;
60 struct vector_t
62 /** Co-ords of starting point */
63 int16_t x;
64 int16_t y;
65 /** Offset to starting point */
66 int16_t x_offset;
67 int16_t y_offset;
70 typedef struct area_t area_t;
71 struct area_t
73 /** Co-ords of upper left corner */
74 int16_t x;
75 int16_t y;
76 uint16_t width;
77 uint16_t height;
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)
87 typedef struct
89 PangoFontDescription *desc;
90 int height;
91 } font_t;
93 typedef struct
95 xcb_pixmap_t pixmap;
96 xcb_visualtype_t *visual;
97 uint16_t width;
98 uint16_t height;
99 int phys_screen;
100 uint8_t depth;
101 cairo_t *cr;
102 cairo_surface_t *surface;
103 PangoLayout *layout;
104 xcolor_t fg;
105 xcolor_t bg;
106 } draw_context_t;
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.
114 static inline void
115 draw_context_wipe(draw_context_t *ctx)
117 if(ctx->layout)
119 g_object_unref(ctx->layout);
120 ctx->layout = NULL;
122 if(ctx->surface)
124 cairo_surface_destroy(ctx->surface);
125 ctx->surface = NULL;
127 if(ctx->cr)
129 cairo_destroy(ctx->cr);
130 ctx->cr = NULL;
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().
147 static inline bool
148 a_iso2utf8(const char *str, ssize_t len, char **dest, ssize_t *dlen)
150 if(draw_iso2utf8(str, len, dest, dlen))
151 return true;
153 *dest = a_strdup(str);
154 if(dlen)
155 *dlen = len;
157 return false;
160 typedef struct
162 PangoAttrList *attr_list;
163 char *text;
164 ssize_t len;
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);
184 static inline void
185 draw_text_context_wipe(draw_text_context_t *pdata)
187 if(pdata)
189 if(pdata->attr_list)
190 pango_attr_list_unref(pdata->attr_list);
191 p_delete(&pdata->text);
195 #endif
196 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80