/// <summary> /// Processes a container from the control host. /// </summary> /// <param name="controlContainer">The container.</param> /// <param name="renderer">The renderer used with this step.</param> /// <param name="screenObject">The screen surface with font information.</param> protected void ProcessContainer(UI.Controls.IContainer controlContainer, ScreenSurfaceRenderer renderer, IScreenSurface screenObject) { foreach (UI.Controls.ControlBase control in controlContainer) { if (!control.IsVisible) { continue; } RenderControlCells(control, renderer, screenObject.Font, screenObject.FontSize, screenObject.Surface.View, screenObject.Surface.Width); if (control is UI.Controls.IContainer container) { ProcessContainer(container, renderer, screenObject); } } }
/// <summary> /// Renders the cells of a control. /// </summary> /// <param name="control">The control.</param> /// <param name="renderer">The renderer used with this step.</param> /// <param name="font">The font to render the cells with.</param> /// <param name="fontSize">The size of a cell in pixels.</param> /// <param name="parentViewRect">The view of the parent to cull cells from.</param> /// <param name="bufferWidth">The width of the parent used to calculate the render rect.</param> protected void RenderControlCells(UI.Controls.ControlBase control, ScreenSurfaceRenderer renderer, IFont font, Point fontSize, Rectangle parentViewRect, int bufferWidth) { font = control.AlternateFont ?? font; ColoredGlyph cell; //if (control.Surface.DefaultBackground.A != 0) //{ // (int x, int y) = (control.AbsolutePosition - parentViewRect.Position).SurfaceLocationToPixel(fontSize); // (int width, int height) = new Point(control.Surface.View.Width, control.Surface.View.Height) * fontSize; // Host.Global.SharedSpriteBatch.DrawQuad(new IntRect(x, y, x + width, y + height), font.SolidGlyphRectangle.ToIntRect(), control.Surface.DefaultBackground.ToSFMLColor(), ((SadConsole.Host.GameTexture)font.Image).Texture); //} for (int y = 0; y < control.Surface.View.Height; y++) { int i = ((y + control.Surface.ViewPosition.Y) * control.Surface.Width) + control.Surface.ViewPosition.X; for (int x = 0; x < control.Surface.View.Width; x++) { cell = control.Surface[i]; cell.IsDirty = false; if (cell.IsVisible) { SadRogue.Primitives.Point cellRenderPosition = control.AbsolutePosition + (x, y); if (!parentViewRect.Contains(cellRenderPosition)) { continue; } IntRect renderRect = renderer.CachedRenderRects[(cellRenderPosition - parentViewRect.Position).ToIndex(bufferWidth)]; Host.Global.SharedSpriteBatch.DrawCell(cell, renderRect, true, font); } i++; } } }
/// <summary> /// Renders the cells of a control. /// </summary> /// <param name="control">The control.</param> /// <param name="renderer">The renderer used with this step.</param> /// <param name="font">The font to render the cells with.</param> /// <param name="fontSize">The size of a cell in pixels.</param> /// <param name="parentViewRect">The view of the parent to cull cells from.</param> /// <param name="bufferWidth">The width of the parent used to calculate the render rect.</param> protected void RenderControlCells(SadConsole.UI.Controls.ControlBase control, ScreenSurfaceRenderer renderer, IFont font, SadRogue.Primitives.Point fontSize, SadRectangle parentViewRect, int bufferWidth) { font = control.AlternateFont ?? font; var fontImage = ((SadConsole.Host.GameTexture)font.Image).Texture; ColoredGlyph cell; for (int y = 0; y < control.Surface.View.Height; y++) { int i = ((y + control.Surface.ViewPosition.Y) * control.Surface.Width) + control.Surface.ViewPosition.X; for (int x = 0; x < control.Surface.View.Width; x++) { cell = control.Surface[i]; cell.IsDirty = false; if (cell.IsVisible) { SadRogue.Primitives.Point cellRenderPosition = control.AbsolutePosition + (x, y); if (!parentViewRect.Contains(cellRenderPosition)) { continue; } XnaRectangle renderRect = renderer.CachedRenderRects[(cellRenderPosition - parentViewRect.Position).ToIndex(bufferWidth)]; if (cell.Background != SadRogue.Primitives.Color.Transparent) { Host.Global.SharedSpriteBatch.Draw(fontImage, renderRect, font.SolidGlyphRectangle.ToMonoRectangle(), cell.Background.ToMonoColor(), 0f, Vector2.Zero, SpriteEffects.None, 0.3f); } if (cell.Foreground != SadRogue.Primitives.Color.Transparent) { Host.Global.SharedSpriteBatch.Draw(fontImage, renderRect, font.GetGlyphSourceRectangle(cell.Glyph).ToMonoRectangle(), cell.Foreground.ToMonoColor(), 0f, Vector2.Zero, cell.Mirror.ToMonoGame(), 0.4f); } foreach (CellDecorator decorator in cell.Decorators) { if (decorator.Color != SadRogue.Primitives.Color.Transparent) { Host.Global.SharedSpriteBatch.Draw(fontImage, renderRect, font.GetGlyphSourceRectangle(decorator.Glyph).ToMonoRectangle(), decorator.Color.ToMonoColor(), 0f, Vector2.Zero, decorator.Mirror.ToMonoGame(), 0.5f); } } } i++; } } }