Example #1
0
        private void DrawText(string portion, Vector3 drawPos, Rect clipRect, TextStyle style)
        {
            // Trace.TraceInformation("Drawing '{0}' at [{1},{2}] clipped by {3}", portion, drawPos.x, drawPos.y, clipRect);
            float textZ    = drawPos.z - (int)SubLevel.Normal * GuiZSubLevelStep;
            float shadowZ  = drawPos.z - (int)SubLevel.Shadow * GuiZSubLevelStep;
            float bgZ      = drawPos.z - (int)SubLevel.Background * GuiZSubLevelStep;
            Font  textFont = this.Font;

            // Draw these on integer boundaries
            drawPos.x = (int)drawPos.x;
            drawPos.y = (int)drawPos.y;
            drawPos.z = textZ;
            ColorRect colors;

            if (style.bgEnabled)
            {
                float x = textFont.GetTextExtent(portion);
                float y = textFont.LineSpacing;
                colors = new ColorRect(style.bgColor);
                Rect bgRect = new Rect(drawPos.x, drawPos.y,
                                       drawPos.x + x, drawPos.y + y);
                bgImage.Draw(bgRect, bgZ, clipRect, colors);
            }
            colors = new ColorRect(style.textColor);
            textFont.DrawTextLine(portion, drawPos, clipRect, colors);
            if (style.shadowEnabled)
            {
                drawPos.x += shadowOffset.x;
                drawPos.y += shadowOffset.y;
                drawPos.z  = shadowZ;
                colors     = new ColorRect(style.shadowColor);
                textFont.DrawTextLine(portion, drawPos, clipRect, colors);
            }
        }
Example #2
0
        protected override void DrawSelf(float z)
        {
            base.DrawSelf(z);
            Rect clipRect = this.PixelRect;
            // Draw the caret
            string allText = GetAllText();

            if (caretIndex > allText.Length)
            {
                caretIndex = allText.Length;
            }
            Point   pt      = GetOffset(caretIndex);
            Vector3 drawPos = new Vector3(pt.x, pt.y, z);

            drawPos.z -= (int)layerLevel * GuiZLevelStep;
            drawPos.z -= (int)SubLevel.Caret * GuiZSubLevelStep;
            if (drawPos.x < clipRect.left)
            {
                drawPos.x = clipRect.left;
            }
            else if (drawPos.x + caret.Width > clipRect.right)
            {
                drawPos.x = clipRect.right - caret.Width;
            }
            Size      caretSize      = new Size(caret.Width, font.LineSpacing);
            ColorRect caretColorRect = new ColorRect(new Color(1, 1, 1));

            caret.Draw(drawPos, caretSize, clipRect, caretColorRect);
        }
Example #3
0
        protected void DrawText(float z)
        {
            Rect absRect  = GetVisibleTextArea();
            Rect clipRect = absRect.GetIntersection(this.PixelRect);
            Font textFont = this.Font;

            // textColors.SetAlpha(EffectiveAlpha);
            string           allText = GetAllText();
            List <TextRange> lines   =
                TextWrapHelper.GetLineBreaks(textFont, allText, absRect.Width, nonSpaceWrap);

            Vector3 drawPos = new Vector3();

            drawPos.x = absRect.left;
            drawPos.y = absRect.top;
            drawPos.z = z;

            switch (vertFormat)
            {
            case VerticalTextFormat.Top:
                drawPos.y += 0.0f;                         // start at the top
                break;

            case VerticalTextFormat.Bottom:
                drawPos.y += absRect.Height - lines.Count * textFont.LineSpacing;
                break;

            case VerticalTextFormat.Centered:
                drawPos.y += (absRect.Height - lines.Count * textFont.LineSpacing) / 2;
                break;
            }

            List <TextChunk> .Enumerator chunkEnum = textChunks.GetEnumerator();
            // the offset of the last character that we have drawn
            int lastChar = 0;
            // the offset of the first character in the chunk we are working with
            int chunkStart = 0;
            // the offset of the last character in the chunk we are working with
            int chunkEnd = 0;
            // offset into the active chunk of the first undrawn character
            int       startOffset;
            string    portion;
            TextChunk chunk = chunkEnum.Current;

            foreach (TextRange range in lines)
            {
                drawPos.x = absRect.left;
                string line = allText.Substring(range.start, range.Length);
                switch (horzFormat)
                {
                case HorizontalTextFormat.Left:
                case HorizontalTextFormat.WordWrapLeft:
                    drawPos.x += 0.0f;                             // start at the left
                    break;

                case HorizontalTextFormat.Right:
                case HorizontalTextFormat.WordWrapRight:
                    drawPos.x += absRect.Width - textFont.GetTextExtent(line);
                    break;

                case HorizontalTextFormat.Center:
                case HorizontalTextFormat.WordWrapCentered:
                    drawPos.x += (absRect.Width - textFont.GetTextExtent(line)) / 2;
                    break;
                }
                // while the rest of the current chunk fits completely on this line
                while (chunkEnd <= range.end)
                {
                    // offset into this chunk of the first undrawn character
                    startOffset = lastChar - chunkStart;
                    // do we have anything to process in this chunk?
                    if (chunkEnd - lastChar > 0)
                    {
                        portion = chunk.text.Substring(startOffset, chunkEnd - lastChar);
                        DrawText(portion, drawPos, clipRect, chunk.style);
                        drawPos.x += textFont.GetTextExtent(portion);
                        lastChar   = chunkEnd;
                    }

                    if (!chunkEnum.MoveNext())
                    {
                        // we have finished processing the last chunk
                        return;
                    }
                    chunk      = chunkEnum.Current;
                    chunkStart = chunkEnd;
                    chunkEnd  += chunk.text.Length;
                }
                // at this point, chunk end > range end, so the whole chunk
                // does not belong on this line
                startOffset = lastChar - chunkStart;
                portion     = chunk.text.Substring(startOffset, range.end - lastChar);

                DrawText(portion, drawPos, clipRect, chunk.style);
                drawPos.x += textFont.GetTextExtent(portion);
                lastChar   = range.end;

                drawPos.y += font.LineSpacing;
            }
        }