Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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()
        {
            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);
                }
            }
        }
Esempio n. 4
0
        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;
                }
            }
        }
Esempio n. 5
0
        private void RecalculateSize()
        {
            Vector2 _size = UiStateManager.MeasureString(text);

            size = new Point((int)_size.X, (int)_size.Y);
        }
Esempio n. 6
0
        public int GetCharacterPixel(int position, string text)
        {
            Vector2 _tmp = UiStateManager.MeasureString(text.Substring(0, position));

            return((int)_tmp.X);
        }