Exemplo n.º 1
0
        /// <summary>
        /// Marshal unmanaged data packets into managed WintabPacket 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>

        /// <summary>
        /// Marshal unmanaged data packets into managed WintabPacket 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>
#if DOTNET_4_OR_LATER
        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];

            int pktSize = Marshal.SizeOf(new WintabPacket());

            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.
                int offset = pktsIdx * pktSize;

                Debug.Write("Packet: [" + Convert.ToString(pktsIdx) + "] ");
                for (int idx = 0; idx < pktSize; idx++)
                {
                    byte val = Marshal.ReadByte(buf_I + offset + idx);
                    Debug.Write(String.Format("{0,3:X2}", val));
                }
                Debug.WriteLine("");
#endif //TRACE_RAW_BYTES

                packets[pktsIdx] = (WintabPacket)Marshal.PtrToStructure(IntPtr.Add(buf_I, pktsIdx * pktSize), typeof(WintabPacket));
            }

            return(packets);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns one packet of Wintab data from the packet queue.
        /// </summary>
        /// <param name="hCtx_I">Wintab context to be used when asking for the data</param>
        /// <param name="pktID_I">Identifier for the tablet event packet to return.</param>
        /// <returns>Returns a data packet with non-null context if successful.</returns>
        public WintabPacket GetDataPacket(HCTX hCtx_I, UInt32 pktID_I)
        {
            IntPtr       buf    = CMemUtils.AllocUnmanagedBuf(Marshal.SizeOf(typeof(WintabPacket)));
            WintabPacket packet = new WintabPacket();

            if (pktID_I == 0)
            {
                throw new Exception("GetDataPacket - invalid pktID");
            }

            CheckForValidHCTX("GetDataPacket");

            if (CWintabFuncs.WTPacket(hCtx_I, pktID_I, buf))
            {
                packet = (WintabPacket)Marshal.PtrToStructure(buf, typeof(WintabPacket));
            }
            else
            {
                //
                // If fails, make sure context is zero.
                //
                packet.pkContext = HCTX.Zero;
            }

            CMemUtils.FreeUnmanagedBuf(buf);

            return(packet);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns one packet of Wintab data from the packet queue.
        /// </summary>
        /// <param name="hCtx_I">Wintab context to be used when asking for the data</param>
        /// <param name="pktID_I">Identifier for the tablet event packet to return.</param>
        /// <returns>Returns a data packet with non-null context if successful.</returns>
        public WintabPacket GetDataPacket(UInt32 hCtx_I, UInt32 pktID_I)
        {
            IntPtr       buf    = CMemUtils.AllocUnmanagedBuf(Marshal.SizeOf(typeof(WintabPacket)));
            WintabPacket packet = new WintabPacket();

            if (pktID_I == 0)
            {
                throw new Exception("GetDataPacket - invalid pktID");
            }

            CheckForValidHCTX("GetDataPacket");

            if (CWintabFuncs.WTPacket(hCtx_I, pktID_I, buf))
            {
                packet = (WintabPacket)Marshal.PtrToStructure(buf, typeof(WintabPacket));
            }
            else
            {
                //
                // If fails, make sure context is zero.
                //
                packet.pkContext = 0;
            }

            /**
             * PERFORMANCE FIX: without this line, the memory consume of .NET apps increase
             * exponentially when the PEN is used for long time (or worse when the pen is leaved alone on the tablet screen)
             * causing the app to crash now or later...
             * Author: Alessandro del Gobbo   ([email protected])
             */
            CMemUtils.FreeUnmanagedBuf(buf);

            return(packet);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns one packet of Wintab data from the packet queue.
        /// </summary>
        /// <param name="pktID_I">Identifier for the tablet event packet to return.</param>
        /// <returns>Returns a data packet with non-null context if successful.</returns>
        public WintabPacket GetDataPacket(UInt32 pktID_I)
        {
            WintabPacket packet = new WintabPacket();

            try {
                bool status = false;

                if (pktID_I == 0)
                {
                    throw new Exception("GetDataPacket - invalid pktID");
                }

                CheckForValidHCTX("GetDataPacket");
                status = WNativeMethods.WTPacket(m_context.HCtx, pktID_I, ref packet);

                // If fails, make sure context is zero.
                if (!status)
                {
                    packet.pkContext = HCTX.Zero;
                }
            } catch (Exception ex) {
                throw new Exception("FAILED GetDataPacket: " + ex.ToString());
            }

            return(packet);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Marshal unmanaged data packets into managed WintabPacket 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 WintabPacket[] MarshalDataPackets(UInt32 numPkts_I, IntPtr buf_I)
        {
            WintabPacket[] packets = new WintabPacket[numPkts_I];

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

            // 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++)
            {
                for (int idx = 0; idx < pktSize; idx++)
                {
                    byteArray2[idx] = byteArray[(pktsIdx * pktSize) + idx];
                }

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

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

            return(packets);
        }
Exemplo n.º 6
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);
        }
        /// <summary>
        /// Marshal unmanaged data packets into managed WintabPacket 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>

        /// <summary>
        /// Marshal unmanaged data packets into managed WintabPacket 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 WintabPacket[] MarshalDataPackets(UInt32 numPkts_I, IntPtr buf_I)
        {
            if (numPkts_I == 0 || buf_I == IntPtr.Zero)
            {
                return(null);
            }

            WintabPacket[] packets = new WintabPacket[numPkts_I];

            int pktSize = Marshal.SizeOf(new WintabPacket());

            for (int pktsIdx = 0; pktsIdx < numPkts_I; pktsIdx++)
            {
                // Tracing can be added here to capture raw packet data if desired

                packets[pktsIdx] = (WintabPacket)Marshal.PtrToStructure(IntPtr.Add(buf_I, pktsIdx * pktSize), typeof(WintabPacket));
            }

            return(packets);
        }
 internal void GuiInput_TabletUp(object sender, WintabPacket pkt)
 {
     EzJson j = new EzJson();
     j.BeginFunction("tool_up");
     j.AddData("x", (int)(pkt.pkX / m_canvasWindow.magnification));
     j.AddData("y", (int)(pkt.pkY / m_canvasWindow.magnification));
     j.AddData("pressure", pkt.pkNormalPressure.pkAbsoluteNormalPressure.ToString());
     j.AddData("layer", selectedLayerID);
     m_toolRunner.ParseJSON(j.Finish());
 }
 internal void GuiInput_TabletDown(object sender, WintabPacket pkt)
 {
     string toolName = m_mainForm.GetToolName();
     EzJson j = new EzJson();
     j.BeginFunction("tool_down");
     j.AddData("pressure", pkt.pkNormalPressure.pkAbsoluteNormalPressure.ToString());
     j.AddData("x", (int)(pkt.pkX / m_canvasWindow.magnification));
     j.AddData("y", (int)(pkt.pkY / m_canvasWindow.magnification));
     j.AddData("layer", selectedLayerID);
     j.AddData("tool", toolName);
     switch (toolName)
     {
         case "brush":
             j.AddData("options", m_mainForm.GetBrushOptions());
             break;
         case "pen":
             j.AddData("options", m_mainForm.GetPenOptions());
             break;
         default:
             j.AddData("options", null);
             break;
     }
     m_toolRunner.ParseJSON(j.Finish());
 }
Exemplo n.º 10
0
 public static extern bool WTPacket(P_HCTX hctx_I, UInt32 pktSerialNum_I, ref WintabPacket pktBuf_O);
Exemplo n.º 11
0
        /// <summary>
        /// Returns one packet of Wintab data from the packet queue.
        /// </summary>
        /// <param name="hCtx_I">Wintab context to be used when asking for the data</param>
        /// <param name="pktID_I">Identifier for the tablet event packet to return.</param>
        /// <returns>Returns a data packet with non-null context if successful.</returns>
        public WintabPacket GetDataPacket(UInt32 hCtx_I, UInt32 pktID_I)
        {
            IntPtr buf = CMemUtils.AllocUnmanagedBuf(Marshal.SizeOf(typeof(WintabPacket)));
            WintabPacket packet = new WintabPacket();

            if (pktID_I == 0)
            {
                throw new Exception("GetDataPacket - invalid pktID");
            }

            CheckForValidHCTX("GetDataPacket");

            if (CWintabFuncs.WTPacket(hCtx_I, pktID_I, buf))
            {
                packet = (WintabPacket)Marshal.PtrToStructure(buf, typeof(WintabPacket));
            }
            else
            {
                //
                // If fails, make sure context is zero.
                //
                packet.pkContext = 0;

            }

            return packet;
        }