Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void RecalculateScreen()
- {
- Display d = Activity.WindowManager.DefaultDisplay;
- graphics.PreferredBackBufferWidth = d.Width;
- graphics.PreferredBackBufferHeight = d.Height;
- graphics.ApplyChanges();
- DisplayMetrics metrics = new DisplayMetrics();
- d.GetMetrics(metrics);
- // Enum: Low = 120, Medium/Default = 160, High = 240, XHigh = 320
- // - přepočet na 100%: Low = 50, Medium/Default = 66.6, High = 100, XHigh = 133.3, XXH: 200
- // - Samsung Galaxy Ace 2: = High (240), ale densityX = 160
- // - převedeme to na 1f = default
- //var densityDPI = metrics.DensityDpi;
- var densityX = metrics.Xdpi;
- //TODO jak to bude vypadat na XXHigh = 480?
- Engine.Params.ScreenSize = new Microsoft.Xna.Framework.Point(d.Width, d.Height);
- Engine.Params.DpiScale = (float)densityX / (float)DisplayMetricsDensity.Default;
- Engine.Params.VirtualSize = new Point((int)(d.Width / (float)Engine.Params.DpiScale), (int)(d.Height / (float)Engine.Params.DpiScale));
- Engine.Params.IsTabletDevice = AndroidOperations.IsTabletDevice(Activity, Application.Context);
- Engine.Params.HQGraphics = false; // Zatím máme pro všechny HQGraphics = false (abychom si to nekomplikovali)
- // Přepočítá danou obrazovku
- Engine.RecalculateScreenResolution();
- }
- public static class AndroidOperations
- {
- public static bool IsTabletDevice(AndroidGameActivity activity, Context activityContext)
- {
- bool xlarge = (activityContext.Resources.Configuration.ScreenLayout & ScreenLayout.SizeMask) >= ScreenLayout.SizeLarge;
- // If XLarge, checks if the Generalized Density is at least MDPI
- // (160dpi)
- if (xlarge)
- {
- Display d = activity.WindowManager.DefaultDisplay;
- DisplayMetrics metrics = new DisplayMetrics();
- d.GetMetrics(metrics);
- // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,
- // DENSITY_TV=213, DENSITY_XHIGH=320
- if (metrics.DensityDpi != DisplayMetricsDensity.Low)
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment