Exemplo n.º 1
0
		public ISquare ToSquare()
		{
			ISquare square = new AGSSquare (new PointF (BottomLeft.X, BottomLeft.Y), new PointF (BottomRight.X, BottomRight.Y),
				new PointF (TopLeft.X, TopLeft.Y), new PointF (TopRight.X, TopRight.Y));
			if (square.BottomLeft.X > square.BottomRight.X) square = square.FlipHorizontal();
			return square;
		}
Exemplo n.º 2
0
		public bool InsideSquareTest (float ax, float ay, float bx, float @by, 
			float cx, float cy, float dx, float dy, float px, float py)
		{
			AGSSquare square = new AGSSquare (new AGS.API.PointF (ax, ay), new AGS.API.PointF (bx, @by),
				new AGS.API.PointF (cx, cy), new AGS.API.PointF (dx, dy));
			return square.Contains (new AGS.API.PointF (px, py));
		}
Exemplo n.º 3
0
        private void drawCorners(SliceValues border, SliceValues slice, SliceValues width)
        {
            var topLeftQuad = new AGSSquare(new PointF(border.Left.Value, border.Top.Value - width.Top.Value),
                                            new PointF(border.Left.Value + width.Top.Value, border.Top.Value - width.Top.Value),
                                            new PointF(border.Left.Value, border.Top.Value), new PointF(border.Left.Value + width.Top.Value, border.Top.Value));

            var topRightQuad = new AGSSquare(new PointF(border.Right.Value - width.Right.Value, border.Top.Value - width.Top.Value),
                                             new PointF(border.Right.Value, border.Top.Value - width.Top.Value),
                                             new PointF(border.Right.Value - width.Right.Value, border.Top.Value), new PointF(border.Right.Value, border.Top.Value));

            var bottomLeftQuad = new AGSSquare(new PointF(border.Left.Value, border.Bottom.Value),
                                               new PointF(border.Left.Value + width.Top.Value, border.Bottom.Value), new PointF(border.Left.Value, border.Bottom.Value + width.Bottom.Value),
                                               new PointF(border.Left.Value + width.Top.Value, border.Bottom.Value + width.Bottom.Value));

            var bottomRightQuad = new AGSSquare(new PointF(border.Right.Value - width.Right.Value, border.Bottom.Value),
                                                new PointF(border.Right.Value, border.Bottom.Value), new PointF(border.Right.Value - width.Right.Value, border.Bottom.Value + width.Bottom.Value),
                                                new PointF(border.Right.Value, border.Bottom.Value + width.Bottom.Value));

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

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

            drawQuad(bottomLeftQuad, new FourCorners <Vector2> (new Vector2(0f, 0f), new Vector2(slice.Left.Value, 0f),
                                                                new Vector2(0f, slice.Bottom.Value), new Vector2(slice.Left.Value, slice.Bottom.Value)));

            drawQuad(bottomRightQuad, new FourCorners <Vector2> (new Vector2(1f - slice.Right.Value, 0f), new Vector2(1f, 0f),
                                                                 new Vector2(1f - slice.Right.Value, slice.Bottom.Value), new Vector2(1f, slice.Bottom.Value)));
        }
Exemplo n.º 4
0
        public void RenderBorderBack(ISquare square)
        {
            runAnimation();

            if (!FillBackground)
            {
                return;
            }

            var slice  = Slice.ToPercentage(_width, _height);
            var width  = Width.ToPixels(_width, _height);
            var outset = Outset.ToPixels(_width, _height);

            float farLeft   = square.TopLeft.X - outset.Left.Value;
            float farRight  = square.TopRight.X + outset.Right.Value;
            float farTop    = square.TopLeft.Y + outset.Top.Value;
            float farBottom = square.BottomLeft.Y - outset.Bottom.Value;

            var quad = new AGSSquare(new PointF(farLeft + width.Left.Value, farBottom + width.Bottom.Value),
                                     new PointF(farRight - width.Right.Value, farBottom + width.Bottom.Value),
                                     new PointF(farLeft + width.Left.Value, farTop - width.Top.Value),
                                     new PointF(farRight - width.Right.Value, farTop - width.Top.Value));

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

            if (DrawBorderBehind)
            {
                drawBorders(square);
            }
        }
Exemplo n.º 5
0
		public void RenderBorderBack(ISquare square)
		{
			runAnimation();

			if (!FillBackground) return;

			var slice = Slice.ToPercentage(_width, _height);
			var width = Width.ToPixels(_width, _height);
			var outset = Outset.ToPixels(_width, _height);

			float farLeft = square.TopLeft.X - outset.Left.Value;
			float farRight = square.TopRight.X + outset.Right.Value;
			float farTop = square.TopLeft.Y + outset.Top.Value;
			float farBottom = square.BottomLeft.Y - outset.Bottom.Value;

			var quad = new AGSSquare (new PointF (farLeft + width.Left.Value, farBottom + width.Bottom.Value),
				           new PointF (farRight - width.Right.Value, farBottom + width.Bottom.Value),
				           new PointF (farLeft + width.Left.Value, farTop - width.Top.Value), 
				           new PointF (farRight - width.Right.Value, farTop - width.Top.Value));

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

			if (DrawBorderBehind) drawBorders(square);
		}
Exemplo n.º 6
0
        private void drawBorders(ISquare square)
        {
            FourCorners <IGLColor> colors = Color.Convert(c => c.ToGLColor());

            float farLeft   = square.TopLeft.X - LineWidth;
            float farRight  = square.TopRight.X + LineWidth;
            float farTop    = square.TopLeft.Y + LineWidth;
            float farBottom = square.BottomLeft.Y - LineWidth;

            AGSSquare border = new AGSSquare(new PointF(farLeft, farBottom), new PointF(farRight, farBottom),
                                             new PointF(farLeft, farTop), new PointF(farRight, farTop));

            float     topQuadBottomY = square.TopLeft.Y;
            float     topQuadLeftX   = HasRoundCorner.TopLeft ? square.TopLeft.X : farLeft;
            float     topQuadRightX  = HasRoundCorner.TopRight ? square.TopRight.X : farRight;
            AGSSquare topQuad        = new AGSSquare(new PointF(topQuadLeftX, topQuadBottomY), new PointF(topQuadRightX, topQuadBottomY),
                                                     new PointF(topQuadLeftX, farTop), new PointF(topQuadRightX, farTop));

            float     bottomQuadTopY   = square.BottomLeft.Y;
            float     bottomQuadLeftX  = HasRoundCorner.BottomLeft ? square.BottomLeft.X : farLeft;
            float     bottomQuadRightX = HasRoundCorner.BottomRight ? square.BottomRight.X : farRight;
            AGSSquare bottomQuad       = new AGSSquare(new PointF(bottomQuadLeftX, farBottom), new PointF(bottomQuadRightX, farBottom),
                                                       new PointF(bottomQuadLeftX, bottomQuadTopY), new PointF(bottomQuadRightX, bottomQuadTopY));

            float horizQuadTop    = square.TopLeft.Y;
            float horizQuadBottom = square.BottomLeft.Y;

            float     leftQuadRightX = square.BottomLeft.X;
            AGSSquare leftQuad       = new AGSSquare(new PointF(farLeft, horizQuadBottom), new PointF(leftQuadRightX, horizQuadBottom),
                                                     new PointF(farLeft, horizQuadTop), new PointF(leftQuadRightX, horizQuadTop));

            float     rightQuadLeftX = square.BottomRight.X;
            AGSSquare rightQuad      = new AGSSquare(new PointF(rightQuadLeftX, horizQuadBottom), new PointF(farRight, horizQuadBottom),
                                                     new PointF(rightQuadLeftX, horizQuadTop), new PointF(farRight, horizQuadTop));

            if (HasRoundCorner.TopLeft)
            {
                drawRoundCorner(square.TopLeft, LineWidth, 270f, border, colors);
            }
            if (HasRoundCorner.TopRight)
            {
                drawRoundCorner(square.TopRight, LineWidth, 0f, border, colors);
            }
            if (HasRoundCorner.BottomLeft)
            {
                drawRoundCorner(square.BottomLeft, LineWidth, 180f, border, colors);
            }
            if (HasRoundCorner.BottomRight)
            {
                drawRoundCorner(square.BottomRight, LineWidth, 90f, border, colors);
            }
            drawQuad(topQuad, border, colors);
            drawQuad(bottomQuad, border, colors);
            drawQuad(leftQuad, border, colors);
            drawQuad(rightQuad, border, colors);
        }
Exemplo n.º 7
0
        public ISquare ToSquare()
        {
            ISquare square = new AGSSquare(new PointF(BottomLeft.X, BottomLeft.Y), new PointF(BottomRight.X, BottomRight.Y),
                                           new PointF(TopLeft.X, TopLeft.Y), new PointF(TopRight.X, TopRight.Y));

            if (square.BottomLeft.X > square.BottomRight.X)
            {
                square = square.FlipHorizontal();
            }
            return(square);
        }
Exemplo n.º 8
0
 private void drawQuadRow(int steps, float x, float width, float y, float height, float textureWidth, float textureHeight,
                          float textureX, float textureY, float stepX, float stepY)
 {
     for (int i = 0; i < steps; i++)
     {
         var quad = new AGSSquare(new PointF(x, y), new PointF(x + width, y), new PointF(x, y + height), new PointF(x + width, y + height));
         drawQuad(quad, new FourCorners <Vector2> (new Vector2(textureX, textureY), new Vector2(textureX + textureWidth, textureY),
                                                   new Vector2(textureX, textureY + textureHeight), new Vector2(textureX + textureWidth, textureY + textureHeight)));
         x += stepX;
         y += stepY;
     }
 }
Exemplo n.º 9
0
		private void drawBorders(ISquare square)
		{
			FourCorners<IGLColor> colors = Color.Convert(c => c.ToGLColor());

			float farLeft = square.TopLeft.X - LineWidth;
			float farRight = square.TopRight.X + LineWidth;
			float farTop = square.TopLeft.Y + LineWidth;
			float farBottom = square.BottomLeft.Y - LineWidth;

			AGSSquare border = new AGSSquare (new PointF (farLeft, farBottom), new PointF (farRight, farBottom),
				new PointF (farLeft, farTop), new PointF (farRight, farTop));

			float topQuadBottomY = square.TopLeft.Y;
			float topQuadLeftX = HasRoundCorner.TopLeft ? square.TopLeft.X : farLeft;
			float topQuadRightX = HasRoundCorner.TopRight ? square.TopRight.X : farRight;
			AGSSquare topQuad = new AGSSquare (new PointF (topQuadLeftX, topQuadBottomY), new PointF (topQuadRightX, topQuadBottomY),
				new PointF (topQuadLeftX, farTop), new PointF (topQuadRightX, farTop));

			float bottomQuadTopY = square.BottomLeft.Y;
			float bottomQuadLeftX = HasRoundCorner.BottomLeft ? square.BottomLeft.X : farLeft;
			float bottomQuadRightX = HasRoundCorner.BottomRight ? square.BottomRight.X : farRight;
			AGSSquare bottomQuad = new AGSSquare (new PointF (bottomQuadLeftX, farBottom), new PointF (bottomQuadRightX, farBottom),
				new PointF (bottomQuadLeftX, bottomQuadTopY), new PointF (bottomQuadRightX, bottomQuadTopY));

			float horizQuadTop = square.TopLeft.Y;
			float horizQuadBottom = square.BottomLeft.Y;

			float leftQuadRightX = square.BottomLeft.X;
			AGSSquare leftQuad = new AGSSquare (new PointF (farLeft, horizQuadBottom), new PointF (leftQuadRightX, horizQuadBottom),
				new PointF (farLeft, horizQuadTop), new PointF (leftQuadRightX, horizQuadTop));

			float rightQuadLeftX = square.BottomRight.X;
			AGSSquare rightQuad = new AGSSquare (new PointF (rightQuadLeftX, horizQuadBottom), new PointF (farRight, horizQuadBottom),
				new PointF (rightQuadLeftX, horizQuadTop), new PointF (farRight, horizQuadTop));

			if (HasRoundCorner.TopLeft) drawRoundCorner(square.TopLeft, LineWidth, 270f, border, colors);
			if (HasRoundCorner.TopRight) drawRoundCorner(square.TopRight, LineWidth, 0f, border, colors);
			if (HasRoundCorner.BottomLeft) drawRoundCorner(square.BottomLeft, LineWidth, 180f, border, colors);
			if (HasRoundCorner.BottomRight) drawRoundCorner(square.BottomRight, LineWidth, 90f, border, colors);
			drawQuad(topQuad, border, colors);
			drawQuad(bottomQuad, border, colors);
			drawQuad(leftQuad, border, colors);
			drawQuad(rightQuad, border, colors);
		}
Exemplo n.º 10
0
        public void Render(IObject obj, IViewport viewport)
        {
            if (obj.Animation == null)
            {
                return;
            }
            ISprite sprite = obj.Animation.Sprite;

            if (sprite == null || sprite.Image == null)
            {
                return;
            }

            var  layerViewport     = _layerViewports.GetViewport(obj.RenderLayer.Z);
            var  gameResolution    = AGSGame.Game.Settings.VirtualResolution;
            var  resolution        = obj.RenderLayer.IndependentResolution ?? gameResolution;
            bool resolutionMatches = resolution.Equals(gameResolution);

            var viewportMatrix = obj.IgnoreViewport ? Matrix4.Identity : layerViewport.GetMatrix(viewport, obj.RenderLayer.ParallaxSpeed);

            var modelMatrices = obj.GetModelMatrices();

            _matrices.ModelMatrix    = modelMatrices.InVirtualResolutionMatrix;
            _matrices.ViewportMatrix = viewportMatrix;

            _boundingBoxBuilder.Build(BoundingBoxes, sprite.Image.Width,
                                      sprite.Image.Height, _matrices, resolutionMatches, true);
            IGLBoundingBox hitTestBox = BoundingBoxes.HitTestBox;

            if (!resolutionMatches)
            {
                _matrices.ModelMatrix = modelMatrices.InObjResolutionMatrix;
                _boundingBoxBuilder.Build(BoundingBoxes, sprite.Image.Width,
                                          sprite.Image.Height, _matrices, true, false);
            }
            IGLBoundingBox renderBox = BoundingBoxes.RenderBox;

            ITexture texture = _textures.GetOrAdd(sprite.Image.ID, () => createNewTexture(sprite.Image.ID));

            IGLColor color = _colorBuilder.Build(sprite, obj);

            IBorderStyle border       = obj.Border;
            ISquare      renderSquare = null;

            if (border != null)
            {
                renderSquare = renderBox.ToSquare();
                border.RenderBorderBack(renderSquare);
            }
            _renderer.Render(texture.ID, renderBox, color);

            Vector3 bottomLeft  = hitTestBox.BottomLeft;
            Vector3 topLeft     = hitTestBox.TopLeft;
            Vector3 bottomRight = hitTestBox.BottomRight;
            Vector3 topRight    = hitTestBox.TopRight;

            AGSSquare square = new AGSSquare(new PointF(bottomLeft.X, bottomLeft.Y),
                                             new PointF(bottomRight.X, bottomRight.Y), new PointF(topLeft.X, topLeft.Y),
                                             new PointF(topRight.X, topRight.Y));

            obj.BoundingBox = square;

            if (border != null)
            {
                border.RenderBorderFront(renderSquare);
            }
            if (obj.DebugDrawAnchor)
            {
                IObject parent = obj.TreeNode.Parent;
                float   x      = obj.X;
                float   y      = obj.Y;
                while (parent != null)
                {
                    x     += (parent.X - parent.Width * parent.Anchor.X);
                    y     += (parent.Y - parent.Height * parent.Anchor.Y);
                    parent = parent.TreeNode.Parent;
                }
                _glUtils.DrawCross(x - viewport.X, y - viewport.Y, 10, 10, 1f, 1f, 1f, 1f);
            }
        }
Exemplo n.º 11
0
		public void Render(IObject obj, IViewport viewport, PointF areaScaling)
		{
			if (obj.Animation == null)
			{
				return;
			}
			ISprite sprite = obj.Animation.Sprite;
			if (sprite == null || sprite.Image == null)
			{
				return;
			}

			var layerViewport = _layerViewports.GetViewport(obj.RenderLayer.Z);
            var gameResolution = AGSGame.Game.Settings.VirtualResolution;
            var resolution = obj.RenderLayer.IndependentResolution ?? gameResolution;
            bool resolutionMatches = resolution.Equals(gameResolution);

            var viewportMatrix = obj.IgnoreViewport ? Matrix4.Identity : layerViewport.GetMatrix(viewport, obj.RenderLayer.ParallaxSpeed);
            PointF resolutionFactor = new PointF(resolution.Width / gameResolution.Width, resolution.Height / gameResolution.Height);
            IGLMatrices matricesRender = _renderMatrixBuilder.Build(obj, obj.Animation.Sprite, obj.TreeNode.Parent,
                viewportMatrix, areaScaling, resolutionFactor);

            IGLMatrices matricesHitTest = resolutionMatches ? matricesRender : _hitTestMatrixBuilder.Build(obj, obj.Animation.Sprite, obj.TreeNode.Parent,
                viewportMatrix, areaScaling, GLMatrixBuilder.NoScaling);

            _boundingBoxBuilder.Build(BoundingBoxes, sprite.Image.Width,
				sprite.Image.Height, matricesHitTest, resolutionMatches, true);
			IGLBoundingBox hitTestBox = BoundingBoxes.HitTestBox;
            
            if (!resolutionMatches)
            {
                _boundingBoxBuilder.Build(BoundingBoxes, sprite.Image.Width,
                    sprite.Image.Height, matricesRender, true, false);
            }
            IGLBoundingBox renderBox = BoundingBoxes.RenderBox;

            ITexture texture = _textures.GetOrAdd (sprite.Image.ID, () => createNewTexture (sprite.Image.ID));

			IGLColor color = _colorBuilder.Build(sprite, obj);

            IBorderStyle border = obj.Border;
			ISquare renderSquare = null;
			if (border != null)
			{
				renderSquare = renderBox.ToSquare();
				border.RenderBorderBack(renderSquare);
			}
            _renderer.Render(texture.ID, renderBox, color);

            Vector3 bottomLeft = hitTestBox.BottomLeft;
            Vector3 topLeft = hitTestBox.TopLeft;
            Vector3 bottomRight = hitTestBox.BottomRight;
            Vector3 topRight = hitTestBox.TopRight;

            AGSSquare square = new AGSSquare (new PointF (bottomLeft.X, bottomLeft.Y),
				new PointF (bottomRight.X, bottomRight.Y), new PointF (topLeft.X, topLeft.Y),
				new PointF (topRight.X, topRight.Y));
			obj.BoundingBox = square;

			if (border != null)
			{
				border.RenderBorderFront(renderSquare);
			}
			if (obj.DebugDrawAnchor)
			{
				IObject parent = obj;
				float x = 0f;
				float y = 0f;
				while (parent != null)
				{
					x += parent.X;
					y += parent.Y;
					parent = parent.TreeNode.Parent;
				}
                _glUtils.DrawCross(x - viewport.X, y - viewport.Y, 10, 10, 1f, 1f, 1f, 1f);
			}
		}
Exemplo n.º 12
0
		private void drawQuadRow(int steps, float x, float width, float y, float height, float textureWidth, float textureHeight,
			float textureX, float textureY, float stepX, float stepY)
		{
			for (int i = 0; i < steps; i++)
			{
				var quad = new AGSSquare (new PointF (x, y), new PointF (x + width, y), new PointF (x, y + height), new PointF (x + width, y + height));
				drawQuad(quad, new FourCorners<Vector2> (new Vector2 (textureX, textureY), new Vector2 (textureX + textureWidth, textureY),
					new Vector2 (textureX, textureY + textureHeight), new Vector2 (textureX + textureWidth, textureY + textureHeight)));
				x += stepX;
				y += stepY;
			}
		}
Exemplo n.º 13
0
		private void drawStretch(SliceValues border, SliceValues slice, SliceValues width)
		{
			var topQuad = new AGSSquare (new PointF (border.Left.Value + width.Left.Value, border.Top.Value - width.Top.Value),
				              new PointF (border.Right.Value - width.Right.Value, border.Top.Value - width.Top.Value), 
				              new PointF (border.Left.Value + width.Left.Value, border.Top.Value),
				              new PointF (border.Right.Value - width.Right.Value, border.Top.Value));


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

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

			var rightQuad = new AGSSquare (new PointF (border.Right.Value - width.Right.Value, border.Bottom.Value + width.Bottom.Value),
				                new PointF (border.Right.Value, border.Bottom.Value + width.Bottom.Value), 
				                new PointF (border.Right.Value - width.Right.Value, border.Top.Value - width.Top.Value),
				                new PointF (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)));
		}