Add Xft and follback-fonts support to graphics lib
[dwm.git] / drw.h
1 /* See LICENSE file for copyright and license details. */
2 #define DRW_FONT_CACHE_SIZE 32
3
4 typedef struct {
5 unsigned long pix;
6 XftColor rgb;
7 } Clr;
8
9 typedef struct {
10 Cursor cursor;
11 } Cur;
12
13 typedef struct {
14 Display *dpy;
15 int ascent;
16 int descent;
17 unsigned int h;
18 XftFont *xfont;
19 FcPattern *pattern;
20 } Fnt;
21
22 typedef struct {
23 Clr *fg;
24 Clr *bg;
25 Clr *border;
26 } ClrScheme;
27
28 typedef struct {
29 unsigned int w, h;
30 Display *dpy;
31 int screen;
32 Window root;
33 Drawable drawable;
34 GC gc;
35 ClrScheme *scheme;
36 size_t fontcount;
37 Fnt *fonts[DRW_FONT_CACHE_SIZE];
38 } Drw;
39
40 typedef struct {
41 unsigned int w;
42 unsigned int h;
43 } Extnts;
44
45 /* Drawable abstraction */
46 Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
47 void drw_resize(Drw *drw, unsigned int w, unsigned int h);
48 void drw_free(Drw *drw);
49
50 /* Fnt abstraction */
51 Fnt *drw_font_create(Drw *drw, const char *fontname);
52 void drw_load_fonts(Drw* drw, const char *fonts[], size_t fontcount);
53 void drw_font_free(Fnt *font);
54 void drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *extnts);
55 unsigned int drw_font_getexts_width(Fnt *font, const char *text, unsigned int len);
56
57 /* Colour abstraction */
58 Clr *drw_clr_create(Drw *drw, const char *clrname);
59 void drw_clr_free(Clr *clr);
60
61 /* Cursor abstraction */
62 Cur *drw_cur_create(Drw *drw, int shape);
63 void drw_cur_free(Drw *drw, Cur *cursor);
64
65 /* Drawing context manipulation */
66 void drw_setfont(Drw *drw, Fnt *font);
67 void drw_setscheme(Drw *drw, ClrScheme *scheme);
68
69 /* Drawing functions */
70 void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert);
71 int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, int invert);
72
73 /* Map functions */
74 void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);