예제 #1
0
        /// <summary>
        /// Creates a set of window settings from the current application state.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <returns>The window settings which were retrieved.</returns>
        public static UltravioletApplicationWindowSettings FromCurrentSettings(UltravioletContext uv)
        {
            Contract.Require(uv, nameof(uv));

            var primary = uv.GetPlatform().Windows.GetPrimary();

            if (primary == null)
            {
                return(null);
            }

            var settings = new UltravioletApplicationWindowSettings();

            settings.WindowState                      = primary.GetWindowState();
            settings.WindowMode                       = primary.GetWindowMode();
            settings.WindowScale                      = primary.WindowScale;
            settings.WindowedPosition                 = new Rectangle(primary.WindowedPosition, primary.WindowedClientSize);
            settings.FullscreenDisplayMode            = primary.GetFullscreenDisplayMode();
            settings.GrabsMouseWhenWindowed           = primary.GrabsMouseWhenWindowed;
            settings.GrabsMouseWhenFullscreenWindowed = primary.GrabsMouseWhenFullscreenWindowed;
            settings.GrabsMouseWhenFullscreen         = primary.GrabsMouseWhenFullscreen;
            settings.SynchronizeWithVerticalRetrace   = primary.SynchronizeWithVerticalRetrace;

            return(settings);
        }
예제 #2
0
        /// <summary>
        /// Saves the specified window settings to XML.
        /// </summary>
        /// <param name="settings">The window settings to save.</param>
        /// <returns>An XML element that represents the specified window settings.</returns>
        public static XElement Save(UltravioletApplicationWindowSettings settings)
        {
            if (settings == null)
            {
                return(null);
            }

            var pos = settings.WindowedPosition;

            return(new XElement("Window",
                                new XElement("WindowState", settings.WindowState),
                                new XElement("WindowMode", settings.WindowMode),
                                new XElement("WindowScale", settings.WindowScale),
                                new XElement("WindowedPosition", $"{pos.X} {pos.Y} {pos.Width} {pos.Height}"),
                                new XElement("GrabsMouseWhenWindowed", settings.GrabsMouseWhenWindowed),
                                new XElement("GrabsMouseWhenFullscreenWindowed", settings.GrabsMouseWhenFullscreenWindowed),
                                new XElement("GrabsMouseWhenFullscreen", settings.GrabsMouseWhenFullscreen),
                                new XElement("SynchronizeWithVerticalRetrace", settings.SynchronizeWithVerticalRetrace),
                                settings.FullscreenDisplayMode == null ? null : new XElement("FullscreenDisplayMode",
                                                                                             new XElement("Width", settings.FullscreenDisplayMode.Width),
                                                                                             new XElement("Height", settings.FullscreenDisplayMode.Height),
                                                                                             new XElement("BitsPerPixel", settings.FullscreenDisplayMode.BitsPerPixel),
                                                                                             new XElement("RefreshRate", settings.FullscreenDisplayMode.RefreshRate),
                                                                                             new XElement("DisplayIndex", settings.FullscreenDisplayMode?.DisplayIndex)
                                                                                             )
                                ));
        }
예제 #3
0
        /// <summary>
        /// Saves the specified application settings to the specified file.
        /// </summary>
        /// <param name="path">The path to the file in which to save the application settings.</param>
        /// <param name="settings">The <see cref="UltravioletApplicationSettings"/> to serialize to the specified file.</param>
        public static void Save(String path, UltravioletApplicationSettings settings)
        {
            var xml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
                                    new XElement("Settings",
                                                 UltravioletApplicationWindowSettings.Save(settings.Window),
                                                 UltravioletApplicationAudioSettings.Save(settings.Audio)
                                                 ));

            xml.Save(path);
        }
예제 #4
0
        /// <summary>
        /// Creates a set of application settings from the current application state.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <returns>The <see cref="UltravioletApplicationSettings"/> which was retrieved.</returns>
        public static UltravioletApplicationSettings FromCurrentSettings(UltravioletContext uv)
        {
            Contract.Require(uv, nameof(uv));

            var settings = new UltravioletApplicationSettings();

            settings.Window = UltravioletApplicationWindowSettings.FromCurrentSettings(uv);
            settings.Audio  = UltravioletApplicationAudioSettings.FromCurrentSettings(uv);

            return(settings);
        }
예제 #5
0
        /// <summary>
        /// Loads a set of application settings from the specified file.
        /// </summary>
        /// <param name="path">The path to the file from which to load the application settings.</param>
        /// <returns>The <see cref="UltravioletApplicationSettings"/> which were deserialized from the specified file
        /// or <see langword="null"/> if settings could not be loaded correctly.</returns>
        public static UltravioletApplicationSettings Load(String path)
        {
            var xml = XDocument.Load(path);

            var settings = new UltravioletApplicationSettings();

            settings.Window = UltravioletApplicationWindowSettings.Load(xml.Root.Element("Window"));
            settings.Audio  = UltravioletApplicationAudioSettings.Load(xml.Root.Element("Audio"));

            if (settings.Window == null && settings.Audio == null)
            {
                return(null);
            }

            return(settings);
        }
예제 #6
0
        /// <summary>
        /// Loads window settings from the specified XML element.
        /// </summary>
        /// <param name="xml">The XML element that contains the window settings to load.</param>
        /// <returns>The window settings that were loaded from the specified XML element or <see langword="null"/> if
        /// settings could not be loaded correctly.</returns>
        public static UltravioletApplicationWindowSettings Load(XElement xml)
        {
            if (xml == null)
            {
                return(null);
            }

            try
            {
                var settings = new UltravioletApplicationWindowSettings();

                settings.WindowState                      = xml.ElementValue <WindowState>("WindowState");
                settings.WindowMode                       = xml.ElementValue <WindowMode>("WindowMode");
                settings.WindowScale                      = (Single?)xml.Element("WindowScale") ?? 1f;
                settings.WindowedPosition                 = xml.ElementValue <Rectangle>("WindowedPosition");
                settings.GrabsMouseWhenWindowed           = xml.ElementValue <Boolean>("GrabsMouseWhenWindowed");
                settings.GrabsMouseWhenFullscreenWindowed = xml.ElementValue <Boolean>("GrabsMouseWhenFullscreenWindowed");
                settings.GrabsMouseWhenFullscreen         = xml.ElementValue <Boolean>("GrabsMouseWhenFullscreen");
                settings.SynchronizeWithVerticalRetrace   = xml.ElementValue <Boolean>("SynchronizeWithVerticalRetrace");

                var fullscreenDisplayMode = xml.Element("FullscreenDisplayMode");
                if (fullscreenDisplayMode != null)
                {
                    var width        = fullscreenDisplayMode.ElementValue <Int32>("Width");
                    var height       = fullscreenDisplayMode.ElementValue <Int32>("Height");
                    var bitsPerPixel = fullscreenDisplayMode.ElementValue <Int32>("BitsPerPixel");
                    var refreshRate  = fullscreenDisplayMode.ElementValue <Int32>("RefreshRate");
                    var displayIndex = fullscreenDisplayMode.ElementValue <Int32>("DisplayIndex");

                    settings.FullscreenDisplayMode = new DisplayMode(width, height, bitsPerPixel, refreshRate, displayIndex);
                }

                return(settings);
            }
            catch (FormatException)
            {
                return(null);
            }
            catch (TargetInvocationException e)
            {
                if (e.InnerException is FormatException)
                {
                    return(null);
                }
                throw;
            }
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UltravioletApplicationSettings"/> class.
 /// </summary>
 private UltravioletApplicationSettings()
 {
     Window = new UltravioletApplicationWindowSettings();
 }