示例#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>
 public virtual void Render(Surfaces.SurfaceBase surface, bool force = false)
 {
     RenderBegin(surface, force);
     RenderCells(surface, force);
     RenderTint(surface, force);
     RenderEnd(surface, force);
 }
示例#2
0
        public virtual void Draw(Surfaces.SurfaceBase surface, Rectangle area, object item, ControlStates itemState)
        {
            if (item is Color || item is Tuple <Color, Color, string> )
            {
                string value = new string(' ', area.Width - 2);

                Cell cellLook = GetStateAppearance(itemState).Clone();

                if (item is Color color)
                {
                    cellLook.Background = color;
                    surface.Print(area.Left + 1, area.Top, value, cellLook);
                }
                else
                {
                    cellLook.Foreground = ((Tuple <Color, Color, string>)item).Item2;
                    cellLook.Background = ((Tuple <Color, Color, string>)item).Item1;
                    value = ((Tuple <Color, Color, string>)item).Item3.Align(HorizontalAlignment.Left, area.Width - 2);
                    surface.Print(area.Left + 1, area.Top, value, cellLook);
                }

                surface.Print(area.Left, area.Top, " ", cellLook);
                surface.Print(area.Left + area.Width - 1, area.Top, " ", cellLook);

                if (itemState.HasFlag(ControlStates.Clicked))
                {
                    surface.SetGlyph(area.Left, area.Top, 16);
                    surface.SetGlyph(area.Left + area.Width - 1, area.Top, 17);
                }
            }
            else
            {
                base.Draw(surface, area, item, itemState);
            }
        }
示例#3
0
        public virtual void RenderBegin(Surfaces.SurfaceBase 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);
            }
        }
示例#4
0
        public virtual void RenderEnd(Surfaces.SurfaceBase surface, bool force = false)
        {
            if (surface.IsDirty || force)
            {
                AfterRenderCallback?.Invoke(Global.SpriteBatch);

                Global.SpriteBatch.End();

                surface.IsDirty = false;

                Global.GraphicsDevice.SetRenderTarget(null);
            }
        }
示例#5
0
        /// <summary>
        /// Renders a surface to the screen.
        /// </summary>
        /// <param name="surface">The surface to render.</param>
        public override void Render(Surfaces.SurfaceBase surface, bool force = false)
        {
            RenderBegin(surface, force);
            RenderCells(surface, force);

            foreach (var control in Controls)
            {
                RenderControlCells(control, surface.IsDirty || force);
            }

            //RenderControls(surface, force);
            RenderTint(surface, force);
            RenderEnd(surface, force);
        }
示例#6
0
        public virtual void Draw(Surfaces.SurfaceBase surface, Rectangle area, object item, ControlStates itemState)
        {
            string value = item.ToString();

            if (value.Length < area.Width)
            {
                value += new string(' ', area.Width - value.Length);
            }
            else if (value.Length > area.Width)
            {
                value = value.Substring(0, area.Width);
            }
            if (Helpers.HasFlag(itemState, ControlStates.Selected) && !Helpers.HasFlag(itemState, ControlStates.MouseOver))
            {
                surface.Print(area.Left, area.Top, value, Selected);
            }
            else
            {
                surface.Print(area.Left, area.Top, value, GetStateAppearance(itemState));
            }
        }
示例#7
0
        public virtual void RenderCells(Surfaces.SurfaceBase surface, bool force = false)
        {
            if (surface.IsDirty || force)
            {
                if (surface.Tint.A != 255)
                {
                    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 (var i = 0; i < surface.RenderCells.Length; i++)
                    {
                        ref var cell = ref surface.RenderCells[i];

                        if (!cell.IsVisible)
                        {
                            continue;
                        }

                        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);
                        }

                        foreach (var decorator in cell.Decorators)
                        {
                            if (decorator.Color != Color.Transparent)
                            {
                                Global.SpriteBatch.Draw(surface.Font.FontImage, surface.RenderRects[i], surface.Font.GlyphRects[decorator.Glyph], decorator.Color, 0f, Vector2.Zero, decorator.Mirror, 0.5f);
                            }
                        }
                    }
                }
            }
        public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, Surfaces.SurfaceBase surface, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
        {
            if (CommandType == CommandTypes.Background)
            {
                glyphState.Background = GradientString[Length - Counter].Foreground;
            }
            else
            {
                glyphState.Foreground = GradientString[Length - Counter].Foreground;
            }

            Counter--;

            if (Counter == 0)
            {
                commandStack.RemoveSafe(this);
            }
        }
示例#9
0
 /// <summary>
 /// Builds a glyph.
 /// </summary>
 /// <param name="glyphState">The current glyph being built.</param>
 /// <param name="glyphString">The current string of glyphs that has been processed until now.</param>
 /// <param name="surfaceIndex">Where on the surface this flyph will appear.</param>
 /// <param name="surface">The surface associated with the glyph.</param>
 /// <param name="stringIndex">Where in the original string this glyph is from.</param>
 /// <param name="processedString">The entire string being processed.</param>
 /// <param name="commandStack">The state of commands.</param>
 public abstract void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, Surfaces.SurfaceBase surface, ref int stringIndex, string processedString, ParseCommandStacks commandStack);
示例#10
0
        public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, Surfaces.SurfaceBase surface, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
        {
            if (RandomGlyph)
            {
                glyphState.GlyphCharacter = (char)SadConsole.Global.Random.Next(RandomGlyphMin, RandomGlyphMax);
            }
            else
            {
                glyphState.GlyphCharacter = Glyph;
            }

            if (Counter != -1)
            {
                Counter--;
            }

            if (Counter == 0)
            {
                commandStack.RemoveSafe(this);
            }
        }
        public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, Surfaces.SurfaceBase surface, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
        {
            glyphState.Effect = BlinkEffect;

            if (Counter != -1)
            {
                Counter--;

                if (Counter == 0)
                {
                    commandStack.RemoveSafe(this);
                }
            }
        }
示例#12
0
        public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, Surfaces.SurfaceBase surface, ref int stringIndex, string processedString, ParseCommandStacks commandStack)
        {
            Color newColor;

            if (Default)
            {
                if (CommandType == CommandTypes.Background)
                {
                    newColor = surface != null ? surface.DefaultBackground : Color.Transparent;
                }
                else
                {
                    newColor = surface != null ? surface.DefaultForeground : Color.White;
                }
            }
            else
            {
                if (CommandType == CommandTypes.Background)
                {
                    newColor = glyphState.Background;
                }
                else
                {
                    newColor = glyphState.Foreground;
                }

                if (!KeepRed)
                {
                    newColor.R = R;
                }
                if (!KeepGreen)
                {
                    newColor.G = G;
                }
                if (!KeepBlue)
                {
                    newColor.B = B;
                }
                if (!KeepAlpha)
                {
                    newColor.A = A;
                }
            }

            if (CommandType == CommandTypes.Background)
            {
                glyphState.Background = newColor;
            }
            else
            {
                glyphState.Foreground = newColor;
            }

            if (Counter != -1)
            {
                Counter--;

                if (Counter == 0)
                {
                    commandStack.RemoveSafe(this);
                }
            }
        }