Skip to content

Commit 5db05ff

Browse files
authored
Merge pull request #812 from Csantucci/rotated-dpu-display
Bug fix for https://bugs.launchpad.net/or/+bug/2009955 Missing code to rotate DMU display in 2D cabs
2 parents 3831af9 + 9dadddb commit 5db05ff

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Source/Orts.Formats.Msts/CabViewFile.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,9 @@ protected int ParseNumStyle(STFReader stf)
14471447
public class CVCScreen : CabViewControl
14481448
{
14491449
public readonly Dictionary<string, string> CustomParameters = new Dictionary<string, string>();
1450+
1451+
public float Rotation { get; set; }
1452+
14501453
public CVCScreen()
14511454
{
14521455
}
@@ -1460,6 +1463,7 @@ public CVCScreen(STFReader stf, string basepath)
14601463
new STFReader.TokenProcessor("graphic", ()=>{ ParseGraphic(stf, basepath); }),
14611464
new STFReader.TokenProcessor("units", ()=>{ ParseUnits(stf); }),
14621465
new STFReader.TokenProcessor("parameters", ()=>{ ParseCustomParameters(stf); }),
1466+
new STFReader.TokenProcessor("ortsangle", () =>{ Rotation = ParseRotation(stf); }),
14631467
new STFReader.TokenProcessor("disablediflowvoltagepowersupplyoff", ()=>{ ParseDisabledIfLowVoltagePowerSupplyOff(stf); }),
14641468
new STFReader.TokenProcessor("disabledifcabpowersupplyoff", ()=>{ ParseDisabledIfCabPowerSupplyOff(stf); }),
14651469
new STFReader.TokenProcessor("hideifdisabled", ()=>{ ParseHideIfDisabled(stf); }),

Source/RunActivity/Viewer3D/Popups/WindowText.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ public void Draw(SpriteBatch spriteBatch, Rectangle position, Point offset, stri
229229
}
230230

231231
[CallOnThread("Render")]
232-
void Draw(SpriteBatch spriteBatch, Point position, float rotation, int width, string text, LabelAlignment align, Color color, Color outline)
232+
public void Draw(SpriteBatch spriteBatch, Point position, float rotation, int width, string text, LabelAlignment align, Color color, Color outline)
233233
{
234+
if (text == null) return;
234235
EnsureCharacterData(text);
235236
var characters = Characters;
236237

Source/RunActivity/Viewer3D/RollingStock/SubSystems/DistributedPowerInterface.cs

+13-8
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class DistributedPowerInterface
8282
/// </summary>
8383
public bool IsSoftLayout;
8484
public DPIWindow ActiveWindow;
85-
public DistributedPowerInterface(float height, float width, MSTSLocomotive locomotive, Viewer viewer, CabViewControl control)
85+
public DistributedPowerInterface(float height, float width, MSTSLocomotive locomotive, Viewer viewer, CVCScreen control)
8686
{
8787
Viewer = viewer;
8888
Locomotive = locomotive;
@@ -172,7 +172,7 @@ public DPDefaultWindow(DistributedPowerInterface dpi, CabViewControl control) :
172172
sUnits = sUnits.Replace('/', '_');
173173
CABViewControlUnits.TryParse(sUnits, out LoadUnits);
174174
}
175-
DPITable = new DPITable(FullTable, LoadUnits, fullScreen:true, dpi:dpi);
175+
DPITable = new DPITable(FullTable, LoadUnits, fullScreen:true, dpi:dpi, (control as CVCScreen).Rotation);
176176
AddToLayout(DPITable, new Point(0, 0));
177177
}
178178
}
@@ -199,18 +199,20 @@ public class TextPrimitive
199199
public Color Color;
200200
public WindowTextFont Font;
201201
public string Text;
202+
public float DrawRotation;
202203

203-
public TextPrimitive(Point position, Color color, string text, WindowTextFont font)
204+
public TextPrimitive(Point position, Color color, string text, WindowTextFont font, float drawRotation = 0)
204205
{
205206
Position = position;
206207
Color = color;
207208
Text = text;
208209
Font = font;
210+
DrawRotation = drawRotation;
209211
}
210212

211213
public void Draw(SpriteBatch spriteBatch, Point position)
212214
{
213-
Font.Draw(spriteBatch, position, Text, Color);
215+
Font.Draw(spriteBatch, position, DrawRotation, 0, Text, LabelAlignment.Left, Color, Color.Black);
214216
}
215217
}
216218
public struct TexturePrimitive
@@ -372,6 +374,7 @@ public class DPITable : DPIWindow
372374
readonly int ColLength = 88;
373375
public bool FullTable = true;
374376
public CABViewControlUnits LoadUnits;
377+
private float DrawRotation = 0;
375378

376379
// Change text color
377380
readonly Dictionary<string, Color> ColorCodeCtrl = new Dictionary<string, Color>
@@ -390,22 +393,24 @@ public class DPITable : DPIWindow
390393

391394
public readonly string[] FirstColumn = { "ID", "Throttle", "Load", "BP", "Flow", "Remote", "ER", "BC", "MR" };
392395

393-
public DPITable(bool fullTable, CABViewControlUnits loadUnits, bool fullScreen, DistributedPowerInterface dpi) : base(dpi, 640, fullTable? 230 : 162)
396+
public DPITable(bool fullTable, CABViewControlUnits loadUnits, bool fullScreen, DistributedPowerInterface dpi, float drawRotation) : base(dpi, 640, fullTable? 230 : 162)
394397
{
395398
DPI = dpi;
396399
FullScreen = fullScreen;
397400
FullTable = fullTable;
398401
LoadUnits = loadUnits;
402+
DrawRotation = drawRotation;
399403
BackgroundColor = DPI.BlackWhiteTheme ? Color.Black : ColorBackground;
400404
SetFont();
401405
string text = "";
402406
for (int iRow = 0; iRow < (fullTable ? NumberOfRowsFull : NumberOfRowsPartial); iRow++)
403407
{
404408
for (int iCol = 0; iCol < NumberOfColumns; iCol++)
405409
{
406-
// text = iCol.ToString() + "--" + iRow.ToString();
407-
TableText[iRow, iCol] = new TextPrimitive(new Point(20 + ColLength * iCol, (iRow) * (FontHeightTableText + 8)), Color.White, text, TableTextFont);
408-
TableSymbol[iRow, iCol] = new TextPrimitive(new Point(10 + ColLength * iCol, (iRow) * (FontHeightTableText + 8)), Color.Green, text, TableSymbolFont);
410+
TableText[iRow, iCol] = new TextPrimitive(new Point(20 + ColLength * iCol - (int)(iRow * (FontHeightTableText - 8) * DrawRotation / 2), (iRow) * (FontHeightTableText + 8) + (int)(ColLength * iCol * DrawRotation)),
411+
Color.White, text, TableTextFont, DrawRotation);
412+
TableSymbol[iRow, iCol] = new TextPrimitive(new Point(10 + ColLength * iCol - (int)(iRow * (FontHeightTableText - 8) * DrawRotation / 2), (iRow) * (FontHeightTableText + 8) + (int)(ColLength * iCol * DrawRotation)),
413+
Color.Green, text, TableSymbolFont, DrawRotation);
409414
}
410415
}
411416
}

0 commit comments

Comments
 (0)