Beispiel #1
0
        public override void HandleInput(InputControl input, bool inFocus)
        {
            if (inFocus)
            {
                downPrevious = down;
                down = false;

                Texture2D texture = Source;
                if (texture != null)
                {
                    int offset = (int)GetAlignment(texture).X;
                    if (input.MouseX() > Position.X-offset && input.MouseX() < (Position.X-offset + texture.Width) && input.MouseY() > Position.Y && input.MouseY() < (Position.Y + texture.Height))
                    {
                        down = input.MouseHold(1);

                        if (downPrevious == true && down == false)
                        {
                            if (Selected != null)
                            {
                                Selected(this, new EventArgs());
                            }
                        }

                        // Check to see button is just being clicked and play a sound
                        if (down == true && downPrevious == false)
                        {
                            if (clickSound != null)
                            {
                                clickSound.Play();
                            }
                        }
                    }
                }
                else
                {
                    int mw = (int)font.MeasureString(text).X;
                    int mh = (int)font.MeasureString(text).Y;
                    int mx = (int)Position.X;
                    switch (align)
                    {
                        case Alignment.Center: { mx -= mw / 2; } break;
                        case Alignment.Right: { mx -= mw; } break;
                    }
                    int my = (int)Position.Y;

                    if (input.MouseX() > mx && input.MouseX() < mx + mw && input.MouseY() > my && input.MouseY() < my + mh)
                    {
                        down = input.MouseHold(1);

                        if (downPrevious == true && down == false)
                        {
                            if (Selected != null)
                            {
                                Selected(this, new EventArgs());
                            }
                        }

                        // Check to see button is just being clicked and play a sound
                        if (down == true && downPrevious == false) if (clickSound != null) clickSound.Play();
                    }
                }
            }
        }
Beispiel #2
0
        public override void HandleInput(InputControl input, bool inFocus)
        {
            if (inFocus)
            {
                if (input.MousePressed(1))
                {
                    if (input.MouseX() > Position.X && input.MouseX() < (Position.X + width) && input.MouseY() > Position.Y && input.MouseY() < (Position.Y + height))
                    {
                        isSelected = true;

                    }
                    else
                    {
                        isSelected = false;
                    }
                }
                if (isSelected)
                {
                    foreach (Keys key in keysToCheck)
                    {
                        if (input.KeyPressed(key) && (OnKeyPressed == null || !OnKeyPressed(this, key)))
                        {
                            switch (key)
                            {
                                case (Keys.Back):
                                    if (textValue.Length > 0 && index > 0)
                                    {
                                        textValue = textValue.Remove(index - 1, 1);
                                        index--;
                                    }
                                    break;
                                case (Keys.Enter):
                                    if(Submitted != null)
                                        Submitted(this);
                                    index = 0;
                                    break;
                                case (Keys.Space):
                                    textValue += " ";
                                    break;
                                case (Keys.Left):
                                    if (index > 0)
                                        index--;
                                    break;
                                case (Keys.Right):
                                    if (index < textValue.Count())
                                        index++;
                                    break;
                                default:
                                    string charToAdd = key.ToString();
                                    if (!input.KeyDown(Keys.RightShift) && !input.KeyDown(Keys.LeftShift))
                                    {
                                        charToAdd = charToAdd.ToLower();

                                    }
                                    if (textValue.Length < this.max)
                                    {
                                        textValue += charToAdd;
                                        index++;
                                    }
                                    break;
                            }
                        }
                    }

                }
            }
        }
Beispiel #3
0
 public override void HandleInput(InputControl input, bool inFocus)
 {
     if (!Locked && inFocus)
     {
         Texture2D texture = Source;
         if (!isItemInUse)
         {
             if (input.MouseX() > Position.X && input.MouseX() < (Position.X + texture.Width) && input.MouseY() > Position.Y && input.MouseY() < (Position.Y + texture.Height))
             {
                 if (input.MouseReleased(1))
                 {
                     isItemInUse = true;
                 }
             }
         }
         else
         {
             if (input.MouseX() > Position.X && input.MouseX() < (Position.X + texture.Width) && input.MouseY() > Position.Y && input.MouseY() < (Position.Y + texture.Height))
             {
                 if (input.MouseReleased(1))
                 {
                     isItemInUse = false;
                 }
             }
             for (int i = 0; i < values.Count(); i++)
             {
                 if (input.MouseX() > Position.X && input.MouseX() < (Position.X + texture.Width) && input.MouseY() > Position.Y + (texture.Height * (i + 1))
                     && input.MouseY() < (Position.Y + texture.Height + (texture.Height * (i + 1))))
                 {
                     if (input.MouseReleased(1))
                     {
                         isItemInUse = false;
                         current = i;
                     }
                 }
             }
         }
     }
 }