Example #1
0
        public void Update(GameTime gameTime)
        {
            if (IsVisible)
            {
                Vector2 mouseLoc = InputMgr.Instance.Mouse_Location(null);

                if (GlobalExpandedComboBox == null || GlobalExpandedComboBox == this)
                {
                    HasFocus = true;
                }
                else
                {
                    if (IsCollapsed)
                    {
                        HasFocus = Collision.PointIsInRect(mouseLoc, DrawRect);
                    }
                    else
                    {
                        HasFocus = true;
                    }
                }

                if (!IgnoreExpansionsThisRun)
                {
                    if (HasFocus && (GlobalExpandedComboBox == null || GlobalExpandedComboBox == this))
                    {
                        if (InputMgr.Instance.Mouse_LeftIsPressed(null) && (ControlMgr.Instance.GetOpenedCombobox() == null || ControlMgr.Instance.GetOpenedCombobox() == this))
                        {
                            // Check for collision for dropdown/expand
                            if (IsCollapsed && Collision.PointIsInRect(mouseLoc, DrawRect))
                            {
                                IsCollapsed            = false;
                                GlobalExpandedComboBox = this;
                            }
                            else if (!IsCollapsed && Collision.PointIsInRect(mouseLoc, DropDownBtnRect))
                            {
                                IsCollapsed             = true;
                                GlobalExpandedComboBox  = null;
                                IgnoreExpansionsThisRun = true;
                            }
                            else if (!IsCollapsed && Collision.PointIsInRect(mouseLoc, ExpandedRectangle)) // check for collision with expanded rectangle if collapsed
                            {
                                // Find out what item was clicked.
                                int    selected     = -1;
                                string selectedText = TextScroller.GetLineTextAtPoint(mouseLoc, out selected);
                                if (selectedText != null)
                                {
                                    SetIndexByStrValue(selectedText.Replace(Environment.NewLine, "").Trim());
                                    IsCollapsed             = true;
                                    GlobalExpandedComboBox  = null;
                                    IgnoreExpansionsThisRun = true;
                                }
                            }
                        }
                    }
                }
            }
        }