示例#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();
                    }
                }
            }
        }