Example #1
0
void TouchInputHandler::handleTouchEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	if (hasTouch()) {
		UINT inputCount = LOWORD(wParam);
		HTOUCHINPUT touchInputData = (HTOUCHINPUT)lParam;
		TOUCHINPUT *inputs = new TOUCHINPUT[inputCount];
		if (touchInfo(touchInputData, inputCount, inputs, sizeof(TOUCHINPUT))) {
			for (UINT i = 0; i < inputCount; i++) {
				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(touchInputData);
		} else {
			WARN_LOG(SYSTEM, "Failed to read input data: %s", GetLastErrorMsg());
		}
		delete [] inputs;
	}
}
// Handler for touch-up message.
// in:
//      hWnd        window handle
//      ti          TOUCHINPUT structure (info about contact)
void OnTouchUpHandler(HWND hWnd, const TOUCHINPUT& ti)
{
    // Extract contact info: contact ID
    int iCursorId = GetTouchContactID(ti);

    // Extract contact info: contact point
    POINT pt = GetTouchPoint(hWnd, ti);

    sendAreaSize(hWnd, iCursorId, pt);
    WPARAM wParam = MAKEWPARAM(EX_TOUCH_EVENT_END, iCursorId);
    LPARAM lParam = MAKELPARAM(pt.x & 0x0000ffff, pt.y & 0x0000ffff);

    //int msgboxID = MessageBox(
    //      hWnd,
    //      (LPCWSTR)L"EX_TOUCH_EVENT_END",
    //      (LPCWSTR)L"TOUCH",
    //      MB_OK
    //  );

    //PostMessage(hWnd, WM_APP + 5, wParam, lParam);
    PostMessage(keyboardHandle, WM_APP + 5, wParam, lParam);

    //remove last move
    lastMoves.erase(ti.dwID);

    //trace("up\n");
}
void OnTouchDownHandler(HWND hWnd, const TOUCHINPUT& ti)
{
    // Extract contact info: point of contact and ID
    int iCursorId = GetTouchContactID(ti);
    POINT pt = GetTouchPoint(hWnd, ti);

    sendAreaSize(hWnd, iCursorId, pt);
    WPARAM wParam = MAKEWPARAM(EX_TOUCH_EVENT_START,iCursorId);
    LPARAM lParam = MAKELPARAM(pt.x & 0x0000ffff, pt.y & 0x0000ffff);

    //int msgboxID = MessageBox(
//       hWnd,
//       (LPCWSTR)L"EX_TOUCH_EVENT_START",
//       (LPCWSTR)L"TOUCH",
//       MB_OK
//   );

    //PostMessage(hWnd, WM_APP + 5, wParam, lParam);
    // Posting to keyboardHandle sends the message to the WndProc of the application that has called InitializeTouch
    // (as opposed to sending it to any sub-process owning hWnd (the window in which the touch occurred)).
    PostMessage(keyboardHandle, WM_APP + 5, wParam, lParam);

    /*
    int globalX = pt.x;
    int globalY = pt.y;
    ScreenToClient(hWnd, &pt);
    int localX = pt.x;
    int localY = pt.y;

    char buf[10240];
    sprintf(buf, "down in window: %d; global = (%d, %d); local = (%d, %d)\n", hWnd, globalX, globalY, localX, localY);
    trace(buf);
    */
}
Example #4
0
uint16_t TFTSlider::processTouch(uint16_t x, uint16_t y) {

	if (!((x >= _x) && (x <= (_x+_w)) && (y >= _y) && (y <= (_y+_h))))
		return 0x0;        // Special value that says Not within the object...

	SetPressed(true);
	draw();    // Show it as depressed.

	// Now lets wait for the touch to release...
    while (ts.touched()) {
      GetTouchPoint(&x, &y);
      if (_fVert) {
    	  if ((y >= _y) && (y <= (_y+_h))) {
    		  _wDispVal = y;
    		  draw();    // try to redraw....
    	  }
      }
      else {
    	  if ((x >= _x) && (x <= (_x+_w))) {
    		  _wDispVal = x;
    		  draw();    // try to redraw....
    	  }
      }
	}
    while (!ts.bufferEmpty()) {
		GetTouchPoint(&x, &y);
	}

	SetPressed(false);

	// And see if we were still inside the button
	if ((x >= _x) && (x < (_x+_w)) && (y >= _y) && (y < (_y+_h))) {
		if (_fVert)
			SetValue(mapDisplayValueToValue(y));
		else
			SetValue(mapDisplayValueToValue(x));
		return 1;
	}

	// Otherwise make sure we are mapped back to the correct value...
	mapValueToDisplayValue();
	draw();
	return 0xffff;    // not on the button any more...
}
void OnTouchDownHandler(HWND hWnd, const TOUCHINPUT& ti)
{
    // Create a new stroke, add a point, and assign a color to it.
    CStroke strkNew;
	POINT p = GetTouchPoint(hWnd, ti); 
	
    strkNew.AddPoint(p);
    strkNew.SetColor(GetTouchColor((ti.dwFlags & TOUCHEVENTF_PRIMARY) != 0));
	strkNew.SetId(ti.dwID);

    // Add the new stroke to the collection of strokes being drawn.
    g_StrkColDrawing.AddStroke(strkNew);
}
Example #6
0
EXPLORER_BUTTON GetExplorerIndex(void)
{
	if(!GetTouchPoint())return 0;
	if(penPoint.y<20)return 0;
	else if(penPoint.y>20&&penPoint.y<220)
	{
		if(penPoint.x<360)return (penPoint.x-20)/25+1;
		else if(penPoint.y<60)return TURNUP;
		else if(penPoint.y>180)return TURNDOWN; 
	}
	else if(penPoint.x<40)return SELECT;
	else if(penPoint.x>360)return BACK;
	return 0;
}
// Handler for touch-move input.
// in:
//      hWnd        window handle
//      ti          TOUCHINPUT structure (info about contact)
void OnTouchMoveHandler(HWND hWnd, const TOUCHINPUT& ti)
{
    // Find the stroke in the collection of the strokes being drawn.
	int iStrk = g_StrkColDrawing.FindStrokeById(ti.dwID);

	POINT p = GetTouchPoint(hWnd, ti); 

    // Add the contact point to the stroke.
    g_StrkColDrawing[iStrk].AddPoint(p);

    // Partial redraw: redraw only the last line segment.
    HDC hDC = GetDC(hWnd);
    g_StrkColDrawing[iStrk].DrawLast(hDC);
    ReleaseDC(hWnd, hDC);
}
// Handler for touch-move message.
// in:
//      hWnd        window handle
//      ti          TOUCHINPUT structure (info about contact)
void OnTouchMoveHandler(HWND hWnd, const TOUCHINPUT& ti)
{
    // Extract contact info: contact ID
    int iCursorId = GetTouchContactID(ti);

    // Extract contact info: contact point
    POINT pt = GetTouchPoint(hWnd, ti);

    //Don't send move message if current move is the same as last move
    std::map<int, POINT>::iterator it = lastMoves.find(iCursorId);

    if (it != lastMoves.end())
    {
        if ( (pt.x != (it->second).x) || (pt.y != (it->second).y) )
        {
            sendAreaSize(hWnd, iCursorId, pt);
            WPARAM wParam = MAKEWPARAM(EX_TOUCH_EVENT_MOVE, iCursorId);
            LPARAM lParam = MAKELPARAM(pt.x & 0x0000ffff, pt.y & 0x0000ffff);
            //PostMessage(hWnd, WM_APP + 5, wParam, lParam);
            PostMessage(keyboardHandle, WM_APP + 5, wParam, lParam);
            lastMoves[iCursorId] = pt;
        }
    }
    else
    {
        sendAreaSize(hWnd, iCursorId, pt);
        WPARAM wParam = MAKEWPARAM(EX_TOUCH_EVENT_MOVE, iCursorId);
        LPARAM lParam = MAKELPARAM(pt.x & 0x0000ffff, pt.y & 0x0000ffff);
        //PostMessage(hWnd, WM_APP + 5, wParam, lParam);
        PostMessage(keyboardHandle, WM_APP + 5, wParam, lParam);
        lastMoves[iCursorId] = pt;
    }

    /*WPARAM wParam = MAKEWPARAM(EX_TOUCH_EVENT_MOVE, iCursorId);
    LPARAM lParam = MAKELPARAM(pt.x, pt.y);
    PostMessage(hWnd, WM_APP + 5, wParam, lParam);*/

    //trace("move\n");
}
Example #9
0
// Assumes that we got a button down event, we pass in the X, Y from this event and it will check to see if the coordinates
// are within the object and process it. If the up happens in the same object then we will return the object ID, else we will
//
uint16_t TFTButton::processTouch(uint16_t x, uint16_t y) {


    if (!((x >= _x) && (x <= (_x+_w)) && (y >= _y) && (y <= (_y+_h))))
        return 0xffff;        // Special value that says Not within the object...

    SetPressed(true);
    draw();    // Show it as depressed.

    // Now lets wait for the touch to release...
    while (ts.touched()) {
        GetTouchPoint(&x, &y);
    }

    SetPressed(false);
    draw();

    // And see if we were still inside the button
    if ((x >= _x) && (x <= (_x+_w)) && (y >= _y) && (y <= (_y+_h)))
        return _wVal;

    return 0xfffe;    // not on the button any more...
}