public static void DrawToolTip(SpriteBatch spriteBatch, string toolTip, Rectangle targetElement) { if (Tutorials.Tutorial.ContentRunning) { return; } int width = (int)(400 * GUI.Scale); int height = (int)(18 * GUI.Scale); Point padding = new Point((int)(20 * GUI.Scale), (int)(7 * GUI.Scale)); if (toolTipBlock == null || (string)toolTipBlock.userData != toolTip) { toolTipBlock = new GUITextBlock(new RectTransform(new Point(width, height), null), toolTip, font: GUI.SmallFont, wrap: true, style: "GUIToolTip"); toolTipBlock.RectTransform.NonScaledSize = new Point( (int)(GUI.SmallFont.MeasureString(toolTipBlock.WrappedText).X + padding.X), (int)(GUI.SmallFont.MeasureString(toolTipBlock.WrappedText).Y + padding.Y)); toolTipBlock.userData = toolTip; } toolTipBlock.RectTransform.AbsoluteOffset = new Point(targetElement.Center.X, targetElement.Bottom); if (toolTipBlock.Rect.Right > GameMain.GraphicsWidth - 10) { toolTipBlock.RectTransform.AbsoluteOffset -= new Point(toolTipBlock.Rect.Width, 0); } if (toolTipBlock.Rect.Bottom > GameMain.GraphicsHeight - 10) { toolTipBlock.RectTransform.AbsoluteOffset -= new Point( (targetElement.Width / 2) * Math.Sign(targetElement.Center.X - toolTipBlock.Center.X), toolTipBlock.Rect.Bottom - (GameMain.GraphicsHeight - 10)); } toolTipBlock.SetTextPos(); toolTipBlock.DrawManually(spriteBatch); }
protected override void Draw(SpriteBatch spriteBatch) { if (!Visible) { return; } base.Draw(spriteBatch); // Frame is not used in the old system. frame?.DrawManually(spriteBatch); textBlock.DrawManually(spriteBatch); if (Selected) { if (caretVisible) { GUI.DrawLine(spriteBatch, new Vector2(Rect.X + (int)caretPos.X + 2, Rect.Y + caretPos.Y + 3), new Vector2(Rect.X + (int)caretPos.X + 2, Rect.Y + caretPos.Y + Font.MeasureString("I").Y - 3), CaretColor ?? textBlock.TextColor * (textBlock.TextColor.A / 255.0f)); } if (selectedCharacters > 0) { DrawSelectionRect(spriteBatch); } //GUI.DrawString(spriteBatch, new Vector2(100, 0), selectedCharacters.ToString(), Color.LightBlue, Color.Black); //GUI.DrawString(spriteBatch, new Vector2(100, 20), selectionStartIndex.ToString(), Color.White, Color.Black); //GUI.DrawString(spriteBatch, new Vector2(140, 20), selectionEndIndex.ToString(), Color.White, Color.Black); //GUI.DrawString(spriteBatch, new Vector2(100, 40), selectedText.ToString(), Color.Yellow, Color.Black); //GUI.DrawString(spriteBatch, new Vector2(100, 60), $"caret index: {CaretIndex.ToString()}", Color.Red, Color.Black); //GUI.DrawString(spriteBatch, new Vector2(100, 80), $"caret pos: {caretPos.ToString()}", Color.Red, Color.Black); //GUI.DrawString(spriteBatch, new Vector2(100, 100), $"caret screen pos: {CaretScreenPos.ToString()}", Color.Red, Color.Black); //GUI.DrawString(spriteBatch, new Vector2(100, 120), $"text start pos: {(textBlock.TextPos - textBlock.Origin).ToString()}", Color.White, Color.Black); //GUI.DrawString(spriteBatch, new Vector2(100, 140), $"cursor pos: {PlayerInput.MousePosition.ToString()}", Color.White, Color.Black); } }
public static void DrawToolTip(SpriteBatch spriteBatch, string toolTip, Rectangle targetElement) { int width = 400; if (toolTipBlock == null || (string)toolTipBlock.userData != toolTip) { toolTipBlock = new GUITextBlock(new RectTransform(new Point(width, 18), null), toolTip, font: GUI.SmallFont, wrap: true, style: "GUIToolTip"); toolTipBlock.RectTransform.NonScaledSize = new Point( (int)(GUI.SmallFont.MeasureString(toolTipBlock.WrappedText).X + 20), toolTipBlock.WrappedText.Split('\n').Length * 18 + 7); toolTipBlock.userData = toolTip; } toolTipBlock.RectTransform.AbsoluteOffset = new Point(targetElement.Center.X, targetElement.Bottom); if (toolTipBlock.Rect.Right > GameMain.GraphicsWidth - 10) { toolTipBlock.RectTransform.AbsoluteOffset -= new Point(toolTipBlock.Rect.Width, 0); } if (toolTipBlock.Rect.Bottom > GameMain.GraphicsHeight - 10) { toolTipBlock.RectTransform.AbsoluteOffset -= new Point( (targetElement.Width / 2) * Math.Sign(targetElement.Center.X - toolTipBlock.Center.X), toolTipBlock.Rect.Bottom - (GameMain.GraphicsHeight - 10)); } toolTipBlock.SetTextPos(); toolTipBlock.DrawManually(spriteBatch); }