public static TileMouseState FromHwndMouseEventArgs(HwndMouseEventArgs e, Vector2Int32 tile)
 {
     return new TileMouseState
                {
                    LeftButton = e.LeftButton,
                    RightButton = e.RightButton,
                    MiddleButton = e.MiddleButton,
                    Location = tile
                };
 }
 private void xnaViewport_HwndRButtonUp(object sender, HwndMouseEventArgs e)
 {
     if (_wvm.CurrentWorld != null)
         _wvm.MouseUpTile(GetTileMouseState(e));
 }
 private void xnaViewport_HwndMouseWheel(object sender, HwndMouseEventArgs e)
 {
     Zoom(e.WheelDelta);
 }
 private void xnaViewport_HwndMouseMove(object sender, HwndMouseEventArgs e)
 {
     _mousePosition = PointToVector2(e.Position);
     if (_wvm.CurrentWorld != null)
         _wvm.MouseMoveTile(GetTileMouseState(e));
 }
 private void xnaViewport_HwndMouseLeave(object sender, HwndMouseEventArgs e)
 {
 }
 private void xnaViewport_HwndMButtonUp(object sender, HwndMouseEventArgs e)
 {
     _isMiddleMouseDown = false;
     xnaViewport.SetCursor(Cursors.Arrow);
 }
 private void xnaViewport_HwndMButtonDown(object sender, HwndMouseEventArgs e)
 {
     _middleClickPoint = PointToVector2(e.Position);
     xnaViewport.SetCursor(Cursors.SizeAll);
     _isMiddleMouseDown = true;
 }
 private TileMouseState GetTileMouseState(HwndMouseEventArgs e)
 {
     return TileMouseState.FromHwndMouseEventArgs(e,
                                                  new Vector2Int32(
                                                      (int)MathHelper.Clamp((float)(e.Position.X / _dpiScale.X / _zoom - _scrollPosition.X), 0, _wvm.CurrentWorld.TilesWide - 1),
                                                      (int)MathHelper.Clamp((float)(e.Position.Y / _dpiScale.Y / _zoom - _scrollPosition.Y), 0, _wvm.CurrentWorld.TilesHigh - 1)));
 }
예제 #9
0
        private void ResetMouseState()
        {
            // We need to invoke events for any buttons that were pressed
            bool fireL = mouseState.LeftButton == MouseButtonState.Pressed;
            bool fireM = mouseState.MiddleButton == MouseButtonState.Pressed;
            bool fireR = mouseState.RightButton == MouseButtonState.Pressed;
            bool fireX1 = mouseState.X1Button == MouseButtonState.Pressed;
            bool fireX2 = mouseState.X2Button == MouseButtonState.Pressed;

            // Update the state of all of the buttons
            mouseState.LeftButton = MouseButtonState.Released;
            mouseState.MiddleButton = MouseButtonState.Released;
            mouseState.RightButton = MouseButtonState.Released;
            mouseState.X1Button = MouseButtonState.Released;
            mouseState.X2Button = MouseButtonState.Released;

            // Fire any events
            HwndMouseEventArgs args = new HwndMouseEventArgs(mouseState);
            if (fireL && HwndLButtonUp != null)
                HwndLButtonUp(this, args);
            if (fireM && HwndMButtonUp != null)
                HwndMButtonUp(this, args);
            if (fireR && HwndRButtonUp != null)
                HwndRButtonUp(this, args);
            if (fireX1 && HwndX1ButtonUp != null)
                HwndX1ButtonUp(this, args);
            if (fireX2 && HwndX2ButtonUp != null)
                HwndX2ButtonUp(this, args);
            // The mouse is no longer considered to be in our window
            mouseInWindow = false;
        }