Ejemplo n.º 1
0
        /// <summary>
        /// Draws label
        /// </summary>
        /// <param name="position">Top-left position</param>
        /// <param name="offset"></param>
        /// <param name="drawSizeMax"></param>
        /// <returns></returns>
        public bool Draw(Vector2 position, float offset, Vector2 drawSizeMax)
        {
            RectangleF scissorRect = new RectangleF(position, drawSizeMax);

            using (MyGuiManager.UsingScissorRectangle(ref scissorRect))
            {
                // Compute size of visible text for alignment.
                Vector2 textSize = Vector2.Zero;
                for (int i = 0; i <= m_linesCount; ++i)
                {
                    var lineSize = m_lines[i].GetSize();
                    textSize.X  = MathHelper.Max(textSize.X, lineSize.X);
                    textSize.Y += lineSize.Y;
                }

                // Compute data for text positioning.
                Vector2 drawPosition         = Vector2.Zero;
                float   horizontalAdjustment = 0.0f;
                switch (TextAlign)
                {
                case MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP:
                case MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER:
                case MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM:
                    break;

                case MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP:
                case MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER:
                case MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM:
                    drawPosition.X       = 0.5f * drawSizeMax.X - 0.5f * textSize.X;
                    horizontalAdjustment = 0.5f;
                    break;

                case MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP:
                case MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER:
                case MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM:
                    drawPosition.X       = drawSizeMax.X - textSize.X;
                    horizontalAdjustment = 1.0f;
                    break;
                }

                switch (TextAlign)
                {
                case MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP:
                case MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP:
                case MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP:
                    break;

                case MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER:
                case MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER:
                case MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER:
                    drawPosition.Y = 0.5f * drawSizeMax.Y - 0.5f * textSize.Y;
                    break;

                case MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM:
                case MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM:
                case MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM:
                    drawPosition.Y = drawSizeMax.Y - textSize.Y;
                    break;
                }
                drawPosition.Y -= offset;

                for (int i = 0; i <= m_linesCount; ++i)
                {
                    MyRichLabelLine currentLine = m_lines[i];
                    var             lineSize    = currentLine.GetSize();
                    var             pos         = position + drawPosition;
                    pos.X += horizontalAdjustment * (textSize.X - lineSize.X);
                    currentLine.Draw(pos);
                    drawPosition.Y += lineSize.Y;
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
 private void AppendPart(MyRichLabelPart part)
 {
     m_currentLine = m_lines[m_linesCount];
     m_currentLine.AddPart(part);
     m_currentLineRestFreeSpace = m_maxLineWidth - m_currentLine.GetSize().X;
 }
Ejemplo n.º 3
0
 private void AppendPart(MyRichLabelPart part)
 {
     m_currentLine = m_lines[m_linesCount];
     m_currentLine.AddPart(part);
     m_currentLineRestFreeSpace = m_maxLineWidth - m_currentLine.GetSize().X;
 }