Skip to content

Commit 4830217

Browse files
authored
Merge pull request #480 from Csantucci/3dCab-digitals-alignment
Blueprint https://blueprints.launchpad.net/or/+spec/digital-alignment-in-3dcabs
2 parents 99a9aa7 + 7815b89 commit 4830217

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

Source/Documentation/Manual/cabs.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,3 +808,13 @@ Here below is an example of an entry for a 3D cab::
808808
ScaleRange ( 0 5000 )
809809
Units ( LBS )
810810
)
811+
812+
Alignment for digital controls
813+
------------------------------
814+
815+
For backwards compatibility reasons, ``Justification ( 1 )``, ``Justification ( 2 )`` and
816+
``Justification ( 3 )`` all lead to a left alignment of the digital in 3Dcabs.
817+
818+
``Justification ( 5 )`` must be used for center alignment, and ``Justification ( 6 )``
819+
must be used for right alignment. ``Justification ( 4 )`` leads to left alignment.
820+

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,7 +2437,18 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
24372437
/// </summary>
24382438
public class CabViewDigitalRenderer : CabViewControlRenderer
24392439
{
2440-
readonly LabelAlignment Alignment;
2440+
public enum CVDigitalAlignment
2441+
{
2442+
Left,
2443+
Center,
2444+
Right,
2445+
// Next ones are used for 3D cabs; digitals of old 3D cab will continue to be displayed left aligned for compatibility
2446+
Cab3DLeft,
2447+
Cab3DCenter,
2448+
Cab3DRight
2449+
}
2450+
2451+
public readonly CVDigitalAlignment Alignment;
24412452
string Format = "{0}";
24422453
readonly string Format1 = "{0}";
24432454
readonly string Format2 = "{0}";
@@ -2458,9 +2469,10 @@ public CabViewDigitalRenderer(Viewer viewer, MSTSLocomotive car, CVCDigital digi
24582469

24592470
// Clock defaults to centered.
24602471
if (Control.ControlType == CABViewControlTypes.CLOCK)
2461-
Alignment = LabelAlignment.Center;
2462-
Alignment = digital.Justification == 1 ? LabelAlignment.Center : digital.Justification == 2 ? LabelAlignment.Left : digital.Justification == 3 ? LabelAlignment.Right : Alignment;
2463-
2472+
Alignment = CVDigitalAlignment.Center;
2473+
Alignment = digital.Justification == 1 ? CVDigitalAlignment.Center : digital.Justification == 2 ? CVDigitalAlignment.Left : digital.Justification == 3 ? CVDigitalAlignment.Right : Alignment;
2474+
// Used for 3D cabs
2475+
Alignment = digital.Justification == 4 ? CVDigitalAlignment.Cab3DCenter : digital.Justification == 5 ? CVDigitalAlignment.Cab3DLeft : digital.Justification == 6 ? CVDigitalAlignment.Cab3DRight : Alignment;
24642476
Format1 = "{0:0" + new String('0', digital.LeadingZeros) + (digital.Accuracy > 0 ? "." + new String('0', (int)digital.Accuracy) : "") + "}";
24652477
Format2 = "{0:0" + new String('0', digital.LeadingZeros) + (digital.AccuracySwitch > 0 ? "." + new String('0', (int)(digital.Accuracy + 1)) : "") + "}";
24662478
}
@@ -2540,7 +2552,8 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
25402552

25412553
public override void Draw(GraphicsDevice graphicsDevice)
25422554
{
2543-
DrawFont.Draw(ControlView.SpriteBatch, DrawPosition, Point.Zero, DrawRotation, DrawText, Alignment, DrawColor, Color.Black);
2555+
var alignment = (LabelAlignment)Alignment;
2556+
DrawFont.Draw(ControlView.SpriteBatch, DrawPosition, Point.Zero, DrawRotation, DrawText, alignment, DrawColor, Color.Black);
25442557
}
25452558

25462559
public string GetDigits(out Color DrawColor)
@@ -3057,14 +3070,32 @@ Material FindMaterial(bool Alert)
30573070
//update the digits with current speed or time
30583071
public void UpdateDigit()
30593072
{
3060-
NumVertices = NumIndices = 0;
30613073

30623074
Material UsedMaterial = Material; //use default material
30633075

30643076
//update text string
30653077
bool Alert;
30663078
string speed = CVFR.Get3DDigits(out Alert);
30673079

3080+
NumVertices = NumIndices = 0;
3081+
3082+
// add leading blanks to consider alignment
3083+
// for backwards compatibiliy with preceding OR releases all Justification values defined by MSTS are considered as left justified
3084+
var leadingBlankCount = 0;
3085+
switch (CVFR.Alignment)
3086+
{
3087+
case CabViewDigitalRenderer.CVDigitalAlignment.Cab3DRight:
3088+
leadingBlankCount = MaxDigits - speed.Length;
3089+
break;
3090+
case CabViewDigitalRenderer.CVDigitalAlignment.Cab3DCenter:
3091+
leadingBlankCount = (MaxDigits - speed.Length + 1) / 2;
3092+
break;
3093+
default:
3094+
break;
3095+
}
3096+
for (int i = leadingBlankCount; i > 0; i--)
3097+
speed = speed.Insert(0, " ");
3098+
30683099
if (Alert)//alert use alert meterial
30693100
{
30703101
if (AlertMaterial == null) AlertMaterial = FindMaterial(true);

0 commit comments

Comments
 (0)