Support of the multi touch for Windows 7/8.
Hello,
I tried to add support for multi touch for cocos2d-x that runs in Windows 7. In principle this feature works, though not as good as I would be desirable. Probably due to the fact that I wasn’t familiar with the architecture of the system. Perhaps someone could make code given below better or tell me how to do it.
Changes related to two files:
-
The counter of touches
touchesCounter_
is added to the classCCEGLView
. -
The following line is added to method bool
CCEGLView::Create(...)
after creation and resizing of the window:
RegisterTouchWindow(m_hWnd, 0);
- The next line is added to the method void
CCEGLView::release()
before destroying of the window:
UnregisterTouchWindow(m_hWnd);
-
The processing of messages
WM_TABLET_QUERYSYSTEMGESTURESTATUS
andWM_TOUCH
must be inserted in procedureLRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
.UINT cInputs = 0; PTOUCHINPUT pInputs; POINT ptInput; case WM_TABLET_QUERYSYSTEMGESTURESTATUS: return TABLET_DISABLE_PRESSANDHOLD | // disables press and hold (right-click) gesture TABLET_DISABLE_PENTAPFEEDBACK | // disables UI feedback on pen up (waves) TABLET_DISABLE_PENBARRELFEEDBACK | // disables UI feedback on pen button down (circle) TABLET_DISABLE_FLICKS; // disables pen flicks (back, forward, drag down, drag up) break; case WM_TOUCH: cInputs = LOWORD(wParam); pInputs = new TOUCHINPUT[cInputs]; if (pInputs) { if (GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))) { for (int i = 0; i < static_cast(cInputs); i++) { TOUCHINPUT ti = pInputs[i]; if (ti.dwID != 0) { // Do something with your touch input handle ptInput.x = TOUCH_COORD_TO_PIXEL(ti.x); ptInput.y = TOUCH_COORD_TO_PIXEL(ti.y); ScreenToClient(m_hWnd, &ptInput); if (ti.dwFlags & TOUCHEVENTF_UP) { if (m_bCaptured) { m_pTouch->SetTouchInfo(0, (float)((short)ptInput.x - m_rcViewPort.left) / m_fScreenScaleFactor, (float)((short)ptInput.y - m_rcViewPort.top) / m_fScreenScaleFactor); m_pDelegate->touchesEnded(m_pSet, NULL); m_pSet->removeObject(m_pTouch); touchesCounter_--; if (!touchesCounter_) { ReleaseCapture(); m_bCaptured = false; } } } else if (ti.dwFlags & TOUCHEVENTF_DOWN) { if (m_pDelegate && m_pTouch) { POINT pt = ptInput; if (PtInRect(&m_rcViewPort, pt)) { m_bCaptured = true; touchesCounter_++; SetCapture(m_hWnd); m_pTouch->SetTouchInfo(0, (float)(pt.x - m_rcViewPort.left) / m_fScreenScaleFactor, (float)(pt.y - m_rcViewPort.top) / m_fScreenScaleFactor); m_pSet->addObject(m_pTouch); m_pDelegate->touchesBegan(m_pSet, NULL); } } } else if (ti.dwFlags & TOUCHEVENTF_MOVE) { if (m_bCaptured) { m_pTouch->SetTouchInfo(0, (float)((short)ptInput.x - m_rcViewPort.left) / m_fScreenScaleFactor, (float)((short)ptInput.y - m_rcViewPort.top) / m_fScreenScaleFactor); m_pDelegate->touchesMoved(m_pSet, NULL) ; DoEvents() ; } } } } } // If you handled the message and don't want anything else done with it, you can close it CloseTouchInputHandle((HTOUCHINPUT)lParam); delete [] pInputs; } else { // TraceLog(_T("******* GetTouchInputInfo Error *******")); } break;
-
Naturally, you must install Windows 7 SDK for MS Visual Studio and add following references to additional include and library folders in the project
libcocos2d
:
C:Files\Microsoft SDKs\Windows\v7.0\Include
and
C:Files\Microsoft SDKs\Windows\v7.0\Lib
- And of course, I can send the modified files or all project to any email address.
Regards,
Mk
CCEGLView_win32.cpp.zip (6.3 KB)
CCEGLView_win32.h.zip (1.5 KB)
CCEGLView_win32.h.zip (1.7 KB)
CCEGLView_win32.cpp.zip (6.8 KB)