示例#1
0
        protected virtual void OnClick(ComboBoxEventArgs e)
        {
            ComboBoxEventHandler handler = Click;

            if (handler != null)
            {
                if (ParentScreen.Name == Storage.Instance.CurrentScreen.Name)
                {
                    handler(this, e);
                }
            }
        }
示例#2
0
        public bool IsClicked(MouseState state, Vector2 cursorPos)
        {
            if (ComboScroll.ParentScreen == null)
            {
                ComboScroll.ParentScreen = this.ParentScreen;
            }
            else if (ComboScroll.ParentViewport == null)
            {
                ComboScroll.ParentViewport = this.ParentViewport;
            }

            if (Visible)
            {
                HoverId = -1;
                if (!ComboScroll.IsClicked(state, cursorPos, Visible))
                {
                    if (Open)
                    {
                        if (Items.Count > 4)
                        {
                            ShowScrollbar = true;
                        }
                        else
                        {
                            ShowScrollbar = false;
                        }

                        if (ComboBoxArea.Contains(cursorPos.X - this.ParentViewport.Viewport.X, cursorPos.Y - this.ParentViewport.Viewport.Y))
                        {
                            for (int i = 0; i < Items.Count; i++)
                            {
                                Rectangle tmpRect = new Rectangle((int)CurrentPosition.X + 15, (int)CurrentPosition.Y + 20 + (i * 16) + _offsetY, Width, 16);

                                if (!Clicked && state.LeftButton == ButtonState.Pressed)
                                {
                                    if (tmpRect.Contains(cursorPos.X - this.ParentViewport.Viewport.X, cursorPos.Y - this.ParentViewport.Viewport.Y))
                                    {
                                        Clicked = true;
                                    }
                                }
                                else if (Clicked && state.LeftButton == ButtonState.Released)
                                {
                                    if (tmpRect.Contains(cursorPos.X - this.ParentViewport.Viewport.X, cursorPos.Y - this.ParentViewport.Viewport.Y))
                                    {
                                        UpdateClicked(i);
                                        ComboBoxEventArgs args = new ComboBoxEventArgs(this.Id, this.Name, this.ParentForm.Id, this.ParentScreen.Id, Items[i]);
                                        OnClick(args);
                                        Clicked = false;
                                        Open    = false;
                                    }
                                }

                                if (tmpRect.Contains(cursorPos.X - this.ParentViewport.Viewport.X, cursorPos.Y - this.ParentViewport.Viewport.Y))
                                {
                                    HoverId = i;
                                }
                            }
                        }
                        else
                        {
                            Clicked = false;
                        }
                    }
                    else
                    {
                        if (!Storage.Instance.ComboBoxOpen)
                        {
                            if (ComboBoxArea.Contains(cursorPos.X - this.ParentViewport.Viewport.X, cursorPos.Y - this.ParentViewport.Viewport.Y))
                            {
                                if (!Clicked && state.LeftButton == ButtonState.Pressed)
                                {
                                    Clicked = true;
                                }
                                else if (Clicked && state.LeftButton == ButtonState.Released)
                                {
                                    Open    = true;
                                    Clicked = false;
                                }
                            }
                            else
                            {
                                Clicked = false;
                            }
                        }
                    }

                    if (Open && !Clicked && state.LeftButton == ButtonState.Pressed)
                    {
                        Open = false;
                    }
                }
            }

            return(Open);
        }