|
@@ -40,6 +40,7 @@ open class EditActorView @JvmOverloads constructor(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ val MIN_ACTOR_SIZE = 160
|
|
|
var actorCallback: OnActorChangeListener? = null
|
|
|
|
|
|
private fun initView() {
|
|
@@ -105,6 +106,7 @@ open class EditActorView @JvmOverloads constructor(
|
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
|
when (motionEvent.action) {
|
|
|
MotionEvent.ACTION_DOWN -> {
|
|
|
+ println("ACTION_DOWN")
|
|
|
val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
|
|
|
sizeX = layoutParams.width
|
|
|
sizeY = layoutParams.height
|
|
@@ -116,13 +118,14 @@ open class EditActorView @JvmOverloads constructor(
|
|
|
MotionEvent.ACTION_MOVE -> {
|
|
|
var mx = motionEvent.rawX.toInt() - positionX
|
|
|
var my = motionEvent.rawY.toInt() - positionY
|
|
|
- var dP = when (Math.abs(mx) > Math.abs(my)){
|
|
|
+// var dP = when (Math.abs(mx) > Math.abs(my)){
|
|
|
+ var dP = when (my < mx){
|
|
|
true -> my
|
|
|
false -> mx
|
|
|
}
|
|
|
var actorData = Actor().apply {
|
|
|
- sideLength = sizeX + dP
|
|
|
- sideHeight = sizeY + dP
|
|
|
+ sideLength = Math.max(MIN_ACTOR_SIZE, sizeX + dP)
|
|
|
+ sideHeight = Math.max(MIN_ACTOR_SIZE, sizeY + dP)
|
|
|
this.positionX = x
|
|
|
this.positionY = y
|
|
|
resourcePath = actor.resourcePath
|
|
@@ -140,6 +143,7 @@ open class EditActorView @JvmOverloads constructor(
|
|
|
actor = actorData
|
|
|
}
|
|
|
MotionEvent.ACTION_UP -> {
|
|
|
+ println("ACTION_UP")
|
|
|
actor.isSelect = true
|
|
|
actorCallback?.onActorChange(actor)
|
|
|
}
|
|
@@ -155,6 +159,8 @@ open class EditActorView @JvmOverloads constructor(
|
|
|
var sizeY = 0
|
|
|
var x = 0
|
|
|
var y = 0
|
|
|
+ var rightX = 0
|
|
|
+ var bottomY = 0
|
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
|
when (motionEvent.action) {
|
|
|
MotionEvent.ACTION_DOWN -> {
|
|
@@ -165,19 +171,21 @@ open class EditActorView @JvmOverloads constructor(
|
|
|
y = layoutParams.topMargin
|
|
|
positionX = (motionEvent.rawX).toInt()
|
|
|
positionY = (motionEvent.rawY).toInt()
|
|
|
+ rightX = x + sizeX
|
|
|
+ bottomY = y + sizeY
|
|
|
}
|
|
|
MotionEvent.ACTION_MOVE -> {
|
|
|
val mx = motionEvent.rawX.toInt() - positionX
|
|
|
val my = motionEvent.rawY.toInt() - positionY
|
|
|
- var dP = when (Math.abs(mx) > Math.abs(my)){
|
|
|
+ var dP = when (my > mx){
|
|
|
true -> my
|
|
|
false -> mx
|
|
|
}
|
|
|
var actorData = Actor().apply {
|
|
|
- sideLength = sizeX - dP
|
|
|
- sideHeight = sizeY - dP
|
|
|
- this.positionX = x + dP
|
|
|
- this.positionY = y + dP
|
|
|
+ sideLength = Math.max(MIN_ACTOR_SIZE, sizeX - dP)
|
|
|
+ sideHeight = Math.max(MIN_ACTOR_SIZE, sizeY - dP)
|
|
|
+ this.positionX = Math.min(rightX - MIN_ACTOR_SIZE, x + dP)
|
|
|
+ this.positionY = Math.min(bottomY - MIN_ACTOR_SIZE, y + dP)
|
|
|
resourcePath = actor.resourcePath
|
|
|
text = actor.text
|
|
|
textColor = actor.textColor
|
|
@@ -208,6 +216,7 @@ open class EditActorView @JvmOverloads constructor(
|
|
|
var sizeY = 0
|
|
|
var x = 0
|
|
|
var y = 0
|
|
|
+ var bottomY = 0
|
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
|
when (motionEvent.action) {
|
|
|
MotionEvent.ACTION_DOWN -> {
|
|
@@ -218,19 +227,20 @@ open class EditActorView @JvmOverloads constructor(
|
|
|
y = layoutParams.topMargin
|
|
|
positionX = (motionEvent.rawX).toInt()
|
|
|
positionY = (motionEvent.rawY).toInt()
|
|
|
+ bottomY = y + sizeY
|
|
|
}
|
|
|
MotionEvent.ACTION_MOVE -> {
|
|
|
var mx = motionEvent.rawX.toInt() - positionX
|
|
|
var my = motionEvent.rawY.toInt() - positionY
|
|
|
- var dP = when (Math.abs(mx) > Math.abs(my)){
|
|
|
+ var dP = when (-mx < my){
|
|
|
true -> my
|
|
|
- false -> mx
|
|
|
+ false -> -mx
|
|
|
}
|
|
|
var actorData = Actor().apply {
|
|
|
- sideLength = sizeX + mx
|
|
|
- sideHeight = sizeY - my
|
|
|
+ sideLength = Math.max(MIN_ACTOR_SIZE, sizeX - dP)
|
|
|
+ sideHeight = Math.max(MIN_ACTOR_SIZE, sizeY - dP)
|
|
|
this.positionX = x
|
|
|
- this.positionY = y + my
|
|
|
+ this.positionY = Math.min(bottomY - MIN_ACTOR_SIZE, y + dP)
|
|
|
resourcePath = actor.resourcePath
|
|
|
text = actor.text
|
|
|
textColor = actor.textColor
|
|
@@ -261,6 +271,7 @@ open class EditActorView @JvmOverloads constructor(
|
|
|
var sizeY = 0
|
|
|
var x = 0
|
|
|
var y = 0
|
|
|
+ var rightX = 0
|
|
|
return View.OnTouchListener { view, motionEvent ->
|
|
|
when (motionEvent.action) {
|
|
|
MotionEvent.ACTION_DOWN -> {
|
|
@@ -271,14 +282,19 @@ open class EditActorView @JvmOverloads constructor(
|
|
|
y = layoutParams.topMargin
|
|
|
positionX = (motionEvent.rawX).toInt()
|
|
|
positionY = (motionEvent.rawY).toInt()
|
|
|
+ rightX = x + sizeX
|
|
|
}
|
|
|
MotionEvent.ACTION_MOVE -> {
|
|
|
var mx = motionEvent.rawX.toInt() - positionX
|
|
|
var my = motionEvent.rawY.toInt() - positionY
|
|
|
+ var dP = when (-mx > my){
|
|
|
+ true -> my
|
|
|
+ false -> -mx
|
|
|
+ }
|
|
|
var actorData = Actor().apply {
|
|
|
- sideLength = sizeX - mx
|
|
|
- sideHeight = sizeY + my
|
|
|
- this.positionX = x + mx
|
|
|
+ sideLength = Math.max(MIN_ACTOR_SIZE, sizeX + dP)
|
|
|
+ sideHeight = Math.max(MIN_ACTOR_SIZE, sizeY + dP)
|
|
|
+ this.positionX = Math.min(rightX - MIN_ACTOR_SIZE, x - dP)
|
|
|
this.positionY = y
|
|
|
resourcePath = actor.resourcePath
|
|
|
text = actor.text
|