Ejemplo n.º 1
0
 private void SetScrollValueByOffset(MyGuiControlListboxScrollBar scrollBar, int offset, int displayCount)
 {
     scrollBar.SetScrollValue((float)(offset + displayCount) / (float)displayCount);
 }
Ejemplo n.º 2
0
        public MyGuiControlListbox(IMyGuiControlsParent parent, Vector2 position, Vector2 size, Vector4 backgroundColor, StringBuilder toolTip, float textScale,
            int columns, int displayRowsCount, int displayColumnsCount, bool supportPicture, bool verticalScrolling, bool horizontalScrolling,
            MyTexture2D backgroundTexture, MyTexture2D itemBackgroundTexture, MyTexture2D verticalScrollBarTexture, MyTexture2D horizontalScrollBarTexture,
            int borderSize, int itemBorderSize, Vector4 itemColor, float paddingTop, float paddingRight, float paddingBottom, float paddingLeft, float itemPaddingRight, float itemPaddingBottom, float sliderOffset, float sliderOffsetTop = 0, float sizeXincrease = 0, float sliderLengthIncrease = 0)
            : base(parent, position, size, backgroundColor, toolTip, backgroundTexture, null, null, true)
        {
            System.Diagnostics.Debug.Assert(columns > 0);
            System.Diagnostics.Debug.Assert(displayRowsCount > 0);
            System.Diagnostics.Debug.Assert(displayColumnsCount > 0);
            m_itemsCount = 0;
            m_doubleClickTimer = 0;
            m_canHandleKeyboardActiveControl = true;
            m_rows = new List<MyGuiControlListboxRow>();
            m_columns = columns;
            m_textScale = textScale;
            m_displayRowsCount = displayRowsCount;
            m_displayColumnsCount = displayColumnsCount;
            m_supportIcon = supportPicture;
            m_itemSize = size;
            m_innerItemSize = size;
            m_topLeftPosition = m_position - m_itemSize / 2.0f;
            m_rowHeight = m_itemSize.Y + itemPaddingBottom;
            m_columnWidth = m_itemSize.X + itemPaddingRight;
            m_borderSize = borderSize;
            m_itemBorderSize = itemBorderSize;
            m_itemTexture = itemBackgroundTexture;
            m_itemColor = itemColor;
            m_paddingTop = paddingTop;
            m_paddingRight = paddingRight;
            m_paddingBottom = paddingBottom;
            m_paddingLeft = paddingLeft;
            m_sliderOffset = sliderOffset;
            m_sliderOffsetTop = sliderOffsetTop;
            m_borderSizeListBox = MyGuiManager.GetNormalizedSizeFromScreenSize(new Vector2(m_borderSize, m_borderSize)).X;
            m_borderSizeItem = MyGuiManager.GetNormalizedSizeFromScreenSize(new Vector2(m_itemBorderSize, m_itemBorderSize)).X;
            m_sizeXincrease = sizeXincrease;
            m_sliderLengthIncrease = sliderLengthIncrease;

            if (verticalScrolling)
            {
                Vector2 scrollBarSize = MyGuiConstants.COMBOBOX_VSCROLLBAR_SIZE;
                Vector2 scrollBarPosition =     m_topLeftPosition
                                            + new Vector2(m_borderSizeListBox, m_borderSizeListBox) +
                                            new Vector2(m_paddingLeft, m_paddingTop) + new Vector2(m_displayColumnsCount * m_columnWidth, 0f) + new Vector2(m_sliderOffset, m_sliderOffsetTop);
                m_verticalScrollBar = new MyGuiControlListboxScrollBar(m_parent, scrollBarPosition, scrollBarSize, m_backgroundColor, MyGuiConstants.LISTBOX_SCROLLBAR_COLOR, MyScrollDirection.Vertical, verticalScrollBarTexture);
                m_verticalScrollBar.ScrollValueChanged += OnScrollValueChanged;
            }

            if (horizontalScrolling)
            {
                Vector2 scrollBarSize = new Vector2(m_displayColumnsCount * m_columnWidth, MyGuiConstants.LISTBOX_SCROLLBAR_WIDTH);
                Vector2 scrollBarPosition = m_topLeftPosition
                    + new Vector2(m_borderSizeListBox, m_borderSizeListBox) + new Vector2(m_paddingLeft, m_paddingTop)
                    + new Vector2(0f, m_rows.Count * m_rowHeight);
                float scrollBarMaxValue = Math.Max((float)m_columns / (float)m_displayColumnsCount, 1.0f);
                m_horizontalScrollBar = new MyGuiControlListboxScrollBar(m_parent, scrollBarPosition, scrollBarSize, m_backgroundColor, MyGuiConstants.LISTBOX_SCROLLBAR_COLOR, MyScrollDirection.Horizontal, horizontalScrollBarTexture);
                m_horizontalScrollBar.ScrollValueChanged += OnScrollValueChanged;
                m_horizontalScrollBar.InitializeScrollBar(scrollBarMaxValue);
            }

            RecalculateRealSize();
            RecalculateRealPosition();

            m_selectedItemIndices = new List<Point>();
            DisplayHighlight = true;
            ShowScrollBarOnlyWhenNeeded = false;
        }