forked from geode-sdk/android-launcher
tweak zoom calculation
This commit is contained in:
2 files changed
+46
-28
No files matched your search
@@ -387,8 +387,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
||||
}
|
||||
|
||||
if (mScreenZoomFit && mScreenZoom != 1.0f) {
|
||||
frameLayout.scaleX = 1/mScreenZoom
|
||||
frameLayout.scaleY = 1/mScreenZoom
|
||||
frameLayout.fitZoom = true
|
||||
}
|
||||
|
||||
if (mScreenZoom != 1.0f) {
|
||||
|
||||
@@ -2,32 +2,19 @@ package com.geode.launcher.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.FrameLayout
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.floor
|
||||
import kotlin.math.min
|
||||
|
||||
class ConstrainedFrameLayout(context: Context) : FrameLayout(context) {
|
||||
// avoid running the aspect ratio fix when we don't need it
|
||||
var aspectRatio: Float? = null
|
||||
var zoom: Float? = null
|
||||
var fitZoom: Boolean = false
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
var paddingX = 0
|
||||
var paddingY = 0
|
||||
|
||||
val currentAspectRatio = aspectRatio
|
||||
if (currentAspectRatio != null) {
|
||||
val width = MeasureSpec.getSize(widthMeasureSpec)
|
||||
val height = MeasureSpec.getSize(heightMeasureSpec)
|
||||
if (width == 0 || height == 0) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
return
|
||||
}
|
||||
|
||||
val calculatedWidth = height * currentAspectRatio
|
||||
val padding = ((width - calculatedWidth) / 2).toInt()
|
||||
|
||||
// ignore paddings where the screen ends up looking odd
|
||||
paddingX += padding
|
||||
}
|
||||
var paddingX = 0.0f
|
||||
var paddingY = 0.0f
|
||||
|
||||
val currentZoom = zoom
|
||||
if (currentZoom != null) {
|
||||
@@ -38,16 +25,48 @@ class ConstrainedFrameLayout(context: Context) : FrameLayout(context) {
|
||||
return
|
||||
}
|
||||
|
||||
val zoomFactor = 1 - currentZoom
|
||||
val widthFactor = width/2.0f + paddingX/4.0f
|
||||
val heightFactor = height/2.0f
|
||||
val calculatedWidth = width * currentZoom
|
||||
val calculatedHeight = height * currentZoom
|
||||
|
||||
paddingX = (widthFactor * zoomFactor).roundToInt()
|
||||
paddingY = (heightFactor * zoomFactor).roundToInt()
|
||||
paddingX = (width - calculatedWidth)/2
|
||||
paddingY = (height - calculatedHeight)/2
|
||||
}
|
||||
|
||||
if (paddingX > 0 || paddingY > 0) {
|
||||
setPadding(paddingX, paddingY, paddingX, paddingY)
|
||||
val currentAspectRatio = aspectRatio
|
||||
if (currentAspectRatio != null) {
|
||||
val width = MeasureSpec.getSize(widthMeasureSpec)
|
||||
val height = MeasureSpec.getSize(heightMeasureSpec)
|
||||
if (width == 0 || height == 0) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
return
|
||||
}
|
||||
|
||||
val calculatedWidth = (height - paddingY * 2) * currentAspectRatio
|
||||
val padding = (width - calculatedWidth) / 2
|
||||
|
||||
paddingX = padding
|
||||
}
|
||||
|
||||
if (paddingX > 0.0 || paddingY > 0.0) {
|
||||
if (fitZoom) {
|
||||
val width = MeasureSpec.getSize(widthMeasureSpec)
|
||||
val height = MeasureSpec.getSize(heightMeasureSpec)
|
||||
|
||||
val calculatedHeight = (height - paddingY * 2)
|
||||
val calculatedWidth = (width - paddingX * 2)
|
||||
|
||||
val zoomFactor = min(height / calculatedHeight, width / calculatedWidth)
|
||||
|
||||
scaleX = zoomFactor
|
||||
scaleY = zoomFactor
|
||||
}
|
||||
|
||||
setPadding(
|
||||
ceil(paddingX).toInt(),
|
||||
ceil(paddingY).toInt(),
|
||||
floor(paddingX).toInt(),
|
||||
floor(paddingY).toInt()
|
||||
)
|
||||
}
|
||||
|
||||
super.onMeasure(
|
||||
|
||||
Reference in new issue
Block a user