コード例 #1
0
ファイル: MyTreeView.cs プロジェクト: whztt07/Miner-Wars-2081
        public void Draw()
        {
            //  End our standard sprite batch
            MyGuiManager.EndSpriteBatch();

            //  Draw the rectangle(basically the opened area) to stencil buffer to be used for clipping partial item
            MyGuiManager.DrawStencilMaskRectangle(new MyRectangle2D(m_body.GetPosition(), m_body.GetSize()), MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);

            //  Set up the stencil operation and parameters
            MyGuiManager.BeginSpriteBatch_StencilMask();

            m_body.Draw();

            //  End stencil-mask batch, and restart the standard sprite batch
            //MyGuiManager.EndSpriteBatch();
            MyGuiManager.EndSpriteBatch_StencilMask();
            MyGuiManager.BeginSpriteBatch();

            Color borderColor = m_control.GetColorAfterTransitionAlpha(MyGuiConstants.TREEVIEW_VERTICAL_LINE_COLOR);

            MyGUIHelper.OutsideBorder(m_position, m_size, 2, borderColor);

            m_vScrollbar.Draw();
            m_hScrollbar.Draw();
        }
コード例 #2
0
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captured = false;

            if (!CanScroll())
            {
                return(false);
            }

            switch (m_state)
            {
            case State.READY:
                if (input.IsNewLeftMousePressed() && MyGUIHelper.Contains(m_position + GetCarretPosition(), m_caretSize, MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y))
                {
                    captured    = true;
                    m_state     = State.DRAG;
                    m_dragClick = MyGuiManager.MouseCursorPosition;
                }
                break;

            case State.DRAG:
                if (!input.IsLeftMousePressed())
                {
                    m_state = State.READY;
                }
                else
                {
                    ChangeValue((MyGuiManager.MouseCursorPosition.X - m_dragClick.X) * (m_max - m_page) / (m_size.X - m_caretSize.X));
                    m_dragClick = MyGuiManager.MouseCursorPosition;
                }
                captured = true;
                break;
            }
            return(captured);
        }
コード例 #3
0
        public void DrawDraged(Vector2 position)
        {
            if ((m_icon != null && m_icon.LoadState == LoadState.Loaded) || Text != null)
            {
                if (m_icon != null)
                {
                    MyTexture2D texture = m_icon;
                    if (texture == null)
                    { // texture is still being loaded on other thread
                        DrawLoadingIcon(Vector4.One, GetIconPosition());
                    }
                    else
                    {
                        MyGUIHelper.OutsideBorder(position + GetIconPosition(), m_iconSize, 2, MyGuiConstants.TOOL_TIP_BORDER_COLOR);
                        MyGuiManager.DrawSpriteBatch(m_icon,
                                                     position + GetIconPosition(), m_iconSize,
                                                     Color.White, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                    }
                }
                else if (Text != null)
                {
                    var textRect = MyGuiManager.MeasureString(MyGuiManager.GetFontMinerWarsBlue(), Text, position + GetTextPosition(), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                    MyGUIHelper.OutsideBorder(textRect.LeftTop, textRect.Size, 2, MyGuiConstants.TOOL_TIP_BORDER_COLOR);
                    MyGUIHelper.FillRectangle(textRect.LeftTop, textRect.Size, TreeView.GetColor(MyGuiConstants.TREEVIEW_SELECTED_ITEM_COLOR));

                    Color textColor = TreeView.GetColor(MyGuiConstants.CONTROL_MOUSE_OVER_BACKGROUND_COLOR_MULTIPLIER);
                    MyGuiManager.DrawString(MyGuiManager.GetFontMinerWarsBlue(), Text,
                                            position + GetTextPosition(),
                                            0.8f, textColor, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                }
            }
        }
コード例 #4
0
        public void Draw()
        {
            if (!Visible || !TreeView.Contains(m_currentOrigin, m_currentSize))
            {
                return;
            }

            bool    isHighlighted      = TreeView.HooveredItem == this;
            Vector2 expandIconPosition = GetExpandIconPosition();
            Vector2 iconPosition       = GetIconPosition();
            Vector2 textPosition       = GetTextPosition();

            Vector4 baseColor = Enabled ? Vector4.One : MyGuiConstants.TREEVIEW_DISABLED_ITEM_COLOR;

            if (TreeView.FocusedItem == this)
            {
                Color selectedColor = TreeView.GetColor(MyGuiConstants.TREEVIEW_SELECTED_ITEM_COLOR * baseColor);
                if (TreeView.WholeRowHighlight())
                {
                    MyGUIHelper.FillRectangle(new Vector2(TreeView.GetPosition().X, m_currentOrigin.Y), new Vector2(TreeView.GetBodySize().X, m_currentSize.Y), selectedColor);
                }
                else
                {
                    MyGUIHelper.FillRectangle(m_currentOrigin, m_currentSize, selectedColor);
                }
            }

            if (GetItemCount() > 0)
            {
                Vector4 expandColor = (isHighlighted) ? baseColor * MyGuiConstants.CONTROL_MOUSE_OVER_BACKGROUND_COLOR_MULTIPLIER : baseColor;
                MyGuiManager.DrawSpriteBatch(IsExpanded ? m_collapseIcon : m_expandIcon,
                                             m_currentOrigin + expandIconPosition, m_expandIconSize,
                                             TreeView.GetColor(expandColor), MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
            }

            if (m_icon != null && m_icon.LoadState != LoadState.Error)
            {
                if (m_icon == null)
                { // texture is still being loaded on other thread
                    DrawLoadingIcon(baseColor, iconPosition);
                }
                else
                {
                    MyGuiManager.DrawSpriteBatch(m_icon, m_currentOrigin + iconPosition, m_iconSize,
                                                 TreeView.GetColor(baseColor),
                                                 MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
                }
            }

            Vector4 textColor = (isHighlighted) ? MyGuiConstants.CONTROL_MOUSE_OVER_BACKGROUND_COLOR_MULTIPLIER * baseColor : MyGuiConstants.TREEVIEW_TEXT_COLOR * baseColor;

            MyGuiManager.DrawString(MyGuiManager.GetFontMinerWarsBlue(), Text,
                                    m_currentOrigin + textPosition,
                                    0.8f, TreeView.GetColor(textColor), MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);

            if (IconTexts != null)
            {
                IconTexts.Draw(m_currentOrigin + iconPosition, m_iconSize, TreeView.GetTransitionAlpha(), isHighlighted);
            }
        }
コード例 #5
0
        public override void Draw()
        {
            if (!Visible)
            {
                return;
            }

            if (CanScroll())
            {
                Vector2 carretPosition = GetCarretPosition();
                //GUIHelper.FillRectangle(m_position + carretPosition, m_caretSize, new Color(0.5f, 0.5f, 0, 0.5f));
                MyGuiManager.DrawSpriteBatch(MyGuiManager.GetHorizontalScrollbarSlider(), m_position + carretPosition, m_caretSize, Color.White, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
            }

            Color borderColor = m_control.GetColorAfterTransitionAlpha(MyGuiConstants.TREEVIEW_VERTICAL_LINE_COLOR);

            MyGUIHelper.Border(m_position, m_size, 1, borderColor, TopBorder, BottomBorder, LeftBorder, RightBorder);
        }
コード例 #6
0
        public bool HandleInputEx(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            if (!Visible)
            {
                return(false);
            }

            bool captured = false;

            // Hoover item if mouse cursor is inside its area
            if (TreeView.Contains(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y) &&
                MyGUIHelper.Contains(m_currentOrigin, m_currentSize, MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y))
            {
                TreeView.HooveredItem = this;
            }

            if (Enabled && DragDrop != null)
            {
                captured = DragDrop.HandleInput(this, input);
            }

            // Single click - expand or focus item
            if (input.IsNewLeftMouseReleased())
            {
                if (GetItemCount() > 0 && MyGUIHelper.Contains(m_currentOrigin + GetExpandIconPosition(), m_expandIconSize, MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y))
                {
                    IsExpanded = !IsExpanded;
                    captured   = true;
                    MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                }
                else if (TreeView.HooveredItem == this)
                {
                    TreeView.FocusItem(this);
                    captured = true;
                    MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                }
            }

            // Double click - launch Action event
            if (Enabled && /*!captured && */ input.IsNewLeftMouseDoubleClick() && TreeView.HooveredItem == this)
            {
                if (Action != null)
                {
                    DoAction();
                }
                else if (GetItemCount() > 0)
                {
                    IsExpanded = !IsExpanded;
                }
                captured = true;
            }

            // Right click - launch RightClick event
            if (/*!captured && */ input.IsNewRightMousePressed() && TreeView.HooveredItem == this)
            {
                if (RightClick != null)
                {
                    RightClick(this, EventArgs.Empty);
                }
                captured = true;
                MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
            }

            return(captured);
        }