Example #1
0
        // font and border rendering


        private void UpdateText()
        {
            float      width  = _hitArea.Width;
            float      height = _hitArea.Height;
            TextFormat format = _helperFormat;

            // By working on a copy of the TextFormat, we make sure that modifications done
            // within the 'fillMeshBatch' method do not cause any side effects.
            //
            // (We cannot use a static variable, because that might lead to problems when
            //  recreating textures after a context loss.)

            format.CopyFrom(_format);

            // Horizontal autoSize does not work for HTML text, since it supports custom alignment.
            // What should we do if one line is aligned to the left, another to the right?

            if (IsHorizontalAutoSize)
            {
                width = 100000;
            }
            if (IsVerticalAutoSize)
            {
                height = 100000;
            }

            _meshBatch.X           = _meshBatch.Y = 0f;
            _options.TextureScale  = SparrowSharp.ContentScaleFactor;
            _options.TextureFormat = _sDefaultTextureFormat;
            _compositor.FillMeshBatch(_meshBatch, width, height, _text, format, _options);

            if (_style != null)
            {
                _meshBatch.Style = _style;
            }
            if (_options.AutoSize != TextFieldAutoSize.NONE)
            {
                _textBounds = _meshBatch.GetBounds(_meshBatch);

                if (IsHorizontalAutoSize)
                {
                    _meshBatch.X   = _textBounds.X = -_textBounds.X;
                    _hitArea.Width = _textBounds.Width;
                    _textBounds.X  = 0;
                }

                if (IsVerticalAutoSize)
                {
                    _meshBatch.Y    = _textBounds.Y = -_textBounds.Y;
                    _hitArea.Height = _textBounds.Height;
                    _textBounds.Y   = 0f;
                }
            }
            else
            {
                // hit area doesn't change, and text bounds can be created on demand
                _textBounds = null;
            }
        }