Ejemplo n.º 1
0
        protected override void OnEvent(WindowMessageType msg, IntPtr wParam, IntPtr lParam)
        {
            base.OnEvent(msg, wParam, lParam);

            // Pass all remaining windows messages to camera so it can respond to user input
            this.camera?.HandleMessages(this.Handle, msg, wParam, lParam);
        }
        protected override void OnEvent(WindowMessageType msg, IntPtr wParam, IntPtr lParam)
        {
            base.OnEvent(msg, wParam, lParam);

            // Pass all windows messages to camera so it can respond to user input
            this.camera?.HandleMessages(this.Handle, msg, wParam, lParam);
            this.lightCamera?.HandleMessages(this.Handle, msg, wParam, lParam);

            switch (msg)
            {
            case WindowMessageType.LeftButtonDown:
            case WindowMessageType.MiddleButtonDown:
            case WindowMessageType.RightButtonDown:
            {
                bool bLeftButtonDown   = ((MouseKeys)wParam & MouseKeys.LeftButton) != 0;
                bool bRightButtonDown  = ((MouseKeys)wParam & MouseKeys.RightButton) != 0;
                bool bMiddleButtonDown = ((MouseKeys)wParam & MouseKeys.MiddleButton) != 0;

                bool bOldLeftButtonDown   = g_bLeftButtonDown;
                bool bOldRightButtonDown  = g_bRightButtonDown;
                bool bOldMiddleButtonDown = g_bMiddleButtonDown;
                g_bLeftButtonDown   = bLeftButtonDown;
                g_bMiddleButtonDown = bMiddleButtonDown;
                g_bRightButtonDown  = bRightButtonDown;

                if (bOldLeftButtonDown && !g_bLeftButtonDown)
                {
                    this.camera.SetEnablePositionMovement(false);
                }
                else if (!bOldLeftButtonDown && g_bLeftButtonDown)
                {
                    this.camera.SetEnablePositionMovement(true);
                }

                if (!bOldRightButtonDown && g_bRightButtonDown)
                {
                    this.camera.SetEnablePositionMovement(false);
                }

                if (bOldMiddleButtonDown && !g_bMiddleButtonDown)
                {
                    this.lightCamera.SetEnablePositionMovement(false);
                }
                else if (!bOldMiddleButtonDown && g_bMiddleButtonDown)
                {
                    this.lightCamera.SetEnablePositionMovement(true);
                    this.camera.SetEnablePositionMovement(false);
                }

                // If no mouse button is down at all, enable camera movement.
                if (!g_bLeftButtonDown && !g_bRightButtonDown && !g_bMiddleButtonDown)
                {
                    this.camera.SetEnablePositionMovement(true);
                }

                break;
            }
            }
        }
 protected internal virtual void OnEvent(WindowMessageType msg, IntPtr wParam, IntPtr lParam)
 {
     switch (msg)
     {
     case WindowMessageType.SetText:
         this.NotifyPropertyChanged("Title");
         break;
     }
 }
Ejemplo n.º 4
0
        private IntPtr Callback(IntPtr hWnd, WindowMessageType msg, IntPtr wParam, IntPtr lParam)
        {
            switch (msg)
            {
            case WindowMessageType.Destroy:
                NativeMethods.PostQuitMessage(0);
                return(new IntPtr(1));

            case WindowMessageType.KeyDown:
                switch ((VirtualKey)wParam)
                {
                case VirtualKey.Escape:
                    NativeMethods.PostQuitMessage(0);
                    break;
                }
                break;

            default:
                return(NativeMethods.DefWindowProc(hWnd, msg, wParam, lParam));
            }

            return(IntPtr.Zero);
        }
        public override void HandleMessages(IntPtr hWnd, WindowMessageType msg, IntPtr wParam, IntPtr lParam)
        {
            base.HandleMessages(hWnd, msg, wParam, lParam);

            // Current mouse position
            int iMouseX = (short)((ulong)lParam & 0xffffU);
            int iMouseY = (short)((ulong)lParam >> 16);

            if (((msg == WindowMessageType.LeftButtonDown || msg == WindowMessageType.LeftButtonDoubleClick) &&
                 (m_nRotateModelButtonMask & SdkCameraMouseKeys.LeftButton) != 0) ||
                ((msg == WindowMessageType.MiddleButtonDown || msg == WindowMessageType.MiddleButtonDoubleClick) &&
                 (m_nRotateModelButtonMask & SdkCameraMouseKeys.MiddleButton) != 0) ||
                ((msg == WindowMessageType.RightButtonDown || msg == WindowMessageType.RightButtonDoubleClick) &&
                 (m_nRotateModelButtonMask & SdkCameraMouseKeys.RightButton) != 0))
            {
                m_WorldArcBall.OnBegin(iMouseX, iMouseY);
            }

            if (((msg == WindowMessageType.LeftButtonDown || msg == WindowMessageType.LeftButtonDoubleClick) &&
                 (m_nRotateCameraButtonMask & SdkCameraMouseKeys.LeftButton) != 0) ||
                ((msg == WindowMessageType.MiddleButtonDown || msg == WindowMessageType.MiddleButtonDoubleClick) &&
                 (m_nRotateCameraButtonMask & SdkCameraMouseKeys.MiddleButton) != 0) ||
                ((msg == WindowMessageType.RightButtonDown || msg == WindowMessageType.RightButtonDoubleClick) &&
                 (m_nRotateCameraButtonMask & SdkCameraMouseKeys.RightButton) != 0))
            {
                m_ViewArcBall.OnBegin(iMouseX, iMouseY);
            }

            if (msg == WindowMessageType.MouseMove)
            {
                m_WorldArcBall.OnMove(iMouseX, iMouseY);
                m_ViewArcBall.OnMove(iMouseX, iMouseY);
            }

            if ((msg == WindowMessageType.LeftButtonUp && (m_nRotateModelButtonMask & SdkCameraMouseKeys.LeftButton) != 0) ||
                (msg == WindowMessageType.MiddleButtonUp && (m_nRotateModelButtonMask & SdkCameraMouseKeys.MiddleButton) != 0) ||
                (msg == WindowMessageType.RightButtonUp && (m_nRotateModelButtonMask & SdkCameraMouseKeys.RightButton) != 0))
            {
                m_WorldArcBall.OnEnd();
            }

            if ((msg == WindowMessageType.LeftButtonUp && (m_nRotateCameraButtonMask & SdkCameraMouseKeys.LeftButton) != 0) ||
                (msg == WindowMessageType.MiddleButtonUp && (m_nRotateCameraButtonMask & SdkCameraMouseKeys.MiddleButton) != 0) ||
                (msg == WindowMessageType.RightButtonUp && (m_nRotateCameraButtonMask & SdkCameraMouseKeys.RightButton) != 0))
            {
                m_ViewArcBall.OnEnd();
            }

            if (msg == WindowMessageType.CaptureChanged)
            {
                if (lParam != hWnd)
                {
                    if (((m_nRotateModelButtonMask & SdkCameraMouseKeys.LeftButton) != 0) ||
                        ((m_nRotateModelButtonMask & SdkCameraMouseKeys.MiddleButton) != 0) ||
                        ((m_nRotateModelButtonMask & SdkCameraMouseKeys.RightButton) != 0))
                    {
                        m_WorldArcBall.OnEnd();
                    }

                    if (((m_nRotateCameraButtonMask & SdkCameraMouseKeys.LeftButton) != 0) ||
                        ((m_nRotateCameraButtonMask & SdkCameraMouseKeys.MiddleButton) != 0) ||
                        ((m_nRotateCameraButtonMask & SdkCameraMouseKeys.RightButton) != 0))
                    {
                        m_ViewArcBall.OnEnd();
                    }
                }
            }

            if (msg == WindowMessageType.LeftButtonDown ||
                msg == WindowMessageType.LeftButtonDoubleClick ||
                msg == WindowMessageType.MiddleButtonDown ||
                msg == WindowMessageType.MiddleButtonDoubleClick ||
                msg == WindowMessageType.RightButtonDown ||
                msg == WindowMessageType.RightButtonDoubleClick ||
                msg == WindowMessageType.LeftButtonUp ||
                msg == WindowMessageType.MiddleButtonUp ||
                msg == WindowMessageType.RightButtonUp ||
                msg == WindowMessageType.MouseWheel ||
                msg == WindowMessageType.MouseMove)
            {
                m_bDragSinceLastUpdate = true;
            }
        }
Ejemplo n.º 6
0
 public WindowMessage(WindowMessageType type, object data)
 {
     this.Type = type;
     this.Data = data;
 }
Ejemplo n.º 7
0
 public static extern IntPtr SendMessage(IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] WindowMessageType wMsg, bool wParam, IntPtr lParam);
        protected override void OnEvent(WindowMessageType msg, IntPtr wParam, IntPtr lParam)
        {
            base.OnEvent(msg, wParam, lParam);

            this.activeCamera?.HandleMessages(this.Handle, msg, wParam, lParam);
        }
Ejemplo n.º 9
0
        public void HandleMessages(IntPtr hWnd, WindowMessageType msg, IntPtr wParam, IntPtr lParam)
        {
            // Current mouse position
            int iMouseX = (short)((ulong)lParam & 0xffffU);
            int iMouseY = (short)((ulong)lParam >> 16);

            switch (msg)
            {
            case WindowMessageType.LeftButtonDown:
            case WindowMessageType.MiddleButtonDown:
            case WindowMessageType.RightButtonDown:
            {
                if ((m_nRotateMask.HasFlag(SdkCameraMouseKeys.LeftButton) && msg == WindowMessageType.LeftButtonDown) ||
                    (m_nRotateMask.HasFlag(SdkCameraMouseKeys.MiddleButton) && msg == WindowMessageType.MiddleButtonDown) ||
                    (m_nRotateMask.HasFlag(SdkCameraMouseKeys.RightButton) && msg == WindowMessageType.RightButtonDown))
                {
                    m_ArcBall.OnBegin(iMouseX, iMouseY);
                    NativeMethods.SetCapture(hWnd);
                }

                break;
            }

            case WindowMessageType.MouseMove:
            {
                if (m_ArcBall.IsBeingDragged())
                {
                    m_ArcBall.OnMove(iMouseX, iMouseY);
                    UpdateLightDir();
                }

                break;
            }

            case WindowMessageType.LeftButtonUp:
            case WindowMessageType.MiddleButtonUp:
            case WindowMessageType.RightButtonUp:
            {
                if ((m_nRotateMask.HasFlag(SdkCameraMouseKeys.LeftButton) && msg == WindowMessageType.LeftButtonDown) ||
                    (m_nRotateMask.HasFlag(SdkCameraMouseKeys.MiddleButton) && msg == WindowMessageType.MiddleButtonDown) ||
                    (m_nRotateMask.HasFlag(SdkCameraMouseKeys.RightButton) && msg == WindowMessageType.RightButtonDown))
                {
                    m_ArcBall.OnEnd();
                    NativeMethods.ReleaseCapture();
                }

                UpdateLightDir();
                break;
            }

            case WindowMessageType.CaptureChanged:
            {
                if (lParam != hWnd)
                {
                    if (m_nRotateMask.HasFlag(SdkCameraMouseKeys.LeftButton) ||
                        m_nRotateMask.HasFlag(SdkCameraMouseKeys.MiddleButton) ||
                        m_nRotateMask.HasFlag(SdkCameraMouseKeys.RightButton))
                    {
                        m_ArcBall.OnEnd();
                        NativeMethods.ReleaseCapture();
                    }
                }

                break;
            }
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 ///     Determines whether this window message matches the specified <paramref name="type"/>.
 /// </summary>
 /// <param name="type">
 ///     Window message type to check for equality.
 /// </param>
 /// <returns>
 ///     <c>true</c> if this window message matches the specified <paramref name="type"/>; otherwise <c>false</c>.
 /// </returns>
 public bool Is(WindowMessageType type)
 {
     return(Id == type.ToInt32());
 }
        private IntPtr Callback(IntPtr hWnd, WindowMessageType msg, IntPtr wParam, IntPtr lParam)
        {
            this.window.OnEvent(msg, wParam, lParam);

            switch (msg)
            {
            case WindowMessageType.Destroy:
                this.doPostQuitMessage = true;
                return(new IntPtr(1));

            case WindowMessageType.GetMinMaxInfo:
                Marshal.WriteInt32(lParam, 24, 150);
                Marshal.WriteInt32(lParam, 28, 150);
                break;

            case WindowMessageType.Size:
                this.window.IsMinimized = wParam.ToInt32() == 1;
                break;

            case WindowMessageType.WindowPositionChanged:
            {
                int oldWidth  = this.window.Width;
                int oldHeight = this.window.Height;

                IntPtr rectPtr = Marshal.AllocHGlobal(16);

                try
                {
                    if (NativeMethods.GetClientRect(this.handle, rectPtr))
                    {
                        this.window.Width  = Marshal.ReadInt32(rectPtr, 8);
                        this.window.Height = Marshal.ReadInt32(rectPtr, 12);
                    }
                }
                finally
                {
                    Marshal.FreeHGlobal(rectPtr);
                }

                if (this.window.Width != oldWidth || this.window.Height != oldHeight)
                {
                    this.doOnWindowSizeChanged = true;
                }

                return(NativeMethods.DefWindowProc(hWnd, msg, wParam, lParam));
            }

            case WindowMessageType.Activate:
                this.window.IsActive = (wParam.ToInt32() & 0xFFFF) != 0;
                break;

            case WindowMessageType.ShowWindow:
                this.window.IsActive = (wParam.ToInt32()) != 0;
                break;

            case WindowMessageType.MouseActivate:
            case WindowMessageType.PointerActivate:
                this.window.Focus();
                break;

            case WindowMessageType.KeyDown:
            case WindowMessageType.KeyUp:
                this.window.OnKeyboardEvent((VirtualKey)wParam, (int)((ulong)lParam & 0xFFFFU), ((ulong)lParam & 0x40000000U) != 0, ((ulong)lParam & 0x80000000U) == 0);
                break;

            default:
                return(NativeMethods.DefWindowProc(hWnd, msg, wParam, lParam));
            }

            return(IntPtr.Zero);
        }
Ejemplo n.º 12
0
 public static extern bool PeekMessage([Out] out WindowMessage message, IntPtr handle, WindowMessageType filterMin, WindowMessageType filterMax, uint remove);
Ejemplo n.º 13
0
 public static extern bool GetMessage([Out] out WindowMessage message, IntPtr handle, WindowMessageType filterMin, WindowMessageType filterMax);
Ejemplo n.º 14
0
 public static extern IntPtr DefWindowProc(IntPtr hWnd, WindowMessageType msg, IntPtr wParam, IntPtr lParam);
Ejemplo n.º 15
0
        public virtual void HandleMessages(IntPtr hWnd, WindowMessageType msg, IntPtr wParam, IntPtr lParam)
        {
            // Current mouse position
            int iMouseX = (short)((ulong)lParam & 0xffffU);
            int iMouseY = (short)((ulong)lParam >> 16);

            switch (msg)
            {
            case WindowMessageType.ActivateApplication:
            {
                m_isActive = wParam.ToInt32() == 1;
                break;
            }

            case WindowMessageType.KeyDown:
            {
                // Map this key to a D3DUtil_CameraKeys enum and update the
                // state of m_aKeys[] by adding the KEY_WAS_DOWN_MASK|KEY_IS_DOWN_MASK mask
                // only if the key is not down
                SdkCameraKey mappedKey = MapKey((VirtualKey)wParam);

                if (mappedKey != SdkCameraKey.Unknown)
                {
                    if (!IsKeyDown(m_aKeys[(int)mappedKey]))
                    {
                        m_aKeys[(int)mappedKey] = SdkCameraKeyStates.WasDownMask | SdkCameraKeyStates.IsDownMask;
                        m_cKeysDown++;
                    }
                }

                break;
            }

            case WindowMessageType.KeyUp:
            {
                // Map this key to a D3DUtil_CameraKeys enum and update the
                // state of m_aKeys[] by removing the KEY_IS_DOWN_MASK mask.
                SdkCameraKey mappedKey = MapKey((VirtualKey)wParam);

                if (mappedKey != SdkCameraKey.Unknown)
                {
                    m_aKeys[(int)mappedKey] &= ~SdkCameraKeyStates.IsDownMask;
                    m_cKeysDown--;
                }

                break;
            }

            case WindowMessageType.RightButtonDown:
            case WindowMessageType.MiddleButtonDown:
            case WindowMessageType.LeftButtonDown:
            case WindowMessageType.RightButtonDoubleClick:
            case WindowMessageType.MiddleButtonDoubleClick:
            case WindowMessageType.LeftButtonDoubleClick:
            {
                // Compute the drag rectangle in screen coord.
                XMInt2 ptCursor = new XMInt2(iMouseX, iMouseY);

                // Update member var state
                if ((msg == WindowMessageType.LeftButtonDown || msg == WindowMessageType.LeftButtonDoubleClick) && NativeMethods.PtInRect(ref m_rcDrag, ptCursor))
                {
                    m_bMouseLButtonDown   = true;
                    m_nCurrentButtonMask |= MouseKeys.LeftButton;
                }

                if ((msg == WindowMessageType.MiddleButtonDown || msg == WindowMessageType.MiddleButtonDoubleClick) && NativeMethods.PtInRect(ref m_rcDrag, ptCursor))
                {
                    m_bMouseMButtonDown   = true;
                    m_nCurrentButtonMask |= MouseKeys.MiddleButton;
                }

                if ((msg == WindowMessageType.RightButtonDown || msg == WindowMessageType.RightButtonDoubleClick) && NativeMethods.PtInRect(ref m_rcDrag, ptCursor))
                {
                    m_bMouseRButtonDown   = true;
                    m_nCurrentButtonMask |= MouseKeys.RightButton;
                }

                // Capture the mouse, so if the mouse button is
                // released outside the window, we'll get the WM_LBUTTONUP message
                NativeMethods.SetCapture(hWnd);
                NativeMethods.GetCursorPos(out m_ptLastMousePosition);
                break;
            }

            case WindowMessageType.RightButtonUp:
            case WindowMessageType.MiddleButtonUp:
            case WindowMessageType.LeftButtonUp:
            {
                // Update member var state
                if (msg == WindowMessageType.LeftButtonUp)
                {
                    m_bMouseLButtonDown   = false;
                    m_nCurrentButtonMask &= ~MouseKeys.LeftButton;
                }

                if (msg == WindowMessageType.MiddleButtonUp)
                {
                    m_bMouseMButtonDown   = false;
                    m_nCurrentButtonMask &= ~MouseKeys.MiddleButton;
                }

                if (msg == WindowMessageType.RightButtonUp)
                {
                    m_bMouseRButtonDown   = false;
                    m_nCurrentButtonMask &= ~MouseKeys.RightButton;
                }

                // Release the capture if no mouse buttons down
                if (!m_bMouseLButtonDown &&
                    !m_bMouseRButtonDown &&
                    !m_bMouseMButtonDown)
                {
                    NativeMethods.ReleaseCapture();
                }

                break;
            }

            case WindowMessageType.CaptureChanged:
            {
                if (lParam != hWnd)
                {
                    if ((m_nCurrentButtonMask & MouseKeys.LeftButton) != 0 ||
                        (m_nCurrentButtonMask & MouseKeys.MiddleButton) != 0 ||
                        (m_nCurrentButtonMask & MouseKeys.RightButton) != 0)
                    {
                        m_bMouseLButtonDown   = false;
                        m_bMouseMButtonDown   = false;
                        m_bMouseRButtonDown   = false;
                        m_nCurrentButtonMask &= ~MouseKeys.LeftButton;
                        m_nCurrentButtonMask &= ~MouseKeys.MiddleButton;
                        m_nCurrentButtonMask &= ~MouseKeys.RightButton;
                        NativeMethods.ReleaseCapture();
                    }
                }

                break;
            }

            case WindowMessageType.MouseWheel:
            {
                // Update member var state
                m_nMouseWheelDelta += (short)((uint)wParam >> 16);
                break;
            }
            }
        }