private void buildForRender(IGLBoundingBox renderBox, IGLMatrices matrices, Vector3 bottomLeft, Vector3 topLeft, Vector3 bottomRight, Vector3 topRight)
 {
     renderBox.BottomLeft = Vector3.Transform(bottomLeft, matrices.ViewportMatrix);
     renderBox.TopLeft = Vector3.Transform(topLeft, matrices.ViewportMatrix);
     renderBox.BottomRight = Vector3.Transform(bottomRight, matrices.ViewportMatrix);
     renderBox.TopRight = Vector3.Transform(topRight, matrices.ViewportMatrix);
 }
 private void buildForRender(IGLBoundingBox renderBox, IGLMatrices matrices, Vector3 bottomLeft, Vector3 topLeft, Vector3 bottomRight, Vector3 topRight)
 {
     renderBox.BottomLeft  = Vector3.Transform(bottomLeft, matrices.ViewportMatrix);
     renderBox.TopLeft     = Vector3.Transform(topLeft, matrices.ViewportMatrix);
     renderBox.BottomRight = Vector3.Transform(bottomRight, matrices.ViewportMatrix);
     renderBox.TopRight    = Vector3.Transform(topRight, matrices.ViewportMatrix);
 }
Exemple #3
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());
            }
        }
		public void Build(IGLBoundingBoxes boxes, float width, float height, IGLMatrices matrices, bool buildRenderBox, bool buildHitTestBox)
		{
			float left = 0f;
			float right = width;
			float bottom = 0f;
			float top = height;
            Vector3 bottomLeft = Vector3.Transform(new Vector3 (left, bottom, 0f), matrices.ModelMatrix);
			Vector3 topLeft = Vector3.Transform(new Vector3 (left, top, 0f), matrices.ModelMatrix);
			Vector3 bottomRight = Vector3.Transform(new Vector3 (right, bottom, 0f), matrices.ModelMatrix);
			Vector3 topRight = Vector3.Transform(new Vector3 (right, top, 0f), matrices.ModelMatrix);

			if (buildHitTestBox) buildForHitTest(boxes.HitTestBox, bottomLeft, topLeft, bottomRight, topRight);
            if (buildRenderBox)  buildForRender(boxes.RenderBox, matrices, bottomLeft, topLeft, bottomRight, topRight);            
		}
Exemple #5
0
        private void build(AGSBoundingBoxes boxes, float width, float height, IGLMatrices matrices, bool buildRenderBox, bool buildHitTestBox)
        {
            var modelMatrix     = matrices.ModelMatrix;
            var intermediateBox = _boundingBoxBuilder.BuildIntermediateBox(width, height, ref modelMatrix);

            if (buildHitTestBox)
            {
                boxes.HitTestBox = _boundingBoxBuilder.BuildHitTestBox(ref intermediateBox);
            }
            if (buildRenderBox)
            {
                PointF scale;
                var    viewportMatrix = matrices.ViewportMatrix;
                boxes.RenderBox = _boundingBoxBuilder.BuildRenderBox(ref intermediateBox, ref viewportMatrix, out scale);
            }
        }
        public void Build(IGLBoundingBoxes boxes, float width, float height, IGLMatrices matrices, bool buildRenderBox, bool buildHitTestBox)
        {
            float   left        = 0f;
            float   right       = width;
            float   bottom      = 0f;
            float   top         = height;
            Vector3 bottomLeft  = Vector3.Transform(new Vector3(left, bottom, 0f), matrices.ModelMatrix);
            Vector3 topLeft     = Vector3.Transform(new Vector3(left, top, 0f), matrices.ModelMatrix);
            Vector3 bottomRight = Vector3.Transform(new Vector3(right, bottom, 0f), matrices.ModelMatrix);
            Vector3 topRight    = Vector3.Transform(new Vector3(right, top, 0f), matrices.ModelMatrix);

            if (buildHitTestBox)
            {
                buildForHitTest(boxes.HitTestBox, bottomLeft, topLeft, bottomRight, topRight);
            }
            if (buildRenderBox)
            {
                buildForRender(boxes.RenderBox, matrices, bottomLeft, topLeft, bottomRight, topRight);
            }
        }
Exemple #7
0
        private void updateBoundingBoxes(IObject obj, IDrawableInfo drawable, IViewport viewport)
        {
            AutoFit autoFit = getAutoFit();

            float height = obj.Height;
            float width  = obj.Width;

            if (autoFit == AutoFit.LabelShouldFitText)
            {
                updateText(GLText.EmptySize, null);
                CustomImageSize = new SizeF(_glText.Width, _glText.Height);
            }
            else
            {
                CustomImageSize = BaseSize;
            }

            var resolutionFactor = string.IsNullOrEmpty(Text) ? AGSModelMatrixComponent.NoScaling : new PointF(GLText.TextResolutionFactorX, GLText.TextResolutionFactorY);

            CustomImageResolutionFactor = resolutionFactor;
            var  noFactor          = AGSModelMatrixComponent.NoScaling;
            bool resolutionMatches = resolutionFactor.Equals(noFactor);
            var  viewportMatrix    = drawable.IgnoreViewport ? Matrix4.Identity : _viewport.GetViewport(drawable.RenderLayer.Z).GetMatrix(viewport, drawable.RenderLayer.ParallaxSpeed);

            var modelMatrices = obj.GetModelMatrices();

            IGLMatrices textRenderMatrices = new GLMatrices {
                ModelMatrix = modelMatrices.InObjResolutionMatrix, ViewportMatrix = viewportMatrix
            };                                                                                                                                      //_textRenderMatrixBuilder.Build(_labelMatrixRenderTarget, sprite, parent, matrix, areaScaling, resolutionFactor);
            IGLMatrices labelRenderMatrices = new GLMatrices {
                ModelMatrix = modelMatrices.InVirtualResolutionMatrix, ViewportMatrix = viewportMatrix
            };                                                                                                                                           // _labelRenderMatrixBuilder.Build(_labelMatrixRenderTarget, sprite, parent, matrix, areaScaling, noFactor);
            IGLMatrices textHitTestMatrices  = resolutionMatches ? textRenderMatrices : labelRenderMatrices;
            IGLMatrices labelHitTestMatrices = labelRenderMatrices;

            updateBoundingBoxes(autoFit, textHitTestMatrices, labelHitTestMatrices, noFactor, resolutionMatches, true);
            if (!resolutionMatches)
            {
                updateBoundingBoxes(autoFit, textRenderMatrices, labelRenderMatrices, resolutionFactor, true, false);
            }
        }
Exemple #8
0
        private void updateBoundingBoxes(IObject obj, IDrawableInfoComponent drawable, IViewport viewport)
        {
            var    noFactor = AGSModelMatrixComponent.NoScaling;
            bool   resolutionMatches;
            PointF hitTestResolutionFactor;
            Size   resolution;
            PointF textScaleFactor = new PointF(GLText.TextResolutionFactorX, GLText.TextResolutionFactorY);

            if (!textScaleFactor.Equals(_lastTextScaleFactor))
            {
                _lastTextScaleFactor = textScaleFactor;
                onBoundingBoxShouldChange();
            }
            resolutionMatches = AGSModelMatrixComponent.GetVirtualResolution(false, _virtualResolution, drawable,
                                                                             textScaleFactor, out hitTestResolutionFactor,
                                                                             out resolution);
            var scaleUpText   = hitTestResolutionFactor;
            var scaleDownText = noFactor;

            if (!textScaleFactor.Equals(hitTestResolutionFactor))
            {
                textScaleFactor = noFactor;
                scaleDownText   = hitTestResolutionFactor;
            }
            AutoFit autoFit = getAutoFit();
            float   height  = obj.Height;
            float   width   = obj.Width;

            bool shouldUpdateBoundingBoxes = _shouldUpdateBoundingBoxes;

            _shouldUpdateBoundingBoxes = false;
            if (autoFit == AutoFit.LabelShouldFitText)
            {
                updateText(_glTextHitTest, resolutionMatches, GLText.EmptySize, scaleUpText, scaleDownText, int.MaxValue);
                if (!resolutionMatches)
                {
                    updateText(_glTextRender, true, GLText.EmptySize, scaleUpText, scaleDownText, int.MaxValue);
                }
                CustomImageSize = new SizeF(_glTextHitTest.Width, _glTextHitTest.Height);
            }
            else if (autoFit == AutoFit.TextShouldWrapAndLabelShouldFitHeight)
            {
                updateText(_glTextHitTest, resolutionMatches, new SizeF(BaseSize.Width, GLText.EmptySize.Height), scaleUpText, scaleDownText, (int)BaseSize.Width);
                if (!resolutionMatches)
                {
                    updateText(_glTextRender, true, new SizeF(BaseSize.Width, GLText.EmptySize.Height), scaleUpText, scaleDownText, (int)BaseSize.Width);
                }
                CustomImageSize = new SizeF(BaseSize.Width, _glTextHitTest.Height);
            }
            else
            {
                CustomImageSize = BaseSize;
            }

            CustomImageResolutionFactor = hitTestResolutionFactor;
            var viewportMatrix = drawable.IgnoreViewport ? Matrix4.Identity : _viewport.GetViewport(drawable.RenderLayer.Z).GetMatrix(viewport, drawable.RenderLayer.ParallaxSpeed);

            if (!viewportMatrix.Equals(_lastViewportMatrix))
            {
                _lastViewportMatrix = viewportMatrix;
                onBoundingBoxShouldChange();
            }

            var modelMatrices = obj.GetModelMatrices();

            if (!modelMatrices.Equals(_lastMatrices))
            {
                _lastMatrices = modelMatrices;
                onBoundingBoxShouldChange();
            }
            if (!shouldUpdateBoundingBoxes)
            {
                return;
            }

            IGLMatrices textRenderMatrices   = acquireMatrix(0).SetMatrices(modelMatrices.InObjResolutionMatrix, viewportMatrix);
            IGLMatrices labelRenderMatrices  = obj.RenderLayer.IndependentResolution != null ? textRenderMatrices : acquireMatrix(1).SetMatrices(modelMatrices.InVirtualResolutionMatrix, viewportMatrix);
            IGLMatrices textHitTestMatrices  = resolutionMatches ? textRenderMatrices : obj.RenderLayer.IndependentResolution == null ? labelRenderMatrices : acquireMatrix(2).SetMatrices(modelMatrices.InVirtualResolutionMatrix, viewportMatrix);
            IGLMatrices labelHitTestMatrices = obj.RenderLayer.IndependentResolution == null ? labelRenderMatrices : textHitTestMatrices;

            if (textScaleFactor.Equals(hitTestResolutionFactor))
            {
                hitTestResolutionFactor = noFactor;
            }

            updateBoundingBoxes(_glTextHitTest, autoFit, textHitTestMatrices, labelHitTestMatrices, scaleUpText, noFactor, hitTestResolutionFactor, resolutionMatches, true);
            if (!resolutionMatches)
            {
                updateBoundingBoxes(_glTextRender, autoFit, textRenderMatrices, labelRenderMatrices, scaleUpText, scaleDownText, noFactor, true, false);
            }

            if (_lastWidth != Width || _lastHeight != Height)
            {
                OnLabelSizeChanged.Invoke();
            }
            _lastWidth  = Width;
            _lastHeight = Height;
        }
Exemple #9
0
 public void Build(IGLBoundingBoxes boxes, float width, float height, IGLMatrices matrices, bool buildRenderBox, bool buildHitTestBox)
 {
 }
Exemple #10
0
        private void updateBoundingBoxes(AutoFit autoFit, IGLMatrices textMatrices, IGLMatrices labelMatrices, PointF resolutionFactor, bool buildRenderBox, bool buildHitTestBox)
        {
            switch (autoFit)
            {
            case AutoFit.NoFitting:
                _boundingBoxBuilder.Build(_labelBoundingBoxes, BaseSize.Width, BaseSize.Height, labelMatrices, buildRenderBox, buildHitTestBox);
                updateText(GLText.EmptySize, null);
                _boundingBoxBuilder.Build(_textBoundingBoxes, _glText.BitmapWidth, _glText.BitmapHeight, textMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.TextShouldWrapAndLabelShouldFitHeight:
                _boundingBoxBuilder.Build(_labelBoundingBoxes, BaseSize.Width, BaseSize.Height, labelMatrices, buildRenderBox, buildHitTestBox);
                updateText(GLText.EmptySize, (int?)BaseSize.Width);
                _boundingBoxBuilder.Build(_textBoundingBoxes, _glText.BitmapWidth, _glText.BitmapHeight, textMatrices, buildRenderBox, buildHitTestBox);
                _boundingBoxBuilder.Build(_labelBoundingBoxes, _glText.Width, _glText.Height, labelMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.TextShouldFitLabel:
                _boundingBoxBuilder.Build(_labelBoundingBoxes, BaseSize.Width, BaseSize.Height, labelMatrices, buildRenderBox, buildHitTestBox);
                updateText(_glText.Width > BaseSize.Width ? GLText.EmptySize : new SizeF(BaseSize.Width, GLText.EmptySize.Height), null);

                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);

                _boundingBoxBuilder.Build(_textBoundingBoxes, textWidth, textHeight, textMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.LabelShouldFitText:
                _boundingBoxBuilder.Build(_textBoundingBoxes, _glText.BitmapWidth, _glText.BitmapHeight, textMatrices, buildRenderBox, buildHitTestBox);
                _boundingBoxBuilder.Build(_labelBoundingBoxes, _glText.Width * resolutionFactor.X, _glText.Height * resolutionFactor.Y,
                                          textMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.TextShouldCrop:
                _boundingBoxBuilder.Build(_labelBoundingBoxes, BaseSize.Width, BaseSize.Height, labelMatrices, buildRenderBox, buildHitTestBox);
                updateText(_glText.Width > BaseSize.Width ? GLText.EmptySize : new SizeF(BaseSize.Width, GLText.EmptySize.Height), (int)BaseSize.Width, true);

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

                _boundingBoxBuilder.Build(_textBoundingBoxes, _glText.BitmapWidth, heightOfText, textMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            default:
                throw new NotSupportedException(autoFit.ToString());
            }
        }