private void DecodeRotateGesture(ref Win32.GESTUREINFO gestureInfo) { RotateGestureEventArgs args = new RotateGestureEventArgs(); if (gestureInfo.dwFlags == Win32.GF_BEGIN) { args.state = GestureState.Begin; args.initialRotation = Win32.ArgToRadians(gestureInfo.ullArguments & Win32.ULL_ARGUMENTS_BIT_MASK); args.rotation = 0; } else { if (gestureInfo.dwFlags == Win32.GF_END) { args.state = GestureState.End; } else { args.state = GestureState.Move; } args.rotation = Win32.ArgToRadians(gestureInfo.ullArguments & Win32.ULL_ARGUMENTS_BIT_MASK); } args.ptCenter.X = gestureInfo.ptsLocation.X; args.ptCenter.Y = gestureInfo.ptsLocation.Y; if (RotateEventHandler != null) { RotateEventHandler(this, args); } }
private void DecodeRotateGesture(ref Win32.GESTUREINFO gestureInfo) { RotateGestureEventArgs e = new RotateGestureEventArgs(); if (gestureInfo.dwFlags == 1) { e.state = GestureState.Begin; e.initialRotation = Win32.ArgToRadians(gestureInfo.ullArguments & ((long)0xffffffffL)); e.rotation = 0.0; } else { if (gestureInfo.dwFlags == 4) { e.state = GestureState.End; } else { e.state = GestureState.Move; } e.rotation = Win32.ArgToRadians(gestureInfo.ullArguments & ((long)0xffffffffL)); } e.ptCenter.X = gestureInfo.ptsLocation.X; e.ptCenter.Y = gestureInfo.ptsLocation.Y; if (this.RotateEventHandler != null) { this.RotateEventHandler(this, e); } }
private void DecodePanGesture(ref Win32.GESTUREINFO gestureInfo) { PanGestureEventArgs args = new PanGestureEventArgs(); switch (gestureInfo.dwFlags) { case Win32.GF_BEGIN: { args.state = GestureState.Begin; mPanInfo.ptFirst.X = gestureInfo.ptsLocation.X; mPanInfo.ptFirst.Y = gestureInfo.ptsLocation.Y; mPanInfo.ptSecond.X = 0; mPanInfo.ptSecond.Y = 0; } break; case Win32.GF_END: { args.state = GestureState.End; mPanInfo.ptSecond.X = gestureInfo.ptsLocation.X; mPanInfo.ptSecond.Y = gestureInfo.ptsLocation.Y; } break; case Win32.GF_INERTIA: { args.state = GestureState.Inertia; mPanInfo.ptSecond.X = gestureInfo.ptsLocation.X; mPanInfo.ptSecond.Y = gestureInfo.ptsLocation.Y; } break; default: // Pan Move { args.state = GestureState.Move; mPanInfo.ptSecond.X = gestureInfo.ptsLocation.X; mPanInfo.ptSecond.Y = gestureInfo.ptsLocation.Y; } break; } // Copy the pan coordinates into the event args and fire the event args.distance = (int)(gestureInfo.ullArguments & Win32.ULL_ARGUMENTS_BIT_MASK); args.ptFirst.X = mPanInfo.ptFirst.X; args.ptFirst.Y = mPanInfo.ptFirst.Y; args.ptSecond.X = mPanInfo.ptSecond.X; args.ptSecond.Y = mPanInfo.ptSecond.Y; if (PanEventHandler != null) { PanEventHandler(this, args); } mPanInfo.argument = (int)(gestureInfo.ullArguments & Win32.ULL_ARGUMENTS_BIT_MASK); if (gestureInfo.dwFlags != Win32.GF_BEGIN) { // Set the first point to the second point, so we can have it as first next time mPanInfo.ptFirst.X = mPanInfo.ptSecond.X; mPanInfo.ptFirst.Y = mPanInfo.ptSecond.Y; } }
private void DecodeTwoFingerTapGesture(ref Win32.GESTUREINFO gestureInfo) { TwoFingerTapGestureEventArgs args = new TwoFingerTapGestureEventArgs(); switch (gestureInfo.dwFlags) { case Win32.GF_BEGIN: { args.state = GestureState.Begin; } break; case Win32.GF_END: { args.state = GestureState.End; } break; } args.distance = (int)(gestureInfo.ullArguments & Win32.ULL_ARGUMENTS_BIT_MASK); args.ptCenter.X = gestureInfo.ptsLocation.X; args.ptCenter.Y = gestureInfo.ptsLocation.Y; if (TwoFingerTapEventHandler != null) { TwoFingerTapEventHandler(this, args); } }
private void DecodePressAndTapGesture(ref Win32.GESTUREINFO gestureInfo) { PressAndTapGestureEventArgs args = new PressAndTapGestureEventArgs(); switch (gestureInfo.dwFlags) { case Win32.GF_BEGIN: { args.state = GestureState.Begin; } break; case Win32.GF_END: { args.state = GestureState.End; } break; } // Nothing is being done here with the ULLArguments or the gestureInfo.ptsLocation, since Microsoft's // Documentation seems to be innacurate. The docs suggest that the ptsLocation contains the // position of the first finger, and the delta between it and the second( tapped ) finger is stored in // the ULLArgument... however it specifically says that it is stored as a POINT structure in the // lower 32 bits... but a points structure is 2 ints. So either their documents are wrong or they packed // it as two shorts knowing that delta screen space coords wouldn't blow that limit. We can find this out // with some testing }
private void DecodeZoomGesture(ref Win32.GESTUREINFO gestureInfo) { ZoomGestureEventArgs args = new ZoomGestureEventArgs(); switch (gestureInfo.dwFlags) { case Win32.GF_BEGIN: { args.state = GestureState.Begin; mZoomInfo.ptFirst.X = gestureInfo.ptsLocation.X; mZoomInfo.ptFirst.Y = gestureInfo.ptsLocation.Y; } break; default: { if (args.state == GestureState.End) { args.state = GestureState.End; } else { args.state = GestureState.Move; } // Read the second point of the gesture, this is the middle point between the fingers mZoomInfo.ptSecond.X = gestureInfo.ptsLocation.X; mZoomInfo.ptSecond.Y = gestureInfo.ptsLocation.Y; // Calculate the zoom center point POINT ptZoomCenter = new POINT((mZoomInfo.ptFirst.X + mZoomInfo.ptSecond.X) / 2, (mZoomInfo.ptFirst.Y + mZoomInfo.ptSecond.Y) / 2); args.zoom = (double)(gestureInfo.ullArguments & Win32.ULL_ARGUMENTS_BIT_MASK) / (double)(mZoomInfo.argument); } break; } args.distance = (int)(gestureInfo.ullArguments & Win32.ULL_ARGUMENTS_BIT_MASK); args.ptFirst.X = mZoomInfo.ptFirst.X; args.ptFirst.Y = mZoomInfo.ptFirst.Y; args.ptSecond.X = mZoomInfo.ptSecond.X; args.ptSecond.Y = mZoomInfo.ptSecond.Y; if (ZoomEventHandler != null) { ZoomEventHandler(this, args); } // Store the new information as a starting point for the next step in the gesture mZoomInfo.argument = (int)(gestureInfo.ullArguments & Win32.ULL_ARGUMENTS_BIT_MASK); if (gestureInfo.dwFlags != Win32.GF_BEGIN) { mZoomInfo.ptFirst.X = mZoomInfo.ptSecond.X; mZoomInfo.ptFirst.Y = mZoomInfo.ptSecond.Y; } }
private void DecodeGesture(ref Message message) { Win32.GESTUREINFO gestureInfo = new Win32.GESTUREINFO(); gestureInfo.cbSize = mdGestureInfoSize; if (!Win32.GetGestureInfo(message.lparam, ref gestureInfo)) { return; } switch (gestureInfo.dwID) { case Win32.GID_BEGIN: case Win32.GID_END: Win32.DefWindowProc(this.hWnd, message.msg, message.lparam, message.wparam); break; case Win32.GID_PAN: { DecodePanGesture(ref gestureInfo); } break; case Win32.GID_ZOOM: { DecodeZoomGesture(ref gestureInfo); } break; case Win32.GID_ROTATE: { DecodeRotateGesture(ref gestureInfo); } break; case Win32.GID_TWOFINGERTAP: { DecodeTwoFingerTapGesture(ref gestureInfo); } break; case Win32.GID_PRESSANDTAP: { DecodePressAndTapGesture(ref gestureInfo); } break; default: break; } // Close the gesture info handle to avoid leaking memory. Win32.CloseGestureInfoHandle(message.lparam); }
private void DecodePressAndTapGesture(ref Win32.GESTUREINFO gestureInfo) { PressAndTapGestureEventArgs args = new PressAndTapGestureEventArgs(); switch (gestureInfo.dwFlags) { case 1: args.state = GestureState.Begin; return; case 4: args.state = GestureState.End; break; } }
private void DecodePanGesture(ref Win32.GESTUREINFO gestureInfo) { PanGestureEventArgs e = new PanGestureEventArgs(); switch (gestureInfo.dwFlags) { case 1: e.state = GestureState.Begin; this.mPanInfo.ptFirst.X = gestureInfo.ptsLocation.X; this.mPanInfo.ptFirst.Y = gestureInfo.ptsLocation.Y; this.mPanInfo.ptSecond.X = 0; this.mPanInfo.ptSecond.Y = 0; break; case 2: e.state = GestureState.Inertia; this.mPanInfo.ptSecond.X = gestureInfo.ptsLocation.X; this.mPanInfo.ptSecond.Y = gestureInfo.ptsLocation.Y; break; case 4: e.state = GestureState.End; this.mPanInfo.ptSecond.X = gestureInfo.ptsLocation.X; this.mPanInfo.ptSecond.Y = gestureInfo.ptsLocation.Y; break; default: e.state = GestureState.Move; this.mPanInfo.ptSecond.X = gestureInfo.ptsLocation.X; this.mPanInfo.ptSecond.Y = gestureInfo.ptsLocation.Y; break; } e.distance = (int)(((ulong)gestureInfo.ullArguments) & 0xffffffffL); e.ptFirst.X = this.mPanInfo.ptFirst.X; e.ptFirst.Y = this.mPanInfo.ptFirst.Y; e.ptSecond.X = this.mPanInfo.ptSecond.X; e.ptSecond.Y = this.mPanInfo.ptSecond.Y; if (this.PanEventHandler != null) { this.PanEventHandler(this, e); } this.mPanInfo.argument = (int)(((ulong)gestureInfo.ullArguments) & 0xffffffffL); if (gestureInfo.dwFlags != 1) { this.mPanInfo.ptFirst.X = this.mPanInfo.ptSecond.X; this.mPanInfo.ptFirst.Y = this.mPanInfo.ptSecond.Y; } }
private void DecodeZoomGesture(ref Win32.GESTUREINFO gestureInfo) { ZoomGestureEventArgs e = new ZoomGestureEventArgs(); if (gestureInfo.dwFlags == 1) { e.state = GestureState.Begin; this.mZoomInfo.ptFirst.X = gestureInfo.ptsLocation.X; this.mZoomInfo.ptFirst.Y = gestureInfo.ptsLocation.Y; } else { if (e.state == GestureState.End) { e.state = GestureState.End; } else { e.state = GestureState.Move; } this.mZoomInfo.ptSecond.X = gestureInfo.ptsLocation.X; this.mZoomInfo.ptSecond.Y = gestureInfo.ptsLocation.Y; new POINT((this.mZoomInfo.ptFirst.X + this.mZoomInfo.ptSecond.X) / 2, (this.mZoomInfo.ptFirst.Y + this.mZoomInfo.ptSecond.Y) / 2); e.zoom = ((double)(((ulong)gestureInfo.ullArguments) & 0xffffffffL)) / ((double)this.mZoomInfo.argument); } e.distance = (int)(((ulong)gestureInfo.ullArguments) & 0xffffffffL); e.ptFirst.X = this.mZoomInfo.ptFirst.X; e.ptFirst.Y = this.mZoomInfo.ptFirst.Y; e.ptSecond.X = this.mZoomInfo.ptSecond.X; e.ptSecond.Y = this.mZoomInfo.ptSecond.Y; if (this.ZoomEventHandler != null) { this.ZoomEventHandler(this, e); } this.mZoomInfo.argument = (int)(((ulong)gestureInfo.ullArguments) & 0xffffffffL); if (gestureInfo.dwFlags != 1) { this.mZoomInfo.ptFirst.X = this.mZoomInfo.ptSecond.X; this.mZoomInfo.ptFirst.Y = this.mZoomInfo.ptSecond.Y; } }
private void DecodeTwoFingerTapGesture(ref Win32.GESTUREINFO gestureInfo) { TwoFingerTapGestureEventArgs e = new TwoFingerTapGestureEventArgs(); switch (gestureInfo.dwFlags) { case 1: e.state = GestureState.Begin; break; case 4: e.state = GestureState.End; break; } e.distance = (int)(((ulong)gestureInfo.ullArguments) & 0xffffffffL); e.ptCenter.X = gestureInfo.ptsLocation.X; e.ptCenter.Y = gestureInfo.ptsLocation.Y; if (this.TwoFingerTapEventHandler != null) { this.TwoFingerTapEventHandler(this, e); } }
private void DecodeGesture(ref Message message) { Win32.GESTUREINFO pGestureInfo = new Win32.GESTUREINFO(); pGestureInfo.cbSize = this.mdGestureInfoSize; if (Win32.GetGestureInfo(message.lparam, ref pGestureInfo)) { switch (pGestureInfo.dwID) { case 1: case 2: Win32.DefWindowProc(base.hWnd, message.msg, message.lparam, message.wparam); break; case 3: this.DecodeZoomGesture(ref pGestureInfo); break; case 4: this.DecodePanGesture(ref pGestureInfo); break; case 5: this.DecodeRotateGesture(ref pGestureInfo); break; case 6: this.DecodeTwoFingerTapGesture(ref pGestureInfo); break; case 7: this.DecodePressAndTapGesture(ref pGestureInfo); break; } Win32.CloseGestureInfoHandle(message.lparam); } }