JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
continued, distinction of Draw and DDC is bad, needs to be merged
[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 DDC *
39 dc_create(Draw *draw) {
40         DDC *dc = (DDC *)calloc(1, sizeof(DDC));
41         dc->draw = draw;
42         dc->next = draw->dc;
43         draw->dc = dc;
44         return dc;
45 }
46
47 void
48 dc_free(DDC *dc) {
49         DDC **tdc;
50
51         if(!dc)
52                 return;
53         /* remove from dc list */
54         for(tdc = &dc->draw->dc; *tdc && *tdc != dc; tdc = &(*tdc)->next);
55         *tdc = dc->next;
56         /* TODO: deallocate any resources of this dc, if needed */
57         free(dc);
58 }
59
60 Fnt *
61 font_create(const char *fontname) {
62         Fnt *font = (Fnt *)calloc(1, sizeof(Fnt));
63         /* TODO: allocate actual font */
64         return font;
65 }
66
67 void
68 font_free(Fnt *font) {
69         if(!font)
70                 return;
71         /* TODO: deallocate any font resources */
72         free(font);
73 }
74
75 Col *
76 col_create(const char *colname) {
77         Col *col = (Col *)calloc(1, sizeof(Col));
78         /* TODO: allocate color */
79         return col;
80 }
81
82 void
83 col_free(Col *col) {
84         if(!col)
85                 return;
86         /* TODO: deallocate any color resource */
87         free(col);
88 }
89
90 void
91 dc_setfont(DDC *dc, Fnt *font) {
92         if(!dc || !font)
93                 return;
94         dc->font = font;
95 }
96
97 void
98 dc_setfg(DDC *dc, Col *col) {
99         if(!dc || !col) 
100                 return;
101         dc->fg = col;
102 }
103
104 void
105 dc_setbg(DDC *dc, Col *col) {
106         if(!dc || !col)
107                 return;
108         dc->bg = col;
109 }
110
111 void
112 dc_setfill(DDC *dc, Bool fill) {
113         if(!dc)
114                 return;
115         dc->fill = fill;
116 }
117
118 void
119 dc_drawrect(DDC *dc, int x, int y, unsigned int w, unsigned int h) {
120         if(!dc)
121                 return;
122         /* TODO: draw the rectangle */
123 }
124
125 void
126 dc_drawtext(DDC *dc, int x, int y, const char *text) {
127         if(!dc)
128                 return;
129         /* TODO: draw the text */
130 }
131
132 void
133 dc_map(DDC *dc, int x, int y, unsigned int w, unsigned int h) {
134         if(!dc)
135                 return;
136         /* TODO: map the dc contents in the region */
137 }
138
139 void
140 dc_getextents(DDC *dc, const char *text, TextExtents *extents) {
141         if(!dc || !extents)
142                 return;
143         /* TODO: get extents */
144 }