public static void CreateClouds(int effectMinY, int effectMaxY, List <CloudParticle> clouds, Random random) { var cloudPoint = new Point(0, random.Next(effectMinY, effectMaxY)); var cloudParticle = new ColoredGlyph(new Color(204 + random.Next(0, 51), 0, 204 + random.Next(0, 51)), Color.Transparent, GetRandomChar()); clouds.Add(new CloudParticle(cloudPoint, cloudParticle)); double i = 1; while (random.NextDouble() < 0.9) { cloudPoint += new Point(-1, (random.Next(0, 5) - 2) / 2); cloudParticle = new ColoredGlyph(new Color(204 + random.Next(0, 51), 0, 225 + random.Next(0, 25)), Color.Transparent, GetRandomChar()); clouds.Add(new CloudParticle(cloudPoint, cloudParticle)); for (int y = 1; y < random.Next(2, 5); y++) { var verticalPoint = cloudPoint + new Point(0, y); cloudParticle = new ColoredGlyph(new Color(225 + random.Next(0, 25), 153 + random.Next(102), 225 + random.Next(0, 25)), Color.Transparent, GetRandomChar()); clouds.Add(new CloudParticle(verticalPoint, cloudParticle)); } i++; } char GetRandomChar() { const string vwls = "?&%~=+;"; return(vwls[random.Next(vwls.Length)]); } }
/// <summary> /// Creates a new terrain object. /// </summary> /// <param name="appearance">The true appearance of the cell.</param> /// <param name="layer">The map layer to which this cell is added</param> /// <param name="walkable">Whether the cell is considered walkable in collision detection</param> /// <param name="transparent">Whether the cell is considered transparent in field-of-view algorithms</param> /// <param name="idGenerator">The function which produces the unique ID for this cell</param> /// <param name="customComponentContainer">Accepts a custom collection</param> public MemoryAwareRogueLikeCell(ColoredGlyph appearance, int layer, bool walkable = true, bool transparent = true, Func <uint>?idGenerator = null, IComponentCollection?customComponentContainer = null) : this(new Point(0, 0), appearance, layer, walkable, transparent, idGenerator, customComponentContainer) { }
public void Copy_SameSizeRegion_IntoBigger() { new SadConsole.Tests.BasicGameHost(); var surface1 = new SadConsole.CellSurface(20, 20); var surface2 = new SadConsole.CellSurface(22, 22); ColoredGlyph defaultCell = new ColoredGlyph(); surface2[0].CopyAppearanceTo(defaultCell); surface1.FillWithRandomGarbage(255); surface1.Copy(surface2); for (int y = 0; y < surface2.Height; y++) { for (int x = 0; x < surface2.Width; x++) { if (x > surface1.Width - 1 || y > surface1.Height - 1) { Assert.IsTrue(surface2[x, y].Matches(defaultCell)); } else { Assert.IsTrue(surface1[x, y].Matches(surface2[x, y])); } } } }
private static void CopyAppearance(ColoredGlyph to, ColoredGlyph from) { to.Foreground = from.Foreground; to.Background = from.Background; to.Mirror = from.Mirror; to.Decorators = from.Decorators; }
/// <inheritdoc /> public override bool ApplyToCell(ColoredGlyph cell, EffectsManager.ColoredGlyphState originalState) { Color oldForeground = cell.Foreground; Color oldBackground = cell.Background; if (FadeForeground) { if (UseCellForeground) { DestinationForeground.Stops[UseCellDestinationReverse ? DestinationForeground.Stops.Length - 1 : 0].Color = originalState.Foreground; } cell.Foreground = DestinationForeground.Lerp((float)_calculatedValue); } if (FadeBackground) { if (UseCellBackground) { DestinationBackground.Stops[UseCellDestinationReverse ? DestinationBackground.Stops.Length - 1 : 0].Color = originalState.Background; } cell.Background = DestinationBackground.Lerp((float)_calculatedValue); } return(oldForeground != cell.Foreground || oldBackground != cell.Background); }
/// <inheritdoc /> public override void UpdateAndDraw(ControlBase control, TimeSpan time) { if (!(control is Button button)) { return; } if (!button.IsDirty) { return; } RefreshTheme(control.FindThemeColors(), control); ColoredGlyph appearance = ControlThemeState.GetStateAppearance(control.State); int middle = button.Height != 1 ? button.Height / 2 : 0; var shadowBounds = new Rectangle(0, 0, button.Width, button.Height).WithPosition((2, 1)); button.Surface.Clear(); if (appearance.Matches(ControlThemeState.MouseDown)) { middle += 1; // Redraw the control button.Surface.Fill(shadowBounds, appearance.Foreground, appearance.Background, appearance.Glyph, null); button.Surface.Print(shadowBounds.X, middle, button.Text.Align(button.TextAlignment, button.Width)); button.MouseArea = new Rectangle(0, 0, button.Width + 2, button.Height + 1); } else { // Redraw the control button.Surface.Fill(new Rectangle(0, 0, button.Width, button.Height), appearance.Foreground, appearance.Background, appearance.Glyph, null); button.Surface.Print(0, middle, button.Text.Align(button.TextAlignment, button.Width)); // Bottom line button.Surface.DrawLine(new Point(shadowBounds.X, shadowBounds.MaxExtentY), new Point(shadowBounds.MaxExtentX, shadowBounds.MaxExtentY), _shade.Glyph, _shade.Foreground, _shade.Background); // Side line 1 button.Surface.DrawLine(new Point(shadowBounds.MaxExtentX - 1, shadowBounds.Y), new Point(shadowBounds.MaxExtentX, shadowBounds.MaxExtentY), _shade.Glyph, _shade.Foreground, _shade.Background); // Side line 2 button.Surface.DrawLine(new Point(shadowBounds.MaxExtentX, shadowBounds.Y), new Point(shadowBounds.MaxExtentX, shadowBounds.MaxExtentY), _shade.Glyph, _shade.Foreground, _shade.Background); button.MouseArea = new Rectangle(0, 0, button.Width, button.Height); } button.IsDirty = false; }
/// <summary> /// Creates a new entity. /// </summary> /// <param name="appearance">The appearance of the entity when displayed. No copy will be made of this value; the given instance will be used directly.</param> /// <param name="walkable">Whether or not the entity can be walked through.</param> /// <param name="transparent">Whether or not the entity is transparent for the purposes of FOV.</param> /// <param name="layer">The layer on which the entity resides. Must NOT be 0, because layer 0 is reserved for terrain.</param> /// <param name="idGenerator"> /// The function used to generate and return an unsigned integer to use assign to the <see cref="ID" /> field. /// Most of the time, you will not need to specify this as the default implementation will be sufficient. /// </param> /// <param name="customComponentCollection"> /// A custom component collection to use for objects. If not specified, a <see cref="ComponentCollection"/> is /// used. Typically you will not need to specify this, as a ComponentCollection is sufficient for nearly all /// use cases. /// </param> public RogueLikeEntity(ref ColoredGlyph appearance, bool walkable = true, bool transparent = true, int layer = 1, Func <uint>?idGenerator = null, IComponentCollection?customComponentCollection = null) : this(new Point(0, 0), ref appearance, walkable, transparent, layer, idGenerator, customComponentCollection) { }
/// <summary> /// /// </summary> /// <param name="cell">The glyph to be drawn.</param> /// <param name="targetRect">Where on the <see cref="Host.Global.SharedSpriteBatch"/> the glyph should be drawn.</param> /// <param name="font">The font to use when drawing the glyph.</param> /// <param name="drawBackground">When <see langword="true"/>, draws the <see cref="ColoredGlyph.Background"/> color for the glyph; otherwise <see langword="false"/>.</param> public DrawCallCell(SadConsole.ColoredGlyph cell, Rectangle targetRect, IFont font, bool drawBackground) { Font = font; TargetRect = targetRect; Cell = cell; DrawBackground = drawBackground; }
/// <summary> /// Creates a new instance of this draw call. /// </summary> /// <param name="cell">The glyph to be drawn.</param> /// <param name="texture">The texture containing the cell.</param> /// <param name="targetRect">Where on the <see cref="Host.Global.SharedSpriteBatch"/> the glyph should be drawn.</param> /// <param name="fontGlyphRect">The rectangle from the <see cref="Texture"/> of the glyph.</param> /// <param name="fontSolidRect">The solid white glyph rectangle from <see cref="Texture"/> used for shading.</param> public DrawCallGlyph(ColoredGlyph cell, Texture2D texture, Rectangle targetRect, Rectangle fontGlyphRect, Rectangle fontSolidRect) { Texture = texture; FontGlyphRect = fontGlyphRect; FontSolidRect = fontSolidRect; TargetRect = targetRect; Cell = cell; }
public static void DrawVerticalLine(this CellSurface surface, int x, int y, int length, ColoredGlyph coloredGlyph) { for (var dY = 0; dY < length; dY++) { surface.Print(x, y + dY, coloredGlyph); } }
public void Filter(int x, int y, ref ColoredGlyph cg) { var value = Math.Sin(time[x, y] * 2 * Math.PI / cycle); float brightness = cg.Foreground.GetBrightness(); brightness = (float)Math.Clamp(brightness + value * brightness / 4, 0, 1); cg.Foreground = cg.Foreground.SetBrightness(brightness); }
public FlickerParticle(XYZ Position, XYZ Velocity, double lifetime, params ColoredGlyph[] symbols) { this.Position = Position; this.Velocity = Velocity; this.lifetime = lifetime; this.symbols = symbols; this.symbolInterval = 0.5; this.symbol = symbols[0]; }
/// <summary> /// Creates a new state from a cell. /// </summary> /// <param name="cell">The colored glyph this state is a copy of.</param> public ColoredGlyphState(ColoredGlyph cell) { Foreground = cell.Foreground; Background = cell.Background; Mirror = cell.Mirror; Glyph = cell.Glyph; IsVisible = cell.IsVisible; Decorators = cell.Decorators.Length != 0 ? cell.Decorators.ToArray() : Array.Empty <CellDecorator>(); }
/// <summary> /// Sets all Appearance* properties based on the existing colors and settings. /// </summary> public virtual void RebuildAppearances() { Appearance_ControlNormal = new ColoredGlyph(ControlForegroundNormal, ControlBackgroundNormal); Appearance_ControlDisabled = new ColoredGlyph(ControlForegroundDisabled, ControlBackgroundDisabled); Appearance_ControlOver = new ColoredGlyph(ControlForegroundMouseOver, ControlBackgroundMouseOver); Appearance_ControlMouseDown = new ColoredGlyph(ControlForegroundMouseDown, ControlBackgroundMouseDown); Appearance_ControlSelected = new ColoredGlyph(ControlForegroundSelected, ControlBackgroundSelected); Appearance_ControlFocused = new ColoredGlyph(ControlForegroundFocused, ControlBackgroundFocused); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { ColoredGlyph c = value as ColoredGlyph; var elements = new List <uint> { c.Foreground.PackedValue, c.Background.PackedValue, (uint)c.Glyph }; return(string.Join(',', elements)); }
/// <summary> /// Restores this state to the specified cell. /// </summary> public void RestoreState(ref ColoredGlyph cell) { cell.Foreground = Foreground; cell.Background = Background; cell.Mirror = Mirror; cell.Glyph = Glyph; cell.IsVisible = IsVisible; cell.Decorators = Decorators.Length != 0 ? Decorators.ToArray() : Array.Empty <CellDecorator>(); }
public BorderComponent(int[] connectedLineStyle, Color foreground, Color background) { if (!ICellSurface.ValidateLineStyle(connectedLineStyle)) { throw new ArgumentException("The connected line array is invalid.", nameof(connectedLineStyle)); } _borderGlyphs = connectedLineStyle; _borderCellStyle = new ColoredGlyph(foreground, background); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var elements = Convert.ToString(value).Trim('(', ')').Split(',', StringSplitOptions.RemoveEmptyEntries); var result = new ColoredGlyph( new Color(uint.Parse(elements[0])), new Color(uint.Parse(elements[1])), (int)uint.Parse(elements[2])); return(result); }
/// <summary> /// Creates a new terrain object. /// </summary> /// <param name="position">Where the cell is located</param> /// <param name="appearance">The true appearance of the cell.</param> /// <param name="layer">The map layer to which this cell is added</param> /// <param name="walkable">Whether the cell is considered walkable in collision detection</param> /// <param name="transparent">Whether the cell is considered transparent in field-of-view algorithms</param> /// <param name="idGenerator">The function which produces the unique ID for this cell</param> /// <param name="customComponentContainer">Accepts a custom collection</param> public MemoryAwareRogueLikeCell(Point position, ColoredGlyph appearance, int layer, bool walkable = true, bool transparent = true, Func <uint>?idGenerator = null, IComponentCollection?customComponentContainer = null) : base(position, appearance, layer, walkable, transparent, idGenerator, customComponentContainer) { // Given appearance was assigned to Appearance, so copy it to TrueAppearance TrueAppearance = new TerrainAppearance(Appearance.Terrain, Appearance); // Since the tile hasn't been seen, make it invisible. LastSeenAppearance.IsVisible = false; }
private void SetEditCell(ColoredGlyph cell) { if (cell == null) { return; } cell.CopyAppearanceTo(this[Width - 3, Height - 3]); IsDirty = true; }
ParseCommandBase CustomParseCommand(string command, string parameters, ColoredGlyph[] glyphString, ITextSurface surface, SurfaceEditor editor, ParseCommandStacks commandStacks) { switch (command) { case "t": return new ParseCommandRetext(parameters); default: return null; ; } }
private MouseScreenObjectState(MouseScreenObjectState clonedCopy) { ScreenObject = clonedCopy.ScreenObject; Mouse = clonedCopy.Mouse.Clone(); Cell = clonedCopy.Cell; SurfaceCellPosition = clonedCopy.SurfaceCellPosition; CellPosition = clonedCopy.CellPosition; WorldCellPosition = clonedCopy.WorldCellPosition; SurfacePixelPosition = clonedCopy.SurfacePixelPosition; IsOnScreenObject = clonedCopy.IsOnScreenObject; }
/// <inheritdoc /> public override bool ApplyToCell(ColoredGlyph cell, EffectsManager.ColoredGlyphState originalState) { if (_activeEffect != null) { return(_activeEffect.ApplyToCell(cell, originalState)); } else { return(false); } }
public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, 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); }
public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, ref int stringIndex, string processedString, ParseCommandStacks commandStack) { glyphState.Effect = BlinkEffect; if (Counter != -1) { Counter--; if (Counter == 0) commandStack.RemoveSafe(this); } }
public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, 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; } newColor = Color.FromArgb(KeepAlpha ? newColor.A : A, KeepRed ? newColor.R : R, KeepGreen ? newColor.G : G, KeepBlue ? newColor.B : B ); } if (CommandType == CommandTypes.Background) { glyphState.Background = newColor; } else { glyphState.Foreground = newColor; } if (Counter != -1) { Counter--; if (Counter == 0) { commandStack.RemoveSafe(this); } } }
public ParseCommandBlink(string parameters, ColoredGlyph[] glyphString, ParseCommandStacks commandStack, SurfaceEditor surfaceEditor) { string[] parametersArray = parameters.Split(':'); if (parametersArray.Length == 2) Speed = double.Parse(parametersArray[1]); if (parametersArray.Length >= 1 && parametersArray[0] != "") Counter = int.Parse(parametersArray[0]); else Counter = -1; // Try sync with surface editor if (surfaceEditor != null) { var effects = surfaceEditor.Effects.GetEffects(); if (effects != null) { var existingBlinks = new List<SadConsole.Effects.ICellEffect>(effects); foreach (var item in existingBlinks) { if (item is CustomBlinkEffect) { if (Speed == ((CustomBlinkEffect)item).BlinkSpeed) BlinkEffect = (CustomBlinkEffect)item; break; } } } } // Failed, look within this parse for existing if (BlinkEffect == null) { foreach (var item in glyphString) { if (item.Effect != null && item.Effect is CustomBlinkEffect) if (Speed == ((CustomBlinkEffect)item.Effect).BlinkSpeed) BlinkEffect = (CustomBlinkEffect)item.Effect; } } if (BlinkEffect == null) BlinkEffect = new CustomBlinkEffect() { BlinkSpeed = Speed }; commandStack.TurnOnEffects = true; // No exceptions, set the type CommandType = CommandTypes.Effect; }
public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ISurface surface, SurfaceEditor editor, ref int stringIndex, string processedString, ParseCommandStacks commandStack) { glyphState.Glyph = 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); } } }
/// <inheritdoc /> public override bool ApplyToCell(ColoredGlyph cell, EffectsManager.ColoredGlyphState originalState) { int oldGlyph = cell.Glyph; if (!_isOn) { cell.Glyph = GlyphIndex; } else { cell.Glyph = originalState.Glyph; } return(cell.Glyph != oldGlyph); }
private void PrintGlyph(ColoredGlyph glyph, ColoredString settings) { var console = (Console)_console.Target; var cell = console.TextSurface.Cells[_position.Y * console.TextSurface.Width + _position.X]; if (!PrintOnlyCharacterData) { if (!settings.IgnoreBackground) { cell.Background = glyph.Background; } if (!settings.IgnoreForeground) { cell.Foreground = glyph.Foreground; } if (!settings.IgnoreEffect) { cell.Effect = glyph.Effect; } if (!settings.IgnoreSpriteEffect) { cell.SpriteEffect = glyph.SpriteEffect; } } if (!settings.IgnoreGlyph) { cell.GlyphIndex = glyph.Glyph; } _position.X += 1; if (_position.X >= console.TextSurface.Width) { _position.X = 0; _position.Y += 1; if (_position.Y >= console.TextSurface.Height) { _position.Y -= 1; if (AutomaticallyShiftRowsUp) { console.ShiftUp(); } } } }
/// <inheritdoc /> public override bool ApplyToCell(ColoredGlyph cell, EffectsManager.ColoredGlyphState originalState) { Color oldForeground = cell.Foreground; Color oldBackground = cell.Background; if (DoBackground) { cell.Background = Background; } if (DoForeground) { cell.Foreground = Foreground; } return(oldForeground != cell.Foreground || oldBackground != cell.Background); }
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); } }
/// <summary> /// Changes the effect of a specific cell. /// </summary> /// <param name="cellIndex">Cell index to set the effect for.</param> /// <param name="effect">The effect to associate with the cell.</param> public void SetEffect(int cellIndex, ICellEffect effect) { ColoredGlyph cell = _backingSurface[cellIndex]; if (effect != null) { ColoredGlyphEffectData workingEffect; if (effect.CloneOnAdd) { effect = effect.Clone(); workingEffect = new ColoredGlyphEffectData(effect); _effects.Add(workingEffect.Effect, workingEffect); } else { // Is the effect unknown? Add it. if (GetKnownEffect(effect, out workingEffect) == false) { _effects.Add(workingEffect.Effect, workingEffect); } else { if (workingEffect.ContainsCell(cellIndex)) { // Make sure the effect is attached to the cell. return; } } } // Remove the targeted cell from the known cells list if it is already there (associated with another effect) ClearCellEffect(cellIndex); // Add the cell to the effects by cell key and to list of known cells for the effect _effectCells.Add(cellIndex, workingEffect); workingEffect.CellsStates.Add(new ColoredGlyphWithState(cell, cellIndex)); } else { ClearCellEffect(cellIndex); } }
public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, 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); } }
public EditableTextBlock() { InitializeComponent(); //Set up components CurrentGlyph = _editGlyph; _actionButton.Content = new FontIcon() { Glyph = CurrentGlyph.Glyph, Foreground = new SolidColorBrush(CurrentGlyph.Color)}; _actionButton.SetValue(Grid.ColumnProperty, 1); _actionButton.Margin = new Thickness(10, 0, 0, 0); //Add event handlers _actionButton.Click += ButtonBase_OnClick; OnIsEditingChanged += _OnIsEditingChanged; OnIsEditableChanged += _OnIsEditableChanged; RemovingChanged += _OnIsRemovableChanged; //Add components to page MainGrid.Children.Add(_actionButton); //Warm up events OnIsEditingChanged?.Invoke(IsEditing, GetValue(ItemProperty) as Item); OnIsEditableChanged?.Invoke(IsEditable); RemovingChanged?.Invoke(IsRemoving, GetValue(ItemProperty) as Item); }
/// <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, Consoles.ITextSurface 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 ParseCommandSpriteEffect(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.SpriteEffect.Count != 0) commandStacks.SpriteEffect.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 }; }
public override void Build(ref ColoredGlyph glyphState, ColoredGlyph[] glyphString, int surfaceIndex, ITextSurface surface, SurfaceEditor editor, ref int stringIndex, string processedString, ParseCommandStacks commandStack) { }
private void PrintGlyph(ColoredGlyph glyph, ColoredString settings) { var console = (SurfaceEditor)_console.Target; var cell = console.TextSurface.Cells[_position.Y * console.TextSurface.Width + _position.X]; if (!PrintOnlyCharacterData) { if (!settings.IgnoreBackground) cell.Background = glyph.Background; if (!settings.IgnoreForeground) cell.Foreground = glyph.Foreground; if (!settings.IgnoreEffect) cell.Effect = glyph.Effect; if (!settings.IgnoreSpriteEffect) cell.SpriteEffect = glyph.SpriteEffect; } if (!settings.IgnoreGlyph) cell.GlyphIndex = glyph.Glyph; _position.X += 1; if (_position.X >= console.TextSurface.Width) { _position.X = 0; _position.Y += 1; if (_position.Y >= console.TextSurface.Height) { _position.Y -= 1; if (AutomaticallyShiftRowsUp) { console.ShiftUp(); } } } }
private void UpdateGlyph() { if (IsRemoving) { CurrentGlyph = _deleteGlyph; } else if (IsEditable && !IsEditing) { CurrentGlyph = _editGlyph; } else if (IsEditable && IsEditing) { CurrentGlyph = _closeGlyph; } var fontIcon = _actionButton.Content as FontIcon; if (fontIcon != null) { fontIcon.Glyph = CurrentGlyph.Glyph; fontIcon.Foreground = new SolidColorBrush(CurrentGlyph.Color); } }