/******************** * MENU SYSTEM METHODS *********************/ // // INITIALIZE THE MENU SYSTEM // private void Init() { Reset(); // choose the text font size according to screen height // the boundaries follow approximately the progression // of font sizes defined in Graphics/Fonts.cs if (Screen.Height <= 512) { menuFont = Fonts.SmallFont; } else if (Screen.Height <= 680) { menuFont = Fonts.NormalFont; } else if (Screen.Height <= 890) { menuFont = Fonts.LargeFont; } else if (Screen.Height <= 1150) { menuFont = Fonts.VeryLargeFont; } else { menuFont = Fonts.EvenLargerFont; } em = (int)menuFont.FontSize; lineHeight = (int)(em * LineSpacing); isInitialized = true; }
internal override void AddMessage() { //HACK: No way of changing this at the minute.... Font = Fonts.SmallFont; QueueForRemoval = false; MessageToDisplay = InternalText; }
/// <summary>Creates a general textual message</summary> internal GeneralMessage() { this.Timeout = double.PositiveInfinity; this.TriggerOnce = true; this.Direction = MessageDirection.Forwards; this.MessageColor = MessageColor.White; this.MessageEarlyColor = MessageColor.White; this.MessageLateColor = MessageColor.White; this.Font = Fonts.SmallFont; }
/// <summary>Renders a string to the screen.</summary> /// <param name="font">The font to use.</param> /// <param name="text">The string to render.</param> /// <param name="location">The location.</param> /// <param name="alignment">The alignment.</param> /// <param name="color">The color.</param> /// <param name="shadow">Whether to draw a shadow.</param> /// <remarks>This function sets the OpenGL blend function to glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA).</remarks> internal static void DrawString(Fonts.OpenGlFont font, string text, Point location, TextAlignment alignment, Color128 color, bool shadow) { if (shadow) { DrawString(font, text, new Point(location.X - 1, location.Y + 1), alignment, new Color128(0.0f, 0.0f, 0.0f, 0.5f * color.A)); DrawString(font, text, location, alignment, color); } else { DrawString(font, text, location, alignment, color); } }
internal Element() { this.Subject = null; this.Position = new Vector2(); this.Alignment = new Vector2(-1, -1); this.BackgroundColor = new Color32(255, 255, 255, 255); this.OverlayColor = new Color32(255, 255, 255, 255); this.TextColor = new Color32(255, 255, 255, 255); this.TextPosition = new Vector2(); this.TextAlignment = new Vector2(-1, 0); this.Font = Fonts.VerySmallFont; this.TextShadow = true; this.Text = null; this.Value1 = 0.0f; this.Value2 = 0.0f; this.Transition = Transition.None; this.TransitionState = 1.0; }
// --- functions --- /// <summary>Measures the size of a string as it would be rendered using the specified font.</summary> /// <param name="font">The font to use.</param> /// <param name="text">The string to render.</param> /// <returns>The size of the string.</returns> internal static Size MeasureString(Fonts.OpenGlFont font, string text) { int width = 0; int height = 0; if (text != null && font != null) { for (int i = 0; i < text.Length; i++) { Textures.Texture texture; Fonts.OpenGlFontChar data; i += font.GetCharacterData(text, i, out texture, out data) - 1; width += data.TypographicSize.Width; if (data.TypographicSize.Height > height) { height = data.TypographicSize.Height; } } } return(new Size(width, height)); }
internal HudElement() { this.Subject = null; this.Position.X = 0.0f; this.Position.Y = 0.0f; this.Alignment.X = -1; this.Alignment.Y = -1; this.BackgroundColor = new Color32(255, 255, 255, 255); this.OverlayColor = new Color32(255, 255, 255, 255); this.TextColor = new Color32(255, 255, 255, 255); this.TextPosition.X = 0.0f; this.TextPosition.Y = 0.0f; this.TextAlignment.X = -1; this.TextAlignment.Y = 0; this.Font = Fonts.VerySmallFont; this.TextShadow = true; this.Text = null; this.Value1 = 0.0f; this.Value2 = 0.0f; this.Transition = HudTransition.None; this.TransitionState = 1.0; }
/******************** * MENU SYSTEM METHODS *********************/ // // INITIALIZE THE MENU SYSTEM // private void Init() { Reset(); // choose the text font size according to screen height // the boundaries follow approximately the progression // of font sizes defined in Graphics/Fonts.cs if (Screen.Height <= 512) { menuFont = Fonts.SmallFont; } else if (Screen.Height <= 680) { menuFont = Fonts.NormalFont; } else if (Screen.Height <= 890) { menuFont = Fonts.LargeFont; } else if (Screen.Height <= 1150) { menuFont = Fonts.VeryLargeFont; } else { menuFont = Fonts.EvenLargerFont; } em = (int)menuFont.FontSize; lineHeight = (int)(em * LineSpacing); for (int i = 0; i < Interface.CurrentControls.Length; i++) { //Find the current menu back key- It's unlikely that we want to set a new key to this if (Interface.CurrentControls[i].Command == Translations.Command.MenuBack) { MenuBackKey = Interface.CurrentControls[i].Key; break; } } isInitialized = true; }
internal Lamp(LampType Type) { this.Type = Type; switch (Type) { case LampType.None: this.Text = null; break; case LampType.Ats: this.Text = Translations.GetInterfaceString("lamps_ats"); break; case LampType.AtsOperation: this.Text = Translations.GetInterfaceString("lamps_atsoperation"); break; case LampType.AtsPPower: this.Text = Translations.GetInterfaceString("lamps_atsppower"); break; case LampType.AtsPPattern: this.Text = Translations.GetInterfaceString("lamps_atsppattern"); break; case LampType.AtsPBrakeOverride: this.Text = Translations.GetInterfaceString("lamps_atspbrakeoverride"); break; case LampType.AtsPBrakeOperation: this.Text = Translations.GetInterfaceString("lamps_atspbrakeoperation"); break; case LampType.AtsP: this.Text = Translations.GetInterfaceString("lamps_atsp"); break; case LampType.AtsPFailure: this.Text = Translations.GetInterfaceString("lamps_atspfailure"); break; case LampType.Atc: this.Text = Translations.GetInterfaceString("lamps_atc"); break; case LampType.AtcPower: this.Text = Translations.GetInterfaceString("lamps_atcpower"); break; case LampType.AtcUse: this.Text = Translations.GetInterfaceString("lamps_atcuse"); break; case LampType.AtcEmergency: this.Text = Translations.GetInterfaceString("lamps_atcemergency"); break; case LampType.Eb: this.Text = Translations.GetInterfaceString("lamps_eb"); break; case LampType.ConstSpeed: this.Text = Translations.GetInterfaceString("lamps_constspeed"); break; default: this.Text = "TEXT"; break; } Fonts.OpenGlFont font = Fonts.NormalFont; for (int i = 0; i < HUD.CurrentHudElements.Length; i++) { if (HUD.CurrentHudElements[i].Subject.Equals("ats", StringComparison.OrdinalIgnoreCase)) { font = HUD.CurrentHudElements[i].Font; break; } } System.Drawing.Size size = MeasureString(font, this.Text); this.Width = size.Width; this.Height = size.Height; }
/// <summary>Renders a string to the screen.</summary> /// <param name="font">The font to use.</param> /// <param name="text">The string to render.</param> /// <param name="location">The location.</param> /// <param name="alignment">The alignment.</param> /// <param name="color">The color.</param> /// <remarks>This function sets the OpenGL blend function to glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA).</remarks> private static void DrawString(Fonts.OpenGlFont font, string text, Point location, TextAlignment alignment, Color128 color) { if (text == null || font == null) { return; } /* * Prepare the top-left coordinates for rendering, incorporating the * orientation of the string in relation to the specified location. * */ int left; if ((alignment & TextAlignment.Left) == 0) { int width = 0; for (int i = 0; i < text.Length; i++) { Textures.Texture texture; Fonts.OpenGlFontChar data; i += font.GetCharacterData(text, i, out texture, out data) - 1; width += data.TypographicSize.Width; } if ((alignment & TextAlignment.Right) != 0) { left = location.X - width; } else { left = location.X - width / 2; } } else { left = location.X; } int top; if ((alignment & TextAlignment.Top) == 0) { int height = 0; for (int i = 0; i < text.Length; i++) { Textures.Texture texture; Fonts.OpenGlFontChar data; i += font.GetCharacterData(text, i, out texture, out data) - 1; if (data.TypographicSize.Height > height) { height = data.TypographicSize.Height; } } if ((alignment & TextAlignment.Bottom) != 0) { top = location.Y - height; } else { top = location.Y - height / 2; } } else { top = location.Y; } /* * Render the string. * */ GL.Enable(EnableCap.Texture2D); for (int i = 0; i < text.Length; i++) { Textures.Texture texture; Fonts.OpenGlFontChar data; i += font.GetCharacterData(text, i, out texture, out data) - 1; if (Textures.LoadTexture(texture, Textures.OpenGlTextureWrapMode.ClampClamp)) { GL.BindTexture(TextureTarget.Texture2D, texture.OpenGlTextures[(int)Textures.OpenGlTextureWrapMode.ClampClamp].Name); int x = left - (data.PhysicalSize.Width - data.TypographicSize.Width) / 2; int y = top - (data.PhysicalSize.Height - data.TypographicSize.Height) / 2; /* * In the first pass, mask off the background with pure black. * */ GL.BlendFunc(BlendingFactor.Zero, BlendingFactor.OneMinusSrcColor); GL.Begin(PrimitiveType.Polygon); GL.Color4(color.A, color.A, color.A, 1.0f); GL.TexCoord2(data.TextureCoordinates.Left, data.TextureCoordinates.Top); GL.Vertex2(x, y); GL.Color4(color.A, color.A, color.A, 1.0f); GL.TexCoord2(data.TextureCoordinates.Right, data.TextureCoordinates.Top); GL.Vertex2(x + data.PhysicalSize.Width, y); GL.Color4(color.A, color.A, color.A, 1.0f); GL.TexCoord2(data.TextureCoordinates.Right, data.TextureCoordinates.Bottom); GL.Vertex2(x + data.PhysicalSize.Width, y + data.PhysicalSize.Height); GL.Color4(color.A, color.A, color.A, 1.0f); GL.TexCoord2(data.TextureCoordinates.Left, data.TextureCoordinates.Bottom); GL.Vertex2(x, y + data.PhysicalSize.Height); GL.End(); /* * In the second pass, add the character onto the background. * */ GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.One); GL.Begin(PrimitiveType.Polygon); GL.Color4(color.R, color.G, color.B, color.A); GL.TexCoord2(data.TextureCoordinates.Left, data.TextureCoordinates.Top); GL.Vertex2(x, y); GL.Color4(color.R, color.G, color.B, color.A); GL.TexCoord2(data.TextureCoordinates.Right, data.TextureCoordinates.Top); GL.Vertex2(x + data.PhysicalSize.Width, y); GL.Color4(color.R, color.G, color.B, color.A); GL.TexCoord2(data.TextureCoordinates.Right, data.TextureCoordinates.Bottom); GL.Vertex2(x + data.PhysicalSize.Width, y + data.PhysicalSize.Height); GL.Color4(color.R, color.G, color.B, color.A); GL.TexCoord2(data.TextureCoordinates.Left, data.TextureCoordinates.Bottom); GL.Vertex2(x, y + data.PhysicalSize.Height); GL.End(); } left += data.TypographicSize.Width; } GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); // HACK // GL.Disable(EnableCap.Texture2D); }
/// <summary>Renders a string to the screen.</summary> /// <param name="font">The font to use.</param> /// <param name="text">The string to render.</param> /// <param name="location">The location.</param> /// <param name="orientation">The orientation.</param> /// <param name="color">The color.</param> /// <remarks>This function sets the OpenGL blend function to glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA).</remarks> private static void DrawString(Fonts.OpenGlFont font, string text, Point location, TextAlignment alignment, Color128 color) { if (text == null) { return; } /* * Prepare the top-left coordinates for rendering, incorporating the * orientation of the string in relation to the specified location. * */ int left; if ((alignment & TextAlignment.Left) == 0) { int width = 0; for (int i = 0; i < text.Length; i++) { Textures.Texture texture; Fonts.OpenGlFontChar data; i += font.GetCharacterData(text, i, out texture, out data) - 1; width += data.TypographicSize.Width; } if ((alignment & TextAlignment.Right) != 0) { left = location.X - width; } else { left = location.X - width / 2; } } else { left = location.X; } int top; if ((alignment & TextAlignment.Top) == 0) { int height = 0; for (int i = 0; i < text.Length; i++) { Textures.Texture texture; Fonts.OpenGlFontChar data; i += font.GetCharacterData(text, i, out texture, out data) - 1; if (data.TypographicSize.Height > height) { height = data.TypographicSize.Height; } } if ((alignment & TextAlignment.Bottom) != 0) { top = location.Y - height; } else { top = location.Y - height / 2; } } else { top = location.Y; } /* * Render the string. * */ Gl.glEnable(Gl.GL_TEXTURE_2D); for (int i = 0; i < text.Length; i++) { Textures.Texture texture; Fonts.OpenGlFontChar data; i += font.GetCharacterData(text, i, out texture, out data) - 1; if (Textures.LoadTexture(texture, Textures.OpenGlTextureWrapMode.ClampClamp)) { Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture.OpenGlTextures[(int)Textures.OpenGlTextureWrapMode.ClampClamp].Name); int x = left - (data.PhysicalSize.Width - data.TypographicSize.Width) / 2; int y = top - (data.PhysicalSize.Height - data.TypographicSize.Height) / 2; /* * In the first pass, mask off the background with pure black. * */ Gl.glBlendFunc(Gl.GL_ZERO, Gl.GL_ONE_MINUS_SRC_COLOR); Gl.glBegin(Gl.GL_POLYGON); Gl.glColor4f(color.A, color.A, color.A, 1.0f); Gl.glTexCoord2f(data.TextureCoordinates.Left, data.TextureCoordinates.Top); Gl.glVertex2f(x, y); Gl.glColor4f(color.A, color.A, color.A, 1.0f); Gl.glTexCoord2f(data.TextureCoordinates.Right, data.TextureCoordinates.Top); Gl.glVertex2f(x + data.PhysicalSize.Width, y); Gl.glColor4f(color.A, color.A, color.A, 1.0f); Gl.glTexCoord2f(data.TextureCoordinates.Right, data.TextureCoordinates.Bottom); Gl.glVertex2f(x + data.PhysicalSize.Width, y + data.PhysicalSize.Height); Gl.glColor4f(color.A, color.A, color.A, 1.0f); Gl.glTexCoord2f(data.TextureCoordinates.Left, data.TextureCoordinates.Bottom); Gl.glVertex2f(x, y + data.PhysicalSize.Height); Gl.glEnd(); /* * In the second pass, add the character onto the background. * */ Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE); Gl.glBegin(Gl.GL_POLYGON); Gl.glColor4f(color.R, color.G, color.B, color.A); Gl.glTexCoord2f(data.TextureCoordinates.Left, data.TextureCoordinates.Top); Gl.glVertex2f(x, y); Gl.glColor4f(color.R, color.G, color.B, color.A); Gl.glTexCoord2f(data.TextureCoordinates.Right, data.TextureCoordinates.Top); Gl.glVertex2f(x + data.PhysicalSize.Width, y); Gl.glColor4f(color.R, color.G, color.B, color.A); Gl.glTexCoord2f(data.TextureCoordinates.Right, data.TextureCoordinates.Bottom); Gl.glVertex2f(x + data.PhysicalSize.Width, y + data.PhysicalSize.Height); Gl.glColor4f(color.R, color.G, color.B, color.A); Gl.glTexCoord2f(data.TextureCoordinates.Left, data.TextureCoordinates.Bottom); Gl.glVertex2f(x, y + data.PhysicalSize.Height); Gl.glEnd(); } left += data.TypographicSize.Width; } Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA); // HACK // }
/******************** MENU SYSTEM METHODS *********************/ // // INITIALIZE THE MENU SYSTEM // private void Init() { Reset(); // choose the text font size according to screen height // the boundaries follow approximately the progression // of font sizes defined in Graphics/Fonts.cs if (Screen.Height <= 512) menuFont = Fonts.SmallFont; else if (Screen.Height <= 680) menuFont = Fonts.NormalFont; else if (Screen.Height <= 890) menuFont = Fonts.LargeFont; else if (Screen.Height <= 1150) menuFont = Fonts.VeryLargeFont; else menuFont = Fonts.EvenLargerFont; em = (int)menuFont.FontSize; lineHeight = (int)(em * LineSpacing); for(int i= 0; i < Interface.CurrentControls.Length; i++) { //Find the current menu back key- It's unlikely that we want to set a new key to this if(Interface.CurrentControls[i].Command == Interface.Command.MenuBack) { MenuBackKey = Interface.CurrentControls[i].Key; break; } } isInitialized = true; }