i’ve hacked a bit the fadeOutProxyComponent to make a component fadein…
[code]//==============================================================================
class FadeInProxyComponent : public Component,
public Timer
{
public:
FadeInProxyComponent (Component* comp,
const int fadeLengthMs,
const int deltaXToMove,
const int deltaYToMove,
const float scaleFactorAtStart)
: lastTime (0),
alpha (0.0f),
scale (scaleFactorAtStart),
component(comp)
{
image = comp->createComponentSnapshot (Rectangle (0, 0, comp->getWidth(), comp->getHeight()));
Rectangle initialBounds = comp->getBounds();
initialBounds.translate(deltaXToMove,deltaYToMove);
setBounds(initialBounds);
comp->getParentComponent()->addAndMakeVisible (this);
comp->toBehind (this);
alphaChangePerMs = 1.0f / (float)fadeLengthMs;
centreX = comp->getX() + comp->getWidth() * 0.5f + deltaXToMove;
xChangePerMs = - deltaXToMove / (float)fadeLengthMs;
centreY = comp->getY() + comp->getHeight() * 0.5f + deltaYToMove;
yChangePerMs = - deltaYToMove / (float)fadeLengthMs;
scaleChangePerMs = (1.0f - scaleFactorAtStart) / (float)fadeLengthMs;
setInterceptsMouseClicks (false, false);
// 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
}
~FadeInProxyComponent()
{
delete image;
}
void paint (Graphics& g)
{
g.setOpacity (alpha);
g.drawImage (image,
0, 0, getWidth(), getHeight(),
0, 0, image->getWidth(), image->getHeight());
}
void timerCallback()
{
const uint32 now = Time::getMillisecondCounter();
if (lastTime == 0)
lastTime = now;
const int msPassed = now - lastTime;
lastTime = now;
alpha += alphaChangePerMs * msPassed;
if (alpha < 1)
{
if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
{
centreX += xChangePerMs * msPassed;
centreY += yChangePerMs * msPassed;
scale += scaleChangePerMs * msPassed;
const int w = roundFloatToInt (image->getWidth() * scale);
const int h = roundFloatToInt (image->getHeight() * scale);
setBounds (roundFloatToInt (centreX) - w / 2,
roundFloatToInt (centreY) - h / 2,
w, h);
}
repaint();
}
else
{
component->toFront(false);
component->setVisible(true);
delete this;
}
}
juce_UseDebuggingNewOperator
private:
Component* component;
Image* image;
uint32 lastTime;
float alpha, alphaChangePerMs;
float centreX, xChangePerMs;
float centreY, yChangePerMs;
float scale, scaleChangePerMs;
FadeInProxyComponent (const FadeInProxyComponent&);
const FadeInProxyComponent& operator= (const FadeInProxyComponent&);
};
void Component::fadeInComponent (const int millisecondsToFade,
const int deltaXToMove,
const int deltaYToMove,
const float scaleFactorAtStart)
{
//xxx won’t work for comps without parents
if (!isShowing() && millisecondsToFade > 0)
new FadeInProxyComponent (this, millisecondsToFade,
deltaXToMove, deltaYToMove, scaleFactorAtStart);
}
[/code]
i hope it will be added in the next juce release