xref: /plan9/sys/src/libdraw/ellipse.c (revision ac57dd0bdfb9d49ce3ebb32937bb07f2cec3da6c)
1 #include <u.h>
2 #include <libc.h>
3 #include <draw.h>
4 
5 static
6 void
doellipse(int cmd,Image * dst,Point * c,int xr,int yr,int thick,Image * src,Point * sp,int alpha,int phi,Drawop op)7 doellipse(int cmd, Image *dst, Point *c, int xr, int yr, int thick, Image *src, Point *sp, int alpha, int phi, Drawop op)
8 {
9 	uchar *a;
10 
11 	_setdrawop(dst->display, op);
12 
13 	a = bufimage(dst->display, 1+4+4+2*4+4+4+4+2*4+2*4);
14 	if(a == 0){
15 		fprint(2, "image ellipse: %r\n");
16 		return;
17 	}
18 	a[0] = cmd;
19 	BPLONG(a+1, dst->id);
20 	BPLONG(a+5, src->id);
21 	BPLONG(a+9, c->x);
22 	BPLONG(a+13, c->y);
23 	BPLONG(a+17, xr);
24 	BPLONG(a+21, yr);
25 	BPLONG(a+25, thick);
26 	BPLONG(a+29, sp->x);
27 	BPLONG(a+33, sp->y);
28 	BPLONG(a+37, alpha);
29 	BPLONG(a+41, phi);
30 }
31 
32 void
ellipse(Image * dst,Point c,int a,int b,int thick,Image * src,Point sp)33 ellipse(Image *dst, Point c, int a, int b, int thick, Image *src, Point sp)
34 {
35 	doellipse('e', dst, &c, a, b, thick, src, &sp, 0, 0, SoverD);
36 }
37 
38 void
ellipseop(Image * dst,Point c,int a,int b,int thick,Image * src,Point sp,Drawop op)39 ellipseop(Image *dst, Point c, int a, int b, int thick, Image *src, Point sp, Drawop op)
40 {
41 	doellipse('e', dst, &c, a, b, thick, src, &sp, 0, 0, op);
42 }
43 
44 void
fillellipse(Image * dst,Point c,int a,int b,Image * src,Point sp)45 fillellipse(Image *dst, Point c, int a, int b, Image *src, Point sp)
46 {
47 	doellipse('E', dst, &c, a, b, 0, src, &sp, 0, 0, SoverD);
48 }
49 
50 void
fillellipseop(Image * dst,Point c,int a,int b,Image * src,Point sp,Drawop op)51 fillellipseop(Image *dst, Point c, int a, int b, Image *src, Point sp, Drawop op)
52 {
53 	doellipse('E', dst, &c, a, b, 0, src, &sp, 0, 0, op);
54 }
55 
56 void
arc(Image * dst,Point c,int a,int b,int thick,Image * src,Point sp,int alpha,int phi)57 arc(Image *dst, Point c, int a, int b, int thick, Image *src, Point sp, int alpha, int phi)
58 {
59 	alpha |= 1<<31;
60 	doellipse('e', dst, &c, a, b, thick, src, &sp, alpha, phi, SoverD);
61 }
62 
63 void
arcop(Image * dst,Point c,int a,int b,int thick,Image * src,Point sp,int alpha,int phi,Drawop op)64 arcop(Image *dst, Point c, int a, int b, int thick, Image *src, Point sp, int alpha, int phi, Drawop op)
65 {
66 	alpha |= 1<<31;
67 	doellipse('e', dst, &c, a, b, thick, src, &sp, alpha, phi, op);
68 }
69 
70 void
fillarc(Image * dst,Point c,int a,int b,Image * src,Point sp,int alpha,int phi)71 fillarc(Image *dst, Point c, int a, int b, Image *src, Point sp, int alpha, int phi)
72 {
73 	alpha |= 1<<31;
74 	doellipse('E', dst, &c, a, b, 0, src, &sp, alpha, phi, SoverD);
75 }
76 
77 void
fillarcop(Image * dst,Point c,int a,int b,Image * src,Point sp,int alpha,int phi,Drawop op)78 fillarcop(Image *dst, Point c, int a, int b, Image *src, Point sp, int alpha, int phi, Drawop op)
79 {
80 	alpha |= 1<<31;
81 	doellipse('E', dst, &c, a, b, 0, src, &sp, alpha, phi, op);
82 }
83