/// <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);
        }
        /// <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);
        }
        /// <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);
        }
        /// <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)
        {
            Contract.Require(settings, "settings");

            return new XElement("Window",
                new XElement("WindowState",                    settings.WindowState),
                new XElement("WindowMode",                     settings.WindowMode),
                new XElement("WindowedPosition",               settings.WindowedPosition),
                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)
                )
            );
        }
Ejemplo n.º 5
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.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;
            }
        }
Ejemplo n.º 6
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)
        {
            Contract.Require(settings, nameof(settings));

            return(new XElement("Window",
                                new XElement("WindowState", settings.WindowState),
                                new XElement("WindowMode", settings.WindowMode),
                                new XElement("WindowedPosition", settings.WindowedPosition),
                                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)
                                                                                             )
                                ));
        }
        /// <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 <c>null</c> if 
        /// settings could not be loaded correctly.</returns>
        public static UltravioletApplicationWindowSettings Load(XElement xml)
        {
            Contract.Require(xml, "xml");

            try
            {
                var settings = new UltravioletApplicationWindowSettings();

                settings.WindowState                    = xml.ElementValue<WindowState>("WindowState");
                settings.WindowMode                     = xml.ElementValue<WindowMode>("WindowMode");
                settings.WindowedPosition               = xml.ElementValue<Rectangle>("WindowedPosition");
                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");

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

                return settings;
            }
            catch (FormatException)
            {
                return null;
            }
            catch (TargetInvocationException e)
            {
                if (e.InnerException is FormatException)
                {
                    return null;
                }
                throw;
            }
        }
Ejemplo n.º 8
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.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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UltravioletApplicationSettings"/> class.
 /// </summary>
 private UltravioletApplicationSettings()
 {
     Window = new UltravioletApplicationWindowSettings();
 }
        /// <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, "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.WindowedPosition               = new Rectangle(primary.WindowedPosition, primary.WindowedClientSize);
            settings.FullscreenDisplayMode          = primary.GetFullscreenDisplayMode();
            settings.SynchronizeWithVerticalRetrace = primary.SynchronizeWithVerticalRetrace;

            return settings;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UltravioletApplicationSettings"/> class.
 /// </summary>
 private UltravioletApplicationSettings()
 {
     Window = new UltravioletApplicationWindowSettings();
 }