public override void Draw() { lines = text.Split('\n'); RecalculateSize(); if (AlignRight) { int _heightOffset = 0; for (int i = 0; i < lines.Length; i++) { //Empty check if (lines[i] != null && lines[i].Length > 0) { //Get the size Vector2 _size = UiStateManager.MeasureString(lines[i]); UiStateManager.DrawText(location.X - _size.X, location.Y + _heightOffset, color, lines[i]); _heightOffset += UiStateManager.gameFont.LineSpacing; } } } else { UiStateManager.DrawText(location.X, location.Y, color, text); } }
public override void Draw() { if (base.screenVisible) { _size = UiStateManager.MeasureString(text); //Draw the button if (enabled) { UiTexture img = TextureManager.GetUiUv("button_neutral"); if (isHovered && Parent.FocusedComponent != null && Parent.FocusedComponent == this) { if (isClicked) { img = TextureManager.GetUiUv("button_clicked"); } else { img = TextureManager.GetUiUv("button_hover"); } } UiStateManager.Draw9SplicedButton(img, this); UiStateManager.DrawText(location.X + size.X / 2 - _size.X / 2, location.Y + size.Y / 2 - _size.Y / 2, buttonColor, text); } else { UiTexture img = TextureManager.GetUiUv("button_disabled"); UiStateManager.Draw9SplicedButton(img, this); UiStateManager.DrawText(location.X + size.X / 2 - _size.X / 2, location.Y + size.Y / 2 - _size.Y / 2, buttonDisabledColor, text); } } }
public override void Draw() { Rectangle source = new Rectangle((int)(UV.X * image.Width), (int)(UV.Y * image.Height), (int)((UV.Z - UV.X) * image.Width), (int)((UV.W - UV.Y) * image.Height)); if (size != Point.Zero) { UiStateManager.DrawImage(new Rectangle(location.X, location.Y, size.X, size.Y), source, image, imageColor); } else { UiStateManager.DrawImage(new Rectangle(location.X, location.Y, image.Width, image.Height), source, image, imageColor); } }
public override void Draw() { if (base.screenVisible) { _size = UiStateManager.MeasureString(text); UiTexture img = TextureManager.GetUiUv("button_disabled"); UiStateManager.Draw9SplicedButton(img, this); //Draw the button if (enabled) { img = TextureManager.GetUiUv("button_neutral"); if (isHovered && Parent.FocusedComponent != null && Parent.FocusedComponent == this) { if (isClicked) { img = TextureManager.GetUiUv("button_clicked"); } else { img = TextureManager.GetUiUv("button_hover"); } } if (isSliding) { UiStateManager.Draw9SplicedButton(img, new Point(HandleWidth * GameSettings.UIScale, size.Y), new Point(FastMath.FastClamp(InputManager.MouseX + MouseOffset.X, location.X, location.X + size.X - HandleWidth * GameSettings.UIScale), location.Y)); } else { //location.X = component.location.X + % of slider value * component.size.X handleX = FastMath.FastClamp(location.X + (_value * size.X / (_maxValue - _minValue)), location.X, location.X + size.X - HandleWidth * GameSettings.UIScale); UiStateManager.Draw9SplicedButton(img, new Point(HandleWidth * GameSettings.UIScale, size.Y), new Point(handleX, location.Y)); } UiStateManager.DrawText(location.X + size.X / 2 - _size.X / 2, location.Y + size.Y / 2 - _size.Y / 2, buttonColor, text); } else { UiStateManager.Draw9SplicedButton(img, new Point(HandleWidth * GameSettings.UIScale, size.Y), new Point(FastMath.FastClamp(location.X + (_value * size.X / (_maxValue - _minValue)), location.X, location.X + size.X - HandleWidth * GameSettings.UIScale), location.Y)); UiStateManager.DrawText(location.X + size.X / 2 - _size.X / 2, location.Y + size.Y / 2 - _size.Y / 2, buttonDisabledColor, text); } } }
public override void Draw() { if (_stack.ItemID != 0) { //Draw the graphic if (size != Point.Zero) { UiStateManager.DrawImage(new Rectangle(location.X, location.Y, size.X, size.Y), image, Color.White); } else { UiStateManager.DrawImage(location, image, Color.White); } //Overlay the count if (_stack.ItemCount > 1) { Vector2 textSize = UiStateManager.gameFont.MeasureString(_stack.ItemCount.ToString()); UiStateManager.DrawText(new Vector2(location.X + size.X - textSize.X, location.Y + size.Y - textSize.Y), _stack.ItemCount.ToString()); } } }
public void DrawText(string text, Color color, int leftMostCharacter, int caretPosition, bool CaretVisible) { string finalString = text.Substring(leftMostCharacter); DrawStringClip(size.X - 2 * paddingX + location.X, UiStateManager.gameFont, finalString, new Vector2(location.X + paddingX * GameSettings.UIScale, location.Y + paddingY * GameSettings.UIScale), color, 0.0f, Vector2.Zero, new Vector2(GameSettings.UITextScale), SpriteEffects.None, 0); if (CaretVisible) { Vector2 textWidth = UiStateManager.gameFont.MeasureString("L"); UiStateManager.DrawImage(new Rectangle( location.X + paddingX * GameSettings.UIScale + (int)UiStateManager.gameFont.MeasureString(text.Substring(leftMostCharacter, caretPosition - leftMostCharacter)).X, //Width location.Y + paddingY, 2 * GameSettings.UIScale, FastMath.FastClamp((int)(textWidth.Y * GameSettings.UIScale), 0, size.Y - 2 * paddingY)), TextureLoader.getWhitePixel(), placeholderColor); } }
public override void Draw() { if (screenVisible) { //If the uiscale updated, redraw the text //Background image UiTexture img = TextureManager.GetUiUv("button_disabled"); UiStateManager.Draw9SplicedButton(img, this); //Check if we have text or we're focused if (text != "" || isEditing) { bool caretVisible = caretTimer * 2 % caretAnimationTime > 0.5f; DrawText(text, textColor, scrollPosition, caretPosition, caretVisible && isEditing); //Don't display the caret if we aren't editing } else { //Placeholder DrawText(placeholderText, placeholderColor, 0, -1, false); } } }
public void GetCaretUnderMouse() { //Calculate the character index of where we clicked int relativeX = InputManager.MouseX - location.X; //mouse relative to the textbox //now that we have the position of the cursor, calculate the index of the caret //get the string on screen string renderStr = text.Substring(scrollPosition); int selectedIndex = scrollPosition; for (int i = 0; i < renderStr.Length; i++) { var txVisible = renderStr.Substring(0, i + 1); var currentChar = renderStr.Substring(i, FastMath.FastClamp(i + 1, 0, 1)); var txtSize = UiStateManager.MeasureString(txVisible); var charWidth = UiStateManager.MeasureString(currentChar); if (txtSize.X + charWidth.X < relativeX) { selectedIndex++; } if (txtSize.X + charWidth.X >= relativeX) { this.caretPosition = selectedIndex; break; } if (i == renderStr.Length - 1) { this.caretPosition = renderStr.Length; break; } } }
private void RecalculateSize() { Vector2 _size = UiStateManager.MeasureString(text); size = new Point((int)_size.X, (int)_size.Y); }
public void DrawStringClip(int width, BMFont bmFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { if (bmFont == null) { throw new ArgumentNullException(nameof(bmFont)); } if (text == null) { throw new ArgumentNullException(nameof(text)); } Matrix temp; Matrix transform; Matrix.CreateScale(scale.X, scale.Y, 1, out temp); Matrix.CreateRotationZ(rotation, out transform); Matrix.Multiply(ref temp, ref transform, out transform); //character index int prevMaxX = -1; int index = 0; int rightMostCharacter = 0; bool isHighlighted = false; int selectionEdge = caretPosition + selectedPosition; int minSelection = Math.Min(caretPosition, selectedPosition); int maxSelection = Math.Max(caretPosition, selectedPosition); bmFont.ProcessChars(text, (actual, drawPos, data, previous) => { var sourceRectangle = new Rectangle(data.X, data.Y, data.Width, data.Height); Vector2.Transform(ref drawPos, ref transform, out drawPos); var destRectangle = new Rectangle((int)(position.X + drawPos.X), (int)(position.Y + drawPos.Y), (int)(data.Width * scale.X), (int)(data.Height * scale.Y)); //Check if the character is highlighted isHighlighted = text.Length > 0 && //text isnt empty selectedPosition != -1 && //we have highlighted something (maxSelection > index && minSelection <= index); //selection edge is greater than caret position //Check if it clips rightMostCharacter = destRectangle.Right; if (rightMostCharacter > width && destRectangle.X < width) //if the rectangle passes through width { //recalculate the rectangles //width * percentage of covered area = new width sourceRectangle.Width = (int)(sourceRectangle.Width * (float)(width - destRectangle.X) / destRectangle.Width); destRectangle.Width = width - destRectangle.X; } //Drawing if (isHighlighted) { if (prevMaxX == -1) { prevMaxX = destRectangle.X; } UiStateManager.DrawImage(new Rectangle(prevMaxX, location.Y + paddingY, destRectangle.Width + GameSettings.UIScale + (destRectangle.X - prevMaxX), size.Y - 2 * paddingY), new Rectangle(0, 0, 1, 1), TextureLoader.getWhitePixel(), HighlightColor); prevMaxX = prevMaxX + destRectangle.Width + GameSettings.UIScale + (destRectangle.X - prevMaxX); } UiStateManager.SpriteBatch.Draw(bmFont.Texture, destRectangle, sourceRectangle, color, rotation, origin, effects, layerDepth); index++; }, null); }
public int GetCharacterPixel(int position, string text) { Vector2 _tmp = UiStateManager.MeasureString(text.Substring(0, position)); return((int)_tmp.X); }