plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

frinit.c (1931B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include <draw.h>
      4 #include <mouse.h>
      5 #include <frame.h>
      6 
      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 }
     27 
     28 void
     29 frinittick(Frame *f)
     30 {
     31 	Image *b;
     32 	Font *ft;
     33 
     34 	if(f->cols[BACK] == nil || f->display == nil)
     35 		return;
     36 	f->tickscale = scalesize(f->display, 1);
     37 	b = f->display->screenimage;
     38 	ft = f->font;
     39 	if(f->tick)
     40 		freeimage(f->tick);
     41 	f->tick = allocimage(f->display, Rect(0, 0, f->tickscale*FRTICKW, ft->height), b->chan, 0, DWhite);
     42 	if(f->tick == nil)
     43 		return;
     44 	if(f->tickback)
     45 		freeimage(f->tickback);
     46 	f->tickback = allocimage(f->display, f->tick->r, b->chan, 0, DWhite);
     47 	if(f->tickback == 0){
     48 		freeimage(f->tick);
     49 		f->tick = 0;
     50 		return;
     51 	}
     52 	/* background color */
     53 	draw(f->tick, f->tick->r, f->cols[BACK], nil, ZP);
     54 	/* vertical line */
     55 	draw(f->tick, Rect(f->tickscale*(FRTICKW/2), 0, f->tickscale*(FRTICKW/2+1), ft->height), f->cols[TEXT], nil, ZP);
     56 	/* box on each end */
     57 	draw(f->tick, Rect(0, 0, f->tickscale*FRTICKW, f->tickscale*FRTICKW), f->cols[TEXT], nil, ZP);
     58 	draw(f->tick, Rect(0, ft->height-f->tickscale*FRTICKW, f->tickscale*FRTICKW, ft->height), f->cols[TEXT], nil, ZP);
     59 }
     60 
     61 void
     62 frsetrects(Frame *f, Rectangle r, Image *b)
     63 {
     64 	f->b = b;
     65 	f->entire = r;
     66 	f->r = r;
     67 	f->r.max.y -= (r.max.y-r.min.y)%f->font->height;
     68 	f->maxlines = (r.max.y-r.min.y)/f->font->height;
     69 }
     70 
     71 void
     72 frclear(Frame *f, int freeall)
     73 {
     74 	if(f->nbox)
     75 		_frdelbox(f, 0, f->nbox-1);
     76 	if(f->box)
     77 		free(f->box);
     78 	if(freeall){
     79 		freeimage(f->tick);
     80 		freeimage(f->tickback);
     81 		f->tick = 0;
     82 		f->tickback = 0;
     83 	}
     84 	f->box = 0;
     85 	f->ticked = 0;
     86 }