Пример #1
0
        // Can be improved
        public static void DrawButton(this SadConsole.Console console, int x, int y, string text, string key, Color keyColor, bool windowCentered)
        {
            var bracketA = new SadConsole.ColoredString("[");

            bracketA.SetForeground(console.DefaultForeground);
            var bracketB = new SadConsole.ColoredString("] ");

            bracketB.SetForeground(console.DefaultForeground);

            var prefix = new SadConsole.ColoredString($"{key}");

            prefix.SetForeground(keyColor);

            var suffix = new SadConsole.ColoredString($"{text}");

            suffix.SetForeground(console.DefaultForeground);

            var button = new SadConsole.ColoredString("");

            button.SetForeground(console.DefaultForeground);
            button.SetBackground(console.DefaultBackground);

            button += bracketA + prefix + bracketB + suffix;

            int _x = windowCentered ? (console.Width / 2 - (button.Count / 2)) : x;

            console.Print(_x, y, button);
        }
Пример #2
0
        public static void DrawHeader(this SadConsole.Console console, int y, string title, Color foregroundColor, Color backgroundColor)
        {
            var str = new SadConsole.ColoredString();

            str.String = title;
            str.SetForeground(foregroundColor);
            str.SetBackground(backgroundColor);
            console.Print(console.Width / 2 - (str.Count / 2), y, str);
        }
Пример #3
0
        public static SadConsole.ColoredString AttributeString(int value, string attribute)
        {
            // currently draws everything as a positive value
            var pVal = Constants.Theme.PositiveAttributeColor;
            var nVal = Constants.Theme.NegativeAttributeColor;
            var cBg  = Constants.Theme.BackgroundColor;
            var cFg  = Constants.Theme.ForegroundColor;

            var val = new SadConsole.ColoredString(value.ToString());
            var att = new SadConsole.ColoredString(attribute, cFg, cBg);

            val.SetForeground(value > 0 ? pVal : nVal);

            var str = new SadConsole.ColoredString("+ ", cFg, cBg);

            return(str + val + " " + att);
        }
Пример #4
0
        /// <summary>
        /// Creates a <see cref="SadConsole.ColoredString"/> object using the current gradient.
        /// </summary>
        /// <param name="text">The text to use for the colored string.</param>
        /// <returns>A new colored string object.</returns>
        public SadConsole.ColoredString ToColoredString(string text)
        {
            SadConsole.ColoredString stringObject = new SadConsole.ColoredString(text);

            if (Stops.Length == 0)
            {
                throw new global::System.IndexOutOfRangeException("The ColorGradient object does not have any gradient stops defined.");
            }

            else if (Stops.Length == 1)
            {
                stringObject.SetForeground(Stops[0].Color);
                return(stringObject);
            }

            float lerp      = 1f / (text.Length - 1);
            float lerpTotal = 0f;

            stringObject[0].Foreground = Stops[0].Color;
            stringObject[text.Length - 1].Foreground = Stops[Stops.Length - 1].Color;

            for (int i = 1; i < text.Length - 1; i++)
            {
                lerpTotal += lerp;
                int counter;
                for (counter = 0; counter < Stops.Length && Stops[counter].Stop < lerpTotal; counter++)
                {
                    ;
                }

                counter--;
                counter = (int)MyMathHelper.Clamp(counter, 0, Stops.Length - 2);

                float newLerp = (Stops[counter].Stop - (float)lerpTotal) / (Stops[counter].Stop - Stops[counter + 1].Stop);

                stringObject[i].Foreground = ColorHelper.Lerp(Stops[counter].Color, Stops[counter + 1].Color, newLerp);
            }

            return(stringObject);
        }