ewmh: fix toggle on maximized_horizontal
[awesome.git] / draw.h
blobf57ad241e5a76ee3304a2e63af7c054cc9e055ba
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 xcb_pixmap_t pixmap;
73 uint16_t width;
74 uint16_t height;
75 int phys_screen;
76 cairo_t *cr;
77 cairo_surface_t *surface;
78 PangoLayout *layout;
79 xcolor_t fg;
80 xcolor_t bg;
81 } draw_context_t;
83 void draw_context_init(draw_context_t *, int, int, int,
84 xcb_pixmap_t, const xcolor_t *, const xcolor_t *);
86 /** Wipe a draw context.
87 * \param ctx The draw_context_t to wipe.
89 static inline void
90 draw_context_wipe(draw_context_t *ctx)
92 if(ctx->layout)
94 g_object_unref(ctx->layout);
95 ctx->layout = NULL;
97 if(ctx->surface)
99 cairo_surface_destroy(ctx->surface);
100 ctx->surface = NULL;
102 if(ctx->cr)
104 cairo_destroy(ctx->cr);
105 ctx->cr = NULL;
109 bool draw_iso2utf8(const char *, size_t, char **, ssize_t *);
111 /** Convert a string to UTF-8.
112 * \param str The string to convert.
113 * \param len The string length.
114 * \param dest The destination string that will be allocated.
115 * \param dlen The destination string length allocated, can be NULL.
116 * \return True if the conversion happened, false otherwise. In both case, dest
117 * and dlen will have value and dest have to be free().
119 static inline bool
120 a_iso2utf8(const char *str, ssize_t len, char **dest, ssize_t *dlen)
122 if(draw_iso2utf8(str, len, dest, dlen))
123 return true;
125 *dest = a_strdup(str);
126 if(dlen)
127 *dlen = len;
129 return false;
132 typedef struct
134 PangoAttrList *attr_list;
135 char *text;
136 ssize_t len;
137 } draw_text_context_t;
139 bool draw_text_context_init(draw_text_context_t *, const char *, ssize_t);
140 void draw_text(draw_context_t *, draw_text_context_t *, PangoEllipsizeMode, PangoWrapMode, alignment_t, alignment_t, area_t);
141 void draw_rectangle(draw_context_t *, area_t, float, bool, const color_t *);
142 void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t,
143 const color_t *, const color_t *, const color_t *);
145 void draw_graph_setup(draw_context_t *);
146 void draw_graph(draw_context_t *, area_t, int *, int *, int, position_t, vector_t,
147 const color_t *, const color_t *, const color_t *);
148 void draw_graph_line(draw_context_t *, area_t, int *, int, position_t, vector_t,
149 const color_t *, const color_t *, const color_t *);
150 void draw_image(draw_context_t *, int, int, double, image_t *);
151 void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int);
152 area_t draw_text_extents(draw_text_context_t *);
153 alignment_t draw_align_fromstr(const char *, ssize_t);
154 const char *draw_align_tostr(alignment_t);
156 static inline void
157 draw_text_context_wipe(draw_text_context_t *pdata)
159 if(pdata)
161 if(pdata->attr_list)
162 pango_attr_list_unref(pdata->attr_list);
163 p_delete(&pdata->text);
167 #endif
168 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80