//-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ ofTouchEventArgs t; t.x = x; t.y = y; t.id = button; touchUp(t); }
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; } }
int TouchInputHandler::ToTouchID(int windowsID, bool allowAllocate) { // Find the id for the touch. Avoid 0 (mouse.) for (int localId = 1; localId < (int)ARRAY_SIZE(touchIds); ++localId) { if (touchIds[localId] == windowsID) { return localId; } } // Allocate a new one, perhaps? if (allowAllocate) { for (int localId = 1; localId < (int)ARRAY_SIZE(touchIds); ++localId) { if (touchIds[localId] == 0) { touchIds[localId] = windowsID; return localId; } } // None were free. // TODO: Better to just ignore this touch instead? touchUp(0, 0, 0); return 0; } return -1; }
//-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ ofTouchEventArgs t; t.x = (float)x/ofGetWidth(); t.y = (float)y/ofGetHeight(); t.id = button; touchUp(t); }
//-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ interf.mouseReleased( x, y ); if (mouseToTouch) { touchUp(ofConvertMouseToTouch(x, y, button)); } isMouseDown = false; }
//-------------------------------------------------------------- bool GuiControl::_touchUp(int _x, int _y, int button){ if(!enabled) return false; over = hitTest(_x, _y); down = false; if(editing) { _touchMoved (_x, _y, button); } else { if(over) touchUp(_x, _y, button); } editState = EDIT_NONE; return over; }
void GestureDetector::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) { CC_UNUSED_PARAM(pEvent); CCPoint tTouchPoint; for (CCSetIterator iter = pTouches->begin(); iter != pTouches->end(); iter++) { CCTouch *touch = (CCTouch *) (*iter); if (mIgnoreProceeded && !touch->getProceeded()) { mCurrentTouch = touch; tTouchPoint = mCurrentTouch->getLocation(); mCurrentTouch->setProceeded(touchUp(tTouchPoint, mCurrentTouch->getID())); } } }
//determines whether the ball touches the brick //and takes the necessary action void whetherBallTouchesBrick(){ for(int i=0;i<20;i++){ for(int j=0;j<8;j++){ if(isBrick[i][j]==1&&b.cy<240){ int touchCx=abs(b.cx+5); int touchCy=abs(b.cy+5); int brickLeft=i*brickLen; int brickRight=brickLeft+brickLen; int brickUp=j*brickBred; int brickDown=brickUp+brickBred; if((touchCx==brickRight)&&(abs(b.upy-brickUp)<=abs(brickBred-b.radius)&&abs(b.downy-brickDown)<=abs(brickBred-b.radius))){ touchLeft(); isBrick[i][j]=0; } else if((touchCx==brickLeft)&&(abs(b.upy-brickUp)<=abs(brickBred-b.radius)&&abs(b.downy-brickDown)<=abs(brickBred-b.radius))){ touchRight(); isBrick[i][j]=0; } else if((touchCy==brickDown)&&(abs(b.leftx-brickLeft)<=abs(brickLen-b.radius)&&abs(b.rightx-brickRight)<=abs(brickLen-b.radius))){ touchUp(); isBrick[i][j]=0; } else if((touchCy==brickUp)&&(abs(b.leftx-brickLeft)<=abs(brickLen-b.radius)&&abs(b.rightx-brickRight)<=abs(brickLen-b.radius))){ touchDown(); isBrick[i][j]=0; } else if((abs(abs(b.cx)-brickLeft)+abs(abs(b.cx)-brickRight)==brickLen)&&(abs(abs(b.cy)-brickUp)+abs(abs(b.cy)-brickDown)==brickBred)){ touchCorner(); isBrick[i][j]=0; } if(isBrick[i][j]==0){ score=score+(10*abs(j-8)); setScoreString(); int brick[8]; setcolor(0); brick[0]=brick[6]=brickLeft; brick[1]=brick[3]=brickUp; brick[2]=brick[4]=brickRight; brick[5]=brick[7]=brickDown; setfillstyle(1,0); fillpoly(4,brick); rectangle(brick[0],brick[1],brick[2],brick[5]); drawBricks(); i=0,j=0; } } } } }
void ofxDraggable::touchMoved(ofTouchEventArgs &touch) { if (!touches.empty()) { vector<ofTouchEventArgs>::iterator iter; for (iter=touches.begin(); iter!=touches.end(); iter++) { if (iter->id == touch.id) { break; } } if (iter==touches.end()) { cout << "ofxDraggable::touchMoved - can't find touch" << endl; } else { switch (touches.size()) { case 1: if (inside(touch)) { mat.postMult(ofMatrix4x4::newTranslationMatrix(ofVec2f(touch.x,touch.y)-ofVec2f(iter->x,iter->y))); *iter = touch; } else { touchUp(touch); } break; case 2: { ofVec2f p2(touch.x,touch.y); ofVec2f p1(iter->x,iter->y); *iter = touch; ofTouchEventArgs &second = touches[1-distance(touches.begin(), iter)]; ofVec2f q(second.x,second.y); ofVec2f qp1 = q-p1; ofVec2f qp2 = q-p2; ofVec2f trans(0.5*(qp1-qp2)); float scl = qp2.length()/qp1.length(); float rot = (atan2(qp2.y, qp2.x)-atan2(qp1.y, qp1.x))*180.0f/PI; ofVec2f anchor = mat.getInverse().preMult(ofVec3f(0.5*(p1+q))); ofMatrix4x4 temp(mat); temp.preMult(ofMatrix4x4::newScaleMatrix(scl, scl, 1.0)); temp.preMult(ofMatrix4x4::newRotationMatrix(rot, ofVec3f(0,0,1.0))); ofVec2f vec = temp.preMult(ofVec3f(anchor))-mat.preMult(ofVec3f(anchor)); // cout << anchor <<"\t" << vec << "\t" << scl << endl; temp.postMult(ofMatrix4x4::newTranslationMatrix(trans-vec)); mat=temp; } break; default: break; } } } };
void ofxUICanvas::onTouchUp(ofTouchEventArgs &data) { touchUp(data); }
void TouchInputHandler::handleTouchEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if (hasTouch()){ UINT inputCount = LOWORD(wParam); TOUCHINPUT *inputs = new TOUCHINPUT[inputCount]; if (touchInfo((HTOUCHINPUT) lParam, inputCount, inputs, sizeof(TOUCHINPUT))) { for (UINT 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 { 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 = (int)(first_free - input_state.pointer_down) / (int)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); 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); } else { // GetLastError() and error handling. } delete [] inputs; } }
//-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ if (m_multitouch.isSetup()) return; touchUp(x,y,-1); }