Ejemplo n.º 1
0
        public void Prepare(IObject obj, IDrawableInfo drawable, IViewport viewport)
        {
            _glText = _glText ?? new GLText(_graphics, _fonts, _bitmapPool);

            updateBoundingBoxes(obj, drawable, viewport);
            _bgRenderer.BoundingBoxes = _usedLabelBoundingBoxes;
            _bgRenderer.Prepare(obj, drawable, viewport);
        }
Ejemplo n.º 2
0
        private void updateBoundingBoxes(GLText glText, AutoFit autoFit, IGLMatrices textMatrices, IGLMatrices labelMatrices, PointF textScaleUp, PointF textScaleDown, PointF labelResolutionFactor, bool buildRenderBox, bool buildHitTestBox)
        {
            switch (autoFit)
            {
            case AutoFit.NoFitting:
                build(_labelBoundingBoxes, BaseSize.Width / labelResolutionFactor.X, BaseSize.Height / labelResolutionFactor.Y, labelMatrices, buildRenderBox, buildHitTestBox);
                updateText(glText, buildRenderBox, BaseSize, textScaleUp, textScaleDown, int.MaxValue);
                build(_textBoundingBoxes, glText.BitmapWidth, glText.BitmapHeight, textMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.TextShouldWrapAndLabelShouldFitHeight:
                build(_textBoundingBoxes, glText.BitmapWidth, glText.BitmapHeight, textMatrices, buildRenderBox, buildHitTestBox);
                build(_labelBoundingBoxes, BaseSize.Width / labelResolutionFactor.X, glText.Height / labelResolutionFactor.Y, labelMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.TextShouldFitLabel:
                build(_labelBoundingBoxes, BaseSize.Width / labelResolutionFactor.X, BaseSize.Height / labelResolutionFactor.Y, labelMatrices, buildRenderBox, buildHitTestBox);
                updateText(glText, buildRenderBox, glText.Width > BaseSize.Width ? new SizeF(0f, BaseSize.Height) : BaseSize, textScaleUp, textScaleDown, int.MaxValue);

                float textWidth  = glText.Width < BaseSize.Width ? glText.BitmapWidth : MathUtils.Lerp(0f, 0f, glText.Width, BaseSize.Width, glText.BitmapWidth);
                float textHeight = glText.Height < BaseSize.Height ? glText.BitmapHeight : MathUtils.Lerp(0f, 0f, glText.Height, BaseSize.Height, glText.BitmapHeight);

                build(_textBoundingBoxes, textWidth, textHeight, textMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.LabelShouldFitText:
                build(_textBoundingBoxes, glText.BitmapWidth, glText.BitmapHeight, textMatrices, buildRenderBox, buildHitTestBox);
                build(_labelBoundingBoxes, glText.Width / labelResolutionFactor.X, glText.Height / labelResolutionFactor.Y, labelMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.TextShouldCrop:
                build(_labelBoundingBoxes, BaseSize.Width / labelResolutionFactor.X, BaseSize.Height / labelResolutionFactor.Y, labelMatrices, buildRenderBox, buildHitTestBox);
                updateText(glText, buildRenderBox, glText.Width > BaseSize.Width ? GLText.EmptySize : new SizeF(BaseSize.Width, GLText.EmptySize.Height), textScaleUp, textScaleDown, (int)BaseSize.Width, true);

                float heightOfText = glText.Height < BaseSize.Height ? glText.BitmapHeight : MathUtils.Lerp(0f, 0f, glText.Height, BaseSize.Height, glText.BitmapHeight);

                build(_textBoundingBoxes, glText.BitmapWidth, heightOfText, textMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            default:
                throw new NotSupportedException(autoFit.ToString());
            }
        }
Ejemplo n.º 3
0
 private void updateText(GLText glText, bool measureOnly, SizeF baseSize, PointF scaleUp, PointF scaleDown, int?maxWidth, bool cropText = false)
 {
     if (TextVisible)
     {
         if (Text == null)
         {
             return;
         }
         if (glText.SetProperties(baseSize, Text, Config, maxWidth, scaleUp, scaleDown, CaretPosition, RenderCaret, cropText, measureOnly))
         {
             onBoundingBoxShouldChange();
         }
     }
 }
Ejemplo n.º 4
0
        public void Prepare(IObject obj, IDrawableInfoComponent drawable, IViewport viewport)
        {
            if (!TextBackgroundVisible && !TextVisible)
            {
                return;
            }

            if (_lastObject != obj)
            {
                IBlockingEvent          boxChangeEvent = obj.GetComponent <IBoundingBoxComponent>()?.OnBoundingBoxesChanged ?? new AGSEvent();
                AGSBoundingBoxComponent box            = new AGSBoundingBoxComponent(_settings, _viewport,
                                                                                     _labelBoundingBoxFakeBuilder, _state, _events, boxChangeEvent);
                obj.RemoveComponent <IBoundingBoxComponent>();
                obj.AddComponent <IBoundingBoxComponent>(box);
                _lastObject = obj;
                foreach (var binding in _bindings)
                {
                    binding?.Unbind();
                }
                var scaleBinding    = obj.Bind <IScaleComponent>(c => c.PropertyChanged += onScalePropertyChanged, c => c.PropertyChanged -= onScalePropertyChanged);
                var matrixBinding   = obj.Bind <IModelMatrixComponent>(c => c.OnMatrixChanged.Subscribe(onMatrixChanged), c => c.OnMatrixChanged.Unsubscribe(onMatrixChanged));
                var drawableBinding = obj.Bind <IDrawableInfoComponent>(c => c.PropertyChanged += onDrawablePropertyChanged, c => c.PropertyChanged -= onDrawablePropertyChanged);
                onBoundingBoxShouldChange();
                _bindings.Clear();
                _bindings.Add(scaleBinding);
                _bindings.Add(matrixBinding);
                _bindings.Add(drawableBinding);
            }
            _glTextHitTest = _glTextHitTest ?? new GLText(_graphics, _messagePump, _fonts, _bitmapPool, false);
            _glTextRender  = _glTextRender ?? new GLText(_graphics, _messagePump, _fonts, _bitmapPool, true);

            updateBoundingBoxes(obj, drawable, viewport);
            if (_usedLabelBoundingBoxes != null)
            {
                _labelBoundingBoxFakeBuilder.BoundingBoxes = _usedLabelBoundingBoxes;
            }
            _bgRenderer.Prepare(obj, drawable, viewport);
            Width  = _usedLabelBoundingBoxes == null ? 1f : _usedLabelBoundingBoxes.RenderBox.Width;
            Height = _usedLabelBoundingBoxes == null ? 1f : _usedLabelBoundingBoxes.RenderBox.Height;
        }