protected void SplitText(string value)
        {
            int code = 0xF;

            for (int i = 0; i < value.Length; i++)
            {
                int nextAnd    = value.IndexOf('&', i);
                int partLength = nextAnd == -1 ? value.Length - i : nextAnd - i;

                if (partLength > 0)
                {
                    string     part = value.Substring(i, partLength);
                    FastColour col  = FastColour.GetHexEncodedCol(code);
                    parts.Add(new TextPart(part, col));
                }
                i += partLength + 1;

                if (nextAnd >= 0 && nextAnd + 1 < value.Length)
                {
                    if (!Utils.TryParseHex(value[nextAnd + 1], out code))
                    {
                        code = 0xF;
                        i--;                        // include the character that isn't a colour code.
                    }
                }
            }
        }
        void CalculateCaretCol()
        {
            int x = indexX;

            for (int y = indexY; y >= 0; y--)
            {
                if (x == partLens[y])
                {
                    x = partLens[y] - 1;
                }
                int start = parts[y].LastIndexOf('&', x, x + 1);

                int  hex;
                bool validIndex = start >= 0 && start < partLens[y] - 1;

                if (validIndex && Utils.TryParseHex(parts[y][start + 1], out hex))
                {
                    caretCol = FastColour.GetHexEncodedCol(hex);
                    return;
                }
                if (y > 0)
                {
                    x = partLens[y - 1] - 1;
                }
            }
        }
Exemple #3
0
        public void InitColours()
        {
            for (int i = 0; i < Colours.Length; i++)
            {
                Colours[i] = default(FastColour);
            }

            for (int i = 0; i <= 9; i++)
            {
                Colours['0' + i] = FastColour.GetHexEncodedCol(i, 191, 64);
            }
            for (int i = 10; i <= 15; i++)
            {
                Colours['a' + i - 10] = FastColour.GetHexEncodedCol(i, 191, 64);
                Colours['A' + i - 10] = Colours['a' + i - 10];
            }
        }