Skip to content

Commit

Permalink
Windows: Cleanup type conversion in touch.
Browse files Browse the repository at this point in the history
This should help if we have uneven DPI.
  • Loading branch information
unknownbrackets committed Apr 12, 2017
1 parent 994e99c commit 587e5f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
53 changes: 32 additions & 21 deletions Windows/TouchInputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/display.h"
#include "Common/CommonWindows.h"
#include "Common/CommonFuncs.h"
#include "base/NativeApp.h"
#include "Windows/MainWindow.h"

Expand Down Expand Up @@ -59,38 +60,48 @@ int TouchInputHandler::ToTouchID(int windowsID, bool allowAllocate) {
return -1;
}

bool TouchInputHandler::GetTouchPoint(HWND hWnd, const TOUCHINPUT &input, float &x, float &y) {
POINT point;
point.x = (LONG)(TOUCH_COORD_TO_PIXEL(input.x));
point.y = (LONG)(TOUCH_COORD_TO_PIXEL(input.y));
if (ScreenToClient(hWnd, &point)) {
x = point.x * g_dpi_scale;
y = point.y * g_dpi_scale;
return true;
}

return false;
}

void TouchInputHandler::handleTouchEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (hasTouch()) {
UINT inputCount = LOWORD(wParam);
HTOUCHINPUT touchInputData = (HTOUCHINPUT) lParam;
HTOUCHINPUT touchInputData = (HTOUCHINPUT)lParam;
TOUCHINPUT *inputs = new TOUCHINPUT[inputCount];
if (touchInfo(touchInputData, inputCount, inputs, sizeof(TOUCHINPUT))) {
for (UINT i = 0; i < inputCount; i++) {
POINT point;
point.x = (float)(TOUCH_COORD_TO_PIXEL(inputs[i].x));
point.y = (float)(TOUCH_COORD_TO_PIXEL(inputs[i].y));
if (ScreenToClient(hWnd, &point)) {
point.x *= g_dpi_scale;
point.y *= g_dpi_scale;
if (inputs[i].dwFlags & TOUCHEVENTF_DOWN) {
touchDown(ToTouchID(inputs[i].dwID), point.x, point.y);
}
if (inputs[i].dwFlags & TOUCHEVENTF_MOVE) {
touchMove(ToTouchID(inputs[i].dwID), point.x, point.y);
}
if (inputs[i].dwFlags & TOUCHEVENTF_UP) {
int id = ToTouchID(inputs[i].dwID, false);
if (id >= 0) {
touchUp(id, point.x, point.y);
touchIds[id] = 0;
}
float x, y;
if (!GetTouchPoint(hWnd, inputs[i], x, y))
continue;

if (inputs[i].dwFlags & TOUCHEVENTF_DOWN) {
touchDown(ToTouchID(inputs[i].dwID), x, y);
}
if (inputs[i].dwFlags & TOUCHEVENTF_MOVE) {
touchMove(ToTouchID(inputs[i].dwID), x, y);
}
if (inputs[i].dwFlags & TOUCHEVENTF_UP) {
int id = ToTouchID(inputs[i].dwID, false);
if (id >= 0) {
touchUp(id, x, y);
touchIds[id] = 0;
}
}
}
closeTouch((HTOUCHINPUT) lParam);
closeTouch(touchInputData);
} else {
// GetLastError() and error handling.
WARN_LOG(SYSTEM, "Failed to read input data: %s", GetLastErrorMsg());
}
delete [] inputs;
}
Expand Down
1 change: 1 addition & 0 deletions Windows/TouchInputHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class TouchInputHandler

private:
int ToTouchID(int windowsID, bool allowAllocate = true);
bool GetTouchPoint(HWND hWnd, const TOUCHINPUT &input, float &x, float &y);

void disablePressAndHold(HWND hWnd);
void touchUp(int id, float x, float y);
Expand Down

0 comments on commit 587e5f7

Please sign in to comment.