Skip to content

Commit

Permalink
Create separate enum and update manual.
Browse files Browse the repository at this point in the history
  • Loading branch information
Csantucci committed Oct 20, 2021
1 parent 6bc94a9 commit 7815b89
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
10 changes: 10 additions & 0 deletions Source/Documentation/Manual/cabs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,13 @@ Here below is an example of an entry for a 3D cab::
ScaleRange ( 0 5000 )
Units ( LBS )
)

Alignment for digital controls
------------------------------

For backwards compatibility reasons, ``Justification ( 1 )``, ``Justification ( 2 )`` and
``Justification ( 3 )`` all lead to a left alignment of the digital in 3Dcabs.

``Justification ( 5 )`` must be used for center alignment, and ``Justification ( 6 )``
must be used for right alignment. ``Justification ( 4 )`` leads to left alignment.

3 changes: 0 additions & 3 deletions Source/RunActivity/Viewer3D/Popups/WindowControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ public enum LabelAlignment
Left,
Center,
Right,
Cab3DLeft,
Cab3DCenter,
Cab3DRight,
}

public class Label : Control
Expand Down
32 changes: 20 additions & 12 deletions Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2431,7 +2431,18 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
/// </summary>
public class CabViewDigitalRenderer : CabViewControlRenderer
{
readonly LabelAlignment Alignment;
public enum CVDigitalAlignment
{
Left,
Center,
Right,
// Next ones are used for 3D cabs; digitals of old 3D cab will continue to be displayed left aligned for compatibility
Cab3DLeft,
Cab3DCenter,
Cab3DRight
}

public readonly CVDigitalAlignment Alignment;
string Format = "{0}";
readonly string Format1 = "{0}";
readonly string Format2 = "{0}";
Expand All @@ -2452,10 +2463,10 @@ public CabViewDigitalRenderer(Viewer viewer, MSTSLocomotive car, CVCDigital digi

// Clock defaults to centered.
if (Control.ControlType == CABViewControlTypes.CLOCK)
Alignment = LabelAlignment.Center;
Alignment = digital.Justification == 1 ? LabelAlignment.Center : digital.Justification == 2 ? LabelAlignment.Left : digital.Justification == 3 ? LabelAlignment.Right : Alignment;
Alignment = CVDigitalAlignment.Center;
Alignment = digital.Justification == 1 ? CVDigitalAlignment.Center : digital.Justification == 2 ? CVDigitalAlignment.Left : digital.Justification == 3 ? CVDigitalAlignment.Right : Alignment;
// Used for 3D cabs
Alignment = digital.Justification == 4 ? LabelAlignment.Cab3DCenter : digital.Justification == 5 ? LabelAlignment.Cab3DLeft : digital.Justification == 6 ? LabelAlignment.Cab3DRight : Alignment;
Alignment = digital.Justification == 4 ? CVDigitalAlignment.Cab3DCenter : digital.Justification == 5 ? CVDigitalAlignment.Cab3DLeft : digital.Justification == 6 ? CVDigitalAlignment.Cab3DRight : Alignment;
Format1 = "{0:0" + new String('0', digital.LeadingZeros) + (digital.Accuracy > 0 ? "." + new String('0', (int)digital.Accuracy) : "") + "}";
Format2 = "{0:0" + new String('0', digital.LeadingZeros) + (digital.AccuracySwitch > 0 ? "." + new String('0', (int)(digital.Accuracy + 1)) : "") + "}";
}
Expand Down Expand Up @@ -2535,7 +2546,8 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)

public override void Draw(GraphicsDevice graphicsDevice)
{
DrawFont.Draw(ControlView.SpriteBatch, DrawPosition, Point.Zero, DrawRotation, DrawText, Alignment, DrawColor, Color.Black);
var alignment = (LabelAlignment)Alignment;
DrawFont.Draw(ControlView.SpriteBatch, DrawPosition, Point.Zero, DrawRotation, DrawText, alignment, DrawColor, Color.Black);
}

public string GetDigits(out Color DrawColor)
Expand Down Expand Up @@ -2680,10 +2692,6 @@ public string GetDigits(out Color DrawColor)
return "";
}

public LabelAlignment GetAlignment() //used in 3D cab, to get alignment
{
return Alignment;
}
}

/// <summary>
Expand Down Expand Up @@ -3067,12 +3075,12 @@ public void UpdateDigit()
// add leading blanks to consider alignment
// for backwards compatibiliy with preceding OR releases all Justification values defined by MSTS are considered as left justified
var leadingBlankCount = 0;
switch (CVFR.GetAlignment())
switch (CVFR.Alignment)
{
case LabelAlignment.Cab3DRight:
case CabViewDigitalRenderer.CVDigitalAlignment.Cab3DRight:
leadingBlankCount = MaxDigits - speed.Length;
break;
case LabelAlignment.Cab3DCenter:
case CabViewDigitalRenderer.CVDigitalAlignment.Cab3DCenter:
leadingBlankCount = (MaxDigits - speed.Length + 1) / 2;
break;
default:
Expand Down

0 comments on commit 7815b89

Please sign in to comment.