Пример #1
0
 bool AnimationPlayer::deserialize(const ConfigParserPtr& parser) {
     if(parser->toNode(L"animations")) {
         if(parser->toFirstChild()) {
             do {
                 StoryBoardPtr storyboard = MakeSharedPtr<StoryBoard>();
                 MistString name = parser->getString(L"name");
                 if(!name.empty()) {
                     bool isdefault = parser->getBool(L"default", false);
                     if(isdefault)
                         setDefault(name);
                     
                     if(parser->toFirstChild()) {
                         do {
                             MistString type = parser->getCurrentNodeName();
                             
                             // linear animation
                             if(type == L"linear") {
                                 MistString prop_name = parser->getString(L"prop");
                                 MistString prop_type = parser->getString(L"prop_type");
                                 
                                 void* prop = getProperty(prop_name);
                                 if(prop) {
                                     create_linear_animation(prop_type,
                                                             prop,
                                                             parser,
                                                             storyboard.get());
                                 }
                                 
                             // keyframe animation
                             } else if(type == L"keyframe") {
                                 MistString prop_name = parser->getString(L"prop");
                                 MistString prop_type = parser->getString(L"prop_type");
                                 void* prop = getProperty(prop_name);
                                 if(prop) {
                                     create_key_frame_animation(prop_type,
                                                                prop,
                                                                parser,
                                                                storyboard.get());
                                   
                                     // back to parent node
                                     parser->toParent();
                                 }
                             }
                             
                         } while(parser->toNextChild());
                         
                         // back to parent node
                         parser->toParent();
                         
                         // add storyboard
                         mStoryBoards[name] = storyboard;
                         // connect to finish event
                         storyboard->onComplete() += Bind(this, &AnimationPlayer::onAnimationFinished);
                     }
                         
                 }
                 
             } while(parser->toNextChild());
             
             parser->toParent();
         }
         
         parser->toParent();
     } else
         return false;
     
     if(!mDefault.empty())
         play(mDefault);
     
     return true;
 }
Пример #2
0
 inline void create_key_frame_animation(const MistString& type, void* prop, const ConfigParserPtr& parser, StoryBoard* storyboard) {
     
     if(type == L"int") {
         SharedPtr<KeyFrameAnimation<int> > anim = MakeSharedPtr<KeyFrameAnimation<int> >();
         
         int32 time = parser->getInt(L"time", 0);
         int32 duration = parser->getInt(L"duration", 0);
         
         if(duration == 0)
             return;
         anim->setDuration(duration);
         
         if(parser->toFirstChild()) {
             do {
                 if(parser->hasAttribute(L"val")) {
                     
                     int32 val = parser->getInt(L"val", 0);
                     int32 dur = parser->getInt(L"duration", 0);
                     int32 type = parser->getInt(L"type", 0);
                 
                     anim->getKeyFrames().push_back(KeyFrameAnimation<int>::KeyFrame(val, 
                                                                                   dur, 
                                                                                   type == 0 ? KFT_Linear : KFT_Discrete));
                 }
                 
             } while(parser->toNextChild());
             
             storyboard->children().push_back(StoryBoard::AnimationInfo(time, 
                                                                        anim,
                                                                        prop));
         }
         return;
     } 
     
     if(type == L"float") {
         SharedPtr<KeyFrameAnimation<float> > anim = MakeSharedPtr<KeyFrameAnimation<float> >();
         
         int32 time = parser->getInt(L"time", 0);
         int32 duration = parser->getInt(L"duration", 0);
         
         if(duration == 0)
             return;
         anim->setDuration(duration);
         
         if(parser->toFirstChild()) {
             do {
                 if(parser->hasAttribute(L"val")) {
                     
                     float val = parser->getFloat(L"val", 0);
                     int32 dur = parser->getInt(L"duration", 0);
                     int32 type = parser->getInt(L"type", 0);
                     
                     anim->getKeyFrames().push_back(KeyFrameAnimation<float>::KeyFrame(val, 
                                                                                     dur, 
                                                                                     type == 0 ? KFT_Linear : KFT_Discrete));
                 }
                 
             } while(parser->toNextChild());
             
             storyboard->children().push_back(StoryBoard::AnimationInfo(time, 
                                                                        anim,
                                                                        prop));
         }
         return;
     } 
     
     if(type == L"double") {
         SharedPtr<KeyFrameAnimation<double> > anim = MakeSharedPtr<KeyFrameAnimation<double> >();
         
         int32 time = parser->getInt(L"time", 0);
         int32 duration = parser->getInt(L"duration", 0);
         
         if(duration == 0)
             return;
         anim->setDuration(duration);
         
         if(parser->toFirstChild()) {
             do {
                 if(parser->hasAttribute(L"val")) {
                     int32 val = parser->getInt(L"val", 0);
                     int32 dur = parser->getInt(L"duration", 0);
                     int32 type = parser->getInt(L"type", 0);
                     
                     anim->getKeyFrames().push_back(KeyFrameAnimation<double>::KeyFrame(val, 
                                                                                      dur, 
                                                                                      type == 0 ? KFT_Linear : KFT_Discrete));
                 }
                 
             } while(parser->toNextChild());
             
             storyboard->children().push_back(StoryBoard::AnimationInfo(time, 
                                                                        anim,
                                                                        prop));
         }
         return;
     } 
     
     if(type == L"uint") {
         SharedPtr<KeyFrameAnimation<uint32> > anim = MakeSharedPtr<KeyFrameAnimation<uint32> >();
         
         int32 time = parser->getInt(L"time", 0);
         int32 duration = parser->getInt(L"duration", 0);
         
         if(duration == 0)
             return;
         anim->setDuration(duration);
         
         if(parser->toFirstChild()) {
             do {
                 if(parser->hasAttribute(L"val")) {
                     
                     int32 val = parser->getInt(L"val", 0);
                     int32 dur = parser->getInt(L"duration", 0);
                     int32 type = parser->getInt(L"type", 0);
                 
                     anim->getKeyFrames().push_back(KeyFrameAnimation<uint32>::KeyFrame(val, 
                                                                                    dur, 
                                                                                    type == 0 ? KFT_Linear : KFT_Discrete));
                     
                 }
                 
             } while(parser->toNextChild());
             
             storyboard->children().push_back(StoryBoard::AnimationInfo(time, 
                                                                        anim,
                                                                        prop));
         }
         return;
     } 
     
     
     if(type == L"color") {
         // to do
     } 
 }