Esempio n. 1
0
        /// <summary>
        /// Crée un menu front
        /// </summary>
        /// <param name="width">Largeur</param>
        /// <param name="height">Hauteur</param>
        /// <returns>Image du menu</returns>
        private static Texture2D CreateMenuFront(int width, int height)
        {
            Texture2D res = ImageManager.GetPermanentImage(VO_GUI.RefResource);

            int blockSize  = VO_GUI.FrontL.Width;
            int miniWidth  = width - blockSize - blockSize;
            int miniHeight = height - blockSize - blockSize;

            #region Remplissage milieu
            RenderTarget2D center = null;
            if (miniHeight > 0 && miniWidth > 0)
            {
                center = new RenderTarget2D(_GraphicsDevice, miniWidth, miniHeight);
                _GraphicsDevice.SetRenderTarget(center);
                _GraphicsDevice.Clear(Color.Black);
                for (int i = 0; i <= miniWidth; i += blockSize)
                {
                    for (int j = 0; j <= miniHeight; j += blockSize)
                    {
                        Copy(res, new Rectangle(i, j, VO_GUI.FrontC.Width, VO_GUI.FrontC.Height), VO_GUI.FrontC.Source);
                    }
                }
            }
            #endregion

            #region Côté gauche
            RenderTarget2D left = null;
            if (miniHeight > 0)
            {
                left = new RenderTarget2D(_GraphicsDevice, blockSize, miniHeight);
                _GraphicsDevice.SetRenderTarget(left);
                _GraphicsDevice.Clear(Color.Black);
                for (int i = 0; i <= miniHeight; i += blockSize)
                {
                    Copy(res, new Rectangle(0, i, VO_GUI.FrontL.Width, VO_GUI.FrontL.Height), VO_GUI.FrontL.Source);
                }
            }
            #endregion

            #region Côté droit
            RenderTarget2D right = null;
            if (miniHeight > 0)
            {
                right = new RenderTarget2D(_GraphicsDevice, blockSize, miniHeight);
                _GraphicsDevice.SetRenderTarget(right);
                _GraphicsDevice.Clear(Color.Black);
                for (int i = 0; i <= miniHeight; i += blockSize)
                {
                    Copy(res, new Rectangle(0, i, VO_GUI.FrontR.Width, VO_GUI.FrontR.Height), VO_GUI.FrontR.Source);
                }
            }
            #endregion

            #region Côté haut
            RenderTarget2D top = null;
            if (miniWidth > 0)
            {
                top = new RenderTarget2D(_GraphicsDevice, miniWidth, blockSize);
                _GraphicsDevice.SetRenderTarget(top);
                _GraphicsDevice.Clear(Color.Black);
                for (int i = 0; i <= miniWidth; i += blockSize)
                {
                    Copy(res, new Rectangle(i, 0, VO_GUI.FrontT.Width, VO_GUI.FrontT.Height), VO_GUI.FrontT.Source);
                }
            }
            #endregion

            #region Côté bas
            RenderTarget2D bottom = null;
            if (miniWidth > 0)
            {
                bottom = new RenderTarget2D(_GraphicsDevice, miniWidth, blockSize);
                _GraphicsDevice.SetRenderTarget(bottom);
                _GraphicsDevice.Clear(Color.Black);
                for (int i = 0; i <= miniWidth; i += blockSize)
                {
                    Copy(res, new Rectangle(i, 0, VO_GUI.FrontB.Width, VO_GUI.FrontB.Height), VO_GUI.FrontB.Source);
                }
            }
            #endregion

            #region Côté leftTop
            RenderTarget2D leftTop = null;
            if (miniHeight > 0 && miniWidth > 0)
            {
                leftTop = new RenderTarget2D(_GraphicsDevice, blockSize, blockSize);
                _GraphicsDevice.SetRenderTarget(leftTop);
                _GraphicsDevice.Clear(Color.Black);
                Copy(res, new Rectangle(0, 0, VO_GUI.FrontLT.Width, VO_GUI.FrontLT.Height), VO_GUI.FrontLT.Source);
            }
            #endregion

            #region Côté leftBottom
            RenderTarget2D leftBottom = null;
            if (miniHeight > 0 && miniWidth > 0)
            {
                leftBottom = new RenderTarget2D(_GraphicsDevice, blockSize, blockSize);
                _GraphicsDevice.SetRenderTarget(leftBottom);
                _GraphicsDevice.Clear(Color.Black);
                Copy(res, new Rectangle(0, 0, VO_GUI.FrontLB.Width, VO_GUI.FrontLB.Height), VO_GUI.FrontLB.Source);
            }
            #endregion

            #region Côté rightTop
            RenderTarget2D rightTop = null;
            if (miniHeight > 0 && miniWidth > 0)
            {
                rightTop = new RenderTarget2D(_GraphicsDevice, blockSize, blockSize);
                _GraphicsDevice.SetRenderTarget(rightTop);
                _GraphicsDevice.Clear(Color.Black);
                Copy(res, new Rectangle(0, 0, VO_GUI.FrontRT.Width, VO_GUI.FrontRT.Height), VO_GUI.FrontRT.Source);
            }
            #endregion

            #region Côté rightBottom
            RenderTarget2D rightBottom = null;
            if (miniHeight > 0 && miniWidth > 0)
            {
                rightBottom = new RenderTarget2D(_GraphicsDevice, blockSize, blockSize);
                _GraphicsDevice.SetRenderTarget(rightBottom);
                _GraphicsDevice.Clear(Color.Black);
                Copy(res, new Rectangle(0, 0, VO_GUI.FrontRB.Width, VO_GUI.FrontRB.Height), VO_GUI.FrontRB.Source);
            }
            #endregion

            #region Réunion
            RenderTarget2D menu = new RenderTarget2D(_GraphicsDevice, width, height);
            _GraphicsDevice.SetRenderTarget(menu);
            _GraphicsDevice.Clear(Color.Black);
            if (center != null)
            {
                Copy(center, new Rectangle(blockSize, blockSize, center.Width, center.Height), center.Bounds);
            }
            if (left != null)
            {
                Copy(left, new Rectangle(0, blockSize, left.Width, left.Height), left.Bounds);
            }
            if (right != null)
            {
                Copy(right, new Rectangle(miniWidth + blockSize, blockSize, right.Width, right.Height), right.Bounds);
            }
            if (top != null)
            {
                Copy(top, new Rectangle(blockSize, 0, top.Width, top.Height), top.Bounds);
            }
            if (bottom != null)
            {
                Copy(bottom, new Rectangle(blockSize, miniHeight + blockSize, bottom.Width, bottom.Height), bottom.Bounds);
            }
            if (leftTop != null)
            {
                Copy(leftTop, new Rectangle(0, 0, leftTop.Width, leftTop.Height), leftTop.Bounds);
            }
            if (leftBottom != null)
            {
                Copy(leftBottom, new Rectangle(0, miniHeight + blockSize, leftBottom.Width, leftBottom.Height), leftBottom.Bounds);
            }
            if (rightTop != null)
            {
                Copy(rightTop, new Rectangle(miniWidth + blockSize, 0, rightTop.Width, rightTop.Height), rightTop.Bounds);
            }
            if (rightBottom != null)
            {
                Copy(rightBottom, new Rectangle(miniWidth + blockSize, miniHeight + blockSize, rightBottom.Width, rightBottom.Height), rightBottom.Bounds);
            }
            #endregion

            if (top != null)
            {
                top.Dispose();
            }
            if (left != null)
            {
                left.Dispose();
            }
            if (right != null)
            {
                right.Dispose();
            }
            if (bottom != null)
            {
                bottom.Dispose();
            }
            if (center != null)
            {
                center.Dispose();
            }
            if (leftTop != null)
            {
                leftTop.Dispose();
            }
            if (leftBottom != null)
            {
                leftBottom.Dispose();
            }
            if (rightBottom != null)
            {
                rightBottom.Dispose();
            }
            if (rightTop != null)
            {
                rightTop.Dispose();
            }

            //Release the GPU back to drawing to the screen
            _GraphicsDevice.SetRenderTarget(null);

            return(menu as Texture2D);
        }