public void RenderText( IRenderContext context, IEffect effect, IEffectParameterSet effectParameterSet, Matrix matrix, string text, FontAsset font, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Color?textColor, bool renderShadow, Color?shadowColor) { if (!context.IsCurrentRenderPass <I3DRenderPass>()) { throw new InvalidOperationException("Can't use 3D rendering utilities in 2D context."); } var targets = context.GraphicsDevice.GetRenderTargets(); var size = MeasureText(context, text, font); var temporary = new RenderTarget2D( context.GraphicsDevice, (int)size.X, (int)size.Y, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.DiscardContents); context.GraphicsDevice.SetRenderTarget(temporary); context.GraphicsDevice.Clear(Color.Transparent); using (var spriteBatch = new SpriteBatch(context.GraphicsDevice)) { _twoDimensionalRenderUtilities.RenderText( context, new Vector2(0, 0), text, font, HorizontalAlignment.Left, VerticalAlignment.Top, textColor, renderShadow, shadowColor); spriteBatch.End(); } var texture = (Texture2D)temporary; context.GraphicsDevice.SetRenderTarget(null); context.GraphicsDevice.BlendState = BlendState.Opaque; context.GraphicsDevice.DepthStencilState = DepthStencilState.Default; context.GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; context.GraphicsDevice.RasterizerState = RasterizerState.CullNone; RenderTexture(context, effect, effectParameterSet, matrix, texture, Color.White, flipHorizontally: false, flipVertically: false); }
public void RenderText(IRenderContext context, IEffect effect, IEffectParameterSet effectParameterSet, Matrix matrix, string text, FontAsset font, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left, VerticalAlignment verticalAlignment = VerticalAlignment.Top, Color?textColor = null, bool renderShadow = true, Color?shadowColor = null) { throw new NotSupportedException(); }
public PhysicsMetricsProfilerVisualiser( IAssetManagerProvider assetManagerProvider, I2DRenderUtilities renderUtilities, IPhysicsEngine physicsEngine) { _renderUtilities = renderUtilities; _physicsEngine = physicsEngine; _defaultFont = assetManagerProvider.GetAssetManager().Get <FontAsset>("font.Default"); }
public NetworkSampler(I2DRenderUtilities renderUtilities, FontAsset defaultFont, string type) { _renderUtilities = renderUtilities; _defaultFont = defaultFont; Type = type; _bytesOverTime = new List <int>(); _countsOverTime = new List <int>(); }
public BasicLabelSkinRenderer( I2DRenderUtilities renderUtilities, IAssetManagerProvider assetManagerProvider, ILayoutPosition layoutPosition) { _renderUtilities = renderUtilities; _layoutPosition = layoutPosition; _fontAsset = assetManagerProvider.GetAssetManager().Get <FontAsset>("font.Default"); }
public KernelMetricsProfilerVisualiser( IKernel kernel, IHierarchy hierachy, IAssetManagerProvider assetManagerProvider, I2DRenderUtilities renderUtilities) { _kernel = kernel; _hierachy = hierachy; _renderUtilities = renderUtilities; _defaultFont = assetManagerProvider.GetAssetManager().Get <FontAsset>("font.Default"); }
public NetworkTrafficProfilerVisualiser( IAssetManagerProvider assetManagerProvider, INetworkEngine networkEngine, I2DRenderUtilities renderUtilities) { _defaultFont = assetManagerProvider.GetAssetManager().Get <FontAsset>("font.Default"); _networkEngine = networkEngine; _renderUtilities = renderUtilities; _sentSampler = new NetworkSampler(_renderUtilities, _defaultFont, "SENT"); _receivedSampler = new NetworkSampler(_renderUtilities, _defaultFont, "RECV"); }
public GraphicsMetricsProfilerVisualiser( IAssetManagerProvider assetManagerProvider, I2DRenderUtilities renderUtilities, IRenderCache renderCache, IRenderAutoCache renderAutoCache, IRenderBatcher renderBatcher) { _renderUtilities = renderUtilities; _renderCache = renderCache; _renderAutoCache = renderAutoCache; _renderBatcher = renderBatcher; _defaultFont = assetManagerProvider.GetAssetManager().Get <FontAsset>("font.Default"); }
public void Render(IGameContext gameContext, IRenderContext renderContext) { if (_renderUtilities == null) { _renderUtilities = _kernel.Get <I2DRenderUtilities>(); } if (_assetManager == null) { _assetManager = _kernel.Get <IAssetManagerProvider>().GetAssetManager(); } if (_defaultFont == null) { _defaultFont = _assetManager.Get <FontAsset>("font.Default"); } if (renderContext.IsCurrentRenderPass <I2DBatchedLoadingScreenRenderPass>()) { var bounds = renderContext.GraphicsDevice.PresentationParameters.Bounds; _renderUtilities.RenderRectangle( renderContext, bounds, new Color(0x33, 0x33, 0x33, 0xFF), true); _renderUtilities.RenderText( renderContext, new Vector2(bounds.Width - 20, bounds.Height - 20), "Loading...", _defaultFont, HorizontalAlignment.Right, VerticalAlignment.Bottom, Color.White, true, Color.Black); _renderUtilities.RenderText( renderContext, new Vector2(20, bounds.Height - 20), "Made with Protogame (protogame.org)", _defaultFont, HorizontalAlignment.Left, VerticalAlignment.Bottom, new Color(0x66, 0x66, 0x66, 0xFF), false, Color.Black); } }
/// <summary> /// The render. /// </summary> /// <param name="gameContext"> /// The game context. /// </param> /// <param name="renderContext"> /// The render context. /// </param> public void Render(IGameContext gameContext, IRenderContext renderContext) { if (this.m_DefaultFontAsset == null) { this.m_DefaultFontAsset = this.m_AssetManagerProvider.GetAssetManager().Get <FontAsset>("font.Default"); } if (!this.Open || renderContext.Is3DContext) { return; } this.m_2DRenderUtilities.RenderRectangle( renderContext, new Rectangle(0, 0, gameContext.Window.ClientBounds.Width, 300), new Color(0, 0, 0, 210), true); this.m_2DRenderUtilities.RenderRectangle( renderContext, new Rectangle(0, 0, gameContext.Window.ClientBounds.Width - 1, 300), Color.White); this.m_2DRenderUtilities.RenderLine( renderContext, new Vector2(0, 300 - 16), new Vector2(gameContext.Window.ClientBounds.Width, 300 - 16), Color.White); this.m_2DRenderUtilities.RenderText( renderContext, new Vector2(2, 300 - 16), this.m_Input.ToString(), this.m_DefaultFontAsset); var a = 0; for (var i = Math.Max(0, this.m_Log.Count - 30); i < this.m_Log.Count; i++) { this.m_2DRenderUtilities.RenderText( renderContext, new Vector2(2, 300 - 32 - a * 16), this.m_Log[this.m_Log.Count - i - 1], this.m_DefaultFontAsset); a++; } if (this.m_Log.Count > 31) { this.m_Log.RemoveRange(0, this.m_Log.Count - 31); } }
public OperationCostProfilerVisualiser( IAssetManagerProvider assetManagerProvider, I2DRenderUtilities renderUtilities, IMemoryProfiler memoryProfiler) { _defaultFont = assetManagerProvider.GetAssetManager().Get <FontAsset>("font.Default"); _renderUtilities = renderUtilities; _memoryProfiler = memoryProfiler; _averageOverTimePeriod = new Dictionary <string, double>(); _historyOverTimePeriod = new Dictionary <string, List <double> >(); _lastFrameToHaveData = new Dictionary <string, int>(); _maximumOverTimePeriod = new Dictionary <string, double>(); MicrosecondLimit = 14000; FramesToAnalyse = 240; }
public Vector2 MeasureText(IRenderContext context, string text, FontAsset font) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (string.IsNullOrWhiteSpace(text)) { return(new Vector2(0, 0)); } if (font == null) { throw new ArgumentNullException(nameof(font)); } return(font.Font.MeasureString(_stringSanitizer.SanitizeCharacters(font.Font, text))); }
public GCMetricsProfilerVisualiser( IAssetManagerProvider assetManagerProvider, I2DRenderUtilities renderUtilities) { _renderUtilities = renderUtilities; _defaultFont = assetManagerProvider.GetAssetManager().Get <FontAsset>("font.Default"); #if PLATFORM_WINDOWS || PLATFORM_MACOS || PLATFORM_LINUX string instanceName; if (TryGetInstanceName(Process.GetCurrentProcess(), out instanceName)) { _gen0PerformanceCounter = new PerformanceCounter(".NET CLR Memory", "# Gen 0 Collections", instanceName, true); _gen1PerformanceCounter = new PerformanceCounter(".NET CLR Memory", "# Gen 1 Collections", instanceName, true); _gen2PerformanceCounter = new PerformanceCounter(".NET CLR Memory", "# Gen 2 Collections", instanceName, true); } #endif }
public DefaultColorInImageDetectionDebugRenderer(IAssetManager assetManager, I2DRenderUtilities renderUtilities) { _renderUtilities = renderUtilities; _defaultFont = assetManager.Get <FontAsset>("font.Default"); }
/// <summary> /// The measure text. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="text"> /// The text. /// </param> /// <param name="font"> /// The font. /// </param> /// <returns> /// The <see cref="Vector2"/>. /// </returns> public Vector2 MeasureText(IRenderContext context, string text, FontAsset font) { return(this.m_2DRenderUtilities.MeasureText(context, text, font)); }
public void RenderText(IRenderContext context, Vector2 position, string text, FontAsset font, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left, VerticalAlignment verticalAlignment = VerticalAlignment.Top, Color?textColor = null, bool renderShadow = true, Color?shadowColor = null) { throw new NotSupportedException(); }
public BasicLinkSkinRenderer(I2DRenderUtilities renderUtilities, IAssetManagerProvider assetManagerProvider) { _renderUtilities = renderUtilities; _fontAsset = assetManagerProvider.GetAssetManager().Get <FontAsset>("font.Default"); }
public Vector2 MeasureText(IRenderContext context, string text, FontAsset font) { throw new NotSupportedException(); }
public BasicMenuItemSkinRenderer(IBasicSkinHelper basicSkinHelper, I2DRenderUtilities renderUtilities, IAssetManagerProvider assetManagerProvider) { _basicSkinHelper = basicSkinHelper; _renderUtilities = renderUtilities; _fontAsset = assetManagerProvider.GetAssetManager().Get <FontAsset>("font.Default"); }
public void RenderText( IRenderContext context, Vector2 position, string text, FontAsset font, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left, VerticalAlignment verticalAlignment = VerticalAlignment.Top, Color?textColor = null, bool renderShadow = true, Color?shadowColor = null) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (string.IsNullOrWhiteSpace(text)) { return; } if (font == null) { throw new ArgumentNullException(nameof(font)); } if (textColor == null) { textColor = Color.White; } if (shadowColor == null) { shadowColor = Color.Black; } if (font.Font == null) { throw new AssetNotCompiledException(font.Name); } // Sanitize the text. text = _stringSanitizer.SanitizeCharacters(font.Font, text); // Determine position to draw. var size = font.Font.MeasureString(text); float xx = 0, yy = 0; switch (horizontalAlignment) { case HorizontalAlignment.Left: xx = position.X; break; case HorizontalAlignment.Center: xx = position.X - (size.X / 2); break; case HorizontalAlignment.Right: xx = position.X - size.X; break; } switch (verticalAlignment) { case VerticalAlignment.Top: yy = position.Y; break; case VerticalAlignment.Center: yy = position.Y - (size.Y / 2); break; case VerticalAlignment.Bottom: yy = position.Y - size.Y; break; } // Normalize location to prevent blurring artifacts. xx = (int)xx; yy = (int)yy; // Draw shadow if required. if (renderShadow) { context.SpriteBatch.DrawString(font.Font, text, new Vector2(xx + 1, yy + 1), shadowColor.Value); } // Render the main text. context.SpriteBatch.DrawString(font.Font, text, new Vector2(xx, yy), textColor.Value); }
public Vector2 MeasureText(IRenderContext context, string text, FontAsset font) { return(_twoDimensionalRenderUtilities.MeasureText(context, text, font)); }
public void Render(IGameContext gameContext, IRenderContext renderContext, StringBuilder inputBuffer, ConsoleState state, List <Tuple <ConsoleLogLevel, string> > logEntries) { if (_fontAsset == null) { _fontAsset = _assetManagerProvider.GetAssetManager().Get <FontAsset>("font.Console"); } if (renderContext.IsCurrentRenderPass <I3DRenderPass>()) { return; } var h = 0; if (state == ConsoleState.Open || state == ConsoleState.OpenNoInput) { h = 300; } else if (state == ConsoleState.FullOpen || state == ConsoleState.FullOpenNoInput) { h = gameContext.Window.ClientBounds.Height; } _renderUtilities.RenderRectangle( renderContext, new Rectangle(0, 0, gameContext.Window.ClientBounds.Width, h), new Color(0, 0, 0, 210), true); _renderUtilities.RenderRectangle( renderContext, new Rectangle(0, 0, gameContext.Window.ClientBounds.Width - 1, h - 1), Color.White); var o = 16; if (state == ConsoleState.FullOpen || state == ConsoleState.Open) { _renderUtilities.RenderLine( renderContext, new Vector2(0, h - 16), new Vector2(gameContext.Window.ClientBounds.Width, h - 16), Color.White); _renderUtilities.RenderText( renderContext, new Vector2(2, h - 16), inputBuffer.ToString(), _fontAsset); o = 32; } var a = 0; for (var i = Math.Max(0, logEntries.Count - 30); i < logEntries.Count; i++) { var color = Color.White; switch (logEntries[logEntries.Count - i - 1].Item1) { case ConsoleLogLevel.Debug: color = Color.White; break; case ConsoleLogLevel.Info: color = Color.Cyan; break; case ConsoleLogLevel.Warning: color = Color.Orange; break; case ConsoleLogLevel.Error: color = Color.Red; break; } _renderUtilities.RenderText( renderContext, new Vector2(2, h - o - a * 16), logEntries[logEntries.Count - i - 1].Item2, _fontAsset, textColor: color); a++; } }