184 |
184 |
float quotient = radius/(float)Math.sqrt(vX*vX + vY*vY);
|
185 |
185 |
float ret = computeAngle(vX,-vY)-computeQuotientOfCurvature(quotient,curvature);
|
186 |
186 |
|
187 |
|
if( ret>=2*PI ) ret -= 2*PI;
|
188 |
|
if( ret<0 ) ret += 2*PI;
|
|
187 |
while( ret>=2*PI ) ret -= 2*PI;
|
|
188 |
while( ret<0 ) ret += 2*PI;
|
189 |
189 |
|
190 |
190 |
return ret;
|
191 |
191 |
}
|
... | ... | |
209 |
209 |
|
210 |
210 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
211 |
211 |
|
212 |
|
private void drawRoundCorner(Canvas canvas, Paint paint,int color, int left, int bottom, float stroke,
|
213 |
|
float radius, float cX, float cY, float pA, float cA)
|
|
212 |
private void drawRoundCorner(Canvas canvas, Paint paint, int color, int left, int bottom,
|
|
213 |
float stroke, float radius, float cX, float cY, float pA, float cA)
|
214 |
214 |
{
|
|
215 |
final float A = 4.0f;
|
|
216 |
|
215 |
217 |
cX = (0.5f+cX)*mTexHeight;
|
216 |
218 |
cY = (0.5f-cY)*mTexHeight;
|
217 |
|
float R = radius*mTexHeight + stroke/2;
|
|
219 |
float r = radius*mTexHeight + stroke/2; // distance from the center of the circle arc of
|
|
220 |
// which we are drawing to the center of the edge line
|
|
221 |
float R = radius*mTexHeight + A*stroke/2; // distance from the center of the circle to the center
|
|
222 |
// of the arc being drawn; the arc is A times thicker.
|
218 |
223 |
|
219 |
224 |
boolean isConvex = ((pA<cA && cA<pA+PI) || (pA<cA+2*PI && cA+2*PI<pA+PI));
|
220 |
225 |
float startA, stopA, centerA, alpha, D;
|
... | ... | |
230 |
235 |
float diff = cA-centerA;
|
231 |
236 |
if( diff<0 ) diff += 2*PI;
|
232 |
237 |
alpha = diff> PI/2 ? PI-diff : diff;
|
233 |
|
D = (float)(R/Math.sin(alpha));
|
|
238 |
D = (float)(r/Math.sin(alpha));
|
234 |
239 |
}
|
235 |
240 |
else
|
236 |
241 |
{
|
... | ... | |
241 |
246 |
float diff = centerA-cA;
|
242 |
247 |
if( diff<0 ) diff += 2*PI;
|
243 |
248 |
alpha = diff> PI/2 ? PI-diff : diff;
|
244 |
|
D = (float)((R-stroke)/Math.sin(alpha));
|
|
249 |
D = (float)((r-stroke)/Math.sin(alpha));
|
245 |
250 |
}
|
246 |
251 |
|
247 |
252 |
float sweepA = startA-stopA;
|
... | ... | |
257 |
262 |
sweepA *= 180/PI;
|
258 |
263 |
|
259 |
264 |
if( !isConvex ) paint.setColor(color);
|
|
265 |
paint.setStrokeWidth(A*stroke);
|
260 |
266 |
canvas.drawArc( left+oX-R, bottom-oY-R, left+oX+R, bottom-oY+R, startA, sweepA, false, paint);
|
261 |
267 |
if( !isConvex ) paint.setColor(COLOR_STROKE);
|
262 |
268 |
}
|
... | ... | |
265 |
271 |
// TODO: this doesn't really support proper drawing of rounded corners in case two neighbouring
|
266 |
272 |
// strokes are not equal to each other.
|
267 |
273 |
|
268 |
|
private void drawEdge(Canvas canvas, Paint paint, int left, int bottom, int color,
|
269 |
|
float[] strokes, float[][] vertices, float[] angles, float[] radii )
|
|
274 |
private void drawEdge(Canvas canvas, Paint paint, int left, int bottom, int color, float[] strokes,
|
|
275 |
float[][] vertices, float[] angles, float[] radii, float borders, float corners )
|
270 |
276 |
{
|
271 |
277 |
int length = vertices.length;
|
272 |
278 |
|
... | ... | |
281 |
287 |
|
282 |
288 |
for(int vert=0; vert<length; vert++)
|
283 |
289 |
{
|
284 |
|
float stroke = strokes[vert]*mTexHeight;
|
|
290 |
float stroke = borders*strokes[vert]*mTexHeight;
|
285 |
291 |
|
286 |
292 |
if( stroke>0 )
|
287 |
293 |
{
|
... | ... | |
312 |
318 |
|
313 |
319 |
for(int vert=0; vert<length; vert++)
|
314 |
320 |
{
|
315 |
|
float stroke = strokes[vert]*mTexHeight;
|
316 |
|
paint.setStrokeWidth(stroke);
|
317 |
|
|
|
321 |
float stroke = borders*strokes[vert]*mTexHeight;
|
318 |
322 |
int prev = vert==0 ? length-1 : vert-1;
|
319 |
|
float prevAngle = computeSideAngle(currX-prevX,currY-prevY,radii[prev],-prevA);
|
320 |
|
float currAngle = computeSideAngle(nextX-currX,nextY-currY,radii[vert],+currA);
|
|
323 |
float rp = radii[prev]*corners;
|
|
324 |
float rv = radii[vert]*corners;
|
|
325 |
float prevAngle = computeSideAngle(currX-prevX,currY-prevY,rp,-prevA);
|
|
326 |
float currAngle = computeSideAngle(nextX-currX,nextY-currY,rv,+currA);
|
321 |
327 |
|
322 |
|
if( radii[vert]>0 && stroke>0 )
|
323 |
|
drawRoundCorner(canvas,paint,color,left,bottom,stroke,radii[vert],currX,currY,prevAngle,currAngle);
|
|
328 |
if( rv>0 && stroke>0 )
|
|
329 |
drawRoundCorner(canvas,paint,color,left,bottom,stroke,rv,currX,currY,prevAngle,currAngle);
|
324 |
330 |
|
325 |
331 |
prevX = currX;
|
326 |
332 |
prevY = currY;
|
... | ... | |
337 |
343 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
338 |
344 |
// PUBLIC
|
339 |
345 |
|
340 |
|
public void drawRoundedPolygons(Canvas canvas, Paint paint, int left, int bottom, int color, int height, ObjectSticker sticker)
|
|
346 |
public void drawRoundedPolygons(Canvas canvas, Paint paint, int left, int bottom, int color,
|
|
347 |
int height, ObjectSticker sticker, float borders, float corners)
|
341 |
348 |
{
|
342 |
349 |
mTexHeight = height;
|
343 |
350 |
|
... | ... | |
362 |
369 |
for(int l=0; l<numLoops; l++)
|
363 |
370 |
{
|
364 |
371 |
float[] ang = (angles==null? null : angles[l]);
|
365 |
|
drawEdge(canvas, paint, left, bottom, color, strokes[l], vertices[l], ang, radii[l]);
|
|
372 |
drawEdge(canvas, paint, left, bottom, color, strokes[l], vertices[l], ang, radii[l], borders, corners);
|
366 |
373 |
}
|
367 |
374 |
|
368 |
375 |
canvas.restore();
|
More support for configuring the stickers.