public FloatRect GetDimensions(string text, uint size, Text.Styles style) { Text tempText = new Text(text, resource, size); tempText.Style = style; return(tempText.GetLocalBounds()); }
/// <summary> /// Adds a mutable sprite string to the batch of sprites to be rendered, specifying the font, output text, /// screen position, color tint, rotation, origin, scale, effects, and depth. /// </summary> /// <param name="font">The <see cref="Font"/> to use to draw.</param> /// <param name="text">The string to draw.</param> /// <param name="position">The location, in screen coordinates, where the text will be drawn.</param> /// <param name="color">The desired color of the text.</param> /// <param name="rotation">The angle, in radians, to rotate the text around the origin.</param> /// <param name="origin">The origin of the string. Specify (0,0) for the upper-left corner.</param> /// <param name="scale">Vector containing separate scalar multiples for the x- and y-axes of the sprite.</param> /// <param name="style">How to style the drawn string.</param> /// <param name="shader">The shader to use on the text being drawn.</param> public virtual void DrawString(Font font, string text, Vector2 position, Color color, float rotation, Vector2 origin, float scale, Text.Styles style = Text.Styles.Regular, Shader shader = null) { if (!IsAssetValid(font)) { return; } DrawString(font, text, position, color, rotation, origin, new Vector2(scale), style, shader); }
public static void AddText(string name, string fontPath, uint size, Text.Styles style) { if (!texts.Keys.Contains(name)) { Font font = new Font(fontPath); Text text = new Text("", font); text.CharacterSize = size; text.Style = style; texts.Add(name, text); } else { throw new ArgumentException("Already used text name '" + name + "'. source:TextManager.AddText()"); } }
private void ChangeColorOfSelectedText(int position, Color color, Text.Styles style) { if (position == 0) { this.start.Color = color; this.start.Style = style; } if (position == 1) { this.HighScore.Color = color; this.HighScore.Style = style; } if (position == 2) { this.quit.Color = color; this.quit.Style = style; } }
/// <summary> /// Adds a mutable sprite string to the batch of sprites to be rendered, specifying the font, output text, /// screen position, color tint, rotation, origin, scale, effects, and depth. /// </summary> /// <param name="font">The <see cref="Font"/> to use to draw.</param> /// <param name="text">The string to draw.</param> /// <param name="position">The location, in screen coordinates, where the text will be drawn.</param> /// <param name="color">The desired color of the text.</param> /// <param name="rotation">The angle, in radians, to rotate the text around the origin.</param> /// <param name="origin">The origin of the string. Specify (0,0) for the upper-left corner.</param> /// <param name="scale">Vector containing separate scalar multiples for the x- and y-axes of the sprite.</param> /// <param name="style">How to style the drawn string.</param> /// <param name="shader">The shader to use on the text being drawn.</param> public virtual void DrawString(Font font, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, Text.Styles style = Text.Styles.Regular, Shader shader = null) { if (!IsAssetValid(font) || string.IsNullOrEmpty(text)) { return; } _str.Font = font; _str.DisplayedString = text; _str.Position = position; _str.Color = color; _str.Rotation = rotation; _str.Origin = origin; _str.Scale = scale; _str.Style = style; _str.CharacterSize = font.DefaultSize; _rt.Draw(_str, shader); }
public void DrawString(FontAsset asset, string text, Vector2f position, Color color, uint size, Text.Styles style, float rotation, Vector2f origin) { Text textSprite = new Text(text, asset.Resource, size); textSprite.Position = position; textSprite.Color = color; textSprite.Style = style; textSprite.Rotation = rotation; textSprite.Origin = origin; sprites.Add(textSprite); }
static extern private void tguiLabelRenderer_setTextStyle(IntPtr cPointer, Text.Styles style);
static extern private void tguiRadioButtonRenderer_setTextStyleChecked(IntPtr cPointer, Text.Styles style);
static extern private void tguiProgressBarRenderer_setTextStyle(IntPtr cPointer, Text.Styles style);
/// <summary> /// Draws the string. /// </summary> /// <param name="font">Font.</param> /// <param name="text">Text.</param> /// <param name="position">Position.</param> /// <param name="color">Color.</param> /// <param name="rotation">Rotation.</param> /// <param name="origin">Origin.</param> /// <param name="scale">Scale.</param> /// <param name="styles">Styles.</param> public void DrawString(Font font, string text, Vector position, Color color, float rotation, Vector origin, float scale, Text.Styles styles = Text.Styles.Regular) { if (!HasBegin) { throw new Exception("TextBatch not start"); } _text.Font = font; _text.DisplayedString = text; var p = _text.Position; p.X = position.X; p.Y = position.Y; _text.Position = p; _text.Rotation = rotation; _text.Scale = new Vector2f(scale, scale); var c = _text.Color; c.A = color.A; c.B = color.B; c.G = color.G; c.R = color.R; _text.Color = c; _text.Style = styles; RenderTarget.Draw(_text); }
public void DrawString(FontAsset asset, string text, Vector2f position, Color color, uint size, Text.Styles style, float rotation, Origin origin) { Text textSprite = new Text(text, asset.Resource, size); textSprite.Position = position; textSprite.Color = color; textSprite.Style = style; textSprite.Rotation = rotation; FloatRect originRect = textSprite.GetLocalBounds(); Vector2f originPosition = new Vector2f(); switch (origin) { case Origin.TopCenter: originPosition.X = originRect.Width / 2f; break; case Origin.TopRight: originPosition.X = originRect.Width; break; case Origin.MiddleLeft: originPosition.Y = originRect.Height / 2f; break; case Origin.Center: originPosition.X = originRect.Width / 2f; originPosition.Y = originRect.Height / 2f; break; case Origin.MiddleRight: originPosition.X = originRect.Width; originPosition.Y = originRect.Height / 2f; break; case Origin.BottomLeft: originPosition.Y = originRect.Height; break; case Origin.BottomCenter: originPosition.X = originRect.Width / 2f; originPosition.Y = originRect.Height; break; case Origin.BottomRight: originPosition.X = originRect.Width; originPosition.Y = originRect.Height; break; } textSprite.Origin = originPosition; sprites.Add(textSprite); }
/// <summary> /// Adds a new line of text to the chat box /// </summary> /// <remarks> /// The whole text passed to this function will be considered as one line for the getLine and removeLine functions, /// even if it is too long and gets split over multiple lines. /// </remarks> /// <param name="text">Text that will be added to the chat box</param> /// <param name="color">Color of the text</param> /// <param name="style">Text style</param> public void AddLine(string text, Color color, Text.Styles style) { tguiChatBox_addLineWithColorAndStyle(CPointer, Util.ConvertStringForC_UTF32(text), color, style); }
public List <Text> createStrings() { // Fields for max width/height of dialogue box, and current width/height of the chopped dialogue float maxw; float maxh; float currw = 0; float currh = 0; // The chopped dialogue that fits in one pane string line = ""; // Boolean to handle when to end bool end = false; // Style and colors for the text object Text.Styles style = Text.Styles.Regular; Color color = Color.White; Color thoughtColor = new Color(172, 172, 172); // List of chopped dialogues List <Text> panes = new List <Text>(); // Split the dialogue string by spaces into an array string[] words = dialogue.DisplayedString.Split(' '); // Set max width and height based off of the current dialogue box sprite if (tag == "AI") { maxw = cursor.GetGlobalBounds().Left - dialogueBoxSprite.GetGlobalBounds().Left; maxh = (float)(dialogueBoxSprite.GetGlobalBounds().Height * 0.4); } else if (tag == "PLAYER") { maxw = cursor.GetGlobalBounds().Left - dialogueBoxSprite.GetGlobalBounds().Left; maxh = (float)(dialogueBoxSprite.GetGlobalBounds().Height * 0.7); } else { maxw = dialogueBoxSprite.GetGlobalBounds().Width; maxh = dialogueBoxSprite.GetGlobalBounds().Height; } // Loop through all of the words for (int i = 0; i < words.Count(); i++) { // Save current word string currWord = words[i]; //Console.WriteLine("currword: " + currWord); //if (currWord == "note,") Console.WriteLine("WTFFFFFFFFFFFFFFFFFFBOOOOOOOOOOOOOOOOOOOOOOOM!@#$%^&*!@#$%^&*!@#$%^&*"); // Check for italic start condition if (currWord.Contains("<")) { style = Text.Styles.Italic; color = thoughtColor; currWord = currWord.Replace("<", ""); } else if (currWord.Contains(">")) { currWord = currWord.Replace(">", ""); end = true; } // Check if next word has an italic start condition then end current pane if (words[((i + 1 < words.Count()) ? i + 1 : i)].Contains("<")) { end = true; style = Text.Styles.Regular; } // Temp text object for sizing Text temp = new Text(currWord + " ", speechFont, dialogueFontSize); // Reset current height if (currh == 0) { currh += (float)(temp.GetGlobalBounds().Height * 1.5); } // If temp string's width plus the current width is less than the width of the dialogue box sprite if (temp.GetGlobalBounds().Width + currw <= maxw) { line += currWord + " "; currw += temp.GetGlobalBounds().Width; // Else If temp string's height plus the current height is less than the height of the dialogue box sprite } else if ((temp.GetGlobalBounds().Height * 1.5) + currh <= maxh) { line += "\n" + currWord + " "; currh += (float)(temp.GetGlobalBounds().Height * 1.5); currw = temp.GetGlobalBounds().Width; // Else end that shit } else { i--; end = true; } // If we're at the end of the array and end hasn't been met yet, end it. if (!end && i == words.Count() - 1) { end = true; } // If we have reached an end, package the current string and put it in a text object with the current style and color // Reset current width, height, line, and end for the next iteration if (end && line != "") { Text pane = new Text(line, speechFont, dialogueFontSize); pane.Style = style; pane.Color = color; panes.Add(pane); end = false; line = ""; currw = 0; currh = 0; } // Reset the style if we have found an italic termination symbol if (words[i].Contains(">") && style == Text.Styles.Italic) { style = Text.Styles.Regular; color = Color.White; } } return(panes); }
/// <summary> /// Adds a mutable sprite string to the batch of sprites to be rendered, specifying the font, output text, /// screen position, color tint, rotation, origin, scale, effects, and depth. /// </summary> /// <param name="font">The <see cref="Font"/> to use to draw.</param> /// <param name="text">The mutable (read/write) string to draw.</param> /// <param name="position">The location, in screen coordinates, where the text will be drawn.</param> /// <param name="color">The desired color of the text.</param> /// <param name="rotation">The angle, in radians, to rotate the text around the origin.</param> /// <param name="origin">The origin of the string. Specify (0,0) for the upper-left corner.</param> /// <param name="scale">Vector containing separate scalar multiples for the x- and y-axes of the sprite.</param> /// <param name="style">How to style the drawn string.</param> /// <param name="shader">The shader to use on the text being drawn.</param> public override void DrawString(Font font, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, Text.Styles style = Text.Styles.Regular, Shader shader = null) { base.DrawString(font, text, position.Round(), color, rotation, origin, scale, style, shader); }
static extern private void tguiListBoxRenderer_setSelectedTextStyle(IntPtr cPointer, Text.Styles style);
static extern private void tguiChatBox_setTextStyle(IntPtr cPointer, Text.Styles style);
static extern private void tguiChatBox_addLineWithColorAndStyle(IntPtr cPointer, IntPtr text, Color color, Text.Styles style);
/// <summary> /// If the specified position lies within this <see cref="Text"/> space, /// decorate it with the specified style. /// </summary> public static void Indicate(this Text text, Vector2i position, Text.Styles style) { text.Style = (text.Contains(position.X, position.Y)) ? text.Style.TurnOn(style) : text.Style.TurnOff(style); }
static extern private void tguiComboBoxRenderer_setDefaultTextStyle(IntPtr cPointer, Text.Styles style);
/// <summary> /// Draw a string /// </summary> /// <param name="font">Font to use to draw a string</param> /// <param name="text">String text to draw</param> /// <param name="position">Position of the text</param> /// <param name="color">Color of the text</param> /// <param name="rotation">Rotation of the text</param> /// <param name="origin">Origin of the text</param> /// <param name="scale">Scale of the text</param> /// <param name="styles">Optional, style of the text</param> public void DrawString(Font font, string text, Vector position, Color color, float rotation, Vector origin, float scale, Text.Styles styles = Text.Styles.Regular) { if (this.HasBegin) { this._text.Font = font; this._text.DisplayedString = text; Vector2f p = this._text.Position; p.X = position.X; p.Y = position.Y; this._text.Position = p; this._text.Rotation = rotation; this._text.Scale = new Vector2f(scale, scale); SFML.Graphics.Color c = this._text.Color; c.A = color.A; c.B = color.B; c.G = color.G; c.R = color.R; this._text.Color = c; this._text.Style = styles; this._renderTarget.Draw(this._text); } else { //TODO throw exception } }
static extern private void tguiButtonRenderer_setTextStyleDisabled(IntPtr cPointer, Text.Styles style);
public CInfo(Vector2f maxDimension, Font font, uint size, Text.Styles styles) { MaxDimension = maxDimension; Font = font; Size = size; Styles = styles; }
public static Text CreateDrawableText(string font, uint fontSize, Color fontColor, Text.Styles fontStyle) { var Text = new Text { Font = new Font(FontFolder + font), CharacterSize = fontSize, FillColor = fontColor, Style = fontStyle }; return(Text); }