示例#1
0
 /// <summary>
 /// Handles the input.
 /// </summary>
 /// <param name="input">The current input state.</param>
 public override void HandleInput(Input.Input input)
 {
     if (active)
     {
         HandleKeyInput(input);
         if (rect.Contains(input.MouseX(), input.MouseY()))
         {
             InputState mouseState = input.GetMouseState(MouseButtons.Left);
             if (mouseState == InputState.Pressed || mouseState == InputState.Held)
             {
                 if (state != UIState.Clicked && state != UIState.Held)
                 {
                     state = UIState.Clicked;
                     OnClick();
                 }
                 else
                 {
                     state = UIState.Held;
                 }
             }
             else
             {
                 state = UIState.MouseOver;
                 if (mouseState == InputState.Released)
                 {
                     OnRelease();
                 }
             }
             HandleInputChildren(input);
         }
         else
         {
             state = UIState.Default;
         }
     }
 }
示例#2
0
 public override void HandleInput(Input.Input input)
 {
     if (active)
     {
         if (state != UIState.Disabled)
         {
             InputState leftState = input.GetMouseState(MouseButtons.Left);
             if (tabRect.Contains(input.MouseX(), input.MouseY()))
             {
                 if (!tabClick && leftState == InputState.Pressed)
                 {
                     tabClick = true;
                     yOff = input.MouseY() - tabRect.Y;
                     xOff = input.MouseX() - tabRect.X;
                 }
             }
             if (tabClick && (leftState == InputState.Held || leftState == InputState.Pressed))
             {
                 tabRect.X = input.MouseX() - xOff;
                 if (tabRect.X < position.X)
                 {
                     tabRect.X = (int)position.X;
                 }
                 else if (tabRect.X > position.X + width - tabRect.Width)
                 {
                     tabRect.X = (int)(position.X + width - tabRect.Width);
                 }
                 scale = (tabRect.X - rect.X) / (rect.Width * 0.9f);
                 OnMove();
             }
             else if (tabClick && (leftState == InputState.Released))
             {
                 tabClick = false;
                 OnRelease();
             }
         }
     }
 }
示例#3
0
 public override void HandleInput(Input.Input input)
 {
     if (active)
     {
         InputState leftState = input.GetMouseState(MouseButtons.Left);
         if (scrollRect.Contains(input.MouseX(), input.MouseY()))
         {
             if (!scrollClick && leftState == InputState.Pressed)
             {
                 scrollClick = true;
                 yOff = input.MouseY() - scrollRect.Y;
                 xOff = input.MouseX() - scrollRect.X;
             }
         }
         if (scrollClick && (leftState == InputState.Held || leftState == InputState.Pressed))
         {
             scrollRect.Y = input.MouseY() - yOff;
             if (scrollRect.Y < position.Y)
             {
                 scrollRect.Y = (int)position.Y;
             }
             else if (scrollRect.Y > position.Y + height - scrollRect.Height)
             {
                 scrollRect.Y = (int)(position.Y + height - scrollRect.Height);
             }
             scrollDist = (int)((position.Y - scrollRect.Y) / scale);
             foreach (UIElement e in children)
             {
                 e.UpdatePosition(new Vector2(0, scrollDist));
             }
         }
         if (rect.Contains(input.MouseX(), input.MouseY()))
         {
             if (!(scrollClick && (leftState == InputState.Held || leftState == InputState.Pressed)))
             {
                 scrollClick = false;
                 int scrollNum = input.ScrollVal();
                 if (scrollNum != 0)
                 {
                     if (scrollNum > 0)
                     {
                         scrollDist -= 8;
                         if (scrollDist < -extraHeight)
                         {
                             scrollDist = -extraHeight;
                         }
                     }
                     if (scrollNum < 0)
                     {
                         scrollDist += 8;
                         if (scrollDist > 0)
                         {
                             scrollDist = 0;
                         }
                     }
                     scrollRect.Y = (int)(position.Y - (scrollDist * scale));
                     UpdateChildPosition(new Vector2(0, scrollDist));
                 }
             }
             if (!scrollClick)
             {
                 HandleInputChildren(input);
             }
         }
     }
 }