Beispiel #1
0
void Mortar::render()
{
    Vector4 UVs{
        (float)(direction) * 8 / pTexture->getSizef().x,
        0,
        (float)(direction + 1) * 8 / pTexture->getSizef().x,
        8 / pTexture->getSizef().y
    };

    OSB->drawSpriteWithUVs(pTexture, getSnapPos(), UVs, Color::White, 0, UNIT_SCALE);
}
Beispiel #2
0
			void ScrollView::eventEnded( int id, ci::vec2 pos )
			{
				if( id == mEventId ) {
					ci::vec2 accel = pos - mPrevEventPos;

					// Get normalized based on maximum distance you can scroll
					// Maybe should be based on the size of this view vs window?
					accel = accel / ci::vec2( ci::app::getWindowSize() );

					// Get the direction then set accel to an abs value for mapping
					ci::vec2 direction( accel.x < 0 ? -1 : 1, accel.y < 0 ? -1 : 1 );
					accel = ci::vec2( fabs( accel.x ), fabs( accel.y ) );

					// Calculate how far to throw
					ci::vec2 maxThrowDistance = getSize() * ci::vec2( 2.0 );
					ci::vec2 throwDistance = ci::lmap<ci::vec2>( accel, ci::vec2( 0.0f ), ci::vec2( mMaxAccel ), ci::vec2( 0.0f ), maxThrowDistance );

					// Apply direction to throw distance
					throwDistance *= direction;

					// Set our target pos, considering snapping so we don't throw out of the view
					ci::vec2 targetPos = mContentView->getPosition() + throwDistance;

					mScrollTargetPos = getSnapPos( targetPos );
					
					/*
					ci::app::console() << "----------------------------------------" << std::endl;
					ci::app::console() << "Pos: " << pos << std::endl;
					ci::app::console() << "Prev Pos: " << mPrevEventPos << std::endl;
					ci::app::console() << "Direction: " << direction << std::endl;
					ci::app::console() << "Throw Distance: " << throwDistance << std::endl;
					ci::app::console() << "Scroll View Content Size: " << mContentView->getSize() << std::endl;
					*/
					
					// Cleanup
					mIsScrolling = false;
					mEventId = -1;

					if( !mDelegate.expired() ) {
						ScrollViewRef self = std::dynamic_pointer_cast<ScrollView>( shared_from_this() );
						mDelegate.lock()->didFinishScrolling( self );
					}
				}
			}