void GuiObject::touchesMoved(app::TouchEvent event){
    
    //Vec2f centroid;
    //int pntCnt=0;
    
        //Go Through all the touches in the event if the current touch is in the objects touch list then call the objects touches moved handler
        for( vector<TouchEvent::Touch>::const_iterator touchIt = event.getTouches().begin(); touchIt != event.getTouches().end(); ++touchIt ) {
            //If the touch object has current touches, check if they are in this event. if so move/reposition object based on the updated touches.
            auto found=std::find_if (currentObjTouches.begin(),currentObjTouches.end(), FindTouch(*touchIt));
            if(found!=currentObjTouches.end() ){//this touch id is touching this object
                touchesMovedHandler();
                event.setHandled();

                // centroid += touchIt->getPos();
               // pntCnt++;
            }
          
        }
    /*
    if(this->oCanMove){
        centroid/=pntCnt;//Get the center/average point of the touches
        if(currentObjTouches.size()>0 && !isNaN(centroid) ){
            oContainer.offsetCenterTo(centroid);
        }
    }
    if(currentObjTouches.size()>0 && !oSelected)  setSelected(true);
*/


}
	bool touchesBegan( app::TouchEvent &event )	override
	{
		vec2 pos = event.getTouches().front().getPos();
		event.getTouches().front().setHandled();
		vec2 localPos = toLocal( pos );

		CI_LOG_V( getLabel() << " local pos: " << localPos << ", world pos: " << getWorldPos() << ", event pos: " << pos );
		moveViewAnimated();

		return true;
	}
	bool touchesEnded( app::TouchEvent &event )		override
	{
		vec2 pos = event.getTouches().front().getPos();
		vec2 localPos = toLocal( pos );
		CI_LOG_V( getLabel() << " local pos: " << localPos << ", world pos: " << getWorldPos() << ", event pos: " << pos );

		return true;
	}
示例#4
0
bool SelectorBase::touchesBegan( app::TouchEvent &event )
{
	setTouchCanceled( false );
	auto &firstTouch = event.getTouches().front();
	vec2 pos = toLocal( firstTouch.getPos() );
	updateSelection( pos );
	firstTouch.setHandled();
	return true;
}
示例#5
0
bool TouchUi::isEventValid( const app::TouchEvent& event ) const
{
	if ( !mEnabled ) {
		return false;
	}
	const int32_t numTouches = (int32_t)event.getTouches().size();
	if ( numTouches < mNumTouchPointsMin || numTouches > mNumTouchPointsMax ) {
		return false;
	}
	return true;
}
void GuiObject::touchesBegan(app::TouchEvent event){

        //Go Through each touch object and check if this object contains the point
        for( vector<TouchEvent::Touch>::iterator touchIt = event.getTouches().begin(); touchIt != event.getTouches().end(); ++touchIt ) {
            
            //if this object contains the point and this is the object is not sitting below any other object;
            if( oContainer.contains( touchIt->getPos()) &&// does this object contain the touch point
                objectOrderList.at(getTopMostObject(touchIt->getPos())) == this //is the topmost object and the current object the same
                ){
                
                    // if this object is accepting touches add the touch to the obj's touch list
                    if(oIsAcceptingTouches){
                        currentObjTouches.push_back(*touchIt);
                         event.setHandled( true );
                    }
                }
        }

    if(currentObjTouches.size()>0)        touchesBeganHandler();

}
示例#7
0
bool SelectorBase::touchesEnded( app::TouchEvent &event )
{
	if( isTouchCanceled() )
		return false;

	vec2 pos = toLocal( event.getTouches().front().getPos() );
	if( ! hitTestInsideCancelPadding( pos ) ) {
		setTouchCanceled( true );
		return false;
	}

	updateSelection( pos );
	return true;
}
示例#8
0
void TouchUi::touchesEnded( app::TouchEvent& event )
{
	if ( !isEventValid( event ) ) {
		return;
	}

	if ( mEnabledTap && mTapTime > 0.0 ) {
		for ( const TouchEvent::Touch& touch : event.getTouches() ) {
			const vec2& tap = touch.getPos();
			if ( mMask.contains( tap ) && glm::distance( tap, mTapPosition ) < mTapThreshold ) {
				mTapPosition	= tap;
				mTapTime		= getElapsedSeconds();
				mTouches		= { touch };
				break;
			}
		}
	}
}
void GuiObject::touchesEnded(app::TouchEvent event){
    
    
        for( vector<TouchEvent::Touch>::const_iterator touchIt = event.getTouches().begin(); touchIt != event.getTouches().end(); ++touchIt ) {
            
            //if current touches vector contains the iterators touch id, remove it from the list, since it is no longer touching the object. If there are no more touches in the current object touches set then the object is no longer selected

            auto found=std::find_if (currentObjTouches.begin(),currentObjTouches.end(), FindTouch(*touchIt));
            
            //this touch id is touching this object
            if(found!=currentObjTouches.end()){
                currentObjTouches.erase(found);
                touchesEndedHandler();
            }
        }
        
   
    
}
示例#10
0
void TouchUi::touchesMoved( app::TouchEvent& event )
{
	if ( !isEventValid( event ) ) {
		return;
	}

	mTouches.clear();
	if ( mEnabledTap ) {
		bool tapped = false;
		for ( const TouchEvent::Touch& touch : event.getTouches() ) {
			const vec2& tap = touch.getPos();
			if ( mMask.contains( tap ) && glm::distance( tap, mTapPosition ) < mTapThreshold ) {
				tapped = true;
				pushTouch( touch );
				break;
			}
		}
		if ( !tapped ) {
			resetTap();
		}
	}
	
	const vec2 panSpeed( 
		mPanSpeed.x * pow( ( mScaleMax.x + mScaleMin.x ) - mScale.x, 0.0002f ), 
		mPanSpeed.y * pow( ( mScaleMax.y + mScaleMin.y ) - mScale.y, 0.0002f ) );

	bool applyPan		= false;
	bool applyRotation	= false;
	bool applyScale		= false;
	float panX			= 0.0f;
	float panY			= 0.0f;
	float scaleX		= 0.0f;
	float scaleY		= 0.0f;
	float rotation		= 0.0f;

	// Pan
	if ( mEnabledPan ) {
		for ( const TouchEvent::Touch& touch : event.getTouches() ) {
			const vec2 a( touch.getPos() );
			const vec2 b( touch.getPrevPos() );
			if ( mMask.contains( b ) ) {
				panX = a.x - b.x;
				panY = a.y - b.y;
				pushTouch( touch );
				break;
			}
		}
	}
	
	// Multi-touch
	TouchEvent::Touch a;
	TouchEvent::Touch b;
	size_t numTouches = event.getTouches().size();
	if ( numTouches > 1 && mNumTouchPointsMax > 1 ) {
		a = *event.getTouches().begin();
		b = *( event.getTouches().begin() + 1 );
		const vec2 ap0( a.getPos() );
		const vec2 ap1( a.getPrevPos() );
		const vec2 bp0( b.getPos() );
		const vec2 bp1( b.getPrevPos() );
		if ( mMask.contains( bp0 ) && mMask.contains( bp1 ) ) {

			// Scale
			if ( mEnabledScale ) {
				float dx0 = glm::distance( ap0.x, bp0.x );
				float dx1 = glm::distance( ap1.x, bp1.x );
				scaleX = dx0 - dx1;

				float dy0 = glm::distance( ap0.y, bp0.y );
				float dy1 = glm::distance( ap1.y, bp1.y );
				scaleY = dy0 - dy1;
			}

			// Rotation
			if ( mEnabledRotation ) {
				float a0 = atan2( ap0.y - bp0.y, ap0.x - bp0.x );
				float a1 = atan2( ap1.y - bp1.y, ap1.x - bp1.x );
				rotation = wrapAngle( a0 - a1 );
			}
		}
	}

	vector<Motion> motions = {
		{ MotionType_PanX, abs( panX ) / mPanThreshold.x },
		{ MotionType_PanY, abs( panY ) / mPanThreshold.y },
		{ MotionType_Rotation, abs( rotation ) / mRotationThreshold },
		{ MotionType_ScaleX, abs( scaleX ) / mScaleThreshold.x },
		{ MotionType_ScaleY, abs( scaleY ) / mScaleThreshold.y },
	};

	auto evaluateMotion = [ &applyPan, &applyRotation, &applyScale ]( const Motion& motion )
	{
		MotionType t = motion.first;
		if ( motion.second > 1.0f ) {
			if ( t == MotionType_PanX || t == MotionType_PanY ) {
				applyPan = true;
			} else if ( t == MotionType_Rotation ) {
				applyRotation = true;
			} else if ( t == MotionType_ScaleX || t == MotionType_ScaleY ) {
				applyScale = true;
			}
		}
	};

	if ( mEnabledConstrain ) {
		sort( motions.begin(), motions.end(), []( const Motion& a, const Motion& b ) -> bool
		{
			return a.second > b.second;
		} );
		evaluateMotion( *motions.begin() );
	} else {
		for ( const Motion& motion : motions ) {
			evaluateMotion( motion );
		}
	}
	
	if ( numTouches > 1 && ( applyPan || applyRotation || applyScale ) ) {
		pushTouch( a );
		pushTouch( b );
	}
	
	if ( applyPan ) {
		mPanTarget.x += panX * panSpeed.x;
		mPanTarget.y += panY * panSpeed.y;
	}
	if ( applyRotation ) {
		mRotationTarget.z += rotation * mRotationSpeed;
	}
	if ( applyScale ) {
		if ( mScaleSymmetry ) {
			mScaleTarget	+= vec2( ( scaleX * mScaleSpeed.x + scaleY * mScaleSpeed.y ) * 0.5f );
		} else {
			mScaleTarget	+= vec2( scaleX * mScaleSpeed.x, scaleY * mScaleSpeed.y );
		}
	}
}