} // RestoreModeValues

        #endregion

        #region Clone Main Camera

        /// <summary>
        /// Clone Main Camera
        /// </summary>
        private void CloneMainCamera()
        {
            // Find out game camera.
            Layer.ActiveLayers = EditorManager.GameActiveMask;
            Camera mainCamera = Camera.MainCamera;

            Layer.ActiveLayers = Layer.GetLayerByNumber(31).Mask; // Update just the editor

            viewportCamera.Camera.ClearColor         = mainCamera.ClearColor;
            viewportCamera.Camera.AmbientLight       = mainCamera.AmbientLight;
            viewportCamera.Camera.Sky                = mainCamera.Sky;
            viewportCamera.Camera.PostProcess        = mainCamera.PostProcess;
            viewportCamera.Transform.WorldMatrix     = ((GameObject3D)mainCamera.Owner).Transform.WorldMatrix; // ViewMatrix
            viewportCamera.Camera.NearPlane          = mainCamera.NearPlane;
            viewportCamera.Camera.FarPlane           = mainCamera.FarPlane;
            viewportCamera.Camera.FieldOfView        = mainCamera.FieldOfView;
            viewportCamera.Camera.AspectRatio        = mainCamera.AspectRatio;
            viewportCamera.Camera.ProjectionMatrix   = mainCamera.ProjectionMatrix;
            viewportCamera.Camera.NormalizedViewport = mainCamera.NormalizedViewport;
            viewportCamera.Camera.CullingMask        = mainCamera.CullingMask;
            Size  size;
            float renderTargetAspectRatio = Camera.AspectRatio,
                  renderSpaceAspectRatio  = ClientArea.Width / (float)ClientArea.Height;

            if (renderTargetAspectRatio > renderSpaceAspectRatio)
            {
                size = new Size(ClientArea.Width, (int)(ClientArea.Width / renderTargetAspectRatio));
            }
            else
            {
                size = new Size((int)(renderTargetAspectRatio * ClientArea.Height), ClientArea.Height);
            }
            viewportCamera.Camera.RenderTargetSize = size;
        } // CloneMainCamera
        } // CloneMainCamera

        #endregion

        #region On Screen Size Changed

        /// <summary>
        /// Reset the viewport dimensions and adjust the viewport camera's render target size.
        /// </summary>
        private void OnScreenSizeChanged(object caller, System.EventArgs eventArgs)
        {
            viewportControl.Left   = (int)(MainWindow.ViewportArea.Width * normalizedViewport.X + MainWindow.ViewportArea.X);
            viewportControl.Top    = (int)(MainWindow.ViewportArea.Height * normalizedViewport.Y + MainWindow.ViewportArea.Y);
            viewportControl.Width  = (int)(MainWindow.ViewportArea.Width * normalizedViewport.Width);
            viewportControl.Height = (int)(MainWindow.ViewportArea.Height * normalizedViewport.Height);
            if (viewportCamera != null)
            {
                editorCameraScript.ClientArea = viewportControl.ClientArea;
                if (mode != ViewportMode.Game)
                {
                    viewportCamera.Camera.RenderTargetSize = new Size(ClientWidth, ClientHeight);
                    viewportCamera.Camera.AspectRatio      = ClientWidth / (float)ClientHeight;
                }
                else
                {
                    Size  size;
                    float renderTargetAspectRatio = Camera.AspectRatio,
                          renderSpaceAspectRatio  = ClientArea.Width / (float)ClientArea.Height;
                    if (renderTargetAspectRatio > renderSpaceAspectRatio)
                    {
                        size = new Size(ClientArea.Width, (int)(ClientArea.Width / renderTargetAspectRatio));
                    }
                    else
                    {
                        size = new Size((int)(renderTargetAspectRatio * ClientArea.Height), ClientArea.Height);
                    }
                    viewportCamera.Camera.RenderTargetSize = size;
                }
                if (viewportCamera.Camera.RenderTarget == null)
                {
                    AssetContentManager userContentManager = AssetContentManager.CurrentContentManager;
                    AssetContentManager.CurrentContentManager = EditorManager.EditorContentManager;
                    viewportCamera.Camera.RenderTarget        = new RenderTarget(viewportCamera.Camera.RenderTargetSize, SurfaceFormat.Color, false);
                    AssetContentManager.CurrentContentManager = userContentManager;
                }
            }
        } // OnScreenSizeChanged