FSO.Client.UI.Framework.UIElement.LocalPoint C# (CSharp) Method

LocalPoint() public method

Converts a point relative to this UIElement into a point relative to the screen
public LocalPoint ( Vector2 point ) : Vector2
point Vector2
return Vector2
        public Vector2 LocalPoint(Vector2 point)
        {
            return _Mtx.TransformPoint(point);
        }

Same methods

UIElement::LocalPoint ( float x, float y ) : Vector2

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Computes drawing commands to layout a block of text within
        /// certain constraints
        /// </summary>
        /// <returns></returns>
        public static TextRendererResult ComputeText(string text, TextRendererOptions options, UIElement target)
        {
            var TextStyle = options.TextStyle;
            var _Scale    = options.Scale;
            var txtScale  = TextStyle.Scale * _Scale;

            var m_LineHeight = TextStyle.MeasureString("W").Y - (2 * txtScale.Y);
            var spaceWidth   = TextStyle.MeasureString(" ").X;

            var words         = text.Split(' ').ToList();
            var newWordsArray = TextRenderer.ExtractLineBreaks(words);

            var m_Lines = new List <UITextEditLine>();

            TextRenderer.CalculateLines(m_Lines, newWordsArray, TextStyle, options.MaxWidth, spaceWidth, options.TopLeftIconSpace, m_LineHeight);

            var topLeft  = options.Position;
            var position = topLeft;

            var result       = new TextRendererResult();
            var drawCommands = new List <ITextDrawCmd>();

            result.DrawingCommands = drawCommands;

            var yPosition     = topLeft.Y;
            var numLinesAdded = 0;
            var realMaxWidth  = 0;

            for (var i = 0; i < m_Lines.Count; i++)
            {
                var lineOffset = (i * m_LineHeight < options.TopLeftIconSpace.Y) ? options.TopLeftIconSpace.X : 0;
                var line       = m_Lines[i];
                var xPosition  = topLeft.X + lineOffset;

                if (line.LineWidth > realMaxWidth)
                {
                    realMaxWidth = (int)line.LineWidth;
                }

                /** Alignment **/
                if (options.Alignment == TextAlignment.Center)
                {
                    xPosition += (int)Math.Round(((options.MaxWidth - lineOffset) - line.LineWidth) / 2);
                }

                var segmentPosition = target.LocalPoint(new Vector2(xPosition, yPosition));
                drawCommands.Add(new TextDrawCmd_Text
                {
                    Selected = false,
                    Text     = line.Text,
                    Style    = TextStyle,
                    Position = segmentPosition,
                    Scale    = txtScale
                });
                numLinesAdded++;


                yPosition  += m_LineHeight;
                position.Y += m_LineHeight;
            }

            result.BoundingBox = new Rectangle((int)topLeft.X, (int)topLeft.Y, (int)options.MaxWidth, (int)(yPosition - m_LineHeight));
            result.MaxWidth    = realMaxWidth;
            foreach (var cmd in drawCommands)
            {
                cmd.Init();
            }

            return(result);
        }
All Usage Examples Of FSO.Client.UI.Framework.UIElement::LocalPoint