-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAINTROID-396 Multiline tool with movable intermediate points
- Loading branch information
1 parent
b34cc9b
commit 0bc32bf
Showing
5 changed files
with
119 additions
and
17 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
59 changes: 59 additions & 0 deletions
59
Paintroid/src/main/java/org/catrobat/paintroid/tools/helper/DynamicLineToolVertex.kt
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,59 @@ | ||
package org.catrobat.paintroid.tools.helper | ||
|
||
import android.graphics.Color | ||
import android.graphics.Paint | ||
import android.graphics.PointF | ||
import android.graphics.RectF | ||
import org.catrobat.paintroid.command.Command | ||
|
||
const val VERTEX_WIDTH = 30.0f | ||
|
||
class DynamicLineToolVertex(vertexCenter: PointF?, outgoingPathCommand: Command?, ingoingPathCommand: Command?) { | ||
var vertexCenter: PointF? = vertexCenter | ||
var vertex: RectF? = null | ||
var outgoingPathCommand: Command? = outgoingPathCommand | ||
var ingoingPathCommand: Command? = ingoingPathCommand | ||
|
||
init { | ||
if (vertexCenter != null) { | ||
vertex = RectF( | ||
vertexCenter.x - VERTEX_WIDTH, | ||
vertexCenter.y - VERTEX_WIDTH, | ||
vertexCenter.x + VERTEX_WIDTH, | ||
vertexCenter.y + VERTEX_WIDTH | ||
) | ||
} | ||
} | ||
|
||
fun updateVertex(newCenter: PointF) { | ||
vertexCenter = newCenter | ||
vertex = RectF( | ||
newCenter.x - VERTEX_WIDTH, | ||
newCenter.y - VERTEX_WIDTH, | ||
newCenter.x + VERTEX_WIDTH, | ||
newCenter.y + VERTEX_WIDTH | ||
) | ||
} | ||
|
||
companion object { | ||
private const val RECT_PAINT_ALPHA = 128 | ||
private const val RECT_PAINT_STROKE_WIDTH = 2f | ||
|
||
fun getPaint(): Paint { | ||
val paint = Paint() | ||
paint.run { | ||
style = Paint.Style.FILL | ||
color = Color.GRAY | ||
alpha = RECT_PAINT_ALPHA | ||
strokeWidth = RECT_PAINT_STROKE_WIDTH | ||
} | ||
return paint | ||
} | ||
|
||
fun isInsideVertex(clickedCoordinate: PointF, rectF: RectF): Boolean = | ||
clickedCoordinate.x < rectF.right && | ||
rectF.left < clickedCoordinate.x && | ||
clickedCoordinate.y < rectF.bottom && | ||
rectF.top < clickedCoordinate.y | ||
} | ||
} |
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