Exemple #1
0
        private ShapeRectangle ConvertShape(ButtonBorder border)
        {
            ShapeRectangle shape = null;

            switch (border)
            {
            case ButtonBorder.Rectangle:
                shape = new ShapeRectangle(0, 0, _width - 1, _height - 1);
                break;

            case ButtonBorder.RoundRectangle:
                shape = new ShapeRoundRectangle(0, 0, _width - 1, _height - 1, _cornerRadius);
                break;

            case ButtonBorder.Ellipse:
                shape = new ShapeEllipse(0, 0, _width - 1, _height - 1);
                break;
            }
            if (shape != null)
            {
                shape.Brush = _fillBrushNormal;
                shape.Pen   = _borderPenNormal;
            }
            return(shape);
        }
        private bool CircleRectangleCollision(ShapeCircle circle, ShapeRectangle rectangle)
        {
            var circleDistanceX = Math.Abs(circle.Position.X - rectangle.Position.X);
            var circleDistanceY = Math.Abs(circle.Position.Y - rectangle.Position.Y);

            if (circleDistanceX > (rectangle.Width / 2 + circle.Radius))
            {
                return(false);
            }
            if (circleDistanceY > (rectangle.Height / 2 + circle.Radius))
            {
                return(false);
            }

            if (circleDistanceX <= (rectangle.Width / 2))
            {
                return(true);
            }
            if (circleDistanceY <= (rectangle.Height / 2))
            {
                return(true);
            }

            var cornerDistanceSQ = Math.Pow((circleDistanceX - rectangle.Width / 2), 2) +
                                   Math.Pow((circleDistanceY - rectangle.Height / 2), 2);

            return(cornerDistanceSQ <= Math.Pow(circle.Radius, 2));
        }
Exemple #3
0
        public void Circle_Rectangle_Collision_Success()
        {
            var collisionManager = new ShapeCollisionManager();
            var circle           = new ShapeCircle(10, new Point(0, 0));
            var rectangle        = new ShapeRectangle(10, 10, new Point(14, 0));

            Assert.IsTrue(collisionManager.CheckCollision(circle, rectangle));
        }
        public override void OnMouseDown(Canvas drawArea, MouseEventArgs e)
        {
            UndoService.BeginTransaction("Add a Rectangle");

            Point          p = drawArea.BackTrackMouse(new Point(e.X, e.Y));
            ShapeRectangle shapeRectangle = new ShapeRectangle(
                drawArea.Document.Zoom
                , p.X
                , p.Y
                , 1
                , 1
                , drawArea.Document.CurrentShapePaintInfo
                , drawArea.MessageControl.Sign.Type);

            AddNewObject(drawArea, shapeRectangle);
        }
Exemple #5
0
        public CustomButtonStyle(int width, int height, ButtonBorder border)
        {
            _width             = width;
            _height            = height;
            _fillBrushNormal   = new LinearGradientBrush(new Rectangle(0, 0, _width, _height), SystemColors.ControlLightLight, SystemColors.Control, LinearGradientMode.Vertical);
            _borderPenNormal   = new Pen(SystemColors.ControlDark, 1.2f);
            _fillBrushHot      = new LinearGradientBrush(new Rectangle(0, 0, _width, _height), SystemColors.ControlLightLight, SystemColors.Control, LinearGradientMode.Vertical);
            _borderPenHot      = new Pen(Color.FromArgb(150, SystemColors.Highlight), 2f);
            _fillBrushPressed  = new LinearGradientBrush(new Rectangle(0, 0, _width, _height), SystemColors.Control, SystemColors.ControlLightLight, LinearGradientMode.Vertical);
            _borderPenPressed  = new Pen(SystemColors.Highlight, 1.2f);
            _fillBrushDisabled = new LinearGradientBrush(new Rectangle(0, 0, _width, _height), SystemColors.Control, SystemColors.Control, LinearGradientMode.Vertical);
            _borderPenDisabled = SystemPens.ControlDark;
            _border            = border;
            _cornerRadius      = 3;

            _shape = ConvertShape(_border);
        }
        private static void CreateHoverUI()
        {
            HoverUI interfaccia = new HoverUI();

            var rect = new ShapeRectangle(0, 0, Color.OrangeRed, 50, 50);

            var color = new ShapeString(100, 100, Color.White, "Color: ");

            interfaccia.Render += (s, e) =>
            {
                color.Text = $"Color: {interfaccia.GetColorAtPixel(new Point(0, 0))}";

                int speed = 5;

                if (interfaccia.GetBackgroundKeyDown(Keys.Right))
                {
                    rect.X += speed;
                }
                if (interfaccia.GetBackgroundKeyDown(Keys.Left))
                {
                    rect.X -= speed;
                }

                if (interfaccia.GetBackgroundKeyDown(Keys.Up))
                {
                    rect.Y -= speed;
                }
                if (interfaccia.GetBackgroundKeyDown(Keys.Down))
                {
                    rect.Y += speed;
                }
            };

            interfaccia.AddShape(color);
            interfaccia.AddShape(rect);

            interfaccia.Run();
        }
Exemple #7
0
    private bool CreateRectCollider(ShapeRectangle shape, IDoorsHolder holder, GameObject gameObject)
    {
        var wallRects     = new List <Rect>();
        var wallWidth     = RoomConsts.WallsWidth;
        var doorsSortList = new List <DoorPositionPair>(10);

        for (int i = 0; i < shape.LinesCount; i++)
        {
            var line     = shape[i];
            var lineLine = line.Line + line.Normale * wallWidth / 2f;
            lineLine.Expand(lineLine.Length + wallWidth * 2f);

            var offsetLine = new OrientedLine(lineLine, line.NormaleRotation);

            if (holder != null)
            {
                foreach (var door in holder.GetDoors((door, doorPosition) => { return(doorPosition.LineId == i); }))
                {
                    doorsSortList.Add(new DoorPositionPair()
                    {
                        Door = door, Position = holder.GetDoorPosition(door)
                    });
                }
            }

            if (doorsSortList.Count == 0)
            {
                wallRects.Add(offsetLine.ToRect(wallWidth));
            }
            else
            {
                doorsSortList.Sort(delegate(DoorPositionPair x, DoorPositionPair y)
                                   { return(x.Position.PartOfTheLine < y.Position.PartOfTheLine ? -1 : 1); });

                var lineNew        = offsetLine.Line;
                var positionOffset = wallWidth;

                foreach (var doorSorted in doorsSortList)
                {
                    var doorWidth   = doorSorted.Door.Width;
                    var newPosition = doorSorted.Position.PartOfTheLine +
                                      positionOffset;
                    Line line1;
                    Line line2;

                    lineNew.CutLine(newPosition - doorWidth / 2f, out line1, out line2);

                    wallRects.Add(new OrientedLine(line1, line.NormaleRotation).ToRect(wallWidth));

                    lineNew.CutLine(newPosition + doorWidth / 2f, out line1, out line2);
                    lineNew = line2;
                }

                wallRects.Add(new OrientedLine(lineNew, line.NormaleRotation).ToRect(wallWidth));
                doorsSortList.Clear();
            }
        }

        foreach (var rect in wallRects)
        {
            var collider = gameObject.AddComponent <BoxCollider2D>();
            collider.usedByComposite = true;
            collider.offset          = rect.center;
            collider.size            = rect.size;
        }

        gameObject.AddComponent <CompositeCollider2D>();
        return(true);
    }
Exemple #8
0
 public override void VisitRectangle(ShapeRectangle rectangle)
 {
     VisitShape(rectangle);
 }
Exemple #9
0
 public virtual void VisitRectangle(ShapeRectangle rectangle)
 {
 }