Exemplo n.º 1
0
        /// <summary>
        /// Returns extension index tag for given tag, if possible.
        /// </summary>
        /// <param name="tag_I">type of extension being searched for</param>
        /// <returns>0xFFFFFFFF on error</returns>
        public static UInt32 FindWTExtensionIndex(EWTXExtensionTag tag_I)
        {
            UInt32 thisTag  = 0;
            UInt32 extIndex = 0xFFFFFFFF;
            IntPtr buf      = CMemUtils.AllocUnmanagedBuf(thisTag);

            for (Int32 loopIdx = 0, size = -1; size != 0; loopIdx++)
            {
                size = (int)CWintabFuncs.WTInfoA(
                    (uint)EWTICategoryIndex.WTI_EXTENSIONS + (UInt32)loopIdx,
                    (uint)EWTIExtensionIndex.EXT_TAG, buf);

                if (size > 0)
                {
                    thisTag = CMemUtils.MarshalUnmanagedBuf <UInt32>(buf, size);

                    if ((EWTXExtensionTag)thisTag == tag_I)
                    {
                        extIndex = (UInt32)loopIdx;
                        break;
                    }
                }
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(extIndex);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return the extension mask for the given tag.
        /// </summary>
        /// <param name="tag_I">type of extension being searched for</param>
        /// <returns>0xFFFFFFFF on error</returns>
        public static UInt32 GetWTExtensionMask(EWTXExtensionTag tag_I)
        {
            UInt32 extMask = 0;
            IntPtr buf     = CMemUtils.AllocUnmanagedBuf(extMask);

            try
            {
                UInt32 extIndex = FindWTExtensionIndex(tag_I);

                // Supported if extIndex != -1
                if (extIndex != 0xFFFFFFFF)
                {
                    int size = (int)CWintabFuncs.WTInfo(
                        (uint)EWTICategoryIndex.WTI_EXTENSIONS + (uint)extIndex,
                        (uint)EWTIExtensionIndex.EXT_MASK, buf);

                    extMask = (UInt32)CMemUtils.MarshalUnmanagedBuf <UInt32>(buf, size);
                }
            }
            finally
            {
                CMemUtils.FreeUnmanagedBuf(buf);
            }

            return(extMask);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Return the extension mask for the given tag.
        /// </summary>
        /// <param name="tag_I">type of extension being searched for</param>
        /// <returns>0xFFFFFFFF on error</returns>
        public static UInt32 GetWTExtensionMask(EWTXExtensionTag tag_I)
        {
            UInt32 extMask = 0;
            IntPtr buf     = CMemUtils.AllocUnmanagedBuf(extMask);

            try
            {
                UInt32 extIndex = FindWTExtensionIndex(tag_I);

                // Supported if extIndex != -1
                if (extIndex != 0xFFFFFFFF)
                {
                    int size = (int)CWintabFuncs.WTInfoA(
                        (uint)EWTICategoryIndex.WTI_EXTENSIONS + (uint)extIndex,
                        (uint)EWTIExtensionIndex.EXT_MASK, buf);

                    extMask = (UInt32)CMemUtils.MarshalUnmanagedBuf <UInt32>(buf, size);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED GetWTExtensionMask: " + ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(extMask);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a 3-element array describing the tablet's rotation range and resolution capabilities
        /// </summary>
        /// <returns></returns>
        public static WintabAxisArray GetDeviceRotation(out bool rotationSupported_O)
        {
            WintabAxisArray axisArray = new WintabAxisArray();

            rotationSupported_O = false;
            IntPtr buf = CMemUtils.AllocUnmanagedBuf(axisArray);

            try
            {
                int size = (int)CWintabFuncs.WTInfoA(
                    (uint)EWTICategoryIndex.WTI_DEVICES,
                    (uint)EWTIDevicesIndex.DVC_ROTATION, buf);

                // If size == 0, then returns a zeroed struct.
                axisArray           = CMemUtils.MarshalUnmanagedBuf <WintabAxisArray>(buf, size);
                rotationSupported_O = (axisArray.array[0].axResolution != 0 && axisArray.array[1].axResolution != 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED GetDeviceRotation: " + ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(axisArray);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Return max normal pressure supported by tablet.
        /// </summary>
        /// <param name="getNormalPressure_I">TRUE=> normal pressure;
        /// FALSE=> tangential pressure (not supported on all tablets)</param>
        /// <returns>maximum pressure value or zero on error</returns>
        public static Int32 GetMaxPressure(bool getNormalPressure_I = true)
        {
            WintabAxis pressureAxis = new WintabAxis();
            IntPtr     buf          = CMemUtils.AllocUnmanagedBuf(pressureAxis);

            EWTIDevicesIndex devIdx = (getNormalPressure_I ?
                                       EWTIDevicesIndex.DVC_NPRESSURE : EWTIDevicesIndex.DVC_TPRESSURE);

            try
            {
                int size = (int)CWintabFuncs.WTInfoA(
                    (uint)EWTICategoryIndex.WTI_DEVICES,
                    (uint)devIdx, buf);

                pressureAxis = CMemUtils.MarshalUnmanagedBuf <WintabAxis>(buf, size);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED GetMaxPressure: " + ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(pressureAxis.axMax);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Marshal unmanaged Extension data packets into managed WintabPacketExt data.
        /// </summary>
        /// <param name="numPkts_I">number of packets to marshal</param>
        /// <param name="buf_I">pointer to unmanaged heap memory containing data packets</param>
        /// <returns></returns>
        public static WintabPacketExt[] MarshalDataExtPackets(UInt32 numPkts_I, IntPtr buf_I)
        {
            WintabPacketExt[] packets = new WintabPacketExt[numPkts_I];

            if (numPkts_I == 0 || buf_I == IntPtr.Zero)
            {
                return(null);
            }

            // Marshal each WintabPacketExt in the array separately.
            // This is "necessary" because none of the other ways I tried to marshal
            // seemed to work.  It's ugly, but it works.
            int pktSize = Marshal.SizeOf(new WintabPacketExt());

            Byte[] byteArray = new Byte[numPkts_I * pktSize];
            Marshal.Copy(buf_I, byteArray, 0, (int)numPkts_I * pktSize);

            Byte[] byteArray2 = new Byte[pktSize];

            for (int pktsIdx = 0; pktsIdx < numPkts_I; pktsIdx++)
            {
                for (int idx = 0; idx < pktSize; idx++)
                {
                    byteArray2[idx] = byteArray[(pktsIdx * pktSize) + idx];
                }

                IntPtr tmp = CMemUtils.AllocUnmanagedBuf(pktSize);
                Marshal.Copy(byteArray2, 0, tmp, pktSize);

                packets[pktsIdx] = CMemUtils.MarshalUnmanagedBuf <WintabPacketExt>(tmp, pktSize);
            }

            return(packets);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Helper function to get digitizing or system default context.
        /// </summary>
        /// <param name="contextType_I">Use WTI_DEFCONTEXT for digital context or WTI_DEFSYSCTX for system context</param>
        /// <returns>Returns the default context or null on error.</returns>
        private static CWintabContext GetDefaultContext(EWTICategoryIndex contextIndex_I)
        {
            CWintabContext context = new CWintabContext();
            IntPtr         buf     = CMemUtils.AllocUnmanagedBuf(context.LogContext);

            try
            {
                int size = (int)CWintabFuncs.WTInfo((uint)contextIndex_I, 0, buf);

                context.LogContext = CMemUtils.MarshalUnmanagedBuf <WintabLogContext>(buf, size);
            }
            finally
            {
                CMemUtils.FreeUnmanagedBuf(buf);
            }

            return(context);
        }
Exemplo n.º 8
0
        public static WintabPacket[] MarshalDataPackets(UInt32 numPkts_I, IntPtr buf_I)
        {
            if (numPkts_I == 0 || buf_I == IntPtr.Zero)
            {
                return(null);
            }

            WintabPacket[] packets = new WintabPacket[numPkts_I];

            //
            // Marshal each WintabPacket in the array separately.
            // This is "necessary" because none of the other ways I tried to marshal
            // seemed to work.  It's ugly, but it works.
            //
            int pktSize = Marshal.SizeOf(new WintabPacket());

            Byte[] byteArray = new Byte[numPkts_I * pktSize];
            Marshal.Copy(buf_I, byteArray, 0, (int)numPkts_I * pktSize);

            Byte[] byteArray2 = new Byte[pktSize];

            for (int pktsIdx = 0; pktsIdx < numPkts_I; pktsIdx++)
            {
#if TRACE_RAW_BYTES
                // Trace out the raw data bytes for each packet using a hex formatter.
                Debug.Write("Packet: [" + Convert.ToString(pktsIdx) + "] ");

                for (int idx = 0; idx < pktSize; idx++)
                {
                    byteArray2[idx] = byteArray[(pktsIdx * pktSize) + idx];
                    Debug.Write(String.Format("{0,3:X2}", byteArray2[idx]));
                }
                Debug.WriteLine("");
#endif //TRACE_RAW_BYTES

                IntPtr tmp = CMemUtils.AllocUnmanagedBuf(pktSize);
                Marshal.Copy(byteArray2, 0, tmp, pktSize);

                packets[pktsIdx] = CMemUtils.MarshalUnmanagedBuf <WintabPacket>(tmp, pktSize);
            }

            return(packets);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Return the WintabAxis object for the specified dimension.
        /// </summary>
        /// <param name="dimension_I">Dimension to fetch (eg: x, y)</param>
        /// <returns></returns>
        public static WintabAxis GetTabletAxis(EAxisDimension dimension_I)
        {
            WintabAxis axis = new WintabAxis();
            IntPtr     buf  = CMemUtils.AllocUnmanagedBuf(axis);

            try
            {
                int size = (int)CWintabFuncs.WTInfo(
                    (uint)EWTICategoryIndex.WTI_DEVICES,
                    (uint)dimension_I, buf);

                axis = CMemUtils.MarshalUnmanagedBuf <WintabAxis>(buf, size);
            }
            finally
            {
                CMemUtils.FreeUnmanagedBuf(buf);
            }

            return(axis);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Returns whether a stylus is currently connected to the active cursor.
        /// </summary>
        /// <returns></returns>
        public static bool IsStylusActive()
        {
            bool   isStylusActive = false;
            IntPtr buf            = CMemUtils.AllocUnmanagedBuf(isStylusActive);

            try
            {
                int size = (int)CWintabFuncs.WTInfo(
                    (uint)EWTICategoryIndex.WTI_INTERFACE,
                    (uint)EWTIInterfaceIndex.IFC_NDEVICES, buf);

                isStylusActive = CMemUtils.MarshalUnmanagedBuf <bool>(buf, size);
            }
            finally
            {
                CMemUtils.FreeUnmanagedBuf(buf);
            }

            return(isStylusActive);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Returns the number of devices connected.
        /// </summary>
        /// <returns></returns>
        public static UInt32 GetNumberOfDevices()
        {
            UInt32 numDevices = 0;
            IntPtr buf        = CMemUtils.AllocUnmanagedBuf(numDevices);

            try
            {
                int size = (int)CWintabFuncs.WTInfo(
                    (uint)EWTICategoryIndex.WTI_INTERFACE,
                    (uint)EWTIInterfaceIndex.IFC_NDEVICES, buf);

                numDevices = CMemUtils.MarshalUnmanagedBuf <UInt32>(buf, size);
            }
            finally
            {
                CMemUtils.FreeUnmanagedBuf(buf);
            }

            return(numDevices);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Returns the default device.  If this value is -1, then it also known as a "virtual device".
        /// </summary>
        /// <returns></returns>
        public static Int32 GetDefaultDeviceIndex()
        {
            Int32  devIndex = 0;
            IntPtr buf      = CMemUtils.AllocUnmanagedBuf(devIndex);

            try
            {
                int size = (int)CWintabFuncs.WTInfo(
                    (uint)EWTICategoryIndex.WTI_DEFCONTEXT,
                    (uint)EWTIContextIndex.CTX_DEVICE, buf);

                devIndex = CMemUtils.MarshalUnmanagedBuf <Int32>(buf, size);
            }
            finally
            {
                CMemUtils.FreeUnmanagedBuf(buf);
            }

            return(devIndex);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Helper function to get digitizing or system default context.
        /// </summary>
        /// <param name="contextType_I">Use WTI_DEFCONTEXT for digital context or WTI_DEFSYSCTX for system context</param>
        /// <returns>Returns the default context or null on error.</returns>
        private static CWintabContext GetDefaultContext(EWTICategoryIndex contextIndex_I)
        {
            CWintabContext context = new CWintabContext();
            IntPtr         buf     = CMemUtils.AllocUnmanagedBuf(context.LogContext);

            try
            {
                int size = (int)CWintabFuncs.WTInfoA((uint)contextIndex_I, 0, buf);

                context.LogContext = CMemUtils.MarshalUnmanagedBuf <WintabLogContext>(buf, size);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED GetDefaultContext: " + ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(context);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Returns the WintabAxis object for specified device and dimension.
        /// </summary>
        /// <param name="devIndex_I">Device index (-1 = virtual device)</param>
        /// <param name="dim_I">Dimension: AXIS_X, AXIS_Y or AXIS_Z</param>
        /// <returns></returns>
        public static WintabAxis GetDeviceAxis(Int32 devIndex_I, EAxisDimension dim_I)
        {
            WintabAxis axis = new WintabAxis();
            IntPtr     buf  = CMemUtils.AllocUnmanagedBuf(axis);

            try
            {
                int size = (int)CWintabFuncs.WTInfo(
                    (uint)(EWTICategoryIndex.WTI_DEVICES + devIndex_I),
                    (uint)dim_I, buf);

                // If size == 0, then returns a zeroed struct.
                axis = CMemUtils.MarshalUnmanagedBuf <WintabAxis>(buf, size);
            }
            finally
            {
                CMemUtils.FreeUnmanagedBuf(buf);
            }

            return(axis);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Return the WintabAxis object for the specified dimension.
        /// </summary>
        /// <param name="dimension_I">Dimension to fetch (eg: x, y)</param>
        /// <returns></returns>
        public static WintabAxis GetTabletAxis(EAxisDimension dimension_I)
        {
            WintabAxis axis = new WintabAxis();
            IntPtr     buf  = CMemUtils.AllocUnmanagedBuf(axis);

            try
            {
                int size = (int)CWintabFuncs.WTInfoA(
                    (uint)EWTICategoryIndex.WTI_DEVICES,
                    (uint)dimension_I, buf);

                axis = CMemUtils.MarshalUnmanagedBuf <WintabAxis>(buf, size);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED GetMaxPressure: " + ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(axis);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Returns whether a stylus is currently connected to the active cursor.
        /// </summary>
        /// <returns></returns>
        public static bool IsStylusActive()
        {
            bool   isStylusActive = false;
            IntPtr buf            = CMemUtils.AllocUnmanagedBuf(isStylusActive);

            try
            {
                int size = (int)CWintabFuncs.WTInfoA(
                    (uint)EWTICategoryIndex.WTI_INTERFACE,
                    (uint)EWTIInterfaceIndex.IFC_NDEVICES, buf);

                isStylusActive = CMemUtils.MarshalUnmanagedBuf <bool>(buf, size);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED GetNumberOfDevices: " + ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(isStylusActive);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Returns the number of devices connected.
        /// </summary>
        /// <returns></returns>
        public static UInt32 GetNumberOfDevices()
        {
            UInt32 numDevices = 0;
            IntPtr buf        = CMemUtils.AllocUnmanagedBuf(numDevices);

            try
            {
                int size = (int)CWintabFuncs.WTInfoA(
                    (uint)EWTICategoryIndex.WTI_INTERFACE,
                    (uint)EWTIInterfaceIndex.IFC_NDEVICES, buf);

                numDevices = CMemUtils.MarshalUnmanagedBuf <UInt32>(buf, size);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED GetNumberOfDevices: " + ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(numDevices);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Returns the default device.  If this value is -1, then it also known as a "virtual device".
        /// </summary>
        /// <returns></returns>
        public static Int32 GetDefaultDeviceIndex()
        {
            Int32  devIndex = 0;
            IntPtr buf      = CMemUtils.AllocUnmanagedBuf(devIndex);

            try
            {
                int size = (int)CWintabFuncs.WTInfoA(
                    (uint)EWTICategoryIndex.WTI_DEFCONTEXT,
                    (uint)EWTIContextIndex.CTX_DEVICE, buf);

                devIndex = CMemUtils.MarshalUnmanagedBuf <Int32>(buf, size);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED GetDefaultDeviceIndex: " + ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(devIndex);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Return max normal pressure supported by tablet.
        /// </summary>
        /// <param name="getNormalPressure_I">TRUE=> normal pressure;
        /// FALSE=> tangential pressure (not supported on all tablets)</param>
        /// <returns>maximum pressure value or zero on error</returns>
        public static Int32 GetMaxPressure(bool getNormalPressure_I = true)
        {
            WintabAxis pressureAxis = new WintabAxis();
            IntPtr     buf          = CMemUtils.AllocUnmanagedBuf(pressureAxis);

            EWTIDevicesIndex devIdx = (getNormalPressure_I ?
                                       EWTIDevicesIndex.DVC_NPRESSURE : EWTIDevicesIndex.DVC_TPRESSURE);

            try
            {
                int size = (int)CWintabFuncs.WTInfo(
                    (uint)EWTICategoryIndex.WTI_DEVICES,
                    (uint)devIdx, buf);

                pressureAxis = CMemUtils.MarshalUnmanagedBuf <WintabAxis>(buf, size);
            }
            finally
            {
                CMemUtils.FreeUnmanagedBuf(buf);
            }

            return(pressureAxis.axMax);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Returns the WintabAxis object for specified device and dimension.
        /// </summary>
        /// <param name="devIndex_I">Device index (-1 = virtual device)</param>
        /// <param name="dim_I">Dimension: AXIS_X, AXIS_Y or AXIS_Z</param>
        /// <returns></returns>
        public static WintabAxis GetDeviceAxis(Int32 devIndex_I, EAxisDimension dim_I)
        {
            WintabAxis axis = new WintabAxis();
            IntPtr     buf  = CMemUtils.AllocUnmanagedBuf(axis);

            try
            {
                int size = (int)CWintabFuncs.WTInfoA(
                    (uint)(EWTICategoryIndex.WTI_DEVICES + devIndex_I),
                    (uint)dim_I, buf);

                // If size == 0, then returns a zeroed struct.
                axis = CMemUtils.MarshalUnmanagedBuf <WintabAxis>(buf, size);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FAILED GetDeviceAxis: " + ex.ToString());
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(axis);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Returns a 3-element array describing the tablet's orientation range and resolution capabilities.
        /// </summary>
        /// <returns></returns>
        public static WintabAxisArray GetDeviceOrientation(out bool tiltSupported_O)
        {
            WintabAxisArray axisArray = new WintabAxisArray();

            tiltSupported_O = false;
            IntPtr buf = CMemUtils.AllocUnmanagedBuf(axisArray);

            try
            {
                int size = (int)CWintabFuncs.WTInfo(
                    (uint)EWTICategoryIndex.WTI_DEVICES,
                    (uint)EWTIDevicesIndex.DVC_ORIENTATION, buf);

                // If size == 0, then returns a zeroed struct.
                axisArray       = CMemUtils.MarshalUnmanagedBuf <WintabAxisArray>(buf, size);
                tiltSupported_O = (axisArray.array[0].axResolution != 0 && axisArray.array[1].axResolution != 0);
            }
            finally
            {
                CMemUtils.FreeUnmanagedBuf(buf);
            }

            return(axisArray);
        }