Xinqi Bao's Git

removed DDC, all is Draw-dependent
[dwm.git] / draw.c
1 /* See LICENSE file for copyright and license details. */
2 #include <stdlib.h>
3 #include <X11/Xlib.h>
4
5 #include "draw.h"
6
7 Draw *
8 draw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h) {
9 Draw *draw = (Draw *)calloc(1, sizeof(Draw));
10 draw->dpy = dpy;
11 draw->screen = screen;
12 draw->win = win;
13 draw->w = w;
14 draw->h = h;
15 draw->drawable = XCreatePixmap(dpy, win, w, h, DefaultDepth(dpy, screen));
16 draw->gc = XCreateGC(dpy, win, 0, NULL);
17 XSetLineAttributes(dpy, draw->gc, 1, LineSolid, CapButt, JoinMiter);
18 return draw;
19 }
20
21 void
22 draw_resize(Draw *draw, unsigned int w, unsigned int h) {
23 if(!draw)
24 return;
25 draw->w = w;
26 draw->h = h;
27 XFreePixmap(draw->dpy, draw->drawable);
28 draw->drawable = XCreatePixmap(draw->dpy, draw->win, w, h, DefaultDepth(draw->dpy, draw->screen));
29 }
30
31 void
32 draw_free(Draw *draw) {
33 XFreePixmap(draw->dpy, draw->drawable);
34 XFreeGC(draw->dpy, draw->gc);
35 free(draw);
36 }
37
38 Fnt *
39 font_create(const char *fontname) {
40 Fnt *font = (Fnt *)calloc(1, sizeof(Fnt));
41 /* TODO: allocate actual font */
42 return font;
43 }
44
45 void
46 font_free(Fnt *font) {
47 if(!font)
48 return;
49 /* TODO: deallocate any font resources */
50 free(font);
51 }
52
53 Col *
54 col_create(const char *colname) {
55 Col *col = (Col *)calloc(1, sizeof(Col));
56 /* TODO: allocate color */
57 return col;
58 }
59
60 void
61 col_free(Col *col) {
62 if(!col)
63 return;
64 /* TODO: deallocate any color resource */
65 free(col);
66 }
67
68 void
69 draw_setfont(Draw *draw, Fnt *font) {
70 if(!draw || !font)
71 return;
72 draw->font = font;
73 }
74
75 void
76 draw_setfg(Draw *draw, Col *col) {
77 if(!draw || !col)
78 return;
79 draw->fg = col;
80 }
81
82 void
83 draw_setbg(Draw *draw, Col *col) {
84 if(!draw || !col)
85 return;
86 draw->bg = col;
87 }
88
89 void
90 draw_rect(Draw *draw, int x, int y, unsigned int w, unsigned int h) {
91 if(!draw)
92 return;
93 /* TODO: draw the rectangle */
94 }
95
96 void
97 draw_text(Draw *draw, int x, int y, const char *text) {
98 if(!draw)
99 return;
100 /* TODO: draw the text */
101 }
102
103 void
104 draw_map(Draw *draw, int x, int y, unsigned int w, unsigned int h) {
105 if(!draw)
106 return;
107 /* TODO: map the draw contents in the region */
108 }
109
110 void
111 draw_getextents(Draw *draw, const char *text, TextExtents *extents) {
112 if(!draw || !extents)
113 return;
114 /* TODO: get extents */
115 }