Ejemplo n.º 1
0
        public static DisplayMode GetGameDisplayMode()
        {
            DisplayMode d = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode;

            //if aspect ratio is 4X3 and width is higher than 1024
            if ((Math.Abs((d.AspectRatio - aspect4X3)) < 0.0005f) && d.Width > 1024)
            {
                foreach (DisplayMode displayMode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes)
                {
                    //search a 4/3 resolution
                    if (displayMode.Width == 1024 && displayMode.Height == 768)
                    {
                        return(displayMode);
                    }
                }
            }

            if (d.Width >= 1024)
            {
                //if aspect ration of the current resolution is 4X3(supported)
                if (Math.Abs((d.AspectRatio - aspect4X3)) < 0.0005f)
                {
                    return(d);
                }
                //if aspect ratio of the current resolution is 16X9(supported)
                if (Math.Abs((d.AspectRatio - aspect16X9)) < 0.0005f)
                {
                    return(d);
                }
            }

            //if current resolution is not 16X9 or 4X3 find the supported resolution that is
            //most equal to the current resolution (not supported)

            if ((Math.Abs(aspect16X9 - d.AspectRatio) < (Math.Abs(aspect4X3 - d.AspectRatio))))
            {
                foreach (DisplayMode displayMode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes)
                {
                    //search a 16/9 resolution
                    ScreenFormat f = Layout.CalculateScreenFormat(displayMode.Width, displayMode.Height);
                    if ((f == ScreenFormat.Format16X9 && displayMode.Width >= 1024))
                    {
                        return(displayMode);
                    }
                }
            }
            else
            {
                foreach (DisplayMode displayMode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes)
                {
                    //search a 4X3 resolution
                    ScreenFormat f = Layout.CalculateScreenFormat(displayMode.Width, displayMode.Height);
                    if (f == ScreenFormat.Format4X3 && displayMode.Width >= 1024)
                    {
                        return(displayMode);
                    }
                }
            }
            return(d);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Looks for the highest supported camera video preview resolution for the current screen format.
        /// </summary>
        /// <param name="areaSize">Preview area size.</param>
        /// <returns>Resolution found.</returns>
        private Size FindHighestSupportedPreviewResolution(Size areaSize)
        {
            ScreenFormat format = this.ScreenFormat;

            uint maxArea = unchecked ((uint)(areaSize.Width * areaSize.Height));

            IEnumerable <Size> supportedResolutions = this.camera.SupportedPreviewResolutions;

            // For the 16:9 format camera provides a native screen-size preview size, which isn't neccessary 16:9.
            // We want to use it, if available.
            if (format == ScreenFormat.SixteenByNine)
            {
                supportedResolutions = supportedResolutions
                                       .Where(r =>
                {
                    ScreenFormat currentFormat = this.GetScreenFormat(new Size(r.Width, r.Height));
                    return((r.Height * r.Width) < maxArea && (currentFormat == format || currentFormat == ScreenFormat.Unknown));
                });
            }
            else
            {
                supportedResolutions = supportedResolutions.Where(r => (r.Height * r.Width) < maxArea && (this.GetScreenFormat(new Size(r.Width, r.Height)) == format));
            }

            List <Size> supportedResolutionsList = supportedResolutions.ToList();

            return(supportedResolutionsList.Aggregate(supportedResolutionsList.First(), (max, current) => (max.Height * max.Width) < (current.Height * current.Width) ? current : max));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Looks for the highest supported camera photo resolution for the current screen format.
        /// </summary>
        /// <returns>Resolution found.</returns>
        private Size FindHighestSupportedPhotoResolution()
        {
            ScreenFormat format = this.ScreenFormat;

            List <Size> supportedResolutions = this.camera.SupportedPhotoResolutions
                                               .Where(r => r.Height * r.Width <= Constants.MaxSupportedResolution && this.GetScreenFormat(new Size(r.Width, r.Height)) == format)
                                               .ToList();

            return(supportedResolutions.Aggregate(supportedResolutions.First(), (max, current) => (max.Height * max.Width) < (current.Height * current.Width) ? current : max));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts the <paramref name="resolution"/> given to a proper <see cref="ScreenFormat"/> value.
        /// </summary>
        /// <param name="resolution">Screen resolution to convert.</param>
        /// <returns><see cref="ScreenFormat"/> value.</returns>
        private ScreenFormat GetScreenFormat(Size resolution)
        {
            ScreenFormat result = ScreenFormat.Unknown;

            double relation = Math.Max(resolution.Width, resolution.Height) / Math.Min(resolution.Width, resolution.Height);

            if (Math.Abs(relation - (4.0 / 3.0)) < 0.01)
            {
                result = ScreenFormat.FourByThree;
            }
            else if (Math.Abs(relation - (16.0 / 9.0)) < 0.01)
            {
                result = ScreenFormat.SixteenByNine;
            }

            return(result);
        }
Ejemplo n.º 5
0
 static public void CreateLayouts(int screenWidth, int screenHeight)
 {
     if (((screenWidth / (float)screenHeight) - (4 / (float)3)) < 0.05f)
     {
         screenFormat   = ScreenFormat.Format4X3;
         layoutPosition = new Vector2(screenWidth / (float)1024, screenHeight / (float)768);
     }
     else
     {
         if (((screenWidth / (float)screenHeight) - (16 / (float)9)) < 0.05f)
         {
             screenFormat   = ScreenFormat.Format16X9;
             layoutPosition = new Vector2(screenWidth / (float)1280, screenHeight / (float)720);
         }
         else
         {
             screenFormat   = ScreenFormat.Format4X3;// to implement in future versions
             layoutPosition = new Vector2(screenWidth / (float)1024, screenHeight / (float)768);
         }
     }
 }