/// <inheritdoc/> public override void OnAdded(IScreenObject host) { if (_screen != null) { throw new Exception("Component has already been added to a host."); } if (!(host is IScreenSurface surface)) { throw new ArgumentException($"Must add this component to a type that implements {nameof(IScreenSurface)}"); } if (RenderStep != null) { surface.RenderSteps.Remove(RenderStep); RenderStep.Dispose(); } RenderStep = GameHost.Instance.GetRendererStep(Renderers.Constants.RenderStepNames.EntityRenderer); RenderStep.SetData(this); surface.RenderSteps.Add(RenderStep); _screen = surface; _isAttached = true; UpdateCachedVisibilityArea(); }
/// <inheritdoc/> public void Render(IRenderer renderer, IScreenSurface screenObject) { // If the tint isn't covering everything if (screenObject.Tint.A != 255) { // Draw any cursors foreach (Components.Cursor cursor in screenObject.GetSadComponents <Components.Cursor>()) { if (cursor.IsVisible && screenObject.Surface.IsValidCell(cursor.Position.X, cursor.Position.Y) && screenObject.Surface.View.Contains(cursor.Position)) { GameHost.Instance.DrawCalls.Enqueue( new DrawCalls.DrawCallGlyph(cursor.CursorRenderCell, ((Host.GameTexture)screenObject.Font.Image).Texture, new XnaRectangle(screenObject.Font.GetRenderRect(cursor.Position.X - screenObject.Surface.ViewPosition.X, cursor.Position.Y - screenObject.Surface.ViewPosition.Y, screenObject.FontSize).Translate(screenObject.AbsolutePosition).Position.ToMonoPoint(), screenObject.FontSize.ToMonoPoint()), screenObject.Font.SolidGlyphRectangle.ToMonoRectangle(), screenObject.Font.GetGlyphSourceRectangle(cursor.CursorRenderCell.Glyph).ToMonoRectangle() ) ); } } } }
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != (int)BackingTexture.Size.X || screenObject.AbsoluteArea.Height != (int)BackingTexture.Size.Y) { BackingTexture?.Dispose(); _cachedTexture?.Dispose(); BackingTexture = new RenderTexture((uint)screenObject.AbsoluteArea.Width, (uint)screenObject.AbsoluteArea.Height); _cachedTexture = new Host.GameTexture(BackingTexture.Texture); result = true; } // Redraw is needed if (result || _controlsHost.IsDirty || isForced) { BackingTexture.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Reset(BackingTexture, ((ScreenSurfaceRenderer)renderer).SFMLBlendState, Transform.Identity); ProcessContainer(_controlsHost, ((ScreenSurfaceRenderer)renderer), screenObject); Host.Global.SharedSpriteBatch.End(); BackingTexture.Display(); result = true; _controlsHost.IsDirty = false; } return(result); }
/// <summary> /// Creates a border and adds it as a child object to <paramref name="contents"/>. /// </summary> /// <param name="contents">The object the border will be around.</param> /// <param name="title">Optional title to display on the border.</param> public Border(IScreenSurface contents, string title) : base(contents.Surface.Width + 3, contents.Surface.Height + 3) { Position = (-1, -1); Font = contents.Font; FontSize = contents.FontSize; Surface.DefaultForeground = Color.AnsiWhite; Surface.Clear(); Surface.DrawBox((0, 0, Surface.Width - 1, Surface.Height - 1), new ColoredGlyph(Color.AnsiWhite, contents.Surface.DefaultBackground), new ColoredGlyph(Color.White, Color.Transparent), ICellSurface.ConnectedLineThin); Surface.DrawLine((Surface.Width - 1, 2), (Surface.Width - 1, Surface.Height - 2), 219, Color.AnsiWhite); Surface.DrawLine((1, Surface.Height - 1), (Surface.Width - 1, Surface.Height - 1), 223, Color.AnsiWhite); Surface.SetGlyph(Surface.Width - 1, 1, 220); if (!string.IsNullOrEmpty(title)) { Surface.Print(((Surface.Width - 1) / 2) - ((title.Length + 2) / 2), 0, title.Align(HorizontalAlignment.Center, title.Length + 2, ' '), contents.Surface.DefaultBackground, Color.AnsiWhite); } IsEnabled = false; UseMouse = false; UseKeyboard = false; contents.Children.Add(this); }
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != BackingTexture.Width || screenObject.AbsoluteArea.Height != BackingTexture.Height) { BackingTexture?.Dispose(); _cachedTexture?.Dispose(); BackingTexture = new RenderTarget2D(Host.Global.GraphicsDevice, screenObject.AbsoluteArea.Width, screenObject.AbsoluteArea.Height, false, Host.Global.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); _cachedTexture = new Host.GameTexture(BackingTexture); result = true; } if (result || _controlsHost.IsDirty || isForced) { Host.Global.GraphicsDevice.SetRenderTarget(BackingTexture); Host.Global.GraphicsDevice.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Begin(SpriteSortMode.Deferred, ((ScreenSurfaceRenderer)renderer).MonoGameBlendState, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone); ProcessContainer(_controlsHost, ((ScreenSurfaceRenderer)renderer), screenObject); Host.Global.SharedSpriteBatch.End(); Host.Global.GraphicsDevice.SetRenderTarget(null); result = true; _controlsHost.IsDirty = false; } return(result); }
public void Render(IRenderer renderer, IScreenSurface screenObject) { if (screenObject.Tint.A != 0) { GameHost.Instance.DrawCalls.Enqueue(new DrawCalls.DrawCallColor(screenObject.Tint.ToMonoColor(), ((SadConsole.Host.GameTexture)screenObject.Font.Image).Texture, screenObject.AbsoluteArea.ToMonoRectangle(), screenObject.Font.SolidGlyphRectangle.ToMonoRectangle())); } }
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != (int)BackingTexture.Size.X || screenObject.AbsoluteArea.Height != (int)BackingTexture.Size.Y) { BackingTexture?.Dispose(); BackingTexture = new RenderTexture((uint)screenObject.AbsoluteArea.Width, (uint)screenObject.AbsoluteArea.Height); _cachedTexture?.Dispose(); _cachedTexture = new Host.GameTexture(BackingTexture.Texture); result = true; } var sfmlRenderer = (ScreenSurfaceRenderer)renderer; // Redraw is needed if (result || screenObject.IsDirty || isForced) { BackingTexture.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Reset(BackingTexture, sfmlRenderer.SFMLBlendState, Transform.Identity); int rectIndex = 0; ColoredGlyph cell; IFont font = screenObject.Font; if (screenObject.Surface.DefaultBackground.A != 0) { Host.Global.SharedSpriteBatch.DrawQuad(new IntRect(0, 0, (int)BackingTexture.Size.X, (int)BackingTexture.Size.Y), font.SolidGlyphRectangle.ToIntRect(), screenObject.Surface.DefaultBackground.ToSFMLColor(), ((SadConsole.Host.GameTexture)font.Image).Texture); } for (int y = 0; y < screenObject.Surface.View.Height; y++) { int i = ((y + screenObject.Surface.ViewPosition.Y) * screenObject.Surface.Width) + screenObject.Surface.ViewPosition.X; for (int x = 0; x < screenObject.Surface.View.Width; x++) { cell = screenObject.Surface[i]; cell.IsDirty = false; if (cell.IsVisible) { Host.Global.SharedSpriteBatch.DrawCell(cell, sfmlRenderer.CachedRenderRects[rectIndex], cell.Background != SadRogue.Primitives.Color.Transparent && cell.Background != screenObject.Surface.DefaultBackground, font); } i++; rectIndex++; } } Host.Global.SharedSpriteBatch.End(); BackingTexture.Display(); result = true; screenObject.IsDirty = false; } return(result); }
/// <inheritdoc/> public void Render(IRenderer renderer, IScreenSurface screenObject) { var monoRenderer = (ScreenSurfaceRenderer)renderer; if (screenObject.Tint.A != 255) { GameHost.Instance.DrawCalls.Enqueue(new DrawCalls.DrawCallTexture(monoRenderer._backingTexture, new Vector2(screenObject.AbsoluteArea.Position.X, screenObject.AbsoluteArea.Position.Y), monoRenderer._finalDrawColor)); } }
/// <inheritdoc/> public void Render(IRenderer renderer, IScreenSurface screenObject) { UI.Window window = (UI.Window)screenObject; UI.Colors colors = window.Controls.GetThemeColors(); if (window.IsModal && colors.ModalBackground.A != 0) { GameHost.Instance.DrawCalls.Enqueue(new DrawCalls.DrawCallColor(colors.ModalBackground.ToMonoColor(), ((Host.GameTexture)window.Font.Image).Texture, new XnaRectangle(0, 0, Settings.Rendering.RenderWidth, Settings.Rendering.RenderHeight), window.Font.SolidGlyphRectangle.ToMonoRectangle())); } }
/// <summary> /// /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="duration"></param> /// <param name="easingFunction"></param> public Fade(IScreenSurface from, IScreenSurface to, TimeSpan duration, EasingFunctions.EasingBase easingFunction = null) { if (easingFunction == null) { easingFunction = new EasingFunctions.Linear(); } _fadeFrom = from; _fadeTo = to; _valueInstructionTo = new Instructions.AnimatedValue(duration, 0, 255, easingFunction); }
/// <inheritdoc/> public override void OnRemoved(IScreenObject host) { ((IScreenSurface)host).RenderSteps.Remove(RenderStep); RenderStep?.Dispose(); RenderStep = null; _screen = null; _screenCachedFont = null; _screenCachedFontSize = Point.None; _screenCachedView = Rectangle.Empty; _isAttached = false; }
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != (int)BackingTexture.Size.X || screenObject.AbsoluteArea.Height != (int)BackingTexture.Size.Y) { BackingTexture?.Dispose(); BackingTexture = new RenderTexture((uint)screenObject.AbsoluteArea.Width, (uint)screenObject.AbsoluteArea.Height); _cachedTexture?.Dispose(); _cachedTexture = new Host.GameTexture(BackingTexture.Texture); result = true; } // Redraw is needed if (result || _entityManager.IsDirty || isForced) { BackingTexture.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Reset(BackingTexture, ((ScreenSurfaceRenderer)renderer).SFMLBlendState, Transform.Identity); ColoredGlyph cell; IntRect renderRect; foreach (Entities.Entity item in _entityManager.EntitiesVisible) { if (!item.IsVisible) { continue; } renderRect = _entityManager.GetRenderRectangle(item.Position, item.UsePixelPositioning).ToIntRect(); cell = item.Appearance; cell.IsDirty = false; Host.Global.SharedSpriteBatch.DrawCell(cell, renderRect, true, screenObject.Font); } Host.Global.SharedSpriteBatch.End(); BackingTexture.Display(); result = true; _entityManager.IsDirty = false; } return(result); }
/// <inheritdoc/> public void Render(IRenderer renderer, IScreenSurface screenObject) { // If the tint isn't covering everything if (screenObject.Tint.A != 255) { // Draw any cursors foreach (Components.Cursor cursor in screenObject.GetSadComponents <Components.Cursor>()) { if (cursor.IsVisible && screenObject.Surface.IsValidCell(cursor.Position.X, cursor.Position.Y) && screenObject.Surface.View.Contains(cursor.Position)) { Point cursorPosition = screenObject.AbsoluteArea.Position + screenObject.Font.GetRenderRect(cursor.Position.X - screenObject.Surface.ViewPosition.X, cursor.Position.Y - screenObject.Surface.ViewPosition.Y, screenObject.FontSize).Position; GameHost.Instance.DrawCalls.Enqueue( new DrawCalls.DrawCallCell(cursor.CursorRenderCell, new Rectangle(cursorPosition.X, cursorPosition.Y, screenObject.FontSize.X, screenObject.FontSize.Y).ToIntRect(), screenObject.Font, true ) ); } } } }
/// <summary> /// Returns true when the mouse is currently over the provided screen object. /// </summary> /// <param name="screenObject">The screen object to check.</param> /// <returns>True or false indicating if the mouse is over the screen object.</returns> public bool IsMouseOverScreenObjectSurface(IScreenSurface screenObject) => new MouseScreenObjectState(screenObject, this).IsOnScreenObject;
public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) => throw new NotImplementedException();
/// <inheritdoc/> public void Composing(IRenderer renderer, IScreenSurface screenObject) { }
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) => false;
/// <inheritdoc/> public void Composing(IRenderer renderer, IScreenSurface screenObject) { Host.Global.SharedSpriteBatch.Draw(BackingTexture, Vector2.Zero, Color.White); }
public void Render(IRenderer renderer, IScreenSurface screenObject) => throw new NotImplementedException();
/// <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); } } }
/// <inheritdoc/> public void Render(IRenderer renderer, IScreenSurface screenObject) { }
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != BackingTexture.Width || screenObject.AbsoluteArea.Height != BackingTexture.Height) { BackingTexture?.Dispose(); BackingTexture = new RenderTarget2D(Host.Global.GraphicsDevice, screenObject.AbsoluteArea.Width, screenObject.AbsoluteArea.Height, false, Host.Global.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); _cachedTexture?.Dispose(); _cachedTexture = new Host.GameTexture(BackingTexture); result = true; } var monoRenderer = (ScreenSurfaceRenderer)renderer; // Redraw is needed if (result || screenObject.IsDirty || isForced) { Host.Global.GraphicsDevice.SetRenderTarget(BackingTexture); Host.Global.GraphicsDevice.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Begin(SpriteSortMode.Deferred, monoRenderer.MonoGameBlendState, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone); IFont font = screenObject.Font; Texture2D fontImage = ((Host.GameTexture)font.Image).Texture; ColoredGlyph cell; if (screenObject.Surface.DefaultBackground.A != 0) { Host.Global.SharedSpriteBatch.Draw(fontImage, new XnaRectangle(0, 0, BackingTexture.Width, BackingTexture.Height), font.SolidGlyphRectangle.ToMonoRectangle(), screenObject.Surface.DefaultBackground.ToMonoColor(), 0f, Vector2.Zero, SpriteEffects.None, 0.2f); } int rectIndex = 0; for (int y = 0; y < screenObject.Surface.View.Height; y++) { int i = ((y + screenObject.Surface.ViewPosition.Y) * screenObject.Surface.Width) + screenObject.Surface.ViewPosition.X; for (int x = 0; x < screenObject.Surface.View.Width; x++) { cell = screenObject.Surface[i]; cell.IsDirty = false; if (cell.IsVisible) { if (cell.Background != SadRogue.Primitives.Color.Transparent && cell.Background != screenObject.Surface.DefaultBackground) { Host.Global.SharedSpriteBatch.Draw(fontImage, monoRenderer.CachedRenderRects[rectIndex], font.SolidGlyphRectangle.ToMonoRectangle(), cell.Background.ToMonoColor(), 0f, Vector2.Zero, SpriteEffects.None, 0.3f); } if (cell.Foreground != SadRogue.Primitives.Color.Transparent && cell.Foreground != cell.Background) { Host.Global.SharedSpriteBatch.Draw(fontImage, monoRenderer.CachedRenderRects[rectIndex], 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, monoRenderer.CachedRenderRects[rectIndex], font.GetGlyphSourceRectangle(decorator.Glyph).ToMonoRectangle(), decorator.Color.ToMonoColor(), 0f, Vector2.Zero, decorator.Mirror.ToMonoGame(), 0.5f); } } } i++; rectIndex++; } } Host.Global.SharedSpriteBatch.End(); Host.Global.GraphicsDevice.SetRenderTarget(null); result = true; screenObject.IsDirty = false; } return(result); }
/// <summary> /// Called when an entity moves within a zone. /// </summary> /// <param name="host">The host that the zone and entity share.</param> /// <param name="zone">The zone the entity moved in.</param> /// <param name="entity">The entity that moved in the zone.</param> /// <param name="newPosition">The position the entity moved to.</param> /// <param name="oldPosition">The position the entity moved from.</param> protected virtual void OnEntityMoveZone(IScreenSurface host, Zone zone, Entity entity, Point newPosition, Point oldPosition) { }
/// <summary> /// Called when an entity enters a zone. /// </summary> /// <param name="host">The host that the zone and entity share.</param> /// <param name="zone">The zone the entity exited.</param> /// <param name="entity">The entity that exited the zone.</param> /// <param name="triggeredPosition">The new position the entity left.</param> protected virtual void OnEntityExitZone(IScreenSurface host, Zone zone, Entity entity, Point triggeredPosition) { }
/// <summary> /// Helper method to add a border to a surface. /// </summary> /// <param name="contents">The object the border will be around.</param> /// <param name="title">Optional title to display on the border.</param> public static void AddToSurface(IScreenSurface contents, string title) => new Border(contents, title);
/// <inheritdoc/> public bool Refresh(IRenderer renderer, IScreenSurface screenObject, bool backingTextureChanged, bool isForced) { bool result = true; // Update texture if something is out of size. if (backingTextureChanged || BackingTexture == null || screenObject.AbsoluteArea.Width != BackingTexture.Width || screenObject.AbsoluteArea.Height != BackingTexture.Height) { BackingTexture?.Dispose(); BackingTexture = new RenderTarget2D(Host.Global.GraphicsDevice, screenObject.AbsoluteArea.Width, screenObject.AbsoluteArea.Height, false, Host.Global.GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24); _cachedTexture?.Dispose(); _cachedTexture = new Host.GameTexture(BackingTexture); result = true; } if (result || _entityManager.IsDirty || isForced) { Host.Global.GraphicsDevice.SetRenderTarget(BackingTexture); Host.Global.GraphicsDevice.Clear(Color.Transparent); Host.Global.SharedSpriteBatch.Begin(SpriteSortMode.Deferred, ((ScreenSurfaceRenderer)renderer).MonoGameBlendState, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone); Texture2D fontImage = ((Host.GameTexture)screenObject.Font.Image).Texture; IFont font = screenObject.Font; ColoredGlyph cell; XnaRectangle renderRect; foreach (Entities.Entity item in _entityManager.EntitiesVisible) { if (!item.IsVisible) { continue; } renderRect = _entityManager.GetRenderRectangle(item.Position, item.UsePixelPositioning).ToMonoRectangle(); cell = item.Appearance; cell.IsDirty = false; 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); } } } Host.Global.SharedSpriteBatch.End(); Host.Global.GraphicsDevice.SetRenderTarget(null); result = true; _entityManager.IsDirty = false; } return(result); }
/// <inheritdoc/> public void Composing(IRenderer renderer, IScreenSurface screenObject) { IntRect outputArea = new IntRect(0, 0, (int)BackingTexture.Size.X, (int)BackingTexture.Size.Y); Host.Global.SharedSpriteBatch.DrawQuad(outputArea, outputArea, Color.White, BackingTexture.Texture); }