Skip to content

Commit 4b94574

Browse files
committed
Merge branch 'master' into release
2 parents a2eb93d + 5dd9d6a commit 4b94574

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1370
-1147
lines changed

assets/Compatibility/RoutePatches/America.xml

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<openBVE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
22
<RoutePatches>
3+
<!-- NYCT-L -->
34
<Patch>
45
<Hash>B97E93C1A21B43CCDA2C504F254E6F8FF099FD51E502E2EE875E6B05FBDE5326</Hash>
56
<FileName>NYCT-L.csv</FileName>
@@ -70,5 +71,11 @@
7071
<FileName>Penn Station to West Side Yard Night.csv</FileName>
7172
<AccurateObjectDisposal>true</AccurateObjectDisposal>
7273
</Patch>
74+
<Patch>
75+
<Hash>DF136CBEB37095503932D068941A9AC54D4F5F4CF96033EAB7533C2CE67EFE6C</Hash>
76+
<FileName>SF&amp;C South.rw</FileName>
77+
<AccurateObjectDisposal>true</AccurateObjectDisposal>
78+
</Patch>
79+
7380
</RoutePatches>
7481
</openBVE>

assets/Compatibility/RoutePatches/Poland.xml

+22-1
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,32 @@
2121
<ReducedColorTransparency>true</ReducedColorTransparency>
2222
</Patch>
2323
<!-- Leszno-Krotoszyn -->
24-
<Patch>
24+
<Patch>
2525
<Hash>1C600BA5074BF9C8B3E1BD045E544C123C919EAA82E676E04EBFBDAE971B0A03</Hash>
2626
<FileName>Leszno-Krotoszyn.csv</FileName>
2727
<AccurateObjectDisposal>true</AccurateObjectDisposal>
2828
<ReducedColorTransparency>true</ReducedColorTransparency>
2929
</Patch>
30+
<Patch>
31+
<Hash>BE4A2C2C9F311E67DC1CC2BB370F758CA576849E728187C93097B91E4BA8FA65</Hash>
32+
<FileName>Leszno-Krotoszyn.csv</FileName>
33+
<AccurateObjectDisposal>true</AccurateObjectDisposal>
34+
<ReducedColorTransparency>true</ReducedColorTransparency>
35+
</Patch>
36+
<!-- Metro Warszawskie -->
37+
<Patch>
38+
<Hash>3BFEA1F51E360DFDC5B1F4CAB7D05BD01097BB4C319D0C770BDD5AEA60FAC1D0</Hash>
39+
<FileName>Metro Warszawskie_81-717.rw</FileName>
40+
<AccurateObjectDisposal>true</AccurateObjectDisposal>
41+
<ReducedColorTransparency>true</ReducedColorTransparency>
42+
<CylinderHack>true</CylinderHack>
43+
</Patch>
44+
<Patch>
45+
<Hash>3AB5C577345A971F652881270601229CD5E6C53F346168A37B83BD51B686F59BA</Hash>
46+
<FileName>Metro Warszawskie_ALSTOM.rw</FileName>
47+
<AccurateObjectDisposal>true</AccurateObjectDisposal>
48+
<ReducedColorTransparency>true</ReducedColorTransparency>
49+
<CylinderHack>true</CylinderHack>
50+
</Patch>
3051
</RoutePatches>
3152
</openBVE>

source/LibRender2/Menu/Menu.OptionType.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//Simplified BSD License (BSD-2-Clause)
1+
//Simplified BSD License (BSD-2-Clause)
22
//
33
//Copyright (c) 2024, Maurizo M. Gavioli, The OpenBVE Project
44
//
@@ -40,6 +40,8 @@ public enum OptionType
4040
/// <summary>Sets the antialiasing level</summary>
4141
AntialiasingLevel,
4242
/// <summary>Sets the UI scale factor</summary>
43-
UIScaleFactor
43+
UIScaleFactor,
44+
/// <summary>Sets the total number of valid sounds</summary>
45+
NumberOfSounds
4446
}
4547
}

source/LibRender2/Menu/MenuEntries/MenuOption.cs

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//Simplified BSD License (BSD-2-Clause)
1+
//Simplified BSD License (BSD-2-Clause)
22
//
33
//Copyright (c) 2024, Maurizo M. Gavioli, The OpenBVE Project
44
//
@@ -55,7 +55,8 @@ public MenuOption(AbstractMenu menu, OptionType type, string text, object[] entr
5555
{
5656
for (int i = 0; i < castEntries.Length; i++)
5757
{
58-
if (castEntries[i].Width == BaseMenu.Renderer.Screen.Width && castEntries[i].Height == BaseMenu.Renderer.Screen.Height)
58+
// n.b. sometimes we seem to end up with a window size 1px different to that requested
59+
if (System.Math.Abs(castEntries[i].Width - BaseMenu.Renderer.Screen.Width) < 5 && System.Math.Abs(castEntries[i].Height - BaseMenu.Renderer.Screen.Height) < 5)
5960
{
6061
CurrentlySelectedOption = i;
6162
return;
@@ -120,7 +121,29 @@ public MenuOption(AbstractMenu menu, OptionType type, string text, object[] entr
120121
}
121122
return;
122123
case OptionType.UIScaleFactor:
123-
CurrentlySelectedOption = BaseMenu.CurrentOptions.UserInterfaceScaleFactor;
124+
CurrentlySelectedOption = BaseMenu.CurrentOptions.UserInterfaceScaleFactor - 1;
125+
return;
126+
case OptionType.NumberOfSounds:
127+
switch (BaseMenu.CurrentOptions.SoundNumber)
128+
{
129+
case 16:
130+
CurrentlySelectedOption = 0;
131+
break;
132+
case 32:
133+
CurrentlySelectedOption = 1;
134+
break;
135+
case 64:
136+
CurrentlySelectedOption = 2;
137+
break;
138+
case 128:
139+
CurrentlySelectedOption = 3;
140+
break;
141+
default:
142+
// n.b. This resets the sound number if edited manually in the file
143+
BaseMenu.CurrentOptions.SoundNumber = 16;
144+
CurrentlySelectedOption = 0;
145+
break;
146+
}
124147
return;
125148
}
126149
CurrentlySelectedOption = 0;
@@ -233,6 +256,9 @@ public void Flip()
233256
currentOption = currentOption.Trim('x');
234257
BaseMenu.CurrentOptions.UserInterfaceScaleFactor = int.Parse(currentOption, NumberStyles.Integer);
235258
break;
259+
case OptionType.NumberOfSounds:
260+
BaseMenu.CurrentOptions.SoundNumber = int.Parse((string)CurrentOption, NumberStyles.Integer);
261+
break;
236262

237263
}
238264

source/LibRender2/Overlays/Keys.cs

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public void Render(int Left, int Top, int Width, OpenGlFont Font, string[][] Key
2424
{
2525
int py = Top;
2626

27+
Width = (int)System.Math.Ceiling(OpenTK.DisplayDevice.Default.ScaleFactor.X * Width);
28+
2729
foreach (string[] key in Keys)
2830
{
2931
int px = Left;

source/LibRender2/Text/Fonts.cs

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Drawing;
2+
using System.IO;
23
using OpenBveApi.Hosts;
4+
using OpenTK;
35

46
namespace LibRender2.Text
57
{
@@ -54,6 +56,10 @@ public OpenGlFont NextSmallestFont(OpenGlFont currentFont)
5456
/// <returns>The next larger font</returns>
5557
public OpenGlFont NextLargestFont(OpenGlFont currentFont)
5658
{
59+
if (currentFont == null)
60+
{
61+
throw new InvalidDataException("No font was specified.");
62+
}
5763
switch ((int)currentFont.FontSize)
5864
{
5965
case 9:
@@ -86,12 +92,15 @@ public Fonts(HostInterface host, string fontName)
8692
}
8793

8894
}
89-
VerySmallFont = new OpenGlFont(uiFont, 9.0f);
90-
SmallFont = new OpenGlFont(uiFont, 12.0f);
91-
NormalFont = new OpenGlFont(uiFont, 16.0f);
92-
LargeFont = new OpenGlFont(uiFont, 21.0f);
93-
VeryLargeFont = new OpenGlFont(uiFont, 27.0f);
94-
EvenLargerFont = new OpenGlFont(uiFont, 34.0f);
95+
96+
float scaleFactor = DisplayDevice.Default.ScaleFactor.X;
97+
98+
VerySmallFont = new OpenGlFont(uiFont, 9.0f * scaleFactor);
99+
SmallFont = new OpenGlFont(uiFont, 12.0f * scaleFactor);
100+
NormalFont = new OpenGlFont(uiFont, 16.0f * scaleFactor);
101+
LargeFont = new OpenGlFont(uiFont, 21.0f * scaleFactor);
102+
VeryLargeFont = new OpenGlFont(uiFont, 27.0f * scaleFactor);
103+
EvenLargerFont = new OpenGlFont(uiFont, 34.0f * scaleFactor);
95104
}
96105
}
97106
}

source/LibRender2/Text/OpenGlFontTable.cs

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Drawing;
3+
using System.Drawing.Imaging;
34
using System.Drawing.Text;
45
using OpenBveApi.Math;
56
using OpenBveApi.Textures;
@@ -19,7 +20,7 @@ public class OpenGlFontTable : IDisposable
1920

2021
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
2122
// Must remain, else will be disposed of by the GC as this is a separate assembly
22-
private readonly Bitmap bitmap;
23+
private readonly byte[] myBytes;
2324
/// <summary>The border around glpyhs on the font bitmap</summary>
2425
const int drawBorder = 20;
2526
/// <summary>The border used when calculating texture co-ordinates</summary>
@@ -36,7 +37,7 @@ public OpenGlFontTable(Font font, int offset)
3637
* */
3738
Vector2[] physicalSizes = new Vector2[256];
3839
Vector2[] typographicSizes = new Vector2[256];
39-
bitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
40+
Bitmap bitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
4041
Graphics graphics = Graphics.FromImage(bitmap);
4142
graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
4243
double lineHeight = 0;
@@ -120,7 +121,18 @@ public OpenGlFontTable(Font font, int offset)
120121
Characters[i] = new OpenGlFontChar(new Vector4(x0, y0, x1 - x0, y1 - y0), new Vector2(physicalSizes[i].X + 2.0 * coordinateBorder, physicalSizes[i].Y + 2.0 * coordinateBorder), typographicSizes[i]);
121122
}
122123
graphics.Dispose();
123-
Texture = new Texture(bitmap);
124+
BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
125+
if (data.Stride == 4 * data.Width) {
126+
/*
127+
* Copy the data from the bitmap
128+
* to the array in BGRA format.
129+
*/
130+
myBytes = new byte[data.Stride * data.Height];
131+
System.Runtime.InteropServices.Marshal.Copy(data.Scan0, myBytes, 0, data.Stride * data.Height);
132+
bitmap.UnlockBits(data);
133+
}
134+
Texture = new Texture(bitmap.Width, bitmap.Height, OpenBveApi.Textures.PixelFormat.RGBAlpha, myBytes, null);
135+
bitmap.Dispose();
124136
}
125137

126138
/// <summary>Rounds the specified value to the next-highest power of two.</summary>
@@ -145,16 +157,7 @@ private static uint RoundToPowerOfTwo(uint value)
145157

146158
public void Dispose()
147159
{
148-
Dispose(true);
149160
GC.SuppressFinalize(this);
150161
}
151-
152-
private void Dispose(bool currentlyDisposing)
153-
{
154-
if (currentlyDisposing)
155-
{
156-
bitmap.Dispose();
157-
}
158-
}
159162
}
160163
}

0 commit comments

Comments
 (0)