Beispiel #1
0
        public override void Draw(SpriteBatch sb)
        {
            Vector2 position = this.position;

            if (parent != null)
            {
                position += this.parent.position;
            }
            this.rectangle = new Rectangle((int)position.X, (int)position.Y, (int)this.size.X, (int)this.size.Y);
            Color color = Color.White;

            if (new Rectangle(Main.mouseX, Main.mouseY, 1, 1).Intersects(this.rectangle))
            {
                this.hover = true;
                color      = Color.LightGray;
                if (UIParameters.mouseState.LeftButton == ButtonState.Pressed && UIParameters.mouseRect.Intersects(new Rectangle((int)position.X, (int)position.Y, (int)this.size.X, (int)this.size.Y)))
                {
                    color = new Color(167, 167, 167, 255);
                }
                if (UIParameters.LeftMouseClick(new Rectangle((int)position.X, (int)position.Y, (int)this.size.X, (int)this.size.Y)))
                {
                    this.Function();
                }
            }
            if (this.texture == null)
            {
                BaseTextureDrawing.DrawRectangleBox(sb, color, Color.Black, this.rectangle, 1);
            }
            else
            {
                sb.Draw(this.texture, this.rectangle, color);
            }
            base.Draw(sb);
        }
Beispiel #2
0
 public void DoMovement() //This code simply allows you to drag around the window :)
 {
     if (new Rectangle(UIParameters.lastMouseState.X, UIParameters.lastMouseState.Y, 1, 1).Intersects(this.obj.rectangle) && new Rectangle(UIParameters.mouseState.X, UIParameters.mouseState.Y, 1, 1).Intersects(this.obj.rectangle) && UIParameters.NoChildrenIntersect(this.obj, new Rectangle(UIParameters.mouseState.X, UIParameters.mouseState.Y, 1, 1)))
     {
         if (UIParameters.lastMouseState.LeftButton == ButtonState.Released && UIParameters.mouseState.LeftButton == ButtonState.Pressed)
         {
             distanceVector = new Vector2(Main.mouseX, Main.mouseY) - this.obj.position;
             canMove        = true;
         }
     }
     if (UIParameters.lastMouseState.LeftButton == ButtonState.Pressed && UIParameters.mouseState.LeftButton == ButtonState.Pressed)
     {
         if (canMove)
         {
             this.obj.position = new Vector2(Main.mouseX, Main.mouseY) - distanceVector;
         }
     }
     if (UIParameters.mouseState.LeftButton == ButtonState.Released)
     {
         canMove = false;
     }
 }