Пример #1
0
        private CWintabContext OpenDigitalContext(bool ctrlSysCursor = true)
        {
            CWintabContext context = CWintabInfo.GetDefaultDigitizingContext();

            if (context == null)
            {
                return(null);
            }

            context.Options |= (uint)ECTXOptionValues.CXO_MESSAGES;
            if (ctrlSysCursor)
            {
                context.Options |= (uint)ECTXOptionValues.CXO_SYSTEM;
            }
            context.Name = "BgoonLibrary Tablet Context";

            deviceID = CWintabInfo.GetDefaultDeviceIndex();
            WintabAxis tabletX = CWintabInfo.GetDeviceAxis(deviceID, EAxisDimension.AXIS_X);
            WintabAxis tabletY = CWintabInfo.GetDeviceAxis(deviceID, EAxisDimension.AXIS_Y);

            NativeRect = new GRect(tabletX.axMin, tabletX.axMax, tabletY.axMin, tabletY.axMax);

            context.OutOrgX = context.OutOrgY = 0;
            context.OutExtX = (int)(context.OutExtX * OutputExtFactor);
            context.OutExtY = (int)(context.OutExtY * OutputExtFactor);

            //context.OutExtY *= -1;

            return(context.Open() ? context : null);
        }
Пример #2
0
        private CWintabContext OpenSystemContext(bool ctrlSysCursor = true)
        {
            CWintabContext context = CWintabInfo.GetDefaultSystemContext();

            if (context == null)
            {
                return(null);
            }
            // Set system cursor if caller wants it.
            if (ctrlSysCursor)
            {
                context.Options |= (uint)ECTXOptionValues.CXO_SYSTEM;
            }
            else
            {
                context.Options &= ~(uint)ECTXOptionValues.CXO_SYSTEM;
            }
            context.Name = "BgoonLibrary Tablet Context";

            deviceID = CWintabInfo.GetDefaultDeviceIndex();
            WintabAxis tabletX = CWintabInfo.GetDeviceAxis(deviceID, EAxisDimension.AXIS_X);
            WintabAxis tabletY = CWintabInfo.GetDeviceAxis(deviceID, EAxisDimension.AXIS_Y);

            NativeRect = new GRect(tabletX.axMin, tabletY.axMin, tabletX.axMax, tabletY.axMax);

            context.OutOrgX = context.OutOrgY = 0;
            context.OutExtX = (int)(context.OutExtX * OutputExtFactor);
            context.OutExtY = (int)(context.OutExtY * OutputExtFactor);
            //context.OutOrgX = context.OutOrgY = 0;
            //context.OutExtX = MaxPos.x;
            //context.OutExtY = MaxPos.y;

            //context.OutExtY *= -1;
            return(context.Open() ? context : null);
        }
Пример #3
0
        ///////////////////////////////////////////////////////////////////////
        private CWintabContext OpenTestSystemContext(
            int width_I = m_TABEXTX, int height_I = m_TABEXTY, bool ctrlSysCursor = true)
        {
            bool           status     = false;
            CWintabContext logContext = null;

            try
            {
                // Get the default system context.
                // Default is to receive data events.
                //logContext = CWintabInfo.GetDefaultDigitizingContext(ECTXOptionValues.CXO_MESSAGES);
                logContext = CWintabInfo.GetDefaultSystemContext(ECTXOptionValues.CXO_MESSAGES);

                // Set system cursor if caller wants it.
                if (ctrlSysCursor)
                {
                    logContext.Options |= (uint)ECTXOptionValues.CXO_SYSTEM;
                }

                if (logContext == null)
                {
                    TraceMsg("FAILED to get default digitizing context.\n");
                    return(null);
                }

                // Modify the digitizing region.
                logContext.Name = "WintabDN Event Data Context";

                WintabAxis tabletX = CWintabInfo.GetTabletAxis(EAxisDimension.AXIS_X);
                WintabAxis tabletY = CWintabInfo.GetTabletAxis(EAxisDimension.AXIS_Y);

                logContext.InOrgX = 0;
                logContext.InOrgY = 0;
                logContext.InExtX = tabletX.axMax;
                logContext.InExtY = tabletY.axMax;

                logContext.OutOrgX = (int)SystemParameters.VirtualScreenLeft;
                logContext.OutOrgY = (int)SystemParameters.VirtualScreenTop;
                logContext.OutExtX = (int)SystemParameters.VirtualScreenWidth;

                // In Wintab, the tablet origin is lower left.  Move origin to upper left
                // so that it coincides with screen origin.
                logContext.OutExtY = -(int)SystemParameters.VirtualScreenHeight;


                // Open the context, which will also tell Wintab to send data packets.
                status = logContext.Open();

                TraceMsg("Context Open: " + (status ? "PASSED [ctx=" + logContext.HCtx + "]" : "FAILED") + "\n");
            }
            catch (Exception ex)
            {
                TraceMsg("OpenTestDigitizerContext ERROR: " + ex.ToString());
            }

            return(logContext);
        }
Пример #4
0
        ///////////////////////////////////////////////////////////////////////
        private CWintabContext OpenTestSystemContext(
            int width_I = m_TABEXTX, int height_I = m_TABEXTY, bool ctrlSysCursor = true)
        {
            bool           status     = false;
            CWintabContext logContext = null;

            try
            {
                // Get the default system context.
                // Default is to receive data events.
                //logContext = CWintabInfo.GetDefaultDigitizingContext(ECTXOptionValues.CXO_MESSAGES);
                logContext = CWintabInfo.GetDefaultSystemContext(ECTXOptionValues.CXO_MESSAGES);

                // Set system cursor if caller wants it.
                if (ctrlSysCursor)
                {
                    logContext.Options |= (uint)ECTXOptionValues.CXO_SYSTEM;
                }
                else
                {
                    logContext.Options &= ~(uint)ECTXOptionValues.CXO_SYSTEM;
                }

                if (logContext == null)
                {
                    TraceMsg("FAILED to get default digitizing context.\n");
                    return(null);
                }

                // Modify the digitizing region.
                logContext.Name = "WintabDN Event Data Context";

                WintabAxis tabletX = CWintabInfo.GetTabletAxis(EAxisDimension.AXIS_X);
                WintabAxis tabletY = CWintabInfo.GetTabletAxis(EAxisDimension.AXIS_Y);

                logContext.InOrgX = 0;
                logContext.InOrgY = 0;
                logContext.InExtX = tabletX.axMax;
                logContext.InExtY = tabletY.axMax;

                // SetSystemExtents() is (almost) a NO-OP redundant if you opened a system context.
                SetSystemExtents(ref logContext);

                // Open the context, which will also tell Wintab to send data packets.
                status = logContext.Open();

                TraceMsg("Context Open: " + (status ? "PASSED [ctx=" + logContext.HCtx + "]" : "FAILED") + "\n");
            }
            catch (Exception ex)
            {
                TraceMsg("OpenTestDigitizerContext ERROR: " + ex.ToString());
            }

            return(logContext);
        }
Пример #5
0
        ///////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Opens a Wintab default system context
        /// </summary>
        /// <param name="ctrlSysCursor"></param>
        /// <returns></returns>

        private CWintabContext OpenTestSystemContext(bool ctrlSysCursor = true)
        {
            bool           status     = false;
            CWintabContext logContext = null;

            try
            {
                // Get the default system context.
                // Default is to receive data events.
                logContext = CWintabInfo.GetDefaultSystemContext(ECTXOptionValues.CXO_MESSAGES);

                // Set system cursor if caller wants it.
                if (ctrlSysCursor)
                {
                    logContext.Options |= (uint)ECTXOptionValues.CXO_SYSTEM;
                }
                else
                {
                    logContext.Options &= ~(uint)ECTXOptionValues.CXO_SYSTEM;
                }

                if (logContext == null)
                {
                    TraceMsg("FAILED to get default wintab context.\n");
                    return(null);
                }

                // ----------------------------------------------------------------------
                // Modify the tablet extents to set what part of the tablet is used.
                Rectangle newTabletInRect  = new Rectangle();
                Rectangle newTabletOutRect = new Rectangle();

                SetTabletExtents(ref logContext, newTabletInRect, newTabletOutRect);

                // ----------------------------------------------------------------------
                // Modify the system extents to control where cursor is allowed to move on desktop.
                Rectangle newScreenRect = new Rectangle();

                SetSystemExtents(ref logContext, newScreenRect);

                // Open the context, which will also tell Wintab to send data packets.
                status = logContext.Open();

                TraceMsg("Context Open: " + (status ? "PASSED [ctx=" + logContext.HCtx + "]" : "FAILED") + "\n");
            }
            catch (Exception ex)
            {
                TraceMsg("OpenTestDigitizerContext ERROR: " + ex.ToString());
            }

            return(logContext);
        }
Пример #6
0
        ///////////////////////////////////////////////////////////////////////

        private CWintabContext OpenTestDigitizerContext(
            int width_I = 0, int height_I = 0, bool ctrlSysCursor = true)
        {
            bool           status     = false;
            CWintabContext logContext = null;

            try
            {
                // Get the default digitizing context.
                // Default is to receive data events.
                logContext = CWintabInfo.GetDefaultDigitizingContext(ECTXOptionValues.CXO_MESSAGES);

                // Set system cursor if caller wants it.
                if (ctrlSysCursor)
                {
                    logContext.Options |= (uint)ECTXOptionValues.CXO_SYSTEM;
                }

                if (logContext == null)
                {
                    TraceMsg("FAILED to get default digitizing context.\n");
                    return(null);
                }

                // Modify the digitizing region.
                logContext.Name = "WintabDN Event Data Context";

                if (width_I != 0 && height_I != 0)
                {
                    // output in a grid of the specified dimensions.
                    logContext.OutOrgX = logContext.OutOrgY = 0;
                    logContext.OutExtX = width_I;
                    logContext.OutExtY = height_I;
                }

                // Open the context, which will also tell Wintab to send data packets.
                status = logContext.Open();

                TraceMsg("Context Open: " + (status ? "PASSED [ctx=" + logContext.HCtx + "]" : "FAILED") + "\n");
            }
            catch (Exception ex)
            {
                TraceMsg("OpenTestDigitizerContext ERROR: " + ex.ToString());
            }

            return(logContext);
        }
Пример #7
0
        ///////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Allows user to change tablet to system mapping.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void MappingButton_Click(object sender, EventArgs e)
        {
            if (m_logContext == null)
            {
                System.Windows.Forms.MessageBox.Show("Oops - You need to run Wintab tests or Scribble before you can use this button.");
                return;
            }

            PenTestApp.MappingForm mappingDlg = new PenTestApp.MappingForm();
            mappingDlg.Init(m_logContext);
            if (DialogResult.OK == mappingDlg.ShowDialog())
            {
                // Close existing context and create a new context with the changed extents.
                CWintabContext temp   = mappingDlg.LogContext;
                Point          inOrg  = new Point(temp.InOrgX, temp.InOrgY);
                Size           inExt  = new Size(temp.InExtX, temp.InExtY);
                Point          outOrg = new Point(temp.OutOrgX, temp.OutOrgY);
                Size           outExt = new Size(temp.OutExtX, temp.OutExtY);
                Point          sysOrg = new Point(temp.SysOrgX, temp.SysOrgY);
                Size           sysExt = new Size(temp.SysExtX, temp.SysExtY);

                CloseCurrentContext();

                m_logContext = CWintabInfo.GetDefaultSystemContext(ECTXOptionValues.CXO_MESSAGES);

                if (m_logContext == null)
                {
                    throw new NullReferenceException("Oops - FAILED to get default system context.\n");
                }

                SetTabletExtents(ref m_logContext, new Rectangle(inOrg, inExt), new Rectangle(outOrg, outExt));
                SetSystemExtents(ref m_logContext, new Rectangle(sysOrg, sysExt));

                if (m_logContext == null)
                {
                    TraceMsg("Test_DataPacketQueueSize: FAILED OpenTestSystemContext - bailing out...\n");
                    return;
                }

                CreateDataObject(m_logContext);

                m_logContext.Open();
            }
        }
Пример #8
0
        private CWintabContext OpenQueryDigitizerContext(out bool status)
        {
            status = false;
            CWintabContext logContext = null;

            try
            {
                // Get the default digitizing context.
                // Default is to receive data events.
                logContext = CWintabInfo.GetDefaultDigitizingContext(ECTXOptionValues.CXO_MESSAGES);

                // Set system cursor
                logContext.Options |= (uint)ECTXOptionValues.CXO_SYSTEM;

                if (logContext == null)
                {
                    return(null);
                }

                // Modify the digitizing region.
                logContext.Name = "WintabDN Event Data Context";

                // output in a 10000 x 10000 grid
                logContext.OutOrgX = logContext.OutOrgY = 0;
                logContext.OutExtX = 10000;
                logContext.OutExtY = 10000;


                // Open the context, which will also tell Wintab to send data packets.
                status = logContext.Open();

                // set IsConnected to the status of the tablet true = tablet ready false = tablet not found / tablet not supported
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(logContext);
        }
        //---------------------------------------------------------------------
        // Prepare to take tablet input
        //---------------------------------------------------------------------
        private void PrepareForTabletInput(object sender, EventArgs e)
        {
            // Set up the tablet context
            CWintabContext context = new CWintabContext();

            context = CWintabInfo.GetDefaultDigitizingContext(ECTXOptionValues.CXO_MESSAGES);

            // Allow the mouse to move
            context.Options |= (uint)ECTXOptionValues.CXO_SYSTEM;

            context.Name    = "Tablet event data context";
            context.OutOrgX = 0;
            context.OutOrgY = 0;
            context.OutExtX = 1000;
            context.OutExtY = 1000;

            bool status = context.Open();

            // Prepare to take data
            data = new CWintabData(context);
            data.SetWTPacketEventHandler(TabletEventHandler);
        }
Пример #10
0
        /// <summary>
        /// Tries initializing the tablet reading logic. Returns false on failure.
        /// </summary>
        public bool Start()
        {
            try
            {
                winTabContext = CWintabInfo.GetDefaultSystemContext(ECTXOptionValues.CXO_MESSAGES | ECTXOptionValues.CXO_SYSTEM);
                winTabData    = new CWintabData(winTabContext);

                // Failed to get the system context
                if (winTabContext == null)
                {
                    return(false);
                }

                winTabContext.Name = "DynamicDraw Tablet Event Data Context";

                WintabAxis tabletX = CWintabInfo.GetTabletAxis(EAxisDimension.AXIS_X);
                WintabAxis tabletY = CWintabInfo.GetTabletAxis(EAxisDimension.AXIS_Y);

                winTabContext.InOrgX = 0;
                winTabContext.InOrgY = 0;
                winTabContext.InExtX = tabletX.axMax;
                winTabContext.InExtY = tabletY.axMax;

                // Tablet origin is usually lower left, invert it to be upper left to match screen coord system.
                winTabContext.OutExtY = -winTabContext.OutExtY;

                bool didOpen = winTabContext.Open();

                winTabData.SetWTPacketEventHandler(UpdateTabletData);

                return(true);
            }
            catch (DllNotFoundException)
            {
                // winTab32.dll is missing. Tablet users will have it; non-tablet users don't need it.
                return(false);
            }
        }
Пример #11
0
        private bool InitWintab()
        {
            bool status = false;

            try
            {
                mLogContext = CWintabInfo.GetDefaultDigitizingContext(ECTXOptionValues.CXO_MESSAGES);
                if (mLogContext == null)
                {
                    return(false);
                    //throw new Exception("Oops - FAILED GetDefaultDigitizingContext");
                }

                // Control system cursor.
                mLogContext.Options |= (UInt32)ECTXOptionValues.CXO_SYSTEM;

                // Verify which extensions are available for targeting.
                // Once we know what the tablet supports, we can set up the data packet
                // definition to be sent events from those control types.

                // All tablets should have at least expresskeys.
                mExpKeysMask = CWintabExtensions.GetWTExtensionMask(EWTXExtensionTag.WTX_EXPKEYS2);

                if (mExpKeysMask > 0)
                {
                    mLogContext.PktData |= (WTPKT)mExpKeysMask;
                }
                else
                {
                    Debug.WriteLine("InitWintab: WTX_EXPKEYS2 mask not found!");
                    throw new Exception("Oops - FAILED GetWTExtensionMask for WTX_EXPKEYS2");
                }

                // It's not an error if either / both of these are zero.  It simply means
                // that those control types are not supported.
                mTouchRingMask = CWintabExtensions.GetWTExtensionMask(EWTXExtensionTag.WTX_TOUCHRING);
                if (mTouchRingMask > 0)
                {
                    mLogContext.PktData |= (WTPKT)mTouchRingMask;
                }

                mTouchStripMask = CWintabExtensions.GetWTExtensionMask(EWTXExtensionTag.WTX_TOUCHSTRIP);
                if (mTouchStripMask > 0)
                {
                    mLogContext.PktData |= (WTPKT)mTouchStripMask;
                }

                status = mLogContext.Open();
                if (!status)
                {
                    //throw new Exception("Oops - failed logContext.Open()");
                    return(false);
                }

                // Setup controls and overrides for first tablet.
                SetupControlsForTablet(mTabletIndexDefault);

                // Create a data object and set its WT_PACKET handler.
                m_wtData = new CWintabData(mLogContext);
                m_wtData.SetWTPacketEventHandler(MyWTPacketEventHandler);
            }
            catch (Exception ex)
            {
                MessageBox.Show("FormExtTestApp: InitWintab: " + ex.ToString());
            }

            return(true);
        }
Пример #12
0
        ///////////////////////////////////////////////////////////////////////
        private CWintabContext OpenTestSystemContext(Screen forScreen,
                                                     int width_I = m_TABEXTX, int height_I = m_TABEXTY, bool ctrlSysCursor = true)
        {
            bool           status     = false;
            CWintabContext logContext = null;

            try
            {
                // Get the default system context.
                // Default is to receive data events.
                //logContext = CWintabInfo.GetDefaultDigitizingContext(ECTXOptionValues.CXO_MESSAGES);
                logContext = CWintabInfo.GetDefaultSystemContext(ECTXOptionValues.CXO_MESSAGES);

                // Set system cursor if caller wants it.
                ctrlSysCursor = false;//#tmp test
                if (ctrlSysCursor)
                {
                    logContext.Options |= (uint)ECTXOptionValues.CXO_SYSTEM;
                }
                else
                {
                    logContext.Options &= ~(uint)ECTXOptionValues.CXO_SYSTEM;
                }
                logContext.PktMode = 0;
                if (logContext == null)
                {
                    return(null);
                }

                // Modify the digitizing region.
                logContext.Name = "WintabDN Event Data Context";

                WintabAxis tabletX = CWintabInfo.GetTabletAxis(EAxisDimension.AXIS_X);
                WintabAxis tabletY = CWintabInfo.GetTabletAxis(EAxisDimension.AXIS_Y);

                logContext.InOrgX = 0;
                logContext.InOrgY = 0;
                logContext.InExtX = tabletX.axMax;
                logContext.InExtY = tabletY.axMax;
                //# this is how to set higher resolution

                /*logContext.OutOrgY = logContext.OutOrgY * MultFactor;
                *  logContext.OutExtX = logContext.OutExtX * MultFactor;
                *  logContext.OutOrgX = logContext.OutOrgX * MultFactor;
                *  logContext.OutExtY = logContext.OutExtY * MultFactor;*/

                logContext.OutOrgY = forScreen.Bounds.Y * MultFactor;
                logContext.OutExtX = forScreen.Bounds.Width * MultFactor;
                logContext.OutOrgX = forScreen.Bounds.X * MultFactor;
                logContext.OutExtY = forScreen.Bounds.Height * MultFactor;

                //logContext.PktRate = 25;


                // SetSystemExtents() is (almost) a NO-OP redundant if you opened a system context.
                SetSystemExtents(ref logContext);

                // Open the context, which will also tell Wintab to send data packets.
                status = logContext.Open();
            }
            catch (Exception ex)
            {
            }

            return(logContext);
        }