Enable touch support by default

Check for touch support and enable it automatically if available.
It's probably possible to hack around Vista with the HID stuff but
I don't think Vista that want multitouch is a large enough group
to invest the time.
This commit is contained in:
Peter Tissen committed 2014-01-23 20:16:38 +01:00
1 parent b991d49049
commit 4a4488eb98
4 files changed
+124 -90

No files matched your search

+82 -53
View File
@@ -9,8 +9,23 @@
extern InputState input_state;
TouchInputHandler::TouchInputHandler()
TouchInputHandler::TouchInputHandler() :
touchInfo(nullptr),
closeTouch(nullptr),
registerTouch(nullptr)
{
touchInfo = (getTouchInputProc) GetProcAddress(
GetModuleHandle(TEXT("User32.dll")),
"GetTouchInputInfo");
closeTouch = (closeTouchInputProc) GetProcAddress(
GetModuleHandle(TEXT("User32.dll")),
"CloseTouchInputHandle");
registerTouch = (registerTouchProc) GetProcAddress(
GetModuleHandle(TEXT("User32.dll")),
"RegisterTouchWindow");
}
@@ -20,67 +35,67 @@ TouchInputHandler::~TouchInputHandler()
void TouchInputHandler::handleTouchEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
#if ENABLE_TOUCH
UINT inputCount = LOWORD(wParam);
TOUCHINPUT *inputs = new TOUCHINPUT[inputCount];
if (GetTouchInputInfo((HTOUCHINPUT) lParam,
inputCount,
inputs,
sizeof(TOUCHINPUT)))
{
for (int i = 0; i < inputCount; i++) {
int id = 0;
if (hasTouch()){
UINT inputCount = LOWORD(wParam);
TOUCHINPUT *inputs = new TOUCHINPUT[inputCount];
if (touchInfo((HTOUCHINPUT) lParam,
inputCount,
inputs,
sizeof(TOUCHINPUT)))
{
for (int i = 0; i < inputCount; i++) {
int id = 0;
//here we map the windows touch id to the ppsspp internal touch id
//currently we ignore the fact that the mouse uses touch id 0, so that
//the mouse could possibly interfere with the mapping so for safety
//the maximum amount of touch points is MAX_POINTERS-1
std::map<int, int>::const_iterator it = touchTranslate.find(inputs[i].dwID);
if (it != touchTranslate.end()) //check if we already mapped this touch id
{
id = it->second;
}
else
{
if (touchTranslate.size() + 1 >= MAX_POINTERS) //check if we're tracking too many points
//here we map the windows touch id to the ppsspp internal touch id
//currently we ignore the fact that the mouse uses touch id 0, so that
//the mouse could possibly interfere with the mapping so for safety
//the maximum amount of touch points is MAX_POINTERS-1
std::map<int, int>::const_iterator it = touchTranslate.find(inputs[i].dwID);
if (it != touchTranslate.end()) //check if we already mapped this touch id
{
touchUp(touchTranslate.begin()->second, 0, 0);
touchTranslate.erase(touchTranslate.begin());
id = it->second;
}
else
{
if (touchTranslate.size() + 1 >= MAX_POINTERS) //check if we're tracking too many points
{
touchUp(touchTranslate.begin()->second, 0, 0);
touchTranslate.erase(touchTranslate.begin());
}
//finding first free internal touch id and map this windows id to an internal id
bool *first_free = std::find(input_state.pointer_down, input_state.pointer_down + MAX_POINTERS, false);
id = (first_free - input_state.pointer_down) / sizeof(bool);
touchTranslate[inputs[i].dwID] = id;
}
//finding first free internal touch id and map this windows id to an internal id
bool *first_free = std::find(input_state.pointer_down, input_state.pointer_down + MAX_POINTERS, false);
id = (first_free - input_state.pointer_down) / sizeof(bool);
touchTranslate[inputs[i].dwID] = id;
}
POINT point;
point.x = TOUCH_COORD_TO_PIXEL(inputs[i].x);
point.y = TOUCH_COORD_TO_PIXEL(inputs[i].y);
POINT point;
point.x = TOUCH_COORD_TO_PIXEL(inputs[i].x);
point.y = TOUCH_COORD_TO_PIXEL(inputs[i].y);
if (ScreenToClient(hWnd, &point)){
if (inputs[i].dwFlags & TOUCHEVENTF_DOWN)
{
touchDown(id, point.x, point.y);
}
if (inputs[i].dwFlags & TOUCHEVENTF_MOVE)
{
touchMove(id, point.x, point.y);
}
if (inputs[i].dwFlags & TOUCHEVENTF_UP)
{
touchUp(id, point.x, point.y);
touchTranslate.erase(touchTranslate.find(inputs[i].dwID));
if (ScreenToClient(hWnd, &point)){
if (inputs[i].dwFlags & TOUCHEVENTF_DOWN)
{
touchDown(id, point.x, point.y);
}
if (inputs[i].dwFlags & TOUCHEVENTF_MOVE)
{
touchMove(id, point.x, point.y);
}
if (inputs[i].dwFlags & TOUCHEVENTF_UP)
{
touchUp(id, point.x, point.y);
touchTranslate.erase(touchTranslate.find(inputs[i].dwID));
}
}
}
closeTouch((HTOUCHINPUT) lParam);
}
CloseTouchInputHandle((HTOUCHINPUT) lParam);
else
{
// GetLastError() and error handling.
}
delete [] inputs;
}
else
{
// GetLastError() and error handling.
}
delete[] inputs;
#endif
}
void TouchInputHandler::touchUp(int id, float x, float y){
@@ -122,4 +137,18 @@ void TouchInputHandler::touchMove(int id, float x, float y){
input_state.pointer_y[id] = y;
input_state.lock.unlock();
NativeTouch(touchevent);
}
void TouchInputHandler::registerTouchWindow(HWND wnd)
{
if (hasTouch())
registerTouch(wnd, TWF_WANTPALM);
}
bool TouchInputHandler::hasTouch(){
return (
touchInfo != nullptr &&
closeTouch != nullptr &&
registerTouch != nullptr
);
}