Example #1
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);
            }
        }
        /// <summary>
        ///		Perform the actual rendering for this Window.
        /// </summary>
        protected override void DrawImpl(Rect drawArea, Rect clipArea, float z)
        {
            if (image == null)
            {
                return;
            }

            // render the image
            Rect clippedArea = null;

            if (clipArea != null)
            {
                clippedArea = clipArea.GetIntersection(PixelRect);
            }
            // update our alpha values
            imageColors.SetAlpha(this.EffectiveAlpha);
            image.Draw(drawArea, z, clippedArea, imageColors);
        }
 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);
     }
 }