Пример #1
0
        /// <summary>
        /// Responds to pen data by removing or peek/flushing data.
        /// </summary>
        /// <param name="sender_I"></param>
        /// <param name="eventArgs_I"></param>
        public void MyWTPacketEventHandler(Object sender_I, MessageReceivedEventArgs eventArgs_I)
        {
            UInt32 numPkts = 0;

            //System.Diagnostics.Debug.WriteLine("Received WT_PACKET event");
            if (m_wtData == null)
            {
                return;
            }

            bool removeData = this.removeRadioButton.Checked;

            try
            {
                // If removeData is true, packets are removed as they are read.
                // If removeData is false, peek at packets only (packets flushed below).
                WintabPacket[] packets = m_wtData.GetDataPackets(m_maxPackets, removeData, ref numPkts);

                if (numPkts > 0)
                {
                    for (int idx = 0; idx < packets.Length; idx++)
                    {
                        TraceMsg(
                            "Context:" + packets[idx].pkContext +
                            " Status:" + packets[idx].pkStatus +
                            " ID:" + packets[idx].pkSerialNumber +
                            " X:" + packets[idx].pkX +
                            " Y:" + packets[idx].pkY +
                            " P:" + packets[idx].pkNormalPressure + "\n");
                    }

                    // If the peek button was pressed, then flush the packets we just peeked at.
                    if (!removeData)
                    {
                        TraceMsg("Flushing " + numPkts.ToString() + " pending data packets...\n\n");
                        m_wtData.FlushDataPackets(numPkts);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("MyWTPacketEventHandler ERROR: " + ex.ToString());
            }
        }
Пример #2
0
        ///////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Called when Wintab WT_PACKET events are received.
        /// </summary>
        /// <param name="sender_I">The EventMessage object sending the report.</param>
        /// <param name="eventArgs_I">eventArgs_I.Message.WParam contains ID of packet containing the data.</param>
        public void MyWTPacketEventHandler(Object sender_I, MessageReceivedEventArgs eventArgs_I)
        {
            //System.Diagnostics.Debug.WriteLine("Received WT_PACKET event");
            if (m_wtData == null)
            {
                return;
            }

            try
            {
                if (m_maxPkts == 1)
                {
                    uint pktID = (uint)eventArgs_I.Message.WParam;
                    WintabPacket pkt = m_wtData.GetDataPacket((uint)eventArgs_I.Message.LParam, pktID);
                    //DEPRECATED WintabPacket pkt = m_wtData.GetDataPacket(pktID);

                    if (pkt.pkContext != 0)
                    {
                        m_pkX = pkt.pkX;
                        m_pkY = pkt.pkY;
                        m_pressure = pkt.pkNormalPressure;

                                //Trace.WriteLine("SCREEN: pkX: " + pkt.pkX + ", pkY:" + pkt.pkY + ", pressure: " + pkt.pkNormalPressure);

                        m_pkTime = pkt.pkTime;
                        //Console.WriteLine("time: " + m_pkTime);
                        if (m_graphics == null)
                        {
                            // display data mode
                            TraceMsg("Received WT_PACKET event[" + pktID + "]: X/Y/P = " +
                                pkt.pkX + " / " + pkt.pkY + " / " + pkt.pkNormalPressure + "\n");
                        }
                        else
                        {
                            // scribble mode
                            int clientWidth = scribblePanel.Width;
                            int clientHeight = scribblePanel.Height;

                            // m_pkX and m_pkY are in screen (system) coordinates.

                            /*
                            //Converts the program to use relative coordinates.
                            System.Drawing.Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea;

                            double percentX = m_pkX / (double)workingRectangle.Width;
                            double percentY = m_pkY / (double)workingRectangle.Height;

                            int newX = (int)(percentX * clientWidth);
                            int newY = (int)(percentY * clientHeight);

                            Point clientPoint = new Point(newX, newY);
                            */

                            Point clientPoint = scribblePanel.PointToClient(new Point(m_pkX, m_pkY));

                            if (clientPoint.X < 0)
                                return;
                            if (clientPoint.Y < 0)
                                return;

                            if (clientPoint.X > scribblePanel.Width)
                                return;
                            if (clientPoint.Y > scribblePanel.Height)
                                return;

                            //Trace.WriteLine("CLIENT:   X: " + clientPoint.X + ", Y:" + clientPoint.Y);

                            if (m_lastPoint.Equals(Point.Empty))
                            {
                                m_lastPoint = clientPoint;
                                m_pkTimeLast = m_pkTime;
                            }

                            //m_pen.Width = (float)(m_pressure / 200);
                            m_pen.Width = (float)3.0;

                            if (m_pressure > 0 && screenEnabled)
                            {
                                if(!timeoutTimer.Enabled && timeoutEnabled && currentSeq != 0)
                                {
                                    timeoutTimer.Start();
                                }
                                if(compareTimer.Enabled)
                                {
                                    compareTimer.Stop();
                                }

                                uint unixTimestamp = (uint)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;

                                if (m_pkTime - m_pkTimeLast > 50)
                                {
                                    Console.WriteLine("new stroke");
                                    m_graphics.DrawRectangle(m_pen, clientPoint.X, clientPoint.Y, 1, 1);
                                    strokeNum++;
                                    DrawPoint dp = new DrawPoint(clientPoint.X, clientPoint.Y, strokeNum, unixTimestamp, m_pressure);
                                    TR.AddStartPoint(dp);
                                    m_lastPoint = clientPoint;
                                    m_pkTimeLast = m_pkTime;
                                }
                                else
                                {
                                    m_graphics.DrawLine(m_pen, clientPoint, m_lastPoint);
                                    DrawPoint dp = new DrawPoint(clientPoint.X, clientPoint.Y, strokeNum, unixTimestamp, m_pressure);
                                    TR.AddPoint(dp);
                                    compareTimer.Start();
                                    m_lastPoint = clientPoint;
                                    m_pkTimeLast = m_pkTime;
                                }
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("FAILED to get packet data: " + ex.ToString());
            }
        }
Пример #3
0
        ///////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Called when Wintab WT_PACKET events are received.
        /// </summary>
        /// <param name="sender_I">The EventMessage object sending the report.</param>
        /// <param name="eventArgs_I">eventArgs_I.Message.WParam contains ID of packet containing the data.</param>
        public void MyWTPacketEventHandler(Object sender_I, MessageReceivedEventArgs eventArgs_I)
        {
            if (m_wtData == null)
            {
                return;
            }

            if (eventArgs_I.Message.Msg == (Int32)EWintabEventMessage.WT_PACKETEXT)
            {
                //Debug.WriteLine("Received WT_PACKETEXT");
                WTPKT hCtx = (WTPKT)eventArgs_I.Message.LParam;
                WTPKT pktID = (WTPKT)eventArgs_I.Message.WParam;
                WintabPacketExt pktExt = m_wtData.GetDataPacketExt(hCtx, pktID);

                if (pktExt.pkBase.nContext != mLogContext.HCtx)
                {
                    throw new Exception("Oops - got a message from unknown context: " + pktExt.pkBase.nContext.ToString());
                }

                if (pktExt.pkBase.nContext == mLogContext.HCtx)
                {
                    // Call updates on all control types, even though some updates will be NO-OPS
                    // because those controls will not be supported for the tablet.
                    mExtensionControlState.UpdateExpressKey((int)pktExt.pkExpKey.nTablet, (int)pktExt.pkExpKey.nControl, (int)pktExt.pkExpKey.nLocation, pktExt.pkExpKey.nState);
                    mExtensionControlState.UpdateTouchRing((int)pktExt.pkTouchRing.nTablet, (int)pktExt.pkTouchRing.nControl, (int)pktExt.pkTouchRing.nMode, pktExt.pkTouchRing.nPosition);
                    mExtensionControlState.UpdateTouchStrip((int)pktExt.pkTouchStrip.nTablet, (int)pktExt.pkTouchStrip.nControl, (int)pktExt.pkTouchStrip.nMode, pktExt.pkTouchStrip.nPosition);

                    // Refresh all supported controls based on current control state.
                    RefreshControls();
                }
            }
        }
Пример #4
0
        //---------------------------------------------------------------------
        // Tablet event handler
        //---------------------------------------------------------------------
        private void TabletEventHandler(object sender, MessageReceivedEventArgs args)
        {
            uint pktID = (uint)args.Message.WParam;
            WintabPacket pkt = data.GetDataPacket(pktID);

            if (pkt.pkNormalPressure.pkAbsoluteNormalPressure > 0)
                tabletPressure = (float)pkt.pkNormalPressure.pkAbsoluteNormalPressure / 1024.0f;
        }
Пример #5
0
        ///////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Called when Wintab WT_PACKET events are received.
        /// </summary>
        /// <param name="sender_I">The EventMessage object sending the report.</param>
        /// <param name="eventArgs_I">eventArgs_I.Message.WParam contains ID of packet containing the data.</param>
        public void MyWTPacketEventHandler(Object sender_I, MessageReceivedEventArgs eventArgs_I)
        {
            //System.Diagnostics.Debug.WriteLine("Received WT_PACKET event");
            if (m_wtData == null)
            {
                return;
            }

            try
            {
                if (m_maxPkts == 1)
                {
                    uint pktID = (uint)eventArgs_I.Message.WParam;
                    WintabPacket pkt = m_wtData.GetDataPacket((uint)eventArgs_I.Message.LParam, pktID);
                    //DEPRECATED WintabPacket pkt = m_wtData.GetDataPacket(pktID);

                    if (pkt.pkContext != 0)
                    {
                        m_pkX = pkt.pkX;
                        m_pkY = pkt.pkY;
                        m_pressure = pkt.pkNormalPressure;

                        Trace.WriteLine("SCREEN: pkX: " + pkt.pkX + ", pkY:" + pkt.pkY + ", pressure: " + pkt.pkNormalPressure);

                        m_pkTime = pkt.pkTime;

                        if (m_graphics == null)
                        {
                            // display data mode
                            //TraceMsg("Received WT_PACKET event[" + pktID + "]: X/Y/P = " +
                            //    pkt.pkX + " / " + pkt.pkY + " / " + pkt.pkNormalPressure + "\n");

                            // udp!

                            // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151003/udppenpressure
                            new float[] { pkt.pkX, pkt.pkY, pkt.pkNormalPressure }.Send("239.1.2.3", 40094);

                        }
                        else
                        {
                            // scribble mode
                            int clientWidth = scribblePanel.Width;
                            int clientHeight = scribblePanel.Height;

                            // m_pkX and m_pkY are in screen (system) coordinates.

                            Point clientPoint = scribblePanel.PointToClient(new Point(m_pkX, m_pkY));
                            Trace.WriteLine("CLIENT:   X: " + clientPoint.X + ", Y:" + clientPoint.Y);

                            if (m_lastPoint.Equals(Point.Empty))
                            {
                                m_lastPoint = clientPoint;
                                m_pkTimeLast = m_pkTime;
                            }

                            m_pen.Width = (float)(m_pressure / 200);

                            if (m_pressure > 0)
                            {
                                if (m_pkTime - m_pkTimeLast < 5)
                                {
                                    m_graphics.DrawRectangle(m_pen, clientPoint.X, clientPoint.Y, 1, 1);
                                }
                                else
                                {
                                    m_graphics.DrawLine(m_pen, clientPoint, m_lastPoint);
                                }
                            }

                            m_lastPoint = clientPoint;
                            m_pkTimeLast = m_pkTime;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("FAILED to get packet data: " + ex.ToString());
            }
        }
        //---------------------------------------------------------------------
        // Tablet event handler
        //---------------------------------------------------------------------
        private void TabletEventHandler(object sender, MessageReceivedEventArgs args)
        {
            uint pktID = (uint)args.Message.WParam;
            WintabPacket pkt = data.GetDataPacket(pktID);

            if (pkt.pkNormalPressure.pkAbsoluteNormalPressure > 0)
            {
                if (lastPressure > 0)
                    m_session.GuiInput_TabletMove(sender, pkt);
                else
                    m_session.GuiInput_TabletDown(sender, pkt);
            }
            else if (pkt.pkNormalPressure.pkAbsoluteNormalPressure == 0 && lastPressure > 0)
                m_session.GuiInput_TabletUp(sender, pkt);
        }