public Graber(Vector2 position, byte defaultValue, Texture2D bar = null, CallOnChange onChange = null, GrabShow show = GrabShow.none, string text = null) { _boudary = new RectangleF(new Vector2(20, 32), position + new Vector2(-10, 1) + new Vector2(defaultValue, 0)); _position = position; _grabed = GraberState.none; _bar = bar; _onChange = onChange; _show = show; _text = text; }
public void Update() { if (MouseInput.MouseStateNew.LeftButton == ButtonState.Pressed && MouseInput.MouseStateOld.LeftButton == ButtonState.Released) { if (CompareF.RectangleVsVector2(_boudary, MouseInput.MouseRealPosMenu()) == true) { _grabed = GraberState.grabed; } } else if (MouseInput.MouseStateNew.LeftButton == ButtonState.Released) { if (CompareF.RectangleVsVector2(_boudary, MouseInput.MouseRealPosMenu()) == true) { _grabed = GraberState.hover; } else { _grabed = GraberState.none; } } if (_grabed == GraberState.grabed) { _boudary.Position = new Vector2(MouseInput.MouseRealPosMenu().X, _boudary.Position.Y) - new Vector2(_boudary.Size.X / 2, 0); } if (_boudary.Position.X < _position.X - _boudary.Size.X / 2) { _boudary.Position = new Vector2(_position.X - _boudary.Size.X / 2, _boudary.Position.Y); } if (_boudary.Position.X > _position.X + 255 - _boudary.Size.X / 2) { _boudary.Position = new Vector2(_position.X + 255 - _boudary.Size.X / 2, _boudary.Position.Y); } if (_onChange != null) { if (_grabed == GraberState.grabed) { _onChange(GetValue()); } } }