Beispiel #1
0
        public override void Update(float elapsed)
        {
            base.Update(elapsed);
            MouseState current = Mouse.GetState();
            Vector2    mouse   = new Vector2(current.X, current.Y);

            if ((current.X != previous.X || current.Y != previous.Y) && dragging != null)
            {
                dragging.Position = mouse + dragOffset;
            }

            if (current.LeftButton == ButtonState.Pressed && previous.LeftButton != ButtonState.Pressed)
            {
                dragging = menu.GetControlAt(mouse);
                if (dragging != null)
                {
                    dragOffset = dragging.Position - mouse;
                }
            }
            if (current.LeftButton != ButtonState.Pressed && previous.LeftButton == ButtonState.Pressed)
            {
                if (dragging != null)
                {
                    dragging.HandleMessage(Messages.SetPosition, dragging.Position);
                    dragging = null;
                }
            }
            previous = current;
        }