summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranselm@garbe.us <unknown>2012-11-18 12:04:29 +0100
committeranselm@garbe.us <unknown>2012-11-18 12:04:29 +0100
commitd456617f0eb93df0ec8eb81ff6e04ca988c09c60 (patch)
tree91fdfc4934a640bc937e2524cff16d60cc6862a5
parentreverting to plain X11 fonts in order to implement draw.c default (diff)
downloaddwm-d456617f0eb93df0ec8eb81ff6e04ca988c09c60.tar.gz
dwm-d456617f0eb93df0ec8eb81ff6e04ca988c09c60.zip
basic draw.c structure
-rw-r--r--Makefile2
-rw-r--r--draw.c139
-rw-r--r--draw.h14
3 files changed, 149 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index b139b54..ce6e508 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
3 3
4include config.mk 4include config.mk
5 5
6SRC = dwm.c 6SRC = draw.c dwm.c
7OBJ = ${SRC:.c=.o} 7OBJ = ${SRC:.c=.o}
8 8
9all: options dwm 9all: options dwm
diff --git a/draw.c b/draw.c
new file mode 100644
index 0000000..04e7f0d
--- /dev/null
+++ b/draw.c
@@ -0,0 +1,139 @@
1/* See LICENSE file for copyright and license details. */
2#include <stdlib.h>
3#include <X11/Xlib.h>
4
5#include "draw.h"
6
7Draw *
8draw_create(Display *dpy, Window win, unsigned int w, unsigned int h) {
9 Draw *draw = (Draw *)calloc(1, sizeof(Draw));
10 draw->w = w;
11 draw->h = h;
12 /* TODO: drawable creation */
13 /* TODO: gc allocation */
14 return draw;
15}
16
17void
18draw_resize(Draw *draw, unsigned int w, unsigned int h) {
19 if(!draw)
20 return;
21 draw->w = w;
22 draw->h = h;
23 /* TODO: resize drawable */
24}
25
26void
27draw_free(Draw *draw) {
28 /* TODO: deallocate DDCs */
29 /* TODO: deallocate drawable */
30 free(draw);
31}
32
33DDC *
34dc_create(Draw *draw) {
35 DDC *dc = (DDC *)calloc(1, sizeof(DDC));
36 dc->draw = draw;
37 dc->next = draw->dc;
38 draw->dc = dc;
39 return dc;
40}
41
42void
43dc_free(DDC *dc) {
44 DDC **tdc;
45
46 if(!dc)
47 return;
48 /* remove from dc list */
49 for(tdc = &dc->draw->dc; *tdc && *tdc != dc; tdc = &(*tdc)->next);
50 *tdc = dc->next;
51 /* TODO: deallocate any resources of this dc, if needed */
52 free(dc);
53}
54
55Fnt *
56font_create(const char *fontname) {
57 Fnt *font = (Fnt *)calloc(1, sizeof(Fnt));
58 /* TODO: allocate actual font */
59 return font;
60}
61
62void
63font_free(Fnt *font) {
64 if(!font)
65 return;
66 /* TODO: deallocate any font resources */
67 free(font);
68}
69
70Col *
71col_create(const char *colname) {
72 Col *col = (Col *)calloc(1, sizeof(Col));
73 /* TODO: allocate color */
74 return col;
75}
76
77void
78col_free(Col *col) {
79 if(!col)
80 return;
81 /* TODO: deallocate any color resource */
82 free(col);
83}
84
85void
86dc_setfont(DDC *dc, Fnt *font) {
87 if(!dc || !font)
88 return;
89 dc->font = font;
90}
91
92void
93dc_setfg(DDC *dc, Col *col) {
94 if(!dc || !col)
95 return;
96 dc->fg = col;
97}
98
99void
100dc_setbg(DDC *dc, Col *col) {
101 if(!dc || !col)
102 return;
103 dc->bg = col;
104}
105
106void
107dc_setfill(DDC *dc, Bool fill) {
108 if(!dc)
109 return;
110 dc->fill = fill;
111}
112
113void
114dc_drawrect(DDC *dc, int x, int y, unsigned int w, unsigned int h) {
115 if(!dc)
116 return;
117 /* TODO: draw the rectangle */
118}
119
120void
121dc_drawtext(DDC *dc, int x, int y, const char *text) {
122 if(!dc)
123 return;
124 /* TODO: draw the text */
125}
126
127void
128dc_map(DDC *dc, int x, int y, unsigned int w, unsigned int h) {
129 if(!dc)
130 return;
131 /* TODO: map the dc contents in the region */
132}
133
134void
135dc_getextents(DDC *dc, const char *text, TextExtents *extents) {
136 if(!dc || !extents)
137 return;
138 /* TODO: get extents */
139}
diff --git a/draw.h b/draw.h
index 955067d..9aec43d 100644
--- a/draw.h
+++ b/draw.h
@@ -1,13 +1,16 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2 2
3typedef struct _DDC DDC;
4
3/* X11 types - begin */ 5/* X11 types - begin */
6typedef struct _XDraw Draw;
4struct _XDraw { 7struct _XDraw {
5 unsigned int w, h; 8 unsigned int w, h;
6 Display *dpy; 9 Display *dpy;
7 Drawable drawable; 10 Drawable drawable;
8 GC gc; 11 GC gc;
12 DDC *dc;
9}; 13};
10typedef struct _XDraw Draw;
11 14
12struct _XCol { 15struct _XCol {
13 unsigned long rgb; 16 unsigned long rgb;
@@ -24,13 +27,14 @@ struct _XFont {
24typedef struct _XFont Fnt; 27typedef struct _XFont Fnt;
25/* X11 types - end */ 28/* X11 types - end */
26 29
27typedef struct { 30struct _DDC {
28 Draw *draw; 31 Draw *draw;
29 Col *fg; 32 Col *fg;
30 Col *bg; 33 Col *bg;
31 Fnt *font; 34 Fnt *font;
32 Bool fill; 35 Bool fill;
33} DDC; 36 DDC *next;
37};
34 38
35typedef struct { 39typedef struct {
36 unsigned int w; 40 unsigned int w;
@@ -60,8 +64,8 @@ void col_free(Col *col);
60 64
61/* Drawing context manipulation */ 65/* Drawing context manipulation */
62void dc_setfont(DDC *dc, Fnt *font); 66void dc_setfont(DDC *dc, Fnt *font);
63void dc_setfg(DDC *dc, Col col); 67void dc_setfg(DDC *dc, Col *col);
64void dc_setbg(DDC *dc, Col col); 68void dc_setbg(DDC *dc, Col *col);
65void dc_setfill(DDC *dc, Bool fill); 69void dc_setfill(DDC *dc, Bool fill);
66 70
67/* Drawing functions */ 71/* Drawing functions */