コード例 #1
0
ファイル: CarGame.cs プロジェクト: jo411/CarPrototype
        void addDebug()
        {
            if (showDebug)
            {
                var diagnosticData = new GeonBit.UI.Entities.Paragraph("", GeonBit.UI.Entities.Anchor.BottomLeft, offset: Vector2.One * 10f, scale: 0.7f);
                diagnosticData.BeforeDraw = (GeonBit.UI.Entities.Entity entity) =>
                {
                    diagnosticData.Text = Diagnostic.Instance.GetReportString();
                };
                UserInterface.AddEntity(diagnosticData);

                Diagnostic.Instance.DebugRenderPhysics = true;
            }
        }
コード例 #2
0
ファイル: CheckBox.cs プロジェクト: smiracle/GeonBit.UI
 /// <summary>
 /// Special init after deserializing entity from file.
 /// </summary>
 internal protected override void InitAfterDeserialize()
 {
     base.InitAfterDeserialize();
     TextParagraph = Find("_checkbox_text") as Paragraph;
     TextParagraph._hiddenInternalEntity = true;
 }
コード例 #3
0
 /// <summary>
 /// Called for every new paragraph entity created as part of the list, to allow children classes
 /// to add extra processing etc to list labels.
 /// </summary>
 /// <param name="paragraph">The newly created paragraph once ready (after added to list container).</param>
 protected virtual void OnCreatedListParagraph(Paragraph paragraph)
 {
 }
コード例 #4
0
        /// <summary>
        /// When list is resized (also called on init), create the labels to show item values and init graphical stuff.
        /// </summary>
        protected virtual void OnResize()
        {
            // if not visible, skip
            if (!IsVisible())
            {
                _hadResizeWhileNotVisible = true;
                return;
            }

            // clear the _hadResizeWhileNotVisible flag
            _hadResizeWhileNotVisible = false;

            // remove all children before re-creating them
            ClearChildren();

            // remove previous paragraphs list
            _paragraphs.Clear();

            // make sure destination rect is up-to-date
            UpdateDestinationRects();

            // calculate paragraphs quantity
            int i = 0;

            while (true)
            {
                // create and add new paragraph
                Paragraph paragraph = UserInterface.DefaultParagraph(".", Anchor.Auto, size: new Vector2(0, 40));
                paragraph.PromiscuousClicksMode = true;
                paragraph.WrapWords             = false;
                paragraph.UpdateStyle(DefaultParagraphStyle);
                paragraph.Scale        = paragraph.Scale * ItemsScale;
                paragraph.SpaceAfter   = paragraph.SpaceAfter + new Vector2(0, ExtraSpaceBetweenLines);
                paragraph.AttachedData = new ParagraphData(this, i++);
                paragraph.UseActualSizeForCollision = false;
                AddChild(paragraph);
                _paragraphs.Add(paragraph);
                OnCreatedListParagraph(paragraph);

                // add callback to selection
                paragraph.OnClick = (Entity entity) =>
                {
                    ParagraphData data = (ParagraphData)entity.AttachedData;
                    if (!data.list.LockSelection)
                    {
                        data.list.Select(data.relativeIndex, true);
                    }
                };

                // to calculate paragraph actual bottom
                paragraph.UpdateDestinationRects();

                // if out of list bounderies remove this paragraph and stop
                if ((paragraph.GetActualDestRect().Bottom > _destRect.Bottom - _scaledPadding.Y) || i > _list.Count)
                {
                    RemoveChild(paragraph);
                    _paragraphs.Remove(paragraph);
                    break;
                }
            }

            // add scrollbar last, but only if needed
            if (_paragraphs.Count > 0 && _paragraphs.Count < _list.Count)
            {
                // add scrollbar to list
                AddChild(_scrollbar, false);

                // calc max scroll value
                _scrollbar.Max = (uint)(_list.Count - _paragraphs.Count);
                if (_scrollbar.Max < 2)
                {
                    _scrollbar.Max = 2;
                }
                _scrollbar.StepsCount = _scrollbar.Max;
                _scrollbar.Visible    = true;
            }
            // if no scrollbar is needed, hide it
            else
            {
                _scrollbar.Visible = false;
                if (_scrollbar.Value > 0)
                {
                    _scrollbar.Value = 0;
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Draw the entity.
        /// </summary>
        /// <param name="spriteBatch">Sprite batch to draw on.</param>
        /// <param name="phase">The phase we are currently drawing.</param>
        override protected void DrawEntity(SpriteBatch spriteBatch, DrawPhase phase)
        {
            // call base draw function to draw the panel part
            base.DrawEntity(spriteBatch, phase);

            // get which paragraph we currently show - real or placeholder
            bool      showPlaceholder = !(IsFocused || _value.Length > 0);
            Paragraph currParagraph   = showPlaceholder ? PlaceholderParagraph : TextParagraph;

            // get actual processed string
            _actualDisplayText = PrepareInputTextForDisplay(showPlaceholder);

            // init some value for carret calculation
            Vector2   charSize     = TextParagraph.GetCharacterActualSize();
            int       caretHeight  = (int)charSize.Y;
            Rectangle caretDstRect = new Rectangle(0, 0, CARET_WIDTH, caretHeight);

            if (_multiLine)
            {
                // if visible, calculate carret position for multiline TextInput
                if (IsCaretCurrentlyVisible)
                {
                    caretDstRect.Location  = CalculateCaretPositionForMultiline(_actualDisplayText, _caret);
                    caretDstRect.Location += TextParagraph._actualDestRect.Location;
                }

                // at which line the text is starting to be shown
                int scrollBarLineOffset = 0;

                // handle scrollbar visibility and max
                if (_actualDisplayText != null && _destRectInternal.Height > 0)
                {
                    // get how many lines can fit in the textbox and how many lines display text actually have
                    int linesFit    = GetNumLinesFitInTheTextBox(currParagraph);
                    int linesInText = _actualDisplayText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Length;

                    // if there are more lines than can fit, show scrollbar and manage scrolling:
                    if (linesInText > linesFit)
                    {
                        // fix paragraph width to leave room for the scrollbar
                        currParagraph.Size = new Vector2(_destRectInternal.Width / GlobalScale - 20, 0);

                        // update text to fit scrollbar. first, rebuild the text with just the visible segment
                        List <string> lines = new List <string>(_actualDisplayText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
                        int           from  = System.Math.Min(_scrollbar.Value, lines.Count - 1);
                        int           size  = System.Math.Min(linesFit, lines.Count - from);
                        lines = lines.GetRange(from, size);
                        _actualDisplayText = string.Join("\n", lines);
                        currParagraph.Text = _actualDisplayText;

                        // get at which line the text is starting to be shown
                        scrollBarLineOffset = from;
                    }
                    // if no need for scrollbar make it invisible
                    else
                    {
                        currParagraph.Size = Vector2.Zero;
                        _scrollbar.Visible = false;
                    }
                }

                if (IsCaretCurrentlyVisible)
                {
                    // move the carret so it corresponds to the scroll position
                    caretDstRect.Y -= (int)charSize.Y * scrollBarLineOffset;
                }
            }
            else
            {
                // if visible, calculate carret position for single line TextInput
                if (IsCaretCurrentlyVisible)
                {
                    caretDstRect.X = (int)(TextParagraph._actualDestRect.X + charSize.X * (_caret == -1 ? _value.Length : _caret) - CARET_WIDTH / 2);
                    caretDstRect.Y = TextParagraph._actualDestRect.Y;
                }
            }

            // set placeholder and main text visibility based on current value
            TextParagraph.Visible        = !showPlaceholder;
            PlaceholderParagraph.Visible = showPlaceholder;

            // if visible and in the visible area, draw carret at calculated position
            bool carretIsInVisibleArea = caretDstRect.Y >= _destRectInternal.Y && caretDstRect.Y < _destRectInternal.Y + _destRectInternal.Height;

            if (IsCaretCurrentlyVisible && ((_multiLine && carretIsInVisibleArea) || !_multiLine))
            {
                caretDstRect.X -= CARET_WIDTH / 2;
                spriteBatch.Draw(Resources.WhiteTexture, caretDstRect, DrawUtils.rectangle_1x1, TextParagraph.FillColor);
            }
        }