/// <summary> /// Updates the cache based on the <paramref name="source"/> surface. /// </summary> /// <param name="source">The surface to render and cache.</param> public void Update(ITextSurfaceRendered source) { #if SFML if (renderedConsole != null && renderedConsole.Size.X != (uint)source.AbsoluteArea.Width && renderedConsole.Size.Y != (uint)source.AbsoluteArea.Height) { renderedConsole.Dispose(); renderedConsole = new RenderTexture((uint)source.AbsoluteArea.Width, (uint)source.AbsoluteArea.Height, false); } else if (renderedConsole == null) { renderedConsole = new RenderTexture((uint)source.AbsoluteArea.Width, (uint)source.AbsoluteArea.Height, false); } renderedConsole.Clear(Color.Transparent); TextSurfaceRenderer renderer = new TextSurfaceRenderer(); //renderer.CallBatchEnd = false; //renderer.AfterRenderCallback = (batch) => batch.End(renderedConsole, RenderStates.Default); renderer.AlternativeRenderTarget = renderedConsole; renderer.Render(source, new Vector2i(0, 0)); renderedConsole.Display(); #elif MONOGAME if (renderedConsole != null) { renderedConsole.Dispose(); } renderedConsole = new RenderTarget2D(Engine.Device, source.AbsoluteArea.Width, source.AbsoluteArea.Height, false, Engine.Device.DisplayMode.Format, DepthFormat.Depth24); Engine.Device.SetRenderTarget(renderedConsole); Engine.Device.Clear(Color.Transparent); TextSurfaceRenderer renderer = new TextSurfaceRenderer(); renderer.Render(source, new Point(0, 0)); Engine.RestoreRenderTarget(); #endif }
/// <summary> /// Creates a new surface view from an existing surface. /// </summary> /// <param name="surface">The source cell data.</param> /// <param name="area">The area of the text surface.</param> public TextSurfaceView(ITextSurfaceRendered surface, Rectangle area) : base(area.Width, area.Height, surface.Font) { data = surface; DefaultBackground = surface.DefaultBackground; DefaultForeground = surface.DefaultForeground; base.font = surface.Font; base.width = surface.Width; base.height = surface.Height; this.originalArea = area; this.cells = data.Cells; base.width = area.Width; base.height = area.Height; RenderRects = new Rectangle[area.Width * area.Height]; RenderCells = new Cell[area.Width * area.Height]; int index = 0; for (int y = 0; y < area.Height; y++) { for (int x = 0; x < area.Width; x++) { RenderRects[index] = Font.GetRenderRect(x, y); RenderCells[index] = base.cells[(y + area.Top) * surface.Width + (x + area.Left)]; index++; } } cells = RenderCells; AbsoluteArea = new Rectangle(0, 0, area.Width * Font.Size.X, area.Height * Font.Size.Y); }
/// <summary> /// Loads a <see cref="TextSurfaceView"/> from a file and existing <see cref="ITextSurfaceRendered"/>. /// </summary> /// <param name="file">The source file.</param> /// <param name="surfaceHydrate">The surface this view was originally from.</param> /// <returns>A surface view.</returns> public static TextSurfaceView Load(string file, ITextSurfaceRendered surfaceHydrate) { TextSurfaceView surface = Serializer.Load <TextSurfaceView>(file); surface.Hydrate(surfaceHydrate); return(surface); }
public override void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { if (surface.Tint.A != 255) { Cell cell; if (surface.DefaultBackground.A != 0) { Batch.DrawQuad(surface.AbsoluteArea, surface.Font.SolidGlyphRectangle, surface.DefaultBackground, surface.Font.FontImage); } for (int i = 0; i < surface.RenderCells.Length; i++) { cell = surface.RenderCells[i]; if (cell.IsVisible) { Batch.DrawCell(cell, surface.RenderRects[i], surface.Font.SolidGlyphRectangle, surface.DefaultBackground, surface.Font); } } } if (surface.Tint.A != 0) { Batch.DrawQuad(surface.AbsoluteArea, surface.Font.SolidGlyphRectangle, surface.Tint, surface.Font.FontImage); } }
/// <summary> /// Renders the cached surface from a previous call to the constructor or the <see cref="Update(ITextSurfaceRendered)"/> method. /// </summary> /// <param name="surface">Only used for tinting and calculation the position from the font.</param> /// <param name="position">Calculates the rendering position on the screen based on the size of the <paramref name="surface"/> parameter.</param> /// <param name="usePixelPositioning">Ignores the <paramref name="surface"/> font for positioning and instead treats the <paramref name="position"/> parameter in pixels.</param> public void Render(ITextSurfaceRendered surface, Point position, bool usePixelPositioning = false) { Matrix matrix; if (usePixelPositioning) { //if (oldAbsolutePosition != position) //{ // absolutePositionTransform = GetPositionTransform(position, surface.Font.Size, true); // oldAbsolutePosition = position; //} //matrix = absolutePositionTransform; matrix = GetPositionTransform(position, surface.Font.Size, true); } else { //if (position != oldPosition) //{ // positionTransform = GetPositionTransform(position, surface.Font.Size, false); // oldPosition = position; //} //matrix = positionTransform; matrix = GetPositionTransform(position, surface.Font.Size, false); } Render(surface, matrix); }
public MapData(int width, int height, ITextSurfaceRendered textSurface) { this.width = width; this.height = height; this.textSurface = textSurface; mapData = new MapObjectBase[width, height]; }
/// <summary> /// Creates a new surface view from an existing surface. /// </summary> /// <param name="surface">The source cell data.</param> /// <param name="area">The area of the text surface.</param> public TextSurfaceView(ITextSurfaceRendered surface, Rectangle area) { data = surface; DefaultBackground = surface.DefaultBackground; DefaultForeground = surface.DefaultForeground; font = surface.Font; ViewArea = area; }
private void AfterSerializing(StreamingContext context) { if (!serializeTextSurface) { textSurface = (ITextSurfaceRendered)oldTextSurface; } oldTextSurface = null; }
private void BeforeSerializing(StreamingContext context) { if (!serializeTextSurface) { oldTextSurface = textSurface; serializedWidth = textSurface.Width; serializedHeight = textSurface.Height; textSurface = null; } }
/// <summary> /// Creates a new renderer. /// </summary> public CachedTextSurfaceRenderer(ITextSurfaceRendered source) { #if SFML Batch = new SpriteBatch(); renderedConsole = new RenderTexture((uint)source.AbsoluteArea.Width, (uint)source.AbsoluteArea.Height, false); #elif MONOGAME Batch = new SpriteBatch(Engine.Device); #endif Update(source); }
/// <summary> /// Renders a /// </summary> /// <param name="surface"></param> /// <param name="renderingMatrix"></param> public override void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { if (IsModal && ModalTint.A != 0) { Batch.Begin(samplerState: SamplerState.PointClamp); Batch.Draw(surface.Font.FontImage, new Rectangle(0, 0, Engine.RenderRect.Width, Engine.RenderRect.Height), surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], ModalTint); Batch.End(); } base.Render(surface, renderingMatrix); }
/// <summary> /// Renders the cached surface from a previous call to the constructor or the <see cref="Update(ITextSurfaceRendered)"/> method. /// </summary> /// <param name="surface">Used only for tinting.</param> /// <param name="renderingMatrix">Display matrix for the rendered console.</param> public virtual void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { Batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone, null, renderingMatrix); BeforeRenderCallback?.Invoke(Batch); Batch.Draw(renderedConsole, Vector2.Zero, surface.Tint); AfterRenderCallback?.Invoke(Batch); Batch.End(); }
/// <summary> /// Only renders a <see cref="LayeredTextSurface"/>. /// </summary> /// <param name="surface">The <see cref="LayeredTextSurface"/> to render.</param> /// <param name="renderingMatrix">Rendering matrix used with the sprite batch.</param> public override void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { var layers = ((LayeredTextSurface)surface).GetLayers(); Batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone, null, renderingMatrix); BeforeRenderCallback?.Invoke(Batch); if (surface.Tint.A != 255) { Cell cell; if (surface.DefaultBackground.A != 0) { Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.DefaultBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.2f); } for (int l = 0; l < layers.Length; l++) { if (layers[l].IsVisible) { for (int i = 0; i < layers[l].RenderCells.Length; i++) { cell = layers[l].RenderCells[i]; if (cell.IsVisible) { if (cell.ActualBackground != Color.Transparent && cell.ActualBackground != surface.DefaultBackground) { Batch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], cell.ActualBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.3f); } if (cell.ActualForeground != Color.Transparent) { Batch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphIndexRects[cell.ActualGlyphIndex], cell.ActualForeground, 0f, Vector2.Zero, cell.ActualSpriteEffect, 0.4f); } } } } } } if (surface.Tint.A != 0) { Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.Tint, 0f, Vector2.Zero, SpriteEffects.None, 0.5f); } AfterRenderCallback?.Invoke(Batch); Batch.End(); }
public Layer Import(ITextSurfaceRendered surface) { if (surface.Cells.Length != width * height) { throw new Exception("The length of cells passed in must match the width * height of this surface"); } var layer = new Layer(); layer.Cells = surface.Cells; ResetAreaLayer(layer); return(layer); }
/// <summary> /// Updates the cache based on the <paramref name="source"/> surface. /// </summary> /// <param name="source">The surface to render and cache.</param> public void Update(ITextSurfaceRendered source) { if (renderedConsole != null) { renderedConsole.Dispose(); } renderedConsole = new RenderTarget2D(Engine.Device, source.AbsoluteArea.Width, source.AbsoluteArea.Height, false, Engine.Device.DisplayMode.Format, DepthFormat.Depth24); Engine.Device.SetRenderTarget(renderedConsole); Engine.Device.Clear(Color.Transparent); TextSurfaceRenderer renderer = new TextSurfaceRenderer(); renderer.Render(source, new Point(0, 0)); Engine.RestoreRenderTarget(); }
public void Start(ITextSurfaceRendered surface, Matrix transform, int additionalDraws = 250) { fillRect = surface.AbsoluteArea; texture = surface.Font.FontImage; solidRect = surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex]; this.transform = transform; int count = ((surface.RenderCells.Length + 8 + additionalDraws) * 4 * 2); if (m_verticies.Length != count) { m_verticies = new Vertex[count]; } vertIndexCounter = 0; }
/// <summary> /// Renders a /// </summary> /// <param name="surface"></param> /// <param name="renderingMatrix"></param> public override void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { if (IsModal && ModalTint.A != 0) { #if SFML Batch.Reset(Engine.Device, RenderStates.Default, Matrix.Identity); Batch.DrawQuad(new IntRect(0, 0, (int)Engine.Device.Size.X, (int)Engine.Device.Size.Y), surface.Font.SolidGlyphRectangle, ModalTint, surface.Font.FontImage); Batch.End(); #elif MONOGAME Batch.Begin(samplerState: SamplerState.PointClamp); Batch.Draw(surface.Font.FontImage, new Rectangle(0, 0, Engine.Device.PresentationParameters.BackBufferWidth, Engine.Device.PresentationParameters.BackBufferHeight), surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], ModalTint); Batch.End(); #endif } base.Render(surface, renderingMatrix); }
private void AfterDeserialized(StreamingContext context) { if (!serializeTextSurface) { textSurface = new TextSurface(serializedWidth, serializedHeight, Engine.DefaultFont); } base.textSurface = textSurface; _virtualCursor.AttachConsole(this); //_virtualCursor.ResetCursorEffect(); if (_renderer is ITextSurfaceRendererUpdate) { ((ITextSurfaceRendererUpdate)_renderer).Update(textSurface); } }
/// <summary> /// Renders a surface to the screen. /// </summary> /// <param name="surface">The surface to render.</param> /// <param name="renderingMatrix">Display matrix for the rendered console.</param> public virtual void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { if (RenderTarget != null) { Batch.Reset(RenderTarget, renderingMatrix); } else { Batch.Reset(surface.Backbuffer, renderingMatrix); } BeforeRenderCallback?.Invoke(Batch); if (surface.Tint.A != 255) { Cell cell; if (surface.DefaultBackground.A != 0) { Batch.DrawQuad(surface.AbsoluteArea, surface.Font.SolidGlyphRectangle, surface.DefaultBackground, surface.Font.Image); } for (int i = 0; i < surface.RenderCells.Length; i++) { cell = surface.RenderCells[i]; if (cell.IsVisible) { Batch.DrawCell(cell, surface.RenderRects[i], surface.Font.SolidGlyphRectangle, surface.DefaultBackground, surface.Font); } } } AfterRenderCallback?.Invoke(Batch); if (surface.Tint.A != 0) { Batch.DrawQuad(surface.AbsoluteArea, surface.Font.SolidGlyphRectangle, surface.Tint, surface.Font.Image); } if (CallBatchEnd) { Batch.End(); } }
/// <summary> /// Only renders a <see cref="LayeredTextSurface"/>. /// </summary> /// <param name="surface">The <see cref="LayeredTextSurface"/> to render.</param> /// <param name="renderingMatrix">Rendering matrix used with the sprite batch.</param> public override void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { var layers = ((LayeredTextSurface)surface).GetLayers(); Batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone, null, renderingMatrix); BeforeRenderCallback?.Invoke(Batch); if (surface.Tint.A != 255) { Cell cell; if (surface.DefaultBackground.A != 0) Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.DefaultBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.2f); for (int l = 0; l < layers.Length; l++) { if (layers[l].IsVisible) { for (int i = 0; i < layers[l].RenderCells.Length; i++) { cell = layers[l].RenderCells[i]; if (cell.IsVisible) { if (cell.ActualBackground != Color.Transparent && cell.ActualBackground != surface.DefaultBackground) Batch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], cell.ActualBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.3f); if (cell.ActualForeground != Color.Transparent) Batch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphIndexRects[cell.ActualGlyphIndex], cell.ActualForeground, 0f, Vector2.Zero, cell.ActualSpriteEffect, 0.4f); } } } } } if (surface.Tint.A != 0) Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.Tint, 0f, Vector2.Zero, SpriteEffects.None, 0.5f); AfterRenderCallback?.Invoke(Batch); Batch.End(); }
/// <summary> /// Renders the cached surface from a previous call to the constructor or the <see cref="Update(ITextSurfaceRendered)"/> method. /// </summary> /// <param name="surface">Used only for tinting.</param> /// <param name="renderingMatrix">Display matrix for the rendered console.</param> public virtual void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { #if SFML //Batch.Start(1, renderedConsole.Texture, renderingMatrix); Batch.Reset(Engine.Device, RenderStates.Default, renderingMatrix); BeforeRenderCallback?.Invoke(Batch); if (surface.Tint == Color.Transparent) { Batch.DrawQuad(surface.AbsoluteArea, surface.AbsoluteArea, Color.White, renderedConsole.Texture); } else { Batch.DrawQuad(surface.AbsoluteArea, surface.AbsoluteArea, surface.Tint, renderedConsole.Texture); } AfterRenderCallback?.Invoke(Batch); Batch.End(); #elif MONOGAME Batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone, null, renderingMatrix); BeforeRenderCallback?.Invoke(Batch); if (surface.Tint.A != 255) { Batch.Draw(renderedConsole, Vector2.Zero, Color.White); if (surface.Tint.A != 0) { Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.Tint, 0f, Vector2.Zero, SpriteEffects.None, 0.5f); } } else { Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.Tint, 0f, Vector2.Zero, SpriteEffects.None, 0.5f); } AfterRenderCallback?.Invoke(Batch); Batch.End(); #endif }
public override void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { if (surface.Tint.A != 255) { Cell cell; if (surface.DefaultBackground.A != 0) { Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.DefaultBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.2f); } for (int i = 0; i < surface.RenderCells.Length; i++) { cell = surface.RenderCells[i]; if (cell.IsVisible) { if (cell.ActualBackground != Color.Transparent && cell.ActualBackground != surface.DefaultBackground) { Batch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], cell.ActualBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.3f); } if (cell.ActualForeground != Color.Transparent) { Batch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphIndexRects[cell.ActualGlyphIndex], cell.ActualForeground, 0f, Vector2.Zero, cell.ActualSpriteEffect, 0.4f); } } } if (surface.Tint.A != 0) { Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.Tint, 0f, Vector2.Zero, SpriteEffects.None, 0.5f); } } else { Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.Tint, 0f, Vector2.Zero, SpriteEffects.None, 0.5f); } }
/// <summary> /// Loads a <see cref="TextSurfaceView"/> from a file and existing <see cref="ITextSurfaceRendered"/>. /// </summary> /// <param name="file">The source file.</param> /// <param name="surfaceHydrate">The surface this view was originally from.</param> /// <returns>A surface view.</returns> public static TextSurfaceView Load(string file, ITextSurfaceRendered surfaceHydrate) { Serialized data = Serializer.Load <Serialized>(file); Font font; // Try to find font if (Engine.Fonts.ContainsKey(data.FontName)) { font = Engine.Fonts[data.FontName].GetFont(data.FontMultiple); } else { font = Engine.DefaultFont; } TextSurfaceView newSurface = new TextSurfaceView(surfaceHydrate, data.Area); newSurface.Font = font; newSurface.DefaultBackground = data.DefaultBackground; newSurface.DefaultForeground = data.DefaultForeground; newSurface.Tint = data.Tint; return(newSurface); }
/// <summary> /// Renders the cached surface from a previous call to the constructor or the <see cref="Update(ITextSurfaceRendered)"/> method. /// </summary> /// <param name="surface">Used only for tinting.</param> /// <param name="renderingMatrix">Display matrix for the rendered console.</param> public virtual void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { #if SFML Batch.Reset(Engine.Device, RenderStates.Default, renderingMatrix); BeforeRenderCallback?.Invoke(Batch); Batch.DrawQuad(surface.AbsoluteArea, surface.AbsoluteArea, surface.Tint, renderedConsole.Texture); AfterRenderCallback?.Invoke(Batch); Batch.End(); #elif MONOGAME Batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone, null, renderingMatrix); BeforeRenderCallback?.Invoke(Batch); Batch.Draw(renderedConsole, Vector2.Zero, surface.Tint); AfterRenderCallback?.Invoke(Batch); Batch.End(); #endif }
/// <summary> /// Creates a serialized object from an existing <see cref="Console"/>. /// </summary> /// <param name="surface">The surface to serialize.</param> public Serialized(Console console, bool serializeTextSurface) { AutoCursorOnFocus = console.AutoCursorOnFocus; CanFocus = console.CanFocus; CanUseKeyboard = console.CanUseKeyboard; CanUseMouse = console.CanUseMouse; if (serializeTextSurface) { TextSurface = console.TextSurface; } Width = console.Width; Height = console.Height; DoUpdate = console.DoUpdate; ExclusiveFocus = console.ExclusiveFocus; IsFocused = console.IsFocused; IsVisible = console.IsVisible; MouseCanFocus = console.MouseCanFocus; MoveToFrontOnMouseFocus = console.MoveToFrontOnMouseFocus; Position = console.Position; Renderer = console.Renderer; UsePixelPositioning = console.UsePixelPositioning; VirtualCursor = console.VirtualCursor; }
/// <summary> /// Loads a <see cref="TextSurfaceView"/> from a file and existing <see cref="ITextSurfaceRendered"/>. /// </summary> /// <param name="file">The source file.</param> /// <param name="surfaceHydrate">The surface this view was originally from.</param> /// <returns>A surface view.</returns> public static TextSurfaceView Load(string file, ITextSurfaceRendered surfaceHydrate) { TextSurfaceView surface = Serializer.Load<TextSurfaceView>(file); surface.Hydrate(surfaceHydrate); return surface; }
/// <summary> /// Call after the <see cref="TextSurfaceView"/> is deserialized to hook it back up to the original surface. /// </summary> /// <param name="surface">The surface to associate with the view.</param> public void Hydrate(ITextSurfaceRendered surface) { data = surface; ResetArea(); }
/// <summary> /// Renders a surface to the screen. /// </summary> /// <param name="surface">The surface to render.</param> /// <param name="renderingMatrix">Display matrix for the rendered console.</param> public virtual void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { Batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone, null, renderingMatrix); BeforeRenderCallback?.Invoke(Batch); if (surface.Tint.A != 255) { Cell cell; if (surface.DefaultBackground.A != 0) Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.DefaultBackground, 0f, PrimitiveStatic.Vector2Zero, SpriteEffects.None, 0.2f); for (int i = 0; i < surface.RenderCells.Length; i++) { cell = surface.RenderCells[i]; if (cell.IsVisible) { if (cell.ActualBackground != Color.Transparent && cell.ActualBackground != surface.DefaultBackground) Batch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], cell.ActualBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.3f); if (cell.ActualForeground != Color.Transparent) Batch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphIndexRects[cell.ActualGlyphIndex], cell.ActualForeground, 0f, Vector2.Zero, cell.ActualSpriteEffect, 0.4f); } } #region Control Render int cellCount; Rectangle rect; Point point; Controls.ControlBase control; // For each control for (int i = 0; i < Controls.Count; i++) { if (Controls[i].IsVisible) { control = Controls[i]; cellCount = control.TextSurface.Cells.Length; var font = control.AlternateFont == null ? surface.Font : control.AlternateFont; // Draw background of each cell for the control for (int cellIndex = 0; cellIndex < cellCount; cellIndex++) { cell = control[cellIndex]; if (cell.IsVisible) { point = Consoles.TextSurface.GetPointFromIndex(cellIndex, control.TextSurface.Width); point = new Point(point.X + control.Position.X, point.Y + control.Position.Y); if (surface.RenderArea.Contains(point.X, point.Y)) { point = new Point(point.X - surface.RenderArea.Left, point.Y - surface.RenderArea.Top); rect = surface.RenderRects[Consoles.TextSurface.GetIndexFromPoint(point, surface.Width)]; if (cell.ActualBackground != Color.Transparent) Batch.Draw(font.FontImage, rect, font.GlyphIndexRects[font.SolidGlyphIndex], cell.ActualBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.23f); if (cell.ActualForeground != Color.Transparent) Batch.Draw(font.FontImage, rect, font.GlyphIndexRects[cell.ActualGlyphIndex], cell.ActualForeground, 0f, Vector2.Zero, cell.ActualSpriteEffect, 0.26f); } } } } } #endregion if (surface.Tint.A != 0) Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.Tint, 0f, Vector2.Zero, SpriteEffects.None, 0.5f); } else { Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.Tint, 0f, Vector2.Zero, SpriteEffects.None, 0.5f); } AfterRenderCallback?.Invoke(Batch); if (CallBatchEnd) Batch.End(); }
/// <summary> /// Call after the <see cref="TextSurfaceView"/> is deserialized to hook it back up to the original surface. /// </summary> /// <param name="surface">The surface to associate with the view.</param> /// <param name="view">The sub view of the <paramref name="surface"/>.</param> public void Hydrate(ITextSurfaceRendered surface, Rectangle view) { data = surface; viewArea = view; ResetArea(); }
/// <summary> /// Renders a surface to the screen. /// </summary> /// <param name="surface">The surface to render.</param> /// <param name="position">Calculates the rendering position on the screen based on the size of the <paramref name="surface"/> parameter.</param> /// <param name="usePixelPositioning">Ignores the <paramref name="surface"/> font for positioning and instead treats the <paramref name="position"/> parameter in pixels.</param> public void Render(ITextSurfaceRendered surface, Point position, bool usePixelPositioning = false) { Matrix matrix; if (usePixelPositioning) { //if (oldAbsolutePosition != position) //{ // absolutePositionTransform = GetPositionTransform(position, surface.Font.Size, true); // oldAbsolutePosition = position; //} //matrix = absolutePositionTransform; matrix = GetPositionTransform(position, surface.Font.Size, true); } else { //if (position != oldPosition) //{ // positionTransform = GetPositionTransform(position, surface.Font.Size, false); // oldPosition = position; //} //matrix = positionTransform; matrix = GetPositionTransform(position, surface.Font.Size, false); } Render(surface, matrix); }
/// <summary> /// Updates the cache based on the <paramref name="source"/> surface. /// </summary> /// <param name="source">The surface to render and cache.</param> public void Update(ITextSurfaceRendered source) { if (renderedConsole != null) renderedConsole.Dispose(); renderedConsole = new RenderTarget2D(Engine.Device, source.AbsoluteArea.Width, source.AbsoluteArea.Height, false, Engine.Device.DisplayMode.Format, DepthFormat.Depth24); Engine.Device.SetRenderTarget(renderedConsole); Engine.Device.Clear(Color.Transparent); TextSurfaceRenderer renderer = new TextSurfaceRenderer(); renderer.Render(source, new Point(0, 0)); Engine.RestoreRenderTarget(); }
public MapLevel(int width, int height, IMapCreationStrategy <RogueSharp.Map> mapCreationStrategy, ITextSurfaceRendered textSurface) { Width = width; Height = height; //All this for the generic type argument. Type[] typeArgs = mapCreationStrategy.GetType().GetGenericArguments(); Type genericMapGen = typeof(MapGenerator <>); Type constructed = genericMapGen.MakeGenericType(typeArgs); mapGenerator = (MapGenerator <RogueSharp.Map>)Activator.CreateInstance(constructed, width, height, mapCreationStrategy, textSurface); EntityContainer = new EntityContainer(); ItemContainer = new ItemContainer(); MapData = mapGenerator.CreateMap(); }
public void Start(ITextSurfaceRendered surface, Matrix transform, int additionalDraws = 250) { fillRect = surface.AbsoluteArea; texture = surface.Font.FontImage; solidRect = surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex]; this.transform = transform; int count = ((surface.RenderCells.Length + 8 + additionalDraws) * 4 * 2); if (m_verticies.Length != count) m_verticies = new Vertex[count]; vertIndexCounter = 0; }
/// <summary> /// Loads effects from a file. /// </summary> /// <param name="file">The file to load from.</param> /// <param name="backingSurface">The surface the effects were originally (or will be) associated with.</param> /// <returns></returns> public static EffectsManager Load(string file, ITextSurfaceRendered backingSurface) { return EffectsManagerSerialized.Load(file, backingSurface); }
/// <summary> /// Renders a surface to the screen. /// </summary> /// <param name="surface">The surface to render.</param> /// <param name="renderingMatrix">Display matrix for the rendered console.</param> public virtual void Render(ITextSurfaceRendered surface, Matrix renderingMatrix) { Batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone, null, renderingMatrix); BeforeRenderCallback?.Invoke(Batch); if (surface.Tint.A != 255) { Cell cell; if (surface.DefaultBackground.A != 0) { Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.DefaultBackground, 0f, PrimitiveStatic.Vector2Zero, SpriteEffects.None, 0.2f); } for (int i = 0; i < surface.RenderCells.Length; i++) { cell = surface.RenderCells[i]; if (cell.IsVisible) { if (cell.ActualBackground != Color.Transparent && cell.ActualBackground != surface.DefaultBackground) { Batch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], cell.ActualBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.3f); } if (cell.ActualForeground != Color.Transparent) { Batch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphIndexRects[cell.ActualGlyphIndex], cell.ActualForeground, 0f, Vector2.Zero, cell.ActualSpriteEffect, 0.4f); } } } #region Control Render int cellCount; Rectangle rect; Point point; Controls.ControlBase control; // For each control for (int i = 0; i < Controls.Count; i++) { if (Controls[i].IsVisible) { control = Controls[i]; cellCount = control.TextSurface.Cells.Length; var font = control.AlternateFont == null ? surface.Font : control.AlternateFont; // Draw background of each cell for the control for (int cellIndex = 0; cellIndex < cellCount; cellIndex++) { cell = control[cellIndex]; if (cell.IsVisible) { point = Consoles.TextSurface.GetPointFromIndex(cellIndex, control.TextSurface.Width); point = new Point(point.X + control.Position.X, point.Y + control.Position.Y); if (surface.RenderArea.Contains(point.X, point.Y)) { point = new Point(point.X - surface.RenderArea.Left, point.Y - surface.RenderArea.Top); rect = surface.RenderRects[Consoles.TextSurface.GetIndexFromPoint(point, surface.Width)]; if (cell.ActualBackground != Color.Transparent) { Batch.Draw(font.FontImage, rect, font.GlyphIndexRects[font.SolidGlyphIndex], cell.ActualBackground, 0f, Vector2.Zero, SpriteEffects.None, 0.23f); } if (cell.ActualForeground != Color.Transparent) { Batch.Draw(font.FontImage, rect, font.GlyphIndexRects[cell.ActualGlyphIndex], cell.ActualForeground, 0f, Vector2.Zero, cell.ActualSpriteEffect, 0.26f); } } } } } } #endregion if (surface.Tint.A != 0) { Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.Tint, 0f, Vector2.Zero, SpriteEffects.None, 0.5f); } } else { Batch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphIndexRects[surface.Font.SolidGlyphIndex], surface.Tint, 0f, Vector2.Zero, SpriteEffects.None, 0.5f); } AfterRenderCallback?.Invoke(Batch); if (CallBatchEnd) { Batch.End(); } }
/// <summary> /// Wraps an existing text surface using a <see cref="TextSurfaceRenderer"/> to render. /// </summary> /// <param name="textData">The backing text surface.</param> public Console(ITextSurfaceRendered textData) : base(textData) { _virtualCursor = new Cursor(this); Renderer = new TextSurfaceRenderer(); textSurface = textData; }
/// <summary> /// Creates a new renderer. /// </summary> public CachedTextSurfaceRenderer(ITextSurfaceRendered source) { Batch = new SpriteBatch(Engine.Device); Update(source); }
public MessagesConsole(ITextSurfaceRendered textData) : base(textData) { }
public BoardConsole(ITextSurfaceRendered textData) : base(textData) { }