Пример #1
0
        public override void Update(float time)
        {
            base.Update(time);

            if (!(GO.Pos.X + GO.Size.X < 16 - properties.Size.X || GO.Pos.Y + GO.Size.Y < properties.Pos.Y))
            {
                properties.Pos = new Vector2(0, 9) - new Vector2(0, properties.Size.Y);
            }
            else
            {
                properties.Pos = new Vector2(16, 9) - properties.Size;
            }

            Vector2 mousePos = Input.GetMouseWorldPosition();

            if (Input.GetMouseButton(PressAction.PRESSED, MouseButton.LEFT))
            {
                if (GO.GetAABB().Inside(mousePos))
                {
                    selected = GO;
                    if (!staticGrabbed)
                    {
                        staticGrabbed = true;
                        grabbed       = true;
                        grabPoint     = mousePos - GO.Pos;
                    }
                }

                else
                {
                    if (selected == GO)
                    {
                        selected = null;
                    }
                }
            }
            else if (Input.GetMouseButton(PressAction.RELEASED, MouseButton.LEFT))
            {
                grabbed   = staticGrabbed = false;
                grabPoint = Vector2.Zero;
            }

            if (selected == GO)
            {
                (GO.Renderer as CRender).colour = new Color(180, 180, 180);
                if (Input.GetKey(PressAction.PRESSED, Keys.Delete))
                {
                    Destroy();
                }
                properties.active = true;
            }
            else
            {
                (GO.Renderer as CRender).colour = Color.White;
                if (properties.Hover == -1 && properties.selected == -1)
                {
                    properties.active = false;
                }
            }

            if (Input.GetKey(PressAction.DOWN, Keys.LeftShift))
            {
                axisAligned = true;
            }
            else
            {
                axisAligned = false;
            }

            if (grabbed)
            {
                if (!axisAligned)
                {
                    GO.Pos = mousePos - grabPoint;
                }
                else
                {
                    GO.Pos = new Vector2((int)(mousePos.X * precision) - (int)(grabPoint.X * precision), (int)(mousePos.Y * precision) - (int)(grabPoint.Y * precision)) / precision;
                }
            }

            HandleProperties();
        }