////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Registers an MTAPI raw data client over the entire tablet surface
        /// (no hitrect or HWND required).
        /// </summary>
        /// <param name="deviceID_I">touch device identifier</param>
        /// <param name="callback_I">callback function used by MTAPI to send touch data</param>
        /// <param name="userData_I">custom user data</param>
        public void RegisterClient(Int32 deviceID_I,
                                   ref WacomMTCallback callback_I, IntPtr userData_I)
        {
            try
            {
                InitWacomMTClientParams(deviceID_I, ref callback_I, userData_I);

                WacomMTError res = CWacomMTInterface.WacomMTRegisterRawReadCallback(
                    mDeviceID, mClientMode, mTouchCallback, mUserData);

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed WacomMTRegisterRawReadCallback with error: " + res.ToString();
                    throw new Exception(errMsg);
                }

#if TRACE_CLIENT
                DumpClient("RegisterClient");
#endif //TRACE_CLIENT
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #2
0
        /// <summary>
        /// 要求されたデバイス識別子のケイパビリティー情報を取得します。
        /// </summary>
        /// <param name="deviceID">デバイス識別子</param>
        /// <returns><see cref="WacomMTCapability"/>構造体</returns>
        public static WacomMTCapability WacomMTGetDeviceCapabilities(int deviceID)
        {
            IntPtr capabilitiesPtr = IntPtr.Zero;            //ポインタの用意

            try {
                capabilitiesPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WacomMTCapability))); //構造体を格納するメモリを確保
                WacomMTError error = _WacomMTGetDeviceCapabilities(deviceID, capabilitiesPtr);     //デバイスの情報を取得

                if (error != WacomMTError.WMTErrorSuccess)                                         //失敗したら例外を発生させる
                {
                    if (capabilitiesPtr != IntPtr.Zero)                                            //メモリが0以外を指していたら
                    {
                        Marshal.FreeHGlobal(capabilitiesPtr);                                      //メモリを解放
                        capabilitiesPtr = IntPtr.Zero;                                             //ポインタを0に
                    }
                    throw new Exception("Error WacomMTGetDeviceCapabilities : " + error);
                }

                return((WacomMTCapability)Marshal.PtrToStructure(capabilitiesPtr, typeof(WacomMTCapability)));
            } catch (Exception e) {
                throw e;
            } finally {
                if (capabilitiesPtr != IntPtr.Zero)                  //メモリが0以外を指していたら
                {
                    Marshal.FreeHGlobal(capabilitiesPtr);            //メモリ解放
                    capabilitiesPtr = IntPtr.Zero;                   //ポインタを0に
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Changes a hitrect client's current hitrect.
        /// </summary>
        /// <param name="newHitRect_I">rectangle tracked by MTAPI for touch contacts</param>
        /// <param name="userData_I">custom user data</param>
        public void MoveHitRectClient(WacomMTHitRect newHitRect_I, IntPtr userData_I)
        {
            try
            {
                WacomMTError   res        = WacomMTError.WMTErrorSuccess;
                WacomMTHitRect oldHitRect = mHitRect;
                WacomMTHitRect newHitRect = newHitRect_I;

                ThrowIfInvalidDeviceID(mDeviceID);
                ThrowIfInvalidHitRect(ref oldHitRect);
                ThrowIfInvalidHitRect(ref newHitRect);

                res = DoMoveHitRectCallback(newHitRect, userData_I);

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed DoMoveHitRectCallback with error: " + res.ToString();
                    throw new Exception(errMsg);
                }

                mHitRect  = newHitRect;
                mUserData = userData_I;

#if TRACE_CLIENT
                DumpClient("MoveHitRectClient");
#endif //TRACE_CLIENT
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Unregisters an MTAPI hitrect client
        /// </summary>
        public void UnregisterHitRectClient()
        {
            try
            {
                ThrowIfInvalidDeviceID(mDeviceID);
                ThrowIfInvalidHitRect(ref mHitRect);

#if TRACE_CLIENT
                DumpClient("UnregisterHitRectClient");
#endif //TRACE_CLIENT

                WacomMTError res = DoUnregisterHitRectCallback();

                ClearWacomMTWindowClientParams();

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed to unregister a hitrect client with error: " + res.ToString();
                    throw new Exception(errMsg);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            WacomMTError status = WacomMTError.WMTErrorSuccess;

            IntPtr userDataBuf = IntPtr.Zero;

            try
            {
                mWacomMTConfig.Init();

                //Delegate called when events come to tablet
                mUpdateRealTimeLabel  = new UpdateDelegate(this.DoUpdateGraphicsControl);
                mUpdateRealTimeLabel += this.DoSendMidiMessage;

                // crée un nouveau callback attach et abonne a ce callback
                mAttachCallback = new WacomMTAttachCallback(this.DoAttachWindowClientCallback);
                status          = CWacomMTInterface.WacomMTRegisterAttachCallback(this.mAttachCallback, IntPtr.Zero);

                if (status != WacomMTError.WMTErrorSuccess)
                {
                    throw new Exception("Failed to register for device attaches - err: " + status.ToString());
                }

                // crée un nouveau callback detack et abonne a ce callback
                mDetachCallback = new WacomMTDetachCallback(this.DoDetachWindowClientCallback);
                status          = CWacomMTInterface.WacomMTRegisterDetachCallback(this.mDetachCallback, IntPtr.Zero);

                if (status != WacomMTError.WMTErrorSuccess)
                {
                    throw new Exception("Failed to register for device detaches - err: " + status.ToString());
                }

                //crée un nouveau callback de type Finger Read et abonne a celui-ci
                WacomMTHitRect HR = new WacomMTHitRect(0, 0, 0, 0);
                mTouchDataCallback = new WacomMTCallback(this.DoFingerDataUpdateCallback);
                status             = CWacomMTInterface.WacomMTRegisterFingerReadCallback(0, ref HR, _processingMode,
                                                                                         mTouchDataCallback, IntPtr.Zero);

                UpdateLabelText();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : " + ex.ToString());
            }
        }
        // -------------------------------------------------------------------------
        // Hwnd methods
        // -------------------------------------------------------------------------

        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Register an MTAPI client by its window handle.
        /// </summary>
        /// <param name="deviceID_I">touch device identifier</param>
        /// <param name="hwnd_I">window handle tracked by MTAPI for touch contacts</param>
        /// <param bufferDepth_I="userData_I">number of callback buffers that MTAPI creates</param>
        public void RegisterHWNDClient(Int32 deviceID_I, HWND hwnd_I,
                                       Int32 bufferDepth_I = 1)
        {
            try
            {
                InitWacomMTHwndClientParams(deviceID_I, hwnd_I, bufferDepth_I);

                WacomMTError res = DoRegisterHwndCallback();

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed DoRegisterHwndCallback with error: " + res.ToString();
                    throw new Exception(errMsg);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Unregisters an MTAPI HWND client.
        /// </summary>
        public void UnregisterHWNDClient()
        {
            try
            {
                ThrowIfInvalidHWND(mHwnd);

                WacomMTError res = DoUnregisterHwndCallback();

                ClearWacomMTWindowClientParams();

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed DoUnregisterHwndCallback with error: " + res.ToString();
                    throw new Exception(errMsg);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Unregisters an MTAPI raw data client
        /// </summary>
        public void UnregisterClient()
        {
            try
            {
                ThrowIfInvalidDeviceID(mDeviceID);

                WacomMTError res =
                    CWacomMTInterface.WacomMTUnRegisterRawReadCallback(
                        mDeviceID,
                        mClientMode,
                        mUserData);

                if (res != WacomMTError.WMTErrorSuccess)
                {
                    throw new Exception("Failed UnregisterClient");
                }

                ClearWacomMTClientParams();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        // -------------------------------------------------------------------------
        // HitRect methods
        // -------------------------------------------------------------------------

        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Registers an MTAPI windowed client using a hitrect.
        /// </summary>
        /// <param name="deviceID_I">touch device identifier</param>
        /// <param name="hitrect_I">rectangle tracked by MTAPI for touch contacts</param>
        /// <param name="callback_I">callback function used by MTAPI to send touch data</param>
        /// <param name="userData_I">custom user data</param>
        public void RegisterHitRectClient(Int32 deviceID_I, WacomMTHitRect hitrect_I,
                                          ref WacomMTCallback callback_I, IntPtr userData_I)
        {
            try
            {
                InitWacomMTHitRectClientParams(deviceID_I, hitrect_I, ref callback_I, userData_I);

                WacomMTError res = DoRegisterHitRectCallback();

                if (WacomMTError.WMTErrorSuccess != res)
                {
                    String errMsg = "Oops - failed DoRegisterHitRectCallback with error: " + res.ToString();
                    throw new Exception(errMsg);
                }

#if TRACE_CLIENT
                DumpClient("RegisterHitRectClient");
#endif //TRACE_CLIENT
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Initialize MTAPI, find/cache connected devices
        /// and their capabilities.
        /// </summary>
        public void Init()
        {
            IntPtr devBuf = IntPtr.Zero;

            try
            {
                WacomMTError res = WacomMTError.WMTErrorSuccess;

                // ----------------------------------------------------------------
                // Initialize the MTAPI.
                //
                res = CWacomMTInterface.WacomMTInitialize(WacomMTConstants.WACOM_MULTI_TOUCH_API_VERSION);
                if (WacomMTError.WMTErrorSuccess != res)
                {
                    throw new Exception("Oops - failed WacomMTInitialize - is the tablet touch driver running?");
                }
                Trace.WriteLine("WacomMTDN: WacomMTInitialize successful.");

                // ----------------------------------------------------------------
                // Find all attached touch devices.
                // If successful, this will populate mDeviceIDArray.data.
                //
                devBuf = CMemUtils.AllocUnmanagedBuf(mDeviceIDArray);
                Marshal.StructureToPtr(mDeviceIDArray, devBuf, false);

                if (mNumDevices > WacomMTConstants.MAX_NUMBER_TOUCH_DEVICES)
                {
                    throw new Exception("Too many touch devices attached");
                }

                mNumDevices = CWacomMTInterface.WacomMTGetAttachedDeviceIDs(devBuf, mMaxNumTouchDevices * sizeof(Int32));

                if (mNumDevices > 0)
                {
                    mDeviceIDArray = (WacomMTDeviceIDArray)Marshal.PtrToStructure(devBuf, typeof(WacomMTDeviceIDArray));
                    DumpDeviceIDArray();
                }
                else
                {
                    Trace.WriteLine("WacomMTDN: NO TOUCH DEVICES FOUND!");
                }

                CMemUtils.FreeUnmanagedBuf(ref devBuf);

                // ----------------------------------------------------------------
                // Find capabilities for all attached touch devices.
                // If successful, this will populate mDeviceCapsMap.
                //
                if ((mNumDevices > 0) && !UpdateDeviceCaps())
                {
                    throw new Exception("Oops - could not complete query for capabilities");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (devBuf != IntPtr.Zero)
                {
                    CMemUtils.FreeUnmanagedBuf(ref devBuf);
                }
            }
        }
        static void Main(string[] args)
        {
            CursorVisible = false;
            try {
                WacomMTError error = WacomMTAPI.WacomMTInitialize();

                if (error == WacomMTError.WMTErrorSuccess)
                {
                    _Ids = WacomMTAPI.WacomMTGetAttachedDeviceIDs();

                    foreach (int id in _Ids)
                    {
                        WriteLine("Tablet Device #" + id);
                        WacomMTCapability capability = WacomMTAPI.WacomMTGetDeviceCapabilities(id);
                        WriteLine("Virsion : " + capability.Version);
                        WriteLine("DeviceID : " + capability.DeviceID);
                        WriteLine("Type : " + capability.Type);
                        WriteLine("LogicalOriginX : " + capability.LogicalOriginX);
                        WriteLine("LogicalOriginY : " + capability.LogicalOriginY);
                        WriteLine("LogicalWidth : " + capability.LogicalWidth);
                        WriteLine("LogicalHeight : " + capability.LogicalHeight);
                        WriteLine("PhysicalSizeX : " + capability.PhysicalSizeX);
                        WriteLine("PhysicalSizeY : " + capability.PhysicalSizeY);
                        WriteLine("ReportedSizeX : " + capability.ReportedSizeX);
                        WriteLine("ReportedSizeY : " + capability.ReportedSizeY);
                        WriteLine("ScanSizeX : " + capability.ScanSizeX);
                        WriteLine("ScanSizeY : " + capability.ScanSizeY);
                        WriteLine("FingerMax : " + capability.FingerMax);
                        WriteLine("BlobMax : " + capability.BlobMax);
                        WriteLine("BlobPointsMax : " + capability.BlobPointsMax);
                        WriteLine("CapabilityFlags : " + capability.CapabilityFlags);
                        WriteLine();
                    }

                    error = WacomMTAPI.WacomMTRegisterFingerReadCallback(_Ids[0], IntPtr.Zero, WacomMTProcessingMode.WMTProcessingModeNone, FingerCallback, IntPtr.Zero);

                    if (error != WacomMTError.WMTErrorSuccess)
                    {
                        throw new Exception("Errpr WacomMTRegisterFingerReadCallback : " + error);
                    }
                }
                else
                {
                    throw new Exception("Error WacomMTInitialize : " + error);
                }
            } catch (Exception e) {
                SetCursorPosition(0, CursorTop + 2);
                WriteLine(e.Message);
            }

            using (GrandSlider slider = new GrandSlider()) {
                slider.Run(60);
            }

            /**
             * do {
             *      Thread.Sleep(10);
             * } while (!Keyboard.IsKeyDown(Key.Enter));
             */
            WacomMTAPI.WacomMTQuit();
        }