Skip to content

Commit

Permalink
Relative nub movement to click position
Browse files Browse the repository at this point in the history
  • Loading branch information
entrhopi committed Dec 15, 2021
1 parent f316953 commit 4c0ad99
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Blish HUD/Controls/TrackBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ private void InputOnLeftMouseButtonReleased(object sender, MouseEventArgs e) {
protected override void OnLeftMouseButtonPressed(MouseEventArgs e) {
base.OnLeftMouseButtonPressed(e);

if (_layoutNubBounds.Contains(this.RelativeMousePosition)) {
if (_layoutNubBounds.Contains(this.RelativeMousePosition) && !_dragging) {
_dragging = true;
_dragOffset = this.RelativeMousePosition.X - _layoutNubBounds.X;
_dragOffset = this.RelativeMousePosition.X - _layoutNubBounds.X - BUMPER_WIDTH / 2;
}
}

public override void DoUpdate(GameTime gameTime) {
if (_dragging) {
float rawValue = (this.RelativeMousePosition.X - BUMPER_WIDTH) / (float)(this.Width - BUMPER_WIDTH - _textureNub.Width) * (this.MaxValue - this.MinValue) + this.MinValue;
float rawValue = (this.RelativeMousePosition.X - BUMPER_WIDTH - _dragOffset) / (float)(this.Width - BUMPER_WIDTH - _textureNub.Width) * (this.MaxValue - this.MinValue) + this.MinValue;

this.Value = GameService.Input.Keyboard.ActiveModifiers != ModifierKeys.Ctrl
? SmallStep ? rawValue : (float)Math.Round(rawValue, 0)
Expand Down

0 comments on commit 4c0ad99

Please sign in to comment.