mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-02-16 02:20:55 +00:00
Correctly scale the surface with 4:3 aspect ratios. Merged from 6f70's PR.
This commit is contained in:
@@ -220,14 +220,24 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
|
|
||||||
private void resizeSurfaceWithAspectRatio(SurfaceView sv, double vidWidth, double vidHeight)
|
private void resizeSurfaceWithAspectRatio(SurfaceView sv, double vidWidth, double vidHeight)
|
||||||
{
|
{
|
||||||
// Get the visible width of the activity
|
// Get the visible width of the activity
|
||||||
double visibleWidth = getWindow().getDecorView().getWidth();
|
double visibleWidth = getWindow().getDecorView().getWidth();
|
||||||
|
double visibleHeight = getWindow().getDecorView().getHeight();
|
||||||
ViewGroup.LayoutParams lp = sv.getLayoutParams();
|
|
||||||
|
ViewGroup.LayoutParams lp = sv.getLayoutParams();
|
||||||
// Calculate the new size of the SurfaceView
|
|
||||||
lp.width = (int) visibleWidth;
|
double vidRatio = vidHeight / vidWidth;
|
||||||
lp.height = (int) ((vidHeight / vidWidth) * visibleWidth);
|
double visibleRatio = visibleHeight / visibleWidth;
|
||||||
|
|
||||||
|
// Calculate the new size of the SurfaceView
|
||||||
|
if (vidRatio < visibleRatio) {
|
||||||
|
lp.width = (int) visibleWidth;
|
||||||
|
lp.height = (int) ((vidHeight / vidWidth) * visibleWidth);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lp.width = (int) ((vidWidth / vidHeight) * visibleHeight);
|
||||||
|
lp.height = (int) visibleHeight;
|
||||||
|
}
|
||||||
|
|
||||||
// Apply the size change
|
// Apply the size change
|
||||||
sv.setLayoutParams(lp);
|
sv.setLayoutParams(lp);
|
||||||
|
|||||||
Reference in New Issue
Block a user