public void makeMenu( Template template ) { // Start makeMenu. // Capturing the current screen size: tempScreenSize = new Vector2( GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height ); // Basic required information to make a menu: _name = template.Name; #region Setting Size and Position Data for the menu // Setting up the size and position if ( template.Size != MenuDefines.MenuSize.Custom ) { // Start if size not equal to custom. #region Size and position Switch switch (template.Size) { // Start Size and position Switch. case MenuDefines.MenuSize.HalfTop: _menuSize = new Vector2( tempScreenSize.X, ( tempScreenSize.Y / 2 )); _position = Vector2.Zero; break; case MenuDefines.MenuSize.HalfBottom: _menuSize = new Vector2(tempScreenSize.X, (tempScreenSize.Y / 2)); _position = new Vector2(0, (tempScreenSize.Y / 2)); break; case MenuDefines.MenuSize.HalfLeft: _menuSize = new Vector2((tempScreenSize.X / 2), tempScreenSize.Y); _position = Vector2.Zero; break; case MenuDefines.MenuSize.HalfRight: _menuSize = new Vector2((tempScreenSize.X / 2), tempScreenSize.Y); _position = new Vector2((tempScreenSize.X / 2), 0); break; case MenuDefines.MenuSize.HalfCentred: _menuSize = new Vector2((tempScreenSize.X / 2), (tempScreenSize.Y / 2)); _position = new Vector2(( tempScreenSize.X / 4 ), ( tempScreenSize.Y / 4 )); break; case MenuDefines.MenuSize.FullScreen: default: _menuSize = tempScreenSize; _position = Vector2.Zero; break; } // End Size and position Switch. #endregion }// End if size not equal to custom. else { // Start else we are using a custom sized menu. #region Checking our custom size if ( template.CustomSize.X > tempScreenSize.X ) { _menuSize.X = tempScreenSize.X; } else { _menuSize.X = tempScreenSize.X; } if ( template.CustomSize.Y > tempScreenSize.Y ) { _menuSize.Y = tempScreenSize.Y; } else { _menuSize.Y = tempScreenSize.Y; } #endregion #region Checking our custom position if ( template.CustomPosition.X > tempScreenSize.X ) { _position.X = 0; } else { _position.X = template.CustomPosition.X; } if ( template.CustomPosition.Y > tempScreenSize.Y ) { _position.Y = 0; } else { _position.Y = template.CustomPosition.Y; } #endregion } // End else we are using a custom sized menu. #endregion _targetScreen = template.TargetScreen; // // Extended information: // _backgroundColor = template.BackgroundColor; _backgroundTransparancy = template.BackgroundTransparancy; #region Setting up the borders, this must be done before we create the background in order to corect for the border size: // Setting the background size to be the same as the menu, we will then correct it if needed. _backgroundSize = _menuSize; // If there is no border then skip this step: if ( template.Border != MenuDefines.BorderList.None ) { // Start if there is no border. _borderColor = template.BorderColor; _borderThickness = template.BorderThickness; _borderThicknessTimesTwo = ( _borderThickness * 2 ); // USed to reduce math. _borderTransparancy = template.BorderTransparancy; _borderImage = new Texture2D[MenuDefines.numberOfBorderSides]; _backgroundPositionCorection = Vector2.Zero; //if ( template.CustomBorderImagePath != null || template.CustomBorderImagePath != "" ) //{ // try // { // _borderImage = MenuManager.Instance.Content.Load<Texture2D>(template.CustomBorderImagePath); // } // catch (System.Exception ex) // { // template.Border = MenuDefines.BorderList.AllSides; // } //} #region Border creation switch switch (template.Border) { // Start border switch. case MenuDefines.BorderList.TopOnly: _borderImage[ (int)MenuDefines.BorderLocation.Top ] = ShapeBuilder.makeRectangle( MenuManager.Instance.GraphicsDevice, _borderThickness, _borderThickness, _borderColor ); _backgroundSize.Y = (int)(_menuSize.Y - _borderThickness); _backgroundPositionCorection.Y = _borderThickness; break; case MenuDefines.BorderList.BottomOnly: _borderImage[ (int)MenuDefines.BorderLocation.Bottom ] = ShapeBuilder.makeRectangle( MenuManager.Instance.GraphicsDevice, _borderThickness, _borderThickness, _borderColor ); _backgroundSize.Y = (int)(_menuSize.Y - _borderThickness); _backgroundPositionCorection.Y = _borderThickness; break; case MenuDefines.BorderList.TopAndBotom: _borderImage[ (int)MenuDefines.BorderLocation.Top ] = ShapeBuilder.makeRectangle( MenuManager.Instance.GraphicsDevice, _borderThickness, _borderThickness, _borderColor ); _borderImage[ (int)MenuDefines.BorderLocation.Bottom ] = _borderImage[ (int)MenuDefines.BorderLocation.Top ]; _backgroundSize.Y = (int)( _menuSize.Y - _borderThicknessTimesTwo ); _backgroundPositionCorection.Y = _borderThickness; break; case MenuDefines.BorderList.SidesOnly: _borderImage[ (int)MenuDefines.BorderLocation.Left ] = ShapeBuilder.makeRectangle( MenuManager.Instance.GraphicsDevice, _borderThickness, _borderThickness, _borderColor ); _borderImage[ (int)MenuDefines.BorderLocation.Right ] = _borderImage[ (int)MenuDefines.BorderLocation.Left ]; _backgroundSize.X = (int)( _menuSize.X - _borderThicknessTimesTwo ); _backgroundPositionCorection.X = _borderThickness; break; case MenuDefines.BorderList.TopAndSides: _borderImage[ (int)MenuDefines.BorderLocation.Top ] = ShapeBuilder.makeRectangle( MenuManager.Instance.GraphicsDevice, _borderThickness, _borderThickness, _borderColor ); _borderImage[ (int)MenuDefines.BorderLocation.Left ] = _borderImage[ (int)MenuDefines.BorderLocation.Top ]; _borderImage[ (int)MenuDefines.BorderLocation.Right ] = _borderImage[ (int)MenuDefines.BorderLocation.Top ]; _backgroundSize.X = (int)( _menuSize.X - _borderThicknessTimesTwo ); _backgroundSize.Y = (int)( _menuSize.Y - _borderThickness ); _backgroundPositionCorection.X = _borderThickness; _backgroundPositionCorection.Y = _borderThickness; break; case MenuDefines.BorderList.BottomAndSides: _borderImage[ (int)MenuDefines.BorderLocation.Left ] = ShapeBuilder.makeRectangle(MenuManager.Instance.GraphicsDevice, _borderThickness, _borderThickness, _borderColor); _borderImage[ (int)MenuDefines.BorderLocation.Right ] = _borderImage[ (int)MenuDefines.BorderLocation.Left ]; _borderImage[ (int)MenuDefines.BorderLocation.Bottom ] = _borderImage[ (int)MenuDefines.BorderLocation.Left ]; _backgroundSize.X = (int)( _menuSize.X - _borderThicknessTimesTwo ); _backgroundSize.Y = (int)( _menuSize.Y - _borderThicknessTimesTwo ); _backgroundPositionCorection.Y = _borderThickness; _backgroundPositionCorection.X = _borderThickness; break; case MenuDefines.BorderList.AllSides: _borderImage[ (int)MenuDefines.BorderLocation.Top ] = ShapeBuilder.makeRectangle( MenuManager.Instance.GraphicsDevice, _borderThickness, _borderThickness, _borderColor ); _borderImage[ (int)MenuDefines.BorderLocation.Bottom ] = _borderImage[ (int)MenuDefines.BorderLocation.Top ]; _borderImage[ (int)MenuDefines.BorderLocation.Left ] = _borderImage[ (int)MenuDefines.BorderLocation.Top ]; _borderImage[ (int)MenuDefines.BorderLocation.Right ] = _borderImage[ (int)MenuDefines.BorderLocation.Top ]; _backgroundSize.X = (int)( _menuSize.X - _borderThicknessTimesTwo ); _backgroundSize.Y = (int)( _menuSize.Y - _borderThicknessTimesTwo ); _backgroundPositionCorection.Y = _borderThickness; _backgroundPositionCorection.X = _borderThickness; break; default: break; } // End border switch. #endregion } // End if there is no border. #endregion #region Setting the background image, making it if needed if (template.BackgroundImagePath != null || template.BackgroundImagePath != "") { try { _backgroundImage = MenuManager.Instance.Content.Load<Texture2D>(template.BackgroundImagePath); } catch (System.Exception ex) { _backgroundImage = ShapeBuilder.makeRectangle( MenuManager.Instance.GraphicsDevice, (int) _backgroundSize.X, (int) _backgroundSize.Y, _backgroundColor ); } } else { if ( _backgroundSize.X <= tempScreenSize.X && _backgroundSize.Y <= tempScreenSize.Y) { _backgroundImage = ShapeBuilder.makeRectangle(MenuManager.Instance.GraphicsDevice, MenuDefines.defaultMenuTextureWidth, MenuDefines.defaultMenuTextureHeight, _backgroundColor); } } #endregion #region Setting up the transit effects: #region Transit in switch _transitInEffectType = template.TransitInEffect; switch ( _transitInEffectType ) { case MenuDefines.EffectsList.Fade: _transitInEffect = new Fadding(); break; case MenuDefines.EffectsList.Slide: _transitInEffect = new Slidding( template.TransitInTime, template.TransitInStartPosition, _position ); break; default: break; } #endregion #region Transit Out Switch _transitOutEffectType = template.TransitOutEffect; switch ( template.TransitOutEffect ) { case MenuDefines.EffectsList.Fade: _transitOutEffect = new Fadding(); break; case MenuDefines.EffectsList.Slide: _transitOutEffect = new Slidding( template.TransitInTime, _position, template.TransitOutEndPosition ); break; default: break; } #endregion #endregion #region Setting up the Widget widgetList = new List<WidgetBase>(); // Loading the widgets: if ( template.widgetList != null ) { listCount = template.widgetList.Count; for ( i = 0; i < listCount; i++ ) { addWidget( template.widgetList[i] ); } } #endregion #region Setting up basic draw fields // Fields required for drawing: _backgroundTint = Color.White; _backgroundOrigin = Vector2.Zero; _backgroundRotation = 0.0f; //_backgroundScale = 1.0f; _backgroundLayer = 1.0f; #endregion }
public void clearMenu() { // Start clearMenu. // Basic required information to make a template: _name = null; _menuSize = Vector2.Zero; _position = Vector2.Zero; _targetScreen = MenuDefines.ScreenMaxTarget.NOT_SET; // Extended information: _backgroundColor = MenuDefines.defaultMenuColor; _backgroundImage = null; _backgroundTransparancy = MenuDefines.defaultMenuTransparancy; _backgroundSize = Vector2.Zero; // Transit In Effects: _transitInEffectType = MenuDefines.EffectsList.None; _transitInEffect = null; // Transit Out Effects: _transitOutEffectType = MenuDefines.EffectsList.None; _transitOutEffect = null; // Widget List: widgetList = null; // Fields required for drawing: _backgroundTint = _backgroundColor; _backgroundOrigin = MenuDefines.defaultMenuOrigin; _backgroundRotation = MenuDefines.defaultMenuRotation; _backgroundDestanationRectangle = new Rectangle( 0, 0, 0, 0 ); _backgroundLayer = MenuDefines.defaultMenuLayer; #region Delegate Lists // Delegate Objects: //Update Widget Delegates: updateWidgetList = null; //Update Position Delegates: updatePositionList = null; //Draw delegates: drawWidgetList = null; #endregion //List and misc variables: i = 0; listCount = 0; listCount2 = 0; tempScreenSize = Vector2.Zero; }