private void drawCorners(SliceValues border, SliceValues slice, SliceValues width)
        {
            var topLeftQuad = new AGSBoundingBox(new Vector2(border.Left.Value, border.Top.Value - width.Top.Value),
                                                 new Vector2(border.Left.Value + width.Top.Value, border.Top.Value - width.Top.Value),
                                                 new Vector2(border.Left.Value, border.Top.Value), new Vector2(border.Left.Value + width.Top.Value, border.Top.Value));

            var topRightQuad = new AGSBoundingBox(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),
                                                  new Vector2(border.Right.Value - width.Right.Value, border.Top.Value), new Vector2(border.Right.Value, border.Top.Value));

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

            var bottomRightQuad = new AGSBoundingBox(new Vector2(border.Right.Value - width.Right.Value, border.Bottom.Value),
                                                     new Vector2(border.Right.Value, border.Bottom.Value), 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));

            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)));
        }
        private void drawBorders(AGSBoundingBox square)
        {
            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;
            SliceValues border    = new SliceValues(SliceMeasurement.Pixels, farLeft, farRight, farTop, farBottom);

            drawCorners(border, slice, width);
            switch (Repeat)
            {
            case BorderRepeat.Repeat:
            case BorderRepeat.Round:
            case BorderRepeat.Space:
                drawEdges(border, slice, width, Repeat);
                break;

            case BorderRepeat.Stretch:
                drawStretch(border, slice, width);
                break;

            default:
                throw new NotSupportedException(Repeat.ToString());
            }
        }
 public AGSSlicedImageBorder(SliceValues slice, SliceValues width, SliceValues outset, BorderRepeat repeat, [MethodParam(Browsable = false, DefaultProvider = nameof(GetDefaultGLUtils))] IGLUtils glUtils)
     : this(glUtils)
 {
     Slice  = slice;
     Width  = width;
     Outset = outset;
     Repeat = repeat;
 }
Beispiel #4
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)));
        }
        private void drawEdges(SliceValues border, SliceValues slice, SliceValues width,
                               BorderRepeat repeat)
        {
            float leftX             = border.Left.Value + width.Left.Value;
            float rightX            = border.Right.Value - width.Right.Value;
            float rowWidth          = rightX - leftX;
            float textureWorldWidth = ((1f - slice.Left.Value - slice.Right.Value) * _width);
            int   stepsX            = (int)(rowWidth / textureWorldWidth);
            float remainderX        = rowWidth - textureWorldWidth * stepsX;

            float textureWidth = 1f - slice.Left.Value - slice.Right.Value;

            if (textureWidth < 0f)
            {
                textureWidth = 1f;
            }
            float topY       = border.Top.Value - width.Top.Value;
            float farBottomY = border.Bottom.Value;
            float stepX      = textureWorldWidth;
            float widthX     = textureWorldWidth;
            float startX     = leftX;

            if (remainderX > 0.001f)
            {
                switch (repeat)
                {
                case BorderRepeat.Round:
                    stepX  = rowWidth / stepsX;
                    widthX = stepX;
                    break;

                case BorderRepeat.Space:
                    stepX  = rowWidth / stepsX;
                    startX = startX + (stepX - widthX) / 2f;
                    break;
                }
            }
            drawHorizQuadRows(stepsX, startX, widthX, topY, farBottomY,
                              width.Top.Value, width.Bottom.Value, textureWidth,
                              slice.Top.Value, slice.Bottom.Value, slice.Left.Value, 1f - slice.Top.Value, 0f,
                              stepX);

            float bottomY            = border.Bottom.Value + width.Bottom.Value;
            float rowHeight          = topY - bottomY;
            float textureWorldHeight = ((1f - slice.Top.Value - slice.Bottom.Value) * _height);
            int   stepsY             = (int)(rowHeight / textureWorldHeight);
            float textureHeight      = 1f - slice.Top.Value - slice.Bottom.Value;

            if (textureHeight < 0f)
            {
                textureHeight = 1f;
            }
            float remainderY = rowHeight - textureWorldHeight * stepsY;
            float stepY      = textureWorldHeight;
            float heightY    = textureWorldHeight;
            float startY     = bottomY;

            if (remainderY > 0.001f)
            {
                switch (repeat)
                {
                case BorderRepeat.Round:
                    stepY   = rowHeight / stepsY;
                    heightY = stepY;
                    break;

                case BorderRepeat.Space:
                    stepY  = rowHeight / stepsY;
                    startY = startY + (stepY - heightY) / 2f;
                    break;
                }
            }
            drawVertQuadRows(stepsY, border.Left.Value, rightX, width.Left.Value, width.Right.Value,
                             startY, heightY, slice.Left.Value, slice.Right.Value, textureHeight, 0f, 1f - slice.Right.Value,
                             slice.Bottom.Value, stepY);

            if (repeat == BorderRepeat.Repeat)
            {
                if (remainderX > 0.0001f)
                {
                    textureWidth = (remainderX / textureWorldWidth) * textureWidth;
                    leftX        = leftX + textureWorldWidth * stepsX;
                    drawHorizQuadRows(1, leftX, remainderX, topY, farBottomY, width.Top.Value, width.Bottom.Value, textureWidth,
                                      slice.Top.Value, slice.Bottom.Value, slice.Left.Value, 1f - slice.Top.Value, 0f, remainderX);
                }

                if (remainderY > 0.001f)
                {
                    textureHeight = (remainderY / textureWorldHeight) * textureHeight;
                    bottomY       = bottomY + textureWorldHeight * stepsY;
                    drawVertQuadRows(1, border.Left.Value, rightX, width.Left.Value, width.Right.Value, bottomY, remainderY,
                                     slice.Left.Value, slice.Right.Value, textureHeight, 0f, 1f - slice.Right.Value, slice.Bottom.Value, remainderY);
                }
            }
        }
		private void drawBorders(ISquare square)
		{
			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;
			SliceValues border = new SliceValues (SliceMeasurement.Pixels, farLeft, farRight, farTop, farBottom);
			drawCorners(border, slice, width);
			switch (Repeat)
			{
				case BorderRepeat.Repeat:
				case BorderRepeat.Round:
				case BorderRepeat.Space:
					drawEdges(border, slice, width, Repeat);
					break;
				case BorderRepeat.Stretch:
					drawStretch(border, slice, width);
					break;
				default:
					throw new NotSupportedException (Repeat.ToString());
			}
		}
		private void drawEdges(SliceValues border, SliceValues slice, SliceValues width, 
			BorderRepeat repeat)
		{
			float leftX = border.Left.Value + width.Left.Value;
			float rightX = border.Right.Value - width.Right.Value;
			float rowWidth = rightX - leftX;
			float textureWorldWidth = ((1f - slice.Left.Value - slice.Right.Value) * _width);
			int stepsX = (int)(rowWidth / textureWorldWidth);
			float remainderX = rowWidth - textureWorldWidth * ((float)stepsX);

			float textureWidth = 1f - slice.Left.Value - slice.Right.Value;
			if (textureWidth < 0f) textureWidth = 1f;
			float topY = border.Top.Value - width.Top.Value;
			float farBottomY = border.Bottom.Value;
			float stepX = textureWorldWidth;
			float widthX = textureWorldWidth;
			float startX = leftX;
			if (remainderX > 0.001f)
			{
				switch (repeat)
				{
					case BorderRepeat.Round:
						stepX = rowWidth / stepsX;
						widthX = stepX;
						break;
					case BorderRepeat.Space:
						stepX = rowWidth / stepsX;
						startX = startX + (stepX - widthX) / 2f;
						break;
				}
			}
			drawHorizQuadRows(stepsX, startX, widthX, topY, farBottomY,
				width.Top.Value, width.Bottom.Value, textureWidth, 
				slice.Top.Value, slice.Bottom.Value, slice.Left.Value, 1f - slice.Top.Value, 0f,
				stepX);

			float bottomY = border.Bottom.Value + width.Bottom.Value;
			float rowHeight = topY - bottomY;
			float textureWorldHeight = ((1f - slice.Top.Value - slice.Bottom.Value) * _height);
			int stepsY = (int)(rowHeight / textureWorldHeight);
			float textureHeight = 1f - slice.Top.Value - slice.Bottom.Value;
			if (textureHeight < 0f) textureHeight = 1f;
			float remainderY = rowHeight - textureWorldHeight * ((float)stepsY);
			float stepY = textureWorldHeight;
			float heightY = textureWorldHeight;
			float startY = bottomY;
			if (remainderY > 0.001f)
			{
				switch (repeat)
				{
					case BorderRepeat.Round:
						stepY = rowHeight / stepsY;
						heightY = stepY;
						break;
					case BorderRepeat.Space:
						stepY = rowHeight / stepsY;
						startY = startY + (stepY - heightY) / 2f;
						break;
				}
			}
			drawVertQuadRows(stepsY, border.Left.Value, rightX, width.Left.Value, width.Right.Value,
				startY, heightY, slice.Left.Value, slice.Right.Value, textureHeight, 0f, 1f - slice.Right.Value,
				slice.Bottom.Value, stepY);

			if (repeat == BorderRepeat.Repeat)
			{
				if (remainderX > 0.0001f)
				{
					textureWidth = (remainderX / textureWorldWidth) * textureWidth;
					leftX = leftX + textureWorldWidth * stepsX;
							drawHorizQuadRows(1, leftX, remainderX, topY, farBottomY, width.Top.Value, width.Bottom.Value, textureWidth,
						slice.Top.Value, slice.Bottom.Value, slice.Left.Value, 1f - slice.Top.Value, 0f, remainderX);
				}

				if (remainderY > 0.001f)
				{
					textureHeight = (remainderY / textureWorldHeight) * textureHeight;
					bottomY = bottomY + textureWorldHeight * stepsY;
					drawVertQuadRows(1, border.Left.Value, rightX, width.Left.Value, width.Right.Value, bottomY, remainderY,
						slice.Left.Value, slice.Right.Value, textureHeight, 0f, 1f - slice.Right.Value, slice.Bottom.Value, remainderY);
				}
			}
		}
		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)));
		}