Page 1 of 1

Gestures...

Posted: Thu Sep 13, 2012 8:46 pm
by DoubleDutch
I can't get gestures to work in win7/8, the GetGestureInfo fails..

Code: Select all

; // Value used in WebViewWndProc For Gestures
#WM_GESTURE =$0119
#WM_GESTURENOTIFY =$011A
; 
; // Gesture Information Flags
#GF_BEGIN=$01
#GF_INERTIA=$02
#GF_END=$04
; 
; // Gesture IDs
Enumeration 1
#GID_BEGIN ; 1
#GID_END ;2
#GID_ZOOM ;3
#GID_PAN ;4
#GID_ROTATE ;5
#GID_TWOFINGERTAP ;6
#GID_PRESSANDTAP ;7
EndEnumeration
#GID_ROLLOVER=#GID_PRESSANDTAP
; 
#GC_ALLGESTURES=$01

; // Zoom Gesture Confiration Flags
#GC_ZOOM=$01
; 
; // Pan Gesture Configuration Flags
#GC_PAN=$01
#GC_PAN_WITH_SINGLE_FINGER_VERTICALLY=$02
#GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY=$04
#GC_PAN_WITH_GUTTER=$08
#GC_PAN_WITH_INERTIA=$10
; 
; // Rotate Gesture Configuration Flags
#GC_ROTATE=$01
; 
; // Two finger tap configuration flags
#GC_TWOFINGERTAP=$01
; 
; // Press And tap Configuration Flags
#GC_PRESSANDTAP=$01
#GC_ROLLOVER=#GC_PRESSANDTAP
; 
; // GESTUREINFO struct definition
Structure GESTUREINFO
	cbSize.l				;                    // size, in bytes, of this structure (including variable length Args field)
	dwFlags.l					;                  // see GF_* flags
	dwID.l				;         	            // gesture ID, see GID_* defines
	hwndTarget.l			;   	             // handle to window targeted by this gesture
	ptsLocation.points		;             // current location of this gesture
	dwInstanceID.l			; 	            // internally used
	dwSequenceID.l				;             // internally used
	ullArguments.q						;         // arguments for gestures whose arguments fit in 8 BYTES
	cbExtraArgs.l				;               // size, in bytes, of extra arguments, if any, that accompany this gesture
EndStructure
; 
; // GESTURECONFIG struct defintion
Structure	GESTURECONFIG
	dwID.l				;                     // gesture ID
	dwWant.l				;                   // settings related to gesture ID that are to be turned on
	dwBlock.l				;                  // settings related to gesture ID that are to be turned off
EndStructure

;  * Gesture notification Structure
;  *   - The WM_GESTURENOTIFY message lParam contains a pointer To this Structure.
;  *   - The WM_GESTURENOTIFY message notifies a window that gesture recognition is
;  *     in progress And a gesture will be generated If one is recognized under the
;  *     current gesture settings.
Structure GESTURENOTIFY
	cbSize.l				;                    // size, in bytes, of this structure
	dwFlags.l					;                  // unused
	hwndTarget.l 				;                // handle to window targeted by the gesture
	ptsLocation.points 		;             // starting location
	dwInstanceID.l	;             // internally used
EndStructure

Global Dim GestureConfig.l(2)
GestureConfig(1)=#GC_ALLGESTURES

CompilerIf #PB_Compiler_OS=#PB_OS_Windows
	Procedure MainWinddowCallback(hWnd,uMsg,wParam,lParam)
		result=#PB_ProcessPureBasicEvents 
		Select uMsg
			Case	#WM_NOTIFY
				
			Case	#WM_GESTURE
				lib=OpenLibrary(#PB_Any,"user32.dll")
				If lib
					Debug("lib open")
					gi.GESTUREINFO\cbSize=SizeOf(GESTUREINFO)
					If CallFunction(lib,"GetGestureInfo",lParam,@gi)
						Select gi\dwID
							Case	#GID_BEGIN:Debug("Gesture begin")
							Case	#GID_END:Debug("Gesture end")
								
							Case	#GID_ZOOM:Debug("Gesture zoom")
								
								
								result=#False
							Case	#GID_PAN:Debug("Gesture pan")
								
								
								result=#False
							Case	#GID_ROTATE:Debug("Gesture rotate")
								
								
								result=#False
							Case	#GID_TWOFINGERTAP:Debug("Gesture two finger tap")
								
								
								result=#False
							Case	#GID_PRESSANDTAP:Debug("Gesture press and tap")
								
								
								result=#False
								
							Default
								Debug("Gesture unknown")
						EndSelect
						CallFunction(lib,"CloseGestureInfoHandle",lParam)
					EndIf
					CloseLibrary(lib)
				EndIf
				
			Case	#WM_GESTURENOTIFY
;				*gesturenotify.GESTURENOTIFY=lParam
				lib=OpenLibrary(#PB_Any,"user32.dll")
				If lib
					CallFunction(lib,"SetGestureConfig",hWnd,0,1,@GestureConfig(0),3*4)
					CloseLibrary(lib)
				EndIf
		EndSelect
				
		ProcedureReturn result
	EndProcedure
CompilerEndIf
;
; Open a window, and do some stuff with it...
;
#W_Main=0

If OpenWindow(#W_Main, 100, 200, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)

CompilerIf #PB_Compiler_OS=#PB_OS_Windows
	SetWindowCallback(@MainWinddowCallback(),#W_Main)
CompilerEndIf

  Repeat
    Event = WaitWindowEvent()

    If Event = #PB_Event_CloseWindow  ; If the user has pressed on the close button
      Quit = 1
    EndIf

  Until Quit = 1
  
EndIf

End   ; All the opened windows are closed automatically by PureBasic
Any ideas?

Re: Gestures...

Posted: Fri Sep 14, 2012 8:23 am
by DoubleDutch
Apparently the gi structure must be 8 bytes aligned, how do you force it to be 8 bytes aligned in PureBasic?

Here is a working structure in PowerBasic:

Code: Select all

' // Size = 48 bytes
TYPE GESTUREINFO QWORD FILL   ' Must be 8 bytes aligned
   cbSize       AS DWORD    ' UINT // size, in bytes, of this structure (including variable length Args field)
   dwFlags      AS DWORD    ' DWORD // see GF_* flags
   dwID         AS DWORD    ' DWORD // gesture ID, see GID_* defines
   hwndTarget   AS DWORD    ' HWND // handle to window targeted by this gesture
   ptsLocation  AS POINTS   ' POINTS // current location of this gesture
   dwInstanceID AS DWORD    ' DWORD // internally used
   dwSequenceID AS DWORD    ' DWORD // internally used
   ullArguments AS QUAD     ' ULONGLONG // arguments for gestures whose arguments fit in 8 BYTES
   cbExtraArgs  AS DWORD    ' UINT // size, in bytes, of extra arguments, if any, that accompany this gesture
   alignment__  AS DWORD    ' // To keep 8 byte alignment
END TYPE
With PureBasic I get it to 40 bytes, 8 bytes missing??

Re: Gestures...

Posted: Fri Sep 14, 2012 8:49 am
by wilbert
DoubleDutch wrote:Apparently the gi structure must be 8 bytes aligned, how do you force it to be 8 bytes aligned in PureBasic?
If you use a pointer like *gi.GESTUREINFO instead of gi.GESTUREINFO you can allocate the memory yourself.
If you use AllocateMemory and allocate the size of the structure with 8 bytes extra, you can set the *gi pointer to the first address of the allocated memory that is 8 bytes aligned.

Re: Gestures...

Posted: Fri Sep 14, 2012 9:14 am
by RASHAD

Code: Select all

Structure GESTUREINFO
   cbSize.i
   dwFlags.i
   dwID.i
   hwndTarget.i
   ptsLocation.POINT
   dwInstanceID.i
   dwSequenceID.i
   ullArguments.q
   cbExtraArgs.i
   PB_Alignment.b[4]
EndStructure

gi.GESTUREINFO

Debug SizeOf(gi)


Re: Gestures...

Posted: Fri Sep 14, 2012 9:22 am
by DoubleDutch
Rashad:

I did the alignment at the end (a .l), but the structure was points, not point - so I made this:

Structure POINTS_ALIGNED
x.w
_alignx.w
y.w
_aligny.w
EndStructure

Works now, looks like gestures are read ok.

Wilbert:

That's what I thought I would have to resort to - the stuff above seems to work for now though.

Shame there isn't an extra parameter for structures for alignment.

Re: Gestures...

Posted: Fri Sep 14, 2012 9:40 am
by RASHAD
Good news
But if is it so
Try the next

Code: Select all

Structure GESTUREINFO
   cbSize.i
   dwFlags.i
   dwID.i
   hwndTarget.i
   ptsLocation.POINTS
   PB_Alignment.b[8]
   dwInstanceID.i
   dwSequenceID.i
   ullArguments.q
   cbExtraArgs.i
EndStructure

Re: Gestures...

Posted: Fri Sep 14, 2012 9:47 am
by DoubleDutch
Good idea, if I have problems I'll try that. :)

Thanks.

Re: Gestures...

Posted: Fri Sep 14, 2012 10:23 am
by DoubleDutch
This seems to work, don't get any results though for the Press and tap, except the the x and y - no delta stuff.

Code: Select all

; // Value used in WebViewWndProc For Gestures
#WM_GESTURE =$0119
#WM_GESTURENOTIFY =$011A
; 
; // Gesture Information Flags
#GF_BEGIN=$01
#GF_INERTIA=$02
#GF_END=$04
; 
; // Gesture IDs
Enumeration 1
#GID_BEGIN ; 1
#GID_END ;2
#GID_ZOOM ;3
#GID_PAN ;4
#GID_ROTATE ;5
#GID_TWOFINGERTAP ;6
#GID_PRESSANDTAP ;7
EndEnumeration
#GID_ROLLOVER=#GID_PRESSANDTAP
; 
#GC_ALLGESTURES=$01

; // Zoom Gesture Confiration Flags
#GC_ZOOM=$01
; 
; // Pan Gesture Configuration Flags
#GC_PAN=$01
#GC_PAN_WITH_SINGLE_FINGER_VERTICALLY=$02
#GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY=$04
#GC_PAN_WITH_GUTTER=$08
#GC_PAN_WITH_INERTIA=$10
; 
; // Rotate Gesture Configuration Flags
#GC_ROTATE=$01
; 
; // Two finger tap configuration flags
#GC_TWOFINGERTAP=$01
; 
; // Press And tap Configuration Flags
#GC_PRESSANDTAP=$01
#GC_ROLLOVER=#GC_PRESSANDTAP

Structure POINTS_ALIGNED
	x.w
	_alignx.w
	y.w
	_aligny.w
EndStructure
; 
; // GESTUREINFO struct definition
Structure GESTUREINFO
	cbSize.l				;                    // size, in bytes, of this structure (including variable length Args field)
	dwFlags.l					;                  // see GF_* flags
	dwID.l				;         	            // gesture ID, see GID_* defines
	hwndTarget.l			;   	             // handle to window targeted by this gesture
	ptsLocation.points		;             // current location of this gesture
	_alignment1.l
	dwInstanceID.l			; 	            // internally used
	dwSequenceID.l				;             // internally used
	ullArguments.q						;         // arguments for gestures whose arguments fit in 8 BYTES
	cbExtraArgs.l				;               // size, in bytes, of extra arguments, if any, that accompany this gesture
	_alignment2.l
EndStructure
; 
; // GESTURECONFIG struct defintion
Structure	GESTURECONFIG
	dwID.l				;                     // gesture ID
	dwWant.l				;                   // settings related to gesture ID that are to be turned on
	dwBlock.l				;                  // settings related to gesture ID that are to be turned off
EndStructure

;  * Gesture notification Structure
;  *   - The WM_GESTURENOTIFY message lParam contains a pointer To this Structure.
;  *   - The WM_GESTURENOTIFY message notifies a window that gesture recognition is
;  *     in progress And a gesture will be generated If one is recognized under the
;  *     current gesture settings.
Structure GESTURENOTIFY
	cbSize.l				;                    // size, in bytes, of this structure
	dwFlags.l					;                  // unused
	hwndTarget.l 				;                // handle to window targeted by the gesture
	ptsLocation.points 		;             // starting location
	dwInstanceID.l	;             // internally used
EndStructure

Global Dim GestureConfig.l(2)
GestureConfig(1)=#GC_ALLGESTURES

CompilerIf #PB_Compiler_OS=#PB_OS_Windows
	Procedure MainWinddowCallback(hWnd,uMsg,wParam,lParam)
		result=#PB_ProcessPureBasicEvents 
		Select uMsg
			Case	#WM_NOTIFY
				
			Case	#WM_GESTURE
				lib=OpenLibrary(#PB_Any,"user32.dll")
				If lib
					Debug("lib open")
					gi.GESTUREINFO\cbSize=SizeOf(GESTUREINFO)
					If CallFunction(lib,"GetGestureInfo",lParam,@gi)
						Select gi\dwID
							Case	#GID_BEGIN:Debug("Gesture begin")
							Case	#GID_END:Debug("Gesture end")
								
							Case	#GID_ZOOM:Debug("Gesture zoom")
								x=gi\ptsLocation\x
								y=gi\ptsLocation\y
								Debug("centre x="+Str(x)+", y="+Str(y))
								Debug("distance="+Str(gi\ullArguments))
								result=#False
							Case	#GID_PAN:Debug("Gesture pan")
								x=gi\ptsLocation\x
								y=gi\ptsLocation\y
								Debug("position x="+Str(x)+", y="+Str(y))
								Debug("distance="+Str(gi\ullArguments))
								
								result=#False
							Case	#GID_ROTATE:Debug("Gesture rotate")
								x=gi\ptsLocation\x
								y=gi\ptsLocation\y
								Debug("centre x="+Str(x)+", y="+Str(y))
								Debug("rotate angle="+Str(gi\ullArguments))
								
								result=#False
							Case	#GID_TWOFINGERTAP:Debug("Gesture two finger tap")
								x=gi\ptsLocation\x
								y=gi\ptsLocation\y
								Debug("centre x="+Str(x)+", y="+Str(y))
								Debug("distance="+Str(gi\ullArguments))
								
								result=#False
							Case	#GID_PRESSANDTAP:Debug("Gesture press and tap")
								x=gi\ptsLocation\x
								y=gi\ptsLocation\y
								x2=PeekW(@gi\ullArguments+4)
								y2=PeekW(@gi\ullArguments+6)
								Debug("first x="+Str(x)+", y="+Str(y))
								Debug("delta x="+Str(x2)+", y="+Str(y2))
								Debug(Str(gi\ullArguments))
								
								result=#False
								
							Default
								Debug("Gesture unknown")
						EndSelect
						If Not result  ; it has been handled, so free the handle
							CallFunction(lib,"CloseGestureInfoHandle",lParam)
						EndIf
					EndIf
					CloseLibrary(lib)
				EndIf
				
			Case	#WM_GESTURENOTIFY
;				*gesturenotify.GESTURENOTIFY=lParam
				lib=OpenLibrary(#PB_Any,"user32.dll")
				If lib
					CallFunction(lib,"SetGestureConfig",hWnd,0,1,@GestureConfig(0),3*4)
					CloseLibrary(lib)
				EndIf
		EndSelect
				
		ProcedureReturn result
	EndProcedure
CompilerEndIf

Re: Gestures...

Posted: Fri Sep 14, 2012 11:35 am
by Danilo

Code: Select all

Structure GESTUREINFO
  cbSize.l
  dwFlags.l
  dwID.l
  PB_Align(0,4)
  hwndTarget.i
  ptsLocation.POINTS
  dwInstanceID.l
  dwSequenceID.l
  PB_Align(4,4,1)
  ullArguments.q
  cbExtraArgs.l
  PB_Align(4,4,2)
EndStructure

;
; // GESTURECONFIG struct defintion
Structure   GESTURECONFIG
   dwID.l               ; gesture ID
   dwWant.l             ; settings related to gesture ID that are to be turned on
   dwBlock.l            ; settings related to gesture ID that are to be turned off
EndStructure

;  * Gesture notification Structure
;  *   - The WM_GESTURENOTIFY message lParam contains a pointer To this Structure.
;  *   - The WM_GESTURENOTIFY message notifies a window that gesture recognition is
;  *     in progress And a gesture will be generated If one is recognized under the
;  *     current gesture settings.
Structure GESTURENOTIFY ; GESTURENOTIFYSTRUCT
   cbSize.l             ; size, in bytes, of this structure
   dwFlags.l            ; unused
   hwndTarget.i         ; handle to window targeted by the gesture
   ptsLocation.points   ; starting location
   dwInstanceID.l       ; internally used
EndStructure
Checked with VS2012 x86 and x64

Re: Gestures...

Posted: Fri Sep 14, 2012 11:56 am
by DoubleDutch
danilo: Thanks. :)

EDIT: the size of GESTUREINFO is 44 though not 48 on x86 - so it fails.

Code: Select all

Structure GESTUREINFO
  cbSize.l
  dwFlags.l
  dwID.l
  PB_Align(0,4)
  hwndTarget.i
  ptsLocation.POINTS
  dwInstanceID.l
  dwSequenceID.l
  PB_Align(4,4,1)
  ullArguments.q
  cbExtraArgs.l
  PB_Align(4,4,2)
EndStructure
On x86 this seems to work better with the call working and ullArguments returning correct distance and angle values, can you check on x64?

Re: Gestures...

Posted: Sat Sep 15, 2012 7:26 am
by Danilo
DoubleDutch wrote:On x86 this seems to work better with the call working and ullArguments returning correct distance and angle values, can you check on x64?
It does not work with mouse and wacom tablet, so cannot test.

Re: Gestures...

Posted: Sat Sep 15, 2012 9:40 am
by DoubleDutch
Does your version of the structures work on the tablet though?

Re: Gestures...

Posted: Sat Sep 15, 2012 10:38 am
by Danilo
DoubleDutch wrote:Does your version of the structures work on the tablet though?
Nope, I didn't see any Debug messages here while moving the tablet pen wild on the window.
I enabled "flicks" in Win7. Is it for finger touch devices only?