libframe/frinit.c (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
#include <u.h> #include <libc.h> #include <draw.h> #include <mouse.h> #include "frame.h" void frinit(Frame* f, Rectangle r, Font* ft, Image* b, Image* cols[NCOL]) { f->font = ft; f->display = b->display; f->maxtab = 8 * stringwidth(ft, "0"); f->nbox = 0; f->nalloc = 0; f->nchars = 0; f->nlines = 0; f->p0 = 0; f->p1 = 0; f->box = 0; f->lastlinefull = 0; if (cols != 0) memmove(f->cols, cols, sizeof f->cols); frsetrects(f, r, b); if (f->tick == nil && f->cols[BACK] != 0) frinittick(f); } void frinittick(Frame* f) { Image* b; Font* ft; if (f->cols[BACK] == nil || f->display == nil) return; f->tickscale = scalesize(f->display, 1); b = f->display->screenimage; ft = f->font; if (f->tick) freeimage(f->tick); f->tick = allocimage( f->display, Rect(0, 0, f->tickscale * FRTICKW, ft->height), b->chan, 0, DWhite); if (f->tick == nil) return; if (f->activetick) freeimage(f->activetick); f->activetick = allocimage( f->display, Rect(0, 0, f->tickscale * FRTICKW, ft->height), b->chan, 0, DWhite); if (f->activetick == nil) return; if (f->tickback) freeimage(f->tickback); f->tickback = allocimage(f->display, f->tick->r, b->chan, 0, DWhite); if (f->tickback == 0) { freeimage(f->tick); f->tick = 0; return; } /* inactive background color */ draw(f->tick, f->tick->r, f->cols[BACK], nil, ZP); /* inactive vertical line */ draw( f->tick, Rect( f->tickscale * (FRTICKW / 2), 0, f->tickscale * (FRTICKW / 2 + 1), ft->height), f->cols[TEXT], nil, ZP); /* inactive box on each end */ draw( f->tick, Rect(0, 0, f->tickscale * FRTICKW, f->tickscale * FRTICKW), f->cols[TEXT], nil, ZP); draw( f->tick, Rect( 0, ft->height - f->tickscale * FRTICKW, f->tickscale * FRTICKW, ft->height), f->cols[TEXT], nil, ZP); /* active background color */ draw(f->activetick, f->activetick->r, f->cols[BACK], nil, ZP); /* active vertical line */ draw( f->activetick, Rect( f->tickscale * (FRTICKW / 2), 0, f->tickscale * (FRTICKW / 2 + 1), ft->height), f->cols[HIGH], nil, ZP); /* active box on each end */ draw( f->activetick, Rect(0, 0, f->tickscale * FRTICKW, f->tickscale * FRTICKW), f->cols[HIGH], nil, ZP); draw( f->activetick, Rect( 0, ft->height - f->tickscale * FRTICKW, f->tickscale * FRTICKW, ft->height), f->cols[HIGH], nil, ZP); f->currenttick = f->tick; } void frsetrects(Frame* f, Rectangle r, Image* b) { f->b = b; f->entire = r; f->r = r; f->r.max.y -= (r.max.y - r.min.y) % f->font->height; f->maxlines = (r.max.y - r.min.y) / f->font->height; } void frclear(Frame* f, int freeall) { if (f->nbox) _frdelbox(f, 0, f->nbox - 1); if (f->box) free(f->box); if (freeall) { freeimage(f->activetick); freeimage(f->tick); freeimage(f->tickback); f->currenttick = nil; f->tick = 0; f->tickback = 0; } f->box = 0; f->ticked = 0; } |