removed DDC, all is Draw-dependent
c0ba635c
2 file(s) · +40 −82
| 35 | 35 | free(draw); |
|
| 36 | 36 | } |
|
| 37 | 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 | 38 | Fnt * |
|
| 61 | 39 | font_create(const char *fontname) { |
|
| 62 | 40 | Fnt *font = (Fnt *)calloc(1, sizeof(Fnt)); |
|
| 88 | 66 | } |
|
| 89 | 67 | ||
| 90 | 68 | void |
|
| 91 | - | dc_setfont(DDC *dc, Fnt *font) { |
|
| 92 | - | if(!dc || !font) |
|
| 69 | + | draw_setfont(Draw *draw, Fnt *font) { |
|
| 70 | + | if(!draw || !font) |
|
| 93 | 71 | return; |
|
| 94 | - | dc->font = font; |
|
| 72 | + | draw->font = font; |
|
| 95 | 73 | } |
|
| 96 | 74 | ||
| 97 | 75 | void |
|
| 98 | - | dc_setfg(DDC *dc, Col *col) { |
|
| 99 | - | if(!dc || !col) |
|
| 76 | + | draw_setfg(Draw *draw, Col *col) { |
|
| 77 | + | if(!draw || !col) |
|
| 100 | 78 | 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; |
|
| 79 | + | draw->fg = col; |
|
| 109 | 80 | } |
|
| 110 | 81 | ||
| 111 | 82 | void |
|
| 112 | - | dc_setfill(DDC *dc, Bool fill) { |
|
| 113 | - | if(!dc) |
|
| 83 | + | draw_setbg(Draw *draw, Col *col) { |
|
| 84 | + | if(!draw || !col) |
|
| 114 | 85 | return; |
|
| 115 | - | dc->fill = fill; |
|
| 86 | + | draw->bg = col; |
|
| 116 | 87 | } |
|
| 117 | 88 | ||
| 118 | 89 | void |
|
| 119 | - | dc_drawrect(DDC *dc, int x, int y, unsigned int w, unsigned int h) { |
|
| 120 | - | if(!dc) |
|
| 90 | + | draw_rect(Draw *draw, int x, int y, unsigned int w, unsigned int h) { |
|
| 91 | + | if(!draw) |
|
| 121 | 92 | return; |
|
| 122 | 93 | /* TODO: draw the rectangle */ |
|
| 123 | 94 | } |
|
| 124 | 95 | ||
| 125 | 96 | void |
|
| 126 | - | dc_drawtext(DDC *dc, int x, int y, const char *text) { |
|
| 127 | - | if(!dc) |
|
| 97 | + | draw_text(Draw *draw, int x, int y, const char *text) { |
|
| 98 | + | if(!draw) |
|
| 128 | 99 | return; |
|
| 129 | 100 | /* TODO: draw the text */ |
|
| 130 | 101 | } |
|
| 131 | 102 | ||
| 132 | 103 | void |
|
| 133 | - | dc_map(DDC *dc, int x, int y, unsigned int w, unsigned int h) { |
|
| 134 | - | if(!dc) |
|
| 104 | + | draw_map(Draw *draw, int x, int y, unsigned int w, unsigned int h) { |
|
| 105 | + | if(!draw) |
|
| 135 | 106 | return; |
|
| 136 | - | /* TODO: map the dc contents in the region */ |
|
| 107 | + | /* TODO: map the draw contents in the region */ |
|
| 137 | 108 | } |
|
| 138 | 109 | ||
| 139 | 110 | void |
|
| 140 | - | dc_getextents(DDC *dc, const char *text, TextExtents *extents) { |
|
| 141 | - | if(!dc || !extents) |
|
| 111 | + | draw_getextents(Draw *draw, const char *text, TextExtents *extents) { |
|
| 112 | + | if(!draw || !extents) |
|
| 142 | 113 | return; |
|
| 143 | 114 | /* TODO: get extents */ |
|
| 144 | 115 | } |
|
| 1 | 1 | /* See LICENSE file for copyright and license details. */ |
|
| 2 | 2 | ||
| 3 | - | typedef struct _DDC DDC; |
|
| 4 | - | ||
| 5 | - | /* X11 types - begin */ |
|
| 6 | - | typedef struct _XDraw Draw; |
|
| 7 | - | struct _XDraw { |
|
| 8 | - | unsigned int w, h; |
|
| 9 | - | Display *dpy; |
|
| 10 | - | int screen; |
|
| 11 | - | Window win; |
|
| 12 | - | Drawable drawable; |
|
| 13 | - | GC gc; |
|
| 14 | - | DDC *dc; |
|
| 15 | - | }; |
|
| 16 | - | ||
| 17 | 3 | struct _XCol { |
|
| 18 | 4 | unsigned long rgb; |
|
| 19 | 5 | }; |
|
| 29 | 15 | typedef struct _XFont Fnt; |
|
| 30 | 16 | /* X11 types - end */ |
|
| 31 | 17 | ||
| 32 | - | struct _DDC { |
|
| 33 | - | Draw *draw; |
|
| 34 | - | Col *fg; |
|
| 35 | - | Col *bg; |
|
| 36 | - | Fnt *font; |
|
| 37 | - | Bool fill; |
|
| 38 | - | DDC *next; |
|
| 39 | - | }; |
|
| 40 | - | ||
| 41 | 18 | typedef struct { |
|
| 42 | 19 | unsigned int w; |
|
| 43 | 20 | unsigned int h; |
|
| 47 | 24 | int yOff; |
|
| 48 | 25 | } TextExtents; |
|
| 49 | 26 | ||
| 27 | + | ||
| 28 | + | /* X11 types - begin */ |
|
| 29 | + | typedef struct _XDraw Draw; |
|
| 30 | + | struct _XDraw { |
|
| 31 | + | unsigned int w, h; |
|
| 32 | + | Display *dpy; |
|
| 33 | + | int screen; |
|
| 34 | + | Window win; |
|
| 35 | + | Drawable drawable; |
|
| 36 | + | GC gc; |
|
| 37 | + | Col *fg; |
|
| 38 | + | Col *bg; |
|
| 39 | + | Fnt *font; |
|
| 40 | + | }; |
|
| 41 | + | ||
| 50 | 42 | /* Drawable abstraction */ |
|
| 51 | 43 | Draw *draw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); |
|
| 52 | 44 | void draw_resize(Draw *draw, unsigned int w, unsigned int h); |
|
| 53 | 45 | void draw_free(Draw *draw); |
|
| 54 | - | ||
| 55 | - | /* Drawing context abstraction */ |
|
| 56 | - | DDC *dc_create(Draw *draw); |
|
| 57 | - | void dc_free(DDC *dc); |
|
| 58 | 46 | ||
| 59 | 47 | /* Fnt abstraction */ |
|
| 60 | 48 | Fnt *font_create(const char *fontname); |
|
| 65 | 53 | void col_free(Col *col); |
|
| 66 | 54 | ||
| 67 | 55 | /* Drawing context manipulation */ |
|
| 68 | - | void dc_setfont(DDC *dc, Fnt *font); |
|
| 69 | - | void dc_setfg(DDC *dc, Col *col); |
|
| 70 | - | void dc_setbg(DDC *dc, Col *col); |
|
| 71 | - | void dc_setfill(DDC *dc, Bool fill); |
|
| 56 | + | void draw_setfont(Draw *draw, Fnt *font); |
|
| 57 | + | void draw_setfg(Draw *draw, Col *col); |
|
| 58 | + | void draw_setbg(Draw *draw, Col *col); |
|
| 72 | 59 | ||
| 73 | 60 | /* Drawing functions */ |
|
| 74 | - | void dc_drawrect(DDC *dc, int x, int y, unsigned int w, unsigned int h); |
|
| 75 | - | void dc_drawtext(DDC *dc, int x, int y, const char *text); |
|
| 61 | + | void draw_rect(Draw *draw, int x, int y, unsigned int w, unsigned int h); |
|
| 62 | + | void draw_text(Draw *draw, int x, int y, const char *text); |
|
| 76 | 63 | ||
| 77 | 64 | /* Map functions */ |
|
| 78 | - | void dc_map(DDC *dc, int x, int y, unsigned int w, unsigned int h); |
|
| 65 | + | void draw_map(Draw *draw, int x, int y, unsigned int w, unsigned int h); |
|
| 79 | 66 | ||
| 80 | 67 | /* Text functions */ |
|
| 81 | - | void dc_getextents(DDC *dc, const char *text, TextExtents *extents); |
|
| 68 | + | void draw_getextents(Draw *draw, const char *text, TextExtents *extents); |
|
| 82 | 69 | ||