コード例 #1
0
 protected void ReplaceStyle(TextStyle oldStyle, TextStyle newStyle)
 {
     if (oldStyle.Equals(newStyle))
         return;
     Dirty = true;
     foreach (TextChunk chunk in textChunks)
     {
         if (chunk.style == oldStyle)
             chunk.style = newStyle;
     }
 }
コード例 #2
0
 public void AddText(string textString, TextStyle style)
 {
     TextChunk lastChunk = null;
     if (textChunks.Count > 0)
         lastChunk = textChunks[textChunks.Count - 1];
     int chunk_start = textBuffer.Length;
     textBuffer.Append(textString);
     int chunk_end = textBuffer.Length;
     if (lastChunk != null &&
         lastChunk.style.Equals(style))
     {
         // Add to the existing chunk
         lastChunk.range.end = chunk_end;
     }
     else
     {
         // Add a new chunk
         textChunks.Add(new TextChunk(new TextRange(chunk_start, chunk_end), new TextStyle(style)));
     }
     UpdateText();
 }
コード例 #3
0
 public void ApplyStyle(TextStyle style)
 {
     foreach (TextChunk chunk in textChunks) {
         if (chunk.style.Equals(style))
             continue;
         chunk.style = style;
         Dirty = true;
     }
 }
コード例 #4
0
 private void DrawText(string text, int offset, int count, Vector3 drawPos, Rect clipRect, TextStyle style)
 {
     if (log.IsDebugEnabled)
         log.DebugFormat("Drawing '{0}' at [{1},{2}] clipped by {3}", text.Substring(offset, count), 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;
     SimpleFont textFont = this.Font;
     float x = textFont.GetTextExtent(text, offset, count);
     float y = textFont.LineSpacing;
     if (clipRect != null) {
         if (drawPos.x > clipRect.Right || drawPos.x + x < clipRect.Left ||
             drawPos.y > clipRect.Bottom || drawPos.y + y < clipRect.Top) {
             // this line is entirely out of bounds - technically, the drop shadow
             // could extend outside this area (as could the font), but I think
             // that if we wouldn't have drawn the background for the text, we don't
             // need to draw the text.
             log.DebugFormat("text with dimensions ({4},{5}) fully clipped by rect [{0},{1} - {2},{3}]", clipRect.Left, clipRect.Top, clipRect.Right, clipRect.Bottom, x, y);
             return;
         }
     }
     // Draw these on integer boundaries
     drawPos.x = (int)drawPos.x;
     drawPos.y = (int)drawPos.y;
     drawPos.z = textZ;
     ColorRect colorRect;
     if (style.bgEnabled) {
         colorRect = new ColorRect(style.bgColor);
         colorRect.SetAlpha(this.EffectiveAlpha);
         Rect bgRect = new Rect(drawPos.x, drawPos.x + x,
                                drawPos.y, drawPos.y + y);
         bgImage.Draw(bgRect, bgZ, clipRect, colorRect);
     }
     colorRect = new ColorRect(style.textColor);
     colorRect.SetAlpha(this.EffectiveAlpha);
     textFont.DrawTextLine(text, offset, count, drawPos, clipRect, colorRect);
     if (style.shadowEnabled) {
         drawPos.x += shadowOffset.X;
         drawPos.y += shadowOffset.Y;
         drawPos.z = shadowZ;
         colorRect = new ColorRect(style.shadowColor);
         colorRect.SetAlpha(this.EffectiveAlpha);
         textFont.DrawTextLine(text, offset, count, drawPos, clipRect, colorRect);
     }
 }
コード例 #5
0
 public TextChunk(TextRange range, TextStyle style)
 {
     this.range = range;
     this.style = style;
 }
コード例 #6
0
 public TextStyle(TextStyle other)
 {
     textColor = new ColorEx(other.textColor);
     bgColor = new ColorEx(other.bgColor);
     shadowColor = new ColorEx(other.shadowColor);
     shadowEnabled = other.shadowEnabled;
     bgEnabled = other.bgEnabled;
 }
コード例 #7
0
 public TextChunk(TextRange range, TextStyle style)
 {
     this.range = range;
     this.style = style;
 }
コード例 #8
0
        private void DrawText(string text, int offset, int count, Vector3 drawPos, Rect clipRect, TextStyle style)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Drawing '{0}' at [{1},{2}] clipped by {3}", text.Substring(offset, count), 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;
            SimpleFont textFont = this.Font;
            float      x        = textFont.GetTextExtent(text, offset, count);
            float      y        = textFont.LineSpacing;

            if (clipRect != null)
            {
                if (drawPos.x > clipRect.Right || drawPos.x + x < clipRect.Left ||
                    drawPos.y > clipRect.Bottom || drawPos.y + y < clipRect.Top)
                {
                    // this line is entirely out of bounds - technically, the drop shadow
                    // could extend outside this area (as could the font), but I think
                    // that if we wouldn't have drawn the background for the text, we don't
                    // need to draw the text.
                    log.DebugFormat("text with dimensions ({4},{5}) fully clipped by rect [{0},{1} - {2},{3}]", clipRect.Left, clipRect.Top, clipRect.Right, clipRect.Bottom, x, y);
                    return;
                }
            }
            // Draw these on integer boundaries
            drawPos.x = (int)drawPos.x;
            drawPos.y = (int)drawPos.y;
            drawPos.z = textZ;
            ColorRect colorRect;

            if (style.bgEnabled)
            {
                colorRect = new ColorRect(style.bgColor);
                colorRect.SetAlpha(this.EffectiveAlpha);
                Rect bgRect = new Rect(drawPos.x, drawPos.x + x,
                                       drawPos.y, drawPos.y + y);
                bgImage.Draw(bgRect, bgZ, clipRect, colorRect);
            }
            colorRect = new ColorRect(style.textColor);
            colorRect.SetAlpha(this.EffectiveAlpha);
            textFont.DrawTextLine(text, offset, count, drawPos, clipRect, colorRect);
            if (style.shadowEnabled)
            {
                drawPos.x += shadowOffset.X;
                drawPos.y += shadowOffset.Y;
                drawPos.z  = shadowZ;
                colorRect  = new ColorRect(style.shadowColor);
                colorRect.SetAlpha(this.EffectiveAlpha);
                textFont.DrawTextLine(text, offset, count, drawPos, clipRect, colorRect);
            }
        }