/// <summary>
        /// Initializes a new instance of the <see cref="WinFormsKeyAndMouseInputHandler"/> class.
        /// </summary>
        public WinFormsKeyAndMouseInputHandler()
        {
            m_stateMouseOrPointer      = new MouseOrPointerState();
            m_stateMouseOrPointer.Type = MouseOrPointerType.Mouse;

            m_stateKeyboard = new KeyboardState();
        }
示例#2
0
        /// <summary>
        /// Stops input handling.
        /// </summary>
        public void Stop()
        {
            // Deregister all events
            if (m_rendererElement != null)
            {
                SeeingSharpRendererElement rendererElement = m_rendererElement;
                m_rendererElement.Dispatcher.BeginInvoke(new Action(() =>
                {
                    rendererElement.MouseWheel        -= OnRendererElement_MouseWheel;
                    rendererElement.MouseDown         -= OnRendererElement_MouseDown;
                    rendererElement.MouseUp           -= OnRendererElement_MouseUp;
                    rendererElement.MouseMove         -= OnRendererElement_MouseMove;
                    rendererElement.MouseLeave        -= OnRendererElement_MouseLeave;
                    rendererElement.LostFocus         -= OnRendererElement_LostFocus;
                    rendererElement.LostKeyboardFocus -= OnRendererElement_LostKeyboardFocus;
                    rendererElement.GotFocus          -= OnRenderElement_GotFocus;
                    rendererElement.PreviewMouseUp    -= OnRendererElement_PreviewMouseUp;
                }));
            }

            m_rendererElement = null;

            m_stateKeyboard       = new KeyboardState();
            m_stateMouseOrPointer = new MouseOrPointerState();
        }
示例#3
0
        private void AddState(InputStateBase inputState)
        {
            m_inputStates.Add(inputState);

            // Register first MouseOrPointer state as default
            if (this.DefaultMouseOrPointer == MouseOrPointerState.Dummy)
            {
                MouseOrPointerState mouseOrPointer = inputState as MouseOrPointerState;
                if (mouseOrPointer != null)
                {
                    this.DefaultMouseOrPointer = mouseOrPointer;
                }
            }

            // Register first Gamepad state as default
            if (this.DefaultGamepad == GamepadState.Dummy)
            {
                GamepadState gamepadState = inputState as GamepadState;
                if (gamepadState != null)
                {
                    this.DefaultGamepad = gamepadState;
                }
            }

            // Register first keyboard state as default
            if (this.DefaultKeyboard == KeyboardState.Dummy)
            {
                KeyboardState keyboardState = inputState as KeyboardState;
                if (keyboardState != null)
                {
                    this.DefaultKeyboard = keyboardState;
                }
            }
        }
示例#4
0
        /// <summary>
        /// Copies this object and then resets it
        /// in preparation of the next update pass.
        /// Called by update-render loop.
        /// </summary>
        protected override void CopyAndResetForUpdatePassInternal(InputStateBase targetState)
        {
            MouseOrPointerState targetStateCasted = targetState as MouseOrPointerState;

            targetStateCasted.EnsureNotNull(nameof(targetStateCasted));

            targetStateCasted.m_moveDistancePixel  = m_moveDistancePixel;
            targetStateCasted.m_screenSizePixel    = m_screenSizePixel;
            targetStateCasted.m_positionPixel      = m_positionPixel;
            targetStateCasted.m_wheelDelta         = m_wheelDelta;
            targetStateCasted.m_isInside           = m_isInside;
            targetStateCasted.m_mouseOrPointerType = m_mouseOrPointerType;
            for (int loop = 0; loop < BUTTON_COUNT; loop++)
            {
                targetStateCasted.m_buttonsDown[loop] = m_buttonsDown[loop];
                targetStateCasted.m_buttonsHit[loop]  = m_buttonsHit[loop];
                targetStateCasted.m_buttonsUp[loop]   = m_buttonsUp[loop];
            }

            // Reset current object
            m_moveDistancePixel = Vector2.Zero;
            m_wheelDelta        = 0;
            for (int loop = 0; loop < BUTTON_COUNT; loop++)
            {
                m_buttonsUp[loop] = false;

                if (m_buttonsHit[loop] || m_buttonsDown[loop])
                {
                    m_buttonsHit[loop]  = false;
                    m_buttonsDown[loop] = true;
                }
                else
                {
                    m_buttonsHit[loop]  = false;
                    m_buttonsDown[loop] = false;
                }
            }
        }