Esempio n. 1
0
        public static float GetFontHeight(MyFontEnum font, float scale)
        {
            //  Fix the scale for screen resolution
            float   fixedScale         = scale * m_safeScreenScale * MyRenderGuiConstants.FONT_SCALE;
            Vector2 sizeInPixelsScaled = new Vector2(0.0f, fixedScale * m_fontsById[(int)font].LineHeight);

            return(GetNormalizedSizeFromScreenSize(sizeInPixelsScaled).Y);
        }
Esempio n. 2
0
        public static Vector2 GetNormalizedMousePosition(Vector2 mousePosition, Vector2 mouseAreaSize)
        {
            Vector2 scaledMousePos;

            scaledMousePos.X = mousePosition.X * (m_fullscreenRectangle.Width / mouseAreaSize.X);
            scaledMousePos.Y = mousePosition.Y * (m_fullscreenRectangle.Height / mouseAreaSize.Y);
            return(GetNormalizedCoordinateFromScreenCoordinate(scaledMousePos));
        }
Esempio n. 3
0
        public static Vector2 MeasureString(MyFontEnum font, StringBuilder text, float scale)
        {
            //  Fix the scale for screen resolution
            float   fixedScale         = scale * m_safeScreenScale;
            Vector2 sizeInPixelsScaled = m_fontsById[(int)font].MeasureString(text, fixedScale);

            return(GetNormalizedSizeFromScreenSize(sizeInPixelsScaled));
        }
        /// <summary>
        /// Draws fog (eg. background for notifications) at specified position in normalized GUI coordinates.
        /// </summary>
        public static void DrawFog(ref Vector2 centerPosition, ref Vector2 textSize)
        {
            Color   color       = new Color(0, 0, 0, (byte)(255 * 0.85f));
            Vector2 fogFadeSize = textSize * new Vector2(1.4f, 3.0f);

            MyGuiManager.DrawSpriteBatch(MyGuiConstants.FOG_SMALL, centerPosition, fogFadeSize, color,
                                         MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyVideoSettingsManager.IsTripleHead());
        }
Esempio n. 5
0
        internal MyVertexFormatTexcoordNormalTangent(Vector2 texcoord, Vector3 normal, Vector3 tangent)
        {
            Texcoord = new HalfVector2(texcoord.X, texcoord.Y);
            Normal   = VF_Packer.PackNormalB4(ref normal);
            Vector4 T = new Vector4(tangent, 1);

            Tangent = VF_Packer.PackTangentSignB4(ref T);
        }
Esempio n. 6
0
        //  Draws sprite batch at specified SCREEN position (in screen coordinates, not normalized coordinates).
        public static void DrawSpriteBatch(string texture, Vector2 pos, Color color)
        {
            if (string.IsNullOrEmpty(texture))
            {
                return;
            }

            DrawSprite(texture, pos, color);
        }
Esempio n. 7
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);
        }
 private void DrawNetgraphAverageLine(ref Vector2 position, float average1, float average2, float sizeMultiplier, Color color)
 {
     if (average1 != 0 || average2 != 0)
     {
         Vector2 pointFrom = new Vector2(position.X - 1, position.Y - average1 * sizeMultiplier);
         Vector2 pointTo   = new Vector2(position.X, position.Y - average2 * sizeMultiplier);
         VRageRender.MyRenderProxy.DebugDrawLine2D(pointFrom, pointTo, color, color);
     }
 }
Esempio n. 9
0
        //  Draws sprite batch at specified SCREEN position (in screen coordinates, not normalized coordinates).
        public static void DrawSpriteBatch(string texture, Vector2 pos, Color color, bool waitTillLoaded = true)
        {
            if (string.IsNullOrEmpty(texture))
            {
                return;
            }

            DrawSprite(texture, pos, color, waitTillLoaded);
        }
            private void DrawWatch(MyListDictionary <MemberInfo, MemberInfo> watch)
            {
                PlotHistory();
                if (watch == null)
                {
                    return;
                }
                List <object> log = new CacheList <object>(watch.Values.Count);

                StringBuilder sb  = new StringBuilder();
                Vector2       pos = new Vector2(100, 50);// m_counter * 0.2f);

                int i = -1;

                foreach (var list in watch.Values)
                {
                    i++;
                    if (i < SelectedMember)
                    {
                        continue;
                    }
                    object currentInstance = SelectedEntity;
                    foreach (var member in list)
                    {
                        sb.Append(".");
                        sb.Append(member.Name);
                        currentInstance = member.GetValue(currentInstance);
                    }
                    sb.Append(":");
                    sb.Append(currentInstance.ToString());
                    MyRenderProxy.DebugDrawText2D(pos, sb.ToString(),
                                                  m_toPlot.Contains(i) ? m_colors[i] : Color.White, 0.55f);
                    pos.Y += 12;
                    sb.Clear();
                    log.Add(currentInstance);
                }
                pos.X = 90;
                foreach (var toPlot in m_toPlot)
                {
                    int idx = (toPlot - SelectedMember);
                    if (idx < 0)
                    {
                        continue;
                    }
                    pos.Y = 50 + idx * 12;
                    MyRenderProxy.DebugDrawText2D(pos, "*",
                                                  m_colors[toPlot], 0.55f);
                }
                m_history.Add(log);
                if (m_history.Count >= MAX_HISTORY)
                {
                    m_history.RemoveAtFast(m_frame);
                }
                m_frame++;
                m_frame %= MAX_HISTORY;
            }
Esempio n. 11
0
        private static void DebugTextSize(StringBuilder text, ref Vector2 size)
        {
            string str      = text.ToString();
            bool   inserted = m_sizes.Add(str);

            if (inserted)
            {
                Console.WriteLine("Text = \"" + str + "\", Width = " + size.X);
            }
        }
Esempio n. 12
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.White, origin, Vector2.UnitX, source, destination);
        }
Esempio n. 13
0
 /// <summary>Convertes normalized size [0,1] to screen size (pixels)</summary>
 /// <param name="useFullClientArea">True uses full client rectangle. False limits to GUI rectangle</param>
 public static Vector2 GetScreenSizeFromNormalizedSize(Vector2 normalizedSize, bool useFullClientArea = false)
 {
     if (useFullClientArea)
     {
         return(new Vector2((m_safeFullscreenRectangle.Width + 1) * normalizedSize.X, m_safeFullscreenRectangle.Height * normalizedSize.Y));
     }
     else
     {
         return(new Vector2((m_safeGuiRectangle.Width + 1) * normalizedSize.X, m_safeGuiRectangle.Height * normalizedSize.Y));
     }
 }
        private void DrawPowerGroupInfo(MyHudConsumerGroupInfo info)
        {
            var   fsRect        = MyGuiManager.GetSafeFullscreenRectangle();
            float namesOffset   = -0.25f / (fsRect.Width / (float)fsRect.Height);
            var   posValuesBase = new Vector2(0.985f, 0.65f); // coordinates in SafeFullscreenRectangle, but DrawString works with SafeGuiRectangle.
            var   posNamesBase  = new Vector2(posValuesBase.X + namesOffset, posValuesBase.Y);
            var   posValues     = ConvertHudToNormalizedGuiPosition(ref posValuesBase);
            var   posNames      = ConvertHudToNormalizedGuiPosition(ref posNamesBase);

            info.Data.DrawBottomUp(posNames, posValues, m_textScale);
        }
Esempio n. 15
0
        public static Vector2 ConvertHudToNormalizedGuiPosition(ref Vector2 hudPos)
        {
            var safeFullscreenRectangle = MyGuiManager.GetSafeFullscreenRectangle();
            var safeFullscreenSize = new Vector2(safeFullscreenRectangle.Width, safeFullscreenRectangle.Height);
            var safeFullscreenOffset = new Vector2(safeFullscreenRectangle.X, safeFullscreenRectangle.Y);

            var safeGuiRectangle = MyGuiManager.GetSafeGuiRectangle();
            var safeGuiSize = new Vector2(safeGuiRectangle.Width, safeGuiRectangle.Height);
            var safeGuiOffset = new Vector2(safeGuiRectangle.X, safeGuiRectangle.Y);

            return ((hudPos * safeFullscreenSize + safeFullscreenOffset) - safeGuiOffset) / safeGuiSize;
        }
Esempio 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());
        }
Esempio n. 17
0
        protected static Vector2 ConvertNormalizedGuiToHud(ref Vector2 normGuiPos)
        {
            var safeFullscreenRectangle = MyGuiManager.GetSafeFullscreenRectangle();
            var safeFullscreenSize      = new Vector2(safeFullscreenRectangle.Width, safeFullscreenRectangle.Height);
            var safeFullscreenOffset    = new Vector2(safeFullscreenRectangle.X, safeFullscreenRectangle.Y);

            var safeGuiRectangle = MyGuiManager.GetSafeGuiRectangle();
            var safeGuiSize      = new Vector2(safeGuiRectangle.Width, safeGuiRectangle.Height);
            var safeGuiOffset    = new Vector2(safeGuiRectangle.X, safeGuiRectangle.Y);

            return(((normGuiPos * safeGuiSize + safeGuiOffset) - safeFullscreenOffset) / safeFullscreenSize);
        }
Esempio n. 18
0
        public static Vector2 ConvertHudToNormalizedGuiPosition(ref Vector2 hudPos)
        {
            var safeFullscreenRectangle = MyGuiManager.GetSafeFullscreenRectangle();
            var safeFullscreenSize      = new Vector2(safeFullscreenRectangle.Width, safeFullscreenRectangle.Height);
            var safeFullscreenOffset    = new Vector2(safeFullscreenRectangle.X, safeFullscreenRectangle.Y);

            var safeGuiRectangle = MyGuiManager.GetSafeGuiRectangle();
            var safeGuiSize      = new Vector2(safeGuiRectangle.Width, safeGuiRectangle.Height);
            var safeGuiOffset    = new Vector2(safeGuiRectangle.X, safeGuiRectangle.Y);

            return(((hudPos * safeFullscreenSize + safeFullscreenOffset) - safeGuiOffset) / safeGuiSize);
        }
            private void PlotHistory()
            {
                const float zeroLine = 400;
                int         idx      = 0;
                Vector2     b        = new Vector2(100, zeroLine);
                Vector2     b2       = b;

                b2.X += 1;
                MyRenderProxy.DebugDrawLine2D(new Vector2(b.X, b.Y - 200), new Vector2(b.X + 1000, b.Y - 200), Color.Gray,
                                              Color.Gray);
                MyRenderProxy.DebugDrawLine2D(new Vector2(b.X, b.Y + 200), new Vector2(b.X + 1000, b.Y + 200), Color.Gray,
                                              Color.Gray);
                MyRenderProxy.DebugDrawLine2D(new Vector2(b.X, b.Y), new Vector2(b.X + 1000, b.Y), Color.Gray, Color.Gray);
                MyRenderProxy.DebugDrawText2D(new Vector2(90, 400 - 200), (200 / m_scale).ToString(), Color.White, 0.55f,
                                              MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER);
                MyRenderProxy.DebugDrawText2D(new Vector2(90, 400 + 200), (-200 / m_scale).ToString(), Color.White, 0.55f,
                                              MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER);
                for (int i = Math.Min(1000, m_history.Count); i > 0; i--)
                {
                    int thisFrame = (m_frame + m_history.Count - i) % m_history.Count;
                    var frame     = m_history[thisFrame];
                    var frame2    = m_history[(thisFrame + 1) % m_history.Count];
                    idx++;
                    foreach (var toPlot in m_toPlot)
                    {
                        if (frame.Count <= toPlot || frame2.Count <= toPlot)
                        {
                            continue;
                        }
                        var o = frame[toPlot];
                        if (o.GetType().IsPrimitive)
                        {
                            var v  = ConvertToFloat(o);
                            var v2 = ConvertToFloat(frame2[toPlot]);
                            b.Y  = zeroLine - v * m_scale;
                            b2.Y = zeroLine - v2 * m_scale;
                            if (idx == 1)
                            {
                                b.Y = b2.Y;
                            }
                            if (i < 3)
                            {
                                b2.Y = b.Y;
                            }
                            MyRenderProxy.DebugDrawLine2D(b, b2, m_colors[toPlot], m_colors[toPlot]);
                        }
                    }
                    b.X  += 1;
                    b2.X += 1;
                }
            }
        private void DrawNetgraphLine(MyHudNetgraph.NetgraphLineData lineData, ref Vector2 position, ref Vector2 size)
        {
            Vector2I offset    = new Vector2I(0, 0);
            Vector2I positionI = new Vector2I((int)position.X, (int)position.Y);

            DrawNetgraphLineBar(positionI.X, ref positionI.Y, lineData.ByteCountReliableReceived, size.Y,
                                MyGuiConstants.NETGRAPH_RELIABLE_PACKET_COLOR, MyGuiConstants.NETGRAPH_RELIABLE_PACKET_COLOR_TOP);

            DrawNetgraphLineBar(positionI.X, ref positionI.Y, lineData.ByteCountUnreliableReceived, size.Y,
                                MyGuiConstants.NETGRAPH_UNRELIABLE_PACKET_COLOR, MyGuiConstants.NETGRAPH_UNRELIABLE_PACKET_COLOR_TOP);

            DrawNetgraphLineBar(positionI.X, ref positionI.Y, lineData.ByteCountSent, size.Y,
                                MyGuiConstants.NETGRAPH_SENT_PACKET_COLOR, MyGuiConstants.NETGRAPH_SENT_PACKET_COLOR_TOP);
        }
Esempio n. 21
0
        private static void CreateBillboard(VRageRender.MyBillboard billboard, ref MyQuadD quad, string material, ref Vector4 color, ref Vector3D origin,
                                            float softParticleDistanceScale = 1.0f, Vector2 uvOffset = new Vector2(), float reflectivity = 0)
        {
            Debug.Assert(material != null);

            if (string.IsNullOrEmpty(material) || !MyTransparentMaterials.ContainsMaterial(material))
            {
                material = "ErrorMaterial";
                color    = Vector4.One;
            }

            billboard.Material = material;

            quad.Point0.AssertIsValid();
            quad.Point1.AssertIsValid();
            quad.Point2.AssertIsValid();
            quad.Point3.AssertIsValid();


            //  Billboard vertexes
            billboard.Position0 = quad.Point0;
            billboard.Position1 = quad.Point1;
            billboard.Position2 = quad.Point2;
            billboard.Position3 = quad.Point3;

            billboard.UVOffset = uvOffset;
            billboard.UVSize   = Vector2.One;

            //  Distance for sorting
            //  IMPORTANT: Must be calculated before we do color and alpha misting, because we need distance there
            billboard.DistanceSquared = (float)Vector3D.DistanceSquared(MyRender11.Environment.Matrices.CameraPosition, origin);

            //  Color
            billboard.Color          = color;
            billboard.Reflectivity   = reflectivity;
            billboard.ColorIntensity = 1;

            billboard.ParentID = -1;

            //  Alpha depends on distance to camera. Very close bilboards are more transparent, so player won't see billboard errors or rotating billboards
            var mat = MyTransparentMaterials.GetMaterial(billboard.Material);

            if (mat.AlphaMistingEnable)
            {
                billboard.Color *= MathHelper.Clamp(((float)Math.Sqrt(billboard.DistanceSquared) - mat.AlphaMistingStart) / (mat.AlphaMistingEnd - mat.AlphaMistingStart), 0, 1);
            }

            billboard.Color *= mat.Color;
            billboard.SoftParticleDistanceScale = softParticleDistanceScale;
        }
        private void DrawVoiceChat(MyHudVoiceChat voiceChat)
        {
            MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            var bg      = MyGuiConstants.TEXTURE_VOICE_CHAT;
            var basePos = new Vector2(0.01f, 0.99f);
            var bgPos   = ConvertHudToNormalizedGuiPosition(ref basePos);

            MyGuiManager.DrawSpriteBatch(
                bg.Texture,
                bgPos,
                bg.SizeGui,
                Color.White,
                align);
        }
Esempio n. 23
0
 public override bool Draw(VRageMath.Vector2 position)
 {
     if (m_highlight)
     {
         MyGuiManager.DrawString(Common.MyFontEnum.White, Text, position, Scale, null, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
     }
     else
     {
         MyGuiManager.DrawString(Common.MyFontEnum.Blue, Text, position, Scale, VRageMath.Color.PowderBlue, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
     }
     m_linkImg.Draw(position + new Vector2(base.GetSize().X + m_linkImgSpace, 0));
     m_highlight = false;
     return(true);
 }
Esempio n. 24
0
        // different rounding of coords
        public static void DrawSpriteBatchRoundUp(string texture, Vector2 normalizedCoord, Vector2 normalizedSize, Color color, MyGuiDrawAlignEnum drawAlign, bool waitTillLoaded = true)
        {
            if (string.IsNullOrEmpty(texture))
            {
                return;
            }

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

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

            DrawSprite(texture, new Rectangle((int)Math.Floor(screenCoord.X), (int)Math.Floor(screenCoord.Y), (int)Math.Ceiling(screenSize.X), (int)Math.Ceiling(screenSize.Y)), color, waitTillLoaded);
        }
        private void DrawObjectiveLine(MyHudObjectiveLine objective)
        {
            MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP;
            var color   = Color.AliceBlue;
            var basePos = new Vector2(0.45f, 0.01f);
            var offset  = new Vector2(0f, 0.02f);

            var bgPos = ConvertHudToNormalizedGuiPosition(ref basePos);

            MyGuiManager.DrawString(MyFontEnum.Debug, new StringBuilder(objective.Title), bgPos, 1f, drawAlign: align, colorMask: color);

            basePos += offset;
            bgPos    = ConvertHudToNormalizedGuiPosition(ref basePos);
            MyGuiManager.DrawString(MyFontEnum.Debug, new StringBuilder("- " + objective.CurrentObjective), bgPos, 1f, drawAlign: align);
        }
Esempio n. 26
0
        //  Draws sprite batch at specified NORMALIZED position, with NORMALIZED width, but SCREEN-PIXEL height.
        //  Use if you want to draw rectangle where height is in screen coords, but rest is in normalized coord (e.g. slider long line)
        public static void DrawSpriteBatch(string texture, Vector2 normalizedCoord, float normalizedWidth, int screenHeight, Color color, MyGuiDrawAlignEnum drawAlign, bool waitTillLoaded = true)
        {
            if (string.IsNullOrEmpty(texture))
            {
                return;
            }

            Vector2 screenCoord = GetScreenCoordinateFromNormalizedCoordinate(normalizedCoord);
            Vector2 screenSize  = GetScreenSizeFromNormalizedSize(new Vector2(normalizedWidth, 0));

            screenSize.Y = screenHeight; //  Replace with desired value
            screenCoord  = MyUtils.GetCoordAligned(screenCoord, screenSize, drawAlign);

            DrawSprite(texture, new Rectangle((int)screenCoord.X, (int)screenCoord.Y, (int)screenSize.X, (int)screenSize.Y), color, waitTillLoaded);
        }
Esempio n. 27
0
 //  Convertes normalized coodrinate <0..1> to screen coordinate (pixels)
 public static Vector2 GetScreenCoordinateFromNormalizedCoordinate(Vector2 normalizedCoord, bool fullscreen = false)
 {
     if (fullscreen)
     {
         return(new Vector2(
                    m_safeFullscreenRectangle.Left + m_safeFullscreenRectangle.Width * normalizedCoord.X,
                    m_safeFullscreenRectangle.Top + m_safeFullscreenRectangle.Height * normalizedCoord.Y));
     }
     else
     {
         return(new Vector2(
                    m_safeGuiRectangle.Left + m_safeGuiRectangle.Width * normalizedCoord.X,
                    m_safeGuiRectangle.Top + m_safeGuiRectangle.Height * normalizedCoord.Y));
     }
 }
Esempio n. 28
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;
        }
Esempio n. 29
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);
        }
        private void DrawNetgraphBasicStrings(MyHudNetgraph netgraph, Vector2 initialPosition, Vector2 normalizedOffset)
        {
            StringBuilder sb = new StringBuilder();

            // Draw last received packet
            sb.Append("In: ").Append(netgraph.LastPacketBytesReceived);
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw average in
            sb.Clear();
            sb.Append("Avg In: ").Append(netgraph.AverageIncomingKBytes.ToString("0.##")).Append(" kB/s");
            initialPosition.X += normalizedOffset.X;
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw last sent packet
            sb.Clear();
            sb.Append("Out: ").Append(netgraph.LastPacketBytesSent);
            initialPosition.X -= normalizedOffset.X;
            initialPosition.Y += normalizedOffset.Y;
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw average out
            sb.Clear();
            sb.Append("Avg Out: ").Append(netgraph.AverageOutgoingKBytes.ToString("0.##")).Append(" kB/s");
            initialPosition.X += normalizedOffset.X;
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw updates per second
            sb.Clear();
            sb.Append("UPS: ").Append(netgraph.UpdatesPerSecond);
            initialPosition.X -= normalizedOffset.X;
            initialPosition.Y += normalizedOffset.Y;
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw frames per second
            sb.Clear();
            sb.Append("FPS: ").Append(netgraph.FramesPerSecond);
            initialPosition.X += normalizedOffset.X;
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw latency
            sb.Clear();
            sb.Append("Ping: ").Append(netgraph.Ping);
            initialPosition.X -= normalizedOffset.X;
            initialPosition.Y += normalizedOffset.Y;
            DrawNetgraphStringValue(initialPosition, sb);
        }
        private void DrawSuitInfo(MyHudCharacterInfo suitInfo)
        {
            MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            Color              color = Color.White;
            var                basePos = new Vector2(0.01f, 0.99f);
            var                bgPos = ConvertHudToNormalizedGuiPosition(ref basePos);
            Vector2            namePos, valuePos, bgScale;
            MyGuiPaddedTexture bg;

            bg      = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_DEFAULT;
            bgScale = new Vector2(1.1f, 1f);
            MyGuiManager.DrawSpriteBatch(bg.Texture, bgPos, new Vector2(bg.SizeGui.X * bgScale.X, suitInfo.Data.GetGuiHeight()), Color.White, align);

            namePos  = bgPos + new Vector2(1f, -1f) * bg.PaddingSizeGui * bgScale;
            valuePos = bgPos + bgScale * (new Vector2(bg.SizeGui.X, 0f) - bg.PaddingSizeGui);

            suitInfo.Data.DrawBottomUp(namePos, valuePos, m_textScale);
        }
Esempio n. 32
0
        //  Find screen texture that best matches aspect ratio of current GUI screen
        public static string GetBackgroundTextureFilenameByAspectRatio(Vector2 normalizedSize)
        {
            Vector2 screenSize        = GetScreenSizeFromNormalizedSize(normalizedSize);
            float   screenAspectRatio = screenSize.X / screenSize.Y;
            float   minDelta          = float.MaxValue;
            string  ret = null;

            foreach (MyGuiTextureScreen texture in m_backgroundScreenTextures)
            {
                float delta = Math.Abs(screenAspectRatio - texture.GetAspectRatio());
                if (delta < minDelta)
                {
                    minDelta = delta;
                    ret      = texture.GetFilename();
                }
            }
            return(ret);
        }
Esempio n. 33
0
        private static void TakeCustomSizedScreenshot(Vector2 rescale)
        {
            var resCpy = m_resolution;

            m_resolution = new Vector2I(resCpy * rescale);
            CreateScreenResources();

            DrawGameScene(false);
            m_resetEyeAdaptation = true;

            // uav3 stores final colors
            var surface = new MyRenderTarget(m_finalImage.GetSize().X, m_finalImage.GetSize().Y, SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            MyCopyToRT.Run(surface, m_finalImage);
            MyCopyToRT.ClearAlpha(surface);
            SaveScreenshotFromResource(surface.m_resource);
            surface.Release();

            m_resolution = resCpy;
            CreateScreenResources();
        }
Esempio n. 34
0
        private void DrawScenarioInfo(MyHudScenarioInfo scenarioInfo)
        {
            MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP;
            Color color = Color.White;
            var basePos = new Vector2(0.99f, 0.01f);
            var bgPos = ConvertHudToNormalizedGuiPosition(ref basePos);
            Vector2 namePos, valuePos, bgScale;
            MyGuiPaddedTexture bg;

            bg = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_DEFAULT;
            bgScale = new Vector2(1.1f, 1f);
            MyGuiManager.DrawSpriteBatch(bg.Texture, bgPos, new Vector2(bg.SizeGui.X * bgScale.X, scenarioInfo.Data.GetGuiHeight()), Color.White, align);

            namePos.X = bgPos.X - (bg.SizeGui.X - bg.PaddingSizeGui.X) * bgScale.X;
            namePos.Y = bgPos.Y + bg.PaddingSizeGui.Y * bgScale.Y;

            valuePos.X = bgPos.X - bgScale.X * bg.PaddingSizeGui.X;
            valuePos.Y = bgPos.Y + bgScale.Y * bg.PaddingSizeGui.Y;

            scenarioInfo.Data.DrawTopDown(namePos, valuePos, m_textScale);
        }
Esempio n. 35
0
        public override bool Draw()
        {
            if (m_transitionAlpha < 1.0f)
                return false;

            if (MyInput.Static.IsNewKeyPressed(MyKeys.J) && MyFakes.ENABLE_OBJECTIVE_LINE)
            {
                MyHud.ObjectiveLine.AdvanceObjective();
            }

            if (!MyHud.MinimalHud)
            {
                ProfilerShort.Begin("Marker rendering");
                ProfilerShort.Begin("m_markerRender.Draw");
                m_markerRender.Draw();
                ProfilerShort.BeginNextBlock("DrawTexts");
                DrawTexts();
                ProfilerShort.End();
                ProfilerShort.End();
            }

            m_toolbarControl.Visible = !(m_hiddenToolbar || MyHud.MinimalHud);

            Vector2 position = new Vector2(0.99f, 0.75f);
            if (MySession.Static.ControlledEntity is MyShipController) position.Y = 0.65f;
            position = ConvertHudToNormalizedGuiPosition(ref position);
            if (MyVideoSettingsManager.IsTripleHead())
                position.X += 1.0f;

            // TODO: refactor this
            m_blockInfo.Visible = MyHud.BlockInfo.Visible && !MyHud.MinimalHud;
            m_blockInfo.BlockInfo = m_blockInfo.Visible ? MyHud.BlockInfo : null;
            m_blockInfo.Position = position;
            m_blockInfo.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;

            m_questlogControl.Visible = MyHud.Questlog.Visible && !MyHud.MinimalHud;
            //m_questlogControl.QuestInfo = MyHud.Questlog;
            //m_questlogControl.RecreateControls();
            //m_questlogControl.Position = GetRealPositionOnCenterScreen(Vector2.Zero);
            //m_questlogControl.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;

            m_rotatingWheelControl.Visible = MyHud.RotatingWheelVisible && !MyHud.MinimalHud;

            m_chatControl.Visible = !(MyScreenManager.GetScreenWithFocus() is MyGuiScreenScenarioMpBase) && (!MyHud.MinimalHud || m_chatControl.HasFocus);

            if (!base.Draw())
                return false;

            var bgPos = new Vector2(0.01f, 0.85f);
            bgPos = MyGuiScreenHudBase.ConvertHudToNormalizedGuiPosition(ref bgPos);
            m_chatControl.Position = bgPos + new Vector2(0.17f, 0);
            m_chatControl.TextScale = 0.9f;

            bgPos = new Vector2(0.03f, 0.1f);
            bgPos = MyGuiScreenHudBase.ConvertHudToNormalizedGuiPosition(ref bgPos);
            m_cameraInfoMultilineControl.Position = bgPos;
            m_cameraInfoMultilineControl.TextScale = 0.9f;

            if (!MyHud.MinimalHud)
            {
                bool inNaturalGravity = false;
                var cockpit = MySession.Static.ControlledEntity as MyCockpit;
                if (cockpit != null)
                {
                    var characterPosition = cockpit.PositionComp.GetPosition();
                    inNaturalGravity = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(characterPosition) != 0;
                }

                if (inNaturalGravity)
                    DrawArtificialHorizonAndAltitude();
            }

            MyHud.Notifications.Draw();

            if (!MyHud.MinimalHud)
            {
                m_buildModeLabel.Visible = MyHud.IsBuildMode;

                m_blocksLeft.Text = MyHud.BlocksLeft.GetStringBuilder().ToString();
                m_blocksLeft.Visible = MyHud.BlocksLeft.Visible;

                if (MyHud.ShipInfo.Visible)
                    DrawShipInfo(MyHud.ShipInfo);

                if (MyHud.CharacterInfo.Visible)
                    DrawSuitInfo(MyHud.CharacterInfo);

                if (MyHud.ObjectiveLine.Visible && MyFakes.ENABLE_OBJECTIVE_LINE)
                    DrawObjectiveLine(MyHud.ObjectiveLine);

                if (MySandboxGame.Config.EnablePerformanceWarnings)
                {
                    foreach (var warning in MySimpleProfiler.CurrentWarnings)
                    {
                        if (warning.Value.Time < 120)
                        {
                            DrawPerformanceWarning();
                            break;
                        }
                    }
                }
            }
            else
            {
                m_buildModeLabel.Visible = false;
                m_blocksLeft.Visible = false;
            }

            MyHud.BlockInfo.Visible = false;
            m_blockInfo.BlockInfo = null;

            if (MyFakes.ENABLE_USE_OBJECT_HIGHLIGHT)
            {
                MyHudObjectHighlightStyleData data = new MyHudObjectHighlightStyleData();
                data.AtlasTexture = m_atlas;
                data.TextureCoord = GetTextureCoord(MyHudTexturesEnum.corner);
                MyGuiScreenHudBase.HandleSelectedObjectHighlight(MyHud.SelectedObjectHighlight, data);
            }

            if (!MyHud.MinimalHud)
            {
                if (MyHud.GravityIndicator.Visible)
                    DrawGravityIndicator(MyHud.GravityIndicator, MyHud.CharacterInfo);

                if (MyHud.SinkGroupInfo.Visible)
                    DrawPowerGroupInfo(MyHud.SinkGroupInfo);

                if (MyHud.LocationMarkers.Visible)
                    m_markerRender.DrawLocationMarkers(MyHud.LocationMarkers);

                if (MyHud.GpsMarkers.Visible && MyFakes.ENABLE_GPS)
                    DrawGpsMarkers(MyHud.GpsMarkers);

                if (MyHud.ButtonPanelMarkers.Visible)
                    DrawButtonPanelMarkers(MyHud.ButtonPanelMarkers);

                if (MyHud.OreMarkers.Visible)
                    DrawOreMarkers(MyHud.OreMarkers);

                if (MyHud.LargeTurretTargets.Visible)
                    DrawLargeTurretTargets(MyHud.LargeTurretTargets);

                DrawWorldBorderIndicator(MyHud.WorldBorderChecker);

                if (MyHud.HackingMarkers.Visible)
                    DrawHackingMarkers(MyHud.HackingMarkers);

                //m_chatControl.Visible = !MyHud.MinimalHud;

            }
                DrawCameraInfo(MyHud.CameraInfo);

            ProfilerShort.Begin("Draw netgraph");
            if (MyFakes.ENABLE_NETGRAPH && MyHud.IsNetgraphVisible)
                DrawNetgraph(MyHud.Netgraph);
            ProfilerShort.End();
            //if (Sync.MultiplayerActive)
            DrawMultiplayerNotifications();

            if (!MyHud.MinimalHud)
            {
                if (MyHud.VoiceChat.Visible)
                    DrawVoiceChat(MyHud.VoiceChat);

                if (MyHud.ScenarioInfo.Visible)
                    DrawScenarioInfo(MyHud.ScenarioInfo);
            }
            return true;
        }
Esempio n. 36
0
 private void DrawVoiceChat(MyHudVoiceChat voiceChat)
 {
     MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
     var bg = MyGuiConstants.TEXTURE_VOICE_CHAT;
     var basePos = new Vector2(0.01f, 0.99f);
     var bgPos = ConvertHudToNormalizedGuiPosition(ref basePos);
     MyGuiManager.DrawSpriteBatch(
         bg.Texture,
         bgPos,
         bg.SizeGui,
         Color.White,
         align);
 }
Esempio n. 37
0
        private void DrawGravityIndicator(MyHudGravityIndicator indicator, MyHudCharacterInfo characterInfo)
        {
            if (indicator.Entity == null)
                return;

            Vector3D worldPosition = MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.Entity || MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator ? indicator.Entity.PositionComp.WorldAABB.Center : MySpectatorCameraController.Static.Position;
            Vector3 totalGravity = MyGravityProviderSystem.CalculateTotalGravityInPoint(worldPosition);
            Vector3 naturalGravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(worldPosition);
            Vector3 artificialGravity = totalGravity - naturalGravity;
            //gravity += MyPhysics.HavokWorld.Gravity;
            bool anyGravity = !Vector3.IsZero(totalGravity);
            bool anyNaturalGravity = anyGravity && !Vector3.IsZero(naturalGravity);

            // Background and text drawing
            string totalGravityFont, artificialGravityFont = MyFontEnum.Blue, naturalGravityFont = MyFontEnum.Blue;
            StringBuilder totalGravityText, artificialGravityText = null, naturalGravityText = null;
            MyGuiPaddedTexture backgroundTexture;
            if (anyGravity)
            {
                totalGravityFont = MyFontEnum.Blue;
                totalGravityText = MyTexts.Get(MySpaceTexts.HudInfoGravity);
                if (!anyNaturalGravity)
                    artificialGravityFont = MyFontEnum.White;
                artificialGravityText = MyTexts.Get(MySpaceTexts.HudInfoGravityArtificial);
                backgroundTexture = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_DEFAULT;
            }
            else
            {
                totalGravityFont = MyFontEnum.Red;
                totalGravityText = MyTexts.Get(MySpaceTexts.HudInfoNoGravity);
                backgroundTexture = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_RED;
            }

            if (anyNaturalGravity)
            {
                naturalGravityText = MyTexts.Get(MySpaceTexts.HudInfoGravityNatural);
                if (naturalGravity.Length() > artificialGravity.Length())
                {
                    artificialGravityFont = MyFontEnum.Blue;
                    naturalGravityFont = MyFontEnum.White;
                }
                else
                {
                    artificialGravityFont = MyFontEnum.White;
                    naturalGravityFont = MyFontEnum.Blue;
                }
            }

            bool drawOxygen = MySession.Static.Settings.EnableOxygen;
            Vector2 bgSizeDelta = new Vector2(0.015f + 0.02f, 0.05f);
            float oxygenLevel = 0f;

            Vector2 oxygenCompensation = Vector2.Zero;
            if (drawOxygen && anyNaturalGravity) oxygenCompensation = new Vector2(0f, 0.025f);
            Vector2 backgroundSize = backgroundTexture.SizeGui + bgSizeDelta + oxygenCompensation;

            Vector2 backgroundPosition, vectorPosition;
            Vector2 totalGravityTextPos, artificialGravityTextPos, naturalGravityTextPos;
            Vector2 totalGravityNumberPos, artificialGravityNumberPos, naturalGravityNumberPos;
            Vector2 dividerLinePosition, dividerLineSize;
            MyGuiDrawAlignEnum backgroundAlignment, gravityTextAlignment = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP, gravityNumberAlignment = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;

            dividerLineSize = new Vector2(backgroundSize.X - backgroundTexture.PaddingSizeGui.X * 1f, backgroundSize.Y / 60f);

            if (indicator.Entity is MyCharacter)
            {
                backgroundAlignment = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
                backgroundPosition = new Vector2(0.99f, 0.99f);
                backgroundPosition = ConvertHudToNormalizedGuiPosition(ref backgroundPosition);

                totalGravityTextPos = backgroundPosition - backgroundSize * new Vector2(0.35f, 1.075f);
                totalGravityNumberPos = totalGravityTextPos + new Vector2(0.0075f, 0.002f);
                dividerLinePosition = new Vector2(backgroundPosition.X - backgroundSize.X + backgroundTexture.PaddingSizeGui.X / 2.0f, totalGravityTextPos.Y) + new Vector2(0.0f, 0.026f);


                {
                    artificialGravityTextPos = new Vector2(totalGravityTextPos.X, dividerLinePosition.Y) + new Vector2(0.0f, 0.005f);
                    artificialGravityNumberPos = new Vector2(totalGravityNumberPos.X, artificialGravityTextPos.Y);
                    naturalGravityTextPos = artificialGravityTextPos + new Vector2(0.0f, 0.025f);
                    naturalGravityNumberPos = artificialGravityNumberPos + new Vector2(0.0f, 0.025f);
                }

                vectorPosition = backgroundPosition - backgroundSize * new Vector2(0.5f, 0.5f - 0.05f) + backgroundTexture.PaddingSizeGui * Vector2.UnitY * 0.5f;

                oxygenLevel = (indicator.Entity as MyCharacter).OxygenComponent != null ? (indicator.Entity as MyCharacter).OxygenComponent.EnvironmentOxygenLevel : 0f;
            }
            else
            {
                backgroundAlignment = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
                backgroundPosition = new Vector2(0.01f, 1f - (characterInfo.Data.GetGuiHeight() + 0.02f));
                backgroundPosition = ConvertHudToNormalizedGuiPosition(ref backgroundPosition);

                gravityTextAlignment = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
                gravityNumberAlignment = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
                totalGravityTextPos = backgroundPosition + backgroundSize * new Vector2(1 - 0.35f, -0.99f) + backgroundTexture.PaddingSizeGui * Vector2.UnitY * 0.2f;
                totalGravityNumberPos = totalGravityNumberPos = totalGravityTextPos + new Vector2(0.0075f, 0.0025f);
                dividerLinePosition = new Vector2(backgroundPosition.X + backgroundTexture.PaddingSizeGui.X / 2.0f, totalGravityTextPos.Y - 0.022f) + new Vector2(0.0f, 0.026f);

                {
                    artificialGravityTextPos = new Vector2(totalGravityTextPos.X, dividerLinePosition.Y + 0.023f) + new Vector2(0.0f, 0.005f);
                    artificialGravityNumberPos = new Vector2(totalGravityNumberPos.X, artificialGravityTextPos.Y);
                    naturalGravityTextPos = artificialGravityTextPos + new Vector2(0.0f, 0.025f);
                    naturalGravityNumberPos = artificialGravityNumberPos + new Vector2(0.0f, 0.025f);
                }

                vectorPosition = backgroundPosition - backgroundSize * new Vector2(-0.5f, 0.5f - 0.05f) + backgroundTexture.PaddingSizeGui * Vector2.UnitY * 0.5f;

                var cockpit = indicator.Entity as MyCockpit;
                if (cockpit != null && cockpit.Pilot != null && cockpit.Pilot.OxygenComponent != null)
                {
                    oxygenLevel = cockpit.Pilot.OxygenComponent.EnvironmentOxygenLevel;
                }
                else
                {
                    drawOxygen = false;
                }
            }

            m_gravityHudWidth = backgroundSize.X;
            MyGuiManager.DrawSpriteBatch(backgroundTexture.Texture, backgroundPosition, backgroundSize + (true ? new Vector2(0f, 0.025f) : Vector2.Zero), Color.White, backgroundAlignment);
            var controlledEntity = MySession.Static.ControlledEntity as MyEntity;
            var scale = 0.85f;
            if (anyNaturalGravity && controlledEntity != null)
            {
                double cosRotation = Vector3D.Normalize(Vector3D.Reject(naturalGravity, controlledEntity.WorldMatrix.Forward)).Dot(Vector3D.Normalize(-controlledEntity.WorldMatrix.Up));
                float rotation = 0.0f;
                rotation = (float)Math.Acos(cosRotation);

                if (naturalGravity.Dot(controlledEntity.WorldMatrix.Right) >= 0)
                    rotation = 2.0f * (float)Math.PI - rotation;

                MyGuiManager.DrawSpriteBatch(MyGuiConstants.TEXTURE_HUD_GRAVITY_GLOBE.Texture, vectorPosition + new Vector2(0.045f, 0.065f) * scale + oxygenCompensation / 2, scale, Color.White, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, rotation, new Vector2(0.5f));
            }
            MyGuiManager.DrawString(totalGravityFont, totalGravityText, totalGravityTextPos, m_textScale, drawAlign: gravityTextAlignment);

            if (anyGravity)
                MyGuiManager.DrawSpriteBatch(MyGuiConstants.TEXTURE_HUD_GRAVITY_LINE.Texture, dividerLinePosition, dividerLineSize, Color.White, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER);

            if (drawOxygen)
            {
                Vector2 oxygenTextPos = artificialGravityTextPos + new Vector2(0.0f, 0.025f) + oxygenCompensation.Y;
                var oxygenFont = MyFontEnum.Blue;
                var oxygenText = new StringBuilder(MyTexts.Get(MySpaceTexts.HudInfoOxygen).ToString());
                if (oxygenLevel == 0f)
                {
                    oxygenText.Append("None");
                    oxygenFont = MyFontEnum.Red;
                }
                else if (oxygenLevel < 0.5f)
                {
                    oxygenText.Append("Low");
                    oxygenFont = MyFontEnum.Red;
                }
                else
                {
                    oxygenText.Append("High");
                }

                MyGuiManager.DrawString(oxygenFont, oxygenText, oxygenTextPos, m_textScale, drawAlign: gravityTextAlignment);
            }

            if (anyGravity)
            {
                m_hudIndicatorText.Clear();
                m_hudIndicatorText.AppendFormatedDecimal("", totalGravity.Length() / MyGravityProviderSystem.G, 2, " g");
                MyGuiManager.DrawString(totalGravityFont, m_hudIndicatorText, totalGravityNumberPos, m_textScale, drawAlign: gravityNumberAlignment);
                m_hudIndicatorText.Clear();
                m_hudIndicatorText.AppendFormatedDecimal("", artificialGravity.Length() / MyGravityProviderSystem.G, 2, " g");
                MyGuiManager.DrawString(artificialGravityFont, artificialGravityText, artificialGravityTextPos, m_textScale, drawAlign: gravityTextAlignment);
                MyGuiManager.DrawString(artificialGravityFont, m_hudIndicatorText, artificialGravityNumberPos, m_textScale, drawAlign: gravityNumberAlignment);
                if (anyNaturalGravity)
                {
                    m_hudIndicatorText.Clear();
                    m_hudIndicatorText.AppendFormatedDecimal("", naturalGravity.Length() / MyGravityProviderSystem.G, 2, " g");
                    MyGuiManager.DrawString(naturalGravityFont, naturalGravityText, naturalGravityTextPos, m_textScale, drawAlign: gravityTextAlignment);
                    MyGuiManager.DrawString(naturalGravityFont, m_hudIndicatorText, naturalGravityNumberPos, m_textScale, drawAlign: gravityNumberAlignment);
                }
            }

            vectorPosition = MyGuiManager.GetHudSize() * ConvertNormalizedGuiToHud(ref vectorPosition) + (oxygenCompensation / 2) * scale;
            if (MyVideoSettingsManager.IsTripleHead())
                vectorPosition.X += 1.0f;

            // Draw each of gravity indicators.
            foreach (var generatorGravity in MyGravityProviderSystem.GravityVectors)
                DrawGravityVectorIndicator(vectorPosition, generatorGravity, MyHudTexturesEnum.gravity_arrow, Color.Gray);

            if (anyGravity)
                DrawGravityVectorIndicator(vectorPosition, totalGravity, MyHudTexturesEnum.gravity_arrow, Color.White);

            // Draw center
            MyAtlasTextureCoordinate centerTextCoord;
            if (anyGravity)
                centerTextCoord = GetTextureCoord(MyHudTexturesEnum.gravity_point_white);
            else
                centerTextCoord = GetTextureCoord(MyHudTexturesEnum.gravity_point_red);

            float hudSizeX = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X;
            float hudSizeY = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y;
            Vector2 rightVector = Vector2.UnitX;

            MyRenderProxy.DrawSpriteAtlas(
                m_atlas,
                vectorPosition,
                centerTextCoord.Offset,
                centerTextCoord.Size,
                rightVector,
                new Vector2(hudSizeX, hudSizeY),
                MyHudConstants.HUD_COLOR_LIGHT,
                Vector2.One * 0.005f);

        }
Esempio n. 38
0
        private void DrawGravityVectorIndicator(Vector2 centerPos, Vector3 worldGravity, MyHudTexturesEnum texture, Color color)
        {
            float hudSizeX = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X;
            float hudSizeY = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y;

            var textureCoord = GetTextureCoord(texture);
            var viewGravity = Vector3.TransformNormal(worldGravity, MySector.MainCamera.ViewMatrix);
            var viewGravityLen = viewGravity.Length();
            if (!MyUtils.IsZero(viewGravityLen))
                viewGravity /= viewGravityLen;

            var right = new Vector2(viewGravity.Y, viewGravity.X);
            var rightLen = right.Length();

            if (!MyUtils.IsZero(rightLen))
                right /= rightLen;

            var scale = Vector2.One * new Vector2(0.003f, 0.013f);
            scale.Y *= rightLen;

            VRageRender.MyRenderProxy.DrawSpriteAtlas(
                m_atlas,
                centerPos + new Vector2(viewGravity.X, -viewGravity.Y) * 0.02f,
                textureCoord.Offset,
                textureCoord.Size,
                right,
                new Vector2(hudSizeX, hudSizeY),
                color,
                scale);
        }
Esempio n. 39
0
        private void DrawObjectiveLine(MyHudObjectiveLine objective)
        {
            MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP;
            var color = Color.AliceBlue;
            var basePos = new Vector2(0.45f, 0.01f);
            var offset = new Vector2(0f, 0.02f);

            var bgPos = ConvertHudToNormalizedGuiPosition(ref basePos);
            MyGuiManager.DrawString(MyFontEnum.Debug, new StringBuilder(objective.Title), bgPos, 1f, drawAlign: align, colorMask: color);

            basePos += offset;
            bgPos = ConvertHudToNormalizedGuiPosition(ref basePos);
            MyGuiManager.DrawString(MyFontEnum.Debug, new StringBuilder("- " + objective.CurrentObjective), bgPos, 1f, drawAlign: align);

        }
Esempio n. 40
0
        public static void DrawSelectionCorner(string atlasTexture, MyHudSelectedObject selection, MyAtlasTextureCoordinate textureCoord, Vector2 scale, Vector2 pos, Vector2 rightVector, float textureScale)
        {
            if (MyVideoSettingsManager.IsTripleHead())
                pos.X = pos.X * 3;

            VRageRender.MyRenderProxy.DrawSpriteAtlas(
                atlasTexture,
                pos,
                textureCoord.Offset,
                textureCoord.Size,
                rightVector,
                scale,
                selection.Color,
                selection.HalfSize / MyGuiManager.GetHudSize() * textureScale);
        }
Esempio n. 41
0
        /// <summary>
        /// Draws fog (eg. background for notifications) at specified position in normalized GUI coordinates.
        /// </summary>
        public static void DrawFog(ref Vector2 centerPosition, ref Vector2 textSize)
        {
            Color color = new Color(0, 0, 0, (byte)(255 * 0.85f));
            Vector2 fogFadeSize = textSize * new Vector2(1.4f, 3.0f);

            MyGuiManager.DrawSpriteBatch(MyGuiConstants.FOG_SMALL, centerPosition, fogFadeSize, color,
                MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyVideoSettingsManager.IsTripleHead());
        }
Esempio n. 42
0
        public static void DrawSelectedObjectHighlight(string atlasTexture, MyAtlasTextureCoordinate textureCoord, MyHudSelectedObject selection)
        {
            var rect = MyGuiManager.GetSafeFullscreenRectangle();

            Vector2 hudSize = new Vector2(rect.Width, rect.Height);

            var worldViewProj = selection.InteractiveObject.ActivationMatrix * MySector.MainCamera.ViewMatrix * (MatrixD)MySector.MainCamera.ProjectionMatrix;
            BoundingBoxD screenSpaceAabb = new BoundingBoxD(-Vector3D.One / 2, Vector3D.One / 2).Transform(worldViewProj);
            var min = new Vector2((float)screenSpaceAabb.Min.X, (float)screenSpaceAabb.Min.Y);
            var max = new Vector2((float)screenSpaceAabb.Max.X, (float)screenSpaceAabb.Max.Y);

            var minToMax = min - max;

            min = min * 0.5f + 0.5f * Vector2.One;
            max = max * 0.5f + 0.5f * Vector2.One;

            min.Y = 1 - min.Y;
            max.Y = 1 - max.Y;

            float textureScale = (float)Math.Pow(Math.Abs(minToMax.X), 0.35f) * 2.5f;

            if (selection.InteractiveObject.ShowOverlay)
            {
                BoundingBoxD one = new BoundingBoxD(new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(0.5f, 0.5f, 0.5f));
                Color color = Color.Gold;
                color *= 0.4f;
                var m = selection.InteractiveObject.ActivationMatrix;
                var localToWorld = MatrixD.Invert(selection.InteractiveObject.WorldMatrix);
                //MySimpleObjectDraw.DrawTransparentBox(ref m, ref one, ref color, MySimpleObjectRasterizer.Solid, 0, 0.05f, "Square", null, true);

                MySimpleObjectDraw.DrawAttachedTransparentBox(ref m, ref one, ref color, selection.InteractiveObject.RenderObjectID,
                    ref localToWorld, MySimpleObjectRasterizer.Solid, 0, 0.05f, "Square", null, true);
            }

            if (MyFakes.ENABLE_USE_OBJECT_CORNERS)
            {
                DrawSelectionCorner(atlasTexture, selection, textureCoord, hudSize, min, -Vector2.UnitY, textureScale);
                DrawSelectionCorner(atlasTexture, selection, textureCoord, hudSize, new Vector2(min.X, max.Y), Vector2.UnitX, textureScale);
                DrawSelectionCorner(atlasTexture, selection, textureCoord, hudSize, new Vector2(max.X, min.Y), -Vector2.UnitX, textureScale);
                DrawSelectionCorner(atlasTexture, selection, textureCoord, hudSize, max, Vector2.UnitY, textureScale);
            }
        }
Esempio n. 43
0
        public static void DrawCrosshair(string atlas, MyAtlasTextureCoordinate textureCoord, MyHudCrosshair crosshair)
        {
            Vector2 rightVector = new Vector2(crosshair.UpVector.Y, crosshair.UpVector.X);

            float hudSizeX = MyGuiManager.GetSafeFullscreenRectangle().Width / MyGuiManager.GetHudSize().X;
            float hudSizeY = MyGuiManager.GetSafeFullscreenRectangle().Height / MyGuiManager.GetHudSize().Y;
            var pos = crosshair.Position;
            if (MyVideoSettingsManager.IsTripleHead())
                pos.X += 1.0f;

            VRageRender.MyRenderProxy.DrawSpriteAtlas(
                atlas,
                pos,
                textureCoord.Offset,
                textureCoord.Size,
                rightVector,
                new Vector2(hudSizeX, hudSizeY),
                crosshair.Color,
                crosshair.HalfSize);
        }
Esempio n. 44
0
        protected static Vector2 ConvertNormalizedGuiToHud(ref Vector2 normGuiPos)
        {
            var safeFullscreenRectangle = MyGuiManager.GetSafeFullscreenRectangle();
            var safeFullscreenSize = new Vector2(safeFullscreenRectangle.Width, safeFullscreenRectangle.Height);
            var safeFullscreenOffset = new Vector2(safeFullscreenRectangle.X, safeFullscreenRectangle.Y);

            var safeGuiRectangle = MyGuiManager.GetSafeGuiRectangle();
            var safeGuiSize = new Vector2(safeGuiRectangle.Width, safeGuiRectangle.Height);
            var safeGuiOffset = new Vector2(safeGuiRectangle.X, safeGuiRectangle.Y);

            return ((normGuiPos * safeGuiSize + safeGuiOffset) - safeFullscreenOffset) / safeFullscreenSize;
        }
        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;
                    }
            }
        }
Esempio n. 46
0
        private void DrawArtificialHorizonAndAltitude()
        {
            var controlledEntity = MySession.Static.ControlledEntity as MyCubeBlock;
            var controlledEntityPosition = controlledEntity.CubeGrid.Physics.CenterOfMassWorld;
            var controlledEntityCenterOfMass = controlledEntity.GetTopMostParent().Physics.CenterOfMassWorld;
            if (controlledEntity == null)
                return;

            var shipController = controlledEntity as MyShipController;
            if (shipController != null && !shipController.HorizonIndicatorEnabled)
                return;

            MyPlanet nearestPlanet;
            FindDistanceToNearestPlanetSeaLevel(controlledEntity.PositionComp.WorldAABB, out nearestPlanet);
            if (nearestPlanet == null)
                return;

            Vector3D closestPoint = nearestPlanet.GetClosestSurfacePointGlobal(ref controlledEntityPosition);
            float distanceToSeaLevel = (float)Vector3D.Distance(closestPoint, controlledEntityPosition);

            string altitudeFont = MyFontEnum.Blue;
            var altitudeAlignment = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
            var altitude = distanceToSeaLevel;

            //GR: Not the best place to start pressurization but it just sets a boolean and the Pressurization itself happens on a seperate thread
            //Do this because the environment oxygen level will not change in the Cubegrid
            if (Math.Abs(altitude - m_altitude) > ALTITUDE_CHANGE_THRESHOLD)
            {
                if (controlledEntity.CubeGrid.GridSystems.GasSystem != null)
                {
                    controlledEntity.CubeGrid.GridSystems.GasSystem.Pressurize();
                    m_altitude = altitude;
                }
            }

            var altitudeText = new StringBuilder().AppendDecimal(altitude, 0).Append(" m");

            var altitudeVerticalOffset = 0.03f;
            var widthRatio = MyGuiManager.GetFullscreenRectangle().Width / MyGuiManager.GetSafeFullscreenRectangle().Width;
            var heightRatio = MyGuiManager.GetFullscreenRectangle().Height / MyGuiManager.GetSafeFullscreenRectangle().Height;
            var altitudePosition = new Vector2(MyHud.Crosshair.Position.X * widthRatio / MyGuiManager.GetHudSize().X/* - MyHud.Crosshair.HalfSize.X*m_textScale*/, MyHud.Crosshair.Position.Y * heightRatio / MyGuiManager.GetHudSize().Y + altitudeVerticalOffset);

            if (MyVideoSettingsManager.IsTripleHead())
                altitudePosition.X -= 1.0f;

            MyGuiManager.DrawString(altitudeFont, altitudeText, altitudePosition, m_textScale, drawAlign: altitudeAlignment, useFullClientArea : true);

            var planetSurfaceNormal = (controlledEntityCenterOfMass - nearestPlanet.WorldMatrix.Translation);
            planetSurfaceNormal.Normalize();

            var rotationMatrix = controlledEntity.WorldMatrix;
            rotationMatrix.Translation = Vector3D.Zero;
            rotationMatrix.Up = planetSurfaceNormal;
            rotationMatrix.Forward = Vector3D.Normalize(Vector3D.Reject(planetSurfaceNormal, controlledEntity.WorldMatrix.Forward));
            rotationMatrix.Left = rotationMatrix.Up.Cross(rotationMatrix.Forward);
            var planetSurfaceTangent = Vector3D.Normalize(Vector3D.Transform(Vector3D.Forward, rotationMatrix));

            double cosVerticalAngle = planetSurfaceNormal.Dot(controlledEntity.WorldMatrix.Forward);
            var scale = 0.75f;

            var horizonDefaultCenterPosition = MyGuiManager.GetNormalizedCoordinateFromScreenCoordinate_FULLSCREEN(MyHud.Crosshair.Position / MyGuiManager.GetHudSize() * new Vector2(MyGuiManager.GetSafeFullscreenRectangle().Width, MyGuiManager.GetSafeFullscreenRectangle().Height));
            var horizonAlignment = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;
            var horizonTexture = MyGuiConstants.TEXTURE_HUD_GRAVITY_HORIZON;
            var horizonSize = horizonTexture.SizeGui;

            float offsetLimit;
            if (MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator)
                offsetLimit = 0.45f;
            else
                offsetLimit = 0.35f;
            float distanceFromCenter = (float)cosVerticalAngle * offsetLimit;

            float cosRotation = Vector3.Reject(planetSurfaceTangent, controlledEntity.WorldMatrix.Forward).Dot(controlledEntity.WorldMatrix.Up);
            float rotation = (float)Math.Acos(cosRotation);
            if (nearestPlanet.Components.Get<MyGravityProviderComponent>().GetWorldGravity(controlledEntityCenterOfMass).Dot(controlledEntity.WorldMatrix.Right) >= 0)
                rotation = 2.0f * (float)Math.PI - rotation;//roll, direction to the left,
            float sinRotation = (float)Math.Sin(rotation);
            Vector2 magicOffset = new Vector2(0.0145f, 0.0175f);	// DrawSpriteBatch with rotation needs this
            var horizonPosition = new Vector2(-sinRotation * distanceFromCenter,
                                              cosRotation * distanceFromCenter);
            horizonPosition += horizonDefaultCenterPosition + scale * horizonSize / 2.0f + magicOffset;

            MyGuiManager.DrawSpriteBatch(horizonTexture.Texture, horizonPosition, scale, Color.White, horizonAlignment, rotation, new Vector2(0.5f));
        }
Esempio n. 47
0
 private void DrawPowerGroupInfo(MyHudSinkGroupInfo info)
 {
     var fsRect = MyGuiManager.GetSafeFullscreenRectangle();
     float namesOffset = -0.25f / (fsRect.Width / (float)fsRect.Height);
     var posValuesBase = new Vector2(0.985f, 0.65f); // coordinates in SafeFullscreenRectangle, but DrawString works with SafeGuiRectangle.
     var posNamesBase = new Vector2(posValuesBase.X + namesOffset, posValuesBase.Y);
     var posValues = ConvertHudToNormalizedGuiPosition(ref posValuesBase);
     var posNames = ConvertHudToNormalizedGuiPosition(ref posNamesBase);
     info.Data.DrawBottomUp(posNames, posValues, m_textScale);
 }
Esempio n. 48
0
        private void DrawSuitInfo(MyHudCharacterInfo suitInfo)
        {
            MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            Color color = Color.White;
            var basePos = new Vector2(0.01f, 0.99f);
            var bgPos = ConvertHudToNormalizedGuiPosition(ref basePos);
            Vector2 namePos, valuePos, bgScale;
            MyGuiPaddedTexture bg;

            bg = MyGuiConstants.TEXTURE_HUD_BG_MEDIUM_DEFAULT;
            bgScale = new Vector2(1.1f, 1f);
            var bgWidth = (!MyHud.ShipInfo.Visible || MyUtils.IsZero(m_gravityHudWidth)) ? bg.SizeGui.X * bgScale.X : m_gravityHudWidth;
            MyGuiManager.DrawSpriteBatch(bg.Texture, bgPos, new Vector2(bgWidth, suitInfo.Data.GetGuiHeight()), Color.White, align);

            namePos = bgPos + new Vector2(1f, -1f) * bg.PaddingSizeGui * bgScale;
            valuePos = bgPos + (new Vector2(bgWidth, 0f) - bg.PaddingSizeGui);

            suitInfo.Data.DrawBottomUp(namePos, valuePos, m_textScale);
        }
Esempio n. 49
0
        private void DrawShipInfo(MyHudShipInfo info)
        {
            MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
            Color color = Color.White;
            Vector2 bgScale = new Vector2(1.2f, 1.05f);

            var bgPos = new Vector2(0.99f, 0.99f);
            bgPos = ConvertHudToNormalizedGuiPosition(ref bgPos);
            var bg = MyGuiConstants.TEXTURE_HUD_BG_LARGE_DEFAULT;
            MyGuiManager.DrawSpriteBatch(bg.Texture, bgPos, bg.SizeGui * bgScale, color, align);

            //float scale = MyGuiConstants.HUD_TEXT_SCALE;
            var valuePos = bgPos - bg.PaddingSizeGui * bgScale;
            var namePos = bgPos - bgScale * new Vector2(bg.SizeGui.X - bg.PaddingSizeGui.X, bg.PaddingSizeGui.Y);

            info.Data.DrawBottomUp(namePos, valuePos, m_textScale);
        }
Esempio n. 50
0
 internal MyVertexFormatTexcoordNormalTangentTexindices(Vector2 texcoord, Vector3 normal, Vector3 tangent, Byte4 texIndices)
 {
     Texcoord = new HalfVector2(texcoord.X, texcoord.Y);
     Normal = VF_Packer.PackNormalB4(ref normal);
     Vector4 T = new Vector4(tangent, 1);
     Tangent = VF_Packer.PackTangentSignB4(ref T);
     TexIndices = texIndices;
 }
Esempio n. 51
0
        /// <summary>
        /// Return position on middle screen based on real desired position on gamescreen.
        /// "Middle" make sense only for tripple monitors. For every else is middle screen all screen.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private static Vector2 GetRealPositionOnCenterScreen(Vector2 value)
        {
            Vector2 position;
            if (MyGuiManager.FullscreenHudEnabled)
                position = MyGuiManager.GetNormalizedCoordinateFromScreenCoordinate_FULLSCREEN(value);
            else
                position = MyGuiManager.GetNormalizedCoordinateFromScreenCoordinate(value);


            if (MyVideoSettingsManager.IsTripleHead())
                position.X += 1.0f;
            return position;
        }
Esempio n. 52
0
 internal MyVertexFormat2DPosition(Vector2 position)
 {
     Position = position;
 }
Esempio n. 53
0
 private void DrawNetgraphStringValue(Vector2 position, StringBuilder sb, float scale = 0.6f)
 {
     MyGuiManager.DrawString(MyFontEnum.White, sb, position, scale, null, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
 }
Esempio n. 54
0
 internal MyVertexFormatPosition2Texcoord(Vector2 position, Vector2 texcoord)
 {
     Position = position;
     Texcoord = texcoord;
 }
Esempio n. 55
0
        private void DrawNetgraphBasicStrings(MyHudNetgraph netgraph, Vector2 initialPosition, Vector2 normalizedOffset)
        {
            StringBuilder sb = new StringBuilder();

            // Draw last received packet         
            sb.Append("In: ").Append(netgraph.LastPacketBytesReceived);
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw average in
            sb.Clear();
            sb.Append("Avg In: ").Append(netgraph.AverageIncomingKBytes.ToString("0.##")).Append(" kB/s");
            initialPosition.X += normalizedOffset.X;
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw last sent packet
            sb.Clear();
            sb.Append("Out: ").Append(netgraph.LastPacketBytesSent);
            initialPosition.X -= normalizedOffset.X;
            initialPosition.Y += normalizedOffset.Y;
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw average out
            sb.Clear();
            sb.Append("Avg Out: ").Append(netgraph.AverageOutgoingKBytes.ToString("0.##")).Append(" kB/s");
            initialPosition.X += normalizedOffset.X;
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw updates per second
            sb.Clear();
            sb.Append("UPS: ").Append(netgraph.UpdatesPerSecond);
            initialPosition.X -= normalizedOffset.X;
            initialPosition.Y += normalizedOffset.Y;
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw frames per second
            sb.Clear();
            sb.Append("FPS: ").Append(netgraph.FramesPerSecond);
            initialPosition.X += normalizedOffset.X;
            DrawNetgraphStringValue(initialPosition, sb);

            // Draw latency
            sb.Clear();
            sb.Append("Ping: ").Append(netgraph.Ping);
            initialPosition.X -= normalizedOffset.X;
            initialPosition.Y += normalizedOffset.Y;
            DrawNetgraphStringValue(initialPosition, sb);
        }
        static void Gather()
        {
            // counting sorted billboards
            m_batches.Clear();
            m_sortedNum = 0;

            PreGatherList(MyRenderProxy.BillboardsRead);
            PreGatherList(m_billboardsOnce);

            m_sortedBillboardsNum = m_sortedNum;

            m_unsorted = 0;
            m_sorted = 0;

            GatherList(MyRenderProxy.BillboardsRead);
            GatherList(m_billboardsOnce);
            
            Array.Sort(m_sortBuffer, 0, m_sortedNum);
            //Array.Reverse(m_sortBuffer, 0, m_sortedNum);
            //Array.Sort(m_sortBuffer, m_sortedNum, m_unsorted);

            var N = m_sorted + m_unsorted;

            var batch = new MyBillboardBatch();
            //MyAssetTexture prevTexture = null;
            var prevTexId = TexId.NULL;
            int currentOffset = 0;

            if(N > 0)
            {
                var material = MyTransparentMaterials.GetMaterial(m_sortBuffer[0].Material);

                if(material.UseAtlas)
                {
                    var item = m_atlasedTextures[material.Texture];
                    prevTexId = item.TextureId;
                }
                else
                {
                    PreloadTexture(material.Texture);
                    //prevTexture = MyTextureManager.GetTextureFast(material.Texture);
                    prevTexId = MyTextures.GetTexture(material.Texture, MyTextureEnum.GUI, true);
                }
            }

            TexId batchTexId = TexId.NULL;
            MyTransparentMaterial prevMaterial = null;

            for(int i=0; i<N; i++)
            {
                var billboard = m_sortBuffer[i];
                var material = MyTransparentMaterials.GetMaterial(billboard.Material);

                var billboardData = new MyBillboardData();

                billboardData.CustomProjectionID = billboard.CustomViewProjection;
                billboardData.Color = billboard.Color;
                if (material.UseAtlas)
                {
                    var atlasItem = m_atlasedTextures[material.Texture];
                    //billboardData.UvModifiers = new HalfVector4(atlasItem.UvOffsetScale);
                    batchTexId = atlasItem.TextureId;
                }
                else
                {
                    batchTexId = MyTextures.GetTexture(material.Texture, MyTextureEnum.GUI, true);
                }

                billboardData.Reflective = billboard.Reflectivity;
                Vector3D pos0 = billboard.Position0;
                Vector3D pos1 = billboard.Position1;
                Vector3D pos2 = billboard.Position2;
                Vector3D pos3 = billboard.Position3;

                if (billboard.ParentID != -1)
                {
                    if (MyIDTracker<MyActor>.FindByID((uint)billboard.ParentID) != null)
                    {
                        var matrix = MyIDTracker<MyActor>.FindByID((uint)billboard.ParentID).WorldMatrix;
                        Vector3D.Transform(ref pos0, ref matrix, out pos0);
                        Vector3D.Transform(ref pos1, ref matrix, out pos1);
                        Vector3D.Transform(ref pos2, ref matrix, out pos2);
                        Vector3D.Transform(ref pos3, ref matrix, out pos3);
                    }
                }

                if (billboard.CustomViewProjection != -1)
                {
                    var billboardViewProjection = MyRenderProxy.BillboardsViewProjectionRead[billboard.CustomViewProjection];

                    //pos0 -= MyEnvironment.CameraPosition;
                    //pos1 -= MyEnvironment.CameraPosition;
                    //pos2 -= MyEnvironment.CameraPosition;
                    //pos3 -= MyEnvironment.CameraPosition;
                }
                else
                {
                    pos0 -= MyEnvironment.CameraPosition;
                    pos1 -= MyEnvironment.CameraPosition;
                    pos2 -= MyEnvironment.CameraPosition;
                    pos3 -= MyEnvironment.CameraPosition;
                }

                var normal = Vector3.Cross(pos1 - pos0, pos2 - pos0);
                normal.Normalize();

                billboardData.Normal = normal;

                m_vertexData[i * 4 + 0].Position = pos0;
                m_vertexData[i * 4 + 1].Position = pos1;
                m_vertexData[i * 4 + 2].Position = pos2;
                m_vertexData[i * 4 + 3].Position = pos3;

                var uv0 = new Vector2(material.UVOffset.X + billboard.UVOffset.X, material.UVOffset.Y + billboard.UVOffset.Y);
                var uv1 = new Vector2(material.UVOffset.X + material.UVSize.X + billboard.UVOffset.X, material.UVOffset.Y + billboard.UVOffset.Y);
                var uv2 = new Vector2(material.UVOffset.X + material.UVSize.X + billboard.UVOffset.X, material.UVOffset.Y + material.UVSize.Y + billboard.UVOffset.Y);
                var uv3 = new Vector2(material.UVOffset.X + billboard.UVOffset.X, material.UVOffset.Y + material.UVSize.Y + billboard.UVOffset.Y);

                if (material.UseAtlas)
                {
                    var atlasItem = m_atlasedTextures[material.Texture];

                    uv0 = uv0 * new Vector2(atlasItem.UvOffsetScale.Z, atlasItem.UvOffsetScale.W) + new Vector2(atlasItem.UvOffsetScale.X, atlasItem.UvOffsetScale.Y);
                    uv1 = uv1 * new Vector2(atlasItem.UvOffsetScale.Z, atlasItem.UvOffsetScale.W) + new Vector2(atlasItem.UvOffsetScale.X, atlasItem.UvOffsetScale.Y);
                    uv2 = uv2 * new Vector2(atlasItem.UvOffsetScale.Z, atlasItem.UvOffsetScale.W) + new Vector2(atlasItem.UvOffsetScale.X, atlasItem.UvOffsetScale.Y);
                    uv3 = uv3 * new Vector2(atlasItem.UvOffsetScale.Z, atlasItem.UvOffsetScale.W) + new Vector2(atlasItem.UvOffsetScale.X, atlasItem.UvOffsetScale.Y);
                }

                m_vertexData[i * 4 + 0].Texcoord = new HalfVector2(uv0);
                m_vertexData[i * 4 + 1].Texcoord = new HalfVector2(uv1);
                m_vertexData[i * 4 + 2].Texcoord = new HalfVector2(uv2);
                m_vertexData[i * 4 + 3].Texcoord = new HalfVector2(uv3);

                pos0.AssertIsValid();
                pos1.AssertIsValid();
                pos2.AssertIsValid();
                pos3.AssertIsValid();


                MyTriangleBillboard triBillboard = billboard as MyTriangleBillboard;
                if(triBillboard != null)
                {
                    m_vertexData[i * 4 + 3].Position = pos2; // second triangle will die in rasterizer

                    m_vertexData[i * 4 + 0].Texcoord = new HalfVector2(triBillboard.UV0); 
                    m_vertexData[i * 4 + 1].Texcoord = new HalfVector2(triBillboard.UV1);
                    m_vertexData[i * 4 + 2].Texcoord = new HalfVector2(triBillboard.UV2);

                    billboardData.Normal = triBillboard.Normal0; // pew pew pew :O
                }

                m_billboardData[i] = billboardData;

                bool closeBatch = (batchTexId != prevTexId) || ((i == m_sortedNum) && (i > 0));

                if(closeBatch)
                {
                    batch = new MyBillboardBatch();

                    batch.Offset = currentOffset;
                    batch.Num = i - currentOffset;
                    batch.Texture = prevTexId != TexId.NULL ? MyTextures.Views[prevTexId.Index] : null;

                    batch.Lit = prevMaterial.CanBeAffectedByOtherLights;

                    m_batches.Add(batch);
                    currentOffset = i;
                }

                prevTexId = batchTexId;
                prevMaterial = material;
            }

            if(N > 0)
            {
                batch = new MyBillboardBatch();
                batch.Offset = currentOffset;
                batch.Num = N - currentOffset;
                batch.Texture = prevTexId != TexId.NULL ? MyTextures.GetView(prevTexId) : null;

                batch.Lit = prevMaterial.CanBeAffectedByOtherLights;

                m_batches.Add(batch);
            }
        }
Esempio n. 57
0
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);

            m_toolbarControl = new MyGuiControlToolbar();
            m_toolbarControl.Position = new Vector2(0.5f, 0.99f);
            m_toolbarControl.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM;
            m_toolbarControl.IsActiveControl = false;
            Elements.Add(m_toolbarControl);
            m_textScale = MyGuiConstants.HUD_TEXT_SCALE * MyGuiManager.LanguageTextScale;

            var style = new MyGuiControlBlockInfo.MyControlBlockInfoStyle()
            {
                BlockNameLabelFont = MyFontEnum.White,
                EnableBlockTypeLabel = true,
                ComponentsLabelText = MySpaceTexts.HudBlockInfo_Components,
                ComponentsLabelFont = MyFontEnum.Blue,
                InstalledRequiredLabelText = MySpaceTexts.HudBlockInfo_Installed_Required,
                InstalledRequiredLabelFont = MyFontEnum.Blue,
                RequiredLabelText = MyCommonTexts.HudBlockInfo_Required,
                IntegrityLabelFont = MyFontEnum.White,
                IntegrityBackgroundColor = new Vector4(78 / 255.0f, 116 / 255.0f, 137 / 255.0f, 1.0f),
                IntegrityForegroundColor = new Vector4(0.5f, 0.1f, 0.1f, 1),
                IntegrityForegroundColorOverCritical = new Vector4(118 / 255.0f, 166 / 255.0f, 192 / 255.0f, 1.0f),
                LeftColumnBackgroundColor = new Vector4(46 / 255.0f, 76 / 255.0f, 94 / 255.0f, 1.0f),
                TitleBackgroundColor = new Vector4(72 / 255.0f, 109 / 255.0f, 130 / 255.0f, 1.0f),
                ComponentLineMissingFont = MyFontEnum.Red,
                ComponentLineAllMountedFont = MyFontEnum.White,
                ComponentLineAllInstalledFont = MyFontEnum.Blue,
                ComponentLineDefaultFont = MyFontEnum.White,
                ComponentLineDefaultColor = new Vector4(0.6f, 0.6f, 0.6f, 1f),
                ShowAvailableComponents = false,
                EnableBlockTypePanel = true,
            };
            m_blockInfo = new MyGuiControlBlockInfo(style);
            m_blockInfo.IsActiveControl = false;
            Controls.Add(m_blockInfo);

            m_questlogControl = new MyGuiControlQuestlog(new Vector2(20f, 20f));
            m_questlogControl.IsActiveControl = false;
            m_questlogControl.RecreateControls();
            Controls.Add(m_questlogControl);

            m_chatControl = new MyHudControlChat(MyHud.Chat, Vector2.Zero, new Vector2(0.4f, 0.28f), visibleLinesCount: 12);
            Elements.Add(m_chatControl);

            m_cameraInfoMultilineControl = new MyGuiControlMultilineText(
                position: Vector2.Zero,
                size: new Vector2(0.4f, 0.25f),
                backgroundColor: null,
                font: MyFontEnum.White,
                textScale: 0.7f,
                textAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM,
                contents: null,
                drawScrollbar: false,
                textBoxAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM);
            m_cameraInfoMultilineControl.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            Elements.Add(m_cameraInfoMultilineControl);

            m_rotatingWheelControl = new MyGuiControlRotatingWheel(position: new Vector2(0.5f, 0.85f));

            Controls.Add(m_rotatingWheelControl);

            Vector2 buildModePosition = new Vector2(0.5f, 0.02f);
            buildModePosition = MyGuiScreenHudBase.ConvertHudToNormalizedGuiPosition(ref buildModePosition);
            m_buildModeLabel = new MyGuiControlLabel(
                position: buildModePosition,
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                font: MyFontEnum.White,
                text: MyTexts.GetString(MyCommonTexts.Hud_BuildMode));
            Controls.Add(m_buildModeLabel);

            m_blocksLeft = new MyGuiControlLabel(
                position: new Vector2(0.238f, 0.89f),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM,
                font: MyFontEnum.White,
                text: MyHud.BlocksLeft.GetStringBuilder().ToString()
                );
            Controls.Add(m_blocksLeft);

            m_relayNotification = new MyGuiControlLabel(new Vector2(1, 0), font: MyFontEnum.White, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP);
            m_relayNotification.TextEnum = MyCommonTexts.Multiplayer_IndirectConnection;
            m_relayNotification.Visible = false;
            Controls.Add(m_relayNotification);
            var offset = new Vector2(0, m_relayNotification.Size.Y);
            m_noMsgSentNotification = new MyGuiControlLabel(new Vector2(1, 0) + offset, font: MyFontEnum.Debug, text: MyTexts.GetString(MyCommonTexts.Multiplayer_LastMsg), originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP);
            m_noMsgSentNotification.Visible = false;
            Controls.Add(m_noMsgSentNotification);
            offset += new Vector2(0, m_noMsgSentNotification.Size.Y);
            m_noConnectionNotification = new MyGuiControlLabel(new Vector2(1, 0) + offset, font: MyFontEnum.Red, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP);
            m_noConnectionNotification.TextEnum = MyCommonTexts.Multiplayer_NoConnection;
            m_noConnectionNotification.Visible = false;
            Controls.Add(m_noConnectionNotification);

            m_serverSavingNotification = new MyGuiControlLabel(new Vector2(1, 0) + offset, font: MyFontEnum.White, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP);
            m_serverSavingNotification.TextEnum = MyCommonTexts.SavingPleaseWait;
            m_serverSavingNotification.Visible = false;
            Controls.Add(m_serverSavingNotification);

            MyHud.ReloadTexts();
        }
 public static void CreateBillboard(VRageRender.MyBillboard billboard, ref MyQuadD quad, string material,
     ref Color color, ref Vector3D origin, Vector2 uvOffset, bool colorize = false, bool near = false, bool lowres = false)
 {
     Debug.Assert(material != null);
     CreateBillboard(billboard, ref quad, material, null, 0, ref color, ref origin, uvOffset, colorize, near, lowres);
 }
        //  This method is like a constructor (which we can't use because billboards are allocated from a pool).
        //  It starts/initializes a billboard. Refs used only for optimalization
        public static void CreateBillboard(VRageRender.MyBillboard billboard, ref MyQuadD quad, string material, string blendMaterial, float textureBlendRatio,
            ref Color color, ref Vector3D origin, Vector2 uvOffset, bool colorize = false, bool near = false, bool lowres = false, float reflectivity = 0)
        {
            Debug.Assert(material != null);
            
            if (string.IsNullOrEmpty(material) || !MyTransparentMaterials.ContainsMaterial(material))
            {
                material = "ErrorMaterial";
                color = Vector4.One;
            }

            billboard.Material = material;
            billboard.BlendMaterial = blendMaterial;
            billboard.BlendTextureRatio = textureBlendRatio;

            quad.Point0.AssertIsValid();
            quad.Point1.AssertIsValid();
            quad.Point2.AssertIsValid();
            quad.Point3.AssertIsValid();


            //  Billboard vertexes
            billboard.Position0 = quad.Point0;
            billboard.Position1 = quad.Point1;
            billboard.Position2 = quad.Point2;
            billboard.Position3 = quad.Point3;

            billboard.UVOffset = uvOffset;

            EnableColorize = colorize;

            if (EnableColorize)
                billboard.Size = (float)(billboard.Position0 - billboard.Position2).Length();

            //  Distance for sorting
            //  IMPORTANT: Must be calculated before we do color and alpha misting, because we need distance there
            billboard.DistanceSquared = (float)Vector3D.DistanceSquared(MyRenderCamera.Position, origin);

            //  Color
            billboard.Color = color;
            billboard.ColorIntensity = 1;
            billboard.Reflectivity = reflectivity;

            billboard.Near = near;
            billboard.Lowres = lowres;
            billboard.ParentID = -1;

            //  Alpha depends on distance to camera. Very close bilboards are more transparent, so player won't see billboard errors or rotating billboards
            var mat = MyTransparentMaterials.GetMaterial(billboard.Material);
            if (mat.AlphaMistingEnable)
                billboard.Color *= MathHelper.Clamp(((float)Math.Sqrt(billboard.DistanceSquared) - mat.AlphaMistingStart) / (mat.AlphaMistingEnd - mat.AlphaMistingStart), 0, 1);

            billboard.Color *= mat.Color;

            billboard.ContainedBillboards.Clear();
        }
Esempio n. 60
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);
            }
        }