Fixed ScrollableContainer clipping.

Changed game select effect to interpolate more interestingly.
This commit is contained in:
Aloshi 2013-08-06 22:46:25 -05:00
parent 541d9a62d1
commit 55b71fab49
4 changed files with 38 additions and 8 deletions

View file

@ -78,6 +78,7 @@ Font::Font(const ResourceManager& rm, const std::string& path, int size) : fontS
Font::~Font()
{
LOG(LogInfo) << "Destroying font \"" << mPath << "\" with size " << mSize << ".";
deinit();
}
@ -238,14 +239,14 @@ void Font::buildAtlas(ResourceData data)
if((y + maxHeight) >= textureHeight)
{
//failed to create a proper font texture
LOG(LogWarning) << "Font with size " << mSize << " exceeded max texture size! Trying again...";
LOG(LogWarning) << "Font \"" << mPath << "\" with size " << mSize << " exceeded max texture size! Trying again...";
//try a 3/4th smaller size and redo initialization
fontScale *= 1.25f;
mSize = (int)(mSize * (1.0f / fontScale));
deinit();
init(data);
}else{
LOG(LogInfo) << "Created font with size " << mSize << ".";
LOG(LogInfo) << "Created font \"" << mPath << "\" with size " << mSize << ".";
}
}

View file

@ -442,15 +442,35 @@ Eigen::Vector2f lerpVector2f(const Eigen::Vector2f& start, const Eigen::Vector2f
return (start * (1 - t) + end * t);
}
float clamp(float min, float max, float val)
{
if(val < min)
val = min;
else if(val > max)
val = max;
return val;
}
//http://en.wikipedia.org/wiki/Smoothstep
float smoothStep(float edge0, float edge1, float x)
{
// Scale, and clamp x to 0..1 range
x = clamp(0, 1, (x - edge0)/(edge1 - edge0));
// Evaluate polynomial
return x*x*x*(x*(x*6 - 15) + 10);
}
void GuiGameList::updateGameLaunchEffect(int t)
{
const int endTime = mGameLaunchEffectLength;
const int zoomTime = endTime;
const int centerTime = endTime - 100;
const int centerTime = endTime - 50;
const int fadeDelay = endTime - 500;
const int fadeTime = endTime - fadeDelay;
const int fadeDelay = endTime - 600;
const int fadeTime = endTime - fadeDelay - 100;
Eigen::Vector2f imageCenter(mScreenshot.getCenter());
if(!isDetailed())
@ -460,8 +480,11 @@ void GuiGameList::updateGameLaunchEffect(int t)
const Eigen::Vector2f centerStart(Renderer::getScreenWidth() / 2, Renderer::getScreenHeight() / 2);
mWindow->setCenterPoint(lerpVector2f(centerStart, imageCenter, (float)t / endTime));
mWindow->setZoomFactor(lerpFloat(1.0f, 2.0f, (float)t / endTime));
//remember to clamp or zoom factor will be incorrect with a negative t because squared
const float tNormalized = clamp(0, 1, (float)t / endTime);
mWindow->setCenterPoint(lerpVector2f(centerStart, imageCenter, smoothStep(0.0, 1.0, tNormalized)));
mWindow->setZoomFactor(lerpFloat(1.0f, 3.0f, tNormalized*tNormalized));
mWindow->setFadePercent(lerpFloat(0.0f, 1.0f, (float)(t - fadeDelay) / fadeTime));
if(t > endTime)

View file

@ -12,7 +12,9 @@ void ScrollableContainer::render(const Eigen::Affine3f& parentTrans)
Eigen::Affine3f trans = parentTrans * getTransform();
Eigen::Vector2i clipPos((int)trans.translation().x(), (int)trans.translation().y());
Eigen::Vector2i clipDim((int)mSize.x(), (int)mSize.y());
Eigen::Vector3f dimScaled = trans * Eigen::Vector3f(mSize.x(), mSize.y(), 0);
Eigen::Vector2i clipDim((int)dimScaled.x() - trans.translation().x(), (int)dimScaled.y() - trans.translation().y());
Renderer::pushClipRect(clipPos, clipDim);

View file

@ -214,6 +214,10 @@ int main(int argc, char* argv[])
int deltaTime = curTime - lastTime;
lastTime = curTime;
//cap deltaTime at 1000
if(deltaTime > 1000 || deltaTime < 0)
deltaTime = 1000;
window.update(deltaTime);
Renderer::swapBuffers(); //swap here so we can read the last screen state during updates (see ImageComponent::copyScreen())
window.render();