public UIChatBalloon(UIChatPanel owner) { Owner = owner; var gfx = Content.Content.Get().UIGraphics; //TODO: switch entire ui onto real content system BPointerBottom = GetTexture(0x1AF0856DDBAC); BPointerSide = GetTexture(0x1B00856DDBAC); BTiles = GetTexture(0x1B10856DDBAC); if (!ProcessedBGFX) { ProcessedBGFX = true; AlphaCopy(BPointerBottom); AlphaCopy(BPointerSide); AlphaCopy(BTiles); } BodyTextStyle = TextStyle.DefaultLabel.Clone(); BodyTextStyle.Size = 10; BodyTextStyle.Color = new Color(240, 240, 48); ShadowStyle = BodyTextStyle.Clone(); ShadowStyle.Color = Color.Black; }
public UIAlert(UIAlertOptions options) : base(UIDialogStyle.Standard, true) { this.m_Options = options; this.Caption = options.Title; this.Opacity = 0.9f; m_TextStyle = TextStyle.DefaultLabel.Clone(); m_TextStyle.Size = options.TextSize; Icon = new UIImage(); Icon.Position = new Vector2(32, 32); Icon.SetSize(0, 0); Add(Icon); /** Determine the size **/ ComputeText(); /** Add buttons **/ Buttons = new List<UIButton>(); foreach (var button in options.Buttons) { string buttonText = ""; if (button.Text != null) buttonText = button.Text; else { switch (button.Type) { case UIAlertButtonType.OK: buttonText = GameFacade.Strings.GetString("142", "ok button"); break; case UIAlertButtonType.Yes: buttonText = GameFacade.Strings.GetString("142", "yes button"); break; case UIAlertButtonType.No: buttonText = GameFacade.Strings.GetString("142", "no button"); break; case UIAlertButtonType.Cancel: buttonText = GameFacade.Strings.GetString("142", "cancel button"); break; } } var btnElem = AddButton(buttonText, button.Type, button.Handler == null); Buttons.Add(btnElem); if (button.Handler != null) btnElem.OnButtonClick += button.Handler; } if (options.TextEntry) { TextBox = new UITextBox(); this.Add(TextBox); } /** Position buttons **/ RefreshSize(); }
public UIChatPanel(VM vm, UILotControl owner) { this.vm = vm; this.Owner = owner; if (FSOEnvironment.SoftwareKeyboard) { //need a button to initiate chat history var btn = new UIButton(); btn.Caption = "Chat"; btn.Position = new Vector2(10, 10); btn.OnButtonClick += (state) => { HistoryDialog.Visible = !HistoryDialog.Visible; }; Add(btn); } Style = TextStyle.DefaultTitle.Clone(); Style.Size = 16; Style.Shadow = true; Labels = new List<UIChatBalloon>(); TextBox = new UITextBox(); TextBox.Visible = false; Add(TextBox); TextBox.Position = new Vector2(25, 25); TextBox.SetSize(GlobalSettings.Default.GraphicsWidth - 50, 25); TextBox.OnEnterPress += SendMessageElem; SelectionFillColor = new Color(0, 25, 70); //-- populate invalid areas -- //chat bubbles will be pushed out of these areas //when this happens, they will also begin displaying the name of the speaking avatar. InvalidAreas = new List<Rectangle>(); InvalidAreas.Add(new Rectangle(-100000, -100000, 100020, 200000 + GlobalSettings.Default.GraphicsHeight)); //left InvalidAreas.Add(new Rectangle(-100000, -100000, 200000 + GlobalSettings.Default.GraphicsWidth, 100020)); //top InvalidAreas.Add(new Rectangle(GlobalSettings.Default.GraphicsWidth-20, -100000, 100020, 200000 + GlobalSettings.Default.GraphicsHeight)); //right InvalidAreas.Add(new Rectangle(-100000, GlobalSettings.Default.GraphicsHeight - 20, 200000 +GlobalSettings.Default.GraphicsWidth, 100020)); //bottom InvalidAreas.Add(new Rectangle(-100000, GlobalSettings.Default.GraphicsHeight - 230, 100230, 100230)); //ucp HistoryDialog = new UIChatDialog(); HistoryDialog.Position = new Vector2(20, 20); HistoryDialog.Visible = false; HistoryDialog.Opacity = 0.75f; HistoryDialog.OnSendMessage += SendMessage; this.Add(HistoryDialog); PropertyLog = new UIPropertyLog(); PropertyLog.Position = new Vector2(400, 20); PropertyLog.Visible = false; PropertyLog.Opacity = 0.75f; this.Add(PropertyLog); }
static UIProgressBar() { StandardBackground = new SlicedTextureRef( UIElement.GetTexture((ulong)FileIDs.UIFileIDs.dialog_progressbarback), new Microsoft.Xna.Framework.Rectangle(13, 13, 13, 13) ); var barTexture = UIElement.GetTexture((ulong)FileIDs.UIFileIDs.dialog_progressbarfront); TextureUtils.ManualTextureMask(ref barTexture, new uint[1] { new Color(0x39, 0x51, 0x6B).PackedValue }); StandardBar = new SlicedTextureRef(barTexture, new Rectangle(18, 7, 18, 7)); StandardCaptionStyle = TextStyle.DefaultLabel.Clone(); StandardCaptionStyle.Color = new Color(0, 0, 0); }
public UIChatPanel(VM vm, UILotControl owner) { this.vm = vm; this.Owner = owner; Style = TextStyle.DefaultTitle.Clone(); Style.Size = 16; Style.Shadow = true; Labels = new List<UILabel>(); TextBox = new UITextBox(); TextBox.Visible = false; Add(TextBox); TextBox.Position = new Vector2(25, 25); TextBox.SetSize(GlobalSettings.Default.GraphicsWidth - 50, 25); TextBox.OnEnterPress += SendMessage; SelectionFillColor = new Color(0, 25, 70); }
public static UIWordWrapOutput WordWrap(string text, int width, TextStyle style, Vector2 scale) { var result = new UIWordWrapOutput(); result.Lines = new List<string>(); var textLines = new string[] {text}; //only support single line for now, since we're only using this utility function for captions int maxWidth = 0; int curpos = 0; var positions = new List<int>(); for (var l=0; l<textLines.Length; l++) { List<string> words = textLines[l].Split(' ').ToList(); while (words.Count > 0) { var lineBuffer = new List<string>(); int i = 0; for (i=0; i<words.Count; i++) { lineBuffer.Add(words[i]); var str = JoinWordList(lineBuffer); //(lineBuffer.concat([words[i]])).join(" "); int w = (int)(style.SpriteFont.MeasureString(str).X * scale.X); if (w > width) { lineBuffer.RemoveAt(lineBuffer.Count-1); if (lineBuffer.Count == 0) { for (var j=words[i].Length-1; j>0; j--) { var str2 = words[i].Substring(0, j); var w2 = (int)(style.SpriteFont.MeasureString(str2).X * scale.X); if (w2 <= width) { curpos += j; lineBuffer.Add(words[i].Substring(0, j)); words[i] = words[i].Substring(j); if (w > maxWidth) maxWidth = w; break; } } } break; } else { if (w > maxWidth) maxWidth = w; curpos += words[i].Length + 1; } } result.Lines.Add(JoinWordList(lineBuffer)); positions.Add(curpos); words.RemoveRange(0, i); } //curpos++; } result.Positions = positions; result.MaxWidth = maxWidth; return result; }
public PrimitiveBox(BHAVInstruction inst, byte ptr, BHAVContainer master) { Type = PrimBoxType.Primitive; Instruction = inst; Descriptor = PrimitiveRegistry.GetDescriptor(inst.Opcode); Operand = (VMPrimitiveOperand)Activator.CreateInstance(Descriptor.OperandType); Operand.Read(inst.Operand); InstPtr = ptr; Nodes = new PrimitiveNode[2]; Nodes[0] = new PrimitiveNode(); Nodes[0].Type = NodeType.False; Nodes[1] = new PrimitiveNode(); Nodes[1].Type = NodeType.True; Title = new UILabel(); Title.Alignment = TextAlignment.Middle | TextAlignment.Center; Title.Y = 0; Title.X = 0; this.Add(Title); Title.CaptionStyle = TextStyle.DefaultLabel.Clone(); Title.CaptionStyle.Font = FSO.Client.GameFacade.EdithFont; Title.CaptionStyle.Size = 14; BodyTextStyle = TextStyle.DefaultLabel.Clone(); BodyTextStyle.Font = FSO.Client.GameFacade.EdithFont; BodyTextStyle.Size = 12; this.Add(Nodes[0]); this.Add(Nodes[1]); HitTest = ListenForMouse(new Rectangle(0, 0, Width, Height), new UIMouseEvent(MouseEvents)); Master = master; UpdateDisplay(); }
/// <summary> /// This utility will draw a line of text onto the UIElement. /// </summary> /// <param name="batch">The SpriteBatch to draw the text onto</param> /// <param name="text">The content of the text</param> /// <param name="to">The position of the text. Relative to this UIElement.</param> /// <param name="style">The text style</param> /// <param name="bounds">Rectangle relative to this UIElement which the text should be positioned within</param> /// <param name="align">Alignment of the text within the bounds box.</param> /// <param name="margin">Margin offset from the bounding box.</param> /// <param name="state">State of the text, e.g. hover, down, normal</param> public void DrawLocalString(SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin, UIElementState state) { //TODO: We should find some way to cache this data /** * Work out the scale of the vector font. * * We need to scale it based on the UIElement's scale factory, * but we also need to scale it based on the text styles scale factor. * * Aka if the vector font is 12px and we asked for 24px it would be scale of 2.0 */ var scale = _Scale; if (style.Scale != 1.0f) { scale = new Vector2(scale.X * style.Scale, scale.Y * style.Scale); } /** Work out how big the text will be so we can align it **/ var textSize = style.SpriteFont.MeasureString(text); Vector2 size = textSize * style.Scale; /** Apply margins **/ if (margin != Rectangle.Empty) { bounds.X += margin.X; bounds.Y += margin.Y; bounds.Width -= margin.Right; bounds.Height -= margin.Bottom; } /** Work out X and Y based on alignment & bounding box **/ var pos = to; pos.X += bounds.X; pos.Y += bounds.Y; if ((align & TextAlignment.Right) == TextAlignment.Right) { pos.X += (bounds.Width - size.X); } else if ((align & TextAlignment.Center) == TextAlignment.Center) { pos.X += (bounds.Width - size.X) / 2; } if ((align & TextAlignment.Middle) == TextAlignment.Middle) { pos.Y += (bounds.Height - size.Y) / 2; } else if ((align & TextAlignment.Bottom) == TextAlignment.Bottom) { pos.Y += (bounds.Height - size.Y); } //pos.Y += style.BaselineOffset; /** Draw the string **/ pos = FlooredLocalPoint(pos); if (style.Shadow) batch.DrawString(style.SpriteFont, text, pos + new Vector2(1, 1), Color.Black, 0, Vector2.Zero, scale, SpriteEffects.None, 0); batch.DrawString(style.SpriteFont, text, pos, style.GetColor(state), 0, Vector2.Zero, scale, SpriteEffects.None, 0); }
/// <summary> /// This utility will draw a line of text onto the UIElement. /// </summary> /// <param name="batch">The SpriteBatch to draw the text onto</param> /// <param name="text">The content of the text</param> /// <param name="to">The position of the text. Relative to this UIElement.</param> /// <param name="style">The text style</param> /// <param name="bounds">Rectangle relative to this UIElement which the text should be positioned within</param> /// <param name="align">Alignment of the text within the bounds box.</param> /// <param name="margin">Margin offset from the bounding box.</param> /// <param name="state">State of the text, e.g. hover, down, normal</param> public void DrawLocalString(SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin, UIElementState state) { //TODO: We should find some way to cache this data /** * Work out the scale of the vector font. * * We need to scale it based on the UIElement's scale factory, * but we also need to scale it based on the text styles scale factor. * * Aka if the vector font is 12px and we asked for 24px it would be scale of 2.0 */ var scale = _Scale; if (style.Scale != 1.0f) { scale = new Vector2(scale.X * style.Scale, scale.Y * style.Scale); } /** Work out how big the text will be so we can align it **/ var size = (align == 0) ? Vector2.Zero : style.MeasureString(text); /** Apply margins **/ if (margin != Rectangle.Empty) { bounds.X += margin.X; bounds.Y += margin.Y; bounds.Width -= margin.Right; bounds.Height -= margin.Bottom; } /** Work out X and Y based on alignment & bounding box **/ var pos = to; pos.X += bounds.X; pos.Y += bounds.Y; if ((align & TextAlignment.Right) == TextAlignment.Right) { pos.X += (bounds.Width - size.X); } else if ((align & TextAlignment.Center) == TextAlignment.Center) { pos.X += (bounds.Width - size.X) / 2; } if ((align & TextAlignment.Middle) == TextAlignment.Middle) { pos.Y += (bounds.Height - size.Y) / 2; } else if ((align & TextAlignment.Bottom) == TextAlignment.Bottom) { pos.Y += (bounds.Height - size.Y); } //pos.Y += style.BaselineOffset; /** Draw the string **/ pos = FlooredLocalPoint(pos); if (style.VFont != null) { batch.End(); Matrix?mat = null; var ui = (batch as UISpriteBatch); if (ui != null && ui.BatchMatrixStack.Count > 0) { mat = ui.BatchMatrixStack.Peek(); } if (style.Shadow) { style.VFont.Draw(batch.GraphicsDevice, text, pos + new Vector2(FSOEnvironment.DPIScaleFactor), Color.Black, scale, mat); } style.VFont.Draw(batch.GraphicsDevice, text, pos, style.GetColor(state) * Opacity, scale, mat); if (mat != null) { batch.Begin(transformMatrix: mat, rasterizerState: RasterizerState.CullNone); } else { batch.Begin(rasterizerState: RasterizerState.CullNone); } } else { if (style.Shadow) { batch.DrawString(style.SpriteFont, text, pos + new Vector2(FSOEnvironment.DPIScaleFactor), Color.Black, 0, Vector2.Zero, scale, SpriteEffects.None, 0); } batch.DrawString(style.SpriteFont, text, pos, style.GetColor(state) * Opacity, 0, Vector2.Zero, scale, SpriteEffects.None, 0); } }
/// <summary> /// This utility will draw a line of text onto the UIElement. /// </summary> /// <param name="batch">The SpriteBatch to draw the text onto</param> /// <param name="text">The content of the text</param> /// <param name="to">The position of the text. Relative to this UIElement.</param> /// <param name="style">The text style</param> public void DrawLocalString(SpriteBatch batch, string text, Vector2 to, TextStyle style) { var scale = _Scale; if (style.Scale != 1.0f) { scale = new Vector2(scale.X * style.Scale, scale.Y * style.Scale); } //to.Y += style.BaselineOffset; to.X = (float)Math.Floor(to.X); to.Y = (float)Math.Floor(to.Y); batch.DrawString(style.SpriteFont, text, LocalPoint(to), style.Color, 0, Vector2.Zero, scale, SpriteEffects.None, 0); }
public static void CalculateLines(List <UITextEditLine> m_Lines, List <string> newWordsArray, TextStyle TextStyle, float lineWidth, float spaceWidth, Vector2 topLeftIconSpace, float lineHeight) { var currentLine = new StringBuilder(); var currentLineWidth = 0.0f; var currentLineNum = 0; for (var i = 0; i < newWordsArray.Count; i++) { var allowedWidth = (currentLineNum * lineHeight < topLeftIconSpace.Y)?lineWidth - topLeftIconSpace.X:lineWidth; var word = newWordsArray[i]; if (word == "\n") { /** Line break **/ m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum, WhitespaceSuffix = 0 }); currentLineNum++; currentLine = new StringBuilder(); currentLineWidth = 0; } else { bool wordWritten = false; while (!wordWritten) //repeat until the full word is written (as part of it can be written each pass if it is too long) { var wordSize = TextStyle.MeasureString(word); if (wordSize.X > allowedWidth) { //SPECIAL CASE, word is bigger than line width and cannot fit on its own line if (currentLineWidth > 0) { //if there are words on this line, we'll start this one on the next to get the most space for it m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum }); currentLineNum++; currentLine = new StringBuilder(); currentLineWidth = 0; } // binary search, makes this a bit faster? // we can safely say that no character is thinner than 4px, so set max substring to maxwidth/4 float width = allowedWidth + 1; int min = 1; int max = Math.Min(word.Length, (int)allowedWidth / 4); int mid = (min + max) / 2; while (max - min > 1) { width = TextStyle.MeasureString(word.Substring(0, mid)).X; if (width > allowedWidth) { max = mid; } else { min = mid; } mid = (max + min) / 2; } currentLine.Append(word.Substring(0, min)); currentLineWidth += width; word = word.Substring(min); m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum, WhitespaceSuffix = 0 }); currentLineNum++; currentLine = new StringBuilder(); currentLineWidth = 0; } else if (currentLineWidth + wordSize.X < allowedWidth) { currentLine.Append(word); if (i != newWordsArray.Count - 1) { currentLine.Append(' '); currentLineWidth += spaceWidth; } currentLineWidth += wordSize.X; wordWritten = true; } else { /** New line **/ m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum, WhitespaceSuffix = 0 }); currentLineNum++; currentLine = new StringBuilder(); currentLine.Append(word); currentLineWidth = wordSize.X; if (i != newWordsArray.Count - 1) { currentLine.Append(' '); currentLineWidth += spaceWidth; } wordWritten = true; } } } } m_Lines.Add(new UITextEditLine //add even if length is 0, so we can move the cursor down! { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum }); var currentIndex = 0; foreach (var line in m_Lines) { line.StartIndex = currentIndex; currentIndex += line.Text.Length + line.WhitespaceSuffix; } }
/// <summary> /// This utility will draw a line of text onto the UIElement. /// </summary> /// <param name="batch">The SpriteBatch to draw the text onto</param> /// <param name="text">The content of the text</param> /// <param name="to">The position of the text. Relative to this UIElement.</param> /// <param name="style">The text style</param> /// <param name="bounds">Rectangle relative to this UIElement which the text should be positioned within</param> /// <param name="align">Alignment of the text within the bounds box.</param> /// <param name="margin">Margin offset from the bounding box.</param> /// <param name="state">State of the text, e.g. hover, down, normal</param> public void DrawLocalString(SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin, UIElementState state) { //TODO: We should find some way to cache this data /** * Work out the scale of the vector font. * * We need to scale it based on the UIElement's scale factory, * but we also need to scale it based on the text styles scale factor. * * Aka if the vector font is 12px and we asked for 24px it would be scale of 2.0 */ var scale = _Scale; if (style.Scale != 1.0f) { scale = new Vector2(scale.X * style.Scale, scale.Y * style.Scale); } /** Work out how big the text will be so we can align it **/ var textSize = style.SpriteFont.MeasureString(text); Vector2 size = textSize * style.Scale; /** Apply margins **/ if (margin != Rectangle.Empty) { bounds.X += margin.X; bounds.Y += margin.Y; bounds.Width -= margin.Right; bounds.Height -= margin.Bottom; } /** Work out X and Y based on alignment & bounding box **/ var pos = to; pos.X += bounds.X; pos.Y += bounds.Y; if ((align & TextAlignment.Right) == TextAlignment.Right) { pos.X += (bounds.Width - size.X); } else if ((align & TextAlignment.Center) == TextAlignment.Center) { pos.X += (bounds.Width - size.X) / 2; } if ((align & TextAlignment.Middle) == TextAlignment.Middle) { pos.Y += (bounds.Height - size.Y) / 2; } else if ((align & TextAlignment.Bottom) == TextAlignment.Bottom) { pos.Y += (bounds.Height - size.Y); } //pos.Y += style.BaselineOffset; /** Draw the string **/ pos = FlooredLocalPoint(pos); if (style.Shadow) { batch.DrawString(style.SpriteFont, text, pos + new Vector2(1, 1), Color.Black, 0, Vector2.Zero, scale, SpriteEffects.None, 0); } batch.DrawString(style.SpriteFont, text, pos, style.GetColor(state) * Opacity, 0, Vector2.Zero, scale, SpriteEffects.None, 0); }
/// <summary> /// This utility will draw a line of text onto the UIElement. /// </summary> /// <param name="batch">The SpriteBatch to draw the text onto</param> /// <param name="text">The content of the text</param> /// <param name="to">The position of the text. Relative to this UIElement.</param> /// <param name="style">The text style</param> /// <param name="bounds">Rectangle relative to this UIElement which the text should be positioned within</param> /// <param name="align">Alignment of the text within the bounds box.</param> /// <param name="margin">Margin offset from the bounding box.</param> public void DrawLocalString(SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin) { DrawLocalString(batch, text, to, style, bounds, align, margin, UIElementState.Normal); }
/// <summary> /// This utility will draw a line of text onto the UIElement. /// </summary> /// <param name="batch">The SpriteBatch to draw the text onto</param> /// <param name="text">The content of the text</param> /// <param name="to">The position of the text. Relative to this UIElement.</param> /// <param name="style">The text style</param> /// <param name="bounds">Rectangle relative to this UIElement which the text should be positioned within</param> /// <param name="align">Alignment of the text within the bounds box.</param> public void DrawLocalString(SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align) { DrawLocalString(batch, text, to, style, bounds, align, Rectangle.Empty); }
public static void CalculateLines(List<UITextEditLine> m_Lines, List<string> newWordsArray, TextStyle TextStyle, float lineWidth, float spaceWidth, Vector2 topLeftIconSpace, float lineHeight) { var currentLine = new StringBuilder(); var currentLineWidth = 0.0f; var currentLineNum = 0; for (var i = 0; i < newWordsArray.Count; i++) { var allowedWidth = (currentLineNum*lineHeight<topLeftIconSpace.Y)?lineWidth-topLeftIconSpace.X:lineWidth; var word = newWordsArray[i]; if (word == "\r\n") { /** Line break **/ m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum, WhitespaceSuffix = 2 }); currentLineNum++; currentLine = new StringBuilder(); currentLineWidth = 0; } else { bool wordWritten = false; while (!wordWritten) //repeat until the full word is written (as part of it can be written each pass if it is too long) { var wordSize = TextStyle.MeasureString(word); if (wordSize.X > allowedWidth) { //SPECIAL CASE, word is bigger than line width and cannot fit on its own line if (currentLineWidth > 0) { //if there are words on this line, we'll start this one on the next to get the most space for it m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum }); currentLineNum++; currentLine = new StringBuilder(); currentLineWidth = 0; } float width = allowedWidth + 1; int j = word.Length; while (width > allowedWidth) { width = TextStyle.MeasureString(word.Substring(0, --j)).X; } currentLine.Append(word.Substring(0, j)); currentLineWidth += width; word = word.Substring(j); m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum, WhitespaceSuffix = 1 }); currentLineNum++; currentLine = new StringBuilder(); currentLineWidth = 0; } else if (currentLineWidth + wordSize.X < allowedWidth) { currentLine.Append(word); if (i != newWordsArray.Count - 1) { currentLine.Append(' '); currentLineWidth += spaceWidth; } currentLineWidth += wordSize.X; wordWritten = true; } else { /** New line **/ m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum, WhitespaceSuffix = 1 }); currentLineNum++; currentLine = new StringBuilder(); currentLine.Append(word); currentLineWidth = wordSize.X; if (i != newWordsArray.Count - 1) { currentLine.Append(' '); currentLineWidth += spaceWidth; } wordWritten = true; } } } } m_Lines.Add(new UITextEditLine //add even if length is 0, so we can move the cursor down! { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum }); var currentIndex = 0; foreach (var line in m_Lines) { line.StartIndex = currentIndex; currentIndex += (line.Text.Length - 1) + line.WhitespaceSuffix; } }
/// <summary> /// This utility will draw a line of text onto the UIElement. /// </summary> /// <param name="batch">The SpriteBatch to draw the text onto</param> /// <param name="text">The content of the text</param> /// <param name="to">The position of the text. Relative to this UIElement.</param> /// <param name="style">The text style</param> /// <param name="bounds">Rectangle relative to this UIElement which the text should be positioned within</param> /// <param name="align">Alignment of the text within the bounds box.</param> public void DrawLocalString(SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align) { DrawLocalString(batch, text, to, style, bounds, align, Rectangle.Empty); }
/// <summary> /// This utility will draw a line of text onto the UIElement. /// </summary> /// <param name="batch">The SpriteBatch to draw the text onto</param> /// <param name="text">The content of the text</param> /// <param name="to">The position of the text. Relative to this UIElement.</param> /// <param name="style">The text style</param> /// <param name="bounds">Rectangle relative to this UIElement which the text should be positioned within</param> /// <param name="align">Alignment of the text within the bounds box.</param> /// <param name="margin">Margin offset from the bounding box.</param> public void DrawLocalString(SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin) { DrawLocalString(batch, text, to, style, bounds, align, margin, UIElementState.Normal); }
public UIPieMenu(List<VMPieMenuInteraction> pie, VMEntity obj, VMEntity caller, UILotControl parent) { if (FSOEnvironment.UIZoomFactor>1.33f) ScaleX = ScaleY = FSOEnvironment.UIZoomFactor*0.75f; TrueScale = ScaleX *FSOEnvironment.DPIScaleFactor; m_PieButtons = new List<UIButton>(); this.m_Obj = obj; this.m_Caller = caller; this.m_Parent = parent; this.ButtonStyle = new TextStyle { Font = GameFacade.MainFont, Size = 12, Color = new Color(0xA5, 0xC3, 0xD6), SelectedColor = new Color(0x00, 0xFF, 0xFF), CursorColor = new Color(255, 255, 255) }; m_Bg = new UIImage(TextureGenerator.GetPieBG(GameFacade.GraphicsDevice)); m_Bg.SetSize(0, 0); //is scaled up later this.AddAt(0, m_Bg); m_PieTree = new UIPieMenuItem() { Category = true }; for (int i = 0; i < pie.Count; i++) { string[] depth = (pie[i].Name == null)?new string[] { "???" } :pie[i].Name.Split('/'); var category = m_PieTree; //set category to root for (int j = 0; j < depth.Length-1; j++) //iterate through categories { if (category.Children.ContainsKey(depth[j])) { category = category.Children[depth[j]]; } else { var newCat = new UIPieMenuItem() { Category = true, Name = depth[j], Parent = category }; category.Children.Add(depth[j], newCat); category = newCat; } } //we are in the category, put the interaction in here; var item = new UIPieMenuItem() { Category = false, Name = depth[depth.Length - 1], ID = pie[i].ID, Param0 = pie[i].Param0 }; if (!category.Children.ContainsKey(item.Name)) category.Children.Add(item.Name, item); } m_CurrentItem = m_PieTree; m_PieButtons = new List<UIButton>(); RenderMenu(); VMAvatar Avatar = (VMAvatar)caller; m_Head = new SimAvatar(Avatar.Avatar); //talk about confusing... m_Head.StripAllButHead(); initSimHead(); }
public static void CalculateLines(List <UITextEditLine> m_Lines, List <string> newWordsArray, TextStyle TextStyle, float lineWidth, float spaceWidth, Vector2 topLeftIconSpace, float lineHeight) { var currentLine = new StringBuilder(); var currentLineWidth = 0.0f; var currentLineNum = 0; for (var i = 0; i < newWordsArray.Count; i++) { var allowedWidth = (currentLineNum * lineHeight < topLeftIconSpace.Y)?lineWidth - topLeftIconSpace.X:lineWidth; var word = newWordsArray[i]; if (word == "\r\n") { /** Line break **/ m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum, WhitespaceSuffix = 2 }); currentLineNum++; currentLine = new StringBuilder(); currentLineWidth = 0; } else { bool wordWritten = false; while (!wordWritten) //repeat until the full word is written (as part of it can be written each pass if it is too long) { var wordSize = TextStyle.MeasureString(word); if (wordSize.X > allowedWidth) { //SPECIAL CASE, word is bigger than line width and cannot fit on its own line if (currentLineWidth > 0) { //if there are words on this line, we'll start this one on the next to get the most space for it m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum }); currentLineNum++; currentLine = new StringBuilder(); currentLineWidth = 0; } float width = allowedWidth + 1; int j = word.Length; while (width > allowedWidth) { width = TextStyle.MeasureString(word.Substring(0, --j)).X; } currentLine.Append(word.Substring(0, j)); currentLineWidth += width; word = word.Substring(j); m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum, WhitespaceSuffix = 1 }); currentLineNum++; currentLine = new StringBuilder(); currentLineWidth = 0; } else if (currentLineWidth + wordSize.X < allowedWidth) { currentLine.Append(word); if (i != newWordsArray.Count - 1) { currentLine.Append(' '); currentLineWidth += spaceWidth; } currentLineWidth += wordSize.X; wordWritten = true; } else { /** New line **/ m_Lines.Add(new UITextEditLine { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum, WhitespaceSuffix = 1 }); currentLineNum++; currentLine = new StringBuilder(); currentLine.Append(word); currentLineWidth = wordSize.X; if (i != newWordsArray.Count - 1) { currentLine.Append(' '); currentLineWidth += spaceWidth; } wordWritten = true; } } } } m_Lines.Add(new UITextEditLine //add even if length is 0, so we can move the cursor down! { Text = currentLine.ToString(), LineWidth = currentLineWidth, LineNumber = currentLineNum }); var currentIndex = 0; foreach (var line in m_Lines) { line.StartIndex = currentIndex; currentIndex += (line.Text.Length - 1) + line.WhitespaceSuffix; } }