private void RenderBackground(RendererParameters parameters, WindowTexture windowTexture) { Color backgroundColor = BackgroundColor * Alpha; RasterizerState rasterizerState = ScissorRectangleContext.Current != null ? new ScissoringRasterizerState() : RasterizerState.CullNone; SpriteBatchContext spriteBatchContext = SpriteBatchContext.Current ?? SpriteBatchContext.Default; Vector2 origin = spriteBatchContext.Origin; parameters.SpriteBatch.Begin( SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, rasterizerState, spriteBatchContext.Effect, spriteBatchContext.TransformMatrix); parameters.SpriteBatch.Draw(windowTexture.Texture, Window.TopLeftCornerRectangle, windowTexture.BackgroundTopLeftRectangle, backgroundColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(windowTexture.Texture, Window.TopRightCornerRectangle, windowTexture.BackgroundTopRightRectangle, backgroundColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(windowTexture.Texture, Window.BottomLeftCornerRectangle, windowTexture.BackgroundBottomLeftRectangle, backgroundColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(windowTexture.Texture, Window.BottomRightCornerRectangle, windowTexture.BackgroundBottomRightRectangle, backgroundColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(windowTexture.Texture, Window.LeftRectangle, windowTexture.BackgroundLeftRectangle, backgroundColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(windowTexture.Texture, Window.RightRectangle, windowTexture.BackgroundRightRectangle, backgroundColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(windowTexture.Texture, Window.TopRectangle, windowTexture.BackgroundTopRectangle, backgroundColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(windowTexture.Texture, Window.BottomRectangle, windowTexture.BackgroundBottomRectangle, backgroundColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(windowTexture.Texture, Window.CenterRectangle, windowTexture.BackgroundCenterRectangle, backgroundColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.End(); }
public void Render(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullNone); parameters.SpriteBatch.Draw(parameters.TextureContent.GameBackground, Constants.GameWindow.DestinationRectangle, Constants.GameWindow.DestinationRectangle, Constants.GameBackgroundRenderer.Color); parameters.SpriteBatch.End(); }
protected override void RenderBorder(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); WindowTexture windowTexture = _getWindowTextureDelegate(parameters.TextureContent); if (windowTexture == null) { throw new Exception("Must specify a valid window texture."); } RenderBorder(parameters, windowTexture); }
protected override void RenderContents(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); SpriteFont font = parameters.FontContent.Calibri10Pt; Vector2 textVector = Window.AbsoluteClientRectangle.Location.ToVector2(); int lineCount = 0; parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); foreach (LogEntry logEntry in _state.GetFilteredLogEntries()) { Color textColor = Constants.LogRenderer.TextColors.Single(arg => arg.Key == logEntry.EntryType).Value * logEntry.TimedLerpHelper.Value; Color shadowColor = Constants.LogRenderer.ShadowColors.Single(arg => arg.Key == logEntry.EntryType).Value * logEntry.TimedLerpHelper.Value; logEntry.TimedLerpHelper.Update(parameters.GameTime.TotalGameTime); string titleText = _state.ShowTimestamps ? String.Format(LineFormatString, logEntry.LoggedTotalWorldTime, logEntry.Title) : logEntry.Title; parameters.SpriteBatch.DrawStringWithShadow(font, titleText, textVector, textColor, shadowColor, Constants.LogRenderer.ShadowOffset); if (++lineCount >= _state.MaximumVisibleLogLines) { break; } textVector.X += Constants.LogRenderer.DetailIndent; textVector.Y += font.LineSpacing + Constants.LogRenderer.ShadowOffset.Y; foreach (string detail in logEntry.Details) { parameters.SpriteBatch.DrawStringWithShadow(font, detail, textVector, textColor, shadowColor, Constants.LogRenderer.ShadowOffset); if (++lineCount >= _state.MaximumVisibleLogLines) { break; } textVector.Y += font.LineSpacing + Constants.LogRenderer.ShadowOffset.Y; } if (lineCount >= _state.MaximumVisibleLogLines) { break; } textVector.X -= Constants.LogRenderer.DetailIndent; } parameters.SpriteBatch.End(); }
public override sealed void Render(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); BeforeRender(parameters); parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); parameters.SpriteBatch.Draw(parameters.TextureContent.Pixel, Window.WindowRectangle, BackgroundColor * Alpha); parameters.SpriteBatch.End(); RenderContents(parameters); }
public override sealed void Render(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); if (!Visible) { return; } BeforeRender(parameters); RenderBackground(parameters); RenderBorder(parameters); RenderContents(parameters); }
public void Render(SpriteBatch spriteBatch, IXnaGameTime gameTime, FontContent fontContent, TextureContent textureContent) { spriteBatch.ThrowIfNull("spriteBatch"); gameTime.ThrowIfNull("gameTime"); fontContent.ThrowIfNull("fontContent"); textureContent.ThrowIfNull("textureContent"); var parameters = new RendererParameters(gameTime, spriteBatch, fontContent, textureContent); // Must call ToArray() because collection could be modified during iteration foreach (IRenderer renderer in _renderers.ToArray()) { renderer.Render(parameters); } }
public void Render(RendererParameters parameters) { parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); parameters.SpriteBatch.Draw( parameters.TextureContent.Pixel, Constants.PlayerRenderer.DestinationRectangle, parameters.TextureContent.Pixel.Bounds, Constants.PlayerRenderer.BackgroundColor); parameters.SpriteBatch.Draw( parameters.TextureContent.Characters, Constants.PlayerRenderer.DestinationRectangle, Constants.PlayerRenderer.TextureRectangle, Constants.PlayerRenderer.ForegroundColor); parameters.SpriteBatch.End(); }
protected override void BeforeRender(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); base.BeforeRender(parameters); if (_windowRectangleSet) { return; } SpriteFont font = parameters.FontContent.Calibri10PtBold; int clientWidth = (font.MeasureString("Normal speed").X + Constants.WorldTimeRenderer.ShadowOffset.X).Round(); int clientHeight = ((font.LineSpacing + Constants.WorldTimeRenderer.ShadowOffset.Y) * 3).Round(); SetWindowRectangleUsingClientSize(WindowAlignment.TopRight, clientWidth, clientHeight, new Padding(Constants.BorderedWindow.Padding)); _windowRectangleSet = true; }
protected override void RenderContents(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); SpriteFont font = parameters.FontContent.Calibri10Pt; string text = _state.FrameCount + " fps"; parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); parameters.SpriteBatch.DrawStringWithShadow( font, text, Window.AbsoluteClientRectangle.Location.ToVector2(), Constants.FpsRenderer.TextColor, Constants.FpsRenderer.ShadowColor, Constants.FpsRenderer.ShadowOffset); parameters.SpriteBatch.End(); }
protected override void BeforeRender(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); base.BeforeRender(parameters); SpriteFont font = parameters.FontContent.Calibri10Pt; LogEntry[] logEntries = _state.GetFilteredLogEntries().ToArray(); int maximumTitleTextWidth = logEntries.Any() ? logEntries.Max(arg => MeasureLineWidth(font, arg.LoggedTotalWorldTime, arg.Title, 0, _state.ShowTimestamps)) : 0; int maximumDetailTextWidth = logEntries.Any(arg => arg.Details.Any()) ? logEntries.Max(arg1 => arg1.Details.Any() ? arg1.Details.Max(arg2 => MeasureLineWidth(font, arg1.LoggedTotalWorldTime, arg2, Constants.LogRenderer.DetailIndent, false)) : 0) : 0; int lineCount = Math.Min(_state.MaximumVisibleLogLines, logEntries.Sum(arg => arg.LineCount)); int clientWidth = (Math.Max(_state.MinimumWindowWidth ?? 0, Math.Max(maximumTitleTextWidth, maximumDetailTextWidth)) + Constants.LogRenderer.ShadowOffset.X).Round(); int clientHeight = ((font.LineSpacing + Constants.LogRenderer.ShadowOffset.Y) * lineCount).Round(); SetWindowRectangleUsingClientSize(WindowAlignment.TopLeft, clientWidth, clientHeight, new Padding(Constants.BorderedWindow.Padding)); }
private void RenderScrollArrows(RendererParameters parameters) { WindowTexture windowTexture = parameters.TextureContent.Windows.InnerBevel1; int x = Window.AbsoluteClientRectangle.Right - windowTexture.SpriteWidth; var scrollPosition = new FloatToInt(_state.ScrollPosition); var upArrowPosition = new Vector2(x, Window.AbsoluteClientRectangle.Y); var downArrowPosition = new Vector2(x, Window.AbsoluteClientRectangle.Bottom - windowTexture.SpriteHeight); Color upArrowColor = (scrollPosition == 0 ? TextAdventure.Xna.Constants.MessageRenderer.DisabledArrowColor : TextAdventure.Xna.Constants.MessageRenderer.ArrowColor) * Alpha; Color downArrowColor = (scrollPosition.FloatValue >= _state.MaximumScrollPosition ? TextAdventure.Xna.Constants.MessageRenderer.DisabledArrowColor : TextAdventure.Xna.Constants.MessageRenderer.ArrowColor) * Alpha; parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); parameters.SpriteBatch.Draw(windowTexture.Texture, upArrowPosition, windowTexture.UpArrowRectangle, upArrowColor); parameters.SpriteBatch.Draw(windowTexture.Texture, downArrowPosition, windowTexture.DownArrowRectangle, downArrowColor); parameters.SpriteBatch.End(); }
private void RenderWords( RendererParameters parameters, SpriteFont font, Matrix transformMatrix, int lineIndex, IList <MessageTextWord> words, Color shadowColor, ref Vector2 position, ref Color textColor) { parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, new ScissoringRasterizerState(), null, transformMatrix); MessageTextAlignment alignment = _formatter.GetAlignmentByLine(lineIndex); Vector2 lineSize = _formatter.GetLineSizeByLine(lineIndex); if (alignment == MessageTextAlignment.Center) { position.X += (Window.AbsoluteClientRectangle.Width - lineSize.X) / 2; } for (int wordIndex = 0; wordIndex < words.Count; wordIndex++) { MessageTextWord word = words[wordIndex]; Engine.Common.Color color; if (_formatter.TryGetColorByWordCoordinate(new Coordinate(wordIndex, lineIndex), out color)) { textColor = color.ToXnaColor() * Alpha; } if (word.PrependSpace) { position.X += _formatter.SpaceWord.Size.X; } parameters.SpriteBatch.DrawStringWithShadow(font, word.Text, position.Round(), textColor, shadowColor, Vector2.One); position.X += word.Size.X; } position.X = Window.AbsoluteClientRectangle.X; position.Y += lineSize.Y; parameters.SpriteBatch.End(); }
protected override void BeforeRender(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); base.BeforeRender(parameters); if (_windowRectangleSet) { return; } SpriteFont font = parameters.FontContent.Calibri10Pt; SetWindowRectangleUsingClientSize( WindowAlignment.BottomLeft, (font.MeasureString("000 fps").X + Constants.FpsRenderer.ShadowOffset.X).Round(), (font.LineSpacing + Constants.FpsRenderer.ShadowOffset.Y).Round(), new Padding(Constants.BorderedWindow.Padding)); _windowRectangleSet = true; }
protected virtual void RenderBackground(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); Texture2D pixelTexture = parameters.TextureContent.Pixel; SpriteBatchContext spriteBatchContext = SpriteBatchContext.Current ?? SpriteBatchContext.Default; parameters.SpriteBatch.Begin( SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullNone, spriteBatchContext.Effect, spriteBatchContext.TransformMatrix); parameters.SpriteBatch.Draw(pixelTexture, Window.WindowRectangle, pixelTexture.Bounds, BackgroundColor, 0f, spriteBatchContext.Origin, SpriteEffects.None, 0f); parameters.SpriteBatch.End(); }
private void RenderMessage(RendererParameters parameters) { Color textColor = TextAdventure.Xna.Constants.MessageRenderer.TextColor * Alpha; Color shadowColor = TextAdventure.Xna.Constants.MessageRenderer.ShadowColor * Alpha; var position = new Vector2(Window.AbsoluteClientRectangle.X, Window.AbsoluteClientRectangle.Y); Matrix translationMatrix = Matrix.CreateTranslation(0f, -_state.ScrollPosition, 0f) * _transformMatrix; SpriteFont font = parameters.FontContent.Calibri12Pt; WindowTexture selectedAnswerWindowTexture = parameters.TextureContent.Windows.Glow1; for (int lineIndex = 0; lineIndex < _formatter.LineCount; lineIndex++) { MessageTextWord[] words = _formatter.GetWordsByLine(lineIndex).ToArray(); MessageTextAnswer[] answers = words.OfType <MessageTextAnswer>().ToArray(); if (answers.Length > 0) { RenderAnswers(parameters, selectedAnswerWindowTexture, font, translationMatrix, answers, shadowColor, position); } else { RenderWords(parameters, font, translationMatrix, lineIndex, words, shadowColor, ref position, ref textColor); } } }
protected override void RenderBorder(RendererParameters parameters) { using (new ScissorRectangleContext(parameters.SpriteBatch.GraphicsDevice, _scissorRectangle)) using (new SpriteBatchContext(_transformMatrix)) { base.RenderBorder(parameters); } }
private void RenderWords( RendererParameters parameters, SpriteFont font, Matrix transformMatrix, int lineIndex, IList<MessageTextWord> words, Color shadowColor, ref Vector2 position, ref Color textColor) { parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, new ScissoringRasterizerState(), null, transformMatrix); MessageTextAlignment alignment = _formatter.GetAlignmentByLine(lineIndex); Vector2 lineSize = _formatter.GetLineSizeByLine(lineIndex); if (alignment == MessageTextAlignment.Center) { position.X += (Window.AbsoluteClientRectangle.Width - lineSize.X) / 2; } for (int wordIndex = 0; wordIndex < words.Count; wordIndex++) { MessageTextWord word = words[wordIndex]; Engine.Common.Color color; if (_formatter.TryGetColorByWordCoordinate(new Coordinate(wordIndex, lineIndex), out color)) { textColor = color.ToXnaColor() * Alpha; } if (word.PrependSpace) { position.X += _formatter.SpaceWord.Size.X; } parameters.SpriteBatch.DrawStringWithShadow(font, word.Text, position.Round(), textColor, shadowColor, Vector2.One); position.X += word.Size.X; } position.X = Window.AbsoluteClientRectangle.X; position.Y += lineSize.Y; parameters.SpriteBatch.End(); }
private void RenderMessage(RendererParameters parameters) { Color textColor = TextAdventure.Xna.Constants.MessageRenderer.TextColor * Alpha; Color shadowColor = TextAdventure.Xna.Constants.MessageRenderer.ShadowColor * Alpha; var position = new Vector2(Window.AbsoluteClientRectangle.X, Window.AbsoluteClientRectangle.Y); Matrix translationMatrix = Matrix.CreateTranslation(0f, -_state.ScrollPosition, 0f) * _transformMatrix; SpriteFont font = parameters.FontContent.Calibri12Pt; WindowTexture selectedAnswerWindowTexture = parameters.TextureContent.Windows.Glow1; for (int lineIndex = 0; lineIndex < _formatter.LineCount; lineIndex++) { MessageTextWord[] words = _formatter.GetWordsByLine(lineIndex).ToArray(); MessageTextAnswer[] answers = words.OfType<MessageTextAnswer>().ToArray(); if (answers.Length > 0) { RenderAnswers(parameters, selectedAnswerWindowTexture, font, translationMatrix, answers, shadowColor, position); } else { RenderWords(parameters, font, translationMatrix, lineIndex, words, shadowColor, ref position, ref textColor); } } }
private void RenderAnswers( RendererParameters parameters, WindowTexture selectedAnswerWindowTexture, SpriteFont font, Matrix transformMatrix, IEnumerable<MessageTextAnswer> answers, Color shadowColor, Vector2 position) { answers = answers.ToArray(); int answerCount = answers.Count(); int totalAnswerPadding = ((answerCount - 1) * TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalPadding); float lineWidth = answers.Sum(arg => arg.Size.X + (selectedAnswerWindowTexture.SpriteWidth * 2) + (TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalTextPadding * 2)) + totalAnswerPadding; float lineHeight = answers.Max(arg => arg.Size.Y); position.X += (Window.AbsoluteClientRectangle.Width - lineWidth) / 2; foreach (MessageTextAnswer answer in answers) { var window = new BorderedWindow( new Rectangle( position.X.Round(), position.Y.Round(), (answer.Size.X + (selectedAnswerWindowTexture.SpriteWidth * 2) + (TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalTextPadding * 2)).Round(), (lineHeight + (selectedAnswerWindowTexture.SpriteHeight * 2)).Round()), selectedAnswerWindowTexture.Padding); if (answer.Answer == _answerSelectionManager.SelectedAnswer) { _messageAnswerRenderer.Update( window.WindowRectangle, selectedAnswerWindowTexture.Padding, answer.SelectedAnswerBackgroundColor.ToXnaColor(), Alpha, Window.AbsoluteClientRectangle, transformMatrix); _messageAnswerRenderer.Render(parameters); } var textPosition = new Vector2( window.AbsoluteClientRectangle.X + ((window.AbsoluteClientRectangle.Width - answer.Size.X) / 2), window.AbsoluteClientRectangle.Y + ((window.AbsoluteClientRectangle.Height - lineHeight) / 2)); Color textColor = answer.Answer == _answerSelectionManager.SelectedAnswer ? answer.SelectedAnswerForegroundColor.ToXnaColor() : answer.UnselectedAnswerForegroundColor.ToXnaColor(); parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, new ScissoringRasterizerState(), null, transformMatrix); parameters.SpriteBatch.DrawStringWithShadow( font, answer.Text, textPosition.Round(), textColor * Alpha, shadowColor, Vector2.One); parameters.SpriteBatch.End(); position.X += window.WindowRectangle.Width + TextAdventure.Xna.Constants.MessageRenderer.AnswerHorizontalPadding; } }
protected override void RenderContents(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); using (new ScissorRectangleContext(parameters.SpriteBatch.GraphicsDevice, Window.AbsoluteClientRectangle)) { RenderMessage(parameters); if (_formatter.TotalHeightAfterFormatting > Window.AbsoluteClientRectangle.Height) { RenderScrollArrows(parameters); } } }
protected override void RenderContents(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); SpriteFont font = parameters.FontContent.Calibri10PtBold; string gameTimeText = String.Format( TimeFormat, parameters.GameTime.TotalGameTime.Hours, parameters.GameTime.TotalGameTime.Minutes, parameters.GameTime.TotalGameTime.Seconds, parameters.GameTime.TotalGameTime.Milliseconds / 100); string worldTimeText = String.Format( TimeFormat, _state.TotalWorldTime.Hours, _state.TotalWorldTime.Minutes, _state.TotalWorldTime.Seconds, _state.TotalWorldTime.Milliseconds / 100); parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); parameters.SpriteBatch.DrawStringWithShadow( font, gameTimeText, TextDrawingHelper.Instance.GetAlignedOrigin(font, gameTimeText, Window.AbsoluteClientRectangle, WindowAlignment.TopRight).ToVector2(), Color.White, Color.Black, Constants.WorldTimeRenderer.ShadowOffset); Vector2 worldTimePosition = TextDrawingHelper.Instance.GetAlignedOrigin(font, worldTimeText, Window.AbsoluteClientRectangle, WindowAlignment.TopRight).ToVector2(); worldTimePosition.Y += font.LineSpacing + Constants.WorldTimeRenderer.ShadowOffset.Y; parameters.SpriteBatch.DrawStringWithShadow( font, worldTimeText, worldTimePosition, _state.Paused ? Constants.WorldTimeRenderer.PausedColor : Constants.WorldTimeRenderer.UnpausedColor, Constants.WorldTimeRenderer.ShadowColor, Constants.WorldTimeRenderer.ShadowOffset); string speedText; if (_state.Paused) { speedText = "Paused"; } else if (_state.Speed < 1) { speedText = String.Format("1/{0} speed", (int)Math.Round(1 / _state.Speed)); } else if (new FloatToInt(_state.Speed) == 1) { speedText = "Normal speed"; } else { speedText = (int)_state.Speed + "x speed"; } parameters.SpriteBatch.DrawStringWithShadow( font, speedText, TextDrawingHelper.Instance.GetAlignedOrigin(font, speedText, Window.AbsoluteClientRectangle, WindowAlignment.BottomRight).ToVector2(), _state.Paused ? Constants.WorldTimeRenderer.PausedColor : Constants.WorldTimeRenderer.UnpausedColor, Constants.WorldTimeRenderer.ShadowColor, Constants.WorldTimeRenderer.ShadowOffset); parameters.SpriteBatch.End(); }
protected override void BeforeRender(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); base.BeforeRender(parameters); WindowTexture windowWindowTexture = parameters.TextureContent.Windows.InnerBevel1; if (!_windowRectangleSet) { var messageWithBackgroundColor = _state.Message as IMessageWithBackgroundColor; if (messageWithBackgroundColor != null) { BackgroundColor = messageWithBackgroundColor.BackgroundColor.ToXnaColor(); } WindowTexture selectedAnswerWindowTexture = parameters.TextureContent.Windows.Glow1; SpriteFont font = parameters.FontContent.Calibri12Pt; Rectangle destinationRectangle = Constants.GameWindow.DestinationRectangle; float maximumLineWidth = destinationRectangle.Width * TextAdventure.Xna.Constants.MessageRenderer.MaximumLineWidthAsPercentageOfGameWindowDestinationRectangle; float maximumClientHeight = destinationRectangle.Height - (destinationRectangle.Center.Y + TextAdventure.Xna.Constants.MessageRenderer.VerticalOffsetFromGameWindowDestinationRectangleCenter) - (TextAdventure.Xna.Constants.MessageRenderer.VerticalWindowPadding * 2) - (windowWindowTexture.SpriteHeight * 2); _formatter = new MessageFormatter(_state.Message, font, selectedAnswerWindowTexture, maximumLineWidth); if (_formatter.Answers.Any()) { _answerSelectionManager = new MessageAnswerSelectionManager(_formatter.Answers); } int clientWidth = _formatter.MaximumLineWidthAfterFormatting.Round(); int clientHeight = Math.Min(maximumClientHeight, _formatter.TotalHeightAfterFormatting).Round(); if (clientHeight < _formatter.TotalHeightAfterFormatting) { clientWidth += TextAdventure.Xna.Constants.MessageRenderer.ArrowHorizontalPadding + windowWindowTexture.SpriteWidth; } SetWindowRectangleUsingWindowYAndClientSize( WindowHorizontalAlignment.Center, destinationRectangle.Center.Y + TextAdventure.Xna.Constants.Tile.TileHeight * 2, clientWidth, clientHeight, windowWindowTexture.Padding); _windowRectangleSet = true; //_textTexture = new Texture2D(_state.GraphicsDevice, clientWidth, clientHeight); _state.AnswerSelectionManager = _answerSelectionManager; _state.MaximumScrollPosition = _formatter.TotalHeightAfterFormatting - clientHeight; _state.VisibleHeight = clientHeight; } Alpha = _state.Alpha; _transformMatrix = Matrix.CreateTranslation(new Vector3(-Window.WindowRectangle.Center.ToVector2(), 0f)) * Matrix.CreateScale(_state.Scale, _state.Scale, 1f) * Matrix.CreateTranslation(new Vector3(Window.WindowRectangle.Center.ToVector2(), 0f)); }
protected virtual void BeforeRender(RendererParameters parameters) { }
public void Render(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); IEnumerable<ILayer> layers = new ILayer[] { _state.Board.BackgroundLayer, _state.Board.ForegroundLayer, _state.Board.ActorInstanceLayer }; Point topLeftPoint; Coordinate topLeftCoordinate; Coordinate bottomRightCoordinate; GetDrawingParameters( _state.Board, _state.Player, out topLeftPoint, out topLeftCoordinate, out bottomRightCoordinate); parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); foreach (ILayer layer in layers) { IEnumerable<Tile> tiles = layer.Tiles.Where( arg => arg.Coordinate.X >= topLeftCoordinate.X && arg.Coordinate.X <= bottomRightCoordinate.X && arg.Coordinate.Y >= topLeftCoordinate.Y && arg.Coordinate.Y <= bottomRightCoordinate.Y); foreach (Tile tile in tiles) { Rectangle destinationRectangle = GetTileDestinationRectangle(topLeftPoint, topLeftCoordinate, tile.Coordinate); parameters.SpriteBatch.Draw(parameters.TextureContent.Pixel, destinationRectangle, parameters.TextureContent.Pixel.Bounds, tile.Character.BackgroundColor.ToXnaColor()); Rectangle symbolSourceRectangle = CharacterTextureHelper.GetSymbolSourceRectangle(tile.Character.Symbol); parameters.SpriteBatch.Draw(parameters.TextureContent.Characters, destinationRectangle, symbolSourceRectangle, tile.Character.ForegroundColor.ToXnaColor()); } } foreach (BoardExit boardExit in _state.Board.Exits) { Coordinate coordinate = boardExit.Coordinate; byte symbol; switch (boardExit.Direction) { case BoardExitDirection.Up: coordinate.Y--; symbol = TextAdventure.Xna.Constants.BoardRenderer.BoardExitUpSymbol; break; case BoardExitDirection.Down: coordinate.Y++; symbol = TextAdventure.Xna.Constants.BoardRenderer.BoardExitDownSymbol; break; case BoardExitDirection.Left: coordinate.X--; symbol = TextAdventure.Xna.Constants.BoardRenderer.BoardExitLeftSymbol; break; case BoardExitDirection.Right: coordinate.X++; symbol = TextAdventure.Xna.Constants.BoardRenderer.BoardExitRightSymbol; break; default: throw new Exception(String.Format("Unexpected board exit direction '{0}'.", boardExit.Direction)); } Rectangle destinationRectangle = GetTileDestinationRectangle(topLeftPoint, topLeftCoordinate, coordinate); Rectangle symbolSourceRectangle = CharacterTextureHelper.GetSymbolSourceRectangle(symbol); parameters.SpriteBatch.Draw(parameters.TextureContent.Characters, destinationRectangle, symbolSourceRectangle, TextAdventure.Xna.Constants.BoardRenderer.BoardExitSymbolColor); } parameters.SpriteBatch.End(); }
protected virtual void RenderContents(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); }
public abstract void Render(RendererParameters parameters);
protected override void RenderBorder(RendererParameters parameters) { using (new SpriteBatchContext(_transformMatrix)) { base.RenderBorder(parameters); } }
protected virtual void RenderBorder(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); Texture2D pixelTexture = parameters.TextureContent.Pixel; SpriteBatchContext spriteBatchContext = SpriteBatchContext.Current ?? SpriteBatchContext.Default; Vector2 origin = spriteBatchContext.Origin; parameters.SpriteBatch.Begin( SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, RasterizerState.CullNone, spriteBatchContext.Effect, spriteBatchContext.TransformMatrix); parameters.SpriteBatch.Draw(pixelTexture, Window.TopLeftCornerRectangle, pixelTexture.Bounds, BorderColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(pixelTexture, Window.TopRectangle, pixelTexture.Bounds, BorderColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(pixelTexture, Window.TopRightCornerRectangle, pixelTexture.Bounds, BorderColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(pixelTexture, Window.RightRectangle, pixelTexture.Bounds, BorderColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(pixelTexture, Window.BottomRightCornerRectangle, pixelTexture.Bounds, BorderColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(pixelTexture, Window.BottomRectangle, pixelTexture.Bounds, BorderColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(pixelTexture, Window.BottomLeftCornerRectangle, pixelTexture.Bounds, BorderColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.Draw(pixelTexture, Window.LeftRectangle, pixelTexture.Bounds, BorderColor, 0f, origin, SpriteEffects.None, 0f); parameters.SpriteBatch.End(); }
public void Render(RendererParameters parameters) { parameters.ThrowIfNull("parameters"); IEnumerable <ILayer> layers = new ILayer[] { _state.Board.BackgroundLayer, _state.Board.ForegroundLayer, _state.Board.ActorInstanceLayer }; Point topLeftPoint; Coordinate topLeftCoordinate; Coordinate bottomRightCoordinate; GetDrawingParameters( _state.Board, _state.Player, out topLeftPoint, out topLeftCoordinate, out bottomRightCoordinate); parameters.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); foreach (ILayer layer in layers) { IEnumerable <Tile> tiles = layer.Tiles.Where( arg => arg.Coordinate.X >= topLeftCoordinate.X && arg.Coordinate.X <= bottomRightCoordinate.X && arg.Coordinate.Y >= topLeftCoordinate.Y && arg.Coordinate.Y <= bottomRightCoordinate.Y); foreach (Tile tile in tiles) { Rectangle destinationRectangle = GetTileDestinationRectangle(topLeftPoint, topLeftCoordinate, tile.Coordinate); parameters.SpriteBatch.Draw(parameters.TextureContent.Pixel, destinationRectangle, parameters.TextureContent.Pixel.Bounds, tile.Character.BackgroundColor.ToXnaColor()); Rectangle symbolSourceRectangle = CharacterTextureHelper.GetSymbolSourceRectangle(tile.Character.Symbol); parameters.SpriteBatch.Draw(parameters.TextureContent.Characters, destinationRectangle, symbolSourceRectangle, tile.Character.ForegroundColor.ToXnaColor()); } } foreach (BoardExit boardExit in _state.Board.Exits) { Coordinate coordinate = boardExit.Coordinate; byte symbol; switch (boardExit.Direction) { case BoardExitDirection.Up: coordinate.Y--; symbol = TextAdventure.Xna.Constants.BoardRenderer.BoardExitUpSymbol; break; case BoardExitDirection.Down: coordinate.Y++; symbol = TextAdventure.Xna.Constants.BoardRenderer.BoardExitDownSymbol; break; case BoardExitDirection.Left: coordinate.X--; symbol = TextAdventure.Xna.Constants.BoardRenderer.BoardExitLeftSymbol; break; case BoardExitDirection.Right: coordinate.X++; symbol = TextAdventure.Xna.Constants.BoardRenderer.BoardExitRightSymbol; break; default: throw new Exception(String.Format("Unexpected board exit direction '{0}'.", boardExit.Direction)); } Rectangle destinationRectangle = GetTileDestinationRectangle(topLeftPoint, topLeftCoordinate, coordinate); Rectangle symbolSourceRectangle = CharacterTextureHelper.GetSymbolSourceRectangle(symbol); parameters.SpriteBatch.Draw(parameters.TextureContent.Characters, destinationRectangle, symbolSourceRectangle, TextAdventure.Xna.Constants.BoardRenderer.BoardExitSymbolColor); } parameters.SpriteBatch.End(); }