Esempio n. 1
0
        public override List <GUIElement> GetElementsUnderPoint(Vector2 location, InputManager.LogicalButtonState buttons)
        {
            List <GUIElement> elements = new List <GUIElement>();

            if (Inited)
            {
                if (Rect.PointInRect(location))
                {
                    elements.Add(this);
                }

                Vector2 childLoc = location - Rect.GetPixelOrigin();
                foreach (var child in Children)
                {
                    if (child == LabelControl)
                    {
                        continue;
                    }

                    List <GUIElement> childElements = child.GetElementsUnderPoint(childLoc, buttons);
                    if (childElements.Count > 0)
                    {
                        elements.AddRange(childElements.ToArray());
                    }
                }
            }

            return(elements);
        }
Esempio n. 2
0
        public virtual List <GUIElement> GetElementsUnderPoint(Vector2 location, InputManager.LogicalButtonState buttons)
        {
            List <GUIElement> elements = new List <GUIElement>();

            if (Inited && !IgnoreMouse)
            {
                if (Rect.PointInRect(location))
                {
                    ProcessMouseEvent(location, buttons);
                    elements.Add(this);
                }

                Vector2 childLoc = location - Rect.GetPixelOrigin();
                foreach (var child in Children)
                {
                    List <GUIElement> childElements = child.GetElementsUnderPoint(childLoc, buttons);
                    if (childElements.Count > 0)
                    {
                        elements.AddRange(childElements.ToArray());
                    }
                }
            }

            return(elements);
        }
Esempio n. 3
0
        public override void ProcessMouseEvent(Vector2 location, InputManager.LogicalButtonState buttons)
        {
            if (!buttons.PrimaryClick)
            {
                return;
            }

            ParentCanvas.SetFocusedTextArea(this);
        }
Esempio n. 4
0
        public override void ProcessMouseEvent(Vector2 location, InputManager.LogicalButtonState buttons)
        {
            int wheelAbs = Math.Abs(buttons.WheelTick);

            if (wheelAbs > 0)
            {
                if (buttons.WheelTick > 0)
                {
                    VScrollbar.Retreat(Math.Abs(wheelAbs));
                }
                else
                {
                    VScrollbar.Advance(Math.Abs(wheelAbs));
                }
            }

            base.ProcessMouseEvent(location, buttons);
        }
Esempio n. 5
0
        protected virtual bool HandleControlClick(UIButton button, InputManager.LogicalButtonState mouseButtons)
        {
            if (button == null || !button.IsEnabled())
            {
                return(false);
            }

            if (mouseButtons.PrimaryClick || mouseButtons.PrimaryDown)
            {
                if (button.IsHovered())
                {
                    button.EndHover();
                }

                if (!button.IsActive())
                {
                    button.Activate();
                }

                if (mouseButtons.PrimaryClick)
                {
                    button.Click();
                }
                NewActive.Add(button);
            }
            else
            {
                if (!button.IsHovered())
                {
                    button.StartHover();
                }

                NewHover.Add(button);
            }

            return(true);
        }
Esempio n. 6
0
        public override List <GUIElement> GetElementsUnderPoint(Vector2 location, InputManager.LogicalButtonState buttons)
        {
            List <GUIElement> elements = new List <GUIElement>();

            if (Inited)
            {
                if (!Rect.PointInRect(location))                        // we don't add ourself, we are a container.
                {
                    return(elements);
                }

                Vector2 childLoc = location - Rect.GetPixelOrigin();
                foreach (var child in Children)
                {
                    List <GUIElement> childElements = child.GetElementsUnderPoint(childLoc, buttons);
                    if (childElements.Count > 0)
                    {
                        elements.AddRange(childElements.ToArray());
                    }
                }
            }

            return(elements);
        }
Esempio n. 7
0
        public override void ProcessMouseEvent(Vector2 location, InputManager.LogicalButtonState buttons)
        {
            int wheelAbs = Math.Abs(buttons.WheelTick);

            if (UseWheelInput && wheelAbs > 0)
            {
                bool advance = buttons.WheelTick > 0;
                if (Vertical)
                {
                    advance = !advance;
                }

                if (!advance)
                {
                    Retreat(Math.Abs(wheelAbs));
                }
                else
                {
                    Advance(Math.Abs(wheelAbs));
                }
            }

            if (!buttons.PrimaryDown)
            {
                return;
            }

            float availableDist = GetAvalailableClickDistance();

            if (availableDist <= 0)
            {
                return;
            }

            float param = 0;

            float areaStart = GetClickAreaStart();
            float areaEnd   = areaStart + (Vertical ? -availableDist : availableDist);

            if (Vertical)
            {
                if (location.Y < areaEnd || location.Y > areaStart)                             // Y has reversed axis dir from the mouse
                {
                    return;
                }
                param = (areaStart - location.Y) / availableDist;
            }
            else
            {
                if (location.X < areaStart || location.X > areaEnd)
                {
                    return;
                }
                param = (location.X - areaStart) / availableDist;
            }

            int range  = MaxValue - MinValue;
            int newVal = (int)((param * range) + MinValue + 0.25f);

            if (newVal == CurrentValue)
            {
                return;
            }

            CurrentValue = newVal;

            ValueChanged?.Invoke(this, this);

            if (CurrentValue == MinValue)
            {
                RetreatButton.Disable();
            }
            else
            {
                RetreatButton.Enable();
            }

            if (CurrentValue == MaxValue)
            {
                AdvanceButton.Disable();
            }
            else
            {
                AdvanceButton.Enable();
            }

            SetThumbPos(true);
        }
Esempio n. 8
0
        public virtual bool MouseEvent(Vector2 position, InputManager.LogicalButtonState buttons)
        {
            List <GUIElement> affectedElements = new List <GUIElement>();

            // check the popup element for clicks
            if (PopUpCTL != null)
            {
                if (PopUpCTL.Rect.PointInRect(position))
                {
                    affectedElements.AddRange(PopUpCTL.GetElementsUnderPoint(position, buttons));
                }
                else if (buttons.AnyButtonIsDown())
                {
                    SetPopupElement(null);
                }
            }

            if (PopUpCTL == null)             // only check the other controls if there is not a popup.
            {
                List <int> keys = new List <int>(GUIElements.Keys);
                keys.Reverse();

                foreach (var layer in keys)
                {
                    foreach (var item in GUIElements[layer])
                    {
                        affectedElements.AddRange(item.GetElementsUnderPoint(position, buttons));
                    }
                }
            }

            bool clearFocus = buttons.PrimaryClick;

            if (affectedElements.Count == 0)             // nothing is affected, clear out the states
            {
                foreach (var item in ActivatedControlls)
                {
                    if (item.IsActive())
                    {
                        item.Deactivate();
                    }
                }
                ActivatedControlls.Clear();

                foreach (var item in HoveredControlls)
                {
                    if (item.IsHovered())
                    {
                        item.EndHover();
                    }
                }
                HoveredControlls.Clear();

                if (clearFocus)
                {
                    SetFocusedTextArea(null);
                }

                return(false);
            }

            NewHover  = new List <UIButton>();
            NewActive = new List <UIButton>();

            foreach (var element in affectedElements)
            {
                UIButton button = element as UIButton;
                HandleControlClick(button, buttons);

                if (element == FocusedTextControl)
                {
                    clearFocus = false;
                }
            }

            foreach (var item in ActivatedControlls)
            {
                if (!NewActive.Contains(item) && item.IsActive())
                {
                    item.Deactivate();
                }
            }
            ActivatedControlls = NewActive;

            foreach (var item in HoveredControlls)
            {
                if (!NewHover.Contains(item) && item.IsHovered())
                {
                    item.EndHover();
                }
            }
            HoveredControlls = NewHover;

            NewHover  = null;
            NewActive = null;

            if (clearFocus)
            {
                SetFocusedTextArea(null);
            }

            return(true);
        }
Esempio n. 9
0
        public override void ProcessMouseEvent(Vector2 location, InputManager.LogicalButtonState buttons)
        {
            if (Math.Abs(buttons.WheelTick) > 0 && TextLabels.Count > 1)
            {
                SetSelectedIndex(SelectedIndex + buttons.WheelTick);
            }

            if (!buttons.PrimaryClick || ParentCanvas == null || ParentCanvas.PopupEnabled() || TextLabels.Count < 2)
            {
                return;
            }

            float width  = Rect.GetPixelSize().X;
            float height = Rect.GetPixelSize().Y;

            Vector2 origin = Rect.GetPixelOrigin();

            float availableDist = width - (height * 2);

            if (location.X < origin.X + height || location.X > origin.X + availableDist + height)
            {
                return;
            }

            Vector2 thisOrigin = GetScreenOrigin();

            float thisCenterY = thisOrigin.Y + (height * 0.5f);

            float totalheight = (MenuCommon.ButtonSpacing.Paramater + (height * 1)) * TextLabels.Count;

            totalheight += MenuCommon.ButtonSpacing.Paramater * 1;

            float halfHeight = totalheight * 0.5f;

            float screenHeight = ParentCanvas.BoundWindow.Height;

            // see where the popup will land on the screen.

            OriginLocation originAllignment = OriginLocation.LowerLeft;

            if (totalheight > screenHeight)  // it won't fit, center it
            {
                originAllignment = OriginLocation.MiddleLeft;
            }
            else
            {
                if (thisCenterY - halfHeight > 0 && thisCenterY + halfHeight <= screenHeight)
                {
                    originAllignment = OriginLocation.MiddleLeft; // it'll fit centered, that looks better
                }
                else
                {
                    // it won't fit centered, so put it on the other side of the screen from where the button is
                    if (thisCenterY > halfHeight)
                    {
                        originAllignment = OriginLocation.UpperLeft;
                    }
                    else
                    {
                        originAllignment = OriginLocation.LowerLeft;
                    }
                }
            }

            if (originAllignment == OriginLocation.UpperLeft)
            {
                thisOrigin.Y += height;
            }
            else if (originAllignment == OriginLocation.MiddleLeft)
            {
                thisOrigin.Y += height * 0.5f;
            }

            RelativeRect rect = new RelativeRect(new RelativeLoc(thisOrigin.X, RelativeLoc.Edge.Raw), new RelativeLoc(thisOrigin.Y, RelativeLoc.Edge.Raw), RelativeSize.FixedPixelSize(width), RelativeSize.FixedPixelSize(totalheight), originAllignment);

            var popup = new UIPanel(rect, ThemeManager.GetThemeAsset("ui/SelectorPopupBackground.png"));

            popup.FillMode    = UIFillModes.SmartStprite;
            popup.IgnoreMouse = false;

            VerticalLayoutGroup vertgroup = MenuCommon.SetupCommonColumn(new RelativeRect(RelativeLoc.XCenter, RelativeLoc.YCenter, RelativeSize.ThreeQuarterWidth, rect.Height, OriginLocation.Center));

            vertgroup.FirstElementHasSpacing = true;

            foreach (var label in TextLabels)
            {
                MenuButton button = new MenuButton(new RelativeRect(), label);
                button.Tag      = label;
                button.Clicked += PopupButton_Clicked;
                if (label == GetText())
                {
                    button.Check();
                }

                vertgroup.AddChild(button);
            }
            popup.AddChild(vertgroup);

            ParentCanvas.SetPopupElement(popup);
        }
Esempio n. 10
0
 public virtual void ProcessMouseEvent(Vector2 location, InputManager.LogicalButtonState buttons)
 {
     // the child class may want to do something with this.
 }
 public virtual void ProcessMouseEvent(Vector2 location, InputManager.LogicalButtonState buttons)
 {
 }