/// <summary> /// Updates the overlay to the provided time. /// </summary> public void Update(JulianDate time) { if (m_textOverlay.Texture != null) { m_textOverlay.Texture.Dispose(); } string text = string.Concat("Time: ", time.ToTimeStandard(TimeStandard.CoordinatedUniversalTime).ToGregorianDate().ToString("MMM d, yyyy hh:mm:ss"), " UTCG\n", m_evaluator.Evaluate(time)); // measure the actual text and resize the overlays to match Size textSize = Insight3DHelper.MeasureString(text, m_font); m_textOverlay.Size = new ScreenOverlaySize(textSize.Width, textSize.Height); m_overlay.Size = m_textOverlay.Size; // Draw the text to a bitmap, create a texture and use that texture as the overlay. using (var textBitmap = new Bitmap(textSize.Width, textSize.Height)) using (var graphics = Graphics.FromImage(textBitmap)) { graphics.DrawString(text, m_font, Brushes.White, new PointF(0, 0)); m_textOverlay.Texture = SceneManager.Textures.FromBitmap(textBitmap); } }
/// <summary> /// Update the number of satellites on the text panel /// </summary> private void SetText(int number) { if (m_textOverlay != null) { m_textPanel.Overlays.Remove(m_textOverlay); m_textOverlay = null; } Font font = new Font("Arial", 10, FontStyle.Bold); string text = "Satellites:\n" + number; Size textSize = Insight3DHelper.MeasureString(text, font); Bitmap textBitmap = new Bitmap(textSize.Width, textSize.Height); Graphics gfx = Graphics.FromImage(textBitmap); gfx.DrawString(text, font, Brushes.Black, new PointF(0, 0)); m_textOverlay = new TextureScreenOverlay(0, 0, textSize.Width, textSize.Height) { Origin = ScreenOverlayOrigin.Center, Texture = SceneManager.Textures.FromBitmap(textBitmap) }; m_textPanel.Overlays.Add(m_textOverlay); }