Exemplo n.º 1
0
    public void CheckMouseButtonEvent()
    {
        MouseButton[] buttons = { MouseButton.Left, MouseButton.Rigth, MouseButton.Middle };

        foreach (MouseButton btn in buttons)
        {
            // Mouse button down
            if (Input.GetMouseButtonDown((int)btn))
            {
                MouseButtonDown.Invoke(new MouseButtonEventData()
                {
                    MouseButton   = btn,
                    MousePosition = Input.mousePosition,
                    ButtonDown    = true
                });
            }

            // Mouse button up
            if (Input.GetMouseButtonUp((int)btn))
            {
                MouseButtonUp.Invoke(new MouseButtonEventData()
                {
                    MouseButton   = btn,
                    MousePosition = Input.mousePosition,
                    ButtonDown    = false
                });
            }
        }
    }
Exemplo n.º 2
0
        /// <summary>
        /// Handles a SharpDX MouseInput event and fires the relevant InputEvents event (Scroll, MouseButtonDown or MouseButtonUp).
        /// </summary>
        private void DeviceOnMouseInput(object sender, MouseInputEventArgs e)
        {
            try
            {
                if (e.WheelDelta != 0)
                {
                    Scroll?.Invoke(sender, e);
                }

                if (e.IsMouseDownEvent())
                {
                    if (!pressedMouseButtons.Contains(e.GetMouseButton()))
                    {
                        pressedMouseButtons.Add(e.GetMouseButton());
                    }
                    MouseButtonDown?.Invoke(sender, e);
                }
                else if (e.IsMouseUpEvent())
                {
                    pressedMouseButtons.Remove(e.GetMouseButton());
                    MouseButtonUp?.Invoke(sender, e);
                }
            }
            catch (Exception exc)
            {
                Global.logger.Error("Exception while handling mouse input. Error: " + exc.ToString());
            }
        }
Exemplo n.º 3
0
 private static void Handle_Mouse_Buttons(MouseUpdate data)
 {
     if (data.IsButton)
     {
         MouseButtonDown?.Invoke(null, new MouseButtonEventArgs((int)data.Offset, data.Value));
     }
 }
Exemplo n.º 4
0
 void Mouse_ButtonDown(object sender, OpenTK.Input.MouseButtonEventArgs otk_e)
 {
     if (!CrowInterface.ProcessMouseButtonDown((int)otk_e.Button))
     {
         MouseButtonDown.Raise(sender, otk_e);
     }
 }
Exemplo n.º 5
0
 private void OnMouseDown(MouseButtonEventArgs args)
 {
     MouseButtonDown?.Invoke(args);
     if (!_blocked)
     {
         BlockableMouseButtonDown?.Invoke(args);
     }
 }
Exemplo n.º 6
0
 public WindowWrapperInput(Window window)
 {
     _window                     = window;
     window.TextEntered         += (sender, args) => TextEntered?.Invoke(args);
     window.KeyPressed          += (sender, args) => KeyPressed?.Invoke(args);
     window.MouseButtonPressed  += (sender, args) => MouseButtonDown?.Invoke(args);
     window.MouseButtonReleased += (sender, args) => MouseButtonUp?.Invoke(args);
     window.MouseMoved          += (sender, args) => MouseMoved?.Invoke(args);
     window.MouseWheelScrolled  += (sender, args) => MouseWheelScrolled?.Invoke(args);
 }
Exemplo n.º 7
0
 protected virtual void GL_Mouse_ButtonDown(object sender, OpenTK.Input.MouseButtonEventArgs otk_e)
 {
     activeIdx = focusedIdx;
     if (focusedIdx >= 0)
     {
         if (ifaceControl [focusedIdx].ProcessMouseButtonDown((int)otk_e.Button))
         {
             return;
         }
     }
     MouseButtonDown.Raise(sender, otk_e);
 }
Exemplo n.º 8
0
 private void EmitButtonChange(bool prev, bool next, MouseButton button, MouseStatus nextStatus)
 {
     if (!prev && next)
     {
         MouseButtonDown?.Invoke(sender, new MouseButtonEvent(LastMouseStatus, nextStatus, button));
     }
     else if (prev && !next)
     {
         var ev = new MouseButtonEvent(LastMouseStatus, nextStatus, button);
         MouseButtonUp?.Invoke(sender, ev);
         MouseClick?.Invoke(sender, ev);
     }
 }
Exemplo n.º 9
0
        internal Window(string title = null, int width = 1920, int height = 1080, bool fullScreen = true)
        {
            if (title == null)
            {
                title = "AshyEngine build " + AssemblyUtils.BuildNumber;
            }

            PrivateWindow = new GameWindow(width,
                                           height,
                                           GraphicsMode.Default,
                                           title,
                                           fullScreen
                                                                  ? GameWindowFlags.Fullscreen
                                                                  : GameWindowFlags.Default);

            _windowCenter = new Point(PrivateWindow.Width / 2, PrivateWindow.Height / 2);
            PressedKeys   = new bool[131];
            KeyDown      += button => PressedKeys[(uint)button] = true;
            KeyUp        += button => PressedKeys[(uint)button] = false;
            Resize       += size => _windowCenter = new Point(size.Width / 2, size.Height / 2);

            PrivateWindow.Mouse.ButtonDown += (sender, args) =>
                                              MouseButtonDown?.Invoke((MouseButton)args.Button, args.Position);

            PrivateWindow.Mouse.ButtonUp += (sender, args) =>
                                            MouseButtonUp?.Invoke((MouseButton)args.Button, args.Position);

            //PrivateWindow.RenderFrame       += (sender, args) =>
            //    RenderFrame?.Invoke         ( (float) args.Time );

            PrivateWindow.Mouse.Move += (sender, args) =>
                                        MouseMove?.Invoke(new Point(args.XDelta, args.YDelta), args.Position);

            PrivateWindow.KeyDown += (sender, args) =>
                                     KeyDown?.Invoke((Key)args.Key);

            PrivateWindow.Resize += (sender, args) =>
                                    Resize?.Invoke(PrivateWindow.ClientSize);

            PrivateWindow.KeyUp += (sender, args) =>
                                   KeyUp?.Invoke((Key)args.Key);

            PrivateWindow.VSync   = VSyncMode.Adaptive;
            PrivateWindow.Visible = true;
        }
Exemplo n.º 10
0
        void picturebox_MouseUp(object sender, MouseEventArgs e)
        {
            if (!_active)
            {
                return;
            }

            _curMousePoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));

            if (_isMouseDown == MouseButtonDown.Left && e.Button == MouseButtons.Left)
            {
                _isMouseDown = MouseButtonDown.None;
            }
            else if (_isMouseDown == MouseButtonDown.Right && e.Button == MouseButtons.Right)
            {
                _isMouseDown = MouseButtonDown.None;
            }
        }
Exemplo n.º 11
0
        void picturebox_MouseDown(object sender, MouseEventArgs e)
        {
            if (!_active)
            {
                return;
            }

            _curMousePoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));
            _cursorBlip.Sphere.Position.StoreNewValues(_curMousePoint);

            if (e.Button == MouseButtons.Left)
            {
                _isMouseDown = MouseButtonDown.Left;
            }
            else if (e.Button == MouseButtons.Right)
            {
                _isMouseDown = MouseButtonDown.Right;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Handles a SharpDX MouseInput event and fires the relevant InputEvents event (Scroll, MouseButtonDown or MouseButtonUp).
        /// </summary>
        private void DeviceOnMouseInput(object sender, MouseInputEventArgs e)
        {
            if (e.WheelDelta != 0)
            {
                Scroll?.Invoke(sender, e);
            }

            if (e.IsMouseDownEvent())
            {
                if (!pressedMouseButtons.Contains(e.GetMouseButton()))
                {
                    pressedMouseButtons.Add(e.GetMouseButton());
                }
                MouseButtonDown?.Invoke(sender, e);
            }
            else if (e.IsMouseUpEvent())
            {
                pressedMouseButtons.Remove(e.GetMouseButton());
                MouseButtonUp?.Invoke(sender, e);
            }
        }
Exemplo n.º 13
0
        void Mouse_ButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (_hoverWidget == null)
            {
                MouseButtonDown.Raise(this, e);
                return;
            }

            GraphicObject g = _hoverWidget;

            while (!g.Focusable)
            {
                g = g.Parent as GraphicObject;
                if (g == null)
                {
                    return;
                }
            }

            _activeWidget = g;
            _activeWidget.onMouseDown(this, e);
        }
Exemplo n.º 14
0
        public Node <INode> GetNode(string nodeName)
        {
            switch (nodeName)
            {
            case KeyDown.NAME:
                INode nodeKeyDown = new KeyDown() as INode;
                return(new Node <INode>(nodeKeyDown));

            case Key.NAME:
                INode nodeKey = new Key() as INode;
                return(new Node <INode>(nodeKey));

            case MouseButtonDown.NAME:
                INode nodeMouseButtonDown = new MouseButtonDown() as INode;
                return(new Node <INode>(nodeMouseButtonDown));

            case MousePosition.NAME:
                INode nodeMousePosition = new MousePosition() as INode;
                return(new Node <INode>(nodeMousePosition));

            default:
                return(null);
            }
        }
Exemplo n.º 15
0
 public void OnMouseButtonDown(int x, int y, MouseButton button)
 {
     MouseButtonDown?.Invoke(this, x, y, button);
 }
Exemplo n.º 16
0
        public void Update()
        {
            InputEvent e;

            if (events_.Count > 0)
            {
                while (events_.Count > 0)
                {
                    e = events_.Pop();
                    switch (e.type_)
                    {
                    case InputEventType.KeyboardEvent:

                        KeyboardEvent ke = (KeyboardEvent)e;

                        switch (ke.keyboardtype_)
                        {
                        case KeyboardEventType.KeyDown:
                            if (KeyDown != null)
                            {
                                KeyDown.Invoke(ke);
                            }
                            break;

                        case KeyboardEventType.KeyUp:
                            if (KeyUp != null)
                            {
                                KeyUp.Invoke(ke);
                            }
                            break;
                        }

                        break;

                    case InputEventType.MouseEvent:

                        MouseEvent me = (MouseEvent)e;

                        switch (me.mouseeventtype_)
                        {
                        case MouseEventType.MouseMove:

                            if (MouseMove != null)
                            {
                                MouseMove.Invoke(me);
                            }

                            break;

                        case MouseEventType.MouseDown:
                            if (MouseButtonDown != null)
                            {
                                MouseButtonDown.Invoke(me);
                            }

                            break;

                        case MouseEventType.MouseUp:
                            if (MouseButtonUp != null)
                            {
                                MouseButtonUp.Invoke(me);
                            }
                            break;

                        case MouseEventType.MouseWheel:
                            if (MouseWheel != null)
                            {
                                MouseWheel.Invoke(me);
                            }
                            break;
                        }
                        break;
                    }
                }
            }
        }
Exemplo n.º 17
0
        void picturebox_MouseDown(object sender, MouseEventArgs e)
        {
            if (!_active)
            {
                return;
            }

            _curMousePoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));
            _cursorBlip.Sphere.Position.StoreNewValues(_curMousePoint);

            if (e.Button == MouseButtons.Left)
            {
                _isMouseDown = MouseButtonDown.Left;
            }
            else if (e.Button == MouseButtons.Right)
            {
                _isMouseDown = MouseButtonDown.Right;
            }
        }
Exemplo n.º 18
0
 protected virtual void OnMouseDown(MouseEventArgs e)
 {
     MouseButtonDown?.Invoke(this, e);
 }
Exemplo n.º 19
0
        void picturebox_MouseUp(object sender, MouseEventArgs e)
        {
            if (!_active)
            {
                return;
            }

            if (_isMouseDown == MouseButtonDown.Left && e.Button == MouseButtons.Left)
            {
                #region Left

                _isMouseDown = MouseButtonDown.None;
                _curMousePoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));

                switch (_mode)
                {
                    case SelectionMode.Rectangle:
                        #region Add Objects Inside Rectangle

                        // Add any objects that were in the rectangle (I don't need to look at ctrl or shift here, I'm just adding)
                        foreach (RadarBlip blip in _map.GetAllBlips())
                        {
                            if (!_selectedObjects.Contains(blip.Token))
                            {
                                if (SelectionTest(blip, _mouseDownPoint, _curMousePoint))
                                {
                                    _selectedObjects.Add(blip.Token);
                                }
                            }
                        }

                        #endregion
                        break;

                    case SelectionMode.Selected:
                        #region Clear temp stationary objects

                        // While dragging, their velocities were manipulated, now just let them fly.  (they're still selected)

                        // Turn any temp stationary objects back into standard objects
                        foreach (RadarBlip blip in _map.GetAllBlips())
                        {
                            if (_tempStationaryObjects.Contains(blip.Token))
                            {
                                blip.CollisionStyle = CollisionStyle.Standard;
                            }
                        }

                        _tempStationaryObjects.Clear();

                        #endregion
                        break;

                    default:
                        throw new ApplicationException("Unknown SelectionMode: " + _mode);
                }

                // Set my mode
                if (_selectedObjects.Count > 0)
                {
                    _mode = SelectionMode.Selected;
                }
                else
                {
                    _mode = SelectionMode.None;
                }

                #endregion
            }
            else if (_isMouseDown == MouseButtonDown.Right && e.Button == MouseButtons.Right)
            {
                #region Right

                _isMouseDown = MouseButtonDown.None;
                _curMousePoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));

                // Apply the velocity to all the selected objects
                MyVector newVelocity = _curMousePoint - _mouseDownPoint;
                newVelocity.Divide(10);

                foreach (RadarBlip blip in _map.GetAllBlips())
                {
                    if (_selectedObjects.Contains(blip.Token))
                    {
                        if (blip is BallBlip)
                        {
                            ((BallBlip)blip).Ball.Velocity.StoreNewValues(newVelocity);
                        }
                    }
                }

                #endregion
            }

        }
Exemplo n.º 20
0
        void picturebox_MouseUp(object sender, MouseEventArgs e)
        {
            if (!_active)
            {
                return;
            }

            _curMousePoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));

            if (_isMouseDown == MouseButtonDown.Left && e.Button == MouseButtons.Left)
            {
                _isMouseDown = MouseButtonDown.None;
            }
            else if (_isMouseDown == MouseButtonDown.Right && e.Button == MouseButtons.Right)
            {
                _isMouseDown = MouseButtonDown.None;
            }

        }
Exemplo n.º 21
0
        public Node <INode> GetNode(string nodeName)
        {
            switch (nodeName)
            {
            case DeltaTime.NAME:
                INode nodeDeltaTime = new DeltaTime() as INode;
                return(new Node <INode> (nodeDeltaTime));

            case KeyDown.NAME:
                INode nodeKeyDown = new KeyDown() as INode;
                return(new Node <INode> (nodeKeyDown));

            case Transform.NAME:
                INode nodeTransform = new Transform() as INode;
                return(new Node <INode> (nodeTransform));

            case Vec3.NAME:
                INode nodeVec3 = new Vec3() as INode;
                return(new Node <INode> (nodeVec3));

            case Key.NAME:
                INode nodeKey = new Key() as INode;
                return(new Node <INode> (nodeKey));

            case FindByName.NAME:
                INode nodeFindByName = new FindByName() as INode;
                return(new Node <INode> (nodeFindByName));

            case ObjectAttribute.NAME:
                INode nodeObjectAttribute = new ObjectAttribute() as INode;
                return(new Node <INode> (nodeObjectAttribute));

            case SplitVec3.NAME:
                INode nodeSplitVec3 = new SplitVec3() as INode;
                return(new Node <INode> (nodeSplitVec3));

            case Update.NAME:
                INode nodeUpdate = new Update() as INode;
                return(new Node <INode> (nodeUpdate));

            case LateUpdate.NAME:
                INode nodeLateUpdate = new LateUpdate() as INode;
                return(new Node <INode> (nodeLateUpdate));

            case MouseButtonDown.NAME:
                INode nodeMouseButtonDown = new MouseButtonDown() as INode;
                return(new Node <INode> (nodeMouseButtonDown));

            case PlayerPreferences.NAME:
                INode nodePlayerPref = new PlayerPreferences() as INode;
                return(new Node <INode> (nodePlayerPref));

            case SetActive.NAME:
                INode nodeSetActive = new SetActive() as INode;
                return(new Node <INode> (nodeSetActive));

            case LoadScene.NAME:
                INode nodeLoadScene = new LoadScene() as INode;
                return(new Node <INode> (nodeLoadScene));

            case MousePosition.NAME:
                INode nodeMousePosition = new MousePosition() as INode;
                return(new Node <INode> (nodeMousePosition));

            case ScreenToWorld.NAME:
                INode nodeScreenToWorld = new ScreenToWorld() as INode;
                return(new Node <INode> (nodeScreenToWorld));

            case LookAtPosition.NAME:
                INode nodeLookAt = new LookAtPosition() as INode;
                return(new Node <INode> (nodeLookAt));

            case GetComponent.NAME:
                INode nodeGetComponent = new GetComponent() as INode;
                return(new Node <INode> (nodeGetComponent));

            case Color.NAME:
                INode nodeColor = new Color() as INode;
                return(new Node <INode> (nodeColor));

            default:
                return(null);
            }
        }
Exemplo n.º 22
0
        void picturebox_MouseUp(object sender, MouseEventArgs e)
        {
            if (!_active)
            {
                return;
            }

            if (_isMouseDown == MouseButtonDown.Left && e.Button == MouseButtons.Left)
            {
                #region Left

                _isMouseDown   = MouseButtonDown.None;
                _curMousePoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));

                switch (_mode)
                {
                case SelectionMode.Rectangle:
                    #region Add Objects Inside Rectangle

                    // Add any objects that were in the rectangle (I don't need to look at ctrl or shift here, I'm just adding)
                    foreach (RadarBlip blip in _map.GetAllBlips())
                    {
                        if (!_selectedObjects.Contains(blip.Token))
                        {
                            if (SelectionTest(blip, _mouseDownPoint, _curMousePoint))
                            {
                                _selectedObjects.Add(blip.Token);
                            }
                        }
                    }

                    #endregion
                    break;

                case SelectionMode.Selected:
                    #region Clear temp stationary objects

                    // While dragging, their velocities were manipulated, now just let them fly.  (they're still selected)

                    // Turn any temp stationary objects back into standard objects
                    foreach (RadarBlip blip in _map.GetAllBlips())
                    {
                        if (_tempStationaryObjects.Contains(blip.Token))
                        {
                            blip.CollisionStyle = CollisionStyle.Standard;
                        }
                    }

                    _tempStationaryObjects.Clear();

                    #endregion
                    break;

                default:
                    throw new ApplicationException("Unknown SelectionMode: " + _mode);
                }

                // Set my mode
                if (_selectedObjects.Count > 0)
                {
                    _mode = SelectionMode.Selected;
                }
                else
                {
                    _mode = SelectionMode.None;
                }

                #endregion
            }
            else if (_isMouseDown == MouseButtonDown.Right && e.Button == MouseButtons.Right)
            {
                #region Right

                _isMouseDown   = MouseButtonDown.None;
                _curMousePoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));

                // Apply the velocity to all the selected objects
                MyVector newVelocity = _curMousePoint - _mouseDownPoint;
                newVelocity.Divide(10);

                foreach (RadarBlip blip in _map.GetAllBlips())
                {
                    if (_selectedObjects.Contains(blip.Token))
                    {
                        if (blip is BallBlip)
                        {
                            ((BallBlip)blip).Ball.Velocity.StoreNewValues(newVelocity);
                        }
                    }
                }

                #endregion
            }
        }
Exemplo n.º 23
0
        public Node <INode> GetNode(string nodeName)
        {
            switch (nodeName)
            {
            case DeltaTime.NAME:
                INode nodeDeltaTime = new DeltaTime() as INode;
                return(new Node <INode> (nodeDeltaTime));

            case KeyDown.NAME:
                INode nodeKeyDown = new KeyDown() as INode;
                return(new Node <INode> (nodeKeyDown));

            case Transform.NAME:
                INode nodeTransform = new Transform() as INode;
                return(new Node <INode> (nodeTransform));

            case Vec3.NAME:
                INode nodeVec3 = new Vec3() as INode;
                return(new Node <INode> (nodeVec3));

            case Key.NAME:
                INode nodeKey = new Key() as INode;
                return(new Node <INode> (nodeKey));

            case FindByName.NAME:
                INode nodeFindByName = new FindByName() as INode;
                return(new Node <INode> (nodeFindByName));

            case ObjectAttribute.NAME:
                INode nodeObjectAttribute = new ObjectAttribute() as INode;
                return(new Node <INode> (nodeObjectAttribute));

            case SplitVec3.NAME:
                INode nodeSplitVec3 = new SplitVec3() as INode;
                return(new Node <INode> (nodeSplitVec3));

            case Update.NAME:
                INode nodeUpdate = new Update() as INode;
                return(new Node <INode> (nodeUpdate));

            case LateUpdate.NAME:
                INode nodeLateUpdate = new LateUpdate() as INode;
                return(new Node <INode> (nodeLateUpdate));

            case MouseButtonDown.NAME:
                INode nodeMouseButtonDown = new MouseButtonDown() as INode;
                return(new Node <INode> (nodeMouseButtonDown));

            case PlayerPreferences.NAME:
                INode nodePlayerPref = new PlayerPreferences() as INode;
                return(new Node <INode> (nodePlayerPref));

            case SetActive.NAME:
                INode nodeSetActive = new SetActive() as INode;
                return(new Node <INode> (nodeSetActive));

            case LoadScene.NAME:
                INode nodeLoadScene = new LoadScene() as INode;
                return(new Node <INode> (nodeLoadScene));

            case MousePosition.NAME:
                INode nodeMousePosition = new MousePosition() as INode;
                return(new Node <INode> (nodeMousePosition));

            case ScreenToWorld.NAME:
                INode nodeScreenToWorld = new ScreenToWorld() as INode;
                return(new Node <INode> (nodeScreenToWorld));

            case LookAtPosition.NAME:
                INode nodeLookAt = new LookAtPosition() as INode;
                return(new Node <INode> (nodeLookAt));

            case GetComponent.NAME:
                INode nodeGetComponent = new GetComponent() as INode;
                return(new Node <INode> (nodeGetComponent));

            case Color.NAME:
                INode nodeColor = new Color() as INode;
                return(new Node <INode> (nodeColor));

            case Instantiate.NAME:
                INode instantiate = new Instantiate() as INode;
                return(new Node <INode> (instantiate));

            case MaterialColor.NAME:
                INode materialColor = new MaterialColor()  as INode;
                return(new Node <INode> (materialColor));

            case Quit.NAME:
                INode quit = new Quit() as INode;
                return(new Node <INode> (quit));

            case LoadTextFileAtPath.NAME:
                INode loadTextFileAtPath = new LoadTextFileAtPath() as INode;
                return(new Node <INode>(loadTextFileAtPath));

            case StreamingAssetsPath.NAME:
                INode streamingAssetsPath = new StreamingAssetsPath() as INode;
                return(new Node <INode>(streamingAssetsPath));

            case AddConstellationBehaviourFromJSON.NAME:
                INode addConstellationBehaviourFromJSON = new AddConstellationBehaviourFromJSON() as INode;
                return(new Node <INode>(addConstellationBehaviourFromJSON));

            default:
                return(null);
            }
        }
Exemplo n.º 24
0
        void picturebox_MouseDown(object sender, MouseEventArgs e)
        {
            if (!_active)
            {
                return;
            }

            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
            {
                _mouseDownPoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));
                _curMousePoint = _mouseDownPoint.Clone();
                _prevMousePositions.Clear();
                _tempStationaryObjects.Clear();		// this should be cleared by now anyway
            }

            if (e.Button == MouseButtons.Left)
            {
                #region Left

                _isMouseDown = MouseButtonDown.Left;

                // Get all the blips
                List<RadarBlip> remainingBlips = new List<RadarBlip>(_map.GetAllBlips());

                bool selectedPrevious = false;
                #region See if they selected one of the previously selected objects

                foreach (long token in _selectedObjects)
                {
                    RadarBlip blip = FindAndRemove(token, remainingBlips);

                    if (blip == null)
                    {
                        continue;
                    }

                    if (selectedPrevious)
                    {
                        // I just wanted to remove this blip from the total list
                        continue;
                    }

                    if (SelectionTest(blip, _curMousePoint))
                    {
                        selectedPrevious = true;
                    }
                }

                #endregion

                // Check for ctrl or shift key being pressed (if they are, don't clear the previous)
                if (!selectedPrevious && !(_isShiftPressed || _isCtrlPressed))
                {
                    _selectedObjects.Clear();
                }

                bool selectedNew = false;
                #region See if they clicked on any other objects

                foreach (RadarBlip blip in remainingBlips)
                {
                    if (SelectionTest(blip, _curMousePoint))
                    {
                        _selectedObjects.Add(blip.Token);
                        selectedNew = true;
                    }
                }

                #endregion

                // Set my mode
                if (selectedPrevious || selectedNew)
                {
                    _mode = SelectionMode.Selected;

                    #region Rebuild the offsets list (and temp stationary)

                    _draggingPositionOffsets.Clear();
                    foreach (RadarBlip blip in _map.GetAllBlips())
                    {
                        if (_selectedObjects.Contains(blip.Token))
                        {
                            _draggingPositionOffsets.Add(blip.Token, blip.Sphere.Position - _curMousePoint);

                            if (blip.CollisionStyle == CollisionStyle.Standard)
                            {
                                _tempStationaryObjects.Add(blip.Token);
                                blip.CollisionStyle = CollisionStyle.Stationary;
                            }
                        }
                    }

                    #endregion
                }
                else
                {
                    _mode = SelectionMode.Rectangle;
                }

                #endregion
            }
            else if (e.Button == MouseButtons.Right)
            {
                #region Right

                if (_mode == SelectionMode.Selected && _selectedObjects.Count > 0)
                {
                    _isMouseDown = MouseButtonDown.Right;
                }
                else
                {
                    // If nothing is selected, then there is nothing for me to do
                    _isMouseDown = MouseButtonDown.None;
                }

                #endregion
            }
        }
Exemplo n.º 25
0
 protected virtual void OnMouseButtonDown(MouseButtonEvent e)
 {
     MouseButtonDown.Raise(e);
 }
Exemplo n.º 26
0
 private void OnMouseButtonDown(IMouse mouse, MouseButton button)
 {
     MouseButtonDown?.Invoke(mouse, button);
 }
Exemplo n.º 27
0
        public override void EnterMessageLoop(bool runInBackground)
        {
            IntPtr e       = System.Runtime.InteropServices.Marshal.AllocHGlobal(24 * sizeof(long));
            bool   running = true;

            while (running)
            {
                while (XPending(_display) != 0)
                {
                    XNextEvent(_display, e);

                    if (XFilterEvent(e, IntPtr.Zero))
                    {
                        continue;
                    }

                    XAnyEvent anyEvent = (XAnyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XAnyEvent));

                    switch ((Event)anyEvent.type)
                    {
                    case Event.ClientMessage:
                    {
                        running = false;
                        break;
                    }

                    case Event.ConfigureNotify:
                    {
                        XConfigureEvent configureEvent = (XConfigureEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XConfigureEvent));

                        LocationChanged?.Invoke(this, configureEvent.x, configureEvent.y);
                        SizeChanged?.Invoke(this, configureEvent.width, configureEvent.height);
                        break;
                    }

                    case Event.FocusIn:
                    {
                        Activated?.Invoke(this);
                        break;
                    }

                    case Event.FocusOut:
                    {
                        Deactivated?.Invoke(this);
                        break;
                    }

                    case Event.MotionNotify:
                    {
                        XMotionEvent motionEvent = (XMotionEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XMotionEvent));
                        MouseMove?.Invoke(this, motionEvent.x, motionEvent.y);
                        break;
                    }

                    case Event.ButtonPress:
                    {
                        XButtonEvent buttonEvent = (XButtonEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XButtonEvent));

                        switch ((Button)buttonEvent.button)
                        {
                        case Button.Button1:
                        {
                            MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Left);
                            break;
                        }

                        case Button.Button2:
                        {
                            MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Middle);
                            break;
                        }

                        case Button.Button3:
                        {
                            MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Right);
                            break;
                        }

                        case Button.Button4:
                        {
                            MouseWheel?.Invoke(this, buttonEvent.x, buttonEvent.y, 120);
                            break;
                        }

                        case Button.Button5:
                        {
                            MouseWheel?.Invoke(this, buttonEvent.x, buttonEvent.y, -120);
                            break;
                        }
                        }
                        break;
                    }

                    case Event.ButtonRelease:
                    {
                        XButtonEvent buttonEvent = (XButtonEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XButtonEvent));

                        switch ((Button)buttonEvent.button)
                        {
                        case Button.Button1:
                        {
                            MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Left);
                            break;
                        }

                        case Button.Button2:
                        {
                            MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Middle);
                            break;
                        }

                        case Button.Button3:
                        {
                            MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Right);
                            break;
                        }
                        }
                        break;
                    }

                    case Event.KeyPress:
                    {
                        XKeyEvent keyEvent = (XKeyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XKeyEvent));
                        KeySym    ks       = XLookupKeysym(ref keyEvent, 0);
                        Key       key      = NoesisKey(ks);
                        if (key != Key.None)
                        {
                            KeyDown?.Invoke(this, key);
                        }

                        if (_xic != IntPtr.Zero)
                        {
                            Status status = 0;
                            byte[] buffer = new byte[256];
                            KeySym ret_ks = (KeySym)0;
                            int    size   = Xutf8LookupString(_xic, e, buffer, 255, ref ret_ks, ref status);
                            if (size > 0 && ((int)status == XLookupChars || (int)status == XLookupBoth))
                            {
                                buffer[size] = 0;
                                Decoder decoder   = _utf8.GetDecoder();
                                char[]  text      = new char[256];
                                int     bytesUsed = 0;
                                int     charsUsed = 0;
                                bool    completed = false;
                                decoder.Convert(buffer, 0, size, text, 0, 255, true, out bytesUsed, out charsUsed, out completed);
                                for (int i = 0; i < charsUsed; ++i)
                                {
                                    Char?.Invoke(this, text[i]);
                                }
                            }
                        }
                        break;
                    }

                    case Event.KeyRelease:
                    {
                        XKeyEvent keyEvent = (XKeyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XKeyEvent));
                        KeySym    ks       = XLookupKeysym(ref keyEvent, 0);
                        Key       key      = NoesisKey(ks);
                        if (key != Key.None)
                        {
                            KeyUp?.Invoke(this, key);
                        }
                        break;
                    }
                    }
                }

                Render?.Invoke(this);
            }
            System.Runtime.InteropServices.Marshal.FreeHGlobal(e);
        }
Exemplo n.º 28
0
        void picturebox_MouseDown(object sender, MouseEventArgs e)
        {
            if (!_active)
            {
                return;
            }

            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
            {
                _mouseDownPoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));
                _curMousePoint  = _mouseDownPoint.Clone();
                _prevMousePositions.Clear();
                _tempStationaryObjects.Clear();         // this should be cleared by now anyway
            }

            if (e.Button == MouseButtons.Left)
            {
                #region Left

                _isMouseDown = MouseButtonDown.Left;

                // Get all the blips
                List <RadarBlip> remainingBlips = new List <RadarBlip>(_map.GetAllBlips());

                bool selectedPrevious = false;
                #region See if they selected one of the previously selected objects

                foreach (long token in _selectedObjects)
                {
                    RadarBlip blip = FindAndRemove(token, remainingBlips);

                    if (blip == null)
                    {
                        continue;
                    }

                    if (selectedPrevious)
                    {
                        // I just wanted to remove this blip from the total list
                        continue;
                    }

                    if (SelectionTest(blip, _curMousePoint))
                    {
                        selectedPrevious = true;
                    }
                }

                #endregion

                // Check for ctrl or shift key being pressed (if they are, don't clear the previous)
                if (!selectedPrevious && !(_isShiftPressed || _isCtrlPressed))
                {
                    _selectedObjects.Clear();
                }

                bool selectedNew = false;
                #region See if they clicked on any other objects

                foreach (RadarBlip blip in remainingBlips)
                {
                    if (SelectionTest(blip, _curMousePoint))
                    {
                        _selectedObjects.Add(blip.Token);
                        selectedNew = true;
                    }
                }

                #endregion

                // Set my mode
                if (selectedPrevious || selectedNew)
                {
                    _mode = SelectionMode.Selected;

                    #region Rebuild the offsets list (and temp stationary)

                    _draggingPositionOffsets.Clear();
                    foreach (RadarBlip blip in _map.GetAllBlips())
                    {
                        if (_selectedObjects.Contains(blip.Token))
                        {
                            _draggingPositionOffsets.Add(blip.Token, blip.Sphere.Position - _curMousePoint);

                            if (blip.CollisionStyle == CollisionStyle.Standard)
                            {
                                _tempStationaryObjects.Add(blip.Token);
                                blip.CollisionStyle = CollisionStyle.Stationary;
                            }
                        }
                    }

                    #endregion
                }
                else
                {
                    _mode = SelectionMode.Rectangle;
                }

                #endregion
            }
            else if (e.Button == MouseButtons.Right)
            {
                #region Right

                if (_mode == SelectionMode.Selected && _selectedObjects.Count > 0)
                {
                    _isMouseDown = MouseButtonDown.Right;
                }
                else
                {
                    // If nothing is selected, then there is nothing for me to do
                    _isMouseDown = MouseButtonDown.None;
                }

                #endregion
            }
        }