Пример #1
0
void 
RotateScreen::preparePaint (int msSinceLastPaint)
{
    float oldXrot = mXrot + mBaseXrot;

    if (mGrabIndex || mMoving)
    {
	float amount = msSinceLastPaint * 0.05f * optionGetSpeed ();
	int   steps  = amount / (0.5f * optionGetTimestep ());

	if (!steps)
	    steps = 1;

	float chunk  = amount / (float) steps;

	while (steps--)
	{
	    mXrot += mXVelocity * chunk;
	    mYrot += mYVelocity * chunk;

	    if (mXrot > 360.0f / screen->vpSize ().width ())
	    {
		mBaseXrot += 360.0f / screen->vpSize ().width ();
		mXrot     -= 360.0f / screen->vpSize ().width ();
	    }
	    else if (mXrot < 0.0f)
	    {
		mBaseXrot -= 360.0f / screen->vpSize ().width ();
		mXrot     += 360.0f / screen->vpSize ().width ();
	    }

	    if (cubeScreen->invert () == -1)
	    {
		if (mYrot > 45.0f)
		{
		    mYVelocity = 0.0f;
		    mYrot      = 45.0f;
		}
		else if (mYrot < -45.0f)
		{
		    mYVelocity = 0.0f;
		    mYrot      = -45.0f;
		}
	    }
	    else
	    {
		if (mYrot > 100.0f)
		{
		    mYVelocity = 0.0f;
		    mYrot      = 100.0f;
		}
		else if (mYrot < -100.0f)
		{
		    mYVelocity = 0.0f;
		    mYrot      = -100.0f;
		}
	    }

	    if (mGrabbed)
	    {
		mXVelocity /= 1.25f;
		mYVelocity /= 1.25f;

		if (fabs (mXVelocity) < 0.01f)
		    mXVelocity = 0.0f;

		if (fabs (mYVelocity) < 0.01f)
		    mYVelocity = 0.0f;
	    }
	    else if (adjustVelocity (screen->vpSize ().width (), cubeScreen->invert ()))
	    {
		mXVelocity = 0.0f;
		mYVelocity = 0.0f;

		if (fabs (mYrot) < 0.1f)
		{
		    CompOption::Vector o (0);
		    int                tx;
		    float              xrot = mBaseXrot + mXrot;

		    if (xrot < 0.0f)
			tx = (screen->vpSize ().width () * xrot / 360.0f) - 0.5f;
		    else
			tx = (screen->vpSize ().width () * xrot / 360.0f) + 0.5f;

		    /* flag end of rotation */
		    cubeScreen->rotationState (CubeScreen::RotationNone);

		    screen->moveViewport (tx, 0, true);

		    mBaseXrot = mMoveTo = mXrot = mYrot = 0.0f;
		    mMoving   = false;

		    if (mGrabIndex)
		    {
			screen->removeGrab (mGrabIndex, &mSavedPointer);
			mGrabIndex = 0;
		    }

		    if (mMoveWindow)
		    {
			CompWindow *w = screen->findWindow (mMoveWindow);

			if (w)
			    w->move (mMoveWindowX - w->x (), 0);
		    }
		    /* only focus default window if switcher isn't active */
		    else if (!screen->grabExist ("switcher"))
			screen->focusDefaultWindow ();

		    mMoveWindow = 0;

		    screen->handleCompizEvent ("rotate", "end_viewport_switch", o);
		}
		break;
	    }
	}

	if (mMoveWindow)
	{
	    CompWindow *w = screen->findWindow (mMoveWindow);

	    if (w)
	    {
		float xrot = (screen->vpSize ().width () * (mBaseXrot + mXrot)) / 360.0f;
		w->moveToViewportPosition (mMoveWindowX - xrot * screen->width (),
					   w->y (), false);
	    }
	}
    }

    if (mMoving)
    {
	if (fabs (mXrot + mBaseXrot + mMoveTo) <= 180 / screen->vpSize ().width ())
	    mProgress = fabs (mXrot + mBaseXrot + mMoveTo) /
			180 / screen->vpSize ().width ();
	else if (fabs (mXrot + mBaseXrot) <= 180 / screen->vpSize ().width ())
	    mProgress = fabs (mXrot + mBaseXrot) /
			180 / screen->vpSize ().width ();
	else
	{
	    mProgress += fabs (mXrot + mBaseXrot - oldXrot) /
			 180 / (screen->vpSize ().width ());
	    mProgress = MIN (mProgress, 1.0);
	}
    }
    else if (mProgress != 0.0f || mGrabbed)
    {
	float amount = msSinceLastPaint * 0.05f * optionGetSpeed ();
	int   steps  = amount / (0.5f * optionGetTimestep ());

	if (!steps)
	    steps = 1;

	float chunk  = amount / (float) steps;

	while (steps--)
	{
	    float dt;

	    if (mGrabbed)
		dt = 1.0 - mProgress;
	    else
		dt = 0.0f - mProgress;

	    float adjust  = dt * 0.15f;
	    float tamount = fabs (dt) * 1.5f;

	    if (tamount < 0.2f)
		tamount = 0.2f;
	    else if (tamount > 2.0f)
		tamount = 2.0f;

	    mProgressVelocity = (tamount * mProgressVelocity + adjust) /
				(tamount + 1.0f);

	    mProgress += mProgressVelocity * chunk;

	    if (fabs (dt) < 0.01f && fabs (mProgressVelocity) < 0.0001f)
	    {
		if (mGrabbed)
		    mProgress = 1.0f;
		else
		    mProgress = 0.0f;

		break;
	    }
	}
    }

    if (cubeScreen->invert () == 1 && !cubeScreen->unfolded ())
	mZoomTranslate = optionGetZoom () * mProgress;
    else
	mZoomTranslate = 0.0;

    cScreen->preparePaint (msSinceLastPaint);
}