void EndCopyWin(XParms xp, Parms p) { EndScroll(xp, p); free(segsa); free(segsb); }
void EndCopyWin(XParms xp, Parms p) { EndScroll(xp, p); free(segsa); free(segsb); if (segsa2) free (segsa2); if (segsb2) free (segsb2); segsa = segsb = segsa2 = segsb2 = NULL; }
void CMScrollLabel::OnTimer() { if ( m_nCurCount < m_nScrollCount ) { // if ( m_nMoveLength + m_nTextLen > 0 ) { // 继续移动 m_nMoveLength -= m_nMoveStep; Invalide(); } else { // 一次移动完毕 ++m_nCurCount; m_nMoveLength = m_nMoveStep; } } else { // 自动结束滚动 EndScroll(); } }
void UIScrollView::Input(UIEvent *currentTouch) { // if(currentTouch->tapCount == 2 && currentTouch->phase == UIControlTouch::PHASE_BEGAN) // { // float32 targetScale; // if(zoomScale < maxScale) // { // //zoom in // targetScale = maxScale; // } // else // { // targetScale = minScale; // } // LinearAnimation<float32> * scaleAnimation = new LinearAnimation<float32>(this, &zoomScale, targetScale, 0.5f, // Interpolation::EASY_IN_EASY_OUT); // scaleAnimation->Start(0); // // // { // float32 multScale = targetScale/zoomScale; // // if(targetScale < zoomScale) // { // LinearAnimation<float32> * xAnim = new LinearAnimation<float32>(this, &scrollOrigin.x, scrollZero.x, 0.5f, Interpolation::EASY_IN_EASY_OUT); // LinearAnimation<float32> * yAnim = new LinearAnimation<float32>(this, &scrollOrigin.y, scrollZero.y, 0.5f, Interpolation::EASY_IN_EASY_OUT); // xAnim->Start(1); // yAnim->Start(2); // } // else // { // Point2f adjPoint = Point2f(currentTouch->point.x*multScale, currentTouch->point.y*multScale); // Point2f delta = Point2f(adjPoint.x - currentTouch->point.x, adjPoint.y - currentTouch->point.y); // // LinearAnimation<float32> * xAnim = new LinearAnimation<float32>(this, &scrollOrigin.x, scrollOrigin.x-delta.x, 0.5f, Interpolation::EASY_IN_EASY_OUT); // LinearAnimation<float32> * yAnim = new LinearAnimation<float32>(this, &scrollOrigin.y, scrollOrigin.y-delta.y, 0.5f, Interpolation::EASY_IN_EASY_OUT); // // xAnim->Start(1); // yAnim->Start(2); // } // } // } // int32 saveState = state; Vector<UIEvent> touches = UIControlSystem::Instance()->GetAllInputs(); if(1 == touches.size()) { bool spaceIsPressed = InputSystem::Instance()->GetKeyboard()->IsKeyPressed(DVKEY_SPACE); // bool spaceIsPressed = false; if(!spaceIsPressed) { for(List<UIControl*>::iterator it = childs.begin(); it != childs.end(); ++it) { (*it)->Input(currentTouch); } return; } switch(currentTouch->phase) { case UIEvent::PHASE_BEGAN: { scrollTouch = *currentTouch; Vector2 start = currentTouch->point; StartScroll(start); // init scrolling speed parameters scrollPixelsPerSecond = 0.0f; scrollStartTime = currentTouch->timestamp;//to avoid cast from uint64 to float64 SystemTimer::Instance()->AbsoluteMS(); touchStartTime = SystemTimer::Instance()->AbsoluteMS(); state = STATE_SCROLL; clickStartPosition = start; } break; case UIEvent::PHASE_DRAG: { if(state == STATE_SCROLL) { if(currentTouch->tid == scrollTouch.tid) { // scrolling speed get parameters float64 scrollCurrentTime = currentTouch->timestamp;//SystemTimer::Instance()->AbsoluteMS(); Vector2 scrollPrevPosition = scrollCurrentPosition; // perform scrolling ProcessScroll(currentTouch->point); // calculate scrolling speed float64 tmp = scrollCurrentTime; if(fabs(scrollCurrentTime - scrollStartTime) < 1e-9) { tmp += .1f; } Vector2 lineLength = scrollCurrentPosition - scrollPrevPosition; scrollPixelsPerSecond = (float32)((float64)lineLength.Length() / (tmp - scrollStartTime)); scrollStartTime = scrollCurrentTime; ///NSLog(@"pps:%f\n", scrollPixelsPerSecond); } } } break; case UIEvent::PHASE_ENDED: { if(state == STATE_SCROLL) { if(currentTouch->tid == scrollTouch.tid) { Vector2 scrollPrevPos = lastMousePositions[(positionIndex - 3) & (MAX_MOUSE_POSITIONS - 1)]; Vector2 currentTouchPos = currentTouch->point; deccelerationSpeed = Vector2(currentTouchPos.x, currentTouchPos.y); deccelerationSpeed.x -= scrollPrevPos.x; deccelerationSpeed.y -= scrollPrevPos.y; float32 deccelerationSpeedLen = sqrtf(deccelerationSpeed.x * deccelerationSpeed.x + deccelerationSpeed.y * deccelerationSpeed.y); if (deccelerationSpeedLen >= 0.00001f) { deccelerationSpeed.x /= deccelerationSpeedLen; deccelerationSpeed.y /= deccelerationSpeedLen; } else { deccelerationSpeed.x = 0.0f; deccelerationSpeed.y = 0.0f; } //Logger::Debug("Dcs: %f, %f\n", deccelerationSpeed.x, deccelerationSpeed.y); EndScroll(); //scrollTouch = 0; if(scrollStartMovement) { state = STATE_DECCELERATION; } clickEndPosition = currentTouchPos; } if(touchStartTime) { touchStartTime = 0; PerformScroll(); } // float32 clickLen = LineLength(clickStartPosition, clickEndPosition); // if (clickLen < SCROLL_BEGIN_PIXELS) // { // clickEndPosition.x -= (scrollOrigin.x); // clickEndPosition.y -= (scrollOrigin.y); // // clickEndPosition.x /= zoomScale; // clickEndPosition.y /= zoomScale; // // UIControlTouch modifiedTouch = *currentTouch; // modifiedTouch.point = clickEndPosition; // // ScrollTouch(&modifiedTouch); // } } } break; } } else if(2 == touches.size()) { switch(currentTouch->phase) { case UIEvent::PHASE_BEGAN: { if (state == STATE_SCROLL) { EndScroll(); //scrollTouch = 0; } // init zoom parameters state = STATE_ZOOM; zoomTouches[0] = touches[0]; zoomTouches[1] = touches[1]; zoomStartPositions[0] = zoomTouches[0].point; zoomStartPositions[1] = zoomTouches[1].point; prevZoomScale = zoomScale; // save current scale to perform scaling in zoom mode } break; case UIEvent::PHASE_DRAG: if(state == STATE_ZOOM) { zoomTouches[0] = touches[0]; zoomTouches[1] = touches[1]; zoomCurrentPositions[0] = zoomTouches[0].point; zoomCurrentPositions[1] = zoomTouches[1].point; float initialDistance = sqrtf( (zoomStartPositions[0].x - zoomStartPositions[1].x) * (zoomStartPositions[0].x - zoomStartPositions[1].x) + (zoomStartPositions[0].y - zoomStartPositions[1].y) * (zoomStartPositions[0].y - zoomStartPositions[1].y)); float currentDistance = sqrtf( (zoomCurrentPositions[0].x - zoomCurrentPositions[1].x) * (zoomCurrentPositions[0].x - zoomCurrentPositions[1].x) + (zoomCurrentPositions[0].y - zoomCurrentPositions[1].y) * (zoomCurrentPositions[0].y - zoomCurrentPositions[1].y)); float32 saveZoomScale = zoomScale; float32 changeCoeff = initialDistance/currentDistance; float32 newScale = prevZoomScale * ((1.f - changeCoeff)/2.5f + 1.f); //float32 changeCoeff = currentDistance/initialDistance; //float32 newScale = prevZoomScale * changeCoeff * changeCoeff; if(newScale > maxScale)newScale = maxScale; if(newScale < minScale)newScale = minScale; SetScale(newScale); Vector2 center = Vector2((zoomStartPositions[0].x + zoomStartPositions[1].x) / 2, (zoomStartPositions[0].y + zoomStartPositions[1].y) / 2); Vector2 scaleVectorOriginal = Vector2(center.x - scrollOrigin.x, center.y - scrollOrigin.y); Vector2 scaleVectorNew = scaleVectorOriginal; scaleVectorNew.x *= zoomScale / saveZoomScale; scaleVectorNew.y *= zoomScale / saveZoomScale; scaleVectorNew.x -= scaleVectorOriginal.x; scaleVectorNew.y -= scaleVectorOriginal.y; scrollOrigin.x -= scaleVectorNew.x; scrollOrigin.y -= scaleVectorNew.y; } break; case UIEvent::PHASE_ENDED: { Vector<UIEvent>::iterator it = touches.begin(); bool zoomToScroll = false; for(; it != touches.end(); ++it) { if((*it).phase == UIEvent::PHASE_DRAG) { zoomToScroll = true; scrollTouch = *it; } } if(zoomToScroll) { //scrollTouch = *it; Vector2 start = scrollTouch.point; StartScroll(start); state = STATE_SCROLL; //zoomTouches[0] = 0; //zoomTouches[1] = 0; } else { if (state != STATE_DECCELERATION) { state = STATE_NONE; } } } break; } } // if (saveState == state) // { // Logger::Debug("event: %d prevState: %d resultState: %d - alltouches: %d", currentTouch->phase, saveState, state, touches.size()); // }else // Logger::Debug("CHANGED: event: %d prevState: %d resultState: %d - alltouches: %d", currentTouch->phase, saveState, state, touches.size()); }