Пример #1
0
        void MoveHandle()
        {
            if (Enabled)
            {
                if (Orientation == Orientation.Horizontal)
                {
                    NormalisedValue = (MouseInput.Position.X - (int)LinkedObject.GetCorner(Alignment.MiddleLeft).X) / LinkedObject.Size.X;
                }
                else
                {
                    NormalisedValue = ((int)LinkedObject.GetCorner(Alignment.MiddleLeft).Y - MouseInput.Position.Y) / LinkedObject.Size.X;
                }

                Value = Math.Clamp((NormalisedValue * (MaxValue + Math.Abs(MinValue))) + MinValue, MinValue, MaxValue);
                UpdateSlider();
            }
        }
Пример #2
0
        public override void Update()
        {
            if (!OtherButtonIsPressed || IsBeingClicked)
            {
                Corners.Clear();
                Corners.Add(LinkedObject.GetCorner(Alignment.TopLeft));
                Corners.Add(LinkedObject.GetCorner(Alignment.BottomLeft));
                Corners.Add(LinkedObject.GetCorner(Alignment.TopRight));
                Corners.Add(LinkedObject.GetCorner(Alignment.BottomRight));

                // Calculates distances to each corner
                CursorDistances.Clear();
                CursorDistances.Add(Vector2.Distance(MouseInput.Position.ToVector2(), Corners[0]));
                CursorDistances.Add(Vector2.Distance(MouseInput.Position.ToVector2(), Corners[1]));
                CursorDistances.Add(Vector2.Distance(MouseInput.Position.ToVector2(), Corners[2]));
                CursorDistances.Add(Vector2.Distance(MouseInput.Position.ToVector2(), Corners[3]));

                // Calculates triangle sizes
                float RotRectArea = CalcTriangleArea(CursorDistances[0], CursorDistances[1], LinkedObject.Size.Y) + CalcTriangleArea(CursorDistances[1], CursorDistances[3], LinkedObject.Size.X) + CalcTriangleArea(CursorDistances[3], CursorDistances[2], LinkedObject.Size.Y) + CalcTriangleArea(CursorDistances[2], CursorDistances[0], LinkedObject.Size.X);

                // When in the bounds of the rectangle
                if (LinkedObject.Size.X * LinkedObject.Size.Y + 1f >= RotRectArea)
                {
                    if (OnHover != null)
                    {
                        OnHover();
                    }

                    if (!WasIn)
                    {
                        WasIn = true;
                        if (OnEnter != null)
                        {
                            OnEnter();
                        }
                    }

                    if (Input.Mouse.LeftButton == ButtonState.Pressed && WasClicked == false)
                    {
                        WasClicked = true;
                        if (OnClick != null)
                        {
                            OnClick();
                        }
                    }
                }
                else
                {
                    if (WasIn)
                    {
                        WasIn = false;
                        if (OnExit != null)
                        {
                            OnExit();
                        }
                    }

                    if (Input.Mouse.LeftButton == ButtonState.Pressed && WasClicked == false)
                    {
                        WasClicked = true;
                        if (OnClickOutside != null)
                        {
                            OnClickOutside();
                        }
                    }
                    else if (!WasClicked && Input.Mouse.LeftButton == ButtonState.Released)
                    {
                        WasClicked = false;
                    }
                }

                if (WasClicked && Input.Mouse.LeftButton == ButtonState.Released)
                {
                    WasClicked = false;
                    if (OnRelease != null)
                    {
                        OnRelease();
                    }
                }

                if (Input.Mouse.LeftButton == ButtonState.Pressed && IsBeingClicked)
                {
                    if (OnPress != null)
                    {
                        OnPress();
                    }
                }
            }
        }