Fading GUI
by Gavin Beard · in Torque Game Builder · 07/02/2008 (12:34 pm) · 7 replies
Hi all
is there a way to fade gui's in and out? i dont like the way they just 'pop' onto screen at the moment?
many thanks
is there a way to fade gui's in and out? i dont like the way they just 'pop' onto screen at the moment?
many thanks
#2
In dg/dgl.h add the following above dglSetBitmapModulation()
In dgl/dgl.cc add the following inside the anonymous namespace below "RectI sgCurerntClipRect;"
In gui/containers/guiWindowCtrl.h, add the following member variables below "S32 mTabIndex"
In gui/containers/guiWindowCtrl.cc, add the following initialization in the constructor "GuiWindowCtrl::GuiWindowCtrl()" below "mProcessMinimize = false;"
NOW WHAT?
Simply add a "fadeInMillis = 250;" inside the GuiWindowCtrl() when you build it. In the example I just game, the window fades in full at one-quarter of a second.
I think this could be adapted to a new class (GuiFadeInControl?) that you could wrap any GUI with (much like a GuiWindowCtrl is often wrapped by a GuiControl now).
I hope this helps! If you have any questions or problems (I think I've got it all here, but who really knows), feel free to ask for help.
08/11/2008 (8:24 pm)
I've come up with a way to fade in and out windows that requires minimal code changes.In dg/dgl.h add the following above dglSetBitmapModulation()
void dglSetFixedAlpha( F32 v );
In dgl/dgl.cc add the following inside the anonymous namespace below "RectI sgCurerntClipRect;"
F32 sgFixedAlpha = 1;and this above dglSetBitmapModulation()
void dglSetFixedAlpha( F32 v )
{
sgFixedAlpha = v;
}and in dglSetBitmapModulation(), add this below "c.clamp();"c.alpha = sgFixedAlpha;and in dglClearBitmapModulation(), replace the code with
sg_bitmapModulation.set( 255, 255, 255, sgFixedAlpha * 255 );and, finally, in dglSetTextAnchorColor(), add this below "c.clamp();"
c.alpha = sgFixedAlpha;
In gui/containers/guiWindowCtrl.h, add the following member variables below "S32 mTabIndex"
bool mProcessFade; S32 mFadeInMillis; S32 mStartTime;
In gui/containers/guiWindowCtrl.cc, add the following initialization in the constructor "GuiWindowCtrl::GuiWindowCtrl()" below "mProcessMinimize = false;"
mFadeInMillis = 0; mStartTime = 0; mProcessFade = false;and at the end of ::initPersistFields()
addField("fadeInMillis", TypeS32, Offset(mFadeInMillis, GuiWindowCtrl));and at the end of ::onWake(), before the "return true;"if( mFadeInMillis > 0 )
{
mProcessFade = true;
mStartTime = Platform::getRealMilliseconds();
}and at the end of ::onSleep()mProcessFade = false;and at the top of ::onRender(), just after the "if( !mProfile..." statement
// Fix the alpha
if( mProcessFade == true )
{
F32 alpha = (F32)(Platform::getRealMilliseconds() - mStartTime) / (F32)mFadeInMillis;
if( alpha < 0 )
alpha = 0;
else if( alpha > 1 )
{
alpha = 1.0;
mProcessFade = false;
}
dglSetFixedAlpha( alpha );
}and, finally, at the very end of the same functionif( mProcessFade == true ) dglSetFixedAlpha( 1.0 );
NOW WHAT?
Simply add a "fadeInMillis = 250;" inside the GuiWindowCtrl() when you build it. In the example I just game, the window fades in full at one-quarter of a second.
I think this could be adapted to a new class (GuiFadeInControl?) that you could wrap any GUI with (much like a GuiWindowCtrl is often wrapped by a GuiControl now).
I hope this helps! If you have any questions or problems (I think I've got it all here, but who really knows), feel free to ask for help.
#3
In dglSetBitmapModulation()
08/11/2008 (9:27 pm)
A quick change. The above will force alpha to 1.0, even if it is set below that. A simple fix, though:In dglSetBitmapModulation()
{
ColorF c = in_rColor;
c.clamp();
if( c.alpha > sgFixedAlpha ) // This is the change
c.alpha = sgFixedAlpha;
sg_bitmapModulation = c;
sg_textAnchorColor = sg_bitmapModulation;
}and the same in dglSetTextAnchorColor(){
ColorF c = in_rColor;
c.clamp();
if( c.alpha > sgFixedAlpha ) // Same thing
c.alpha = sgFixedAlpha;
sg_textAnchorColor = c;
}
#4
08/12/2008 (5:15 pm)
Cheers! This is a really nice addition.
#5
04/28/2013 (6:49 pm)
Nice! The bitmap won't fade. The toolbar and stuff will, but why doesn't the bitmap?
#6
05/02/2013 (1:27 pm)
Go through and double check that you applied all of the changes. I'd first look at dglClearBitmapModulation() to make sure it executes the new code "sg_bitmapModulation.set( 255, 255, 255, sgFixedAlpha * 255 );" since that's what the GuiBitmapCtrl calls first.
#7
That sound right? Do you want any of my DGL files?
05/03/2013 (11:26 am)
No luck...//dgl.h:
void dglClearBitmapModulation();
//dgl.cc:
void dglClearBitmapModulation()
{
sg_bitmapModulation.set( 255, 255, 255, sgFixedAlpha * 255 );
}That sound right? Do you want any of my DGL files?
Associate James Ford
Sickhead Games
I have personal experience adding an alphaFade value to the base GuiControl which allows you to do this, but this is a C++ change, and was a fairly big pain in the ass. And unfortunately I also can't provide it as a resource "as is" because it is in an unreleased version of the engine that has completely different draw-calls.
That being said, it is possible to add that feature with C++ changes. Another possibility might be to use sceneObjects and utilize blend-mode for gui elements you want that effect on.