private string windowTitle = Defaults.WindowTitle; //kernel #endregion Fields #region Constructors private GameConstants() { kernelConstantReaders.Add(XmlElements.CONTENT_FOLDER, s => { contentFolder = s; }); kernelConstantReaders.Add(XmlElements.FIXED_TIME_STEP, s => { fixedTimeStep = ReadBool(s, fixedTimeStep); }); kernelConstantReaders.Add(XmlElements.WINDOW_TITLE, s => { windowTitle = s; }); displayConstantReaders.Add(XmlElements.FULLSCREEN_TOGGLABLE, s => { fullscreenTogglable = ReadBool(s, fullscreenTogglable); }); displayConstantReaders.Add(XmlElements.MOUSE_VISIBILITY_TOGGLABLE, s => { mouseVisibilityTogglable = ReadBool(s, mouseVisibilityTogglable); }); displayConstantReaders.Add(XmlElements.BORDER_TOGGLABLE, s => { borderTogglable = ReadBool(s, borderTogglable); }); displayConstantReaders.Add(XmlElements.STATIC_RESOLUTION, s => { staticResolution = ReadBool(s, staticResolution); }); displayConstantReaders.Add(XmlElements.STATIC_ASPECT_RATIO, s => { staticAspectRatio = ReadBool(s, staticAspectRatio); }); displayConstantReaders.Add(XmlElements.ONLY_LANDSCAPE_RESOLUTIONS, s => { onlyLandscapeResolutions = ReadBool(s, onlyLandscapeResolutions); }); displayConstantReaders.Add(XmlElements.ONLY_PORTRAIT_RESOLUTIONS, s => { onlyPortraitResolutions = ReadBool(s, onlyPortraitResolutions); }); displayConstantReaders.Add(XmlElements.BASE_RESOLUTION, s => { baseResolution = ReadResolution(s, baseResolution); }); displayConstantReaders.Add(XmlElements.BACKGROUND_COLOUR, s => { bgColour = ReadColour(s, bgColour); }); optionDefaultsConstantReaders.Add(XmlElements.DEFAULT_FULLSCREEN, s => { defaultFullscreen = ReadBool(s, defaultFullscreen); }); optionDefaultsConstantReaders.Add(XmlElements.DEFAULT_MOUSE_VISIBILITY, s => { defaultMouseVisibility = ReadBool(s, defaultMouseVisibility); }); optionDefaultsConstantReaders.Add(XmlElements.DEFAULT_BORDERLESS, s => { defaultBorderless = ReadBool(s, defaultBorderless); }); optionDefaultsConstantReaders.Add(XmlElements.DEFAULT_VSYNC, s => { defaultVSync = ReadBool(s, defaultVSync); }); optionDefaultsConstantReaders.Add(XmlElements.DEFAULT_RESOLUTION, s => { defaultResolution = ReadResolution(s, defaultResolution); }); optionDefaultsConstantReaders.Add(XmlElements.DEFAULT_FRAME_RATE, s => { defaultFrameRate = ReadInt(s, defaultFrameRate); }); physicsConstantReaders.Add(XmlElements.PIXELS_PER_SIM_UNIT, s => { pixelsPerSimUnit = ReadFloat(s, pixelsPerSimUnit); }); debugConstantReaders.Add(XmlElements.DISABLE_USER_OPTIONS_WRITE_ON_CLOSE, s => { disableUserOptionsWriteOnClose = ReadBool(s, disableUserOptionsWriteOnClose); }); }
internal DisplayManager( GameKernel game , RenderPipeline renderPipeline , Resolution baseResolution , string windowTitle , Color bgColor ) { this.game = game; this.graphicsDevice = renderPipeline.GraphicsDevice; this.graphicsManager = renderPipeline.GraphicsDeviceManager; this.spriteBatch = renderPipeline.SpriteBatch; window = game.Window; WindowResolution = baseResolution; WindowTitle = windowTitle; BackgroundColour = bgColor; ReinitDisplayProperties(true); }
/// <summary> /// Setup the game's properties using the given setup parameters. /// </summary> public static void Setup( Action initializer , Resolution? baseResolution = null , bool fullscreen = GameProperties.DEFAULT_FULLSCREEN , bool fullscreenTogglable = GameProperties.DEFAULT_FULLSCREEN_TOGGLABLE , bool mouseVisible = GameProperties.DEFAULT_MOUSE_VISIBLE , bool mouseVisibilityTogglable = GameProperties.DEFAULT_MOUSE_VISIBILITY_TOGGLABLE , bool borderless = GameProperties.DEFAULT_BORDERLESS , bool borderTogglable = GameProperties.DEFAULT_BORDER_TOGGLABLE , bool vsync = GameProperties.DEFAULT_VSYNC , Color? bgColour = null , string windowTitle = null) { var properties = new GameProperties(); properties.BaseResolution = baseResolution.HasValue ? baseResolution.Value : GameProperties.DEFAULT_RESOLUTION; properties.BackgroundColour = bgColour.HasValue ? bgColour.Value : GameProperties.DEFAULT_BG_COLOUR; if (windowTitle != null) { properties.WindowTitle = windowTitle; } properties.Fullscreen = fullscreen; properties.FullscreenTogglable = fullscreenTogglable; properties.MouseVisible = mouseVisible; properties.MouseVisibilityTogglable = mouseVisibilityTogglable; properties.Borderless = borderless; properties.BorderTogglable = borderTogglable; properties.VSync = vsync; Setup(properties, initializer); }
public void SetResolution(Resolution resolution) { if (resolution != WindowResolution && GameConstants.StaticResolution) { throw new DisplayManagerException( String.Format( "Cannot change resolution. (Game Property '{0}' set to true)", GameConstants.XmlElements.STATIC_RESOLUTION ) ); } if (GameConstants.OnlyLandscapeResolutions && !resolution.IsLandscape) { throw new DisplayManagerException( String.Format( "Cannot change resolution to '{0}'; resolutions must be landscape. " + "(GameProperty '{1}' set to true)", resolution, GameConstants.XmlElements.ONLY_LANDSCAPE_RESOLUTIONS ) ); } else if (GameConstants.OnlyPortraitResolutions && !resolution.IsPortrait) { throw new DisplayManagerException( String.Format( "Cannot change resolution to '{0}'; resolutions must be portrait. " + "(GameProperty '{1}' set to true)", resolution, GameConstants.XmlElements.ONLY_PORTRAIT_RESOLUTIONS ) ); } var prev = WindowResolution; WindowResolution = resolution; dirty = true; iteratingResolutionChangeListeners = true; foreach (var obj in registeredResolutionChangeListeners) { if (obj.OnResolutionChanged != null) obj.OnResolutionChanged(prev, resolution, ResolutionScale); } iteratingResolutionChangeListeners = false; if (_toAdd.Count > 0) { foreach (var obj in _toAdd) registeredResolutionChangeListeners.Add(obj); _toAdd.Clear(); } if (_toRemove.Count > 0) { foreach (var obj in _toRemove) registeredResolutionChangeListeners.Remove(obj); _toRemove.Clear(); } }
/// <summary> /// Read a Resolution object from an XmlElement. /// </summary> private Resolution ReadResolution(XmlElement element, Resolution defaultValue) { var text = element.InnerText; if (text == NATIVE_RESOLUTION) { return Resolution.Native; } if (!Regex.IsMatch(text, RESOLUTION_REGEX)) { // Log that we couldn't figure out the resolution. return defaultValue; } var parts = text.Split('x'); var width = Int32.Parse(parts[0]); var height = Int32.Parse(parts[1]); return new Resolution(width, height); }
/// <summary> /// Read a Resolution object from a string in the xml file. /// </summary> /// <param name="s"></param> /// <param name="defaultVal"></param> /// <returns></returns> private Resolution ReadResolution(string s, Resolution defaultVal) { try { var parts = s.Split('x'); return new Resolution(Convert.ToInt32(parts[0]), Convert.ToInt32(parts[1])); } catch (Exception ex) { if (ex is FormatException || ex is IndexOutOfRangeException) { return defaultVal; } throw; } }