void SmoothScroll::Update()
{
	if( m_touchManager->GetSwipeDirection() != TouchManager::SD_NONE )
	{
		const double distance = m_touchManager->GetSwipe()->m_delta.GetLength() * s_lengthFactor;
		const uint64 duration = static_cast< uint64 >( distance * s_durationFactor );

		StartScroll( m_touchManager->GetSwipeDirection(), distance * s_distanceDecrease * s_timeCoef, duration ); 
		
		m_touchManager->ResetSwipeDirection();
	}

	if( m_isActive )
	{
		const uint64 currentTime = s3eTimerGetMs() - m_startTime;

		if( currentTime <= m_duration )
		{
			if( currentTime >= m_duration * s_percentOfSmoothingStart )
			{
				m_distance = ( m_duration - currentTime ) * s_distanceDecrease;
			}

			switch( m_direction )
			{
			case TouchManager::SD_LEFT:
				{
					m_stepX = m_distance;
				}	
				break;
			case TouchManager::SD_RIGHT:
				{
					m_stepX = -m_distance;
				}	
				break;
			case TouchManager::SD_UP:
				{
					m_stepY = m_distance;
				}
				break;
			case TouchManager::SD_DOWN:
				{
					m_stepY = -m_distance;
				}
				break;
			}
		}
		else
		{
			StopScroll();
		}
	}
}
Example #2
0
bool MediaApplication::Start() {
	Logger::Default()->SetLevel(Logger::LOG_INFO);

	//初始化环境
	StartInitialize();

	if (type == "media") {
		rateInfo = new NetInformation(Config::GetHost(), Config::GetPort(),
				Config::GetUrl() + "?method=getRate&id=" + id, 4096);
		scrollInfo = new NetInformation(Config::GetHost(), Config::GetPort(),
				Config::GetUrl() + "?method=getRoll&id=" + id, 4096);
		ratefrequency = new NetInformation(Config::GetHost(), Config::GetPort(),
				Config::GetUrl() + "?method=getFrequency&id=" + id, 4096);

		//播放利率牌
		StartRate();

		//播放滚动条
		StartScroll();
	}

	//开始执行任务
	StartCommand();

	//打开谷歌浏览器
	void* h = StartChrome();

	//列出机器上的文件,传回给服务器,服务器会通知删除所有过期的文件
	this->Receive("S:f6f2a76c-bf34-4cc7-adba-8d2ab99d0fba");

	Sleep(5000);
	keybd_event(VK_F5, 0, 0, 0);
	keybd_event(VK_F5, 0, KEYEVENTF_KEYUP, 0);

	//列出机器上的任务,传回给服务器,服务器会通知删除所有过期的任务
	this->Receive("S:f6f2a76c-bf34-4cc7-adba-8d2ab99d0fbb");

	WaitForSingleObject(h, INFINITE);

	return true;
}
void ScrollLabelEx::OnPauseTimeOut()
{
    StartScroll();
}
void ScrollLabelEx::SetText(const QString& text)
{
    ui->textlabel->setText(text);
    StartScroll();
}
Example #5
0
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());
}