Exemplo n.º 1
0
        private void buildMatrix()
        {
            var     pivotOffsets = AGSModelMatrixComponent.GetPivotOffsets(_lastPivot, _virtualResolution.Width, _virtualResolution.Height);
            Matrix4 pivotMat     = Matrix4.CreateTranslation(new Vector3(pivotOffsets.X, pivotOffsets.Y, 0f));
            var     radians      = MathUtils.DegreesToRadians(_lastRotation);

            _lastMatrix =
                Matrix4.CreateTranslation(new Vector3(-_lastX * _lastParallaxSpeedX, -_lastY * _lastParallaxSpeedY, 0f)) *
                Matrix4.CreateRotationZ(radians) *
                Matrix4.CreateScale(_lastScaleX, _lastScaleY, 1f) * pivotMat;
        }
        private void updateHitTestBox(SizeF size, IDrawableInfoComponent drawable, IModelMatrixComponent matrix)
        {
            var modelMatrices = matrix.GetModelMatrices();
            var modelMatrix   = modelMatrices.InVirtualResolutionMatrix;

            AGSModelMatrixComponent.GetVirtualResolution(false, _settings.VirtualResolution,
                                                         drawable, null, out PointF resolutionFactor, out Size _);

            float width  = size.Width / resolutionFactor.X;
            float height = size.Height / resolutionFactor.Y;

            _intermediateBox = _boundingBoxBuilder.BuildIntermediateBox(width, height, ref modelMatrix);
            _hitTestBox      = _boundingBoxBuilder.BuildHitTestBox(ref _intermediateBox);
        }
Exemplo n.º 3
0
        public void Render(IObject obj, IViewport viewport)
        {
            if (!TextBackgroundVisible && !TextVisible)
            {
                return;
            }
            if (!obj.Visible || _usedTextBoundingBoxes == null)
            {
                return;
            }

            PointF resolutionFactor; Size resolution;
            PointF textScaleFactor = new PointF(GLText.TextResolutionFactorX, GLText.TextResolutionFactorY);

            AGSModelMatrixComponent.GetVirtualResolution(false, _virtualResolution, obj,
                                                         textScaleFactor, out resolutionFactor, out resolution);
            if (!resolutionFactor.Equals(textScaleFactor))
            {
                resolutionFactor = AGSModelMatrixComponent.NoScaling;
            }

            if (TextBackgroundVisible)
            {
                _bgRenderer.Render(obj, viewport);
            }

            if (TextVisible && Text != "")
            {
                _glTextHitTest.Refresh();
                if (!string.IsNullOrEmpty(Text))
                {
                    _glUtils.AdjustResolution(resolution.Width, resolution.Height);
                }

                IGLColor color    = _colorBuilder.Build(Colors.White);
                var      cropInfo = _usedTextBoundingBoxes.RenderBox.Crop(BoundingBoxType.Render, CustomTextCrop ?? obj.GetComponent <ICropSelfComponent>(), AGSModelMatrixComponent.NoScaling);
                if (cropInfo.Equals(_defaultCrop))
                {
                    return;
                }

                _afterCropTextBoundingBoxes.RenderBox  = cropInfo.BoundingBox;
                _afterCropTextBoundingBoxes.TextureBox = cropInfo.TextureBox;

                _textureRenderer.Render(_glTextHitTest.Texture, _afterCropTextBoundingBoxes, color);
            }
        }
Exemplo n.º 4
0
        private void updateHitTestBox(IAnimationComponent animation, IDrawableInfoComponent drawable, IModelMatrixComponent matrix)
        {
            var modelMatrices = matrix.GetModelMatrices();
            var modelMatrix   = modelMatrices.InVirtualResolutionMatrix;

            Size   resolution;
            PointF resolutionFactor;
            bool   resolutionMatches = AGSModelMatrixComponent.GetVirtualResolution(false, _settings.VirtualResolution,
                                                                                    drawable, null, out resolutionFactor, out resolution);

            var   sprite = animation.Animation.Sprite;
            float width  = sprite.BaseSize.Width / resolutionFactor.X;
            float height = sprite.BaseSize.Height / resolutionFactor.Y;

            _intermediateBox = _boundingBoxBuilder.BuildIntermediateBox(width, height, ref modelMatrix);
            _hitTestBox      = _boundingBoxBuilder.BuildHitTestBox(ref _intermediateBox);
        }
        private AGSBoundingBoxes recalculate(IViewport viewport, ViewportBoundingBoxes viewportBoxes)
        {
            var  boundingBoxes     = viewportBoxes.BoundingBoxes;
            var  drawable          = _drawable;
            var  matrix            = _matrix;
            var  scale             = _scale;
            var  sprite            = _image?.CurrentSprite;
            bool isHitTestBoxDirty = _isHitTestBoxDirty;

            if (scale == null || drawable == null || matrix == null)
            {
                return(boundingBoxes);
            }

            var baseSize = sprite?.BaseSize ?? scale.BaseSize;

            if (isHitTestBoxDirty)
            {
                _isCropDirty       = true;
                _isHitTestBoxDirty = false;
                updateHitTestBox(baseSize, drawable, matrix);
            }
            var crop = _crop;

            _areViewportsDirty    = false;
            viewportBoxes.IsDirty = false;

            bool resolutionMatches = AGSModelMatrixComponent.GetVirtualResolution(false, _settings.VirtualResolution,
                                                                                  drawable, null, out PointF _, out Size _);

            var            viewportMatrix = drawable.IgnoreViewport ? Matrix4.Identity : viewport.GetMatrix(drawable.RenderLayer);
            AGSBoundingBox intermediateBox, hitTestBox;

            hitTestBox = _hitTestBox;

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

            if (resolutionMatches)
            {
                intermediateBox = _intermediateBox;
            }
            else
            {
                var modelMatrices = matrix.GetModelMatrices();
                var modelMatrix   = modelMatrices.InObjResolutionMatrix;
                intermediateBox = _boundingBoxBuilder.BuildIntermediateBox(width, height, ref modelMatrix);
            }

            var renderBox = _boundingBoxBuilder.BuildRenderBox(ref intermediateBox, ref viewportMatrix, out PointF renderCropScale);

            PointF hitTestCropScale = renderCropScale;

            if (MathUtils.FloatEquals(hitTestCropScale.X, 1f) && MathUtils.FloatEquals(hitTestCropScale.Y, 1f))
            {
                hitTestCropScale = new PointF(_hitTestBox.Width / renderBox.Width, _hitTestBox.Height / renderBox.Height);
            }

            var cropInfo = renderBox.Crop(BoundingBoxType.Render, crop, renderCropScale);

            boundingBoxes.PreCropViewportBox = renderBox;
            renderBox = cropInfo.BoundingBox;
            boundingBoxes.ViewportBox = renderBox;
            if (cropInfo.TextureBox != null)
            {
                boundingBoxes.TextureBox = cropInfo.TextureBox;
            }
            else
            {
                var textureOffset = _textureOffset;
                var image         = sprite?.Image;
                // ReSharper disable CompareOfFloatsByEqualityOperator
                if (image != null && (width != image.Width || height != image.Height ||
                                      // ReSharper restore CompareOfFloatsByEqualityOperator
                                      (!textureOffset?.TextureOffset.Equals(PointF.Empty) ?? false)))
                {
                    var offset = textureOffset?.TextureOffset ?? PointF.Empty;
                    setProportionalTextureSize(boundingBoxes, image, width, height, offset);
                }
                else
                {
                    boundingBoxes.TextureBox = null;
                }
            }

            if (cropInfo.Equals(_defaultCropInfo))
            {
                boundingBoxes.WorldBox = default;
            }
            else
            {
                hitTestBox             = hitTestBox.Crop(BoundingBoxType.HitTest, crop, hitTestCropScale).BoundingBox;
                boundingBoxes.WorldBox = hitTestBox;
            }
            _isCropDirty = false;

            return(boundingBoxes);
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        private AGSBoundingBoxes recalculate(IViewport viewport, ViewportBoundingBoxes viewportBoxes)
        {
            var  boundingBoxes     = viewportBoxes.BoundingBoxes;
            var  animation         = _animation;
            var  drawable          = _drawable;
            var  matrix            = _matrix;
            bool isHitTestBoxDirty = _isHitTestBoxDirty;

            if (animation?.Animation?.Sprite?.Image == null || drawable == null || matrix == null)
            {
                return(boundingBoxes);
            }

            if (isHitTestBoxDirty)
            {
                _isCropDirty       = true;
                _isHitTestBoxDirty = false;
                updateHitTestBox(animation, drawable, matrix);
            }
            var crop = _crop;

            _isCropDirty          = false;
            _areViewportsDirty    = false;
            viewportBoxes.IsDirty = false;

            var    layerViewport = _layerViewports.GetViewport(drawable.RenderLayer.Z);
            Size   resolution;
            PointF resolutionFactor;
            bool   resolutionMatches = AGSModelMatrixComponent.GetVirtualResolution(false, _settings.VirtualResolution,
                                                                                    drawable, null, out resolutionFactor, out resolution);

            var            viewportMatrix = drawable.IgnoreViewport ? Matrix4.Identity : layerViewport.GetMatrix(viewport, drawable.RenderLayer.ParallaxSpeed);
            AGSBoundingBox intermediateBox, hitTestBox;

            hitTestBox = _hitTestBox;

            var   sprite     = animation.Animation.Sprite;
            float width      = sprite.BaseSize.Width;
            float height     = sprite.BaseSize.Height;

            if (resolutionMatches)
            {
                intermediateBox = _intermediateBox;
            }
            else
            {
                var modelMatrices = matrix.GetModelMatrices();
                var modelMatrix   = modelMatrices.InObjResolutionMatrix;
                intermediateBox = _boundingBoxBuilder.BuildIntermediateBox(width, height, ref modelMatrix);
            }

            PointF renderCropScale;
            var    renderBox = _boundingBoxBuilder.BuildRenderBox(ref intermediateBox, ref viewportMatrix, out renderCropScale);

            PointF hitTestCropScale = renderCropScale;

            if (MathUtils.FloatEquals(hitTestCropScale.X, 1f) && MathUtils.FloatEquals(hitTestCropScale.Y, 1f))
            {
                hitTestCropScale = new PointF(_hitTestBox.Width / renderBox.Width, _hitTestBox.Height / renderBox.Height);
            }

            var cropInfo = renderBox.Crop(BoundingBoxType.Render, crop, renderCropScale);

            boundingBoxes.PreCropRenderBox = renderBox;
            renderBox = cropInfo.BoundingBox;
            boundingBoxes.RenderBox = renderBox;
            if (cropInfo.TextureBox != null)
            {
                boundingBoxes.TextureBox = cropInfo.TextureBox;
            }
            else
            {
                var textureOffset = _textureOffset;
                if (width != sprite.Image.Width || height != sprite.Image.Height ||
                    (!textureOffset?.TextureOffset.Equals(Vector2.Zero) ?? false))
                {
                    var offset = textureOffset?.TextureOffset ?? PointF.Empty;
                    setProportionalTextureSize(boundingBoxes, sprite, width, height, offset);
                }
                else
                {
                    boundingBoxes.TextureBox = null;
                }
            }

            if (cropInfo.Equals(_defaultCropInfo))
            {
                boundingBoxes.HitTestBox = default;
            }
            else
            {
                hitTestBox = hitTestBox.Crop(BoundingBoxType.HitTest, crop, hitTestCropScale).BoundingBox;
                boundingBoxes.HitTestBox = hitTestBox;
            }

            return(boundingBoxes);
        }