protected void SetHighlightFormat(int index)
        {
            lastSelection = hudChain[index];
            ITextBoard textBoard = lastSelection.Element.TextBoard;

            lastFormat = textBoard.Format;
            textBoard.SetFormatting(textBoard.Format.WithColor(FocusTextColor));
        }
            public SelectionBox(TextCaret caret, Label parent) : base(parent)
            {
                text       = parent.TextBoard;
                this.caret = caret;

                Start          = -Vector2I.One;
                highlightBoard = new MatBoard();
                highlightList  = new List <HighlightBox>();
            }
        protected void SetFocusFormat(int index)
        {
            var        selection = hudChain[index];
            ITextBoard textBoard = selection.Element.TextBoard;

            lastSelection.Item1 = selection;
            lastSelection.Item2 = textBoard.Format;

            textBoard.SetFormatting(textBoard.Format.WithColor(FocusTextColor));
        }
            public TextCaret(TextBox textElement) : base(textElement)
            {
                this.textElement = textElement;
                text             = textElement.TextBoard;
                Size             = new Vector2(1f, 16f);
                Color            = new Color(240, 240, 230);

                blinkTimer = new Stopwatch();
                blinkTimer.Start();
            }
                protected override void Layout()
                {
                    ITextBoard textBoard = textBox.TextBoard;

                    SliderBar slider = verticalScroll.slide;

                    slider.BarColor     = TerminalFormatting.OuterSpace.SetAlphaPct(HudMain.UiBkOpacity);
                    slider.SliderHeight = (textBoard.Size.Y / textBoard.TextSize.Y) * verticalScroll.Height;

                    textBox.Height = Height - header.Height - subheader.Height - Padding.Y;
                    textBox.Width  = Width - verticalScroll.Width - Padding.X;

                    header.Width    = textBox.Width;
                    subheader.Width = textBox.Width;
                }
        /// <summary>
        /// Updates text box formatting in response to input from the toolbar
        /// </summary>
        private void ChangeFormat()
        {
            ITextBoard textBoard = textBox.text.TextBoard;

            textBoard.Format = toolBar.Format;

            // Apply new formatting to selected text range. This will completely overwrite the text
            // formatting of the selected range. Modifying it to only apply the last effect/setting
            // used would require setting formatting per-character. I should probably add a function
            // for that in the future, probably using some kind of bit mask.
            if (!textBox.text.SelectionEmpty)
            {
                textBoard.SetFormatting(textBox.text.SelectionStart, textBox.text.SelectionEnd, toolBar.Format);
            }
        }
        protected virtual void UpdateSelectionFormatting()
        {
            if (lastSelection.Item1 != null)
            {
                ITextBoard textBoard = lastSelection.Item1.Element.TextBoard;
                textBoard.SetFormatting(lastSelection.Item2);
                lastSelection.Item1 = null;
            }

            if ((SelectionIndex == listInput.FocusIndex) && SelectionIndex != -1)
            {
                if (
                    (listInput.KeyboardScroll ^ (SelectionIndex != listInput.HighlightIndex)) ||
                    (!MouseInput.IsMousedOver && SelectionIndex == listInput.HighlightIndex)
                    )
                {
                    if (hudChain[listInput.SelectionIndex].AllowHighlighting)
                    {
                        SetFocusFormat(listInput.SelectionIndex);
                        selectionBox.Color = FocusColor;
                    }
                }
                else
                {
                    selectionBox.Color = HighlightColor;
                }

                highlightBox.Color = HighlightColor;
            }
            else
            {
                if (listInput.KeyboardScroll)
                {
                    if (hudChain[listInput.HighlightIndex].AllowHighlighting)
                    {
                        SetFocusFormat(listInput.HighlightIndex);
                        highlightBox.Color = FocusColor;
                    }
                }
                else
                {
                    highlightBox.Color = HighlightColor;
                }

                selectionBox.Color = HighlightColor;
            }
        }
Example #8
0
            protected override void HandleInput(Vector2 cursorPos)
            {
                /* TextBoard Offsets:
                 *
                 * The TextBoard allows you to set an offset for the text being rendered starting from the
                 * center of the element. Text outside the bounds of the element will not be drawn.
                 * Offset is measured in pixels and updates with changes to scale.
                 *
                 * An offset in the negative direction on the X-axis will offset the text to the left; a positive
                 * offset will move the text to the right.
                 *
                 * On the Y-axis, a negative offset will move the text down and a positive offset will move it in
                 * the opposite direction.
                 *
                 * By default, the visible range of text will start at the first line on the first character.
                 * It starts in the upper left hand corner.
                 */

                ITextBoard  textBoard   = text.TextBoard;
                IMouseInput horzControl = horizontalScroll.slide.MouseInput,
                            vertControl = verticalScroll.slide.MouseInput;

                // If the total width of the text is greater than the size of the element, then I can scroll
                // horiztonally. This value is negative because the text is starts at the right hand side
                // and I need to move it left.
                horizontalScroll.Max = Math.Max(0f, textBoard.TextSize.X - textBoard.Size.X);

                // Same principle, but vertical and moving up. TextBoards start at the first line which means
                // every line that follows lower than the last, so I need to move up.
                verticalScroll.Max = Math.Max(0f, textBoard.TextSize.Y - textBoard.Size.Y);

                // Update the ScrollBar positions to represent the current offset unless they're being clicked.
                if (!horzControl.IsLeftClicked)
                {
                    horizontalScroll.Current = -textBoard.TextOffset.X;
                }

                if (!vertControl.IsLeftClicked)
                {
                    verticalScroll.Current = textBoard.TextOffset.Y;
                }

                textBoard.TextOffset = new Vector2(-horizontalScroll.Current, verticalScroll.Current);
            }
Example #9
0
            protected override void Layout()
            {
                // Update scroll bar and text box size to match changes parent size
                verticalScroll.Height  = Height - horizontalScroll.Height - Padding.Y;
                horizontalScroll.Width = Width - Padding.X;

                text.Width  = Width - verticalScroll.Width - Padding.X;
                text.Height = Height - horizontalScroll.Height - Padding.Y;

                // Update slider size to reflect the amount of text being displayed
                //
                // ScrollBars will automatically hide the slide if the slide and slide bar are the
                // same size, meaning we don't need to worry about hiding the slides if the amount of
                // text is less than or equal to what will fit in the text box.
                ITextBoard textBoard = text.TextBoard;

                horizontalScroll.slide.SliderWidth = (textBoard.Size.X / textBoard.TextSize.X) * horizontalScroll.Width;
                verticalScroll.slide.SliderHeight  = (textBoard.Size.Y / textBoard.TextSize.Y) * verticalScroll.Height;
            }
                protected override void HandleInput(Vector2 cursorPos)
                {
                    ITextBoard  textBoard   = textBox.TextBoard;
                    IMouseInput vertControl = verticalScroll.slide.MouseInput;

                    verticalScroll.Max = Math.Max(0f, textBoard.TextSize.Y - textBoard.Size.Y);

                    // Update the ScrollBar positions to represent the current offset unless they're being clicked.
                    if (!vertControl.IsLeftClicked)
                    {
                        if (IsMousedOver || verticalScroll.IsMousedOver)
                        {
                            Vector2I lineRange = textBoard.VisibleLineRange;

                            if (SharedBinds.MousewheelUp.IsPressed || SharedBinds.UpArrow.IsNewPressed || SharedBinds.UpArrow.IsPressedAndHeld)
                            {
                                textBoard.MoveToChar(new Vector2I(lineRange.X - 1, 0));
                            }
                            else if (SharedBinds.MousewheelDown.IsPressed || SharedBinds.DownArrow.IsNewPressed || SharedBinds.DownArrow.IsPressedAndHeld)
                            {
                                textBoard.MoveToChar(new Vector2I(lineRange.Y + 1, 0));
                            }
                            else if (SharedBinds.PageUp.IsNewPressed || SharedBinds.PageUp.IsPressedAndHeld)
                            {
                                // A hacky, somewhat inefficient solution, but it works well
                                textBoard.MoveToChar(new Vector2I(0, 0));
                                textBoard.MoveToChar(new Vector2I(lineRange.X - 1, 0));
                            }
                            else if (SharedBinds.PageDown.IsNewPressed || SharedBinds.PageDown.IsPressedAndHeld)
                            {
                                textBoard.MoveToChar(new Vector2I(textBoard.Count - 1, 0));
                                textBoard.MoveToChar(new Vector2I(lineRange.Y + 1, 0));
                            }
                        }

                        verticalScroll.Current = textBoard.TextOffset.Y;
                    }

                    textBoard.TextOffset = new Vector2(0, verticalScroll.Current);
                }
Example #11
0
            /// <summary>
            /// Updates associated text label for the entry in the menu
            /// </summary>
            public virtual void UpdateText(bool isHighlighted, bool isDuplicating)
            {
                ITextBoard nameTB         = Element.name.TextBoard,
                           valueTB        = Element.value.TextBoard,
                           postTB         = Element.postfix.TextBoard;
                IBlockMember  blockMember = AssocMember;
                StringBuilder name        = blockMember.Name,
                              disp        = blockMember.FormattedValue,
                              status      = blockMember.StatusText;

                GlyphFormat dupeCrossFormat, bodyFormat, valueFormat;

                if (PropertyOpen)
                {
                    dupeCrossFormat = QuickActionMenu.selectedFormat;
                    bodyFormat      = QuickActionMenu.selectedFormat;
                    valueFormat     = QuickActionMenu.selectedFormat;
                }
                else
                {
                    dupeCrossFormat = QuickActionMenu.dupeCrossFormat;
                    bodyFormat      = QuickActionMenu.bodyFormat;
                    valueFormat     = isHighlighted ? QuickActionMenu.highlightFormat : QuickActionMenu.valueFormat;
                }

                // Update Name
                nameTB.Clear();

                if (isDuplicating && IsSelectedForDuplication)
                {
                    nameTB.Append("+ ", dupeCrossFormat);
                }

                if (name != null)
                {
                    textBuf.Clear();
                    textBuf.AppendSubstringMax(name, maxEntryCharCount);
                    nameTB.Append(textBuf, bodyFormat);

                    if (disp != null || status != null)
                    {
                        nameTB.Append(": ", bodyFormat);
                    }
                }

                // Update Value
                if (!Element.value.InputOpen && !WaitingForChatInput)
                {
                    valueTB.Clear();

                    if (disp != null)
                    {
                        var colorMember = AssocMember as IBlockNumericValue <Color>;
                        valueTB.Append(disp, valueFormat);
                    }
                }

                // Update Postfix
                postTB.Clear();

                if (status != null)
                {
                    postTB.Append(' ', bodyFormat);
                    postTB.Append(status, bodyFormat);
                }
            }