Blob


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