Skip to content

Commit 0ac5d30

Browse files
committed
Cabview mouse wheel support
1 parent c74058d commit 0ac5d30

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

Source/RunActivity/Viewer3D/Cameras.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ protected void ZoomByMouseWheel(float speed)
266266
{
267267
// Will not zoom-in-out when help windows is up.
268268
// TODO: Property input processing through WindowManager.
269-
if (UserInput.IsMouseWheelChanged && !Viewer.HelpWindow.Visible)
269+
if (UserInput.IsMouseWheelChanged && !Viewer.HelpWindow.Visible && !Viewer.RenderProcess.IsMouseVisible)
270270
{
271271
var fieldOfView = MathHelper.Clamp(FieldOfView - speed * UserInput.MouseWheelChange / 10, 1, 135);
272272
new FieldOfViewCommand(Viewer.Log, fieldOfView);

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2336,8 +2336,8 @@ public virtual int GetDrawIndex()
23362336
float NormalizedMouseMovement()
23372337
{
23382338
return (ControlDiscrete.Orientation > 0
2339-
? (float)UserInput.MouseMoveY / (float)Control.Height
2340-
: (float)UserInput.MouseMoveX / (float)Control.Width)
2339+
? (float)(UserInput.MouseMoveY + UserInput.MouseWheelChange) / (float)Control.Height
2340+
: (float)(UserInput.MouseMoveX + UserInput.MouseWheelChange) / (float)Control.Width)
23412341
* (ControlDiscrete.Direction > 0 ? -1 : 1);
23422342
}
23432343

Source/RunActivity/Viewer3D/Viewer.cs

+16-25
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public void ToggleCabCameraView()
166166
List<Camera> WellKnownCameras; // Providing Camera save functionality by GeorgeS
167167

168168
public TrainCarViewer PlayerLocomotiveViewer { get; private set; } // we are controlling this loco, or null if we aren't controlling any
169-
MouseState originalMouseState; // Current mouse coordinates.
170169

171170
// This is the train we are controlling
172171
public TrainCar PlayerLocomotive { get { return Simulator.PlayerLocomotive; } set { Simulator.PlayerLocomotive = value; } }
@@ -1437,15 +1436,10 @@ void HandleUserInput(ElapsedTime elapsedTime)
14371436
ForceMouseVisible = false;
14381437
}
14391438

1440-
// reset cursor type when needed
1441-
1442-
if (!(Camera is CabCamera) && !(Camera is ThreeDimCabCamera) && ActualCursor != Cursors.Default) ActualCursor = Cursors.Default;
1443-
14441439
if (UserInput.IsMouseLeftButtonPressed || RenderProcess.IsMouseVisible)
14451440
{
1446-
var locoViewer = (PlayerLocomotiveViewer as MSTSLocomotiveViewer);
1441+
var locoViewer = PlayerLocomotiveViewer as MSTSLocomotiveViewer;
14471442

1448-
// Mouse control for 2D cab
14491443
if (Camera is CabCamera && locoViewer._hasCabRenderer)
14501444
{
14511445
foreach (var controlRenderer in locoViewer._CabRenderer.ControlMap.Values)
@@ -1463,8 +1457,7 @@ void HandleUserInput(ElapsedTime elapsedTime)
14631457
}
14641458
}
14651459
}
1466-
// mouse for 3D camera
1467-
if (Camera is ThreeDimCabCamera && locoViewer._has3DCabRenderer)
1460+
else if (Camera is ThreeDimCabCamera && locoViewer._has3DCabRenderer)
14681461
{
14691462
var trainCarShape = locoViewer.ThreeDimentionCabViewer.TrainCarShape;
14701463
float bestD = 0.01f; // 10 cm squared click range
@@ -1497,35 +1490,33 @@ void HandleUserInput(ElapsedTime elapsedTime)
14971490
}
14981491
}
14991492
}
1493+
else
1494+
{
1495+
ActualCursor = Cursors.Default;
1496+
}
15001497
}
15011498

15021499
if (MousePickedControl != null & MousePickedControl != OldMousePickedControl)
15031500
Simulator.Confirmer.Message(ConfirmLevel.None, String.IsNullOrEmpty(MousePickedControl.ControlLabel) ? MousePickedControl.GetControlName() : MousePickedControl.ControlLabel);
15041501

1505-
if (MousePickedControl != null) ActualCursor = Cursors.Hand;
1506-
else if (ActualCursor == Cursors.Hand) ActualCursor = Cursors.Default;
1502+
ActualCursor = RenderProcess.ActualCursor = MousePickedControl != null ? Cursors.Hand : Cursors.Default;
1503+
1504+
if (UserInput.IsMouseWheelChanged)
1505+
MousePickedControl?.HandleUserInput();
15071506

15081507
OldMousePickedControl = MousePickedControl;
15091508
MousePickedControl = null;
15101509

1511-
if (MouseChangingControl != null)
1512-
{
1513-
MouseChangingControl.HandleUserInput();
1514-
if (UserInput.IsMouseLeftButtonReleased)
1515-
MouseChangingControl = null;
1516-
}
1517-
1518-
UserInput.Handled();
1510+
MouseChangingControl?.HandleUserInput();
1511+
if (UserInput.IsMouseLeftButtonReleased)
1512+
MouseChangingControl = null;
15191513

1520-
MouseState currentMouseState = Mouse.GetState();
1521-
1522-
if (currentMouseState.X != originalMouseState.X ||
1523-
currentMouseState.Y != originalMouseState.Y)
1514+
if (UserInput.IsMouseMoved || RenderProcess.IsMouseVisible && UserInput.IsMouseWheelChanged)
15241515
MouseVisibleTillRealTime = RealTime + 1;
15251516

15261517
RenderProcess.IsMouseVisible = ForceMouseVisible || RealTime < MouseVisibleTillRealTime;
1527-
originalMouseState = currentMouseState;
1528-
RenderProcess.ActualCursor = ActualCursor;
1518+
1519+
UserInput.Handled();
15291520
}
15301521

15311522
static bool IsReverserInNeutral(TrainCar car)

0 commit comments

Comments
 (0)