Beispiel #1
0
        public void Hover(int x, int y)
        {
            if (IsHoveringBoard(x, y) && !GetDrawingPoint(x, y).Equals(Point.Empty))
            {
                int[] boardCoordinates = GetBoardCoordinates(x, y);
                if (Hovered != null)
                {
                    int hoverI = Hovered.GetCoordinates()[0];
                    int hoverJ = Hovered.GetCoordinates()[1];
                    if (boardCoordinates[0] != hoverI || boardCoordinates[1] != hoverJ)
                    {
                        Hovered = null;
                    }
                }


                if (Hovered == null && Board[boardCoordinates[0], boardCoordinates[1]].Equals(' '))
                {
                    Point point = GetDrawingPoint(x, y);
                    if (XTurn)
                    {
                        Hovered = new PlayX(point, boardCoordinates[0], boardCoordinates[1], Color.LightGray);
                    }
                    else
                    {
                        Hovered = new PlayO(point, boardCoordinates[0], boardCoordinates[1], Color.LightGray);
                    }
                }
            }
            else
            {
                Hovered = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Called, when mouse/finger/pen hovers around
        /// </summary>
        /// <param name="screenPosition">Actual position of mouse/finger/pen</param>
        private bool OnHovered(Geometries.Point screenPosition)
        {
            var args = new HoveredEventArgs(screenPosition);

            Hovered?.Invoke(this, args);

            return(args.Handled);
        }
 private void Unhover()
 {
     if (Hovered != null)
     {
         Hovered.OnPointerExit(null);
         Hovered = null;
     }
 }
Beispiel #4
0
 public void DrawAll(Graphics g)
 {
     if (Hovered != null)
     {
         Hovered.Draw(g);
     }
     foreach (IPlay play in Plays)
     {
         play.Draw(g);
     }
 }
Beispiel #5
0
        public override uint MouseDown(MouseEventArgs e, GL_ControlBase control)
        {
            bool TryGetActionType(MouseButtons button, out DragActionType dragActionType)
            {
                if (e.Button == MouseButtons.Left)
                {
                    dragActionType = DragActionType.TRANSLATE;
                    return(true);
                }
                else if (e.Button == MouseButtons.Right)
                {
                    dragActionType = DragActionType.ROTATE;
                    return(true);
                }
                else if (e.Button == MouseButtons.Middle)
                {
                    bool ctrl = WinInput.Keyboard.IsKeyDown(WinInput.Key.LeftCtrl);

                    dragActionType = ctrl ? DragActionType.SCALE_INDIVIDUAL : DragActionType.SCALE;
                    return(true);
                }
                dragActionType = DragActionType.NONE;
                return(false);
            }

            uint var = 0;

            {
                if (CurrentAction == NoAction && ExclusiveAction == NoAction && Hovered != null && TryGetActionType(e.Button, out DragActionType dragActionType))
                {
                    Hovered.StartDragging(dragActionType, HoveredPart, this);
                }
                else
                {
                    var |= REDRAW_PICKING;
                    var |= FORCE_REENTER;

                    CurrentAction   = NoAction; //abort current action
                    ExclusiveAction = NoAction;
                }
            }

            foreach (AbstractGlDrawable obj in StaticObjects)
            {
                var |= obj.MouseDown(e, control);
            }

            foreach (IEditableObject obj in GetObjects())
            {
                var |= obj.MouseDown(e, control);
            }

            return(var);
        }
Beispiel #6
0
        protected override void OnMouseMove(MouseEventArgs args)
        {
            base.OnMouseMove(args);
            var location = args.GetPosition(this);

            // Look for the mouse op to perform
            var op = MouseOperations.Active;

            if (op != null)
            {
                if (!op.Cancelled)
                {
                    op.DropClient = location;                     // Note: in ChartControl space, not ChartPanel space
                    op.DropChart  = ClientToChart(location);
                    op.MouseMove(args);
                }
            }
            // Otherwise, provide mouse hover detection
            else if (SceneBounds != Rect_.Zero)
            {
                var hit     = HitTestCS(location, Keyboard.Modifiers, args.ToMouseBtns(), null);
                var hovered = hit.Hits.Select(x => x.Element).ToHashSet(0);

                // Remove elements that are no longer hovered
                // and remove existing hovered's from the set.
                for (int i = Hovered.Count; i-- != 0;)
                {
                    if (hovered.Contains(Hovered[i]))
                    {
                        hovered.Remove(Hovered[i]);
                    }
                    else
                    {
                        Hovered.RemoveAt(i);
                    }
                }

                // Add elements that are now hovered
                Hovered.AddRange(hovered);

                // Notify that the chart coordinate at the mouse pointer has changed
                if (hit.Zone == EZone.Chart && ShowValueAtPointer)
                {
                    NotifyPropertyChanged(nameof(ValueAtPointer));
                }
            }
        }
        public Task Event(string eventName, int datasetIndex, int index, string modelJson)
        {
            var model = Serialize(modelJson);

            var chartClickData = new ChartMouseEventArgs(datasetIndex, index, model);

            if (eventName == "click")
            {
                return(Clicked.InvokeAsync(chartClickData));
            }
            else if (eventName == "hover")
            {
                return(Hovered.InvokeAsync(chartClickData));
            }

            return(Task.CompletedTask);
        }
Beispiel #8
0
        public override uint MouseUp(MouseEventArgs e, GL_ControlBase control)
        {
            TransformChangeInfos transformChangeInfos = new TransformChangeInfos(new List <TransformChangeInfo>());
            uint var = 0;

            if (CurrentAction != NoAction && CurrentAction.IsApplyOnRelease())
            {
                foreach (IEditableObject obj in GetObjects())
                {
                    obj.ApplyTransformActionToSelection(CurrentAction, ref transformChangeInfos);
                }

                var |= REDRAW_PICKING | FORCE_REENTER;

                AddTransformToUndo(transformChangeInfos);
                EndUndoCollection();

                CurrentAction = NoAction;
            }

            if (ExclusiveAction != NoAction)
            {
                Hovered.ApplyTransformActionToPart(ExclusiveAction, HoveredPart, ref transformChangeInfos);

                var |= REDRAW_PICKING;

                AddTransformToUndo(transformChangeInfos);
                EndUndoCollection();

                ExclusiveAction = NoAction;
            }

            foreach (AbstractGlDrawable obj in StaticObjects)
            {
                var |= obj.MouseUp(e, control);
            }

            foreach (IEditableObject obj in GetObjects())
            {
                var |= obj.MouseUp(e, control);
            }

            return(var);
        }
Beispiel #9
0
        public override uint MouseMove(MouseEventArgs e, Point lastMousePos, GL_ControlBase control)
        {
            uint var = 0;

            foreach (IEditableObject obj in GetObjects())
            {
                var |= obj.MouseMove(e, lastMousePos, control);
            }

            foreach (AbstractGlDrawable obj in StaticObjects)
            {
                var |= obj.MouseMove(e, lastMousePos, control);
            }

            if (SelectionTransformAction != NoAction || CurrentAction != null)
            {
                SelectionTransformAction.UpdateMousePos(e.Location);
                CurrentAction?.UpdateMousePos(e.Location);

                var |= REDRAW | NO_CAMERA_ACTION;

                var &= ~REPICK;
            }
            else
            {
                if (e.Button == MouseButtons.Left && WinInput.Keyboard.IsKeyDown(WinInput.Key.LeftAlt))
                {
                    if (WinInput.Keyboard.IsKeyDown(WinInput.Key.LeftShift))
                    {
                        Hovered?.Deselect(HoveredPart, control);
                    }
                    else
                    {
                        Hovered?.Select(HoveredPart, control);
                    }

                    SelectionChanged?.Invoke(this, new EventArgs());

                    var |= NO_CAMERA_ACTION | FORCE_REENTER;
                }
                var |= REPICK;
            }
            return(var);
        }
Beispiel #10
0
 public virtual void Update(float deltaTime)
 {
     PreUpdate?.Invoke(deltaTime);
     if (!enabled)
     {
         return;
     }
     if (IsMouseOver || (!RequireMouseOn && selectedWidgets.Contains(this) && PlayerInput.PrimaryMouseButtonHeld()))
     {
         Hovered?.Invoke();
         System.Diagnostics.Debug.WriteLine("hovered");
         if (RequireMouseOn || PlayerInput.PrimaryMouseButtonDown())
         {
             if ((multiselect && !selectedWidgets.Contains(this)) || selectedWidgets.None())
             {
                 selectedWidgets.Add(this);
                 Selected?.Invoke();
             }
         }
     }
     else if (selectedWidgets.Contains(this))
     {
         System.Diagnostics.Debug.WriteLine("selectedWidgets.Contains(this) -> remove");
         selectedWidgets.Remove(this);
         Deselected?.Invoke();
     }
     if (IsSelected)
     {
         if (PlayerInput.PrimaryMouseButtonDown())
         {
             MouseDown?.Invoke();
         }
         if (PlayerInput.PrimaryMouseButtonHeld())
         {
             MouseHeld?.Invoke(deltaTime);
         }
         if (PlayerInput.PrimaryMouseButtonClicked())
         {
             MouseUp?.Invoke();
         }
     }
     PostUpdate?.Invoke(deltaTime);
 }
Beispiel #11
0
 public virtual void Update(float deltaTime)
 {
     PreUpdate?.Invoke(deltaTime);
     if (!enabled)
     {
         return;
     }
     if (IsMouseOver || (!RequireMouseOn && selectedWidgets.Contains(this) && PlayerInput.LeftButtonHeld()))
     {
         Hovered?.Invoke();
         if (RequireMouseOn || PlayerInput.LeftButtonDown())
         {
             if ((multiselect && !selectedWidgets.Contains(this)) || selectedWidgets.None())
             {
                 selectedWidgets.Add(this);
                 Selected?.Invoke();
             }
         }
     }
     else if (selectedWidgets.Contains(this))
     {
         selectedWidgets.Remove(this);
         Deselected?.Invoke();
     }
     if (IsSelected)
     {
         if (PlayerInput.LeftButtonDown())
         {
             MouseDown?.Invoke();
         }
         if (PlayerInput.LeftButtonHeld())
         {
             MouseHeld?.Invoke(deltaTime);
         }
         if (PlayerInput.LeftButtonClicked())
         {
             MouseUp?.Invoke();
         }
     }
     PostUpdate?.Invoke(deltaTime);
 }
Beispiel #12
0
        public override uint MouseClick(MouseEventArgs e, GL_ControlBase control)
        {
            uint var = 0;

            foreach (IEditableObject obj in GetObjects())
            {
                var |= obj.MouseClick(e, control);
            }

            bool shift             = WinInput.Keyboard.IsKeyDown(WinInput.Key.LeftShift);
            bool hoveredIsSelected = Hovered != null && Hovered.IsSelected(HoveredPart);
            bool nothingHovered    = Hovered == null;

            /*
             * Selecting Objects:
             *
             * If the object is not selected, select it
             * If another object is selected, deselect the old object, and select the new one
             * UNLESS [SHIFT] is being pressed
             * If [SHIFT] is being pressed, select the new object, but DON'T deselect the old object
             *
             * If an object that is already selected is clicked, deselect it
             * If multiple objects are selected, deselect all of them
             * UNLESS [SHIFT] is being pressed
             * If [SHIFt] is being pressed, only deselect the one object, leave the rest alone
             *
             * If nothing is being selected, and [SHIFT] isn't pressed, de-select everything
             */
            if (e.Button == MouseButtons.Left)
            {
                if (nothingHovered)
                {
                    if (!shift)
                    {
                        foreach (IEditableObject obj in GetObjects())
                        {
                            obj.DeselectAll(control);
                        }
                        SelectionChanged?.Invoke(this, new EventArgs());
                    }
                }
                else if (multiSelect)
                {
                    if (hoveredIsSelected)
                    {
                        if (shift)
                        {
                            //remove from selection
                            Hovered.Deselect(HoveredPart, control);
                            SelectionChanged?.Invoke(this, new EventArgs());
                        }
                        else
                        {
                            foreach (IEditableObject obj in GetObjects())
                            {
                                obj.DeselectAll(control);
                            }
                            SelectionChanged?.Invoke(this, new EventArgs());
                        }
                    }
                    else
                    {
                        if (shift)
                        {
                            //add to selection
                            Hovered.Select(HoveredPart, control);
                            SelectionChanged?.Invoke(this, new EventArgs());
                        }
                        else
                        {
                            //change selection
                            foreach (IEditableObject obj in GetObjects())
                            {
                                obj.DeselectAll(control);
                            }
                            Hovered.Select(HoveredPart, control);
                            SelectionChanged?.Invoke(this, new EventArgs());
                        }
                    }
                }
                else
                {
                    if (hoveredIsSelected)
                    {
                        //remove from selection
                        Hovered.Deselect(HoveredPart, control);
                        SelectionChanged?.Invoke(this, new EventArgs());
                    }
                    else
                    {
                        //change selection
                        foreach (IEditableObject obj in GetObjects())
                        {
                            obj.DeselectAll(control);
                        }
                        Hovered.Select(HoveredPart, control);
                        SelectionChanged?.Invoke(this, new EventArgs());
                    }
                }
            }

            foreach (AbstractGlDrawable obj in StaticObjects)
            {
                var |= obj.MouseClick(e, control);
            }

            var |= REDRAW;
            var |= FORCE_REENTER;

            return(var);
        }
Beispiel #13
0
        protected override bool OnHover(HoverEvent e)
        {
            bool handledByBase = base.OnHover(e);

            return(Hovered?.Invoke(e) ?? handledByBase);
        }
Beispiel #14
0
        public override uint MouseDown(MouseEventArgs e, GL_ControlBase control)
        {
            bool TryGetActionType(out DragActionType dragActionType)
            {
                if (e.Button == MouseButtons.Left)
                {
                    dragActionType = DragActionType.TRANSLATE;
                    return(true);
                }
                else if (e.Button == MouseButtons.Right)
                {
                    dragActionType = DragActionType.ROTATE;
                    return(true);
                }
                else if (e.Button == MouseButtons.Middle)
                {
                    bool ctrl = WinInput.Keyboard.IsKeyDown(WinInput.Key.LeftCtrl);

                    dragActionType = ctrl ? DragActionType.SCALE_INDIVIDUAL : DragActionType.SCALE;
                    return(true);
                }
                dragActionType = DragActionType.NONE;
                return(false);
            }

            uint var = 0;

            {
                var buttons = OpenTK.Input.Mouse.GetCursorState();

                if (SelectionTransformAction == NoAction && CurrentAction == null && Hovered != null && TryGetActionType(out DragActionType dragActionType))
                {
                    if (!WinInput.Keyboard.IsKeyDown(WinInput.Key.LeftAlt))
                    {
                        Hovered.StartDragging(dragActionType, HoveredPart, this);
                    }
                }
                else if (buttons.RightButton == OpenTK.Input.ButtonState.Pressed ||                           //the right mouse button is pressed or
                         (int)buttons.LeftButton + (int)buttons.RightButton + (int)buttons.MiddleButton >= 2) //atleast 2 buttons are pressed at once
                {
                    var |= REDRAW_PICKING;
                    var |= FORCE_REENTER;

                    if (SelectionTransformAction != NoAction)
                    {
                        EndUndoCollection();
                    }

                    if (SelectionTransformAction != NoAction || CurrentAction != null)
                    {
                        control.CameraTarget = actionStartCamTarget;
                    }

                    SelectionTransformAction = NoAction; //abort current action
                    CurrentAction?.Cancel();
                    CurrentAction = null;
                }
            }

            foreach (AbstractGlDrawable obj in StaticObjects)
            {
                var |= obj.MouseDown(e, control);
            }

            foreach (IEditableObject obj in GetObjects())
            {
                var |= obj.MouseDown(e, control);
            }

            return(var);
        }
Beispiel #15
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            // Check if the mouse is in the click area, as well as if the game window is actually the active window.
            if (GameBase.Game.IsActive && Visible && IsMouseInClickArea())
            {
                // Set this to be hovered without the draw order check.
                IsHoveredWithoutDrawOrder = true;

                // Get the button that is on the top layer.
                var topLayerButton = ButtonManager.Buttons.FindAll(x => x.IsHoveredWithoutDrawOrder && x.IsClickable && IsGloballyClickable)
                                     .OrderBy(x => x.Depth).ThenByDescending(x => x.DrawOrder).DefaultIfEmpty(null).First();

                if (topLayerButton == null)
                {
                    base.Update(gameTime);
                    return;
                }

                // Set this to be truly hovered and follow up with click actions for this button.
                if (topLayerButton == this)
                {
                    if (!IsHovered)
                    {
                        Hovered?.Invoke(this, EventArgs.Empty);
                    }

                    IsHovered = true;
                    OnHover(gameTime);

                    // If we're not waiting for a click release and the mouse button is currently held down,
                    // then we'll set this to true.
                    if (!WaitingForClickRelease && MouseManager.IsUniquePress(MouseButton.Left) || MouseManager.IsUniquePress(MouseButton.Right) ||
                        MouseManager.IsUniquePress(MouseButton.Middle))
                    {
                        WaitingForClickRelease = true;
                        IsHeld = true;

                        if (MouseManager.IsUniquePress(MouseButton.Left))
                        {
                            MouseButtonClicked = MouseButton.Left;
                        }
                        else if (MouseManager.IsUniquePress(MouseButton.Right))
                        {
                            MouseButtonClicked = MouseButton.Right;
                        }
                        else if (MouseManager.IsUniquePress(MouseButton.Middle))
                        {
                            MouseButtonClicked = MouseButton.Middle;
                        }
                    }
                    // In the event that we are waiting for a click release, and the user doesn, then we can call
                    // the click action.
                    else if (WaitingForClickRelease)
                    {
                        // Check to see if the clicked button was released.
                        var released = false;
                        switch (MouseButtonClicked)
                        {
                        case MouseButton.Left:
                            released = MouseManager.CurrentState.LeftButton == ButtonState.Released;
                            break;

                        case MouseButton.Right:
                            released = MouseManager.CurrentState.RightButton == ButtonState.Released;
                            break;

                        case MouseButton.Middle:
                            released = MouseManager.CurrentState.MiddleButton == ButtonState.Released;
                            break;
                        }

                        // If the button was released, reset the waiting property.
                        if (released)
                        {
                            WaitingForClickRelease = false;

                            if (IsClickable)
                            {
                                switch (MouseButtonClicked)
                                {
                                case MouseButton.Left:
                                    Clicked?.Invoke(this, new EventArgs());
                                    break;

                                case MouseButton.Right:
                                    RightClicked?.Invoke(this, new EventArgs());
                                    break;

                                case MouseButton.Middle:
                                    MiddleMouseClicked?.Invoke(this, new EventArgs());
                                    break;

                                default:
                                    throw new ArgumentOutOfRangeException();
                                }
                            }

                            MouseButtonClicked = null;
                        }
                    }
                }
                // If the button isn't the top layered button, then we'll want to consider it not hovered.
                else
                {
                    var wasHovered = IsHovered;
                    IsHovered = false;

                    WaitingForClickRelease = false;
                    MouseButtonClicked     = null;

                    if (wasHovered)
                    {
                        LeftHover?.Invoke(this, EventArgs.Empty);
                    }

                    OnNotHovered(gameTime);
                }
            }
            // The button isn't actually hovered over so we can safely consider it not hovered.
            // However,
            else
            {
                IsHoveredWithoutDrawOrder = false;
                WaitingForClickRelease    = false;

                var wasHovered = IsHovered;
                IsHovered = false;

                if (wasHovered)
                {
                    LeftHover?.Invoke(this, EventArgs.Empty);
                }

                OnNotHovered(gameTime);
            }

            if (MouseManager.CurrentState.LeftButton == ButtonState.Released)
            {
                IsHeld = false;
            }

            if (IsHeld)
            {
                OnHeld(gameTime);
            }

            // Fire an event if the user clicks outside of the button.
            if (MouseManager.IsUniqueClick(MouseButton.Left) && !IsMouseInClickArea())
            {
                ClickedOutside?.Invoke(this, EventArgs.Empty);
            }

            base.Update(gameTime);
        }
Beispiel #16
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            // Check if the mouse is in the click area, as well as if the game window is actually the active window.
            if (GameBase.Game.IsActive && Visible && IsMouseInClickArea())
            {
                // Set this to be hovered without the draw order check.
                IsHoveredWithoutDrawOrder = true;

                // Get the button that is on the top layer.
                Button topLayerButton;

                try
                {
                    topLayerButton = ButtonManager.Buttons.FindAll(x => x.IsHoveredWithoutDrawOrder && x.IsClickable && IsGloballyClickable)
                                     .OrderByDescending(x => x.DrawOrder).First();
                }
                catch (Exception e)
                {
                    base.Update(gameTime);
                    return;
                }

                // Set this to be truly hovered and follow up with click actions for this button.
                if (topLayerButton == this)
                {
                    if (!IsHovered)
                    {
                        Hovered?.Invoke(this, EventArgs.Empty);
                    }

                    IsHovered = true;
                    OnHover(gameTime);

                    // If we're not waiting for a click reelase and the mouse button is currently held down,
                    // then we'll set this to true.
                    if (!WaitingForClickRelease && MouseManager.CurrentState.LeftButton == ButtonState.Pressed &&
                        MouseManager.PreviousState.LeftButton == ButtonState.Released)
                    {
                        WaitingForClickRelease = true;
                        IsHeld = true;
                    }
                    // In the event that we are waiting for a click release, and the user doesn, then we can call
                    // the click action.
                    else if (WaitingForClickRelease && MouseManager.CurrentState.LeftButton == ButtonState.Released)
                    {
                        // Now that the button is clicked, reset the waiting property.
                        WaitingForClickRelease = false;

                        if (IsClickable)
                        {
                            Clicked?.Invoke(this, new EventArgs());
                        }
                    }
                }
                // If the button isn't the top layered button, then we'll want to consider it not hovered.
                else
                {
                    if (IsHovered)
                    {
                        LeftHover?.Invoke(this, EventArgs.Empty);
                    }

                    IsHovered = false;
                    WaitingForClickRelease = false;

                    OnNotHovered(gameTime);
                }
            }
            // The button isn't actually hovered over so we can safely consider it not hovered.
            // However,
            else
            {
                if (IsHovered)
                {
                    LeftHover?.Invoke(this, EventArgs.Empty);
                }

                IsHoveredWithoutDrawOrder = false;
                IsHovered = false;
                WaitingForClickRelease = false;

                OnNotHovered(gameTime);
            }

            if (MouseManager.CurrentState.LeftButton == ButtonState.Released)
            {
                IsHeld = false;
            }

            if (IsHeld)
            {
                OnHeld(gameTime);
            }

            // Fire an event if the user clicks outside of the button.
            if (MouseManager.IsUniqueClick(MouseButton.Left) && !IsMouseInClickArea())
            {
                ClickedOutside?.Invoke(this, EventArgs.Empty);
            }

            base.Update(gameTime);
        }