screen: compute screen area with wiboxes strut
[awesome.git] / draw.h
blob0124838bcc0d2412a03dc7b5d1d4d052be81851d
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 AlignMiddle = (1 << 5)
55 } alignment_t;
57 typedef struct vector_t vector_t;
58 struct vector_t
60 /** Co-ords of starting point */
61 int16_t x;
62 int16_t y;
63 /** Offset to starting point */
64 int16_t x_offset;
65 int16_t y_offset;
68 typedef struct area_t area_t;
69 struct area_t
71 /** Co-ords of upper left corner */
72 int16_t x;
73 int16_t y;
74 uint16_t width;
75 uint16_t height;
78 #define AREA_LEFT(a) ((a).x)
79 #define AREA_TOP(a) ((a).y)
80 #define AREA_RIGHT(a) ((a).x + (a).width)
81 #define AREA_BOTTOM(a) ((a).y + (a).height)
83 typedef struct
85 PangoFontDescription *desc;
86 int height;
87 } font_t;
89 typedef struct
91 xcb_pixmap_t pixmap;
92 uint16_t width;
93 uint16_t height;
94 int phys_screen;
95 cairo_t *cr;
96 cairo_surface_t *surface;
97 PangoLayout *layout;
98 xcolor_t fg;
99 xcolor_t bg;
100 } draw_context_t;
102 void draw_context_init(draw_context_t *, int, int, int,
103 xcb_pixmap_t, const xcolor_t *, const xcolor_t *);
105 /** Wipe a draw context.
106 * \param ctx The draw_context_t to wipe.
108 static inline void
109 draw_context_wipe(draw_context_t *ctx)
111 if(ctx->layout)
113 g_object_unref(ctx->layout);
114 ctx->layout = NULL;
116 if(ctx->surface)
118 cairo_surface_destroy(ctx->surface);
119 ctx->surface = NULL;
121 if(ctx->cr)
123 cairo_destroy(ctx->cr);
124 ctx->cr = NULL;
128 font_t *draw_font_new(const char *);
129 void draw_font_delete(font_t **);
131 bool draw_iso2utf8(const char *, size_t, char **, ssize_t *);
133 /** Convert a string to UTF-8.
134 * \param str The string to convert.
135 * \param len The string length.
136 * \param dest The destination string that will be allocated.
137 * \param dlen The destination string length allocated, can be NULL.
138 * \return True if the conversion happened, false otherwise. In both case, dest
139 * and dlen will have value and dest have to be free().
141 static inline bool
142 a_iso2utf8(const char *str, ssize_t len, char **dest, ssize_t *dlen)
144 if(draw_iso2utf8(str, len, dest, dlen))
145 return true;
147 *dest = a_strdup(str);
148 if(dlen)
149 *dlen = len;
151 return false;
154 typedef struct
156 PangoAttrList *attr_list;
157 char *text;
158 ssize_t len;
159 } draw_text_context_t;
161 bool draw_text_context_init(draw_text_context_t *, const char *, ssize_t);
162 void draw_text(draw_context_t *, draw_text_context_t *, PangoEllipsizeMode, PangoWrapMode, alignment_t, padding_t *, area_t, area_t *);
163 void draw_rectangle(draw_context_t *, area_t, float, bool, const color_t *);
164 void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t,
165 const color_t *, const color_t *, const color_t *);
167 void draw_graph_setup(draw_context_t *);
168 void draw_graph(draw_context_t *, area_t, int *, int *, int, position_t, vector_t,
169 const color_t *, const color_t *, const color_t *);
170 void draw_graph_line(draw_context_t *, area_t, int *, int, position_t, vector_t,
171 const color_t *, const color_t *, const color_t *);
172 void draw_image(draw_context_t *, int, int, double, image_t *);
173 void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int);
174 area_t draw_text_extents(draw_text_context_t *);
175 alignment_t draw_align_fromstr(const char *, ssize_t);
176 const char *draw_align_tostr(alignment_t);
178 static inline void
179 draw_text_context_wipe(draw_text_context_t *pdata)
181 if(pdata)
183 if(pdata->attr_list)
184 pango_attr_list_unref(pdata->attr_list);
185 p_delete(&pdata->text);
189 #endif
190 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80