//////////////////////////////////////////////////////////////////////////// /// <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> /// Throws an exception if hitrect is invalid. /// </summary> /// <param name="hitrect_I">rectangle tracked by MTAPI for touch contacts</param> public void ThrowIfInvalidHitRect(ref WacomMTHitRect hitRect_I) { if (hitRect_I.Width == 0 || hitRect_I.Height == 0) { throw new Exception("Oops - bad hitrect: [" + hitRect_I.Width + "," + hitRect_I.Height + "]"); } }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Sets/verifies MTAPI hitrect client params. /// </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>s protected void InitWacomMTHitRectClientParams(Int32 deviceID_I, WacomMTHitRect hitrect_I, ref WacomMTCallback callback_I, IntPtr userData_I) { InitWacomMTClientParams(deviceID_I, ref callback_I, userData_I); ThrowIfInvalidHitRect(ref hitrect_I); mHitRect = hitrect_I; }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Helper function to move an MTAPI blob callback by hitrect. /// </summary> /// <param name="newHitRect_I">rectangle tracked by MTAPI for touch contacts</param> /// <param name="userData_I">custom user data</param> /// <returns>See the WacomMTError enumeration definition.</returns> protected override WacomMTError DoMoveHitRectCallback( WacomMTHitRect newHitRect_I, IntPtr userData_I) { WacomMTHitRect oldHitRect = mHitRect; return(CWacomMTInterface.WacomMTMoveRegisteredBlobReadCallback( mDeviceID, ref oldHitRect, mClientMode, ref newHitRect_I, userData_I )); }
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Send updated hitrect to MTAPI for tracking this client. /// </summary> /// <param name="hitrect_I">rectangle tracked by MTAPI for touch contacts</param> public void UpdateHitRect(WacomMTHitRect hitrect_I) { try { // Unregister the client at the old hitrect. UnregisterHitRectClient(); // Register the client at the new hitrect. RegisterHitRectClient(mDeviceID, hitrect_I, ref mTouchCallback, mUserData); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
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()); } }
// ------------------------------------------------------------------------- // 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> /// Help function to notify MTAPI that a client has moved. /// </summary> /// <param name="newHitRect_I">rectangle tracked by MTAPI for touch contacts</param> /// <param name="userData_I">custom user data</param> /// <returns>See the WacomMTError enumeration definition.</returns> protected abstract WacomMTError DoMoveHitRectCallback( WacomMTHitRect newHitRect_I, IntPtr userData_I);
//////////////////////////////////////////////////////////////////////////// /// <summary> /// Sets client params to a default "not a client" condition. /// </summary> protected void ClearWacomMTWindowClientParams() { ClearWacomMTClientParams(); mHitRect = new WacomMTHitRect(0, 0, 0, 0); mHwnd = IntPtr.Zero; }