Esempio n. 1
0
        void CalculateCaretData()
        {
            if (caretPos >= chatInputText.Length)
            {
                caretPos = -1;
            }
            chatInputText.MakeCoords(caretPos, partLens, out indexX, out indexY);
            DrawTextArgs args = new DrawTextArgs(null, font, true);

            if (indexX == 64)
            {
                caretTex.X1 = 10 + sizes[indexY].Width;
                caretCol    = FastColour.Yellow;
            }
            else
            {
                args.Text = parts[indexY].Substring(0, indexX);
                Size trimmedSize = game.Drawer2D.MeasureChatSize(ref args);
                caretTex.X1 = 10 + trimmedSize.Width;

                string line = parts[indexY];
                args.Text = indexX < line.Length ? new String(line[indexX], 1) : " ";
                Size charSize = game.Drawer2D.MeasureChatSize(ref args);
                caretTex.Width = charSize.Width;
                caretCol       = FastColour.Scale(FastColour.White, 0.8f);
            }
            caretTex.Y1 = sizes[0].Height * indexY + Y;
            CalculateCaretCol();
        }
        void DrawPart(FastBitmap dst, ref DrawTextArgs args, int x, int y, bool shadowCol)
        {
            FastColour col = Colours['f'];

            if (shadowCol)
            {
                col = BlackTextShadows ? FastColour.Black : FastColour.Scale(col, 0.25f);
            }
            FastColour lastCol = col;

            int    xMul = args.Font.Style == FontStyle.Italic ? 1 : 0;
            int    runCount = 0, lastY = -1;
            string text      = args.Text;
            int    point     = Utils.Floor(args.Font.Size);
            byte * coordsPtr = stackalloc byte[256];

            for (int i = 0; i < text.Length; i++)
            {
                char c    = text[i];
                bool code = c == '&' && i < text.Length - 1;
                if (code && ValidColour(text[i + 1]))
                {
                    col = Colours[text[i + 1]];
                    if (shadowCol)
                    {
                        col = BlackTextShadows ? FastColour.Black : FastColour.Scale(col, 0.25f);
                    }
                    i++; continue;                     // Skip over the colour code.
                }
                int coords = ConvertToCP437(c);

                // First character in the string, begin run counting
                if (lastY == -1)
                {
                    lastY        = coords >> 4; lastCol = col;
                    coordsPtr[0] = (byte)coords; runCount = 1;
                    continue;
                }
                if (lastY == (coords >> 4) && col == lastCol)
                {
                    coordsPtr[runCount] = (byte)coords; runCount++;
                    continue;
                }

                DrawRun(dst, x, y, xMul, runCount, coordsPtr, point, lastCol);
                lastY = coords >> 4; lastCol = col;
                for (int j = 0; j < runCount; j++)
                {
                    x += PtToPx(point, widths[coordsPtr[j]] + 1);
                }
                coordsPtr[0] = (byte)coords; runCount = 1;
            }
            DrawRun(dst, x, y, xMul, runCount, coordsPtr, point, lastCol);
        }