Exemplo n.º 1
0
        internal PointerStylusDevice(PointerTabletDevice tabletDevice, UnsafeNativeMethods.POINTER_DEVICE_CURSOR_INFO cursorInfo)
        {
            _cursorInfo   = cursorInfo;
            _tabletDevice = tabletDevice;
            _pointerLogic = StylusLogic.GetCurrentStylusLogicAs <PointerLogic>();

            // Touch devices have a special set of handling code
            if (tabletDevice.Type == TabletDeviceType.Touch)
            {
                TouchDevice = new PointerTouchDevice(this);
            }

            _interactionEngine = new PointerInteractionEngine(this);

            _interactionEngine.InteractionDetected += HandleInteraction;

            List <StylusButton> buttons = new List <StylusButton>();

            // Create a button collection for this StylusDevice based off the button properties stored in the tablet
            // This needs to be done as each button instance has a StylusDevice owner that it uses to access the raw
            // data in the StylusDevice.
            foreach (var prop in _tabletDevice.DeviceInfo.StylusPointProperties)
            {
                if (prop.IsButton)
                {
                    StylusButton button = new StylusButton(StylusPointPropertyIds.GetStringRepresentation(prop.Id), prop.Id);
                    button.SetOwner(this);
                    buttons.Add(button);
                }
            }

            _stylusButtons = new StylusButtonCollection(buttons);
        }
Exemplo n.º 2
0
        public static string ToText(this StylusButtonCollection bts)
        {
            StringBuilder sb = new StringBuilder();

            foreach (StylusButton bt in bts)
            {
                sb.AppendFormat(" {0}: {1} ", bt.Name, bt.StylusButtonState.ToString());
            }
            return(sb.ToString());
        }
Exemplo n.º 3
0
        //</Snippet7>

        //<Snippet23>
        void textbox1_StylusInRange(object sender, StylusEventArgs e)
        {
            StylusButtonCollection buttons = e.StylusDevice.StylusButtons;

            StylusButton barrelButton = buttons.GetStylusButtonByGuid(StylusPointProperties.BarrelButton.Id);

            if (barrelButton != null)
            {
                textbox1.AppendText(barrelButton.StylusButtonState.ToString());
            }

            textbox1.AppendText("\r\n");
        }
Exemplo n.º 4
0
        internal StylusDevice(TabletDevice tabletDevice, string sName, int id, bool fInverted, StylusButtonCollection stylusButtonCollection)
        {
            _tabletDevice       = tabletDevice;
            _sName              = sName;
            _id                 = id;
            _fInverted          = fInverted;
            // For tablet devices that can go out of range default them to
            // being out of range until we see some events from it.
            _fInRange      = false; // All tablets out of range by default.
            _stylusButtonCollection   = stylusButtonCollection;

#if MULTICAPTURE
            _overIsEnabledChangedEventHandler = new DependencyPropertyChangedEventHandler(OnOverIsEnabledChanged);
            _overIsVisibleChangedEventHandler = new DependencyPropertyChangedEventHandler(OnOverIsVisibleChanged);
            _overIsHitTestVisibleChangedEventHandler = new DependencyPropertyChangedEventHandler(OnOverIsHitTestVisibleChanged);
            _reevaluateStylusOverDelegate = new DispatcherOperationCallback(ReevaluateStylusOverAsync);
            _reevaluateStylusOverOperation = null;

            _captureIsEnabledChangedEventHandler = new DependencyPropertyChangedEventHandler(OnCaptureIsEnabledChanged);
            _captureIsVisibleChangedEventHandler = new DependencyPropertyChangedEventHandler(OnCaptureIsVisibleChanged);
            _captureIsHitTestVisibleChangedEventHandler = new DependencyPropertyChangedEventHandler(OnCaptureIsHitTestVisibleChanged);
            _reevaluateCaptureDelegate = new DispatcherOperationCallback(ReevaluateCaptureAsync);
            _reevaluateCaptureOperation = null;
#endif

            if (_stylusButtonCollection != null)
            {
                foreach (StylusButton button in _stylusButtonCollection)
                {
                    button.SetOwner(this);
                }
            }

            // Because the stylus device gets a steady stream of input events when it is in range,
            // we don't have to be so careful about responding to layout changes as we have to be
            // with the mouse.
            // InputManager.Current.HitTestInvalidatedAsync += new EventHandler(OnHitTestInvalidatedAsync);

            InputManager inputManager = (InputManager)Dispatcher.InputManager;
            _stylusLogic = inputManager.StylusLogic;
            _stylusLogic.RegisterStylusDeviceCore(this);
        }
Exemplo n.º 5
0
        private static StylusDeviceInfo[] GetStylusDevicesInfo(IPimcTablet pimcTablet)
        {
            int cCursors;

            pimcTablet.GetCursorCount(out cCursors); // Calls Unmanaged code - SecurityCritical with SUC.

            StylusDeviceInfo[] stylusDevicesInfo = new StylusDeviceInfo[cCursors];

            for ( int iCursor = 0; iCursor < cCursors; iCursor++ )
            {
                string sCursorName;
                int cursorId;
                bool fCursorInverted;
                pimcTablet.GetCursorInfo(iCursor, out sCursorName, out cursorId, out fCursorInverted); // Calls Unmanaged code - SecurityCritical with SUC.

                int cButtons;

                pimcTablet.GetCursorButtonCount(iCursor, out cButtons); // Calls Unmanaged code - SecurityCritical with SUC.
                StylusButton[] buttons = new StylusButton[cButtons];
                for ( int iButton = 0; iButton < cButtons; iButton++ )
                {
                    string sButtonName;
                    Guid buttonGuid;
                    pimcTablet.GetCursorButtonInfo(iCursor, iButton, out sButtonName, out buttonGuid); // Calls Unmanaged code - SecurityCritical with SUC.
                    buttons[iButton] = new StylusButton(sButtonName, buttonGuid);
                }
                StylusButtonCollection buttonCollection = new StylusButtonCollection(buttons);

                stylusDevicesInfo[iCursor].CursorName = sCursorName;
                stylusDevicesInfo[iCursor].CursorId = cursorId;
                stylusDevicesInfo[iCursor].CursorInverted = fCursorInverted;
                stylusDevicesInfo[iCursor].ButtonCollection = buttonCollection;
            }

            return stylusDevicesInfo;
        }
Exemplo n.º 6
0
        // When user clicks button,
        //  Display capabilities to panel
        private void Button1Click(object sender, RoutedEventArgs e)
        {
            // Clear the textbox if they clicked once before
            textbox1.Clear();

            // <Snippet1>
            // Get the current stylus device
            StylusDevice myStylusDevice = Stylus.CurrentStylusDevice;

            // </Snippet1>

            // Check whether we got the current stylus
            if (null == myStylusDevice)
            {
                textbox1.AppendText("No current stylus device\n");

                // Try to get it through the default tablet
                TabletDevice defaultTabletDevice = Tablet.TabletDevices[0];

                // Quit if we did not get the default tablet
                if (null == defaultTabletDevice)
                {
                    textbox1.AppendText("No default tablet device. Goodby!\n");
                    return;
                }

                // Now try to get the default stylus device through the default tablet device
                StylusDeviceCollection myStylusDeviceCollection = defaultTabletDevice.StylusDevices;

                int numStylusDevices = myStylusDeviceCollection.Count;

                // If none returned, we are toast, so quit
                if (numStylusDevices < 1)
                {
                    textbox1.AppendText("No stylus devices attached.\n");
                    return;
                }
                else
                {
                    // We have at least one stylus device, so just grab the first one
                    textbox1.AppendText("Got " + numStylusDevices + " stylus device through default tablet\n");
                    myStylusDevice = myStylusDeviceCollection[0];
                }
            }

            // See what properties the default stylus device has

            // <Snippet2>
            PresentationSource myPresentationSource = myStylusDevice.ActiveSource;

            if (null == myPresentationSource)
            {
                textbox1.AppendText("ActiveSource : null\n");
            }
            else
            {
                textbox1.AppendText("ActiveSource :" + myPresentationSource.ToString() + "\n");
            }
            // </Snippet2>

            // <Snippet15>
            TabletDevice myTabletDevice = myStylusDevice.TabletDevice;

            // </Snippet15>

            // <Snippet3>
            // Bind stylus to tablet's input element
            myStylusDevice.Capture(myStylusDevice.Target);
            // </Snippet3>

            // <Snippet4>
            // See to what Captured property is set
            // First see if it's null
            if (null == myStylusDevice.Captured)
            {
                textbox1.AppendText("Captured: null\n");
            }
            else
            {
                // Otherwise display the underlying type
                textbox1.AppendText("Captured: " + myStylusDevice.Captured.GetType().Name + "\n");
            }
            // </Snippet4>

            // <Snippet5>
            // Bind stylus to tablet's input element
            // through entire subtree
            myStylusDevice.Capture(myStylusDevice.Target, CaptureMode.SubTree);
            // </Snippet5>

            // <Snippet6>
            // See to what DirectlyOver property is set
            // First see if it's null
            if (null == myStylusDevice.DirectlyOver)
            {
                textbox1.AppendText("DirectlyOver: null\n");
            }
            else
            {
                // Otherwise display the underlying type
                textbox1.AppendText("DirectlyOver: " + myStylusDevice.DirectlyOver.GetType().Name + "\n");
            }
            // </Snippet6>

            //StylusPointDescription

            // <Snippet7>
            StylusPointCollection myStylusPoints =
                myStylusDevice.GetStylusPoints(myStylusDevice.Target);

            textbox1.AppendText("Got " + myStylusPoints.Count.ToString() + " packets\n");
            // </Snippet7>

            // <Snippet8>
            Point myPoint = myStylusDevice.GetPosition(myStylusDevice.Target);

            textbox1.AppendText("The relative position is: (" + myPoint.X.ToString() + "," + myPoint.Y.ToString() + ")\n");
            // </Snippet8>

            // <Snippet9>
            textbox1.AppendText("Id: " + myStylusDevice.Id.ToString() + "\n");
            // </Snippet9>

            // <Snippet11>
            textbox1.AppendText("InRange: " + myStylusDevice.InRange.ToString() + "\n");
            // </Snippet11>

            // <Snippet13>
            textbox1.AppendText("Name: " + myStylusDevice.Name + "\n");
            // </Snippet13>

            // <Snippet14>
            StylusButtonCollection myStylusButtonCollection = myStylusDevice.StylusButtons;

            if (null == myStylusButtonCollection)
            {
                textbox1.AppendText("StylusButtons: null\n");
            }
            else
            {
                textbox1.AppendText("# of StylusButtons == " + myStylusButtonCollection.Count.ToString() + "\n");
            }
            // </Snippet14>

            // Snippet 15 (TabletDevice property) is between snippet 2 and snippet 3

            // <Snippet16>
            // See to what Target property is set
            // First see if it's null
            if (null == myStylusDevice.Target)
            {
                textbox1.AppendText("Target: null\n");
            }
            else
            {
                // Otherwise display the underlying type
                textbox1.AppendText("Target: " + myStylusDevice.Target.GetType().Name + "\n");
            }
            // </Snippet16>

            // <Snippet17>
            textbox1.AppendText("\n" + "StylusDevice: " + myStylusDevice.ToString() + "\n");
            // </Snippet17>

            // StylusButton members

            // Dummy array to hold result of CopyTo method
            StylusButton[] myStylusButtonArray = new StylusButton[100];

            int index = 0;

            // <Snippet19>
            myStylusButtonCollection.CopyTo(myStylusButtonArray, index);
            // </Snippet19>

            // <Snippet20>
            // Get the names of the buttons
            for (int i = 0; i < myStylusButtonCollection.Count; i++)
            {
                textbox1.AppendText("Button[" + i + "]: " + myStylusButtonCollection[i].Name);
            }
            // </Snippet20>

            // <Snippet21>
            // Ensure collection access is synchronized
            //if (!myStylusButtonCollection.IsSynchronized)
            //{
            //    lock (myStylusButtonCollection.SyncRoot)
            //    {
            //        // work with collection
            //    }
            //}
            // </Snippet21>

            // <Snippet22>
            // Get the names of all of the of StylusButton objects
            // and store them in an ArrayList
            ArrayList myStylusButtonNamesArrayList = new ArrayList();

            foreach (StylusButton sb in myStylusButtonCollection)
            {
                myStylusButtonNamesArrayList.Add(sb.Name);
            }
            // </Snippet22>

            // <Snippet23>
            // Get the first StylusButton, if it exists
            if (myStylusButtonCollection.Count > 0)
            {
                StylusButton mySB = myStylusButtonCollection[0];
            }
            // </Snippet23>

            StylusButton myStylusButton = myStylusButtonCollection[0];

            // <Snippet25>
            // Get the name of the StylusButton
            textbox1.AppendText("StylusButton.Name: " + myStylusButton.Name + "\n");
            // </Snippet25>

            // <Snippet26>
            // Get the state of the StylusButton
            switch (myStylusButton.StylusButtonState)
            {
            case StylusButtonState.Down:
                textbox1.AppendText("StylusButton.State: Down\n");
                break;

            default:      // StylusButtonState.Up
                textbox1.AppendText("StylusButton.State: Up\n");
                break;
            }
            // </Snippet26>

            // <Snippet27>
            // Get the name of the StylusDevice to which the StylusButton is attached
            textbox1.AppendText("StylusButton.StylusDevice: " + myStylusButton.StylusDevice.Name + "\n");
            // </Snippet27>

            // <Snippet28>
            // Get string representation of the StylusButton
            textbox1.AppendText("\n" + myStylusButton.ToString() + "\n");
            // </Snippet28>
        }