コード例 #1
0
        public override void Draw()
        {
            base.Draw();

            Vector3 transformedPoint = Vector3.Transform(Container.Entity.PositionComp.GetPosition(), MySector.MainCamera.ViewMatrix);
            Vector4 projectedPoint   = Vector4.Transform(transformedPoint, MySector.MainCamera.ProjectionMatrix);

            if (transformedPoint.Z > 0)
            {
                projectedPoint.X *= -1;
                projectedPoint.Y *= -1;
            }
            if (projectedPoint.W <= 0)
            {
                return;
            }

            Vector2 projectedPoint2D = new Vector2(projectedPoint.X / projectedPoint.W / 2.0f + 0.5f, -projectedPoint.Y / projectedPoint.W / 2.0f + 0.5f);

            projectedPoint2D = MyGuiManager.GetHudPixelCoordFromNormalizedCoord(projectedPoint2D);

            for (int i = 0; i < m_invetoryItem.IconTextures.Length; i++)
            {
                MyGuiManager.DrawSprite(m_invetoryItem.IconTextures[i], projectedPoint2D, new Rectangle(0, 0, 128, 128), Color.White,
                                        0, new Vector2(64, 64), new Vector2(0.5f), SpriteEffects.None, 0);
            }
        }
コード例 #2
0
        public void Draw(float progression, Color colorMask)
        {
            if (m_positionsAndSizesDirty)
            {
                RefreshPositionsAndSizes();
            }

            var targetRect = new Rectangle();

            for (var i = 0; i < 3; i++)
            {
                for (var j = 0; j < 3; j++)
                {
                    var textureData = m_textures[i, j];

                    if (i == 1 && j == 1)
                    {
                        // Center handling #different
                        var middleBarDefaultSize     = Math.Round(m_textures[1, 1].Size.X);
                        var currentProgressionLength = middleBarDefaultSize;
                        var fullProgressionLength    = Math.Ceiling(m_textures[0, 1].Size.X);
                        var progressionLength        = Math.Ceiling(fullProgressionLength * progression);

                        SetTarget(ref targetRect, textureData);
                        for (; currentProgressionLength < progressionLength; currentProgressionLength += middleBarDefaultSize)
                        {
                            MyGuiManager.DrawSprite(textureData.Texture.Texture, targetRect, colorMask);

                            targetRect.X = (int)(textureData.Position.X + currentProgressionLength);
                        }

                        var lastBarSize = middleBarDefaultSize - (currentProgressionLength - progressionLength);
                        targetRect.Width = (int)lastBarSize;
                        MyGuiManager.DrawSprite(textureData.Texture.Texture, targetRect, colorMask);
                    }
                    else
                    {
                        // All other parts can be rendered as usual
                        SetTarget(ref targetRect, textureData);

                        MyGuiManager.DrawSprite(textureData.Texture.Texture, targetRect, colorMask);
                    }
                }
            }
        }
コード例 #3
0
        public override unsafe void Draw()
        {
            base.Draw();
            Vector3 position = (Vector3)Vector3.Transform((Vector3)base.Container.Entity.PositionComp.GetPosition(), MySector.MainCamera.ViewMatrix);
            Vector4 vector   = Vector4.Transform(position, (Matrix)MySector.MainCamera.ProjectionMatrix);

            if (position.Z > 0f)
            {
                float *singlePtr1 = (float *)ref vector.X;
                singlePtr1[0] *= -1f;
                float *singlePtr2 = (float *)ref vector.Y;
                singlePtr2[0] *= -1f;
            }
            if (vector.W > 0f)
            {
                Vector2 normalizedCoord = new Vector2(((vector.X / vector.W) / 2f) + 0.5f, ((-vector.Y / vector.W) / 2f) + 0.5f);
                normalizedCoord = MyGuiManager.GetHudPixelCoordFromNormalizedCoord(normalizedCoord);
                for (int i = 0; i < this.m_invetoryItem.IconTextures.Length; i++)
                {
                    MyGuiManager.DrawSprite(this.m_invetoryItem.IconTextures[i], normalizedCoord, new Rectangle(0, 0, 0x80, 0x80), Color.White, 0f, new Vector2(64f, 64f), new Vector2(0.5f), SpriteEffects.None, 0f, true);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Draw the composite texture at specified position with given height (width is implicit from size of each part).
        /// </summary>
        /// <param name="positionTopLeft">Position of the top left corner of the composite texture.</param>
        /// <param name="innerHeight">Height of expandable area within composite texture (real height will include top and bottom as well).</param>
        public void Draw(Vector2 positionTopLeft, float innerHeight, Color colorMask)
        {
            Vector2   screenSize;
            Rectangle target;

            positionTopLeft = MyGuiManager.GetScreenCoordinateFromNormalizedCoordinate(positionTopLeft);
            target.X        = (int)positionTopLeft.X;
            target.Y        = (int)positionTopLeft.Y;
            target.Width    = 0;
            target.Height   = 0;

            if (!string.IsNullOrEmpty(m_leftTop.Texture))
            {
                screenSize    = MyGuiManager.GetScreenSizeFromNormalizedSize(m_leftTop.SizeGui);
                target.Width  = (int)screenSize.X;
                target.Height = (int)screenSize.Y;
                MyGuiManager.DrawSprite(m_leftTop.Texture, target, colorMask);
            }

            target.Y += target.Height;
            if (!string.IsNullOrEmpty(m_leftCenter.Texture))
            {
                screenSize    = MyGuiManager.GetScreenSizeFromNormalizedSize(new Vector2(m_leftCenter.SizeGui.X, innerHeight));
                target.Width  = (int)screenSize.X;
                target.Height = (int)screenSize.Y;
                MyGuiManager.DrawSprite(m_leftCenter.Texture, target, colorMask);
            }

            target.Y += target.Height;
            if (!string.IsNullOrEmpty(m_leftBottom.Texture))
            {
                screenSize    = MyGuiManager.GetScreenSizeFromNormalizedSize(m_leftBottom.SizeGui);
                target.Width  = (int)screenSize.X;
                target.Height = (int)screenSize.Y;
                MyGuiManager.DrawSprite(m_leftBottom.Texture, target, colorMask);
            }
        }
コード例 #5
0
        public void Draw(Vector2 positionLeftTop, Vector2 size, Color colorMask, float textureScale = 1f)
        {
            Rectangle target;

            size = Vector2.Clamp(size, MinSizeGui * textureScale, MaxSizeGui * textureScale);

            // L-left, R-right, T-top, B-bottom, C-center.
            Vector2I screenPosLT, screenPosLB, screenPosRT, screenPosRB;
            Vector2I screenSize, screenSizeLT, screenSizeCT, screenSizeRT,
                     screenSizeLC, screenSizeRC,
                     screenSizeLB, screenSizeCB, screenSizeRB;

            screenSizeLT = screenSizeCT = screenSizeRT = Vector2I.Zero;
            screenSizeLC = screenSizeRC = Vector2I.Zero;
            screenSizeLB = screenSizeCB = screenSizeRB = Vector2I.Zero;

            screenSize  = new Vector2I(MyGuiManager.GetScreenSizeFromNormalizedSize(size));
            screenPosLT = new Vector2I(MyGuiManager.GetScreenCoordinateFromNormalizedCoordinate(positionLeftTop));
            screenPosRB = screenPosLT + screenSize;
            screenPosLB = new Vector2I(screenPosLT.X, screenPosRB.Y);
            screenPosRT = new Vector2I(screenPosRB.X, screenPosLT.Y);

            // Render corners.
            if (!string.IsNullOrEmpty(m_leftTop.Texture))
            {
                screenSizeLT = (Vector2I)(MyGuiManager.GetScreenSizeFromNormalizedSize(m_leftTop.SizeGui) * textureScale);
                SetTargetRectangle(out target, ref screenPosLT, ref screenSizeLT, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                MyGuiManager.DrawSprite(m_leftTop.Texture, target, colorMask);
            }

            if (!string.IsNullOrEmpty(m_leftBottom.Texture))
            {
                screenSizeLB = (Vector2I)(MyGuiManager.GetScreenSizeFromNormalizedSize(m_leftBottom.SizeGui) * textureScale);
                SetTargetRectangle(out target, ref screenPosLB, ref screenSizeLB, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM);
                MyGuiManager.DrawSprite(m_leftBottom.Texture, target, colorMask);
            }

            if (!string.IsNullOrEmpty(m_rightTop.Texture))
            {
                screenSizeRT = (Vector2I)(MyGuiManager.GetScreenSizeFromNormalizedSize(m_rightTop.SizeGui) * textureScale);
                SetTargetRectangle(out target, ref screenPosRT, ref screenSizeRT, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP);
                MyGuiManager.DrawSprite(m_rightTop.Texture, target, colorMask);
            }

            if (!string.IsNullOrEmpty(m_rightBottom.Texture))
            {
                screenSizeRB = (Vector2I)(MyGuiManager.GetScreenSizeFromNormalizedSize(m_rightBottom.SizeGui) * textureScale);
                SetTargetRectangle(out target, ref screenPosRB, ref screenSizeRB, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                MyGuiManager.DrawSprite(m_rightBottom.Texture, target, colorMask);
            }

            // Render expandable sides to fill space between corners.
            if (!string.IsNullOrEmpty(m_centerTop.Texture))
            {
                screenSizeCT.X = (int)screenSize.X - ((int)screenSizeLT.X + (int)screenSizeRT.X);
                screenSizeCT.Y = (int)(MyGuiManager.GetScreenSizeFromNormalizedSize(m_centerTop.SizeGui).Y *textureScale);
                var pos = screenPosLT + new Vector2I(screenSizeLT.X, 0);
                SetTargetRectangle(out target, ref pos, ref screenSizeCT, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                MyGuiManager.DrawSprite(m_centerTop.Texture, target, colorMask);
            }

            if (!string.IsNullOrEmpty(m_centerBottom.Texture))
            {
                screenSizeCB.X = (int)screenSize.X - ((int)screenSizeLB.X + (int)screenSizeRB.X);
                screenSizeCB.Y = (int)(MyGuiManager.GetScreenSizeFromNormalizedSize(m_centerBottom.SizeGui).Y *textureScale);
                var pos = screenPosLB + new Vector2I(screenSizeLB.X, 0);
                SetTargetRectangle(out target, ref pos, ref screenSizeCB, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM);
                MyGuiManager.DrawSprite(m_centerBottom.Texture, target, colorMask);
            }

            if (!string.IsNullOrEmpty(m_leftCenter.Texture))
            {
                screenSizeLC.X = (int)(MyGuiManager.GetScreenSizeFromNormalizedSize(m_leftCenter.SizeGui).X *textureScale);
                screenSizeLC.Y = (int)screenSize.Y - ((int)screenSizeLT.Y + (int)screenSizeLB.Y);
                var pos = screenPosLT + new Vector2I(0, screenSizeLT.Y);
                SetTargetRectangle(out target, ref pos, ref screenSizeLC, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                MyGuiManager.DrawSprite(m_leftCenter.Texture, target, colorMask);
            }

            if (!string.IsNullOrEmpty(m_rightCenter.Texture))
            {
                screenSizeRC.X = (int)(MyGuiManager.GetScreenSizeFromNormalizedSize(m_rightCenter.SizeGui).X *textureScale);
                screenSizeRC.Y = (int)screenSize.Y - ((int)screenSizeRT.Y + (int)screenSizeRB.Y);
                var pos = screenPosRT + new Vector2I(0, screenSizeRT.Y);
                SetTargetRectangle(out target, ref pos, ref screenSizeRC, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP);
                MyGuiManager.DrawSprite(m_rightCenter.Texture, target, colorMask);
            }

            // Render expandable center to fill everything in between.
            if (!string.IsNullOrEmpty(m_center.Texture))
            {
                int leftWidth    = MathHelper.Max(screenSizeLT.X, screenSizeLC.X, screenSizeLB.X);
                int rightWidth   = MathHelper.Max(screenSizeRT.X, screenSizeRC.X, screenSizeRB.X);
                int topHeight    = MathHelper.Max(screenSizeLT.Y, screenSizeCT.Y, screenSizeRT.Y);
                int bottomHeight = MathHelper.Max(screenSizeLB.Y, screenSizeCB.Y, screenSizeRB.Y);

                var screenSizeC = screenSize - new Vector2I(leftWidth + rightWidth, topHeight + bottomHeight);
                var pos         = screenPosLT + new Vector2I(leftWidth, topHeight);
                SetTargetRectangle(out target, ref pos, ref screenSizeC, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                MyGuiManager.DrawSprite(m_center.Texture, target, colorMask);
            }
        }