Ejemplo n.º 1
0
        /// <summary> Calculates the location and size of the caret character </summary>
        public void UpdateCaret()
        {
            int maxChars = UsedLines * MaxCharsPerLine;

            if (caret >= maxChars)
            {
                caret = -1;
            }
            Text.GetCoords(caret, lines, out caretX, out caretY);
            DrawTextArgs args   = new DrawTextArgs(null, font, false);
            IDrawer2D    drawer = game.Drawer2D;

            caretAccumulator = 0;

            if (caretX == MaxCharsPerLine)
            {
                caretTex.X1    = X + Padding + lineSizes[caretY].Width;
                caretColour    = FastColour.Yellow;
                caretTex.Width = (ushort)caretWidth;
            }
            else
            {
                args.Text = lines[caretY].Substring(0, caretX);
                Size trimmedSize = drawer.MeasureSize(ref args);
                if (caretY == 0)
                {
                    trimmedSize.Width += prefixWidth;
                }

                caretTex.X1 = X + Padding + trimmedSize.Width;
                caretColour = FastColour.Scale(FastColour.White, 0.8f);

                string line = lines[caretY];
                if (caretX < line.Length)
                {
                    args.Text      = new String(line[caretX], 1);
                    args.UseShadow = true;
                    caretTex.Width = (ushort)drawer.MeasureSize(ref args).Width;
                }
                else
                {
                    caretTex.Width = (ushort)caretWidth;
                }
            }
            caretTex.Y1 = lineSizes[0].Height * caretY + inputTex.Y1 + 2;

            // Update the colour of the caret
            char code = GetLastColour(caretX, caretY);

            if (code != '\0')
            {
                caretColour = IDrawer2D.GetCol(code);
            }
        }