Skip to content

Instantly share code, notes, and snippets.

@Vavius
Created February 21, 2014 13:50
Show Gist options
  • Save Vavius/9134546 to your computer and use it in GitHub Desktop.
Save Vavius/9134546 to your computer and use it in GitHub Desktop.
//----------------------------------------------------------------//
void MOAITouchSensor::HandleEvent ( ZLStream& eventStream ) {
u32 eventType = eventStream.Read < u32 >( 0 );
if ( eventType == TOUCH_CANCEL ) {
this->Clear ();
if ( this->mCallback && this->mAcceptCancel ) {
MOAIScopedLuaState state = this->mCallback.GetSelf ();
lua_pushnumber ( state, eventType );
state.DebugCall ( 1, 0 );
}
}
else {
MOAITouch touch;
touch.mState = 0;
touch.mTouchID = eventStream.Read < u32 >( 0 );
touch.mX = eventStream.Read < float >( 0.0f );
touch.mY = eventStream.Read < float >( 0.0f );
touch.mTime = eventStream.Read < float >( 0.0f );
touch.mTapCount = 0;
u32 idx = this->FindTouch ( touch.mTouchID );
if ( eventType == TOUCH_DOWN ) {
if ( idx == UNKNOWN_TOUCH || (this->mTouches [ idx ].mState & UP) == UP ) { // force add new touch if found touch has UP state
idx = this->AddTouch ();
if ( idx == UNKNOWN_TOUCH ) return;
touch.mTapCount = CheckLingerList ( touch.mX, touch.mY, touch.mTime ) + 1;
touch.mState = IS_DOWN | DOWN;
}
else {
if ( idx == UNKNOWN_TOUCH ) return;
touch.mState = this->mTouches [ idx ].mState | IS_DOWN;
touch.mTapCount = this->mTouches [ idx ].mTapCount;
eventType = TOUCH_MOVE;
}
}
else {
MOAITouchLinger linger;
linger.mX = this->mTouches [ idx ].mX;
linger.mY = this->mTouches [ idx ].mY;
linger.mTapCount = this->mTouches [ idx ].mTapCount;
linger.mTime = this->mTouches [ idx ].mTime;
this->AddLingerTouch ( linger );
touch.mState &= ~IS_DOWN;
touch.mState |= UP;
touch.mTouchID = 0;
touch.mTapCount = CheckLingerList ( touch.mX, touch.mY, touch.mTime );
}
if ( idx != UNKNOWN_TOUCH ) {
this->mTouches [ idx ] = touch;
if (( idx != UNKNOWN_TOUCH ) && ( this->mCallback )) {
MOAIScopedLuaState state = this->mCallback.GetSelf ();
lua_pushnumber ( state, eventType );
lua_pushnumber ( state, idx );
lua_pushnumber ( state, touch.mX );
lua_pushnumber ( state, touch.mY );
lua_pushnumber ( state, touch.mTapCount );
state.DebugCall ( 5, 0 );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment