1 #include <u.h>
2 #include <libc.h>
3 #include <draw.h>
4 
5 void
borderop(Image * im,Rectangle r,int i,Image * color,Point sp,Drawop op)6 borderop(Image *im, Rectangle r, int i, Image *color, Point sp, Drawop op)
7 {
8 	if(i < 0){
9 		r = insetrect(r, i);
10 		sp = addpt(sp, Pt(i,i));
11 		i = -i;
12 	}
13 	drawop(im, Rect(r.min.x, r.min.y, r.max.x, r.min.y+i),
14 		color, nil, sp, op);
15 	drawop(im, Rect(r.min.x, r.max.y-i, r.max.x, r.max.y),
16 		color, nil, Pt(sp.x, sp.y+Dy(r)-i), op);
17 	drawop(im, Rect(r.min.x, r.min.y+i, r.min.x+i, r.max.y-i),
18 		color, nil, Pt(sp.x, sp.y+i), op);
19 	drawop(im, Rect(r.max.x-i, r.min.y+i, r.max.x, r.max.y-i),
20 		color, nil, Pt(sp.x+Dx(r)-i, sp.y+i), op);
21 }
22 
23 void
border(Image * im,Rectangle r,int i,Image * color,Point sp)24 border(Image *im, Rectangle r, int i, Image *color, Point sp)
25 {
26 	borderop(im, r, i, color, sp, SoverD);
27 }
28