Browse Source

Merge branch 'fixMovieView'

cooperku_kdanmobile 6 years ago
parent
commit
0306a0345a

+ 8 - 0
src/main/java/com/bomostory/sceneeditmodule/screen/movie/MovieEditActivity.kt

@@ -10,6 +10,7 @@ import android.os.Handler
 import android.support.v4.app.DialogFragment
 import android.support.v4.app.DialogFragment
 import android.support.v4.content.FileProvider
 import android.support.v4.content.FileProvider
 import android.support.v7.app.AppCompatActivity
 import android.support.v7.app.AppCompatActivity
+import android.util.DisplayMetrics
 import android.view.View
 import android.view.View
 import android.widget.CompoundButton
 import android.widget.CompoundButton
 import android.widget.SeekBar
 import android.widget.SeekBar
@@ -250,6 +251,13 @@ class MovieEditActivity : AppCompatActivity(),
                 }
                 }
             }
             }
         }
         }
+
+        val monitorSize = DisplayMetrics()
+        windowManager.defaultDisplay.getMetrics(monitorSize)
+        var layoutPrams = movieView.layoutParams
+        layoutPrams.width = monitorSize.widthPixels
+        layoutPrams.height = monitorSize.widthPixels.div(2)
+        movieView.layoutParams = layoutPrams
     }
     }
 
 
 
 

+ 53 - 19
src/main/java/com/bomostory/sceneeditmodule/screen/view/MovieView.kt

@@ -1,11 +1,15 @@
 package com.bomostory.sceneeditmodule.screen.view
 package com.bomostory.sceneeditmodule.screen.view
 
 
 import android.content.Context
 import android.content.Context
+import android.graphics.Paint
 import android.graphics.drawable.Drawable
 import android.graphics.drawable.Drawable
 import android.support.constraint.ConstraintLayout
 import android.support.constraint.ConstraintLayout
 import android.util.AttributeSet
 import android.util.AttributeSet
+import android.util.DisplayMetrics
 import android.view.ViewGroup
 import android.view.ViewGroup
+import android.view.WindowManager
 import android.widget.RelativeLayout
 import android.widget.RelativeLayout
+import com.bomostory.sceneeditmodule.basicdata.Actor
 import com.bomostory.sceneeditmodule.basicdata.Scene
 import com.bomostory.sceneeditmodule.basicdata.Scene
 import kotlin.math.pow
 import kotlin.math.pow
 
 
@@ -19,19 +23,60 @@ class MovieView : ConstraintLayout {
             value?.let {
             value?.let {
                 removeAllViews()
                 removeAllViews()
 
 
+                val screenWidth = it.sceneWidth
+                val screenHeight = it.sceneWidth / 2
+                val widthScaleFactor: Float = layoutParams.width / screenWidth.toFloat()
+                val heightScaleFactor: Float = layoutParams.height / screenHeight.toFloat()
+
                 backgroundView.apply {
                 backgroundView.apply {
-                    var lParams = RelativeLayout.LayoutParams(it.sceneWidth + it.sceneWidth.div(32),it.sceneWidth.div(2))
+                    val width = (it.sceneWidth * 33 / 32f * widthScaleFactor).toInt()
+                    val height = (it.sceneWidth / 2 * heightScaleFactor).toInt()
+                    var lParams = RelativeLayout.LayoutParams(width, height)
                     layoutParams = lParams
                     layoutParams = lParams
                     background = Drawable.createFromPath(it.backgroundPath)
                     background = Drawable.createFromPath(it.backgroundPath)
-                    x = -(it.sceneWidth.div(64)).toFloat()
+                    x = -width / 64f
                 }
                 }
                 addView(backgroundView)
                 addView(backgroundView)
 
 
+                val CONTROLLER_RADIUS = 25
                 for (layer in it.layers) {
                 for (layer in it.layers) {
                     val layerView = LayerView(context)
                     val layerView = LayerView(context)
+
+                    val actorsFix = ArrayList<Actor>()
+                    for (actor in layer.actors) {
+                        val actorFix = Actor().apply {
+                            resourcePath = actor.resourcePath
+                            if (!actor.isDialogue) {
+                                positionX = ((actor.positionX + CONTROLLER_RADIUS * 2) * widthScaleFactor).toInt()
+                                positionY = ((actor.positionY + CONTROLLER_RADIUS * 2) * heightScaleFactor).toInt()
+                                sideLength = ((actor.sideLength - CONTROLLER_RADIUS * 4) * widthScaleFactor).toInt()
+                                sideHeight = ((actor.sideHeight - CONTROLLER_RADIUS * 4) * heightScaleFactor).toInt()
+                            }
+                            else {
+                                positionX = actor.positionX
+                                positionY = actor.positionY
+                                sideLength = actor.sideLength
+                                sideHeight = actor.sideHeight
+                            }
+                            positionZ = actor.positionZ
+                            isSelect = actor.isSelect
+                            parentLayerIndex = actor.parentLayerIndex
+                            isMovable = actor.isMovable
+                            text = actor.text
+                            textColor = actor.textColor
+                            textAlign = actor.textAlign
+                            isDialogue = actor.isDialogue
+                            isMirror = actor.isMirror
+                            opacity = actor.opacity
+                            dialogColor = actor.dialogColor
+                            dialogType = actor.dialogType
+                        }
+                        actorsFix.add(actorFix)
+                    }
+
                     layerView.apply {
                     layerView.apply {
                         id = layer.id
                         id = layer.id
-                        actors = layer.actors
+                        actors = actorsFix
                     }
                     }
                     addView(layerView)
                     addView(layerView)
                 }
                 }
@@ -43,25 +88,14 @@ class MovieView : ConstraintLayout {
             field = value
             field = value
             scene?.let {
             scene?.let {
 
 
-                backgroundView.apply {
-                    layout(
-                            (value / 2f.pow(5)).toInt(),
-                            y.toInt(),
-                            (value / 2f.pow(5)).toInt() + width,
-                            y.toInt() + height
-                    )
-                }
+                val screenWidth = it.sceneWidth
+                val widthScaleFactor: Float = layoutParams.width / screenWidth.toFloat()
+
+                backgroundView.x = value * widthScaleFactor / 32f - backgroundView.width / 64f
 
 
                 for (layer in it.layers) {
                 for (layer in it.layers) {
                     val layerView = findViewById<LayerView>(layer.id)
                     val layerView = findViewById<LayerView>(layer.id)
-                    layerView.apply {
-                        layout(
-                                value / ((2f.pow(it.layers.indexOf(layer))).toInt()),
-                                y.toInt(),
-                                value / ((2f.pow(it.layers.indexOf(layer))).toInt()) + width,
-                                y.toInt() + height
-                        )
-                    }
+                    layerView.x = value * widthScaleFactor / (2f.pow(it.layers.indexOf(layer)))
                 }
                 }
             }
             }
         }
         }