[solved] How to Animate gifs
Posted: Thu Sep 02, 2010 06:45
hi~I know 0.7.2 added animation system, but I'm still confused about how to animate gifs in cegui?
Anyone could help me,here?
Anyone could help me,here?
The official forum for CEGUI
http://cegui.org.uk/forum/
Code: Select all
#include "Sample_FirstWindow.h"
#include "CEGUI.h"
int main(int /*argc*/, char* /*argv*/[])
{
FirstWindowSample app;
return app.run();
}
bool FirstWindowSample::initialiseSample()
{
using namespace CEGUI;
CEGUI::Animation* anim = CEGUI::AnimationManager::getSingleton().createAnimation("Testing");
anim->setDuration(0.3f); // duration in seconds
anim->setReplayMode(CEGUI::Animation::RM_Once); // when this animation is started, only play it once, then stop
CEGUI::Affector* affector1 = anim->createAffector("YRotation", "float");
affector1->createKeyFrame(0.0f, "0.0");
affector1->createKeyFrame(0.3f, "10.0", CEGUI::KeyFrame::P_QuadraticAccelerating);
CEGUI::Affector* affector2 = anim->createAffector("Alpha", "float");
affector2->createKeyFrame(0.0f, "1.0"); // at 0.0 seconds, set alpha to 0.5
affector2->createKeyFrame(0.3f, "0.5", CEGUI::KeyFrame::P_QuadraticDecelerating); // at 1.0 seconds, set alpha to 1.0, now decelerating!
CEGUI::Affector* affector3 = anim->createAffector("Text", "float");
affector3->createKeyFrame(0.0f, "AAAA"); // at 0.0 seconds, set alpha to 0.5
affector3->createKeyFrame(0.3f, "BBBB", CEGUI::KeyFrame::P_QuadraticDecelerating);
CEGUI::Affector* affector4 = anim->createAffector("Visible", "bool");
affector4->createKeyFrame(0.0f, "true"); // at 0.0 seconds, set alpha to 0.5
affector4->createKeyFrame(0.3f, "false", CEGUI::KeyFrame::P_QuadraticDecelerating);
SchemeManager::getSingleton().create("TaharezLook.scheme");
System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
WindowManager& winMgr = WindowManager::getSingleton();
DefaultWindow* root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root");
CEGUI::Font& font = FontManager::getSingleton().createFreeTypeFont("DefaultFont", 10/*pt*/, true, "simhei.ttf");
System::getSingleton().setDefaultFont("DefaultFont");
System::getSingleton().setGUISheet(root);
FrameWindow* wnd = (FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "Demo Window");
root->addChildWindow(wnd);
CEGUI::AnimationInstance* instance = CEGUI::AnimationManager::getSingleton().instantiateAnimation(anim);
instance->setTargetWindow(wnd);
instance->start();
wnd->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
wnd->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
wnd->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
wnd->setMinSize(UVector2(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
wnd->subscribeEvent(CEGUI::Window::EventMouseEntersArea, CEGUI::Event::Subscriber(&CEGUI::AnimationInstance::handleStart, instance));
return true;
}
void FirstWindowSample::cleanupSample()
{
// nothing to do here!
}
Code: Select all
<Animations>
<AnimationDefinition name="Testing" duration="0.3" replayMode="once">
<Affector property="Image" interpolator="String">
<KeyFrame position="0.1" value="set:guangbiao image:NewImage1" />
<KeyFrame position="0.2" progression="discrete" value="set:guangbiao image:NewImage2" />
<KeyFrame position="0.3" progression="discrete" value="set:guangbiao image:NewImage3" />
</Affector>
<Affector property="Alpha" interpolator="float">
<KeyFrame position="0.0" value="1.0" />
<KeyFrame position="0.3" value="0.5" />
</Affector>
<Affector property="XRotation" interpolator="float">
<KeyFrame position="0.0" value="0" />
<KeyFrame position="0.3" value="10" />
</Affector>
<Affector property="Text" interpolator="String">
<KeyFrame position="0.0" value="AAAA" />
<KeyFrame position="0.3" value="BBBB" />
</Affector>
</AnimationDefinition>
</Animations>
Code: Select all
{
// this affector will again use String to change the Image
CEGUI::Affector* affector = anim->createAffector("Image", "String");
affector->createKeyFrame(0.1f, "set:guangbiao image:NewImage1"); // at 0.1 seconds
affector->createKeyFrame(0.2f, "set:guangbiao image:NewImage2", CEGUI::KeyFrame::P_Linear); // at 0.2 seconds
affector->createKeyFrame(0.3f, "set:guangbiao image:NewImage3", CEGUI::KeyFrame::P_Linear);
}
//CEGUI::MouseCursor
instance = CEGUI::AnimationManager::getSingleton().instantiateAnimation(anim);
// after we instantiate the animation, we have to set its target window
instance->setTargetWindow(imageComponent); //textComponent imageComponent
Code: Select all
<WidgetLook name="game1/Button">
...
<AnimationDefinition name="Testing" duration="0.3" replayMode="once">
<Affector property="Image" interpolator="String">
<KeyFrame position="0.1" value="set:game1 image:myImage1" />
<KeyFrame position="0.2" progression="discrete" value="set:game1 image:myImage2" />
<KeyFrame position="0.3" progression="discrete" value="set:game1 image:myImage3" />
</Affector>
...
<Subscription event="MouseEntersArea" action="Start" />
...
</WidgetLook>
Code: Select all
CEGUI_THROW(UnknownObjectException("There is no Property named '" + name + "' available in the set."));