forked from burhanrashid52/PhotoEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e617f96
commit 0e900b7
Showing
5 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
photoeditor/src/main/java/ja/burhanrashid52/photoeditor/shape/ArrowShape.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package ja.burhanrashid52.photoeditor.shape; | ||
|
||
import static java.lang.Math.cos; | ||
import static java.lang.Math.sin; | ||
|
||
import android.graphics.Path; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public class ArrowShape extends AbstractShape { | ||
|
||
private float lastX, lastY; | ||
|
||
@Override | ||
protected String getTag() { return "LineShape"; } | ||
|
||
@Override | ||
public void startShape(float x, float y) { | ||
Log.d(getTag(), "startShape@ " + x + "," + y); | ||
left = x; | ||
top = y; | ||
} | ||
|
||
@Override | ||
public void moveShape(float x, float y) { | ||
right = x; | ||
bottom = y; | ||
|
||
float dx = Math.abs(x - lastX); | ||
float dy = Math.abs(y - lastY); | ||
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { | ||
path = createLinePath(); | ||
lastX = x; | ||
lastY = y; | ||
} | ||
} | ||
|
||
private @NonNull Path createLinePath() { | ||
float angle = 90; | ||
float radius = 35; | ||
float angleRad = (float) (Math.PI*angle/180.0f); | ||
float lineAngle = (float) (Math.atan2(bottom-top,right-left)); | ||
Path path = new Path(); | ||
// line | ||
path.moveTo(left, top); | ||
path.lineTo(right, bottom); | ||
// arrow head | ||
path.moveTo(right, bottom); | ||
path.lineTo( | ||
(float)(right-radius*cos(lineAngle - (angleRad / 2.0))), | ||
(float)(bottom-radius*sin(lineAngle - (angleRad / 2.0))) | ||
); | ||
path.lineTo( | ||
(float)(right-radius*cos(lineAngle + (angleRad / 2.0))), | ||
(float)(bottom-radius*sin(lineAngle + (angleRad / 2.0))) | ||
); | ||
path.close(); | ||
return path; | ||
} | ||
|
||
@Override | ||
public void stopShape() { | ||
Log.d(getTag(), "stopShape"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ public enum ShapeType { | |
BRUSH, | ||
OVAL, | ||
RECTANGLE, | ||
LINE | ||
LINE, | ||
ARROW | ||
} |