1 #include <u.h> 2 #include <libc.h> 3 #include <draw.h> 4 #include <thread.h> 5 #include <mouse.h> 6 #include <frame.h> 7 8 void 9 frinit(Frame *f, Rectangle r, Font *ft, Image *b, Image *cols[NCOL]) 10 { 11 f->font = ft; 12 f->display = b->display; 13 f->maxtab = 8*stringwidth(ft, "0"); 14 f->nbox = 0; 15 f->nalloc = 0; 16 f->nchars = 0; 17 f->nlines = 0; 18 f->p0 = 0; 19 f->p1 = 0; 20 f->box = 0; 21 f->lastlinefull = 0; 22 if(cols != 0) 23 memmove(f->cols, cols, sizeof f->cols); 24 frsetrects(f, r, b); 25 if(f->tick==nil && f->cols[BACK]!=0) 26 frinittick(f); 27 } 28 29 void 30 frinittick(Frame *f) 31 { 32 Image *b; 33 Font *ft; 34 35 b = f->display->screenimage; 36 ft = f->font; 37 if(f->tick) 38 freeimage(f->tick); 39 f->tick = allocimage(f->display, Rect(0, 0, FRTICKW, ft->height), b->chan, 0, DWhite); 40 if(f->tick == nil) 41 return; 42 if(f->tickback) 43 freeimage(f->tickback); 44 f->tickback = allocimage(f->display, f->tick->r, b->chan, 0, DWhite); 45 if(f->tickback == 0){ 46 freeimage(f->tick); 47 f->tick = 0; 48 return; 49 } 50 /* background color */ 51 draw(f->tick, f->tick->r, f->cols[BACK], nil, ZP); 52 /* vertical line */ 53 draw(f->tick, Rect(FRTICKW/2, 0, FRTICKW/2+1, ft->height), f->cols[TEXT], nil, ZP); 54 /* box on each end */ 55 draw(f->tick, Rect(0, 0, FRTICKW, FRTICKW), f->cols[TEXT], nil, ZP); 56 draw(f->tick, Rect(0, ft->height-FRTICKW, FRTICKW, ft->height), f->cols[TEXT], nil, ZP); 57 } 58 59 void 60 frsetrects(Frame *f, Rectangle r, Image *b) 61 { 62 f->b = b; 63 f->entire = r; 64 f->r = r; 65 f->r.max.y -= (r.max.y-r.min.y)%f->font->height; 66 f->maxlines = (r.max.y-r.min.y)/f->font->height; 67 } 68 69 void 70 frclear(Frame *f, int freeall) 71 { 72 if(f->nbox) 73 _frdelbox(f, 0, f->nbox-1); 74 if(f->box) 75 free(f->box); 76 if(freeall){ 77 freeimage(f->tick); 78 freeimage(f->tickback); 79 f->tick = 0; 80 f->tickback = 0; 81 } 82 f->box = 0; 83 f->ticked = 0; 84 } 85