diff options
Diffstat (limited to '')
| -rw-r--r-- | draw.c | 139 |
1 files changed, 139 insertions, 0 deletions
| @@ -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 | } | ||
