History

libmemdraw: update memarc() and memellipse() from 9front

cinap_lenrek committed 7 years ago

Commit 5f074881 parent 176099b2 files · +21 −21Browse files

Unified · Split

2 files
  1. libmemdraw/arc.c +19 −17
  2. libmemdraw/ellipse.c +2 −4
libmemdraw/arc.c+19−17
@@ -24,9 +24,6 @@ Point corners[] = { · 23 unmodified lines
24 {1,-1}24 {1,-1}
25};25};
26 26
27static
28Point p00;
29
30/*27/*
31 * make a "wedge" mask covering the desired angle and contained in28 * make a "wedge" mask covering the desired angle and contained in
32 * a surrounding square; draw a full ellipse; intersect that with the29 * a surrounding square; draw a full ellipse; intersect that with the
@@ -40,13 +37,13 @@ memarc(Memimage *dst, Point c, int a, int b, int t, Memimage *src, Point sp, int · 7 unmodified lines
40 Point p, bnd[8];37 Point p, bnd[8];
41 Memimage *wedge, *figure, *mask;38 Memimage *wedge, *figure, *mask;
42 39
43 if(a < 0)40 if(phi == 0)
44 a = -a;41 return;
45 if(b < 0)42 if(phi <= -360 || phi >= 360){
46 b = -b;43 memellipse(dst, c, a, b, t, src, sp, op);
47 w = t;44 return;
48 if(w < 0)45 }
49 w = 0;46 alpha %= 360;
50 alpha = -alpha; /* compensate for upside-down coords */47 alpha = -alpha; /* compensate for upside-down coords */
51 phi = -phi;48 phi = -phi;
52 beta = alpha + phi;49 beta = alpha + phi;
@@ -56,10 +53,6 @@ memarc(Memimage *dst, Point c, int a, int b, int t, Memimage *src, Point sp, int · 3 unmodified lines
56 beta = tmp;53 beta = tmp;
57 phi = -phi;54 phi = -phi;
58 }55 }
59 if(phi >= 360){
60 memellipse(dst, c, a, b, t, src, sp, op);
61 return;
62 }
63 while(alpha < 0)56 while(alpha < 0)
64 alpha += 360;57 alpha += 360;
65 while(beta < 0)58 while(beta < 0)
@@ -70,6 +63,15 @@ memarc(Memimage *dst, Point c, int a, int b, int t, Memimage *src, Point sp, int · 4 unmodified lines
70 * icossin returns point at radius ICOSSCALE.63 * icossin returns point at radius ICOSSCALE.
71 * multiplying by m1 moves it outside the ellipse64 * multiplying by m1 moves it outside the ellipse
72 */65 */
66
67 if(a < 0)
68 a = -a;
69 if(b < 0)
70 b = -b;
71 w = t;
72 if(w < 0)
73 w = 0;
74
73 rect = Rect(-a-w, -b-w, a+w+1, b+w+1);75 rect = Rect(-a-w, -b-w, a+w+1, b+w+1);
74 m = rect.max.x; /* inradius of bounding square */76 m = rect.max.x; /* inradius of bounding square */
75 if(m < rect.max.y)77 if(m < rect.max.y)
@@ -96,19 +98,19 @@ memarc(Memimage *dst, Point c, int a, int b, int t, Memimage *src, Point sp, int · 20 unmodified lines
96 if(wedge == nil)98 if(wedge == nil)
97 goto Return;99 goto Return;
98 memfillcolor(wedge, DTransparent);100 memfillcolor(wedge, DTransparent);
99 memfillpoly(wedge, bnd, i, ~0, memopaque, p00, S);101 memfillpoly(wedge, bnd, i, ~0, memopaque, ZP, S);
100 figure = allocmemimage(rect, GREY1);102 figure = allocmemimage(rect, GREY1);
101 if(figure == nil)103 if(figure == nil)
102 goto Return;104 goto Return;
103 memfillcolor(figure, DTransparent);105 memfillcolor(figure, DTransparent);
104 memellipse(figure, p00, a, b, t, memopaque, p00, S);106 memellipse(figure, ZP, a, b, t, memopaque, ZP, S);
105 mask = allocmemimage(rect, GREY1);107 mask = allocmemimage(rect, GREY1);
106 if(mask == nil)108 if(mask == nil)
107 goto Return;109 goto Return;
108 memfillcolor(mask, DTransparent);110 memfillcolor(mask, DTransparent);
109 memimagedraw(mask, rect, figure, rect.min, wedge, rect.min, S);111 memimagedraw(mask, rect, figure, rect.min, wedge, rect.min, S);
110 c = subpt(c, dst->r.min);112 c = subpt(c, dst->r.min);
111 memdraw(dst, dst->r, src, subpt(sp, c), mask, subpt(p00, c), op);113 memdraw(dst, dst->r, src, subpt(sp, c), mask, subpt(ZP, c), op);
112 114
113 Return:115 Return:
114 freememimage(wedge);116 freememimage(wedge);
libmemdraw/ellipse.c+2−4
@@ -164,8 +164,6 @@ memellipse(Memimage *dst, Point c, int a, int b, int t, Memimage *src, Point sp, · 163 unmodified lines
164 }164 }
165}165}
166 166
167static Point p00 = {0, 0};
168
169/*167/*
170 * a brushed ellipse168 * a brushed ellipse
171 */169 */
@@ -180,7 +178,7 @@ bellipse(int y, State *s, Param *p) · 8 unmodified lines
180 if(p->disc == nil)178 if(p->disc == nil)
181 return;179 return;
182 memfillcolor(p->disc, DTransparent);180 memfillcolor(p->disc, DTransparent);
183 memellipse(p->disc, p00, t, t, -1, memopaque, p00, p->op);181 memellipse(p->disc, ZP, t, t, -1, memopaque, ZP, p->op);
184 oy = y;182 oy = y;
185 ox = 0;183 ox = 0;
186 nx = x = step(s);184 nx = x = step(s);
@@ -211,7 +209,7 @@ erect(int x0, int y0, int x1, int y1, Param *p) · 24 unmodified lines
211 209
212/* print("R %d,%d %d,%d\n", x0, y0, x1, y1); /**/210/* print("R %d,%d %d,%d\n", x0, y0, x1, y1); /**/
213 r = Rect(p->c.x+x0, p->c.y+y0, p->c.x+x1+1, p->c.y+y1+1);211 r = Rect(p->c.x+x0, p->c.y+y0, p->c.x+x1+1, p->c.y+y1+1);
214 memdraw(p->dst, r, p->src, addpt(p->sp, r.min), memopaque, p00, p->op);212 memdraw(p->dst, r, p->src, addpt(p->sp, r.min), memopaque, ZP, p->op);
215}213}
216 214
217/*215/*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t