void NavigationBarObject::touchesBeganHandler(){
//    console()<<"NavBar touch BEGIN Handler"<<endl;
//    console()<<"NavBar has TOuches "<< GuiObject::currentObjTouches.size() <<endl;
//    
    
    GuiObject *selectedObj=NULL;
    
    //Test the point if there is a child object that contains it
    for(int t =0;t<GuiObject::currentObjTouches.size();++t){
        TouchEvent::Touch curTouch = GuiObject::currentObjTouches.at(t);
        
        //Test each Child if there are touch points in their container
        for(int i=0;i< nbChildren.size();i++){
            GuiObject *curObj = nbChildren.at(i);
            if(curObj->containerHasPoint(curTouch.getPos()) && !curObj->isSelected()){
                selectedObj=curObj;
                touchCountMap[curObj]++;

                //get out of these loops
                break;break;
            }
        }
    }
    
    if(selectedObj){
        //go through the other children and unselect them
        for(int i=0;i< nbChildren.size();i++){
            // if this is not the selected object unselect it
            if(nbChildren.at(i)!=selectedObj) nbChildren.at(i)->setSelected(false,true);
        }
        
        //set the new object to selected
        selectedObj->setSelected(true);
    }
}
Example #2
0
void PhotoBoothApp::touchesBegan( TouchEvent event ){

    TouchEvent::Touch touch = event.getTouches().front();
    Vec2f cameraButtonTargetPos = Vec2f(mCameraButtonPos.value());
    
    float touchX = touch.getX() / DISPLAY_SCALE;
    float touchY = touch.getY() / DISPLAY_SCALE;
    
    switch(mCurrentState) {
        case STATE_PREVIEW:
        
            // see if the camera icon has been tapped (touch coordinates are reversed for landscape mode)
            
            cameraButtonTargetPos.x += mCameraButtonTexture.getWidth() / 2.0f;
            cameraButtonTargetPos.y += mCameraButtonTexture.getHeight() / 2.0f;
            
            if( cameraButtonTargetPos.distance( Vec2f(touchX, touchY) ) < (mCameraButtonTexture.getWidth() * 2) ) {
               mCountDownStartTime = getElapsedSeconds();
               mCurrentState = STATE_COUNT_DOWN;
            }
        
        break;

        case STATE_COUNT_DOWN:
            // stub..
        break;
        
        case STATE_ACCEPT:
            
            if(touchY > 1280) { // only look for touches near the bottom of the screen.
                
                // just split the screen in half, no need to do precise hit detection for save/cancel buttons..
                if(touchX > width / 2){
                    
                    ip::flipVertical( &mCameraSurface );
                    cinder::cocoa::SafeUiImage img = cocoa::createUiImage( mCameraSurface );
                    
                    
                    // Call into objective C to do upload via cocoa
                    FileSender::sendFile(img);

                    
                    timeline().apply( &mPreviewTexturePos, Vec2f(0, -height ), 1.0f, EaseInCubic() );
                    
                }else{
                    timeline().apply( &mPreviewTexturePos, Vec2f(0, height ), 1.0f, EaseInBack() );
                }
                
                mCurrentState = STATE_PREVIEW;
                
                timeline().apply( &mDarkBgAlpha, 0.0f, 1.0f, EaseInCubic() );
                
                // Hide buttons
                timeline().apply( &mDiscardPos, Vec2f(100, height + 100 ), 1.0f, EaseInCubic() );
                timeline().apply( &mSavePos, Vec2f(width-700, height + 100 ), 1.0f, EaseInCubic() );
            }
        break;
    }
}
Example #3
0
void TouchUi::pushTouch( const TouchEvent::Touch& touch )
{
	mTouchTime = getElapsedSeconds();
	bool found = false;
	for ( const TouchEvent::Touch& iter : mTouches ) {
		if ( iter.getId() == touch.getId() ) {
			found = true;
		}
	}
	if ( !found ) {
		mTouches.push_back( touch );
	}
}
Example #4
0
bool UiLayer::touchBegan( TouchEvent::Touch touch )
{
	mHasPanelBeenDragged = false;

	Vec2f touchPos = globalToLocal( touch.getPos() );

    mIsPanelTabTouched = mPanelTabRect.contains( touchPos );
    
	if( mIsPanelTabTouched ){
        // remember touch offset for accurate dragging
		mPanelTabTouchOffset = mPanelTabRect.getUpperLeft() - touchPos;
	}
		
	return mIsPanelTabTouched;
}
Example #5
0
bool UiLayer::touchMoved( TouchEvent::Touch touch )
{
	Vec2f touchPos = globalToLocal( touch.getPos() );
    
	if( mIsPanelTabTouched ){
		mHasPanelBeenDragged = true;

        // apply the touch pos and offset
        Vec2f newPos = touchPos + mPanelTabTouchOffset;
        mPanelY += newPos.y - mPanelTabRect.y1;
		
		const float maxPanelY = mInterfaceSize.y - getPanelHeight();
		mPanelY = constrain( mPanelY, maxPanelY, mPanelClosedY );
	}

	return mIsPanelTabTouched;
}
Example #6
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 );
		}
	}
}
Example #7
0
bool ScrollingLabel::touchBegan( TouchEvent::Touch touch )
{
    return mRect.contains( globalToLocal( touch.getPos() ) );
}