Skip to content

Commit 867b5df

Browse files
committed
fix android mode arc mode lack feature
fix issue 48 (#48) . Because android does not use the AWT canvas,and the canvas.drawArc api is different.This commit use some trick to achieve the same function as AWT provides.
1 parent 1447ba7 commit 867b5df

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

core/src/processing/core/PGraphicsAndroid2D.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,13 +754,42 @@ protected void arcImpl(float x, float y, float w, float h,
754754
}
755755
} else if (mode == OPEN) {
756756
if (fill) {
757-
showMissingWarning("arc");
757+
// Work around:android does not support storke and fill with different color
758+
// after drawing the arc,draw the arc with Paint.Style.Stroke style again
759+
canvas.drawArc(rect, start, sweep, false, fillPaint);
760+
canvas.drawArc(rect, start, sweep, false, strokePaint);
758761
}
759762
if (stroke) {
760763
canvas.drawArc(rect, start, sweep, false, strokePaint);
761764
}
762765
} else if (mode == CHORD) {
763-
showMissingWarning("arc");
766+
// Work around: draw an extra line between start angle point and end point
767+
// to achiece the Chord
768+
float endAngle = start + sweep;
769+
float halfRectWidth = rect.width()/2;
770+
float halfRectHeight = rect.height()/2;
771+
float centerX = rect.centerX();
772+
float centerY = rect.cenerY();
773+
774+
float startX = (float) (halfWidth* Math.cos(Math.toRadians(start))) + centerX;
775+
float startY = (float) (halfHeight * Math.sin(Math.toRadians(start))) + centerY;
776+
float endX = (float) (halfWidth * Math.cos(Math.toRadians(endAngle))) + centerX;
777+
float endY = (float) (halfHeight * Math.sin(Math.toRadians(endAngle))) + centerY;
778+
779+
if(fill){
780+
// draw the fill arc
781+
canvas.drawArc(rect,start,sweep,false,fillPaint);
782+
// draw the arc round border
783+
canvas.drawAcr(rect,start,sweep,false,strokePaint);
784+
// draw the straight border
785+
canvas.drawLine(startX,startY,endX,endY,strokePaint);
786+
}
787+
if (stroke) {
788+
// draw the arc
789+
canvas.drawAcr(rect,start,sweep,false,strokePaint);
790+
// draw the straight border
791+
canvas.drawLine(startX,startY,endX,endY,strokePaint);
792+
}
764793

765794
} else if (mode == PIE) {
766795
if (fill) {
@@ -2179,4 +2208,4 @@ public void copy(int sx, int sy, int sw, int sh,
21792208
// loadPixels();
21802209
// super.save(filename);
21812210
// }
2182-
}
2211+
}

0 commit comments

Comments
 (0)