Exemplo n.º 1
0
 //  This method scales picture to bounding area according to bounding area's height. We don't care about width, so sometimes if picture has wide
 //  aspect ratio, borders of image may be outisde of the bounding area. This method is used when we want to have picture covering whole screen
 //  and don't care if part of picture is invisible. Also, aspect ration is unchanged too.
 static void GetSafeHeightPictureSize(Vector2I originalSize, Rectangle boundingArea, out Rectangle outRect)
 {
     outRect.Height = boundingArea.Height;
     outRect.Width  = (int)(((float)outRect.Height / (float)originalSize.Y) * originalSize.X);
     outRect.X      = boundingArea.Left + (boundingArea.Width - outRect.Width) / 2;
     outRect.Y      = boundingArea.Top + (boundingArea.Height - outRect.Height) / 2;
 }
        internal void Draw(Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
        {
            int w = 0, h = 0;
            byte [] data = m_wrapper.GetTextureData(ref w, ref h);
            process_frame(data, w, h);

            Rectangle dst = rect;
            Rectangle src = new Rectangle(0, 0, w, h);
            var videoSize = new Vector2(w, h);
            float videoAspect = videoSize.X / videoSize.Y;
            float rectAspect = (float)rect.Width / (float)rect.Height;

            // Automatic decision based on ratios.
            if (fitMode == MyVideoRectangleFitMode.AutoFit)
                fitMode = (videoAspect > rectAspect) ? MyVideoRectangleFitMode.FitHeight : MyVideoRectangleFitMode.FitWidth;

            float scaleRatio = 0.0f;
            switch (fitMode)
            {
                case MyVideoRectangleFitMode.None:
                    break;

                case MyVideoRectangleFitMode.FitWidth:
                    scaleRatio = (float)dst.Width / videoSize.X;
                    dst.Height = (int)(scaleRatio * videoSize.Y);
                    if (dst.Height > rect.Height)
                    {
                        var diff = dst.Height - rect.Height;
                        dst.Height = rect.Height;
                        diff = (int)(diff / scaleRatio);
                        src.Y += (int)(diff * 0.5f);
                        src.Height -= diff;
                    }
                    break;

                case MyVideoRectangleFitMode.FitHeight:
                    scaleRatio = (float)dst.Height / videoSize.Y;
                    dst.Width = (int)(scaleRatio * videoSize.X);
                    if (dst.Width > rect.Width)
                    {
                        var diff = dst.Width - rect.Width;
                        dst.Width = rect.Width;
                        diff = (int)(diff / scaleRatio);
                        src.X += (int)(diff * 0.5f);
                        src.Width -= diff;
                    }
                    break;
            }
            dst.X = rect.Left + (rect.Width - dst.Width) / 2;
            dst.Y = rect.Top + (rect.Height - dst.Height) / 2;


            VRageMath.RectangleF destination = new VRageMath.RectangleF(dst.X, dst.Y, dst.Width, -dst.Height);
            VRageMath.Rectangle? source = src;
            Vector2 origin = new Vector2(src.Width / 2 * 0, src.Height);

            MySpritesRenderer.AddSingleSprite(m_texture, videoSize, color, origin, Vector2.UnitX, source, destination);
        }
Exemplo n.º 3
0
        internal void Draw(Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
        {
            Rectangle dst         = rect;
            Rectangle src         = new Rectangle(0, 0, VideoWidth, VideoHeight);
            var       videoSize   = new Vector2(VideoWidth, VideoHeight);
            float     videoAspect = videoSize.X / videoSize.Y;
            float     rectAspect  = (float)rect.Width / (float)rect.Height;

            // Automatic decision based on ratios.
            if (fitMode == MyVideoRectangleFitMode.AutoFit)
            {
                fitMode = (videoAspect > rectAspect) ? MyVideoRectangleFitMode.FitHeight : MyVideoRectangleFitMode.FitWidth;
            }

            float scaleRatio = 0.0f;

            switch (fitMode)
            {
            case MyVideoRectangleFitMode.None:
                break;

            case MyVideoRectangleFitMode.FitWidth:
                scaleRatio = (float)dst.Width / videoSize.X;
                dst.Height = (int)(scaleRatio * videoSize.Y);
                if (dst.Height > rect.Height)
                {
                    var diff = dst.Height - rect.Height;
                    dst.Height  = rect.Height;
                    diff        = (int)(diff / scaleRatio);
                    src.Y      += (int)(diff * 0.5f);
                    src.Height -= diff;
                }
                break;

            case MyVideoRectangleFitMode.FitHeight:
                scaleRatio = (float)dst.Height / videoSize.Y;
                dst.Width  = (int)(scaleRatio * videoSize.X);
                if (dst.Width > rect.Width)
                {
                    var diff = dst.Width - rect.Width;
                    dst.Width  = rect.Width;
                    diff       = (int)(diff / scaleRatio);
                    src.X     += (int)(diff * 0.5f);
                    src.Width -= diff;
                }
                break;
            }
            dst.X = rect.Left + (rect.Width - dst.Width) / 2;
            dst.Y = rect.Top + (rect.Height - dst.Height) / 2;


            VRageMath.RectangleF destination = new VRageMath.RectangleF(dst.X, dst.Y, dst.Width, -dst.Height);
            VRageMath.Rectangle? source      = src;
            Vector2 origin = new Vector2(src.Width / 2 * 0, src.Height);

            MySpritesRenderer.AddSingleSprite(m_texture.ShaderView, videoSize, color, origin, Vector2.UnitX, source, destination);
        }
Exemplo n.º 4
0
        //  Draws sprite batch at specified SCREEN position (in screen coordinates, not normalized coordinates).
        public static void DrawSpriteBatch(string texture, Rectangle destinationRectangle, Color color, bool waitTillLoaded = true)
        {
            if (string.IsNullOrEmpty(texture))
            {
                return;
            }

            var destination = new RectangleF(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Width, destinationRectangle.Height);

            DrawSprite(texture, ref destination, false, ref nullRectangle, color, 0f, ref vector2Zero, VRageRender.Graphics.SpriteEffects.None, 0f, waitTillLoaded);
        }
Exemplo n.º 5
0
        public static SpriteScissorToken UsingScissorRectangle(ref RectangleF normalizedRectangle)
        {
            Vector2 screenSize      = GetScreenSizeFromNormalizedSize(normalizedRectangle.Size);
            Vector2 screenPosition  = GetScreenCoordinateFromNormalizedCoordinate(normalizedRectangle.Position);
            var     screenRectangle = new Rectangle((int)Math.Round(screenPosition.X, MidpointRounding.AwayFromZero),
                                                    (int)Math.Round(screenPosition.Y, MidpointRounding.AwayFromZero),
                                                    (int)Math.Round(screenSize.X, MidpointRounding.AwayFromZero),
                                                    (int)Math.Round(screenSize.Y, MidpointRounding.AwayFromZero));

            VRageRender.MyRenderProxy.SpriteScissorPush(screenRectangle);
            return(new SpriteScissorToken());
        }
Exemplo n.º 6
0
        //  Return picture size that is safe for displaying in bounding area and doesn't distort the aspect ratio of original picture or bounding area.
        //  Example: picture of video frame is scaled to size of screen, so it fits it as much as possible, but still maintains aspect ration of
        //  original video frame or screen. So if screen's heigh is not enouch, video frame is scaled down to fit height, but also width is scaled
        //  according to original video frame.
        //  It's used whenever we need to scale picture/texture to some area, usually to screen size.
        //  Also this method calculated left/top coordinates, so it's always centered.
        static void GetSafeAspectRatioPictureSize(Vector2I originalSize, Rectangle boundingArea, out Rectangle outRect)
        {
            outRect.Width  = boundingArea.Width;
            outRect.Height = (int)(((float)outRect.Width / (float)originalSize.X) * originalSize.Y);

            if (outRect.Height > boundingArea.Height)
            {
                outRect.Height = boundingArea.Height;
                outRect.Width  = (int)(outRect.Height * ((float)originalSize.X / (float)originalSize.Y));
            }

            outRect.X = boundingArea.Left + (boundingArea.Width - outRect.Width) / 2;
            outRect.Y = boundingArea.Top + (boundingArea.Height - outRect.Height) / 2;
        }
Exemplo n.º 7
0
        public static void UpdateScreenSize(Vector2I screenSize, Vector2I screenSizeHalf, bool isTriple)
        {
            int safeGuiSizeY = screenSize.Y;
            int safeGuiSizeX = (int)(safeGuiSizeY * MyGuiConstants.SAFE_ASPECT_RATIO);     //  This will mantain same aspect ratio for GUI elements

            int safeFullscreenSizeX = screenSize.X;
            int safeFullscreenSizeY = screenSize.Y;

            m_fullscreenRectangle = new Rectangle(0, 0, screenSize.X, screenSize.Y);

            //  Triple head is drawn on three monitors, so we will draw GUI only on the middle one

            if (isTriple == true)
            {
                const int TRIPLE_SUB_SCREENS_COUNT = 3;
                //safeGuiSizeX = safeGuiSizeX / TRIPLE_SUB_SCREENS_COUNT;
                safeFullscreenSizeX = safeFullscreenSizeX / TRIPLE_SUB_SCREENS_COUNT;
            }


            m_safeGuiRectangle = new Rectangle(screenSize.X / 2 - safeGuiSizeX / 2, 0, safeGuiSizeX, safeGuiSizeY);

            //if (MyVideoModeManager.IsTripleHead() == true)
            //m_safeGuiRectangle.X += MySandboxGame.ScreenSize.X / 3;

            m_safeFullscreenRectangle = new Rectangle(screenSize.X / 2 - safeFullscreenSizeX / 2, 0, safeFullscreenSizeX, safeFullscreenSizeY);

            //  This will help as maintain scale/ratio of images, texts during in different resolution
            m_safeScreenScale = (float)safeGuiSizeY / MyGuiConstants.REFERENCE_SCREEN_HEIGHT;

            //  Min and max mouse coords (in normalized units). Must be calculated from fullscreen, no GUI rectangle.
            m_minMouseCoord = GetNormalizedCoordinateFromScreenCoordinate(new Vector2(m_safeFullscreenRectangle.Left, m_safeFullscreenRectangle.Top));
            m_maxMouseCoord = GetNormalizedCoordinateFromScreenCoordinate(new Vector2(m_safeFullscreenRectangle.Left + m_safeFullscreenRectangle.Width, m_safeFullscreenRectangle.Top + m_safeFullscreenRectangle.Height));
            m_minMouseCoordFullscreenHud = GetNormalizedCoordinateFromScreenCoordinate(new Vector2(m_fullscreenRectangle.Left, m_fullscreenRectangle.Top));
            m_maxMouseCoordFullscreenHud = GetNormalizedCoordinateFromScreenCoordinate(new Vector2(m_fullscreenRectangle.Left + m_fullscreenRectangle.Width, m_fullscreenRectangle.Top + m_fullscreenRectangle.Height));

#if XB1
            //XB1_TODO: error: 'VRage.Input.IMyInput' does not contain a definition for 'SetMouseLimits'
            //XB1_TODO: MyInput.Static.SetMouseLimits( new Vector2(m_safeFullscreenRectangle.Left, m_safeFullscreenRectangle.Top),
            //XB1_TODO:    new Vector2(m_safeFullscreenRectangle.Left + m_safeFullscreenRectangle.Width, m_safeFullscreenRectangle.Top + m_safeFullscreenRectangle.Height) );
#endif

            //  Normalized coordinates where width is always 1.0 and height something like 0.8
            //  Don't confuse with GUI normalized coordinates. They are different.
            //  HUD - get normalized screen size -> width is always 1.0, but height depends on aspect ratio, so usualy it is 0.8 or something.
            m_hudSize     = CalculateHudSize();
            m_hudSizeHalf = m_hudSize / 2.0f;
        }
Exemplo n.º 8
0
        //  Draws sprite batch at specified position
        //  normalizedPosition -> X and Y are within interval <0..1>
        //  size -> size of destination rectangle (normalized). Don't forget that it may be distorted by aspect ration, so rectangle size [1,1] can make larger wide than height on your screen.
        //  rotation -> angle in radians. Rotation is always around "origin" coordinate
        //  originNormalized -> the origin of the sprite. Specify (0,0) for the upper-left corner.
        //  RETURN: Method returns rectangle where was sprite/texture drawn in normalized coordinates

        public static void DrawSpriteBatch(string texture, Vector2 normalizedCoord, Vector2 normalizedSize, Color color, MyGuiDrawAlignEnum drawAlign, bool fullscreen = false, bool waitTillLoaded = true)
        {
            if (string.IsNullOrEmpty(texture))
            {
                return;
            }

            Vector2 screenCoord = GetScreenCoordinateFromNormalizedCoordinate(normalizedCoord, fullscreen);
            Vector2 screenSize  = GetScreenSizeFromNormalizedSize(normalizedSize, fullscreen);

            screenCoord = MyUtils.GetCoordAligned(screenCoord, screenSize, drawAlign);

            var rect = new Rectangle((int)screenCoord.X, (int)screenCoord.Y, (int)screenSize.X, (int)screenSize.Y);

            DrawSprite(texture, rect, color, waitTillLoaded);
        }
Exemplo n.º 9
0
        public static BoundingFrustum UnprojectRectangle(VRageMath.Rectangle source, Viewport viewport, Matrix viewMatrix, Matrix projectionMatrix)
        {
            // Point in screen space of the center of the region selected
            Vector2 regionCenterScreen = new Vector2(source.Center.X, source.Center.Y);
            // Generate the projection matrix for the screen region
            Matrix regionProjMatrix = projectionMatrix;

            // Calculate the region dimensions in the projection matrix. M11 is inverse of width, M22 is inverse of height.
            regionProjMatrix.M11 /= ((float)source.Width / (float)viewport.Width);
            regionProjMatrix.M22 /= ((float)source.Height / (float)viewport.Height);
            // Calculate the region center in the projection matrix. M31 is horizonatal center.
            regionProjMatrix.M31 = (regionCenterScreen.X - (viewport.Width / 2f)) / ((float)source.Width / 2f);

            // M32 is vertical center. Notice that the screen has low Y on top, projection has low Y on bottom.
            regionProjMatrix.M32 = -(regionCenterScreen.Y - (viewport.Height / 2f)) / ((float)source.Height / 2f);

            return(new BoundingFrustum(viewMatrix * regionProjMatrix));
        }
Exemplo n.º 10
0
        internal static void UpdateScreenSize()
        {
            MyRender.Log.WriteLine("MyRender.UpdateScreenSize() - START");

            //VRageRender.MyRender.GetRenderProfiler().StartProfilingBlock("MySandboxGame::UpdateScreenSize");

            ScreenSize     = new Vector2I((int)GraphicsDevice.Viewport.Width, (int)GraphicsDevice.Viewport.Height);
            ScreenSizeHalf = new Vector2I(ScreenSize.X / 2, ScreenSize.Y / 2);

            if (m_screenshot != null)
            {
                ScreenSize.X   = (int)(ScreenSize.X * m_screenshot.SizeMultiplier.X);
                ScreenSize.Y   = (int)(ScreenSize.Y * m_screenshot.SizeMultiplier.Y);
                ScreenSizeHalf = new Vector2I(ScreenSize.X / 2, ScreenSize.Y / 2);
            }

            MyRender.Log.WriteLine("ScreenSize: " + ScreenSize.ToString());

            int safeGuiSizeY = ScreenSize.Y;
            int safeGuiSizeX = (int)(safeGuiSizeY * 1.3333f);     //  This will mantain same aspect ratio for GUI elements

            int safeFullscreenSizeX = ScreenSize.X;
            int safeFullscreenSizeY = ScreenSize.Y;

            m_fullscreenRectangle = new VRageMath.Rectangle(0, 0, ScreenSize.X, ScreenSize.Y);

            //  Triple head is drawn on three monitors, so we will draw GUI only on the middle one
            m_safeGuiRectangle = new VRageMath.Rectangle(ScreenSize.X / 2 - safeGuiSizeX / 2, 0, safeGuiSizeX, safeGuiSizeY);

            //if (MyVideoModeManager.IsTripleHead() == true)
            //m_safeGuiRectangle.X += MySandboxGame.ScreenSize.X / 3;

            m_safeFullscreenRectangle = new VRageMath.Rectangle(ScreenSize.X / 2 - safeFullscreenSizeX / 2, 0, safeFullscreenSizeX, safeFullscreenSizeY);

            //  This will help as maintain scale/ratio of images, texts during in different resolution
            m_safeScreenScale = (float)safeGuiSizeY / MyRenderGuiConstants.REFERENCE_SCREEN_HEIGHT;

            MyRenderCamera.UpdateScreenSize();

            MyRender.Log.WriteLine("MyRender.UpdateScreenSize() - END");
        }
Exemplo n.º 11
0
 static void DrawSprite(string texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, VRageRender.Graphics.SpriteEffects effects, float layerDepth)
 {
     var destination = new RectangleF(position.X, position.Y, scale, scale);
     DrawSprite(texture, ref destination, true, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth);
 }
Exemplo n.º 12
0
        private static void ProcessDrawMessage(MyRenderMessageBase drawMessage)
        {
            switch (drawMessage.MessageType)
            {
                case MyRenderMessageEnum.SpriteScissorPush:
                    {
                        var msg = drawMessage as MyRenderMessageSpriteScissorPush;

                        MySpritesRenderer.ScissorStackPush(msg.ScreenRectangle);

                        break;
                    }

                case MyRenderMessageEnum.SpriteScissorPop:
                    {
                        MySpritesRenderer.ScissorStackPop();

                        break;
                    }

                case MyRenderMessageEnum.DrawSprite:
                    {
                        MyRenderMessageDrawSprite sprite = (MyRenderMessageDrawSprite)drawMessage;

                        MySpritesRenderer.AddSingleSprite(MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, waitTillLoaded: sprite.WaitTillLoaded), sprite.Color, sprite.Origin, sprite.RightVector, sprite.SourceRectangle, sprite.DestinationRectangle);

                        break;
                    }

                case MyRenderMessageEnum.DrawSpriteNormalized:
                    {
                        MyRenderMessageDrawSpriteNormalized sprite = (MyRenderMessageDrawSpriteNormalized)drawMessage;

                        var rotation = sprite.Rotation;
                        if (sprite.RotationSpeed != 0)
                        {
                            rotation += sprite.RotationSpeed * (float)(MyRender11.CurrentDrawTime - MyRender11.CurrentUpdateTime).Seconds;
                        }

                        Vector2 rightVector = rotation != 0f ? new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) : sprite.RightVector;

                        int safeGuiSizeY = MyRender11.ResolutionI.Y;
                        int safeGuiSizeX = (int)(safeGuiSizeY * 1.3333f);     //  This will mantain same aspect ratio for GUI elements

                        var safeGuiRectangle = new VRageMath.Rectangle(MyRender11.ResolutionI.X / 2 - safeGuiSizeX / 2, 0, safeGuiSizeX, safeGuiSizeY);
                        var safeScreenScale = (float)safeGuiSizeY / MyRenderGuiConstants.REFERENCE_SCREEN_HEIGHT;
                        float fixedScale = sprite.Scale * safeScreenScale;

                        var tex = MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, true);

                        var normalizedCoord = sprite.NormalizedCoord;
                        var screenCoord = new Vector2(safeGuiRectangle.Left + safeGuiRectangle.Width * normalizedCoord.X,
                            safeGuiRectangle.Top + safeGuiRectangle.Height * normalizedCoord.Y);

                        var sizeInPixels = MyTextures.GetSize(tex);
                        var sizeInPixelsScaled = sizeInPixels * fixedScale;

                        Vector2 alignedScreenCoord = screenCoord;
                        var drawAlign = sprite.DrawAlign;

                        if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP)
                        {
                            //  Nothing to do as position is already at this point
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER)
                        {
                            //  Move position to the texture center
                            alignedScreenCoord -= sizeInPixelsScaled / 2.0f;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP)
                        {
                            alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM)
                        {
                            alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f;
                            alignedScreenCoord.Y -= sizeInPixelsScaled.Y;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM)
                        {
                            alignedScreenCoord -= sizeInPixelsScaled;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER)
                        {
                            alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER)
                        {
                            alignedScreenCoord.X -= sizeInPixelsScaled.X;
                            alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM)
                        {
                            alignedScreenCoord.Y -= sizeInPixelsScaled.Y;// *0.75f;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP)
                        {
                            alignedScreenCoord.X -= sizeInPixelsScaled.X;
                        }

                        screenCoord = alignedScreenCoord;

                        var rect = new RectangleF(screenCoord.X, screenCoord.Y, fixedScale * sizeInPixels.X, fixedScale * sizeInPixels.Y);
                        Vector2 origin;
                        if (sprite.OriginNormalized.HasValue)
                        {
                            origin = sprite.OriginNormalized.Value * sizeInPixels;
                        }
                        else
                        {
                            origin = sizeInPixels / 2;
                        }

                        sprite.OriginNormalized = sprite.OriginNormalized ?? new Vector2(0.5f);

                        MySpritesRenderer.AddSingleSprite(MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, waitTillLoaded: sprite.WaitTillLoaded), sprite.Color, origin, rightVector, null, rect);

                        break;
                    }


                case MyRenderMessageEnum.DrawSpriteAtlas:
                    {
                        MyRenderMessageDrawSpriteAtlas sprite = (MyRenderMessageDrawSpriteAtlas)drawMessage;

                        var tex = MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, true);
                        var textureSize = MyTextures.GetSize(tex);

                        Rectangle? sourceRect = new Rectangle(
                          (int)(textureSize.X * sprite.TextureOffset.X),
                          (int)(textureSize.Y * sprite.TextureOffset.Y),
                          (int)(textureSize.X * sprite.TextureSize.X),
                          (int)(textureSize.Y * sprite.TextureSize.Y));

                        VRageMath.RectangleF destRect = new VRageMath.RectangleF(
                                     (sprite.Position.X) * sprite.Scale.X,
                                     (sprite.Position.Y) * sprite.Scale.Y,
                                     sprite.HalfSize.X * sprite.Scale.X * 2,
                                     sprite.HalfSize.Y * sprite.Scale.Y * 2);

                        Vector2 origin = new Vector2(textureSize.X * sprite.TextureSize.X * 0.5f, textureSize.Y * sprite.TextureSize.Y * 0.5f);

                        MySpritesRenderer.AddSingleSprite(MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, true), sprite.Color, origin, sprite.RightVector, sourceRect, destRect);

                        break;
                    }

                case MyRenderMessageEnum.DrawString:
                    {
                        var message = drawMessage as MyRenderMessageDrawString;

                        var font = MyRender11.GetFont(message.FontIndex);
                        font.DrawString(
                            message.ScreenCoord,
                            message.ColorMask,
                            message.Text,
                            message.ScreenScale,
                            message.ScreenMaxWidth);

                        break;
                    }

                case MyRenderMessageEnum.DrawScene:
                    {
                        AddDebugQueueMessage("Frame render start");

                        UpdateSceneFrame();

                        ProfilerShort.Begin("DrawScene");
                        DrawGameScene(Backbuffer);
                        ProfilerShort.Begin("TransferPerformanceStats");
                        TransferPerformanceStats();
                        ProfilerShort.End();
                        ProfilerShort.End();

                        ProfilerShort.Begin("Draw scene debug");
                        MyGpuProfiler.IC_BeginBlock("Draw scene debug");
                        DrawSceneDebug();
                        MyGpuProfiler.IC_EndBlock();
                        ProfilerShort.End();

                        ProfilerShort.Begin("ProcessDebugMessages");
                        ProcessDebugMessages();
                        ProfilerShort.End();

                        ProfilerShort.Begin("MyDebugRenderer.Draw");
                        MyGpuProfiler.IC_BeginBlock("MyDebugRenderer.Draw");
                        MyDebugRenderer.Draw(MyRender11.Backbuffer);
                        MyGpuProfiler.IC_EndBlock();
                        ProfilerShort.End();

                        var testingDepth = MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth : MyGBuffer.Main.DepthStencil;

                        ProfilerShort.Begin("MyPrimitivesRenderer.Draw");
                        MyGpuProfiler.IC_BeginBlock("MyPrimitivesRenderer.Draw");
                        MyPrimitivesRenderer.Draw(MyRender11.Backbuffer, testingDepth);
                        MyGpuProfiler.IC_EndBlock();
                        ProfilerShort.End();

                        ProfilerShort.Begin("MyLinesRenderer.Draw");
                        MyGpuProfiler.IC_BeginBlock("MyLinesRenderer.Draw");
                        MyLinesRenderer.Draw(MyRender11.Backbuffer, testingDepth);
                        MyGpuProfiler.IC_EndBlock();
                        ProfilerShort.End();

                        if (m_screenshot.HasValue && m_screenshot.Value.IgnoreSprites)
                        {
                            if (m_screenshot.Value.SizeMult == Vector2.One)
                            {
                                SaveScreenshotFromResource(Backbuffer.m_resource);
                            }
                            else
                            {
                                TakeCustomSizedScreenshot(m_screenshot.Value.SizeMult);
                            }
                        }

                        ProfilerShort.Begin("MySpritesRenderer.Draw");
                        MyGpuProfiler.IC_BeginBlock("MySpritesRenderer.Draw");
                        MySpritesRenderer.Draw(MyRender11.Backbuffer.m_RTV, new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y));
                        MyGpuProfiler.IC_EndBlock();
                        ProfilerShort.End();

                        if (MyRenderProxy.DRAW_RENDER_STATS)
                        {
                            MyRender11.GetRenderProfiler().StartProfilingBlock("MyRenderStatsDraw.Draw");
                            MyRenderStatsDraw.Draw(MyRenderStats.m_stats, 0.6f, VRageMath.Color.Yellow);
                            ProfilerShort.End();
                        }

                        AddDebugQueueMessage("Frame render end");
                        ProcessDebugOutput();
                        break;
                    }
            }
        }
Exemplo n.º 13
0
        static void DrawVideo(uint id, Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
        {
            MyVideoPlayerDx9 video;

            if (m_videos.TryGetValue(id, out video))
            {
                Rectangle dst         = rect;
                Rectangle src         = new Rectangle(0, 0, video.VideoWidth, video.VideoHeight);
                var       videoSize   = new Vector2(video.VideoWidth, video.VideoHeight);
                float     videoAspect = videoSize.X / videoSize.Y;
                float     rectAspect  = (float)rect.Width / (float)rect.Height;

                // Automatic decision based on ratios.
                if (fitMode == MyVideoRectangleFitMode.AutoFit)
                {
                    fitMode = (videoAspect > rectAspect) ? MyVideoRectangleFitMode.FitHeight : MyVideoRectangleFitMode.FitWidth;
                }

                float scaleRatio = 0.0f;
                switch (fitMode)
                {
                case MyVideoRectangleFitMode.None:
                    break;

                case MyVideoRectangleFitMode.FitWidth:
                    scaleRatio = (float)dst.Width / videoSize.X;
                    dst.Height = (int)(scaleRatio * videoSize.Y);
                    if (dst.Height > rect.Height)
                    {
                        var diff = dst.Height - rect.Height;
                        dst.Height  = rect.Height;
                        diff        = (int)(diff / scaleRatio);
                        src.Y      += (int)(diff * 0.5f);
                        src.Height -= diff;
                    }
                    break;

                case MyVideoRectangleFitMode.FitHeight:
                    scaleRatio = (float)dst.Height / videoSize.Y;
                    dst.Width  = (int)(scaleRatio * videoSize.X);
                    if (dst.Width > rect.Width)
                    {
                        var diff = dst.Width - rect.Width;
                        dst.Width  = rect.Width;
                        diff       = (int)(diff / scaleRatio);
                        src.X     += (int)(diff * 0.5f);
                        src.Width -= diff;
                    }
                    break;
                }
                dst.X = rect.Left + (rect.Width - dst.Width) / 2;
                dst.Y = rect.Top + (rect.Height - dst.Height) / 2;

                Texture texture = video.OutputFrame;

                // Draw upside down
                VRageMath.RectangleF destination = new VRageMath.RectangleF(dst.X, dst.Y, dst.Width, -dst.Height);
                VRageMath.Rectangle? source      = src;
                Vector2 origin = new Vector2(src.Width / 2 * 0, src.Height);
                MyRender.DrawSprite(texture, null, ref destination, false, ref source, color, Vector2.UnitX, ref origin, VRageRender.Graphics.SpriteEffects.None, 0f);
            }
        }
Exemplo n.º 14
0
 public static void SpriteScissorPush(Rectangle screenRectangle)
 {
     var message = MessagePool.Get<MyRenderMessageSpriteScissorPush>(MyRenderMessageEnum.SpriteScissorPush);
     message.ScreenRectangle = screenRectangle;
     EnqueueMessage(message);
 }
Exemplo n.º 15
0
        private static void ProcessDrawMessage(MyRenderMessageBase drawMessage)
        {
            switch (drawMessage.MessageType)
            {
            case MyRenderMessageEnum.SpriteScissorPush:
            {
                var msg = drawMessage as MyRenderMessageSpriteScissorPush;

                MySpritesRenderer.ScissorStackPush(msg.ScreenRectangle);

                break;
            }

            case MyRenderMessageEnum.SpriteScissorPop:
            {
                MySpritesRenderer.ScissorStackPop();

                break;
            }

            case MyRenderMessageEnum.DrawSprite:
            {
                MyRenderMessageDrawSprite sprite = (MyRenderMessageDrawSprite)drawMessage;

                MyFileTextureManager texManager = MyManagers.FileTextures;
                MySpritesRenderer.AddSingleSprite(texManager.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, waitTillLoaded: sprite.WaitTillLoaded), sprite.Color, sprite.Origin, sprite.RightVector, sprite.SourceRectangle, sprite.DestinationRectangle);

                break;
            }

            case MyRenderMessageEnum.DrawSpriteNormalized:
            {
                MyRenderMessageDrawSpriteNormalized sprite = (MyRenderMessageDrawSpriteNormalized)drawMessage;

                var rotation = sprite.Rotation;
                if (sprite.RotationSpeed != 0)
                {
                    rotation += sprite.RotationSpeed * (float)(MyRender11.CurrentDrawTime - MyRender11.CurrentUpdateTime).Seconds;
                }

                Vector2 rightVector = rotation != 0f ? new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) : sprite.RightVector;

                int safeGuiSizeY = MyRender11.ResolutionI.Y;
                int safeGuiSizeX = (int)(safeGuiSizeY * 1.3333f);             //  This will mantain same aspect ratio for GUI elements

                var   safeGuiRectangle = new VRageMath.Rectangle(MyRender11.ResolutionI.X / 2 - safeGuiSizeX / 2, 0, safeGuiSizeX, safeGuiSizeY);
                var   safeScreenScale  = (float)safeGuiSizeY / MyRenderGuiConstants.REFERENCE_SCREEN_HEIGHT;
                float fixedScale       = sprite.Scale * safeScreenScale;


                var tex = MyManagers.FileTextures.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, true);

                var normalizedCoord = sprite.NormalizedCoord;
                var screenCoord     = new Vector2(safeGuiRectangle.Left + safeGuiRectangle.Width * normalizedCoord.X,
                                                  safeGuiRectangle.Top + safeGuiRectangle.Height * normalizedCoord.Y);

                Vector2 sizeInPixels       = tex.Size;
                var     sizeInPixelsScaled = sizeInPixels * fixedScale;

                Vector2 alignedScreenCoord = screenCoord;
                var     drawAlign          = sprite.DrawAlign;

                if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP)
                {
                    //  Nothing to do as position is already at this point
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER)
                {
                    //  Move position to the texture center
                    alignedScreenCoord -= sizeInPixelsScaled / 2.0f;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP)
                {
                    alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM)
                {
                    alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f;
                    alignedScreenCoord.Y -= sizeInPixelsScaled.Y;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM)
                {
                    alignedScreenCoord -= sizeInPixelsScaled;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER)
                {
                    alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER)
                {
                    alignedScreenCoord.X -= sizeInPixelsScaled.X;
                    alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM)
                {
                    alignedScreenCoord.Y -= sizeInPixelsScaled.Y;        // *0.75f;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP)
                {
                    alignedScreenCoord.X -= sizeInPixelsScaled.X;
                }

                screenCoord = alignedScreenCoord;

                var     rect = new RectangleF(screenCoord.X, screenCoord.Y, fixedScale * sizeInPixels.X, fixedScale * sizeInPixels.Y);
                Vector2 origin;
                if (sprite.OriginNormalized.HasValue)
                {
                    origin = sprite.OriginNormalized.Value * sizeInPixels;
                }
                else
                {
                    origin = sizeInPixels / 2;
                }

                sprite.OriginNormalized = sprite.OriginNormalized ?? new Vector2(0.5f);

                MyFileTextureManager texManager = MyManagers.FileTextures;
                MySpritesRenderer.AddSingleSprite(texManager.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, waitTillLoaded: sprite.WaitTillLoaded), sprite.Color, origin, rightVector, null, rect);

                break;
            }


            case MyRenderMessageEnum.DrawSpriteAtlas:
            {
                MyRenderMessageDrawSpriteAtlas sprite = (MyRenderMessageDrawSpriteAtlas)drawMessage;

                MyFileTextureManager texManager = MyManagers.FileTextures;
                var tex         = texManager.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, true);
                var textureSize = tex.Size;

                Rectangle?sourceRect = new Rectangle(
                    (int)(textureSize.X * sprite.TextureOffset.X),
                    (int)(textureSize.Y * sprite.TextureOffset.Y),
                    (int)(textureSize.X * sprite.TextureSize.X),
                    (int)(textureSize.Y * sprite.TextureSize.Y));

                VRageMath.RectangleF destRect = new VRageMath.RectangleF(
                    (sprite.Position.X) * sprite.Scale.X,
                    (sprite.Position.Y) * sprite.Scale.Y,
                    sprite.HalfSize.X * sprite.Scale.X * 2,
                    sprite.HalfSize.Y * sprite.Scale.Y * 2);

                Vector2 origin = new Vector2(textureSize.X * sprite.TextureSize.X * 0.5f, textureSize.Y * sprite.TextureSize.Y * 0.5f);

                MySpritesRenderer.AddSingleSprite(texManager.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, true), sprite.Color, origin, sprite.RightVector, sourceRect, destRect);

                break;
            }

            case MyRenderMessageEnum.DrawString:
            {
                var message = drawMessage as MyRenderMessageDrawString;

                var font = MyRender11.GetFont(message.FontIndex);
                font.DrawString(
                    message.ScreenCoord,
                    message.ColorMask,
                    message.Text,
                    message.ScreenScale,
                    message.ScreenMaxWidth);

                break;
            }

            default:
                throw new Exception();
            }
        }
Exemplo n.º 16
0
 public static SpriteScissorToken UsingScissorRectangle(ref RectangleF normalizedRectangle)
 {
     Vector2 screenSize     = GetScreenSizeFromNormalizedSize(normalizedRectangle.Size);
     Vector2 screenPosition = GetScreenCoordinateFromNormalizedCoordinate(normalizedRectangle.Position);
     var screenRectangle = new Rectangle((int)Math.Round(screenPosition.X, MidpointRounding.AwayFromZero),
                                         (int)Math.Round(screenPosition.Y, MidpointRounding.AwayFromZero),
                                         (int)Math.Round(screenSize.X, MidpointRounding.AwayFromZero),
                                         (int)Math.Round(screenSize.Y, MidpointRounding.AwayFromZero));
     VRageRender.MyRenderProxy.SpriteScissorPush(screenRectangle);
     return new SpriteScissorToken();
 }
Exemplo n.º 17
0
        //  Draws sprite batch at specified SCREEN position (in screen coordinates, not normalized coordinates).
        public static void DrawSpriteBatch(string texture, Rectangle destinationRectangle, Color color, bool waitTillLoaded = true)
        {
            if (string.IsNullOrEmpty(texture))
                return;

            var destination = new RectangleF(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Width, destinationRectangle.Height);
            DrawSprite(texture, ref destination, false, ref nullRectangle, color, 0f, ref vector2Zero, SpriteEffects.None, 0f, waitTillLoaded);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Draw a sprite into rectangle specified in screen coordinates (pixels).
 /// </summary>
 /// <param name="texture">Sprite texture as path.</param>
 /// <param name="rectangle">Rectangle in screen coordinates (pixels).</param>
 /// <param name="color">Masking color.</param>
 public static void DrawSprite(string texture, Rectangle rectangle, Color color, bool waitTillLoaded = true)
 {
     var destination = new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
     DrawSprite(texture, ref destination, false, ref nullRectangle, color, 0f, ref vector2Zero, SpriteEffects.None, 0f, waitTillLoaded);
 }
Exemplo n.º 19
0
 public static void SpriteScissorPush(Rectangle screenRectangle, string targetTexture = null)
 {
     var message = MessagePool.Get<MyRenderMessageSpriteScissorPush>(MyRenderMessageEnum.SpriteScissorPush);
     message.ScreenRectangle = screenRectangle;
     message.TargetTexture = targetTexture;
     EnqueueMessage(message);
 }
Exemplo n.º 20
0
 public static void DrawVideo(uint id, Rectangle rect, Color color)
 {
     DrawVideo(id, rect, color, MyVideoRectangleFitMode.None);
 }
Exemplo n.º 21
0
        private static void ProcessDrawMessage(MyRenderMessageBase drawMessage)
        {
            switch (drawMessage.MessageType)
            {
                case MyRenderMessageEnum.SpriteScissorPush:
                    {
                        var msg = drawMessage as MyRenderMessageSpriteScissorPush;

                        MySpritesRenderer.ScissorStackPush(msg.ScreenRectangle);

                        break;
                    }

                case MyRenderMessageEnum.SpriteScissorPop:
                    {
                        MySpritesRenderer.ScissorStackPop();

                        break;
                    }

                case MyRenderMessageEnum.DrawSprite:
                    {
                        MyRenderMessageDrawSprite sprite = (MyRenderMessageDrawSprite)drawMessage;

                        MyFileTextureManager texManager = MyManagers.FileTextures;
                        MySpritesRenderer.AddSingleSprite(texManager.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, waitTillLoaded: sprite.WaitTillLoaded), sprite.Color, sprite.Origin, sprite.RightVector, sprite.SourceRectangle, sprite.DestinationRectangle);

                        break;
                    }

                case MyRenderMessageEnum.DrawSpriteNormalized:
                    {
                        MyRenderMessageDrawSpriteNormalized sprite = (MyRenderMessageDrawSpriteNormalized)drawMessage;

                        var rotation = sprite.Rotation;
                        if (sprite.RotationSpeed != 0)
                        {
                            rotation += sprite.RotationSpeed * (float)(MyRender11.CurrentDrawTime - MyRender11.CurrentUpdateTime).Seconds;
                        }

                        Vector2 rightVector = rotation != 0f ? new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) : sprite.RightVector;

                        int safeGuiSizeY = MyRender11.ResolutionI.Y;
                        int safeGuiSizeX = (int)(safeGuiSizeY * 1.3333f);     //  This will mantain same aspect ratio for GUI elements

                        var safeGuiRectangle = new VRageMath.Rectangle(MyRender11.ResolutionI.X / 2 - safeGuiSizeX / 2, 0, safeGuiSizeX, safeGuiSizeY);
                        var safeScreenScale = (float)safeGuiSizeY / MyRenderGuiConstants.REFERENCE_SCREEN_HEIGHT;
                        float fixedScale = sprite.Scale * safeScreenScale;


                        var tex = MyManagers.FileTextures.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, true);

                        var normalizedCoord = sprite.NormalizedCoord;
                        var screenCoord = new Vector2(safeGuiRectangle.Left + safeGuiRectangle.Width * normalizedCoord.X,
                            safeGuiRectangle.Top + safeGuiRectangle.Height * normalizedCoord.Y);

                        Vector2 sizeInPixels = tex.Size;
                        var sizeInPixelsScaled = sizeInPixels * fixedScale;

                        Vector2 alignedScreenCoord = screenCoord;
                        var drawAlign = sprite.DrawAlign;

                        if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP)
                        {
                            //  Nothing to do as position is already at this point
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER)
                        {
                            //  Move position to the texture center
                            alignedScreenCoord -= sizeInPixelsScaled / 2.0f;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP)
                        {
                            alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM)
                        {
                            alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f;
                            alignedScreenCoord.Y -= sizeInPixelsScaled.Y;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM)
                        {
                            alignedScreenCoord -= sizeInPixelsScaled;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER)
                        {
                            alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER)
                        {
                            alignedScreenCoord.X -= sizeInPixelsScaled.X;
                            alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM)
                        {
                            alignedScreenCoord.Y -= sizeInPixelsScaled.Y;// *0.75f;
                        }
                        else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP)
                        {
                            alignedScreenCoord.X -= sizeInPixelsScaled.X;
                        }

                        screenCoord = alignedScreenCoord;

                        var rect = new RectangleF(screenCoord.X, screenCoord.Y, fixedScale * sizeInPixels.X, fixedScale * sizeInPixels.Y);
                        Vector2 origin;
                        if (sprite.OriginNormalized.HasValue)
                        {
                            origin = sprite.OriginNormalized.Value * sizeInPixels;
                        }
                        else
                        {
                            origin = sizeInPixels / 2;
                        }

                        sprite.OriginNormalized = sprite.OriginNormalized ?? new Vector2(0.5f);

                        MyFileTextureManager texManager = MyManagers.FileTextures;
                        MySpritesRenderer.AddSingleSprite(texManager.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, waitTillLoaded: sprite.WaitTillLoaded), sprite.Color, origin, rightVector, null, rect);

                        break;
                    }


                case MyRenderMessageEnum.DrawSpriteAtlas:
                    {
                        MyRenderMessageDrawSpriteAtlas sprite = (MyRenderMessageDrawSpriteAtlas)drawMessage;

                        MyFileTextureManager texManager = MyManagers.FileTextures;
                        var tex = texManager.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, true);
                        var textureSize = tex.Size;

                        Rectangle? sourceRect = new Rectangle(
                          (int)(textureSize.X * sprite.TextureOffset.X),
                          (int)(textureSize.Y * sprite.TextureOffset.Y),
                          (int)(textureSize.X * sprite.TextureSize.X),
                          (int)(textureSize.Y * sprite.TextureSize.Y));

                        VRageMath.RectangleF destRect = new VRageMath.RectangleF(
                                     (sprite.Position.X) * sprite.Scale.X,
                                     (sprite.Position.Y) * sprite.Scale.Y,
                                     sprite.HalfSize.X * sprite.Scale.X * 2,
                                     sprite.HalfSize.Y * sprite.Scale.Y * 2);

                        Vector2 origin = new Vector2(textureSize.X * sprite.TextureSize.X * 0.5f, textureSize.Y * sprite.TextureSize.Y * 0.5f);

                        MySpritesRenderer.AddSingleSprite(texManager.GetTexture(sprite.Texture, MyFileTextureEnum.GUI, true), sprite.Color, origin, sprite.RightVector, sourceRect, destRect);

                        break;
                    }

                case MyRenderMessageEnum.DrawString:
                    {
                        var message = drawMessage as MyRenderMessageDrawString;

                        var font = MyRender11.GetFont(message.FontIndex);
                        font.DrawString(
                            message.ScreenCoord,
                            message.ColorMask,
                            message.Text,
                            message.ScreenScale,
                            message.ScreenMaxWidth);

                        break;
                    }

                default:
                    throw new Exception();
            }
        }
        static void DrawVideo(uint id, Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
		{
            Debug.Assert(false);
		}
Exemplo n.º 23
0
 static void DrawSprite(string texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, VRageRender.Graphics.SpriteEffects effects, float layerDepth)
 {
     var destination = new RectangleF(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Width, destinationRectangle.Height);
     DrawSprite(texture, ref destination, false, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth);
 }
Exemplo n.º 24
0
 internal void Draw(Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
 {
     //Debug.Assert(false, "Video DRAW Not Supported yet on XB1!");
 }
Exemplo n.º 25
0
        //  Draws sprite batch at specified SCREEN position (in screen coordinates, not normalized coordinates).
        public static void DrawSpriteBatch(string texture, Rectangle destinationRectangle, Color color)
        {
            if (string.IsNullOrEmpty(texture))
                return;

            var destination = new RectangleF(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Width, destinationRectangle.Height);
            DrawSprite(texture, ref destination, false, ref nullRectangle, color, 0f, ref vector2Zero, VRageRender.Graphics.SpriteEffects.None, 0f);
        }
Exemplo n.º 26
0
 //  Draws sprite batch at specified SCREEN position (in screen coordinates, not normalized coordinates).
 public static void DrawSpriteBatch(string texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth, bool waitTillLoaded = true)
 {
     DrawSprite(texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth, waitTillLoaded);
 }
Exemplo n.º 27
0
        private static void ProcessDrawMessage(MyRenderMessageBase drawMessage)
        {
            switch (drawMessage.MessageType)
            {
            case MyRenderMessageEnum.SpriteScissorPush:
            {
                var msg = drawMessage as MyRenderMessageSpriteScissorPush;

                MySpritesRenderer.ScissorStackPush(msg.ScreenRectangle);

                break;
            }

            case MyRenderMessageEnum.SpriteScissorPop:
            {
                MySpritesRenderer.ScissorStackPop();

                break;
            }

            case MyRenderMessageEnum.DrawSprite:
            {
                MyRenderMessageDrawSprite sprite = (MyRenderMessageDrawSprite)drawMessage;

                MySpritesRenderer.AddSingleSprite(MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, waitTillLoaded: sprite.WaitTillLoaded), sprite.Color, sprite.Origin, sprite.RightVector, sprite.SourceRectangle, sprite.DestinationRectangle);

                break;
            }

            case MyRenderMessageEnum.DrawSpriteNormalized:
            {
                MyRenderMessageDrawSpriteNormalized sprite = (MyRenderMessageDrawSpriteNormalized)drawMessage;

                var rotation = sprite.Rotation;
                if (sprite.RotationSpeed != 0)
                {
                    rotation += sprite.RotationSpeed * (float)(MyRender11.CurrentDrawTime - MyRender11.CurrentUpdateTime).Seconds;
                }

                Vector2 rightVector = rotation != 0f ? new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) : sprite.RightVector;

                int safeGuiSizeY = MyRender11.ResolutionI.Y;
                int safeGuiSizeX = (int)(safeGuiSizeY * 1.3333f);             //  This will mantain same aspect ratio for GUI elements

                var   safeGuiRectangle = new VRageMath.Rectangle(MyRender11.ResolutionI.X / 2 - safeGuiSizeX / 2, 0, safeGuiSizeX, safeGuiSizeY);
                var   safeScreenScale  = (float)safeGuiSizeY / MyRenderGuiConstants.REFERENCE_SCREEN_HEIGHT;
                float fixedScale       = sprite.Scale * safeScreenScale;

                var tex = MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, true);

                var normalizedCoord = sprite.NormalizedCoord;
                var screenCoord     = new Vector2(safeGuiRectangle.Left + safeGuiRectangle.Width * normalizedCoord.X,
                                                  safeGuiRectangle.Top + safeGuiRectangle.Height * normalizedCoord.Y);

                var sizeInPixels       = MyTextures.GetSize(tex);
                var sizeInPixelsScaled = sizeInPixels * fixedScale;

                Vector2 alignedScreenCoord = screenCoord;
                var     drawAlign          = sprite.DrawAlign;

                if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP)
                {
                    //  Nothing to do as position is already at this point
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER)
                {
                    //  Move position to the texture center
                    alignedScreenCoord -= sizeInPixelsScaled / 2.0f;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP)
                {
                    alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM)
                {
                    alignedScreenCoord.X -= sizeInPixelsScaled.X / 2.0f;
                    alignedScreenCoord.Y -= sizeInPixelsScaled.Y;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM)
                {
                    alignedScreenCoord -= sizeInPixelsScaled;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER)
                {
                    alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER)
                {
                    alignedScreenCoord.X -= sizeInPixelsScaled.X;
                    alignedScreenCoord.Y -= sizeInPixelsScaled.Y / 2.0f;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM)
                {
                    alignedScreenCoord.Y -= sizeInPixelsScaled.Y;        // *0.75f;
                }
                else if (drawAlign == MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP)
                {
                    alignedScreenCoord.X -= sizeInPixelsScaled.X;
                }

                screenCoord = alignedScreenCoord;

                var     rect = new RectangleF(screenCoord.X, screenCoord.Y, fixedScale * sizeInPixels.X, fixedScale * sizeInPixels.Y);
                Vector2 origin;
                if (sprite.OriginNormalized.HasValue)
                {
                    origin = sprite.OriginNormalized.Value * sizeInPixels;
                }
                else
                {
                    origin = sizeInPixels / 2;
                }

                sprite.OriginNormalized = sprite.OriginNormalized ?? new Vector2(0.5f);

                MySpritesRenderer.AddSingleSprite(MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, waitTillLoaded: sprite.WaitTillLoaded), sprite.Color, origin, rightVector, null, rect);

                break;
            }


            case MyRenderMessageEnum.DrawSpriteAtlas:
            {
                MyRenderMessageDrawSpriteAtlas sprite = (MyRenderMessageDrawSpriteAtlas)drawMessage;

                var tex         = MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, true);
                var textureSize = MyTextures.GetSize(tex);

                Rectangle?sourceRect = new Rectangle(
                    (int)(textureSize.X * sprite.TextureOffset.X),
                    (int)(textureSize.Y * sprite.TextureOffset.Y),
                    (int)(textureSize.X * sprite.TextureSize.X),
                    (int)(textureSize.Y * sprite.TextureSize.Y));

                VRageMath.RectangleF destRect = new VRageMath.RectangleF(
                    (sprite.Position.X) * sprite.Scale.X,
                    (sprite.Position.Y) * sprite.Scale.Y,
                    sprite.HalfSize.X * sprite.Scale.X * 2,
                    sprite.HalfSize.Y * sprite.Scale.Y * 2);

                Vector2 origin = new Vector2(textureSize.X * sprite.TextureSize.X * 0.5f, textureSize.Y * sprite.TextureSize.Y * 0.5f);

                MySpritesRenderer.AddSingleSprite(MyTextures.GetTexture(sprite.Texture, MyTextureEnum.GUI, true), sprite.Color, origin, sprite.RightVector, sourceRect, destRect);

                break;
            }

            case MyRenderMessageEnum.DrawString:
            {
                var message = drawMessage as MyRenderMessageDrawString;

                var font = MyRender11.GetFont(message.FontIndex);
                font.DrawString(
                    message.ScreenCoord,
                    message.ColorMask,
                    message.Text,
                    message.ScreenScale,
                    message.ScreenMaxWidth);

                break;
            }

            case MyRenderMessageEnum.DrawScene:
            {
                UpdateSceneFrame();

                ProfilerShort.Begin("DrawScene");
                DrawGameScene(Backbuffer);
                ProfilerShort.Begin("TransferPerformanceStats");
                TransferPerformanceStats();
                ProfilerShort.End();
                ProfilerShort.End();

                ProfilerShort.Begin("Draw scene debug");
                MyGpuProfiler.IC_BeginBlock("Draw scene debug");
                DrawSceneDebug();
                MyGpuProfiler.IC_EndBlock();
                ProfilerShort.End();

                ProfilerShort.Begin("ProcessDebugMessages");
                ProcessDebugMessages();
                ProfilerShort.End();

                ProfilerShort.Begin("MyDebugRenderer.Draw");
                MyGpuProfiler.IC_BeginBlock("MyDebugRenderer.Draw");
                MyDebugRenderer.Draw(MyRender11.Backbuffer);
                MyGpuProfiler.IC_EndBlock();
                ProfilerShort.End();

                var testingDepth = MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth : MyGBuffer.Main.DepthStencil;

                ProfilerShort.Begin("MyPrimitivesRenderer.Draw");
                MyGpuProfiler.IC_BeginBlock("MyPrimitivesRenderer.Draw");
                MyPrimitivesRenderer.Draw(MyRender11.Backbuffer, testingDepth);
                MyGpuProfiler.IC_EndBlock();
                ProfilerShort.End();

                ProfilerShort.Begin("MyLinesRenderer.Draw");
                MyGpuProfiler.IC_BeginBlock("MyLinesRenderer.Draw");
                MyLinesRenderer.Draw(MyRender11.Backbuffer, testingDepth);
                MyGpuProfiler.IC_EndBlock();
                ProfilerShort.End();

                if (m_screenshot.HasValue && m_screenshot.Value.IgnoreSprites)
                {
                    if (m_screenshot.Value.SizeMult == Vector2.One)
                    {
                        SaveScreenshotFromResource(Backbuffer.m_resource);
                    }
                    else
                    {
                        TakeCustomSizedScreenshot(m_screenshot.Value.SizeMult);
                    }
                }

                ProfilerShort.Begin("MySpritesRenderer.Draw");
                MyGpuProfiler.IC_BeginBlock("MySpritesRenderer.Draw");
                MySpritesRenderer.Draw(MyRender11.Backbuffer.m_RTV, new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y));
                MyGpuProfiler.IC_EndBlock();
                ProfilerShort.End();

                if (MyRenderProxy.DRAW_RENDER_STATS)
                {
                    MyRender11.GetRenderProfiler().StartProfilingBlock("MyRenderStatsDraw.Draw");
                    MyRenderStatsDraw.Draw(MyRenderStats.m_stats, 0.6f, VRageMath.Color.Yellow);
                    ProfilerShort.End();
                }

                break;
            }
            }
        }
Exemplo n.º 28
0
 static void DrawSprite(string texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth, bool waitTillLoaded = true)
 {
     var destination = new RectangleF(position.X, position.Y, scale, scale);
     DrawSprite(texture, ref destination, true, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth, waitTillLoaded);
 }
Exemplo n.º 29
0
        public static void DrawVideo(uint id, Rectangle rect, Color color, MyVideoRectangleFitMode fitMode = MyVideoRectangleFitMode.None)
        {
            var message = MessagePool.Get<MyRenderMessageDrawVideo>(MyRenderMessageEnum.DrawVideo);

            message.ID = id;
            message.Rectangle = rect;
            message.Color = color;
            message.FitMode = fitMode;

            EnqueueMessage(message);
        }
Exemplo n.º 30
0
 static void DrawSprite(string texture, ref RectangleF destination, bool scaleDestination, ref Rectangle? sourceRectangle, Color color, float rotation, ref Vector2 origin, SpriteEffects effects, float depth, bool waitTillLoaded = true)
 {
     VRageRender.MyRenderProxy.DrawSprite(texture, ref destination, scaleDestination, ref sourceRectangle, color, rotation, Vector2.UnitX, ref origin, effects, depth, waitTillLoaded);
 }
Exemplo n.º 31
0
        public static void DrawSprite(string texture, ref RectangleF destination, bool scaleDestination, ref Rectangle? sourceRectangle, Color color, float rotation, Vector2 rightVector, ref Vector2 origin, SpriteEffects effects, float depth, bool waitTillLoaded = true)
        {
            Debug.Assert(!string.IsNullOrEmpty(texture) && (texture.EndsWith(".jpg") || texture.EndsWith(".dds") || texture.EndsWith(".png")), "Unsupported sprite texture! ");

            var message = MessagePool.Get<MyRenderMessageDrawSprite>(MyRenderMessageEnum.DrawSprite);

            message.Texture = texture;
            message.DestinationRectangle = destination;
            message.SourceRectangle = sourceRectangle;
            message.Color = color;
            message.Rotation = rotation;
            message.RightVector = rightVector;
            message.Depth = depth;
            message.Effects = effects;
            message.Origin = origin;
            message.ScaleDestination = scaleDestination;
            message.WaitTillLoaded = waitTillLoaded;

            EnqueueMessage(message);
        }
Exemplo n.º 32
0
        /// <summary>Draws sprite batch at specified position</summary>
        /// <param name="normalizedCoord">X and Y are within interval [0,1]</param>
        /// <param name="normalizedSize">size of destination rectangle (normalized).
        /// Don't forget that it may be distorted by aspect ration, so rectangle size
        /// [1,1] can make larger wide than height on your screen.</param>
        /// <param name="useFullClientArea">True uses full client rectangle. False limits to GUI rectangle</param>
        public static void DrawSpriteBatch(string texture, Vector2 normalizedCoord, Vector2 normalizedSize, Color color, MyGuiDrawAlignEnum drawAlign, bool useFullClientArea = false, bool waitTillLoaded = true)
        {
            if (string.IsNullOrEmpty(texture))
                return;

            Vector2 screenCoord = GetScreenCoordinateFromNormalizedCoordinate(normalizedCoord, useFullClientArea);
            Vector2 screenSize = GetScreenSizeFromNormalizedSize(normalizedSize, useFullClientArea);
            screenCoord = MyUtils.GetCoordAligned(screenCoord, screenSize, drawAlign);

            var rect = new Rectangle((int)screenCoord.X, (int)screenCoord.Y, (int)screenSize.X, (int)screenSize.Y);

            DrawSprite(texture, rect, color, waitTillLoaded);
        }
Exemplo n.º 33
0
        static void DrawVideo(uint id, Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
        {
            MyVideoPlayerDx9 video;
            if (m_videos.TryGetValue(id, out video))
            {
                Rectangle dst = rect;
                Rectangle src = new Rectangle(0, 0, video.VideoWidth, video.VideoHeight);
                var videoSize = new Vector2(video.VideoWidth, video.VideoHeight);
                float videoAspect = videoSize.X / videoSize.Y;
                float rectAspect = (float)rect.Width / (float)rect.Height;

                // Automatic decision based on ratios.
                if (fitMode == MyVideoRectangleFitMode.AutoFit)
                    fitMode = (videoAspect > rectAspect) ? MyVideoRectangleFitMode.FitHeight : MyVideoRectangleFitMode.FitWidth;

                float scaleRatio = 0.0f;
                switch (fitMode)
                {
                    case MyVideoRectangleFitMode.None:
                        break;

                    case MyVideoRectangleFitMode.FitWidth:
                        scaleRatio = (float)dst.Width / videoSize.X;
                        dst.Height = (int)(scaleRatio * videoSize.Y);
                        if (dst.Height > rect.Height)
                        {
                            var diff = dst.Height - rect.Height;
                            dst.Height = rect.Height;
                            diff = (int)(diff / scaleRatio);
                            src.Y += (int)(diff * 0.5f);
                            src.Height -= diff;
                        }
                        break;

                    case MyVideoRectangleFitMode.FitHeight:
                        scaleRatio = (float)dst.Height / videoSize.Y;
                        dst.Width = (int)(scaleRatio * videoSize.X);
                        if (dst.Width > rect.Width)
                        {
                            var diff = dst.Width - rect.Width;
                            dst.Width = rect.Width;
                            diff = (int)(diff / scaleRatio);
                            src.X += (int)(diff * 0.5f);
                            src.Width -= diff;
                        }
                        break;
                }
                dst.X = rect.Left + (rect.Width - dst.Width) / 2;
                dst.Y = rect.Top + (rect.Height - dst.Height) / 2;

                Texture texture = video.OutputFrame;

                // Draw upside down
                VRageMath.RectangleF destination = new VRageMath.RectangleF(dst.X, dst.Y, dst.Width, -dst.Height);
                VRageMath.Rectangle? source = src;
                Vector2 origin = new Vector2(src.Width / 2 * 0, src.Height);
                MyRender.DrawSprite(texture, null, ref destination, false, ref source, color, Vector2.UnitX, ref origin, VRageRender.Graphics.SpriteEffects.None, 0f);
            }
        }
Exemplo n.º 34
0
 static void DrawSprite(string texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth, bool waitTillLoaded = true)
 {
     var destination = new RectangleF(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Width, destinationRectangle.Height);
     DrawSprite(texture, ref destination, false, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth, waitTillLoaded);
 }
Exemplo n.º 35
0
 static void DrawVideo(uint id, Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
 {
     Debug.Assert(false);
 }
Exemplo n.º 36
0
        static void DrawSprite(string texture, Rectangle destinationRectangle, Rectangle?sourceRectangle, Color color, float rotation, Vector2 origin, VRageRender.Graphics.SpriteEffects effects, float layerDepth, bool waitTillLoaded = true)
        {
            var destination = new RectangleF(destinationRectangle.X, destinationRectangle.Y, destinationRectangle.Width, destinationRectangle.Height);

            DrawSprite(texture, ref destination, false, ref sourceRectangle, color, rotation, ref origin, effects, layerDepth, waitTillLoaded);
        }
Exemplo n.º 37
0
        /// <summary>
        /// Draw a sprite into rectangle specified in screen coordinates (pixels).
        /// </summary>
        /// <param name="texture">Sprite texture as path.</param>
        /// <param name="rectangle">Rectangle in screen coordinates (pixels).</param>
        /// <param name="color">Masking color.</param>
        public static void DrawSprite(string texture, Rectangle rectangle, Color color, bool waitTillLoaded = true)
        {
            var destination = new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);

            DrawSprite(texture, ref destination, false, ref nullRectangle, color, 0f, ref vector2Zero, VRageRender.Graphics.SpriteEffects.None, 0f, waitTillLoaded);
        }
Exemplo n.º 38
0
 //  Draws sprite batch at specified SCREEN position (in screen coordinates, not normalized coordinates).
 public static void DrawSpriteBatch(string texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, float scale, VRageRender.Graphics.SpriteEffects effects, float layerDepth)
 {
     DrawSprite(texture, position, sourceRectangle, color, rotation, origin, scale, effects, layerDepth);
 }
Exemplo n.º 39
0
        public static void DrawSprite(string texture, ref RectangleF destination, bool scaleDestination, ref Rectangle? sourceRectangle, Color color, float rotation, Vector2 rightVector, ref Vector2 origin, SpriteEffects effects, float depth, bool waitTillLoaded = true, string targetTexture = null)
        {
            var message = MessagePool.Get<MyRenderMessageDrawSprite>(MyRenderMessageEnum.DrawSprite);

            message.Texture = texture;
            message.DestinationRectangle = destination;
            message.SourceRectangle = sourceRectangle;
            message.Color = color;
            message.Rotation = rotation;
            message.RightVector = rightVector;
            message.Depth = depth;
            message.Effects = effects;
            message.Origin = origin;
            message.ScaleDestination = scaleDestination;
            message.WaitTillLoaded = waitTillLoaded;
            message.TargetTexture = targetTexture;

            EnqueueMessage(message);
        }
Exemplo n.º 40
0
        //  Return picture size that is safe for displaying in bounding area and doesn't distort the aspect ratio of original picture or bounding area.
        //  Example: picture of video frame is scaled to size of screen, so it fits it as much as possible, but still maintains aspect ration of
        //  original video frame or screen. So if screen's heigh is not enouch, video frame is scaled down to fit height, but also width is scaled
        //  according to original video frame.
        //  It's used whenever we need to scale picture/texture to some area, usually to screen size.
        //  Also this method calculated left/top coordinates, so it's always centered.
        static void GetSafeAspectRatioPictureSize(Vector2I originalSize, Rectangle boundingArea, out Rectangle outRect)
        {
            outRect.Width = boundingArea.Width;
            outRect.Height = (int)(((float)outRect.Width / (float)originalSize.X) * originalSize.Y);

            if (outRect.Height > boundingArea.Height)
            {
                outRect.Height = boundingArea.Height;
                outRect.Width = (int)(outRect.Height * ((float)originalSize.X / (float)originalSize.Y));
            }

            outRect.X = boundingArea.Left + (boundingArea.Width - outRect.Width) / 2;
            outRect.Y = boundingArea.Top + (boundingArea.Height - outRect.Height) / 2;
        }
Exemplo n.º 41
0
 public static void GetSafeAspectRatioFullScreenPictureSize(Vector2I originalSize, out Rectangle outRect)
 {
     GetSafeAspectRatioPictureSize(originalSize, m_safeFullscreenRectangle, out outRect);
 }
Exemplo n.º 42
0
        public static void UpdateScreenSize(Vector2I screenSize, Vector2I screenSizeHalf, bool isTriple)
        {
            int safeGuiSizeY = screenSize.Y;
            int safeGuiSizeX = (int)(safeGuiSizeY * MyGuiConstants.SAFE_ASPECT_RATIO);     //  This will mantain same aspect ratio for GUI elements

            int safeFullscreenSizeX = screenSize.X;
            int safeFullscreenSizeY = screenSize.Y;

            m_fullscreenRectangle = new Rectangle(0, 0, screenSize.X, screenSize.Y);

            //  Triple head is drawn on three monitors, so we will draw GUI only on the middle one

            if (isTriple == true)
            {
                const int TRIPLE_SUB_SCREENS_COUNT = 3;
                //safeGuiSizeX = safeGuiSizeX / TRIPLE_SUB_SCREENS_COUNT;
                safeFullscreenSizeX = safeFullscreenSizeX / TRIPLE_SUB_SCREENS_COUNT;
            }


            m_safeGuiRectangle = new Rectangle(screenSize.X / 2 - safeGuiSizeX / 2, 0, safeGuiSizeX, safeGuiSizeY);

            //if (MyVideoModeManager.IsTripleHead() == true)
            //m_safeGuiRectangle.X += MySandboxGame.ScreenSize.X / 3;

            m_safeFullscreenRectangle = new Rectangle(screenSize.X / 2 - safeFullscreenSizeX / 2, 0, safeFullscreenSizeX, safeFullscreenSizeY);

            //  This will help as maintain scale/ratio of images, texts during in different resolution
            m_safeScreenScale = (float)safeGuiSizeY / MyGuiConstants.REFERENCE_SCREEN_HEIGHT;

            //  Min and max mouse coords (in normalized units). Must be calculated from fullscreen, no GUI rectangle.
            m_minMouseCoord = GetNormalizedCoordinateFromScreenCoordinate(new Vector2(m_safeFullscreenRectangle.Left, m_safeFullscreenRectangle.Top));
            m_maxMouseCoord = GetNormalizedCoordinateFromScreenCoordinate(new Vector2(m_safeFullscreenRectangle.Left + m_safeFullscreenRectangle.Width, m_safeFullscreenRectangle.Top + m_safeFullscreenRectangle.Height));
            m_minMouseCoordFullscreenHud = GetNormalizedCoordinateFromScreenCoordinate(new Vector2(m_fullscreenRectangle.Left, m_fullscreenRectangle.Top));
            m_maxMouseCoordFullscreenHud = GetNormalizedCoordinateFromScreenCoordinate(new Vector2(m_fullscreenRectangle.Left + m_fullscreenRectangle.Width, m_fullscreenRectangle.Top + m_fullscreenRectangle.Height));

#if XB1
            //XB1_TODO: error: 'VRage.Input.IMyInput' does not contain a definition for 'SetMouseLimits'
            //XB1_TODO: MyInput.Static.SetMouseLimits( new Vector2(m_safeFullscreenRectangle.Left, m_safeFullscreenRectangle.Top),
            //XB1_TODO:    new Vector2(m_safeFullscreenRectangle.Left + m_safeFullscreenRectangle.Width, m_safeFullscreenRectangle.Top + m_safeFullscreenRectangle.Height) );
#endif

            //  Normalized coordinates where width is always 1.0 and height something like 0.8
            //  Don't confuse with GUI normalized coordinates. They are different.
            //  HUD - get normalized screen size -> width is always 1.0, but height depends on aspect ratio, so usualy it is 0.8 or something.
            m_hudSize = CalculateHudSize();
            m_hudSizeHalf = m_hudSize / 2.0f;
        }
Exemplo n.º 43
0
 public static void GetSafeAspectRatioFullScreenPictureSize(Vector2I originalSize, out Rectangle outRect)
 {
     GetSafeAspectRatioPictureSize(originalSize, m_safeFullscreenRectangle, out outRect);
 }
Exemplo n.º 44
0
 /// <summary>
 /// Draw a sprite into rectangle specified in screen coordinates (pixels).
 /// </summary>
 /// <param name="texture">Sprite texture as path.</param>
 /// <param name="rectangle">Rectangle in screen coordinates (pixels).</param>
 /// <param name="color">Masking color.</param>
 public static void DrawSprite(string texture, Rectangle rectangle, Color color)
 {
     var destination = new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
     DrawSprite(texture, ref destination, false, ref nullRectangle, color, 0f, ref vector2Zero, VRageRender.Graphics.SpriteEffects.None, 0f);
 }
Exemplo n.º 45
0
 //  This method scales picture to bounding area according to bounding area's height. We don't care about width, so sometimes if picture has wide
 //  aspect ratio, borders of image may be outisde of the bounding area. This method is used when we want to have picture covering whole screen
 //  and don't care if part of picture is invisible. Also, aspect ration is unchanged too.
 static void GetSafeHeightPictureSize(Vector2I originalSize, Rectangle boundingArea, out Rectangle outRect)
 {
     outRect.Height = boundingArea.Height;
     outRect.Width = (int)(((float)outRect.Height / (float)originalSize.Y) * originalSize.X);
     outRect.X = boundingArea.Left + (boundingArea.Width - outRect.Width) / 2;
     outRect.Y = boundingArea.Top + (boundingArea.Height - outRect.Height) / 2;
 }
Exemplo n.º 46
0
        internal void Draw(Rectangle rect, Color color, MyVideoRectangleFitMode fitMode)
		{
            //Debug.Assert(false, "Video DRAW Not Supported yet on XB1!");
		}