/// <summary>
        /// Shows a window prompt with two buttons for the user to click.
        /// </summary>
        /// <param name="message">The text to display. (background color is ignored)</param>
        /// <param name="yesPrompt">The yes button's text.</param>
        /// <param name="noPrompt">The no button's text.</param>
        /// <param name="resultCallback">Callback with the yes (true) or no (false) result.</param>
        public static void Prompt(ColoredString message, string yesPrompt, string noPrompt, Action <bool> resultCallback)
        {
            message.IgnoreBackground = true;

            Themes.Library.Default.ButtonTheme = new Themes.ButtonLinesTheme();

            Button yesButton = new Button(yesPrompt.Length + 2, 1);
            Button noButton  = new Button(noPrompt.Length + 2, 1);

            Window window = new Window(message.ToString().Length + 4, 5 + yesButton.Surface.Height);

            window.Print(2, 2, message);

            yesButton.Position = new Point(2, window.Height - 1 - yesButton.Surface.Height);
            noButton.Position  = new Point(window.Width - noButton.Width - 2, window.Height - 1 - yesButton.Surface.Height);

            yesButton.Text = yesPrompt;
            noButton.Text  = noPrompt;

            yesButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); };
            noButton.Click  += (o, e) => { window.DialogResult = false; window.Hide(); };

            window.Add(yesButton);
            window.Add(noButton);

            window.Closed += (o, e) =>
            {
                resultCallback?.Invoke(window.DialogResult);
            };

            window.Show(true);
            window.Center();
        }
Exemple #2
0
        /// <summary>
        /// Displays a dialog to the user with a specific message.
        /// </summary>
        /// <param name="message">The message. (background color is ignored)</param>
        /// <param name="closeButtonText">The text of the dialog's close button.</param>
        /// <param name="closedCallback">A callback indicating the message was dismissed.</param>
        public static void Message(ColoredString message, string closeButtonText, Action closedCallback = null)
        {
            var width       = message.ToString().Length + 4;
            var buttonWidth = closeButtonText.Length + 2;

            if (buttonWidth < 9)
            {
                buttonWidth = 9;
            }

            if (width < buttonWidth + 4)
            {
                width = buttonWidth + 4;
            }

            Window window = new Window(width, 6);

            message.IgnoreBackground = true;

            window.Print(2, 2, message);

            Button closeButton = new Button(buttonWidth, 1);

            closeButton.Position = new Point(2, window.Height - 2);

            closeButton.Text = closeButtonText;

            closeButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); closedCallback?.Invoke(); };

            window.Add(closeButton);
            window.CloseOnESC = true;
            window.Show(true);
            window.Center();
        }
Exemple #3
0
        internal static void LoadEmbeddedFont()
        {
            //var auxList = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
#if WINDOWS_UWP || WINDOWS_UAP
            var assembly = new ColoredString().GetType().GetTypeInfo().Assembly;
#else
            var assembly = Assembly.GetExecutingAssembly();
#endif
            var resourceNameFont  = "SadConsole.Resources.IBM_ext.font";
            var resourceNameImage = "SadConsole.Resources.IBM8x16_NoPadding_extended.png";

            using (Stream stream = assembly.GetManifestResourceStream(resourceNameFont))
                using (StreamReader sr = new StreamReader(stream))
                {
                    Settings.LoadingEmbeddedFont = true;
                    Global.SerializerPathHint    = "";
                    var masterFont = (FontMaster)Newtonsoft.Json.JsonConvert.DeserializeObject(
                        sr.ReadToEnd(),
                        typeof(FontMaster),
                        new Newtonsoft.Json.JsonSerializerSettings()
                    {
                        TypeNameHandling = Newtonsoft.Json.TypeNameHandling.All
                    });

                    using (Stream fontStream = assembly.GetManifestResourceStream(resourceNameImage))
                        masterFont.Image = Texture2D.FromStream(Global.GraphicsDevice, fontStream);

                    masterFont.ConfigureRects();
                    Fonts.Add(masterFont.Name, masterFont);
                    FontDefault = masterFont.GetFont(Font.FontSizes.One);

                    Settings.LoadingEmbeddedFont = false;
                }
        }
        /// <summary>
        /// Shows a window prompt with two buttons for the user to click.
        /// </summary>
        /// <param name="message">The text to display. (background color is ignored)</param>
        /// <param name="yesPrompt">The yes button's text.</param>
        /// <param name="noPrompt">The no button's text.</param>
        /// <param name="resultCallback">Callback with the yes (true) or no (false) result.</param>
        public static void Prompt(ColoredString message, string yesPrompt, string noPrompt, Action <bool> resultCallback)
        {
            Window window = new Window(message.ToString().Length + 4, 6);

            message.IgnoreBackground = true;

            window.Print(2, 2, message);

            Button yesButton = new Button(yesPrompt.Length + 2);
            Button noButton  = new Button(noPrompt.Length + 2);

            yesButton.Position = new Point(2, window.textSurface.Height - 2);
            noButton.Position  = new Point(window.textSurface.Width - noButton.Width - 2, window.textSurface.Height - 2);

            yesButton.Text = yesPrompt;
            noButton.Text  = noPrompt;

            yesButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); };
            noButton.Click  += (o, e) => { window.DialogResult = false; window.Hide(); };

            window.Add(yesButton);
            window.Add(noButton);

            window.Closed += (o, e) =>
            {
                resultCallback(window.DialogResult);
            };

            window.Show(true);
            window.Center();
        }
        public override void Draw(int x, int y, SadConsole.Console console)
        {
            var str = new SadConsole.ColoredString("");

            str += KeyString + " " + Name;
            str.SetBackground(console.DefaultBackground);

            console.Print(x, y, str);
        }
 /// <summary>
 /// Creates a <see cref="ColoredString"/> object from an existing string with the specified foreground, background, and cell effect.
 /// </summary>
 /// <param name="value">The current string.</param>
 /// <param name="foreground">The foreground color.</param>
 /// <param name="background">The background color.</param>
 /// <param name="effect">The cell effect.</param>
 /// <returns>A <see cref="ColoredString"/> object instace.</returns>
 public static ColoredString CreateColored(this string value, Color foreground, Color background, ICellEffect effect)
 {
     ColoredString newString = new ColoredString(value);
     newString.Foreground = foreground;
     newString.Background = background;
     newString.Effect = effect;
     newString.UpdateWithDefaults();
     return newString;
 }
        /// <summary>
        /// Shows a window prompt with two buttons for the user to click.
        /// </summary>
        /// <param name="message">The text to display. (background color is ignored)</param>
        /// <param name="yesPrompt">The yes button's text.</param>
        /// <param name="noPrompt">The no button's text.</param>
        /// <param name="resultCallback">Callback with the yes (true) or no (false) result.</param>
        /// <param name="library">The library to theme the message box. If <see langword="null"/>, then the theme will be set to <see cref="Themes.Library.Default"/>.</param>
        public static void Prompt(ColoredString message, string yesPrompt, string noPrompt, Action <bool> resultCallback, Themes.Library library = null)
        {
            message.IgnoreBackground = true;

            if (library == null)
            {
                library = Themes.Library.Default;
            }

            var yesButton = new Button(yesPrompt.Length + 2, 1);
            var noButton  = new Button(noPrompt.Length + 2, 1);

            yesButton.Theme = library.GetControlTheme(typeof(Button));
            noButton.Theme  = library.GetControlTheme(typeof(Button));

            var window = new Window(message.ToString().Length + 4, 5 + yesButton.Surface.Height)
            {
                Theme = library.WindowTheme
            };

            var printArea = new DrawingSurface(window.Width, window.Height)
            {
                OnDraw = (ds) =>
                {
                    Cell appearance = ((Themes.DrawingSurfaceTheme)ds.Theme).Appearance;
                    ds.Surface.Fill(appearance.Foreground, appearance.Background, null);
                    ds.Surface.Print(2, 2, message);
                }
            };

            yesButton.Position = new Point(2, window.Height - 1 - yesButton.Surface.Height);
            noButton.Position  = new Point(window.Width - noButton.Width - 2, window.Height - 1 - yesButton.Surface.Height);

            yesButton.Text = yesPrompt;
            noButton.Text  = noPrompt;

            yesButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); };
            noButton.Click  += (o, e) => { window.DialogResult = false; window.Hide(); };

            yesButton.Theme = null;
            noButton.Theme  = null;

            window.Add(printArea);
            window.Add(yesButton);
            window.Add(noButton);

            noButton.IsFocused = true;

            window.Closed += (o, e) =>
            {
                resultCallback?.Invoke(window.DialogResult);
            };

            window.Show(true);
            window.Center();
        }
        /// <summary>
        /// Displays a dialog to the user with a specific message.
        /// </summary>
        /// <param name="message">The message. (background color is ignored)</param>
        /// <param name="closeButtonText">The text of the dialog's close button.</param>
        /// <param name="closedCallback">A callback indicating the message was dismissed.</param>
        /// <param name="library">The library to theme the message box. If <see langword="null"/>, then the theme will be set to <see cref="Themes.Library.Default"/>.</param>
        public static void Message(ColoredString message, string closeButtonText, Action closedCallback = null, Themes.Library library = null)
        {
            int width       = message.ToString().Length + 4;
            int buttonWidth = closeButtonText.Length + 2;

            if (library == null)
            {
                library = Themes.Library.Default;
            }

            if (buttonWidth < 9)
            {
                buttonWidth = 9;
            }

            if (width < buttonWidth + 4)
            {
                width = buttonWidth + 4;
            }

            var closeButton = new Button(buttonWidth, 1)
            {
                Text  = closeButtonText,
                Theme = library.GetControlTheme(typeof(Button))
            };

            var window = new Window(width, 5 + closeButton.Surface.Height)
            {
                Theme = library.WindowTheme
            };

            message.IgnoreBackground = true;

            var printArea = new DrawingSurface(window.Width, window.Height)
            {
                OnDraw = (ds) =>
                {
                    Cell appearance = ((Themes.DrawingSurfaceTheme)ds.Theme).Appearance;
                    ds.Surface.Fill(appearance.Foreground, appearance.Background, null);
                    ds.Surface.Print(2, 2, message);
                }
            };

            window.Add(printArea);

            closeButton.Position = new Point(2, window.Height - 1 - closeButton.Surface.Height);
            closeButton.Click   += (o, e) => { window.DialogResult = true; window.Hide(); closedCallback?.Invoke(); };
            closeButton.Theme    = null;

            window.Add(closeButton);
            closeButton.IsFocused = true;
            window.CloseOnEscKey  = true;
            window.Show(true);
            window.Center();
        }
        private void RefreshBackingPanel()
        {
            topBarPane.Clear();

            var text = new SadConsole.ColoredString("   X: ", Settings.Appearance_Text) + new SadConsole.ColoredString(topBarMousePosition.X.ToString(), Settings.Appearance_TextValue) +
                       new SadConsole.ColoredString(" Y: ", Settings.Appearance_Text) + new SadConsole.ColoredString(topBarMousePosition.Y.ToString(), Settings.Appearance_TextValue) +
                       new SadConsole.ColoredString("   Layer: ", Settings.Appearance_Text) + new SadConsole.ColoredString(topBarLayerName, Settings.Appearance_TextValue) +
                       new SadConsole.ColoredString("   Tool: ", Settings.Appearance_Text) + new SadConsole.ColoredString(topBarToolName, Settings.Appearance_TextValue);

            topBarPane.Print(0, 0, text);
        }
Exemple #10
0
        private void PrintGlyph(ColoredGlyph glyph, ColoredString settings)
        {
            var cell = editor.TextSurface.Cells[position.Y * editor.TextSurface.Width + position.X];

            if (!PrintOnlyCharacterData)
            {
                if (!settings.IgnoreGlyph)
                {
                    cell.Glyph = glyph.GlyphCharacter;
                }
                if (!settings.IgnoreBackground)
                {
                    cell.Background = glyph.Background;
                }
                if (!settings.IgnoreForeground)
                {
                    cell.Foreground = glyph.Foreground;
                }
                if (!settings.IgnoreMirror)
                {
                    cell.Mirror = glyph.Mirror;
                }
                if (!settings.IgnoreEffect)
                {
                    editor.SetEffect(cell, glyph.Effect);
                }
            }
            else if (!settings.IgnoreGlyph)
            {
                cell.Glyph = glyph.GlyphCharacter;
            }


            position.X += 1;
            if (position.X >= editor.TextSurface.Width)
            {
                position.X  = 0;
                position.Y += 1;

                if (position.Y >= editor.TextSurface.Height)
                {
                    position.Y -= 1;

                    if (AutomaticallyShiftRowsUp)
                    {
                        editor.ShiftUp();
                    }
                }
            }

            editor.TextSurface.IsDirty = true;
        }
        /// <summary>
        /// Creates a <see cref="ColoredString"/> object from an existing string with the specified foreground gradient, background gradient, and cell effect.
        /// </summary>
        /// <param name="value">The current string.</param>
        /// <param name="startingForeground">The starting foreground color to blend.</param>
        /// <param name="endingForeground">The ending foreground color to blend.</param>
        /// <param name="startingBackground">The starting background color to blend.</param>
        /// <param name="endingBackground">The ending background color to blend.</param>
        /// <returns>A <see cref="ColoredString"/> object instace.</returns>
        public static ColoredString CreateGradient(this string value, Color startingForeground, Color endingForeground, Color startingBackground, Color endingBackground)
        {
            ColoredString newString = new ColoredString(value);

            for (int i = 0; i < value.Length; i++)
            {
                newString[i].Foreground = Color.Lerp(startingForeground, endingForeground, i / (float)value.Length);
                newString[i].Background = Color.Lerp(startingBackground, endingBackground, i / (float)value.Length);
            }

            newString.IgnoreMirror = true;

            return(newString);
        }
        /// <summary>
        /// Creates a new instance of the ColoredString class with the specified string value, foreground and background colors, and a cell effect.
        /// </summary>
        /// <param name="value">The backing string.</param>
        /// <param name="foreground">The foreground color for each character.</param>
        /// <param name="background">The background color for each character.</param>
        /// <param name="spriteEffect">The sprite effects for each character.</param>
        public ColoredString(string value, Color foreground, Color background)
        {
            var stacks = new ParseCommandStacks();

            stacks.AddSafe(new ParseCommandRecolor()
            {
                R = foreground.R, G = foreground.G, B = foreground.B, A = foreground.A, CommandType = CommandTypes.Foreground
            });
            stacks.AddSafe(new ParseCommandRecolor()
            {
                R = background.R, G = background.G, B = background.B, A = background.A, CommandType = CommandTypes.Background
            });
            _characters = ColoredString.Parse(value, initialBehaviors: stacks)._characters;
        }
Exemple #13
0
        /// <summary>
        /// Prints text on the console.
        /// </summary>
        /// <param name="text">The text to print.</param>
        /// <param name="template">The way the text will look when it is printed.</param>
        /// <param name="templateEffect">Effect to apply to the text as its printed.</param>
        /// <returns>Returns this cursor object.</returns>
        public Cursor Print(string text, Cell template, Effects.ICellEffect templateEffect)
        {
            ColoredString coloredString;

            if (UseStringParser)
            {
                coloredString = ColoredString.Parse(text, position.Y * editor.TextSurface.Width + position.X, editor.TextSurface, editor, new StringParser.ParseCommandStacks());
            }
            else
            {
                coloredString = text.CreateColored(template.Foreground, template.Background, template.Mirror);
                coloredString.SetEffect(templateEffect);
            }

            return(Print(coloredString));
        }
        /// <summary>
        /// Creates a <see cref="ColoredString"/> object from an existing string with the specified foreground and background, setting the ignore properties if needed.
        /// </summary>
        /// <param name="value">The current string.</param>
        /// <param name="foreground">The foreground color. If null, <see cref="ColoredString.IgnoreForeground"/> will be set.</param>
        /// <param name="background">The background color. If null, <see cref="ColoredString.IgnoreBackground"/> will be set.</param>
        /// <param name="mirror">The mirror setting. If null, <see cref="ColoredString.IgnoreMirror"/> will be set.</param>
        /// <returns>A <see cref="ColoredString"/> object instace.</returns>
        public static ColoredString CreateColored(this string value, Color?foreground = null, Color?background = null, Mirror?mirror = null)
        {
            var stacks = new ParseCommandStacks();

            if (foreground.HasValue)
            {
                stacks.AddSafe(new ParseCommandRecolor()
                {
                    R = foreground.Value.R, G = foreground.Value.G, B = foreground.Value.B, A = foreground.Value.A, CommandType = CommandTypes.Foreground
                });
            }

            if (background.HasValue)
            {
                stacks.AddSafe(new ParseCommandRecolor()
                {
                    R = background.Value.R, G = background.Value.G, B = background.Value.B, A = background.Value.A, CommandType = CommandTypes.Background
                });
            }

            if (mirror.HasValue)
            {
                stacks.AddSafe(new ParseCommandMirror()
                {
                    Mirror = mirror.Value, CommandType = CommandTypes.Mirror
                });
            }

            ColoredString newString = ColoredString.Parse(value, initialBehaviors: stacks);

            if (!foreground.HasValue)
            {
                newString.IgnoreForeground = true;
            }

            if (!background.HasValue)
            {
                newString.IgnoreBackground = true;
            }

            if (!mirror.HasValue)
            {
                newString.IgnoreMirror = true;
            }

            return(newString);
        }
Exemple #15
0
        /// <summary>
        /// Displays a dialog to the user with a specific message.
        /// </summary>
        /// <param name="message">The message. (background color is ignored)</param>
        /// <param name="closeButtonText">The text of the dialog's close button.</param>
        /// <param name="closedCallback">A callback indicating the message was dismissed.</param>
        /// <param name="library">The library to theme the message box. If <see langword="null"/>, then the theme will be set to <see cref="Themes.Library.Default"/>.</param>
        public static void Message(ColoredString message, string closeButtonText, Action closedCallback = null, Themes.Library library = null)
        {
            var width       = message.ToString().Length + 4;
            var buttonWidth = closeButtonText.Length + 2;

            if (library == null)
            {
                library = Themes.Library.Default;
            }

            if (buttonWidth < 9)
            {
                buttonWidth = 9;
            }

            if (width < buttonWidth + 4)
            {
                width = buttonWidth + 4;
            }

            var closeButton = new Button(buttonWidth, 1)
            {
                Text  = closeButtonText,
                Theme = library.ButtonTheme
            };

            var window = new Window(width, 5 + closeButton.Surface.Height);

            window.Theme = library;

            message.IgnoreBackground = true;

            var printArea = new DrawingSurface(window.Width, window.Height);

            printArea.OnDraw = (ds) => ds.Surface.Print(2, 2, message);
            window.Add(printArea);

            closeButton.Position = new Point(2, window.Height - 1 - closeButton.Surface.Height);
            closeButton.Click   += (o, e) => { window.DialogResult = true; window.Hide(); closedCallback?.Invoke(); };
            closeButton.Theme    = null;

            window.Add(closeButton);
            closeButton.IsFocused = true;
            window.CloseOnEscKey  = true;
            window.Show(true);
            window.Center();
        }
        /// <summary>
        /// Combines two ColoredString objects into a single ColoredString object. Ignore* values are only copied when both strings Ignore* values match.
        /// </summary>
        /// <param name="string1">The left-side of the string.</param>
        /// <param name="string2">The right-side of the string.</param>
        /// <returns></returns>
        public static ColoredString operator +(ColoredString string1, ColoredString string2)
        {
            ColoredString returnString = new ColoredString(string1.Count + string2.Count);

            for (int i = 0; i < string1.Count; i++)
            {
                returnString._characters[i] = string1._characters[i].Clone();
            }

            for (int i = 0; i < string2.Count; i++)
            {
                returnString._characters[i + string1.Count] = string2._characters[i].Clone();
            }

            returnString.IgnoreGlyph      = string1.IgnoreGlyph && string1.IgnoreGlyph;
            returnString.IgnoreForeground = string1.IgnoreForeground && string1.IgnoreForeground;
            returnString.IgnoreBackground = string1.IgnoreBackground && string1.IgnoreBackground;

            return(returnString);
        }
        /// <summary>
        /// Returns a new <see cref="ColoredString"/> object using a substring of this instance.
        /// </summary>
        /// <param name="index">The index to copy the contents from.</param>
        /// <param name="count">The count of <see cref="ColoredGlyph"/> objects to copy.</param>
        /// <returns>A new <see cref="ColoredString"/> object.</returns>
        public ColoredString SubString(int index, int count)
        {
            if (index + count > _characters.Count)
            {
                throw new System.IndexOutOfRangeException();
            }

            ColoredString returnObject = new ColoredString(count);

            returnObject.IgnoreBackground = this.IgnoreBackground;
            returnObject.IgnoreForeground = this.IgnoreForeground;
            returnObject.IgnoreGlyph      = this.IgnoreGlyph;

            for (int i = 0; i < count; i++)
            {
                returnObject._characters[i] = _characters[i + index].Clone();
            }

            return(returnObject);
        }
        /// <summary>
        /// Displays a dialog to the user with a specific message.
        /// </summary>
        /// <param name="message">The message. (background color is ignored)</param>
        /// <param name="closeButtonText">The text of the dialog's close button.</param>
        /// <param name="closedCallback">A callback indicating the message was dismissed.</param>
        public static void Message(ColoredString message, string closeButtonText, Action closedCallback = null)
        {
            Window window = new Window(message.ToString().Length + 4, 6);

            message.IgnoreBackground = true;

            window.Print(2, 2, message);

            Button closeButton = new Button(closeButtonText.Length + 2);

            closeButton.Position = new Point(2, window.textSurface.Height - 2);

            closeButton.Text = closeButtonText;

            closeButton.Click += (o, e) => { window.DialogResult = true; window.Hide(); closedCallback?.Invoke(); };

            window.Add(closeButton);
            window.CloseOnESC = true;
            window.Show(true);
            window.Center();
        }
 /// <summary>
 /// Creates a <see cref="ColoredString"/> object from an existing string with the specified foreground and background.
 /// </summary>
 /// <param name="value">The current string.</param>
 /// <param name="appearance">The foreground and background color.</param>
 /// <returns>A <see cref="ColoredString"/> object instace.</returns>
 public static ColoredString CreateColored(this string value, ICellAppearance appearance)
 {
     ColoredString newString = new ColoredString(value);
     newString.Foreground = appearance.Foreground;
     newString.Background = appearance.Background;
     newString.Effect = null;
     newString.UpdateWithDefaults();
     return newString;
 }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="surface"></param>
            /// <param name="area"></param>
            public override void Draw(ITextSurface surface, Microsoft.Xna.Framework.Rectangle area)
            {
                var hotSpot = ((Hotspot)Item);
                ColoredString value = ((char)hotSpot.DebugAppearance.GlyphIndex).ToString().CreateColored(hotSpot.DebugAppearance.Foreground, hotSpot.DebugAppearance.Background, hotSpot.DebugAppearance.SpriteEffect) + " ".CreateColored(_currentAppearance.Foreground, _currentAppearance.Background) + hotSpot.Title.CreateColored(_currentAppearance.Foreground, _currentAppearance.Background);

                if (value.Count < area.Width)
                    value += new string(' ', area.Width - value.Count).CreateColored(_currentAppearance.Foreground, _currentAppearance.Background);
                else if (value.Count > area.Width)
                    value = new ColoredString(value.Take(area.Width).ToArray());
                var editor = new SurfaceEditor(surface);
                editor.Print(area.X, area.Y, value);
                _isDirty = false;
            }
        /// <summary>
        /// Creates a <see cref="ColoredString"/> object from an existing string with the specified foreground gradient, background gradient, and cell effect. 
        /// </summary>
        /// <param name="value">The current string.</param>
        /// <param name="startingForeground">The starting foreground color to blend.</param>
        /// <param name="endingForeground">The ending foreground color to blend.</param>
        /// <param name="startingBackground">The starting background color to blend.</param>
        /// <param name="endingBackground">The ending background color to blend.</param>
        /// <param name="effect">The cell effect.</param>
        /// <returns>A <see cref="ColoredString"/> object instace.</returns>
        public static ColoredString CreateGradient(this string value, Color startingForeground, Color endingForeground, Color startingBackground, Color endingBackground, ICellEffect effect)
        {
            ColoredString newString = new ColoredString(value);

            for (int i = 0; i < value.Length; i++)
            {
                newString[i].Foreground = Color.Lerp(startingForeground, endingForeground, (float)i / (float)value.Length);
                newString[i].Background = Color.Lerp(startingBackground, endingBackground, (float)i / (float)value.Length);
                newString[i].Effect = newString.Effect;
            }

            return newString;
        }
Exemple #22
0
        /// <summary>
        /// Creates a <see cref="ColoredString"/> object from an existing string with the specified foreground gradient, background gradient, and cell effect. 
        /// </summary>
        /// <param name="value">The current string.</param>
        /// <param name="startingForeground">The starting foreground color to blend.</param>
        /// <param name="endingForeground">The ending foreground color to blend.</param>
        /// <param name="startingBackground">The starting background color to blend.</param>
        /// <param name="endingBackground">The ending background color to blend.</param>
        /// <returns>A <see cref="ColoredString"/> object instace.</returns>
        public static ColoredString CreateGradient(this string value, Color startingForeground, Color endingForeground, Color startingBackground, Color endingBackground)
        {
            ColoredString newString = new ColoredString(value);

            for (int i = 0; i < value.Length; i++)
            {
                newString[i].Foreground = ColorHelper.Lerp(startingForeground, endingForeground, (float)i / (float)value.Length);
                newString[i].Background = ColorHelper.Lerp(startingBackground, endingBackground, (float)i / (float)value.Length);
            }

            newString.IgnoreSpriteEffect = true;

            return newString;
        }
 private void DrawFrameCount()
 {
     ColoredString frameNumber = new ColoredString((currentAnimation.Frames.IndexOf(selectedFrame) + 1).ToString(), Settings.Blue, Settings.Color_MenuBack);
     ColoredString frameSep = new ColoredString(" \\ ", Settings.Grey, Settings.Color_MenuBack);
     ColoredString frameMax = new ColoredString(currentAnimation.Frames.Count.ToString(), Settings.Blue, Settings.Color_MenuBack);
     framesCounterBox.Fill(Settings.Blue, Settings.Color_MenuBack, 0, null);
     framesCounterBox.Print(0, 0, frameNumber + frameSep + frameMax);
 }
Exemple #24
0
        /// <summary>
        /// Prints text to the console using the appearance of the colored string.
        /// </summary>
        /// <param name="text">The text to print.</param>
        /// <returns>Returns this cursor object.</returns>
        public Cursor Print(ColoredString text)
        {
            // If we don't want the pretty print, or we're printing a single character (for example, from keyboard input)
            // Then use the pretty print system.
            if (!DisableWordBreak && text.String.Length != 1)
            {
                // Prep
                ColoredGlyph glyph;
                ColoredGlyph spaceGlyph = text[0].Clone();
                spaceGlyph.GlyphCharacter = ' ';
                string stringText = text.String.TrimEnd(' ');

                // Pull any starting spaces off
                var newStringText = stringText.TrimStart(' ');
                int spaceCount    = stringText.Length - newStringText.Length;

                for (int i = 0; i < spaceCount; i++)
                {
                    PrintGlyph(spaceGlyph, text);
                }

                if (spaceCount != 0)
                {
                    text = text.SubString(spaceCount, text.Count - spaceCount);
                }

                stringText = newStringText;
                string[] parts = stringText.Split(' ');

                // Start processing the string
                int c = 0;

                for (int wordMajor = 0; wordMajor < parts.Length; wordMajor++)
                {
                    // Words broken up by spaces = parts
                    if (parts[wordMajor].Length != 0)
                    {
                        // Parts broken by new lines = newLineParts
                        string[] newlineParts = parts[wordMajor].Split('\n');

                        for (int indexNL = 0; indexNL < newlineParts.Length; indexNL++)
                        {
                            if (newlineParts[indexNL].Length != 0)
                            {
                                int currentLine = position.Y;

                                // New line parts broken up by carriage returns = returnParts
                                string[] returnParts = newlineParts[indexNL].Split('\r');

                                for (int indexR = 0; indexR < returnParts.Length; indexR++)
                                {
                                    // If the text we'll print will move off the edge, fill with spaces to get a fresh line
                                    if (returnParts[indexR].Length > editor.Width - position.X && position.X != 0)
                                    {
                                        var spaces = editor.Width - position.X;

                                        // Fill rest of line with spaces
                                        for (int i = 0; i < spaces; i++)
                                        {
                                            PrintGlyph(spaceGlyph, text);
                                        }
                                    }

                                    // Print the rest of the text as normal.
                                    for (int i = 0; i < returnParts[indexR].Length; i++)
                                    {
                                        glyph = text[c];

                                        PrintGlyph(glyph, text);

                                        c++;
                                    }

                                    // If we had a \r in the string, handle it by going back
                                    if (returnParts.Length != 1 && indexR != returnParts.Length - 1)
                                    {
                                        // Wrapped to a new line through print glyph, which triggerd \r\n. We don't want the \n so return back.
                                        if (position.X == 0 && position.Y != currentLine)
                                        {
                                            position.Y -= 1;
                                        }
                                        else
                                        {
                                            CarriageReturn();
                                        }
                                        c++;
                                    }
                                }
                            }

                            // We had \n in the string, handle them.
                            if (newlineParts.Length != 1 && indexNL != newlineParts.Length - 1)
                            {
                                if (!UseLinuxLineEndings)
                                {
                                    LineFeed();
                                }
                                else
                                {
                                    NewLine();
                                }
                                c++;
                            }
                        }
                    }

                    // Not last part
                    if (wordMajor != parts.Length - 1 && position.X != 0)
                    {
                        PrintGlyph(spaceGlyph, text);
                        c++;
                    }
                    else
                    {
                        c++;
                    }
                }
            }
            else
            {
                bool movedLines = false;
                int  oldLine    = position.Y;

                foreach (var glyph in text)
                {
                    // Check if the previous print moved us down a line (from print at end of the line) and move use back for the \r
                    if (movedLines)
                    {
                        if (position.X == 0 && glyph.GlyphCharacter == '\r')
                        {
                            position.Y -= 1;
                            continue;
                        }
                        else
                        {
                            movedLines = false;
                        }
                    }

                    if (glyph.GlyphCharacter == '\r')
                    {
                        CarriageReturn();
                    }

                    else if (glyph.GlyphCharacter == '\n')
                    {
                        if (!UseLinuxLineEndings)
                        {
                            LineFeed();
                        }
                        else
                        {
                            NewLine();
                        }
                    }
                    else
                    {
                        PrintGlyph(glyph, text);

                        // Lines changed and it wasn't a \n that caused it, so it was a print that did it.
                        movedLines = position.Y != oldLine;
                    }
                }
            }
            return(this);
        }