diff options
| author | anselm@garbe.us <unknown> | 2012-11-18 12:04:29 +0100 |
|---|---|---|
| committer | anselm@garbe.us <unknown> | 2012-11-18 12:04:29 +0100 |
| commit | d456617f0eb93df0ec8eb81ff6e04ca988c09c60 (patch) | |
| tree | 91fdfc4934a640bc937e2524cff16d60cc6862a5 | |
| parent | reverting to plain X11 fonts in order to implement draw.c default (diff) | |
| download | dwm-d456617f0eb93df0ec8eb81ff6e04ca988c09c60.tar.gz dwm-d456617f0eb93df0ec8eb81ff6e04ca988c09c60.zip | |
basic draw.c structure
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | draw.c | 139 | ||||
| -rw-r--r-- | draw.h | 14 |
3 files changed, 149 insertions, 6 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | include config.mk | 4 | include config.mk |
| 5 | 5 | ||
| 6 | SRC = dwm.c | 6 | SRC = draw.c dwm.c |
| 7 | OBJ = ${SRC:.c=.o} | 7 | OBJ = ${SRC:.c=.o} |
| 8 | 8 | ||
| 9 | all: options dwm | 9 | all: options dwm |
| @@ -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 | |||
| 7 | Draw * | ||
| 8 | draw_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 | |||
| 17 | void | ||
| 18 | draw_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 | |||
| 26 | void | ||
| 27 | draw_free(Draw *draw) { | ||
| 28 | /* TODO: deallocate DDCs */ | ||
| 29 | /* TODO: deallocate drawable */ | ||
| 30 | free(draw); | ||
| 31 | } | ||
| 32 | |||
| 33 | DDC * | ||
| 34 | dc_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 | |||
| 42 | void | ||
| 43 | dc_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 | |||
| 55 | Fnt * | ||
| 56 | font_create(const char *fontname) { | ||
| 57 | Fnt *font = (Fnt *)calloc(1, sizeof(Fnt)); | ||
| 58 | /* TODO: allocate actual font */ | ||
| 59 | return font; | ||
| 60 | } | ||
| 61 | |||
| 62 | void | ||
| 63 | font_free(Fnt *font) { | ||
| 64 | if(!font) | ||
| 65 | return; | ||
| 66 | /* TODO: deallocate any font resources */ | ||
| 67 | free(font); | ||
| 68 | } | ||
| 69 | |||
| 70 | Col * | ||
| 71 | col_create(const char *colname) { | ||
| 72 | Col *col = (Col *)calloc(1, sizeof(Col)); | ||
| 73 | /* TODO: allocate color */ | ||
| 74 | return col; | ||
| 75 | } | ||
| 76 | |||
| 77 | void | ||
| 78 | col_free(Col *col) { | ||
| 79 | if(!col) | ||
| 80 | return; | ||
| 81 | /* TODO: deallocate any color resource */ | ||
| 82 | free(col); | ||
| 83 | } | ||
| 84 | |||
| 85 | void | ||
| 86 | dc_setfont(DDC *dc, Fnt *font) { | ||
| 87 | if(!dc || !font) | ||
| 88 | return; | ||
| 89 | dc->font = font; | ||
| 90 | } | ||
| 91 | |||
| 92 | void | ||
| 93 | dc_setfg(DDC *dc, Col *col) { | ||
| 94 | if(!dc || !col) | ||
| 95 | return; | ||
| 96 | dc->fg = col; | ||
| 97 | } | ||
| 98 | |||
| 99 | void | ||
| 100 | dc_setbg(DDC *dc, Col *col) { | ||
| 101 | if(!dc || !col) | ||
| 102 | return; | ||
| 103 | dc->bg = col; | ||
| 104 | } | ||
| 105 | |||
| 106 | void | ||
| 107 | dc_setfill(DDC *dc, Bool fill) { | ||
| 108 | if(!dc) | ||
| 109 | return; | ||
| 110 | dc->fill = fill; | ||
| 111 | } | ||
| 112 | |||
| 113 | void | ||
| 114 | dc_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 | |||
| 120 | void | ||
| 121 | dc_drawtext(DDC *dc, int x, int y, const char *text) { | ||
| 122 | if(!dc) | ||
| 123 | return; | ||
| 124 | /* TODO: draw the text */ | ||
| 125 | } | ||
| 126 | |||
| 127 | void | ||
| 128 | dc_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 | |||
| 134 | void | ||
| 135 | dc_getextents(DDC *dc, const char *text, TextExtents *extents) { | ||
| 136 | if(!dc || !extents) | ||
| 137 | return; | ||
| 138 | /* TODO: get extents */ | ||
| 139 | } | ||
| @@ -1,13 +1,16 @@ | |||
| 1 | /* See LICENSE file for copyright and license details. */ | 1 | /* See LICENSE file for copyright and license details. */ |
| 2 | 2 | ||
| 3 | typedef struct _DDC DDC; | ||
| 4 | |||
| 3 | /* X11 types - begin */ | 5 | /* X11 types - begin */ |
| 6 | typedef struct _XDraw Draw; | ||
| 4 | struct _XDraw { | 7 | struct _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 | }; |
| 10 | typedef struct _XDraw Draw; | ||
| 11 | 14 | ||
| 12 | struct _XCol { | 15 | struct _XCol { |
| 13 | unsigned long rgb; | 16 | unsigned long rgb; |
| @@ -24,13 +27,14 @@ struct _XFont { | |||
| 24 | typedef struct _XFont Fnt; | 27 | typedef struct _XFont Fnt; |
| 25 | /* X11 types - end */ | 28 | /* X11 types - end */ |
| 26 | 29 | ||
| 27 | typedef struct { | 30 | struct _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 | ||
| 35 | typedef struct { | 39 | typedef 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 */ |
| 62 | void dc_setfont(DDC *dc, Fnt *font); | 66 | void dc_setfont(DDC *dc, Fnt *font); |
| 63 | void dc_setfg(DDC *dc, Col col); | 67 | void dc_setfg(DDC *dc, Col *col); |
| 64 | void dc_setbg(DDC *dc, Col col); | 68 | void dc_setbg(DDC *dc, Col *col); |
| 65 | void dc_setfill(DDC *dc, Bool fill); | 69 | void dc_setfill(DDC *dc, Bool fill); |
| 66 | 70 | ||
| 67 | /* Drawing functions */ | 71 | /* Drawing functions */ |
