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) {
|
if (mScreenZoomFit && mScreenZoom != 1.0f) {
|
||||||
frameLayout.scaleX = 1/mScreenZoom
|
frameLayout.fitZoom = true
|
||||||
frameLayout.scaleY = 1/mScreenZoom
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mScreenZoom != 1.0f) {
|
if (mScreenZoom != 1.0f) {
|
||||||
|
|||||||
@@ -2,32 +2,19 @@ package com.geode.launcher.utils
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.widget.FrameLayout
|
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) {
|
class ConstrainedFrameLayout(context: Context) : FrameLayout(context) {
|
||||||
// avoid running the aspect ratio fix when we don't need it
|
// avoid running the aspect ratio fix when we don't need it
|
||||||
var aspectRatio: Float? = null
|
var aspectRatio: Float? = null
|
||||||
var zoom: Float? = null
|
var zoom: Float? = null
|
||||||
|
var fitZoom: Boolean = false
|
||||||
|
|
||||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
var paddingX = 0
|
var paddingX = 0.0f
|
||||||
var paddingY = 0
|
var paddingY = 0.0f
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
val currentZoom = zoom
|
val currentZoom = zoom
|
||||||
if (currentZoom != null) {
|
if (currentZoom != null) {
|
||||||
@@ -38,16 +25,48 @@ class ConstrainedFrameLayout(context: Context) : FrameLayout(context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val zoomFactor = 1 - currentZoom
|
val calculatedWidth = width * currentZoom
|
||||||
val widthFactor = width/2.0f + paddingX/4.0f
|
val calculatedHeight = height * currentZoom
|
||||||
val heightFactor = height/2.0f
|
|
||||||
|
|
||||||
paddingX = (widthFactor * zoomFactor).roundToInt()
|
paddingX = (width - calculatedWidth)/2
|
||||||
paddingY = (heightFactor * zoomFactor).roundToInt()
|
paddingY = (height - calculatedHeight)/2
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paddingX > 0 || paddingY > 0) {
|
val currentAspectRatio = aspectRatio
|
||||||
setPadding(paddingX, paddingY, paddingX, paddingY)
|
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(
|
super.onMeasure(
|
||||||
|
|||||||
Reference in new issue
Block a user