Bladeren bron

Merge branch 'actor-bound-setter'

cooperku_kdanmobile 6 jaren geleden
bovenliggende
commit
e7b84e9451

+ 29 - 10
src/main/java/com/bomostory/sceneeditmodule/SceneEditActivity.kt

@@ -2,6 +2,7 @@ package com.example.tfat.myapplication
 
 import android.app.Activity
 import android.app.ProgressDialog
+import android.content.Context
 import android.content.DialogInterface
 import android.content.Intent
 import android.graphics.Bitmap
@@ -805,14 +806,20 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
     }
 
     private fun addActor(positionX: Int, positionY: Int, resourcePath: String) {
+        val metrics = DisplayMetrics()
+        val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
+        windowManager.defaultDisplay.getMetrics(metrics);
+        val screenWidth = metrics.widthPixels;
+        val screenHeight = screenWidth / 2
+
         project.story?.let {
             it.scenes?.let{
                 val actorData = Actor()
-                actorData.positionX = positionX
-                actorData.positionY = positionY
-                actorData.positionZ = it[currentSceneIndex].layers[currentLayerIndex].actors.size
                 actorData.sideLength = ACTOR_WIDTH
                 actorData.sideHeight = ACTOR_HEIGHT
+                actorData.positionX = Math.max(0, Math.min(screenWidth - actorData.sideLength, positionX))
+                actorData.positionY = Math.max(0, Math.min(screenHeight - actorData.sideHeight, positionY))
+                actorData.positionZ = it[currentSceneIndex].layers[currentLayerIndex].actors.size
                 actorData.resourcePath = resourcePath
                 actorData.parentLayerIndex = currentLayerIndex
                 actorData.isMovable = true
@@ -825,14 +832,20 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
     }
 
     private fun addObject(positionX: Int, positionY: Int, resourcePath: String) {
+        val metrics = DisplayMetrics()
+        val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
+        windowManager.defaultDisplay.getMetrics(metrics);
+        val screenWidth = metrics.widthPixels;
+        val screenHeight = screenWidth / 2
+
         project.story?.let {
             it.scenes?.let{
                 val actorData = Actor()
-                actorData.positionX = positionX
-                actorData.positionY = positionY
-                actorData.positionZ = it[currentSceneIndex].layers[currentLayerIndex].actors.size
                 actorData.sideLength = ACTOR_WIDTH
                 actorData.sideHeight = ACTOR_HEIGHT
+                actorData.positionX = Math.max(0, Math.min(screenWidth - actorData.sideLength, positionX))
+                actorData.positionY = Math.max(0, Math.min(screenHeight - actorData.sideHeight, positionY))
+                actorData.positionZ = it[currentSceneIndex].layers[currentLayerIndex].actors.size
                 actorData.resourcePath = resourcePath
                 actorData.parentLayerIndex = currentLayerIndex
                 actorData.isMovable = true
@@ -844,15 +857,21 @@ class SceneEditActivity : AppCompatActivity(), ActorAdapter.OnActorDragListener,
         viewContainer.removeAllViews()
     }
     private fun addDialogue(positionX: Int, positionY: Int, resource: Int) {
+        val metrics = DisplayMetrics()
+        val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
+        windowManager.defaultDisplay.getMetrics(metrics);
+        val screenWidth = metrics.widthPixels;
+        val screenHeight = screenWidth / 2
+
         project.story?.let {
             it.scenes?.let{
                 val dialog = Actor()
-                dialog.resourcePath = resource.toString()
-                dialog.positionX = positionX
-                dialog.positionY = positionY
-                dialog.positionZ = it[currentSceneIndex].layers[currentLayerIndex].actors.size
                 dialog.sideLength = DIALOGUE_WIDTH
                 dialog.sideHeight = DIALOGUE_HEIGHT
+                dialog.resourcePath = resource.toString()
+                dialog.positionX = Math.max(0, Math.min(screenWidth - dialog.sideLength, positionX))
+                dialog.positionY = Math.max(0, Math.min(screenHeight - dialog.sideHeight, positionY))
+                dialog.positionZ = it[currentSceneIndex].layers[currentLayerIndex].actors.size
                 dialog.parentLayerIndex = currentLayerIndex
                 dialog.isMovable = true
                 dialog.isDialogue = true

+ 124 - 65
src/main/java/com/bomostory/sceneeditmodule/screen/view/DialogueView.kt

@@ -6,7 +6,9 @@ import android.util.AttributeSet
 import android.view.View
 import android.graphics.drawable.VectorDrawable
 import android.graphics.Bitmap
+import android.util.DisplayMetrics
 import android.view.MotionEvent
+import android.view.WindowManager
 import android.widget.RelativeLayout
 import com.bomostory.sceneeditmodule.DialogueDrawer
 import com.bomostory.sceneeditmodule.basicdata.Actor
@@ -20,6 +22,11 @@ class DialogueView : EditActorView{
 
     constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
 
+    val radius = 25f
+    val MIN_DIALOGUE_WIDTH = (400 - radius * 2) / 2f + radius * 2
+    val MIN_DIALOGUE_HEIGHT = (320 - radius * 2) / 2f + radius * 2
+    val DIALOGUE_RATIO = MIN_DIALOGUE_HEIGHT / MIN_DIALOGUE_WIDTH
+
     var dialogue = Actor()
         set(value) {
             value?.let {
@@ -75,13 +82,13 @@ class DialogueView : EditActorView{
                     if (!(Math.abs(motionEvent.x - positionStart) < 10 && Math.abs(motionEvent.y - positionEnd) < 10) && dialogue.isSelect) {
                         mx = motionEvent.rawX.toInt() - positionStart
                         my = motionEvent.rawY.toInt() - positionEnd
+                        dialogue.positionX = Math.max(0, Math.min(SCREEN_WIDTH - dialogue.sideLength, mx))
+                        dialogue.positionY = Math.max(0, Math.min(SCREEN_HEIGHT - dialogue.sideHeight, my - 200))
                         var laParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
-                        laParams.setMargins(mx, my - 200, 0, 0)
+                        laParams.setMargins(dialogue.positionX, dialogue.positionY, 0, 0)
                         actor_layout.layoutParams = laParams
                         val actorLayoutParams = RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
                         view.layoutParams = actorLayoutParams
-                        dialogue.positionX = mx
-                        dialogue.positionY = my - 200
                     }
                 }
                 MotionEvent.ACTION_UP -> {
@@ -101,40 +108,50 @@ class DialogueView : EditActorView{
     }
 
     override fun rightBottomSizeChangeListener() : View.OnTouchListener {
-        var positionX = 0
-        var positionY = 0
-        var sizeX = 0
-        var sizeY = 0
+        var positionX = 0f
+        var positionY = 0f
+        var sizeX = 0f
+        var sizeY = 0f
         var x = 0
         var y = 0
         return View.OnTouchListener { view, motionEvent ->
             when (motionEvent.action) {
                 MotionEvent.ACTION_DOWN -> {
                     val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
-                    sizeX = layoutParams.width
-                    sizeY = layoutParams.height
+                    sizeX = layoutParams.width.toFloat()
+                    sizeY = layoutParams.height.toFloat()
                     x = layoutParams.leftMargin
                     y = layoutParams.topMargin
-                    positionX = (motionEvent.rawX).toInt()
-                    positionY = (motionEvent.rawY).toInt()
+                    positionX = motionEvent.rawX
+                    positionY = motionEvent.rawY
                 }
                 MotionEvent.ACTION_MOVE -> {
-                    var mx =  motionEvent.rawX.toInt() - positionX
-                    var my =  motionEvent.rawY.toInt() - positionY
-                    var dP = when (Math.abs(mx) > Math.abs(my)){
-                        true ->  my
+                    var mx = Math.min(SCREEN_WIDTH - CONTROLLER_RADIUS.toFloat(), motionEvent.rawX) - positionX
+                    var my = Math.min(SCREEN_HEIGHT + SCREEN_TOP_MARGIN - CONTROLLER_RADIUS.toFloat(), motionEvent.rawY) - positionY
+                    var dP = when (my < mx){
+                        true -> my
                         false -> mx
                     }
                     var dialogueData = Actor().apply {
+                        when (my < mx){
+                            true -> {
+                                sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX + dP / DIALOGUE_RATIO).toInt()
+                                sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY + dP).toInt()
+                                this.positionX = x
+                                this.positionY = y
+                            }
+                            false -> {
+                                sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX + dP).toInt()
+                                sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY + dP * DIALOGUE_RATIO).toInt()
+                                this.positionX = x
+                                this.positionY = y
+                            }
+                        }
                         resourcePath = dialogue.resourcePath
                         text = dialogue.text
                         textColor = dialogue.textColor
                         textAlign = dialogue.textAlign
-                        this.positionX = x
-                        this.positionY = y
                         positionZ = dialogue.positionZ
-                        sideLength = sizeX + dP
-                        sideHeight = sizeY + dP
                         isSelect = dialogue.isSelect
                         parentLayerIndex = dialogue.parentLayerIndex
                         isMovable = dialogue.isMovable
@@ -154,40 +171,54 @@ class DialogueView : EditActorView{
     }
 
     override fun leftTopSizeChangeListener() : View.OnTouchListener {
-        var positionX = 0
-        var positionY = 0
-        var sizeX = 0
-        var sizeY = 0
+        var positionX = 0f
+        var positionY = 0f
+        var sizeX = 0f
+        var sizeY = 0f
         var x = 0
         var y = 0
+        var rightX = 0f
+        var bottomY = 0f
         return View.OnTouchListener { view, motionEvent ->
             when (motionEvent.action) {
                 MotionEvent.ACTION_DOWN -> {
                     val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
-                    sizeX = layoutParams.width
-                    sizeY = layoutParams.height
+                    sizeX = layoutParams.width.toFloat()
+                    sizeY = layoutParams.height.toFloat()
                     x = layoutParams.leftMargin
                     y = layoutParams.topMargin
-                    positionX = (motionEvent.rawX).toInt()
-                    positionY = (motionEvent.rawY).toInt()
+                    positionX = motionEvent.rawX
+                    positionY = motionEvent.rawY
+                    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)){
-                        true ->  my
+                    val mx = Math.max(CONTROLLER_RADIUS.toFloat(), motionEvent.rawX) - positionX
+                    var my = Math.max(SCREEN_TOP_MARGIN + CONTROLLER_RADIUS.toFloat(), motionEvent.rawY) - positionY
+                    var dP = when (my > mx){
+                        true -> my
                         false -> mx
                     }
                     var dialogueData = Actor().apply {
+                        when (my > mx){
+                            true -> {
+                                sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX - dP / DIALOGUE_RATIO).toInt()
+                                sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY - dP).toInt()
+                                this.positionX = Math.min(rightX - MIN_DIALOGUE_WIDTH, x + dP / DIALOGUE_RATIO).toInt()
+                                this.positionY = Math.min(bottomY - MIN_DIALOGUE_HEIGHT, y + dP).toInt()
+                            }
+                            false -> {
+                                sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX - dP).toInt()
+                                sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY - dP * DIALOGUE_RATIO).toInt()
+                                this.positionX = Math.min(rightX - MIN_DIALOGUE_WIDTH, x + dP).toInt()
+                                this.positionY = Math.min(bottomY - MIN_DIALOGUE_HEIGHT, y + dP * DIALOGUE_RATIO).toInt()
+                            }
+                        }
                         resourcePath = dialogue.resourcePath
                         text = dialogue.text
                         textColor = dialogue.textColor
                         textAlign = dialogue.textAlign
-                        this.positionX = x + dP
-                        this.positionY = y + dP
                         positionZ = dialogue.positionZ
-                        sideLength = sizeX - dP
-                        sideHeight = sizeY - dP
                         isSelect = dialogue.isSelect
                         parentLayerIndex = dialogue.parentLayerIndex
                         isMovable = dialogue.isMovable
@@ -207,40 +238,52 @@ class DialogueView : EditActorView{
     }
 
     override fun rightTopSizeChangeListener() : View.OnTouchListener {
-        var positionX = 0
-        var positionY = 0
-        var sizeX = 0
-        var sizeY = 0
+        var positionX = 0f
+        var positionY = 0f
+        var sizeX = 0f
+        var sizeY = 0f
         var x = 0
         var y = 0
+        var bottomY = 0f
         return View.OnTouchListener { view, motionEvent ->
             when (motionEvent.action) {
                 MotionEvent.ACTION_DOWN -> {
                     val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
-                    sizeX = layoutParams.width
-                    sizeY = layoutParams.height
+                    sizeX = layoutParams.width.toFloat()
+                    sizeY = layoutParams.height.toFloat()
                     x = layoutParams.leftMargin
                     y = layoutParams.topMargin
-                    positionX = (motionEvent.rawX).toInt()
-                    positionY = (motionEvent.rawY).toInt()
+                    positionX = motionEvent.rawX
+                    positionY = motionEvent.rawY
+                    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 mx = Math.min(SCREEN_WIDTH - CONTROLLER_RADIUS.toFloat(), motionEvent.rawX) - positionX
+                    var my = Math.max(SCREEN_TOP_MARGIN + CONTROLLER_RADIUS.toFloat(), motionEvent.rawY) - positionY
+                    var dP = when (-mx < my){
                         true ->  my
-                        false -> mx
+                        false -> -mx
                     }
                     var dialogueData = Actor().apply {
+                        when (-mx < my){
+                            true -> {
+                                sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX - dP / DIALOGUE_RATIO).toInt()
+                                sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY - dP).toInt()
+                                this.positionX = x
+                                this.positionY = Math.min(bottomY - MIN_DIALOGUE_HEIGHT, y + dP).toInt()
+                            }
+                            false -> {
+                                sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX - dP).toInt()
+                                sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY - dP * DIALOGUE_RATIO).toInt()
+                                this.positionX = x
+                                this.positionY = Math.min(bottomY - MIN_DIALOGUE_HEIGHT, y + dP * DIALOGUE_RATIO).toInt()
+                            }
+                        }
                         resourcePath = dialogue.resourcePath
                         text = dialogue.text
                         textColor = dialogue.textColor
                         textAlign = dialogue.textAlign
-                        this.positionX = x
-                        this.positionY = y + my
                         positionZ = dialogue.positionZ
-                        sideLength = sizeX + mx
-                        sideHeight = sizeY - my
                         isSelect = dialogue.isSelect
                         parentLayerIndex = dialogue.parentLayerIndex
                         isMovable = dialogue.isMovable
@@ -260,36 +303,52 @@ class DialogueView : EditActorView{
     }
 
     override fun leftBottomSizeChangeListener() : View.OnTouchListener {
-        var positionX = 0
-        var positionY = 0
-        var sizeX = 0
-        var sizeY = 0
+        var positionX = 0f
+        var positionY = 0f
+        var sizeX = 0f
+        var sizeY = 0f
         var x = 0
         var y = 0
+        var rightX = 0f
         return View.OnTouchListener { view, motionEvent ->
             when (motionEvent.action) {
                 MotionEvent.ACTION_DOWN -> {
                     val layoutParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
-                    sizeX = layoutParams.width
-                    sizeY = layoutParams.height
+                    sizeX = layoutParams.width.toFloat()
+                    sizeY = layoutParams.height.toFloat()
                     x = layoutParams.leftMargin
                     y = layoutParams.topMargin
-                    positionX = (motionEvent.rawX).toInt()
-                    positionY = (motionEvent.rawY).toInt()
+                    positionX = motionEvent.rawX
+                    positionY = motionEvent.rawY
+                    rightX = x + sizeX
                 }
                 MotionEvent.ACTION_MOVE -> {
-                    var mx =  motionEvent.rawX.toInt() - positionX
-                    var my =  motionEvent.rawY.toInt() - positionY
+                    val mx = Math.max(CONTROLLER_RADIUS.toFloat(), motionEvent.rawX) - positionX
+                    var my = Math.min(SCREEN_HEIGHT + SCREEN_TOP_MARGIN - CONTROLLER_RADIUS.toFloat(), motionEvent.rawY) - positionY
+                    var dP = when (-mx > my){
+                        true -> my
+                        false -> -mx
+                    }
                     var dialogueData = Actor().apply {
+                        when (-mx > my){
+                            true -> {
+                                sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX + dP / DIALOGUE_RATIO).toInt()
+                                sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY + dP).toInt()
+                                this.positionX = Math.min(rightX - MIN_DIALOGUE_WIDTH, x - dP / DIALOGUE_RATIO).toInt()
+                                this.positionY = y
+                            }
+                            false -> {
+                                sideLength = Math.max(MIN_DIALOGUE_WIDTH, sizeX + dP).toInt()
+                                sideHeight = Math.max(MIN_DIALOGUE_HEIGHT, sizeY + dP * DIALOGUE_RATIO).toInt()
+                                this.positionX = Math.min(rightX - MIN_DIALOGUE_WIDTH, x - dP).toInt()
+                                this.positionY = y
+                            }
+                        }
                         resourcePath = dialogue.resourcePath
                         text = dialogue.text
                         textColor = dialogue.textColor
                         textAlign = dialogue.textAlign
-                        this.positionX = x + mx
-                        this.positionY = y
                         positionZ = dialogue.positionZ
-                        sideLength = sizeX - mx
-                        sideHeight = sizeY + my
                         isSelect = dialogue.isSelect
                         parentLayerIndex = dialogue.parentLayerIndex
                         isMovable = dialogue.isMovable

+ 35 - 20
src/main/java/com/bomostory/sceneeditmodule/screen/view/EditActorView.kt

@@ -10,7 +10,8 @@ import android.widget.RelativeLayout
 import com.example.tfat.myapplication.R
 import kotlinx.android.synthetic.main.actor_view.view.*
 import com.bomostory.sceneeditmodule.basicdata.Actor
-
+import android.view.WindowManager
+import android.util.DisplayMetrics
 
 open class EditActorView @JvmOverloads constructor(
         context: Context,
@@ -40,7 +41,25 @@ open class EditActorView @JvmOverloads constructor(
             }
         }
 
+    val CONTROLLER_RADIUS = 25
     val MIN_ACTOR_SIZE = 160
+    val SCREEN_TOP_MARGIN by lazy {
+        val resources = context.resources
+        val metrics = resources.displayMetrics
+        (128 * (metrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT)).toInt()
+    }
+
+    val SCREEN_WIDTH by lazy {
+        val metrics = DisplayMetrics()
+        val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
+        windowManager.defaultDisplay.getMetrics(metrics);
+        metrics.widthPixels
+    }
+
+    val SCREEN_HEIGHT by lazy {
+        SCREEN_WIDTH / 2
+    }
+
     var actorCallback: OnActorChangeListener? = null
 
     private fun initView() {
@@ -53,7 +72,6 @@ open class EditActorView @JvmOverloads constructor(
         resize_button_left_bottom.setOnTouchListener(leftBottomSizeChangeListener())
     }
 
-
     private fun actorOnTouchListener() : View.OnTouchListener {
         var clickPeriod = 0L
         var positionStart = 0
@@ -71,13 +89,13 @@ open class EditActorView @JvmOverloads constructor(
                     if (!(Math.abs(motionEvent.x - positionStart) < 10 && Math.abs(motionEvent.y - positionEnd) < 10) && actor.isSelect) {
                         mx = motionEvent.rawX.toInt() - positionStart
                         my = motionEvent.rawY.toInt() - positionEnd
+                        actor.positionX = Math.max(0, Math.min(SCREEN_WIDTH - actor.sideLength, mx))
+                        actor.positionY = Math.max(0, Math.min(SCREEN_HEIGHT - actor.sideHeight, my - 200))
                         var laParams = actor_layout.layoutParams as RelativeLayout.LayoutParams
-                        laParams.setMargins(mx, my - 200, 0, 0)
+                        laParams.setMargins(actor.positionX, actor.positionY, 0, 0)
                         actor_layout.layoutParams = laParams
                         val actorLayoutParams = RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
                         view.layoutParams = actorLayoutParams
-                        actor.positionX = mx
-                        actor.positionY = my - 200
                     }
                 }
                 MotionEvent.ACTION_UP -> {
@@ -106,7 +124,6 @@ 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,11 +133,10 @@ open class EditActorView @JvmOverloads constructor(
                     positionY = (motionEvent.rawY).toInt()
                 }
                 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 mx = Math.min(SCREEN_WIDTH - CONTROLLER_RADIUS, motionEvent.rawX.toInt()) - positionX
+                    var my = Math.min(SCREEN_HEIGHT + SCREEN_TOP_MARGIN - CONTROLLER_RADIUS, motionEvent.rawY.toInt()) - positionY
                     var dP = when (my < mx){
-                        true ->  my
+                        true -> my
                         false -> mx
                     }
                     var actorData = Actor().apply {
@@ -143,7 +159,6 @@ open class EditActorView @JvmOverloads constructor(
                     actor = actorData
                 }
                 MotionEvent.ACTION_UP -> {
-                    println("ACTION_UP")
                     actor.isSelect = true
                     actorCallback?.onActorChange(actor)
                 }
@@ -175,10 +190,10 @@ open class EditActorView @JvmOverloads constructor(
                     bottomY = y + sizeY
                 }
                 MotionEvent.ACTION_MOVE -> {
-                    val mx =  motionEvent.rawX.toInt() - positionX
-                    val my =  motionEvent.rawY.toInt() - positionY
+                    val mx = Math.max(CONTROLLER_RADIUS, motionEvent.rawX.toInt()) - positionX
+                    var my = Math.max(SCREEN_TOP_MARGIN + CONTROLLER_RADIUS, motionEvent.rawY.toInt()) - positionY
                     var dP = when (my > mx){
-                        true ->  my
+                        true -> my
                         false -> mx
                     }
                     var actorData = Actor().apply {
@@ -230,10 +245,10 @@ open class EditActorView @JvmOverloads constructor(
                     bottomY = y + sizeY
                 }
                 MotionEvent.ACTION_MOVE -> {
-                    var mx =  motionEvent.rawX.toInt() - positionX
-                    var my =  motionEvent.rawY.toInt() - positionY
+                    var mx = Math.min(SCREEN_WIDTH - CONTROLLER_RADIUS, motionEvent.rawX.toInt()) - positionX
+                    var my = Math.max(SCREEN_TOP_MARGIN + CONTROLLER_RADIUS, motionEvent.rawY.toInt()) - positionY
                     var dP = when (-mx < my){
-                        true ->  my
+                        true -> my
                         false -> -mx
                     }
                     var actorData = Actor().apply {
@@ -285,10 +300,10 @@ open class EditActorView @JvmOverloads constructor(
                     rightX = x + sizeX
                 }
                 MotionEvent.ACTION_MOVE -> {
-                    var mx =  motionEvent.rawX.toInt() - positionX
-                    var my =  motionEvent.rawY.toInt() - positionY
+                    val mx = Math.max(CONTROLLER_RADIUS, motionEvent.rawX.toInt()) - positionX
+                    var my = Math.min(SCREEN_HEIGHT + SCREEN_TOP_MARGIN - CONTROLLER_RADIUS, motionEvent.rawY.toInt()) - positionY
                     var dP = when (-mx > my){
-                        true ->  my
+                        true -> my
                         false -> -mx
                     }
                     var actorData = Actor().apply {