コード例 #1
0
 /// <summary>
 /// Renders the cached surface from a previous call to the constructor or the <see cref="Update(ISurfaceRendered)"/> method.
 /// </summary>
 /// <param name="surface">Used only for tinting.</param>
 /// <param name="renderingMatrix">Display matrix for the rendered console.</param>
 public virtual void Render(Surfaces.ISurface surface, bool force = false)
 {
     RenderBegin(surface, force);
     RenderCells(surface, force);
     RenderTint(surface, force);
     RenderEnd(surface, force);
 }
コード例 #2
0
        public virtual void RenderCells(Surfaces.ISurface surface, bool force = false)
        {
            if (surface.IsDirty || force)
            {
                if (surface.Tint.A != 255)
                {
                    Cell cell;

                    if (surface.DefaultBackground.A != 0)
                    {
                        Global.SpriteBatch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphRects[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.Background != Color.Transparent && cell.Background != surface.DefaultBackground)
                            {
                                Global.SpriteBatch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphRects[surface.Font.SolidGlyphIndex], cell.Background, 0f, Vector2.Zero, SpriteEffects.None, 0.3f);
                            }

                            if (cell.Foreground != Color.Transparent)
                            {
                                Global.SpriteBatch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphRects[cell.Glyph], cell.Foreground, 0f, Vector2.Zero, cell.Mirror, 0.4f);
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: SurfaceView.cs プロジェクト: x3nx1a/SadConsole
 public Surfaces.SurfaceView ToSurfaceView(Surfaces.ISurface originalSurface)
 {
     return(new Surfaces.SurfaceView(originalSurface, ViewArea)
     {
         Tint = Tint, DefaultForeground = DefaultForeground, DefaultBackground = DefaultBackground, Font = Font
     });
 }
コード例 #4
0
        public virtual void RenderEnd(Surfaces.ISurface surface, bool force = false)
        {
            if (surface.IsDirty || force)
            {
                AfterRenderCallback?.Invoke(Global.SpriteBatch);

                Global.SpriteBatch.End();

                surface.IsDirty = false;
            }
        }
コード例 #5
0
        public virtual void RenderBegin(Surfaces.ISurface surface, bool force = false)
        {
            if (surface.IsDirty || force)
            {
                Global.GraphicsDevice.SetRenderTarget(surface.LastRenderResult);
                Global.GraphicsDevice.Clear(Color.Transparent);

                Global.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone);

                BeforeRenderCallback?.Invoke(Global.SpriteBatch);
            }
        }
コード例 #6
0
        public virtual void RenderTint(Surfaces.ISurface surface, bool force = false)
        {
            if (surface.IsDirty || force)
            {
                BeforeRenderTintCallback?.Invoke(Global.SpriteBatch);

                if (surface.Tint.A != 0)
                {
                    Global.SpriteBatch.Draw(surface.Font.FontImage, surface.AbsoluteArea, surface.Font.GlyphRects[surface.Font.SolidGlyphIndex], surface.Tint, 0f, Vector2.Zero, SpriteEffects.None, 0.5f);
                }
            }
        }
コード例 #7
0
        public virtual void RenderEnd(Surfaces.ISurface surface, bool force = false)
        {
            if (surface.IsDirty || force)
            {
                AfterRenderCallback?.Invoke(Global.SpriteBatch);

                Global.SpriteBatch.End();

                surface.IsDirty = false;

                Global.GraphicsDevice.SetRenderTarget(null);
            }
        }
コード例 #8
0
        /// <summary>
        /// Creates a colored string by parsing commands embedded in the string.
        /// </summary>
        /// <param name="value">The string to parse.</param>
        /// <param name="surfaceIndex">Index of where this string will be printed.</param>
        /// <param name="surface">The surface the string will be printed to.</param>
        /// <param name="editor">A surface editor associated with the text surface.</param>
        /// <param name="initialBehaviors">Any initial defaults.</param>
        /// <returns></returns>
        public static ColoredString Parse(string value, int surfaceIndex = -1, Surfaces.ISurface surface = null, SurfaceEditor editor = null, ParseCommandStacks initialBehaviors = null)
        {
            var commandStacks          = initialBehaviors != null ? initialBehaviors : new ParseCommandStacks();
            List <ColoredGlyph> glyphs = new List <ColoredGlyph>(value.Length);

            for (int i = 0; i < value.Length; i++)
            {
                var existingGlyphs = glyphs.ToArray();

                if (value[i] == '`' && i + 1 < value.Length && value[i + 1] == '[')
                {
                    continue;
                }

                if (value[i] == '[' && (i == 0 || value[i - 1] != '`'))
                {
                    try
                    {
                        if (i + 4 < value.Length && value[i + 1] == 'c' && value[i + 2] == ':' && value.IndexOf(']', i + 2) != -1)
                        {
                            int    commandExitIndex = value.IndexOf(']', i + 2);
                            string command          = value.Substring(i + 3, commandExitIndex - (i + 3));
                            string commandParams    = "";

                            if (command.Contains(" "))
                            {
                                var commandSections = command.Split(new char[] { ' ' }, 2);
                                command       = commandSections[0].ToLower();
                                commandParams = commandSections[1];
                            }

                            // Check for custom command
                            ParseCommandBase commandObject = CustomProcessor != null?CustomProcessor(command, commandParams, existingGlyphs, surface, editor, commandStacks) : null;

                            // No custom command found, run build in ones
                            if (commandObject == null)
                            {
                                switch (command)
                                {
                                case "recolor":
                                case "r":
                                    commandObject = new ParseCommandRecolor(commandParams);
                                    break;

                                case "mirror":
                                case "m":
                                    commandObject = new ParseCommandMirror(commandParams);
                                    break;

                                case "undo":
                                case "u":
                                    commandObject = new ParseCommandUndo(commandParams, commandStacks);
                                    break;

                                case "grad":
                                case "g":
                                    commandObject = new ParseCommandGradient(commandParams);
                                    break;

                                case "blink":
                                case "b":
                                    commandObject = new ParseCommandBlink(commandParams, existingGlyphs, commandStacks, editor);
                                    break;

                                case "sglyph":
                                case "sg":
                                    commandObject = new ParseCommandSetGlyph(commandParams);
                                    break;

                                default:
                                    break;
                                }
                            }

                            if (commandObject != null && commandObject.CommandType != CommandTypes.Invalid)
                            {
                                commandStacks.AddSafe(commandObject);

                                i = commandExitIndex;
                                continue;
                            }
                        }
                    }
                    catch (System.Exception e1)
                    {
#if DEBUG
                        throw e1;
#endif
                    }
                }

                int fixedSurfaceIndex;

                if (surfaceIndex == -1 || surface == null)
                {
                    fixedSurfaceIndex = -1;
                }
                else
                {
                    fixedSurfaceIndex = i + surfaceIndex < surface.Cells.Length ? i + surfaceIndex : -1;
                }


                ColoredGlyph newGlyph;

                if (fixedSurfaceIndex != -1)
                {
                    newGlyph = new ColoredGlyph(surface[i + surfaceIndex])
                    {
                        Glyph = value[i]
                    }
                }
                ;
                else
                {
                    newGlyph = new ColoredGlyph(new Cell())
                    {
                        Glyph = value[i]
                    }
                };


                // Foreground
                if (commandStacks.Foreground.Count != 0)
                {
                    commandStacks.Foreground.Peek().Build(ref newGlyph, existingGlyphs, fixedSurfaceIndex, surface, editor, ref i, value, commandStacks);
                }

                // Background
                if (commandStacks.Background.Count != 0)
                {
                    commandStacks.Background.Peek().Build(ref newGlyph, existingGlyphs, fixedSurfaceIndex, surface, editor, ref i, value, commandStacks);
                }

                if (commandStacks.Glyph.Count != 0)
                {
                    commandStacks.Glyph.Peek().Build(ref newGlyph, existingGlyphs, fixedSurfaceIndex, surface, editor, ref i, value, commandStacks);
                }

                // SpriteEffect
                if (commandStacks.Mirror.Count != 0)
                {
                    commandStacks.Mirror.Peek().Build(ref newGlyph, existingGlyphs, fixedSurfaceIndex, surface, editor, ref i, value, commandStacks);
                }

                // Effect
                if (commandStacks.Effect.Count != 0)
                {
                    commandStacks.Effect.Peek().Build(ref newGlyph, existingGlyphs, fixedSurfaceIndex, surface, editor, ref i, value, commandStacks);
                }

                glyphs.Add(newGlyph);
            }

            return(new ColoredString(glyphs.ToArray())
            {
                IgnoreEffect = !commandStacks.TurnOnEffects
            });
        }
    }