static private RegisterTexture ( |
||
Bitmap | ||
TransparentColor | ||
return | int |
// get opengl texture index internal static int GetTextureIndex(FontType FontType, int Codepoint) { int Font = (int)FontType; string t = char.ConvertFromUtf32(Codepoint); int i = char.ConvertToUtf32(t, 0); if (i >= Characters[Font].Length || Characters[Font][i].Texture == -1) { if (Characters[Font].Length == 0) { Characters[Font] = new Character[i + 1]; for (int j = 0; j <= i; j++) { Characters[Font][j].Texture = -1; } } while (i >= Characters[Font].Length) { int n = Characters[Font].Length; Array.Resize <Character>(ref Characters[Font], 2 * n); for (int j = n; j < 2 * n; j++) { Characters[Font][j].Texture = -1; } } float s1; switch (Font) { case 0: s1 = ExtraSmallFontSize; break; case 1: s1 = SmallFontSize; break; case 2: s1 = MediumFontSize; break; case 3: s1 = LargeFontSize; break; case 4: s1 = ExtraLargeFontSize; break; default: s1 = SmallFontSize; break; } int s0w = Interface.RoundToPowerOfTwo((int)Math.Ceiling((double)s1 * 1.25)); int s0h = s0w; FontStyle fs = Font == 0 ? FontStyle.Regular : FontStyle.Regular; Bitmap b = new Bitmap(s0w, s0h, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(b); g.Clear(Color.Black); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; Font f = new Font(FontFamily.GenericSansSerif, s1, fs, GraphicsUnit.Pixel); SizeF s = g.MeasureString(t, f, s0w, StringFormat.GenericTypographic); g.DrawString(t, f, Brushes.White, 0.0f, 0.0f); g.Dispose(); Characters[Font][i].Texture = TextureManager.RegisterTexture(b, false); Characters[Font][i].Width = s.Width <= 0.05f ? 4.0f : (float)Math.Ceiling((double)s.Width); Characters[Font][i].Height = s.Height <= 0.05f ? 4.0f : (float)Math.Ceiling((double)s.Height); b.Dispose(); } return(Characters[Font][i].Texture); }
private static void Init() { Initialized = true; string Folder = OpenBveApi.Path.CombineDirectory(Program.FileSystem.GetDataFolder(), "RouteViewer"); TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "background.png"), out BackgroundChangeTexture); TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "brightness.png"), out BrightnessChangeTexture); TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "transponder.png"), out TransponderTexture); TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "section.png"), out SectionTexture); TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "limit.png"), out LimitTexture); TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "station_start.png"), out StationStartTexture); TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "station_end.png"), out StationEndTexture); TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "stop.png"), out StopTexture); TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "buffer.png"), out BufferTexture); TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "sound.png"), out SoundTexture); TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, "switchsound.png"), out PointSoundTexture); }
/// <summary>Registers a texture and returns a handle to the texture.</summary> /// <param name="path">The path to the file or folder that contains the texture.</param> /// <param name="parameters">The parameters that specify how to process the texture.</param> /// <param name="handle">Receives the handle to the texture.</param> /// <returns>Whether loading the texture was successful.</returns> public override bool RegisterTexture(string path, TextureParameters parameters, out Texture handle) { if (System.IO.File.Exists(path) || System.IO.Directory.Exists(path)) { Texture data; if (TextureManager.RegisterTexture(path, parameters, out data)) { handle = data; return(true); } } else { ReportProblem(OpenBveApi.Hosts.ProblemType.PathNotFound, path); } handle = null; return(false); }
public override void Initialize(HostInterface CurrentHost, BaseOptions CurrentOptions) { base.Initialize(CurrentHost, CurrentOptions); string Folder = Path.CombineDirectory(Program.FileSystem.GetDataFolder(), "RouteViewer"); TextureManager.RegisterTexture(Path.CombineFile(Folder, "background.png"), out BackgroundChangeTexture); TextureManager.RegisterTexture(Path.CombineFile(Folder, "brightness.png"), out BrightnessChangeTexture); TextureManager.RegisterTexture(Path.CombineFile(Folder, "transponder.png"), out TransponderTexture); TextureManager.RegisterTexture(Path.CombineFile(Folder, "section.png"), out SectionTexture); TextureManager.RegisterTexture(Path.CombineFile(Folder, "limit.png"), out LimitTexture); TextureManager.RegisterTexture(Path.CombineFile(Folder, "station_start.png"), out StationStartTexture); TextureManager.RegisterTexture(Path.CombineFile(Folder, "station_end.png"), out StationEndTexture); TextureManager.RegisterTexture(Path.CombineFile(Folder, "stop.png"), out StopTexture); TextureManager.RegisterTexture(Path.CombineFile(Folder, "buffer.png"), out BufferTexture); TextureManager.RegisterTexture(Path.CombineFile(Folder, "sound.png"), out SoundTexture); TextureManager.RegisterTexture(Path.CombineFile(Folder, "switchsound.png"), out PointSoundTexture); }
// // INIT LOADING RESOURCES // /// <summary>Initializes the textures used for the loading screen</summary> internal static void InitLoading() { customLoadScreen = false; string Path = Program.FileSystem.GetDataFolder("In-game"); int bkgNo = Game.Generator.Next(numOfLoadingBkgs); if (TextureLoadingBkg == -1) { string file = OpenBveApi.Path.CombineFile(Path, "loadingbkg_" + bkgNo + ".png"); if (System.IO.File.Exists(file)) { TextureLoadingBkg = TextureManager.RegisterTexture(file, TextureManager.TextureWrapMode.ClampToEdge, TextureManager.TextureWrapMode.ClampToEdge, false); TextureManager.UseTexture(TextureLoadingBkg, TextureManager.UseMode.LoadImmediately); } } // choose logo size according to screen width string fName; if (Renderer.ScreenWidth > 2048) { fName = LogoFileName[2]; } else if (Renderer.ScreenWidth > 1024) { fName = LogoFileName[1]; } else { fName = LogoFileName[0]; } fName = OpenBveApi.Path.CombineFile(Path, fName); if (System.IO.File.Exists(fName)) { TextureLogo = TextureManager.RegisterTexture(fName, TextureManager.TextureWrapMode.ClampToEdge, TextureManager.TextureWrapMode.ClampToEdge, false); TextureManager.UseTexture(TextureLogo, TextureManager.UseMode.LoadImmediately); } }
/// <summary>Loads the current HUD</summary> internal static void LoadHUD() { CultureInfo Culture = CultureInfo.InvariantCulture; string Folder = Program.FileSystem.GetDataFolder("In-game", Interface.CurrentOptions.UserInterfaceFolder); string File = OpenBveApi.Path.CombineFile(Folder, "interface.cfg"); CurrentHudElements = new Element[16]; int Length = 0; if (System.IO.File.Exists(File)) { string[] Lines = System.IO.File.ReadAllLines(File, new System.Text.UTF8Encoding()); for (int i = 0; i < Lines.Length; i++) { int j = Lines[i].IndexOf(';'); if (j >= 0) { Lines[i] = Lines[i].Substring(0, j).Trim(); } else { Lines[i] = Lines[i].Trim(); } if (Lines[i].Length != 0) { if (!Lines[i].StartsWith(";", StringComparison.Ordinal)) { if (Lines[i].Equals("[element]", StringComparison.OrdinalIgnoreCase)) { Length++; if (Length > CurrentHudElements.Length) { Array.Resize <Element>(ref CurrentHudElements, CurrentHudElements.Length << 1); } CurrentHudElements[Length - 1] = new Element(); } else if (Length == 0) { MessageBox.Show("Line outside of [element] structure encountered at line " + (i + 1).ToString(Culture) + " in " + File); } else { j = Lines[i].IndexOf("=", StringComparison.Ordinal); if (j >= 0) { string Command = Lines[i].Substring(0, j).TrimEnd(); string[] Arguments = Lines[i].Substring(j + 1).TrimStart().Split(new char[] { ',' }, StringSplitOptions.None); for (j = 0; j < Arguments.Length; j++) { Arguments[j] = Arguments[j].Trim(); } switch (Command.ToLowerInvariant()) { case "subject": if (Arguments.Length == 1) { CurrentHudElements[Length - 1].Subject = Arguments[0]; } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "position": if (Arguments.Length == 2) { float x, y; if (!float.TryParse(Arguments[0], NumberStyles.Float, Culture, out x)) { MessageBox.Show("X is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!float.TryParse(Arguments[1], NumberStyles.Float, Culture, out y)) { MessageBox.Show("Y is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { CurrentHudElements[Length - 1].Position.X = x; CurrentHudElements[Length - 1].Position.Y = y; } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "alignment": if (Arguments.Length == 2) { int x, y; if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out x)) { MessageBox.Show("X is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!int.TryParse(Arguments[1], NumberStyles.Integer, Culture, out y)) { MessageBox.Show("Y is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { CurrentHudElements[Length - 1].Alignment.X = Math.Sign(x); CurrentHudElements[Length - 1].Alignment.Y = Math.Sign(y); } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "topleft": if (Arguments.Length == 2) { if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].TopLeft.BackgroundTexture); } if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].TopLeft.OverlayTexture); } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "topmiddle": if (Arguments.Length == 2) { if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].TopMiddle.BackgroundTexture); } if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].TopMiddle.OverlayTexture); } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "topright": if (Arguments.Length == 2) { if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].TopRight.BackgroundTexture); } if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].TopRight.OverlayTexture); } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "centerleft": if (Arguments.Length == 2) { if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].CenterLeft.BackgroundTexture); } if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].CenterLeft.OverlayTexture); } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "centermiddle": if (Arguments.Length == 2) { if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].CenterMiddle.BackgroundTexture); } if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].CenterMiddle.OverlayTexture); } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "centerright": if (Arguments.Length == 2) { if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].CenterRight.BackgroundTexture); } if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].CenterRight.OverlayTexture); } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "bottomleft": if (Arguments.Length == 2) { if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].BottomLeft.BackgroundTexture); } if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].BottomLeft.OverlayTexture); } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "bottommiddle": if (Arguments.Length == 2) { if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].BottomMiddle.BackgroundTexture); } if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].BottomMiddle.OverlayTexture); } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "bottomright": if (Arguments.Length == 2) { if (Arguments[0].Length != 0 & !Arguments[0].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[0]), out CurrentHudElements[Length - 1].BottomRight.BackgroundTexture); } if (Arguments[1].Length != 0 & !Arguments[1].Equals("null", StringComparison.OrdinalIgnoreCase)) { TextureManager.RegisterTexture(OpenBveApi.Path.CombineFile(Folder, Arguments[1]), out CurrentHudElements[Length - 1].BottomRight.OverlayTexture); } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "backcolor": if (Arguments.Length == 4) { int r, g, b, a; if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out r)) { MessageBox.Show("R is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!int.TryParse(Arguments[1], NumberStyles.Integer, Culture, out g)) { MessageBox.Show("G is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!int.TryParse(Arguments[2], NumberStyles.Integer, Culture, out b)) { MessageBox.Show("B is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!int.TryParse(Arguments[3], NumberStyles.Integer, Culture, out a)) { MessageBox.Show("A is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { r = r < 0 ? 0 : r > 255 ? 255 : r; g = g < 0 ? 0 : g > 255 ? 255 : g; b = b < 0 ? 0 : b > 255 ? 255 : b; a = a < 0 ? 0 : a > 255 ? 255 : a; CurrentHudElements[Length - 1].BackgroundColor = new Color32((byte)r, (byte)g, (byte)b, (byte)a); } break; } MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); break; case "overlaycolor": if (Arguments.Length == 4) { int r, g, b, a; if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out r)) { MessageBox.Show("R is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!int.TryParse(Arguments[1], NumberStyles.Integer, Culture, out g)) { MessageBox.Show("G is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!int.TryParse(Arguments[2], NumberStyles.Integer, Culture, out b)) { MessageBox.Show("B is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!int.TryParse(Arguments[3], NumberStyles.Integer, Culture, out a)) { MessageBox.Show("A is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { r = r < 0 ? 0 : r > 255 ? 255 : r; g = g < 0 ? 0 : g > 255 ? 255 : g; b = b < 0 ? 0 : b > 255 ? 255 : b; a = a < 0 ? 0 : a > 255 ? 255 : a; CurrentHudElements[Length - 1].OverlayColor = new Color32((byte)r, (byte)g, (byte)b, (byte)a); } break; } MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); break; case "textcolor": if (Arguments.Length == 4) { int r, g, b, a; if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out r)) { MessageBox.Show("R is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!int.TryParse(Arguments[1], NumberStyles.Integer, Culture, out g)) { MessageBox.Show("G is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!int.TryParse(Arguments[2], NumberStyles.Integer, Culture, out b)) { MessageBox.Show("B is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!int.TryParse(Arguments[3], NumberStyles.Integer, Culture, out a)) { MessageBox.Show("A is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { r = r < 0 ? 0 : r > 255 ? 255 : r; g = g < 0 ? 0 : g > 255 ? 255 : g; b = b < 0 ? 0 : b > 255 ? 255 : b; a = a < 0 ? 0 : a > 255 ? 255 : a; CurrentHudElements[Length - 1].TextColor = new Color32((byte)r, (byte)g, (byte)b, (byte)a); } break; } MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); break; case "textposition": if (Arguments.Length == 2) { float x, y; if (!float.TryParse(Arguments[0], NumberStyles.Float, Culture, out x)) { MessageBox.Show("X is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!float.TryParse(Arguments[1], NumberStyles.Float, Culture, out y)) { MessageBox.Show("Y is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { CurrentHudElements[Length - 1].TextPosition.X = x; CurrentHudElements[Length - 1].TextPosition.Y = y; } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "textalignment": if (Arguments.Length == 2) { int x, y; if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out x)) { MessageBox.Show("X is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!int.TryParse(Arguments[1], NumberStyles.Integer, Culture, out y)) { MessageBox.Show("Y is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { CurrentHudElements[Length - 1].TextAlignment.X = Math.Sign(x); CurrentHudElements[Length - 1].TextAlignment.Y = Math.Sign(y); } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "textsize": if (Arguments.Length == 1) { int s; if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out s)) { MessageBox.Show("SIZE is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { switch (s) { case 0: CurrentHudElements[Length - 1].Font = Fonts.VerySmallFont; break; case 1: CurrentHudElements[Length - 1].Font = Fonts.SmallFont; break; case 2: CurrentHudElements[Length - 1].Font = Fonts.NormalFont; break; case 3: CurrentHudElements[Length - 1].Font = Fonts.LargeFont; break; case 4: CurrentHudElements[Length - 1].Font = Fonts.VeryLargeFont; break; default: CurrentHudElements[Length - 1].Font = Fonts.NormalFont; break; } } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "textshadow": if (Arguments.Length == 1) { int s; if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out s)) { MessageBox.Show("SHADOW is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { CurrentHudElements[Length - 1].TextShadow = s != 0; } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "text": if (Arguments.Length == 1) { CurrentHudElements[Length - 1].Text = Arguments[0]; } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "value": if (Arguments.Length == 1) { int n; if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out n)) { MessageBox.Show("VALUE1 is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { CurrentHudElements[Length - 1].Value1 = n; } } else if (Arguments.Length == 2) { float a, b; if (!float.TryParse(Arguments[0], NumberStyles.Float, Culture, out a)) { MessageBox.Show("VALUE1 is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!float.TryParse(Arguments[1], NumberStyles.Float, Culture, out b)) { MessageBox.Show("VALUE2 is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { CurrentHudElements[Length - 1].Value1 = a; CurrentHudElements[Length - 1].Value2 = b; } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "transition": if (Arguments.Length == 1) { int n; if (!int.TryParse(Arguments[0], NumberStyles.Integer, Culture, out n)) { MessageBox.Show("TRANSITION is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { CurrentHudElements[Length - 1].Transition = (HUD.Transition)n; } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "transitionvector": if (Arguments.Length == 2) { float x, y; if (!float.TryParse(Arguments[0], NumberStyles.Float, Culture, out x)) { MessageBox.Show("X is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else if (!float.TryParse(Arguments[1], NumberStyles.Float, Culture, out y)) { MessageBox.Show("Y is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } else { CurrentHudElements[Length - 1].TransitionVector.X = x; CurrentHudElements[Length - 1].TransitionVector.Y = y; } } else { MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; default: MessageBox.Show("Invalid command encountered at line " + (i + 1).ToString(Culture) + " in " + File); break; } } else { MessageBox.Show("Invalid statement encountered at line " + (i + 1).ToString(Culture) + " in " + File); } } } } } } Array.Resize <Element>(ref CurrentHudElements, Length); }
private static void ApplyMeshBuilder(ref ObjectManager.StaticObject Object, MeshBuilder Builder, ObjectManager.ObjectLoadMode LoadMode, bool ForceTextureRepeatX, bool ForceTextureRepeatY) { if (Builder.Faces.Count != 0) { int mf = Object.Mesh.Faces.Length; int mm = Object.Mesh.Materials.Length; int mv = Object.Mesh.Vertices.Length; Array.Resize <World.MeshFace>(ref Object.Mesh.Faces, mf + Builder.Faces.Count); if (mm == 0) { if (Object.Mesh.Materials.Length == 0) { /* * If the object has no materials defined at all, we need to add one */ Array.Resize(ref Object.Mesh.Materials, 1); Object.Mesh.Materials[0] = new World.MeshMaterial(); Object.Mesh.Materials[0].Color = new Color32(255, 255, 255); Object.Mesh.Materials[0].Flags = (byte)(0 | 0); Object.Mesh.Materials[0].DaytimeTextureIndex = -1; Object.Mesh.Materials[0].NighttimeTextureIndex = -1; mm++; } } if (Builder.Materials.Length > 0) { Array.Resize <World.MeshMaterial>(ref Object.Mesh.Materials, mm + Builder.Materials.Length); } else { /* * If no materials have been defined for this face group, use the last material */ mm -= 1; } Array.Resize <VertexTemplate>(ref Object.Mesh.Vertices, mv + Builder.Vertices.Count); for (int i = 0; i < Builder.Vertices.Count; i++) { Object.Mesh.Vertices[mv + i] = new Vertex((Vertex)Builder.Vertices[i]); } for (int i = 0; i < Builder.Faces.Count; i++) { Object.Mesh.Faces[mf + i] = Builder.Faces[i]; for (int j = 0; j < Object.Mesh.Faces[mf + i].Vertices.Length; j++) { Object.Mesh.Faces[mf + i].Vertices[j].Index += (ushort)mv; } Object.Mesh.Faces[mf + i].Material += (ushort)mm; } for (int i = 0; i < Builder.Materials.Length; i++) { Object.Mesh.Materials[mm + i].Flags = (byte)((Builder.Materials[i].EmissiveColorUsed ? World.MeshMaterial.EmissiveColorMask : 0) | (Builder.Materials[i].TransparentColorUsed ? World.MeshMaterial.TransparentColorMask : 0)); Object.Mesh.Materials[mm + i].Color = Builder.Materials[i].Color; Object.Mesh.Materials[mm + i].TransparentColor = Builder.Materials[i].TransparentColor; TextureManager.TextureWrapMode WrapX, WrapY; if (ForceTextureRepeatX) { WrapX = TextureManager.TextureWrapMode.Repeat; } else { WrapX = TextureManager.TextureWrapMode.ClampToEdge; } if (ForceTextureRepeatY) { WrapY = TextureManager.TextureWrapMode.Repeat; } else { WrapY = TextureManager.TextureWrapMode.ClampToEdge; } if (WrapX != TextureManager.TextureWrapMode.Repeat | WrapY != TextureManager.TextureWrapMode.Repeat) { for (int j = 0; j < Builder.Vertices.Count; j++) { if (Builder.Vertices[j].TextureCoordinates.X <0.0 | Builder.Vertices[j].TextureCoordinates.X> 1.0) { WrapX = TextureManager.TextureWrapMode.Repeat; } if (Builder.Vertices[j].TextureCoordinates.Y <0.0 | Builder.Vertices[j].TextureCoordinates.Y> 1.0) { WrapY = TextureManager.TextureWrapMode.Repeat; } } } if (Builder.Materials[i].DaytimeTexture != null) { int tday = TextureManager.RegisterTexture(Builder.Materials[i].DaytimeTexture, Builder.Materials[i].TransparentColor, Builder.Materials[i].TransparentColorUsed ? (byte)1 : (byte)0, WrapX, WrapY, LoadMode != ObjectManager.ObjectLoadMode.Normal); Object.Mesh.Materials[mm + i].DaytimeTextureIndex = tday; } else { Object.Mesh.Materials[mm + i].DaytimeTextureIndex = -1; } Object.Mesh.Materials[mm + i].EmissiveColor = Builder.Materials[i].EmissiveColor; if (Builder.Materials[i].NighttimeTexture != null) { int tnight = TextureManager.RegisterTexture(Builder.Materials[i].NighttimeTexture, Builder.Materials[i].TransparentColor, Builder.Materials[i].TransparentColorUsed ? (byte)1 : (byte)0, WrapX, WrapY, LoadMode != ObjectManager.ObjectLoadMode.Normal); Object.Mesh.Materials[mm + i].NighttimeTextureIndex = tnight; } else { Object.Mesh.Materials[mm + i].NighttimeTextureIndex = -1; } Object.Mesh.Materials[mm + i].DaytimeNighttimeBlend = 0; Object.Mesh.Materials[mm + i].BlendMode = Builder.Materials[i].BlendMode; Object.Mesh.Materials[mm + i].GlowAttenuationData = Builder.Materials[i].GlowAttenuationData; } } }
internal void Apply(out StaticObject Object) { Object = new StaticObject(Program.CurrentHost) { Mesh = { Faces = new MeshFace[] { }, Materials = new MeshMaterial[] { }, Vertices = new VertexTemplate[] { } } }; if (faces.Count != 0) { int mf = Object.Mesh.Faces.Length; int mm = Object.Mesh.Materials.Length; int mv = Object.Mesh.Vertices.Length; Array.Resize(ref Object.Mesh.Faces, mf + faces.Count); Array.Resize(ref Object.Mesh.Materials, mm + materials.Count); Array.Resize(ref Object.Mesh.Vertices, mv + verticies.Count); for (int i = 0; i < verticies.Count; i++) { Object.Mesh.Vertices[mv + i] = new OpenBveApi.Objects.Vertex(verticies[i].Coordinates, verticies[i].TextureCoordinates); } for (int i = 0; i < faces.Count; i++) { Object.Mesh.Faces[i] = new MeshFace(faces[i].Vertices); Object.Mesh.Faces[i].Material = (ushort)faces[i].Material; for (int k = 0; k < faces[i].Vertices.Length; k++) { Object.Mesh.Faces[i].Vertices[k].Normal = verticies[faces[i].Vertices[k]].Normal; } for (int j = 0; j < Object.Mesh.Faces[mf + i].Vertices.Length; j++) { Object.Mesh.Faces[mf + i].Vertices[j].Index += (ushort)mv; } Object.Mesh.Faces[mf + i].Material += (ushort)mm; } for (int i = 0; i < materials.Count; i++) { Object.Mesh.Materials[mm + i].Flags = 0; Object.Mesh.Materials[mm + i].Color = materials[i].Color; Object.Mesh.Materials[mm + i].TransparentColor = Color24.Black; Object.Mesh.Materials[mm + i].BlendMode = MeshMaterialBlendMode.Normal; if (materials[i].DaytimeTexture != null) { OpenBveApi.Textures.Texture tday; TextureManager.RegisterTexture(materials[i].DaytimeTexture, out tday); Object.Mesh.Materials[mm + i].DaytimeTexture = tday; } else { Object.Mesh.Materials[mm + i].DaytimeTexture = null; } Object.Mesh.Materials[mm + i].EmissiveColor = materials[i].EmissiveColor; Object.Mesh.Materials[mm + i].NighttimeTexture = null; Object.Mesh.Materials[mm + i].DaytimeNighttimeBlend = 0; Object.Mesh.Materials[mm + i].GlowAttenuationData = materials[i].GlowAttenuationData; Object.Mesh.Materials[mm + i].WrapMode = materials[i].WrapMode; } } }
private static void ApplyMeshBuilder(ref ObjectManager.StaticObject Object, MeshBuilder Builder, ObjectManager.ObjectLoadMode LoadMode, bool ForceTextureRepeatX, bool ForceTextureRepeatY) { if (Builder.Faces.Length != 0) { int mf = Object.Mesh.Faces.Length; int mm = Object.Mesh.Materials.Length; int mv = Object.Mesh.Vertices.Length; Array.Resize <World.MeshFace>(ref Object.Mesh.Faces, mf + Builder.Faces.Length); Array.Resize <World.MeshMaterial>(ref Object.Mesh.Materials, mm + Builder.Materials.Length); Array.Resize <World.Vertex>(ref Object.Mesh.Vertices, mv + Builder.Vertices.Length); for (int i = 0; i < Builder.Vertices.Length; i++) { Object.Mesh.Vertices[mv + i] = Builder.Vertices[i]; } for (int i = 0; i < Builder.Faces.Length; i++) { Object.Mesh.Faces[mf + i] = Builder.Faces[i]; for (int j = 0; j < Object.Mesh.Faces[mf + i].Vertices.Length; j++) { Object.Mesh.Faces[mf + i].Vertices[j].Index += (ushort)mv; } Object.Mesh.Faces[mf + i].Material += (ushort)mm; } for (int i = 0; i < Builder.Materials.Length; i++) { Object.Mesh.Materials[mm + i].Flags = (byte)((Builder.Materials[i].EmissiveColorUsed ? World.MeshMaterial.EmissiveColorMask : 0) | (Builder.Materials[i].TransparentColorUsed ? World.MeshMaterial.TransparentColorMask : 0)); Object.Mesh.Materials[mm + i].Color = Builder.Materials[i].Color; Object.Mesh.Materials[mm + i].TransparentColor = Builder.Materials[i].TransparentColor; TextureManager.TextureWrapMode WrapX, WrapY; if (ForceTextureRepeatX) { WrapX = TextureManager.TextureWrapMode.Repeat; } else { WrapX = TextureManager.TextureWrapMode.ClampToEdge; } if (ForceTextureRepeatY) { WrapY = TextureManager.TextureWrapMode.Repeat; } else { WrapY = TextureManager.TextureWrapMode.ClampToEdge; } if (WrapX != TextureManager.TextureWrapMode.Repeat | WrapY != TextureManager.TextureWrapMode.Repeat) { for (int j = 0; j < Builder.Vertices.Length; j++) { if (Builder.Vertices[j].TextureCoordinates.X <0.0 | Builder.Vertices[j].TextureCoordinates.X> 1.0) { WrapX = TextureManager.TextureWrapMode.Repeat; } if (Builder.Vertices[j].TextureCoordinates.Y <0.0 | Builder.Vertices[j].TextureCoordinates.Y> 1.0) { WrapY = TextureManager.TextureWrapMode.Repeat; } } } if (Builder.Materials[i].DaytimeTexture != null) { int tday; if (!string.IsNullOrEmpty(Builder.Materials[i].TransparencyTexture)) { Bitmap Main = new Bitmap(Builder.Materials[i].DaytimeTexture); Main = ResizeImage(Main, Main.Size.Width, Main.Size.Height); Bitmap Alpha = new Bitmap(Builder.Materials[i].TransparencyTexture); if (Alpha.Size != Main.Size) { Alpha = ResizeImage(Alpha, Main.Size.Width, Main.Size.Height); } Bitmap texture = MergeAlphaBitmap(Main, Alpha); //Dispose of main and alpha Main.Dispose(); Alpha.Dispose(); tday = TextureManager.RegisterTexture(texture, true); } else { tday = TextureManager.RegisterTexture(Builder.Materials[i].DaytimeTexture, Builder.Materials[i].TransparentColor, Builder.Materials[i].TransparentColorUsed ? (byte)1 : (byte)0, WrapX, WrapY, LoadMode != ObjectManager.ObjectLoadMode.Normal); } Object.Mesh.Materials[mm + i].DaytimeTextureIndex = tday; } else { Object.Mesh.Materials[mm + i].DaytimeTextureIndex = -1; } Object.Mesh.Materials[mm + i].EmissiveColor = Builder.Materials[i].EmissiveColor; if (Builder.Materials[i].NighttimeTexture != null) { int tnight = TextureManager.RegisterTexture(Builder.Materials[i].NighttimeTexture, Builder.Materials[i].TransparentColor, Builder.Materials[i].TransparentColorUsed ? (byte)1 : (byte)0, WrapX, WrapY, LoadMode != ObjectManager.ObjectLoadMode.Normal); Object.Mesh.Materials[mm + i].NighttimeTextureIndex = tnight; } else { Object.Mesh.Materials[mm + i].NighttimeTextureIndex = -1; } Object.Mesh.Materials[mm + i].DaytimeNighttimeBlend = 0; Object.Mesh.Materials[mm + i].BlendMode = Builder.Materials[i].BlendMode; Object.Mesh.Materials[mm + i].GlowAttenuationData = Builder.Materials[i].GlowAttenuationData; } } }
// // SET CUSTOM LOADING SCREEN BACKGROUND // /// <summary>Sets the loading screen background to a custom image</summary> internal static void SetLoadingBkg(string fileName) { TextureLoadingBkg = TextureManager.RegisterTexture(fileName, TextureManager.TextureWrapMode.ClampToEdge, TextureManager.TextureWrapMode.ClampToEdge, false); TextureManager.UseTexture(TextureLoadingBkg, TextureManager.UseMode.LoadImmediately); customLoadScreen = true; }
internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) { double speedModified = (ShiftPressed ? 2.0 : 1.0) * (ControlPressed ? 4.0 : 1.0) * (AltPressed ? 8.0 : 1.0); switch (e.Key) { case Key.ShiftLeft: case Key.ShiftRight: ShiftPressed = true; break; case Key.ControlLeft: case Key.ControlRight: ControlPressed = true; break; case Key.LAlt: case Key.RAlt: AltPressed = true; break; case Key.F5: if (CurrentRoute != null && CurrentlyLoading == false) { CurrentlyLoading = true; Renderer.OptionInterface = false; if (!Interface.CurrentOptions.LoadingBackground) { Renderer.RenderScene(0.0); currentGameWindow.SwapBuffers(); Bitmap bitmap = new Bitmap(Renderer.ScreenWidth, Renderer.ScreenHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); BitmapData bData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); GL.ReadPixels(0, 0, Renderer.ScreenWidth, Renderer.ScreenHeight, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bData.Scan0); bitmap.UnlockBits(bData); bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); Renderer.TextureLoadingBkg = TextureManager.RegisterTexture(bitmap, false); bitmap.Dispose(); } World.CameraAlignment a = World.CameraCurrentAlignment; if (LoadRoute()) { World.CameraCurrentAlignment = a; TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, -1.0, true, false); TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, a.TrackPosition, true, false); World.CameraAlignmentDirection = new World.CameraAlignment(); World.CameraAlignmentSpeed = new World.CameraAlignment(); ObjectManager.UpdateVisibility(a.TrackPosition, true); ObjectManager.UpdateAnimatedWorldObjects(0.0, true); } CurrentlyLoading = false; Renderer.OptionInterface = true; TextureManager.UnregisterTexture(ref Renderer.TextureLoadingBkg); } break; case Key.F7: if (CurrentlyLoading == true) { break; } OpenFileDialog Dialog = new OpenFileDialog(); Dialog.CheckFileExists = true; Dialog.Filter = "CSV/RW files|*.csv;*.rw|All files|*"; if (Dialog.ShowDialog() == DialogResult.OK) { Application.DoEvents(); CurrentlyLoading = true; CurrentRoute = Dialog.FileName; LoadRoute(); ObjectManager.UpdateAnimatedWorldObjects(0.0, true); CurrentlyLoading = false; UpdateCaption(); } else { if (Program.CurrentlyRunOnMono) { //HACK: Dialog doesn't close properly when pressing the ESC key under Mono //Avoid calling Application.DoEvents() unless absolutely necessary though! Application.DoEvents(); } } Dialog.Dispose(); break; case Key.F8: if (Program.CurrentlyLoading == true) { //Don't allow the user to update the settings during loading, bad idea.... break; } if (formOptions.ShowOptions() == DialogResult.OK) { UpdateGraphicsSettings(); } Application.DoEvents(); break; case Key.F9: if (Interface.MessageCount != 0) { formMessages.ShowMessages(); Application.DoEvents(); } break; case Key.F10: Renderer.RenderStatsOverlay = !Renderer.RenderStatsOverlay; break; case Key.A: case Key.Keypad4: World.CameraAlignmentDirection.Position.X = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.D: case Key.Keypad6: World.CameraAlignmentDirection.Position.X = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad2: World.CameraAlignmentDirection.Position.Y = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad8: World.CameraAlignmentDirection.Position.Y = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.W: case Key.Keypad9: World.CameraAlignmentDirection.TrackPosition = World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.S: case Key.Keypad3: World.CameraAlignmentDirection.TrackPosition = -World.CameraExteriorTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Left: World.CameraAlignmentDirection.Yaw = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Right: World.CameraAlignmentDirection.Yaw = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Up: World.CameraAlignmentDirection.Pitch = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Down: World.CameraAlignmentDirection.Pitch = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.KeypadDivide: World.CameraAlignmentDirection.Roll = -World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.KeypadMultiply: World.CameraAlignmentDirection.Roll = World.CameraExteriorTopAngularSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad0: World.CameraAlignmentDirection.Zoom = World.CameraZoomTopSpeed * speedModified; CpuReducedMode = false; break; case Key.KeypadPeriod: World.CameraAlignmentDirection.Zoom = -World.CameraZoomTopSpeed * speedModified; CpuReducedMode = false; break; case Key.Keypad1: Game.ApplyPointOfInterest(-1, true); CpuReducedMode = false; break; case Key.Keypad7: Game.ApplyPointOfInterest(1, true); CpuReducedMode = false; break; case Key.PageUp: JumpToStation(1); CpuReducedMode = false; break; case Key.PageDown: JumpToStation(-1); CpuReducedMode = false; break; case Key.Keypad5: World.CameraCurrentAlignment.Yaw = 0.0; World.CameraCurrentAlignment.Pitch = 0.0; World.CameraCurrentAlignment.Roll = 0.0; World.CameraCurrentAlignment.Position = new Vector3(0.0, 2.5, 0.0); World.CameraCurrentAlignment.Zoom = 0.0; World.CameraAlignmentDirection = new World.CameraAlignment(); World.CameraAlignmentSpeed = new World.CameraAlignment(); World.VerticalViewingAngle = World.OriginalVerticalViewingAngle; UpdateViewport(); World.UpdateAbsoluteCamera(0.0); World.UpdateViewingDistances(); CpuReducedMode = false; break; case Key.F: Renderer.OptionWireframe = !Renderer.OptionWireframe; CpuReducedMode = false; if (Renderer.OptionWireframe) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } else { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } break; case Key.N: Renderer.OptionNormals = !Renderer.OptionNormals; CpuReducedMode = false; break; case Key.E: Renderer.OptionEvents = !Renderer.OptionEvents; CpuReducedMode = false; break; case Key.C: CpuAutomaticMode = !CpuAutomaticMode; CpuReducedMode = false; break; case Key.I: Renderer.OptionInterface = !Renderer.OptionInterface; CpuReducedMode = false; break; case Key.M: //SoundManager.Mute = !SoundManager.Mute; break; case Key.Plus: case Key.KeypadPlus: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "+"; CpuReducedMode = false; } break; case Key.Minus: case Key.KeypadMinus: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "-"; CpuReducedMode = false; } break; case Key.Number0: case Key.Number1: case Key.Number2: case Key.Number3: case Key.Number4: case Key.Number5: case Key.Number6: case Key.Number7: case Key.Number8: case Key.Number9: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = string.Empty; } JumpToPositionValue += char.ConvertFromUtf32(48 + e.Key - Key.Number0); CpuReducedMode = false; break; case Key.Period: if (!JumpToPositionEnabled) { JumpToPositionEnabled = true; JumpToPositionValue = "0."; } else if (JumpToPositionValue.IndexOf('.') == -1) { JumpToPositionValue += "."; } CpuReducedMode = false; break; case Key.BackSpace: if (JumpToPositionEnabled && JumpToPositionValue.Length != 0) { JumpToPositionValue = JumpToPositionValue.Substring(0, JumpToPositionValue.Length - 1); CpuReducedMode = false; } break; case Key.Enter: if (JumpToPositionEnabled) { if (JumpToPositionValue.Length != 0) { int direction; if (JumpToPositionValue[0] == '-') { JumpToPositionValue = JumpToPositionValue.Substring(1); direction = -1; } else if (JumpToPositionValue[0] == '+') { JumpToPositionValue = JumpToPositionValue.Substring(1); direction = 1; } else { direction = 0; } double value; if (double.TryParse(JumpToPositionValue, NumberStyles.Float, CultureInfo.InvariantCulture, out value)) { if (value < TrackManager.CurrentTrack.Elements[TrackManager.CurrentTrack.Elements.Length - 1].StartingTrackPosition + 100 && value > MinimumJumpToPositionValue - 100) { if (direction != 0) { value = World.CameraTrackFollower.TrackPosition + (double)direction * value; } TrackManager.UpdateTrackFollower(ref World.CameraTrackFollower, value, true, false); World.CameraCurrentAlignment.TrackPosition = value; World.UpdateAbsoluteCamera(0.0); World.UpdateViewingDistances(); } } } } JumpToPositionEnabled = false; CpuReducedMode = false; break; case Key.Escape: JumpToPositionEnabled = false; CpuReducedMode = false; break; } }
/// <summary>Registers a texture and returns a handle to the texture.</summary> /// <param name="texture">The texture data.</param> /// <param name="parameters">The parameters that specify how to process the texture.</param> /// <param name="handle">Receives the handle to the texture.</param> /// <returns>Whether loading the texture was successful.</returns> public override bool RegisterTexture(Texture texture, TextureParameters parameters, out Texture handle) { texture = texture.ApplyParameters(parameters); handle = TextureManager.RegisterTexture(texture); return(true); }
/// <summary>Renders the timetable data</summary> /// <param name="timetableTexture">The texture to create</param> internal void RenderData(ref Texture timetableTexture) { // prepare timetable int w = 384, h = 192; int offsetx = 0; int actualheight = h; float descriptionwidth = 256; float descriptionheight = 16; float stationnamewidth = 16; for (int k = 0; k < 2; k++) { Bitmap b = new Bitmap(w, h); Graphics g = Graphics.FromImage(b); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; g.Clear(Color.Transparent); g.FillRectangle(Brushes.White, new RectangleF(offsetx, 0, w, actualheight)); Font f = new Font(FontFamily.GenericSansSerif, 13.0f, GraphicsUnit.Pixel); Font fs = new Font(FontFamily.GenericSansSerif, 11.0f, GraphicsUnit.Pixel); Font fss = new Font(FontFamily.GenericSansSerif, 9.0f, GraphicsUnit.Pixel); // draw timetable string t; // description float x0 = offsetx + 8; float y0 = 8; if (k == 1) { t = DefaultTimetableDescription; g.DrawString(t, f, Brushes.Black, new RectangleF(x0, 6, descriptionwidth, descriptionheight + 8)); y0 += descriptionheight + 2; } // highest speed t = Translations.GetInterfaceString("timetable_highestspeed"); SizeF s = g.MeasureString(t, fs); g.DrawString(t, fs, Brushes.Black, x0, y0); float y0a = y0 + s.Height + 2; float x1 = x0 + s.Width + 4; for (int i = 0; i < Tracks.Length; i++) { float y = y0a + 18 * i; t = Tracks[i].Speed; g.DrawString(t, f, Brushes.Black, x0, y); s = g.MeasureString(t, f); float x = x0 + s.Width + 4; if (x > x1) { x1 = x; } } g.DrawLine(Pens.LightGray, new PointF(x1 - 2, 4 + descriptionheight), new PointF(x1 - 2, y0a + 18 * Tracks.Length - 1)); // driving time t = Translations.GetInterfaceString("timetable_drivingtime"); s = g.MeasureString(t, fs); g.DrawString(t, fs, Brushes.Black, x1, y0); float x2 = x1 + s.Width + 4; for (int i = 0; i < Tracks.Length; i++) { float y = y0a + 18 * i; if (Tracks[i].Time.Hour.Length != 0) { t = Tracks[i].Time.Hour; g.DrawString(t, fss, Brushes.Black, x1, y + 2); } else { t = "0"; } s = g.MeasureString(t, fss, 9999, StringFormat.GenericTypographic); float x = x1 + s.Width - 1; if (Tracks[i].Time.Minute.Length != 0) { t = Tracks[i].Time.Minute; g.DrawString(t, fs, Brushes.Black, x, y + 2); } else { t = "00:"; } s = g.MeasureString(t, fs, 9999, StringFormat.GenericTypographic); x += s.Width + 1; t = Tracks[i].Time.Second; g.DrawString(t, fss, Brushes.Black, x, y + 2); s = g.MeasureString(t, fss, 9999, StringFormat.GenericTypographic); x += s.Width + 8; if (x > x2) { x2 = x; } } for (int i = 0; i < Tracks.Length; i++) { float y = y0a + 18 * i; g.DrawLine(Pens.LightGray, new PointF(offsetx + 4, y - 1), new PointF(x2 - 2, y - 1)); } g.DrawLine(Pens.LightGray, new PointF(x2 - 2, 4 + descriptionheight), new PointF(x2 - 2, y0a + 18 * Tracks.Length - 1)); // station name float y2 = y0; t = Translations.GetInterfaceString("timetable_stationname"); s = g.MeasureString(t, f); g.DrawString(t, f, Brushes.Black, x2, y2); float x3 = x2 + s.Width + 4; for (int i = 0; i < Stations.Length; i++) { float y = y0 + 18 * (i + 1) + 2; g.DrawLine(Pens.LightGray, new PointF(x2 - 2, y - 1), new PointF(w - 4, y - 1)); t = Stations[i].Name; if (Stations[i].NameJapanese & Stations[i].Name.Length > 1) { float[] sizes = new float[t.Length]; float totalsize = 0.0f; for (int j = 0; j < t.Length; j++) { sizes[j] = g.MeasureString(new string(t[j], 1), f, 9999, StringFormat.GenericTypographic).Width; totalsize += sizes[j]; } float space = (stationnamewidth - totalsize) / (float)(t.Length - 1); float x = 0.0f; for (int j = 0; j < t.Length; j++) { g.DrawString(new string(t[j], 1), f, Brushes.Black, x2 + x, y); x += sizes[j] + space; } } else { g.DrawString(t, f, Brushes.Black, x2, y); } s = g.MeasureString(t, f); { float x = x2 + s.Width + 4; if (x > x3) { x3 = x; } } } g.DrawLine(Pens.LightGray, new PointF(x3 - 2, 4 + descriptionheight), new PointF(x3 - 2, y0 + 18 * (Stations.Length + 1))); if (k == 0) { stationnamewidth = x3 - x2 - 6; } // arrival time t = Translations.GetInterfaceString("timetable_arrivaltime"); s = g.MeasureString(t, f); g.DrawString(t, f, Brushes.Black, x3, y2); float x4 = x3 + s.Width + 4; for (int i = 0; i < Stations.Length; i++) { float y = y0 + 18 * (i + 1) + 2; if (Stations[i].Pass) { t = "00"; s = g.MeasureString(t, fs); float x = x3 + s.Width; t = " ↓"; g.DrawString(t, f, Brushes.Black, x, y); s = g.MeasureString(t, f); x += +s.Width + 4; if (x > x4) { x4 = x; } } else { if (Stations[i].Arrival.Hour.Length != 0) { t = Stations[i].Arrival.Hour; g.DrawString(t, fs, Brushes.Black, x3, y); } else { t = "00"; } s = g.MeasureString(t, fs); float x = x3 + s.Width; if (Stations[i].Arrival.Minute.Length != 0 & Stations[i].Arrival.Second.Length != 0) { t = Stations[i].Arrival.Minute + ":" + Stations[i].Arrival.Second; } else { t = ""; } g.DrawString(t, f, Brushes.Black, x, y); s = g.MeasureString(t, f); x += s.Width + 4; if (x > x4) { x4 = x; } } } g.DrawLine(Pens.LightGray, new PointF(x4 - 2, 4 + descriptionheight), new PointF(x4 - 2, y0 + 18 * (Stations.Length + 1))); // departure time t = Translations.GetInterfaceString("timetable_departuretime"); s = g.MeasureString(t, f); g.DrawString(t, f, Brushes.Black, x4, y2); float x5 = x4 + s.Width + 4; for (int i = 0; i < Stations.Length; i++) { float y = y0 + 18 * (i + 1) + 2; if (Stations[i].Terminal) { t = "00"; s = g.MeasureString(t, fs); float x = x4 + s.Width; const float c0 = 4; const float c1 = 32; g.DrawLine(Pens.Black, new PointF(x + c0, y + 6), new PointF(x + c1, y + 6)); g.DrawLine(Pens.Black, new PointF(x + c0, y + 10), new PointF(x + c1, y + 10)); x += c1 + 4; if (x > x5) { x5 = x; } } else { if (Stations[i].Departure.Hour.Length != 0) { t = Stations[i].Departure.Hour; g.DrawString(t, fs, Brushes.Black, x4, y); } else { t = "00"; } s = g.MeasureString(t, fs); float x = x4 + s.Width; if (Stations[i].Departure.Minute.Length != 0 & Stations[i].Departure.Second.Length != 0) { t = Stations[i].Departure.Minute + ":" + Stations[i].Departure.Second; } else { t = ""; } g.DrawString(t, f, Brushes.Black, x, y); s = g.MeasureString(t, f); x += s.Width + 4; if (x > x5) { x5 = x; } } } for (int i = 0; i < Stations.Length; i++) { float y = y0 + 18 * (i + 1) + 2; g.DrawLine(Pens.LightGray, new PointF(x2 - 2, y - 1), new PointF(w - 4, y - 1)); } // border if (k == 1) { g.DrawLine(Pens.Black, new PointF(offsetx + 4, 4), new PointF(offsetx + 4, y0a + 18 * Tracks.Length - 1)); g.DrawLine(Pens.Black, new PointF(offsetx + 4, y0a + 18 * Tracks.Length - 1), new PointF(x2 - 2, y0a + 18 * Tracks.Length - 1)); g.DrawLine(Pens.Black, new PointF(offsetx + 4, 4), new PointF(w - 4, 4)); g.DrawLine(Pens.Black, new PointF(offsetx + 4, 4 + descriptionheight), new PointF(w - 4, 4 + descriptionheight)); g.DrawLine(Pens.Black, new PointF(x2 - 2, y0 + 18 * (Stations.Length + 1)), new PointF(w - 4, y0 + 18 * (Stations.Length + 1))); g.DrawLine(Pens.Black, new PointF(w - 4, 4), new PointF(w - 4, y0 + 18 * (Stations.Length + 1))); g.DrawLine(Pens.Black, new PointF(x2 - 2, y0a + 18 * Tracks.Length - 1), new PointF(x2 - 2, y0 + 18 * (Stations.Length + 1))); } // measure w = (int)Math.Ceiling((double)(x5 + 1)); h = (int)Math.Ceiling((double)(y0 + 18 * (Stations.Length + 1) + 4)); // description if (k == 0) { t = DefaultTimetableDescription; s = g.MeasureString(t, f, w - 16); descriptionwidth = s.Width; descriptionheight = s.Height + 2; h += (int)Math.Ceiling((double)s.Height) + 4; } // finish if (k == 0) { // measures int nw = TextureManager.RoundUpToPowerOfTwo(w); offsetx = nw - w; w = nw; actualheight = h; h = TextureManager.RoundUpToPowerOfTwo(h); } else { // create texture g.Dispose(); timetableTexture = TextureManager.RegisterTexture(b); } } }
// --- constructors --- /// <summary>Creates a new table of characters.</summary> /// <param name="font">The font.</param> /// <param name="offset">The offset from codepoint U+0000.</param> internal OpenGlFontTable(Font font, int offset) { /* * Measure characters. * */ Size[] physicalSizes = new Size[256]; Size[] typographicSizes = new Size[256]; Bitmap bitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bitmap); graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; for (int i = 0; i < 256; i++) { SizeF physicalSize = graphics.MeasureString(char.ConvertFromUtf32(offset + i), font, int.MaxValue, StringFormat.GenericDefault); SizeF typographicSize = graphics.MeasureString(char.ConvertFromUtf32(offset + i), font, int.MaxValue, StringFormat.GenericTypographic); physicalSizes[i] = new Size((int)Math.Ceiling(physicalSize.Width), (int)Math.Ceiling(physicalSize.Height)); typographicSizes[i] = new Size((int)Math.Ceiling(typographicSize.Width == 0.0f ? physicalSize.Width : typographicSize.Width), (int)Math.Ceiling(typographicSize.Height == 0.0f ? physicalSize.Height : typographicSize.Height)); } /* * Find suitable bitmap dimensions. * */ const int width = 256; const int border = 1; int x = border; int y = border; int lineHeight = 0; for (int i = 0; i < 256; i++) { if (x + physicalSizes[i].Width + border > width) { x = border; y += lineHeight; lineHeight = 0; } else { x += physicalSizes[i].Width + 2 * border; } if (physicalSizes[i].Height + border > lineHeight) { lineHeight = physicalSizes[i].Height + 2 * border; } } y += lineHeight; int height = (int)RoundToPowerOfTwo((uint)y); graphics.Dispose(); bitmap.Dispose(); /* * Draw character to bitmap. * */ bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); graphics = Graphics.FromImage(bitmap); graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; graphics.Clear(Color.Black); x = border; y = border; lineHeight = 0; this.Characters = new OpenGlFontChar[256]; for (int i = 0; i < 256; i++) { if (x + physicalSizes[i].Width + border > width) { x = border; y += lineHeight; lineHeight = 0; } graphics.DrawString(char.ConvertFromUtf32(offset + i), font, Brushes.White, new PointF(x, y)); float x0 = (float)(x - border) / (float)width; float x1 = (float)(x + physicalSizes[i].Width + border) / (float)width; float y0 = (float)(y - border) / (float)height; float y1 = (float)(y + physicalSizes[i].Height + border) / (float)height; this.Characters[i] = new OpenGlFontChar(new RectangleF(x0, y0, x1 - x0, y1 - y0), new Size(physicalSizes[i].Width + 2 * border, physicalSizes[i].Height + 2 * border), typographicSizes[i]); x += physicalSizes[i].Width + 2 * border; if (physicalSizes[i].Height + border > lineHeight) { lineHeight = physicalSizes[i].Height + 2 * border; } } graphics.Dispose(); this.Texture = TextureManager.RegisterTexture(bitmap, false); }
private static void ApplyMeshBuilder(ref ObjectManager.StaticObject Object, MeshBuilder Builder, ObjectManager.ObjectLoadMode LoadMode, bool ForceTextureRepeatX, bool ForceTextureRepeatY) { if (Builder.Faces.Length != 0) { int mf = Object.Mesh.Faces.Length; int mm = Object.Mesh.Materials.Length; int mv = Object.Mesh.Vertices.Length; Array.Resize <World.MeshFace>(ref Object.Mesh.Faces, mf + Builder.Faces.Length); Array.Resize <World.MeshMaterial>(ref Object.Mesh.Materials, mm + Builder.Materials.Length); Array.Resize <World.Vertex>(ref Object.Mesh.Vertices, mv + Builder.Vertices.Length); for (int i = 0; i < Builder.Vertices.Length; i++) { Object.Mesh.Vertices[mv + i] = Builder.Vertices[i]; } for (int i = 0; i < Builder.Faces.Length; i++) { Object.Mesh.Faces[mf + i] = Builder.Faces[i]; for (int j = 0; j < Object.Mesh.Faces[mf + i].Vertices.Length; j++) { Object.Mesh.Faces[mf + i].Vertices[j].Index += (ushort)mv; } Object.Mesh.Faces[mf + i].Material += (ushort)mm; } for (int i = 0; i < Builder.Materials.Length; i++) { Object.Mesh.Materials[mm + i].Flags = (byte)((Builder.Materials[i].EmissiveColorUsed ? World.MeshMaterial.EmissiveColorMask : 0) | (Builder.Materials[i].TransparentColorUsed ? World.MeshMaterial.TransparentColorMask : 0)); Object.Mesh.Materials[mm + i].Color = Builder.Materials[i].Color; Object.Mesh.Materials[mm + i].TransparentColor = Builder.Materials[i].TransparentColor; TextureManager.TextureWrapMode WrapX, WrapY; if (ForceTextureRepeatX) { WrapX = TextureManager.TextureWrapMode.Repeat; } else { WrapX = TextureManager.TextureWrapMode.ClampToEdge; } if (ForceTextureRepeatY) { WrapY = TextureManager.TextureWrapMode.Repeat; } else { WrapY = TextureManager.TextureWrapMode.ClampToEdge; } if (WrapX != TextureManager.TextureWrapMode.Repeat | WrapY != TextureManager.TextureWrapMode.Repeat) { for (int j = 0; j < Builder.Vertices.Length; j++) { if (Builder.Vertices[j].TextureCoordinates.X <0.0 | Builder.Vertices[j].TextureCoordinates.X> 1.0) { WrapX = TextureManager.TextureWrapMode.Repeat; } if (Builder.Vertices[j].TextureCoordinates.Y <0.0 | Builder.Vertices[j].TextureCoordinates.Y> 1.0) { WrapY = TextureManager.TextureWrapMode.Repeat; } } } if (Builder.Materials[i].DaytimeTexture != null) { int tday = TextureManager.RegisterTexture(Builder.Materials[i].DaytimeTexture, Builder.Materials[i].TransparentColor, Builder.Materials[i].TransparentColorUsed ? (byte)1 : (byte)0, WrapX, WrapY, LoadMode != ObjectManager.ObjectLoadMode.Normal); Object.Mesh.Materials[mm + i].DaytimeTextureIndex = tday; } else { Object.Mesh.Materials[mm + i].DaytimeTextureIndex = -1; } Object.Mesh.Materials[mm + i].EmissiveColor = Builder.Materials[i].EmissiveColor; if (Builder.Materials[i].NighttimeTexture != null) { int tnight = TextureManager.RegisterTexture(Builder.Materials[i].NighttimeTexture, Builder.Materials[i].TransparentColor, Builder.Materials[i].TransparentColorUsed ? (byte)1 : (byte)0, WrapX, WrapY, LoadMode != ObjectManager.ObjectLoadMode.Normal); Object.Mesh.Materials[mm + i].NighttimeTextureIndex = tnight; } else { Object.Mesh.Materials[mm + i].NighttimeTextureIndex = -1; } Object.Mesh.Materials[mm + i].DaytimeNighttimeBlend = 0; Object.Mesh.Materials[mm + i].BlendMode = Builder.Materials[i].BlendMode; Object.Mesh.Materials[mm + i].GlowAttenuationData = Builder.Materials[i].GlowAttenuationData; } } }