示例#1
0
 public bool DrawQuad(IFrameBuffer frameBuffer, AGSBoundingBox square, GLVertex[] vertices)
 {
     if (frameBuffer == null)
     {
         return(false);
     }
     vertices[0] = new GLVertex(square.BottomLeft.Xy, _bottomLeft, Colors.White);
     vertices[1] = new GLVertex(square.BottomRight.Xy, _bottomRight, Colors.White);
     vertices[2] = new GLVertex(square.TopRight.Xy, _topRight, Colors.White);
     vertices[3] = new GLVertex(square.TopLeft.Xy, _topLeft, Colors.White);
     DrawQuad(frameBuffer.Texture.ID, vertices);
     return(true);
 }
示例#2
0
        public bool CollidesWith(float x, float y, IViewport viewport)
        {
            var boundingBoxesComponent = _boundingBox;

            if (boundingBoxesComponent == null)
            {
                return(false);
            }
            var boundingBoxes = boundingBoxesComponent.GetBoundingBoxes(viewport);

            if (boundingBoxes == null)
            {
                return(false);
            }
            AGSBoundingBox boundingBox           = boundingBoxes.HitTestBox;
            var            pixelPerfectComponent = _pixelPerfect;
            IArea          pixelPerfect          = pixelPerfectComponent == null ? null : pixelPerfectComponent.PixelPerfectHitTestArea;

            if (_drawableInfo?.IgnoreViewport ?? false)
            {
                //todo: Support viewport rotation (+ ignore scaling areas = false?)
                x = (x - viewport.X) * viewport.ScaleX;
                y = (y - viewport.Y) * viewport.ScaleY;
            }

            if (pixelPerfect == null || !pixelPerfect.Enabled)
            {
                if (!boundingBox.IsValid)
                {
                    return(false);
                }
                if (boundingBox.Contains(new Vector2(x, y)))
                {
                    return(true);
                }
            }
            else
            {
                var   obj       = _obj;
                float objScaleX = obj == null ? 1f : obj.Animation.Sprite.ScaleX;
                float objScaleY = obj == null ? 1f : obj.Animation.Sprite.ScaleY;
                var   scale     = _scale;
                float scaleX    = scale == null ? 1f : scale.ScaleX;
                float scaleY    = scale == null ? 1f : scale.ScaleY;
                if (pixelPerfect.IsInArea(new PointF(x, y), boundingBox, scaleX * objScaleX, scaleY * objScaleY))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#3
0
        private bool recalculateBeforeUnlock()
        {
            var lastBox    = BoundingBoxWithChildren;
            var lastPreBox = PreCropBoundingBoxWithChildren;

            _preUnlockBoundingBox        = getBoundingBox(_tree, _boundingBox, boxes => boxes.ViewportBox, DebugPrintouts ? $"Box before unlock ({_entity.ID})" : null);
            _preUnlockPreCropBoundingBox = getBoundingBox(_tree, _boundingBox, boxes => boxes.PreCropViewportBox, DebugPrintouts ? $"Box Pre Crop before unlock ({_entity.ID})" : null);
            if (DebugPrintouts)
            {
                Debug.WriteLine($"Pre crop (before unlock) for ${_entity.ID}: {_preUnlockBoundingBox.ToString()}");
            }
            _isDirty = false;
            return(!lastBox.Equals(_preUnlockBoundingBox) || !lastPreBox.Equals(_preUnlockPreCropBoundingBox));
        }
示例#4
0
        public bool IsMasked_WithProjection_Test(int width, int height, float x, float y, float projectionLeft, float projectionBottom, float scaleX, float scaleY, params int[] pointsInMask)
        {
            bool[][] array = GetArray(width, height, true, pointsInMask);
            AGSMask  mask  = new AGSMask(array, null);


            Vector2        bottomLeft  = new Vector2(projectionLeft, projectionBottom);
            Vector2        bottomRight = new Vector2(projectionLeft + width * Math.Abs(scaleX), projectionBottom);
            Vector2        topLeft     = new Vector2(projectionLeft, projectionBottom + height * Math.Abs(scaleY));
            Vector2        topRight    = new Vector2(projectionLeft + width * Math.Abs(scaleX), projectionBottom + height * Math.Abs(scaleY));
            AGSBoundingBox square      = new AGSBoundingBox(bottomLeft, bottomRight, topLeft, topRight);

            return(mask.IsMasked(new PointF(x, y), square, scaleX, scaleY));
        }
        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);
        }
示例#6
0
        public bool CollidesWith(float x, float y, IViewport viewport)
        {
            var boundingBoxesComponent = _boundingBox;

            if (boundingBoxesComponent == null)
            {
                return(false);
            }
            AGSBoundingBox boundingBox           = boundingBoxesComponent.WorldBoundingBox;
            var            pixelPerfectComponent = _pixelPerfect;
            IArea          pixelPerfect          = pixelPerfectComponent == null || !pixelPerfectComponent.IsPixelPerfect ? null : pixelPerfectComponent.PixelPerfectHitTestArea;

            if (!(_drawableInfo?.IgnoreViewport ?? false))
            {
                var matrix = viewport.GetMatrix(_drawableInfo.RenderLayer);
                matrix.Invert();
                Vector3 xyz = new Vector3(x, y, 0f);
                Vector3.Transform(ref xyz, ref matrix, out xyz);
                //todo: (support ignore scaling areas = false?)
                x = xyz.X;
                y = xyz.Y;
            }

            if (pixelPerfect == null || !pixelPerfect.Enabled)
            {
                if (!boundingBox.IsValid)
                {
                    return(false);
                }
                if (boundingBox.Contains(new Vector2(x, y)))
                {
                    return(true);
                }
            }
            else
            {
                var   obj       = _obj;
                float objScaleX = obj == null ? 1f : obj.CurrentSprite.ScaleX;
                float objScaleY = obj == null ? 1f : obj.CurrentSprite.ScaleY;
                var   scale     = _scale;
                float scaleX    = scale == null ? 1f : scale.ScaleX;
                float scaleY    = scale == null ? 1f : scale.ScaleY;
                if (pixelPerfect.IsInArea(new PointF(x, y), boundingBox, scaleX * objScaleX, scaleY * objScaleY))
                {
                    return(true);
                }
            }
            return(false);
        }
        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);
        }
示例#8
0
        public IFrameBuffer BeginFrameBuffer(AGSBoundingBox square, IRuntimeSettings settings)
        {
            float width       = square.MaxX - square.MinX;
            float height      = square.MaxY - square.MinY;
            var   aspectRatio = new SizeF(settings.WindowSize.Width / CurrentResolution.Width,
                                          settings.WindowSize.Height / CurrentResolution.Height);

            var frameBuffer = new GLFrameBuffer(new Size((int)Math.Ceiling(width * aspectRatio.Width),
                                                         (int)Math.Ceiling(height * aspectRatio.Height)), _graphics, _messagePump);

            if (!frameBuffer.Begin())
            {
                frameBuffer.End();
                return(null);
            }
            return(frameBuffer);
        }
示例#9
0
        private void drawRoundCorner(Vector3 center, float radius, float angle, AGSBoundingBox border, FourCorners <IGLColor> colors)
        {
            Vector2  tex          = new Vector2();
            GLVertex centerVertex = new GLVertex(center.Xy, tex, getColor(colors, border, center));

            _roundCorner[0] = centerVertex;
            float step = (90f / (_roundCorner.Length - 2));

            for (int i = 1; i < _roundCorner.Length; i++)
            {
                float anglerad = (float)Math.PI * angle / 180.0f;
                float x        = (float)Math.Sin(anglerad) * radius;
                float y        = (float)Math.Cos(anglerad) * radius;
                angle += step;
                Vector3 point = new Vector3(x + center.X, y + center.Y, 0f);
                _roundCorner[i] = new GLVertex(point.Xy, tex, getColor(colors, border, point));
            }

            _glUtils.DrawTriangleFan(0, _roundCorner);
        }
示例#10
0
文件: XIcon.cs 项目: saizant/MonoAGS
        public void RenderBorderFront(AGSBoundingBox square)
        {
            if (_glUtils.DrawQuad(_frameBuffer, square, _quad))
            {
                return;
            }

            float width  = _glUtils.CurrentResolution.Width - _padding;
            float height = _glUtils.CurrentResolution.Height - _padding;

            _frameBuffer = _glUtils.BeginFrameBuffer(square, _settings);
            if (_frameBuffer == null)
            {
                return;
            }
            _glUtils.DrawLine(_padding, _padding, width, height, _lineWidth, _color.R, _color.G, _color.B, _color.A);
            _glUtils.DrawLine(_padding, height, width, _padding, _lineWidth, _color.R, _color.G, _color.B, _color.A);

            _frameBuffer.End();

            _glUtils.DrawQuad(_frameBuffer, square, _quad);
        }
        private void drawStretch(SliceValues border, SliceValues slice, SliceValues width)
        {
            var topQuad = new AGSBoundingBox(new Vector2(border.Left.Value + width.Left.Value, border.Top.Value - width.Top.Value),
                                             new Vector2(border.Right.Value - width.Right.Value, border.Top.Value - width.Top.Value),
                                             new Vector2(border.Left.Value + width.Left.Value, border.Top.Value),
                                             new Vector2(border.Right.Value - width.Right.Value, border.Top.Value));


            var bottomQuad = new AGSBoundingBox(new Vector2(border.Left.Value + width.Left.Value, border.Bottom.Value),
                                                new Vector2(border.Right.Value - width.Right.Value, border.Bottom.Value),
                                                new Vector2(border.Left.Value + width.Left.Value, border.Bottom.Value + width.Bottom.Value),
                                                new Vector2(border.Right.Value - width.Right.Value, border.Bottom.Value + width.Bottom.Value));

            var leftQuad = new AGSBoundingBox(new Vector2(border.Left.Value, border.Bottom.Value + width.Bottom.Value),
                                              new Vector2(border.Left.Value + width.Left.Value, border.Bottom.Value + width.Bottom.Value),
                                              new Vector2(border.Left.Value, border.Top.Value - width.Top.Value),
                                              new Vector2(border.Left.Value + width.Left.Value, border.Top.Value - width.Top.Value));

            var rightQuad = new AGSBoundingBox(new Vector2(border.Right.Value - width.Right.Value, border.Bottom.Value + width.Bottom.Value),
                                               new Vector2(border.Right.Value, border.Bottom.Value + width.Bottom.Value),
                                               new Vector2(border.Right.Value - width.Right.Value, border.Top.Value - width.Top.Value),
                                               new Vector2(border.Right.Value, border.Top.Value - width.Top.Value));

            drawQuad(topQuad, new FourCorners <Vector2> (new Vector2(slice.Left.Value, 1f - slice.Top.Value),
                                                         new Vector2(1f - slice.Right.Value, 1f - slice.Top.Value), new Vector2(slice.Left.Value, 1f),
                                                         new Vector2(1f - slice.Right.Value, 1f)));

            drawQuad(bottomQuad, new FourCorners <Vector2> (new Vector2(slice.Left.Value, 0f),
                                                            new Vector2(1f - slice.Right.Value, 0f), new Vector2(slice.Left.Value, slice.Bottom.Value),
                                                            new Vector2(1f - slice.Right.Value, slice.Bottom.Value)));

            drawQuad(leftQuad, new FourCorners <Vector2> (new Vector2(0f, slice.Bottom.Value),
                                                          new Vector2(slice.Left.Value, slice.Bottom.Value), new Vector2(0f, 1f - slice.Top.Value),
                                                          new Vector2(slice.Left.Value, 1f - slice.Top.Value)));

            drawQuad(rightQuad, new FourCorners <Vector2> (new Vector2(1f - slice.Right.Value, slice.Bottom.Value),
                                                           new Vector2(1f, slice.Bottom.Value), new Vector2(1f - slice.Right.Value, 1f - slice.Top.Value),
                                                           new Vector2(1f, 1f - slice.Top.Value)));
        }
示例#12
0
 public bool IsInArea(PointF point, AGSBoundingBox projectionBox, float scaleX, float scaleY)
 {
     return(Mask.IsMasked(point, projectionBox, scaleX, scaleY));
 }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:AGS.API.AGSCropInfo"/> struct.
 /// </summary>
 /// <param name="boundingBox">Bounding box.</param>
 /// <param name="textureBox">Texture box.</param>
 public AGSCropInfo(AGSBoundingBox boundingBox, FourCorners <Vector2> textureBox)
 {
     TextureBox  = textureBox;
     BoundingBox = boundingBox;
 }
示例#14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:AGS.API.BeforeCropEventArgs"/> struct.
 /// </summary>
 /// <param name="boundingBox">Bounding box.</param>
 /// <param name="boundingBoxType">Bounding box type.</param>
 public BeforeCropEventArgs(AGSBoundingBox boundingBox, BoundingBoxType boundingBoxType)
 {
     BoundingBox     = boundingBox;
     BoundingBoxType = boundingBoxType;
 }
示例#15
0
        private void drawBorders(AGSBoundingBox square)
        {
            FourCorners <IGLColor> colors = Color.Convert(c => c.ToGLColor());

            float farBottomLeftX  = square.BottomLeft.X - LineWidth;
            float farBottomLeftY  = square.BottomLeft.Y - LineWidth;
            float farBottomRightX = square.BottomRight.X + LineWidth;
            float farBottomRightY = square.BottomRight.Y - LineWidth;
            float farTopLeftX     = square.TopLeft.X - LineWidth;
            float farTopLeftY     = square.TopLeft.Y + LineWidth;
            float farTopRightX    = square.TopRight.X + LineWidth;
            float farTopRightY    = square.TopRight.Y + LineWidth;

            AGSBoundingBox colorBox = new AGSBoundingBox(new Vector2(farBottomLeftX, farBottomLeftY), new Vector2(farBottomRightX, farBottomRightY),
                                                         new Vector2(farTopLeftX, farTopLeftY), new Vector2(farTopRightX, farTopRightY));

            float          topQuadLeftX  = HasRoundCorner.TopLeft ? square.TopLeft.X : farTopLeftX;
            float          topQuadRightX = HasRoundCorner.TopRight ? square.TopRight.X : farTopRightX;
            AGSBoundingBox topQuad       = new AGSBoundingBox(
                new Vector2(topQuadLeftX, square.TopLeft.Y), new Vector2(topQuadRightX, square.TopRight.Y),
                new Vector2(topQuadLeftX, farTopLeftY), new Vector2(topQuadRightX, farTopRightY));

            float          bottomQuadLeftX  = HasRoundCorner.BottomLeft ? square.BottomLeft.X : farBottomLeftX;
            float          bottomQuadRightX = HasRoundCorner.BottomRight ? square.BottomRight.X : farBottomRightX;
            AGSBoundingBox bottomQuad       = new AGSBoundingBox(
                new Vector2(bottomQuadLeftX, farBottomLeftY), new Vector2(bottomQuadRightX, farBottomRightY),
                new Vector2(bottomQuadLeftX, square.BottomLeft.Y), new Vector2(bottomQuadRightX, square.BottomRight.Y));

            float          leftQuadBottomY = square.BottomLeft.Y;
            float          leftQuadTopY    = square.TopLeft.Y;
            AGSBoundingBox leftQuad        = new AGSBoundingBox(
                new Vector2(farBottomLeftX, leftQuadBottomY), new Vector2(square.BottomLeft.X, leftQuadBottomY),
                new Vector2(farTopLeftX, leftQuadTopY), new Vector2(square.TopLeft.X, leftQuadTopY));

            float          rightQuadBottomY = square.BottomRight.Y;
            float          rightQuadTopY    = square.TopRight.Y;
            AGSBoundingBox rightQuad        = new AGSBoundingBox(
                new Vector2(square.BottomRight.X, rightQuadBottomY), new Vector2(farBottomRightX, rightQuadBottomY),
                new Vector2(square.TopRight.X, rightQuadTopY), new Vector2(farTopRightX, rightQuadTopY));

            if (HasRoundCorner.TopLeft)
            {
                drawRoundCorner(square.TopLeft, LineWidth, 270f, colorBox, colors);
            }
            if (HasRoundCorner.TopRight)
            {
                drawRoundCorner(square.TopRight, LineWidth, 0f, colorBox, colors);
            }
            if (HasRoundCorner.BottomLeft)
            {
                drawRoundCorner(square.BottomLeft, LineWidth, 180f, colorBox, colors);
            }
            if (HasRoundCorner.BottomRight)
            {
                drawRoundCorner(square.BottomRight, LineWidth, 90f, colorBox, colors);
            }
            drawQuad(topQuad, colorBox, colors);
            drawQuad(bottomQuad, colorBox, colors);
            drawQuad(leftQuad, colorBox, colors);
            drawQuad(rightQuad, colorBox, colors);
        }
示例#16
0
 private GLColor getColor(FourCorners <IGLColor> colors, AGSBoundingBox border, Vector3 point)
 {
     return(getColor(colors, MathUtils.Lerp(border.BottomLeft.X, 0f, border.BottomRight.X, 1f, point.X),
                     MathUtils.Lerp(border.BottomRight.Y, 0f, border.TopRight.Y, 1f, point.Y)));
 }
 private void drawQuad(AGSBoundingBox quad, FourCorners <Vector2> texturePos)
 {
     _glUtils.DrawQuad(_texture, quad, _white, texturePos);
 }
 public AGSCropInfo Crop(ref AGSBoundingBox box, BoundingBoxType boundingBoxType, PointF adjustedScale)
 {
     (var isGuaranteed, var cropFromGuarantee) = isGuaranteedToFullyCrop();
     if (isGuaranteed)
     {
         return(LastCrop = new AGSCropInfo(default, null, cropFromGuarantee));
示例#19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:AGS.API.AGSCropInfo"/> struct.
 /// </summary>
 /// <param name="boundingBox">Bounding box.</param>
 /// <param name="textureBox">Texture box.</param>
 /// <param name="cropFrom">The direction the item was cropped from, if fully cropped.</param>
 public AGSCropInfo(AGSBoundingBox boundingBox, FourCorners <Vector2> textureBox, CropFrom cropFrom)
 {
     TextureBox  = textureBox;
     BoundingBox = boundingBox;
     CropFrom    = cropFrom;
 }
示例#20
0
        public void Render(IObject obj, IViewport viewport)
        {
            ISprite sprite = obj.CurrentSprite;

            if (sprite == null || sprite.Image == null)
            {
                return;
            }
            var boundingBoxes = obj.GetBoundingBoxes(viewport);

            if (boundingBoxes == null || !boundingBoxes.RenderBox.IsValid)
            {
                return;
            }

            ITexture texture = _textures.GetTexture(sprite.Image.ID, _getTextureFunc);

            _colorAdjusters[0] = sprite;
            _colorAdjusters[1] = obj;
            IGLColor color = _colorBuilder.Build(_colorAdjusters);

            IBorderStyle   border    = obj.Border;
            AGSBoundingBox borderBox = _emptySquare;

            if (!obj.Visible)
            {
                return;
            }
            if (border != null)
            {
                if (boundingBoxes.RenderBox.BottomLeft.X > boundingBoxes.RenderBox.BottomRight.X)
                {
                    borderBox = boundingBoxes.RenderBox.FlipHorizontal();
                }
                else
                {
                    borderBox = boundingBoxes.RenderBox;
                }

                border.RenderBorderBack(borderBox);
            }
            _renderer.Render(texture.ID, boundingBoxes, color);

            border?.RenderBorderFront(borderBox);
            if (obj.DebugDrawPivot)
            {
                IObject parent = obj.TreeNode.Parent;
                float   x      = obj.X;
                float   y      = obj.Y;
                while (parent != null)
                {
                    x     += (parent.X - parent.Width * parent.Pivot.X);
                    y     += (parent.Y - parent.Height * parent.Pivot.Y);
                    parent = parent.TreeNode.Parent;
                }
                if (!obj.IgnoreViewport)
                {
                    x -= viewport.X;
                    y -= viewport.Y;
                }
                _glUtils.DrawCross(x, y, 10, 10, 1f, 1f, 1f, 1f);
            }
        }
示例#21
0
 public AGSBoundingBox BuildHitTestBox(ref AGSBoundingBox intermediateBox) => BoundingBoxes?.HitTestBox ?? default;
示例#22
0
 public void RenderBorderBack(AGSBoundingBox square)
 {
 }
 public AGSBoundingBox BuildHitTestBox(ref AGSBoundingBox intermediateBox)
 {
     return(buildForHitTest(ref intermediateBox));
 }
示例#24
0
 public AGSBoundingBox BuildRenderBox(ref AGSBoundingBox intermediateBox, ref Matrix4 viewportMatrix, out PointF scale)
 {
     scale = AGSModelMatrixComponent.NoScaling;
     return(BoundingBoxes?.RenderBox ?? default);
 }
示例#25
0
 public void Setup(IBorderStyle border, AGSBoundingBox box)
 {
     _border = border;
     _box    = box;
 }