Example #1
0
        public void DrawMarkedString(Font textureFont, TextEditor text, ref Rect rect, Color color, Color selectionColor, TextAlignment textAlignment)
        {
            int   length = textureFont.BestWidthFitBackWards(text.ToString(), text.MarkerIndex, rect.W);
            float markerPos;

            if (length < text.Length)
            {
                markerPos = rect.W - 1;
            }
            else
            {
                markerPos = textureFont.MessureSubstring(text.ToString(), Math.Max(0, (text.MarkerIndex - length)), text.MarkerIndex - (text.Length - length)).X;
                markerPos = MathHelper.Clamp(0, rect.W - 1, markerPos);
            }

            Vector2 align = GetAlignment(textureFont, text.ToString(), text.MarkerIndex - length, length, ref rect, textAlignment);

            if (text.Selected)
            {
                float selectionStart = textureFont.MessureSubstring(text.ToString(), 0, text.SelectionIndex - (text.Length - length)).X;

                this.batch.BufferFrame(this.pixel, new Rect(rect.X + selectionStart, rect.Y, markerPos - selectionStart, rect.H), selectionColor * 0.6f);
            }

            this.batch.BufferFrame(this.pixel, new Rect(rect.X + markerPos, rect.Y, 1, rect.H), color);
            this.batch.BufferSubString(textureFont, text.ToString(), Math.Max(0, text.MarkerIndex - length), length, new Vector2(rect.X, rect.Y), color, align, Vector2.One);
        }