Merge pull request #9944 from JosJuice/android-nonsquare-buttons

Android: Allow non-square overlay control images
This commit is contained in:
JosJuice 2022-12-11 12:10:55 +01:00 committed by GitHub
commit 82e87cf7b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -106,11 +106,14 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// Determine the button size based on the smaller screen dimension.
// This makes sure the buttons are the same size in both portrait and landscape.
DisplayMetrics dm = context.getResources().getDisplayMetrics();
int minDimension = Math.min(dm.widthPixels, dm.heightPixels);
int minScreenDimension = Math.min(dm.widthPixels, dm.heightPixels);
int maxBitmapDimension = Math.max(bitmap.getWidth(), bitmap.getHeight());
float bitmapScale = scale * minScreenDimension / maxBitmapDimension;
return Bitmap.createScaledBitmap(bitmap,
(int) (minDimension * scale),
(int) (minDimension * scale),
(int) (bitmap.getWidth() * bitmapScale),
(int) (bitmap.getHeight() * bitmapScale),
true);
}