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); }
/// <summary> /// Creates WPF property infos from WM_POINTER device properties. This appropriately maps and converts HID spec /// properties found in WM_POINTER to their WPF equivalents. This is based on code from the WISP implementation /// that feeds the legacy WISP based stack. /// </summary> /// <param name="prop">The pointer property to convert</param> /// <returns>The equivalent WPF property info</returns> internal static StylusPointPropertyInfo CreatePropertyInfo(UnsafeNativeMethods.POINTER_DEVICE_PROPERTY prop) { StylusPointPropertyInfo result = null; // Get the mapped GUID for the HID usages Guid propGuid = StylusPointPropertyIds.GetKnownGuid( (StylusPointPropertyIds.HidUsagePage)prop.usagePageId, (StylusPointPropertyIds.HidUsage)prop.usageId); if (propGuid != Guid.Empty) { StylusPointProperty stylusProp = new StylusPointProperty(propGuid, StylusPointPropertyIds.IsKnownButton(propGuid)); // Set Units StylusPointPropertyUnit?unit = StylusPointPropertyUnitHelper.FromPointerUnit(prop.unit); // If the parsed unit is invalid, set the default if (!unit.HasValue) { unit = StylusPointPropertyInfoDefaults.GetStylusPointPropertyInfoDefault(stylusProp).Unit; } // Set to default resolution float resolution = StylusPointPropertyInfoDefaults.GetStylusPointPropertyInfoDefault(stylusProp).Resolution; short mappedExponent = 0; if (_hidExponentMap.TryGetValue((byte)(prop.unitExponent & HidExponentMask), out mappedExponent)) { float exponent = (float)Math.Pow(10, mappedExponent); // Guard against divide by zero or negative resolution if (prop.physicalMax - prop.physicalMin > 0) { // Calculated resolution is a scaling factor from logical units into the physical space // at the given exponentiation. resolution = (prop.logicalMax - prop.logicalMin) / ((prop.physicalMax - prop.physicalMin) * exponent); } } result = new StylusPointPropertyInfo( stylusProp, prop.logicalMin, prop.logicalMax, unit.Value, resolution); } return(result); }