Space Engineers
MyRenderStats.cs
Go to the documentation of this file.
2 using System.Text;
3 using VRage.Library.Utils;
4 using VRage.Render11.Common;
5 using VRage.Stats;
6 using VRageMath;
8 using VRageRender.Utils;
9 
10 namespace VRageRender
11 {
15  public static class MyRenderStatsDraw
16  {
17  static float m_rightGapSizeRatio = 0.1f;
18  static float m_rightColumnWidth;
19  static MyTimeSpan m_rightColumnChangeTime = MyRender11.CurrentDrawTime;
20 
21  static StringBuilder m_tmpDrawText = new StringBuilder(4096);
22 
23  public static void Draw(Dictionary<MyRenderStats.ColumnEnum, List<MyStats>> m_stats, float scale, Color color)
24  {
25  foreach (var pair in m_stats)
26  {
27  try
28  {
29  foreach (var s in pair.Value)
30  {
31  s.WriteTo(m_tmpDrawText);
32  m_tmpDrawText.AppendLine(); // Newline between each group
33  }
34 
35  Vector2 pos = new Vector2(10, 10);
36 
37  if (pair.Key == MyRenderStats.ColumnEnum.Right)
38  {
39  Vector2 size = MyRender11.GetDebugFont().MeasureString(m_tmpDrawText, scale);
40  if (m_rightColumnWidth < size.X)
41  {
42  m_rightColumnWidth = size.X * m_rightGapSizeRatio; // Add some gap
43  m_rightColumnChangeTime = MyRender11.CurrentDrawTime;
44  }
45  else if (m_rightColumnWidth > size.X * m_rightGapSizeRatio && (MyRender11.CurrentDrawTime - m_rightColumnChangeTime).Seconds > 3)
46  {
47  m_rightColumnWidth = size.X * m_rightGapSizeRatio;
48  m_rightColumnChangeTime = MyRender11.CurrentDrawTime;
49  }
50  pos = new Vector2(MyRender11.ViewportResolution.X - m_rightColumnWidth, 0);
51  }
52 
53  MyDebugTextHelpers.DrawText(pos, m_tmpDrawText, color, scale);
54  }
55  finally
56  {
57  m_tmpDrawText.Clear();
58  }
59  }
60  }
61  }
62 }
VRageMath.Vector2 Vector2
float X
Gets or sets the x-component of the vector.
Definition: Vector2.cs:23
Hi-resolution time span. Beware: the resolution can be different on different systems! ...
Definition: MyTimeSpan.cs:8