From af451bfa81a68d958eef127b7d3aaa5c7490af30 Mon Sep 17 00:00:00 2001 From: emb <> Date: Thu, 19 Feb 2015 07:39:17 -0600 Subject: [PATCH] Breaking tweens up into 4 classes for readability. Created copy constructors. ScrollingList copy constructor still causes crash when update is called. --- RetroFE/Source/CMakeLists.txt | 8 +- RetroFE/Source/Graphics/Animate/Animation.cpp | 68 +++++++++++ RetroFE/Source/Graphics/Animate/Animation.h | 36 ++++++ .../Graphics/Animate/AnimationEvents.cpp | 95 +++++++++++++++ .../{TweenSets.h => AnimationEvents.h} | 22 ++-- RetroFE/Source/Graphics/Animate/TweenSet.cpp | 65 ++++++++++ RetroFE/Source/Graphics/Animate/TweenSet.h | 35 ++++++ RetroFE/Source/Graphics/Animate/TweenSets.cpp | 93 -------------- .../Source/Graphics/Component/Component.cpp | 65 ++++++---- RetroFE/Source/Graphics/Component/Component.h | 12 +- .../Graphics/Component/ScrollingList.cpp | 115 +++++++++++------- .../Source/Graphics/Component/ScrollingList.h | 9 +- RetroFE/Source/Graphics/Page.cpp | 7 ++ RetroFE/Source/Graphics/PageBuilder.cpp | 44 +++---- RetroFE/Source/Graphics/PageBuilder.h | 8 +- 15 files changed, 477 insertions(+), 205 deletions(-) create mode 100644 RetroFE/Source/Graphics/Animate/Animation.cpp create mode 100644 RetroFE/Source/Graphics/Animate/Animation.h create mode 100644 RetroFE/Source/Graphics/Animate/AnimationEvents.cpp rename RetroFE/Source/Graphics/Animate/{TweenSets.h => AnimationEvents.h} (58%) create mode 100644 RetroFE/Source/Graphics/Animate/TweenSet.cpp create mode 100644 RetroFE/Source/Graphics/Animate/TweenSet.h delete mode 100644 RetroFE/Source/Graphics/Animate/TweenSets.cpp diff --git a/RetroFE/Source/CMakeLists.txt b/RetroFE/Source/CMakeLists.txt index 6c35c18..fa7c87b 100644 --- a/RetroFE/Source/CMakeLists.txt +++ b/RetroFE/Source/CMakeLists.txt @@ -86,7 +86,9 @@ set(RETROFE_HEADERS "${RETROFE_DIR}/Source/Execute/Launcher.h" "${RETROFE_DIR}/Source/Graphics/Animate/Tween.h" "${RETROFE_DIR}/Source/Graphics/Animate/TweenTypes.h" - "${RETROFE_DIR}/Source/Graphics/Animate/TweenSets.h" + "${RETROFE_DIR}/Source/Graphics/Animate/TweenSet.h" + "${RETROFE_DIR}/Source/Graphics/Animate/Animation.h" + "${RETROFE_DIR}/Source/Graphics/Animate/AnimationEvents.h" "${RETROFE_DIR}/Source/Graphics/ComponentItemBinding.h" "${RETROFE_DIR}/Source/Graphics/Component/Container.h" "${RETROFE_DIR}/Source/Graphics/Component/Component.h" @@ -132,8 +134,10 @@ set(RETROFE_SOURCES "${RETROFE_DIR}/Source/Graphics/PageBuilder.cpp" "${RETROFE_DIR}/Source/Graphics/Page.cpp" "${RETROFE_DIR}/Source/Graphics/ViewInfo.cpp" + "${RETROFE_DIR}/Source/Graphics/Animate/Animation.cpp" + "${RETROFE_DIR}/Source/Graphics/Animate/AnimationEvents.cpp" "${RETROFE_DIR}/Source/Graphics/Animate/Tween.cpp" - "${RETROFE_DIR}/Source/Graphics/Animate/TweenSets.cpp" + "${RETROFE_DIR}/Source/Graphics/Animate/TweenSet.cpp" "${RETROFE_DIR}/Source/Graphics/ComponentItemBindingBuilder.cpp" "${RETROFE_DIR}/Source/Graphics/ComponentItemBinding.cpp" "${RETROFE_DIR}/Source/Graphics/Component/Container.cpp" diff --git a/RetroFE/Source/Graphics/Animate/Animation.cpp b/RetroFE/Source/Graphics/Animate/Animation.cpp new file mode 100644 index 0000000..13e114e --- /dev/null +++ b/RetroFE/Source/Graphics/Animate/Animation.cpp @@ -0,0 +1,68 @@ +/* This file is part of RetroFE. + * + * RetroFE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * RetroFE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RetroFE. If not, see . + */ + +#include "Animation.h" +#include + +Animation::Animation() +{ +} + +Animation::Animation(Animation ©) +{ + for(std::vector::iterator it = copy.AnimationVector.begin(); it != copy.AnimationVector.end(); it++) + { + Push(new TweenSet(**it)); + } +} +Animation::~Animation() +{ + Clear(); +} + +void Animation::Push(TweenSet *set) +{ + AnimationVector.push_back(set); +} + +void Animation::Clear() +{ + std::vector::iterator it = AnimationVector.begin(); + while(it != AnimationVector.end()) + { + delete *it; + AnimationVector.erase(it); + it = AnimationVector.begin(); + } + + AnimationVector.clear(); +} + +std::vector *Animation::GetTweenSets() +{ + return &AnimationVector; +} + +TweenSet *Animation::GetTweenSet(unsigned int index) +{ + return AnimationVector[index]; +} + + +unsigned int Animation::GetSize() +{ + return AnimationVector.size(); +} diff --git a/RetroFE/Source/Graphics/Animate/Animation.h b/RetroFE/Source/Graphics/Animate/Animation.h new file mode 100644 index 0000000..cb991aa --- /dev/null +++ b/RetroFE/Source/Graphics/Animate/Animation.h @@ -0,0 +1,36 @@ +/* This file is part of RetroFE. + * + * RetroFE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * RetroFE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RetroFE. If not, see . + */ +#pragma once + +#include "TweenSet.h" +#include +#include +#include + +class Animation +{ +public: + Animation(); + Animation(Animation ©); + ~Animation(); + void Push(TweenSet *set); + void Clear(); + std::vector *GetTweenSets(); + TweenSet *GetTweenSet(unsigned int index); + unsigned int GetSize(); +private: + std::vector AnimationVector; +}; diff --git a/RetroFE/Source/Graphics/Animate/AnimationEvents.cpp b/RetroFE/Source/Graphics/Animate/AnimationEvents.cpp new file mode 100644 index 0000000..9c7b327 --- /dev/null +++ b/RetroFE/Source/Graphics/Animate/AnimationEvents.cpp @@ -0,0 +1,95 @@ +/* This file is part of RetroFE. + * + * RetroFE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * RetroFE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RetroFE. If not, see . + */ + +#include "AnimationEvents.h" +#include + + + +AnimationEvents::AnimationEvents() +{ +} + +AnimationEvents::AnimationEvents(AnimationEvents ©) +{ + for(std::map >::iterator it = copy.AnimationMap.begin(); it != copy.AnimationMap.end(); it++) + { + for(std::map::iterator it2 = (it->second).begin(); it2 != (it->second).end(); it2++) + { + Animation *t = new Animation(*it2->second); + AnimationMap[it->first][it2->first] = t; + } + } +} + +AnimationEvents::~AnimationEvents() +{ + Clear(); +} + +Animation *AnimationEvents::GetAnimation(std::string tween) +{ + return GetAnimation(tween, -1); +} + +Animation *AnimationEvents::GetAnimation(std::string tween, int index) +{ + if(AnimationMap.find(tween) == AnimationMap.end()) + { + AnimationMap[tween][-1] = new Animation(); + } + + if(AnimationMap[tween].find(index) == AnimationMap[tween].end()) + { + index = -1; + + if(AnimationMap[tween].find(index) == AnimationMap[tween].end()) + { + AnimationMap[tween][index] = new Animation(); + } + } + + return AnimationMap[tween][index]; +} + +void AnimationEvents::SetAnimation(std::string tween, int index, Animation *animation) +{ + AnimationMap[tween][index] = animation; +} + +void AnimationEvents::Clear() +{ + std::map >::iterator it = AnimationMap.begin(); + while(it != AnimationMap.end()) + { + std::map::iterator it2 = (it->second).begin(); + while(it2 != (it->second).end()) + { + delete it2->second; + (it->second).erase(it2); + } + + (it->second).clear(); + AnimationMap.erase(it); + it = AnimationMap.begin(); + } + + AnimationMap.clear(); +} + + + + diff --git a/RetroFE/Source/Graphics/Animate/TweenSets.h b/RetroFE/Source/Graphics/Animate/AnimationEvents.h similarity index 58% rename from RetroFE/Source/Graphics/Animate/TweenSets.h rename to RetroFE/Source/Graphics/Animate/AnimationEvents.h index ef23aa8..1b4ab12 100644 --- a/RetroFE/Source/Graphics/Animate/TweenSets.h +++ b/RetroFE/Source/Graphics/Animate/AnimationEvents.h @@ -16,25 +16,23 @@ #pragma once #include "Tween.h" +#include "Animation.h" #include #include #include -class TweenSets +class AnimationEvents { public: - TweenSets(); - TweenSets(TweenSets ©); - ~TweenSets(); - typedef std::vector *> TweenAttributes; + AnimationEvents(); + AnimationEvents(AnimationEvents ©); + ~AnimationEvents(); - TweenAttributes *GetTween(std::string tween); - TweenAttributes *GetTween(std::string tween, int index); - void SetTween(std::string tween, int index, TweenAttributes *set); + Animation *GetAnimation(std::string tween); + Animation *GetAnimation(std::string tween, int index); + void SetAnimation(std::string tween, int index, Animation *animation); + void Clear(); private: - TweenAttributes *FindTween(std::map &tweens, int index); - void DestroyTweens(); - - std::map > TweenMap; + std::map > AnimationMap; }; diff --git a/RetroFE/Source/Graphics/Animate/TweenSet.cpp b/RetroFE/Source/Graphics/Animate/TweenSet.cpp new file mode 100644 index 0000000..74bfdcc --- /dev/null +++ b/RetroFE/Source/Graphics/Animate/TweenSet.cpp @@ -0,0 +1,65 @@ +/* This file is part of RetroFE. + * + * RetroFE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * RetroFE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RetroFE. If not, see . + */ +#include "TweenSet.h" + +TweenSet::TweenSet() +{ +} + +TweenSet::TweenSet(TweenSet ©) +{ + for(std::vector::iterator it = copy.Set.begin(); it != copy.Set.end(); it++) + { + Tween *t = new Tween(**it); + Set.push_back(t); + } +} + +TweenSet::~TweenSet() +{ + Clear(); +} + +void TweenSet::Push(Tween *tween) +{ + Set.push_back(tween); +} + +void TweenSet::Clear() +{ + std::vector::iterator it = Set.begin(); + while(it != Set.end()) + { + delete *it; + Set.erase(it); + it = Set.begin(); + } +} +std::vector *TweenSet::GetTweens() +{ + return &Set; +} + +Tween *TweenSet::GetTween(unsigned int index) +{ + return Set[index]; +} + + +unsigned int TweenSet::GetSize() +{ + return Set.size(); +} diff --git a/RetroFE/Source/Graphics/Animate/TweenSet.h b/RetroFE/Source/Graphics/Animate/TweenSet.h new file mode 100644 index 0000000..ea0cdb4 --- /dev/null +++ b/RetroFE/Source/Graphics/Animate/TweenSet.h @@ -0,0 +1,35 @@ +/* This file is part of RetroFE. + * + * RetroFE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * RetroFE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with RetroFE. If not, see . + */ +#pragma once + +#include "Tween.h" +#include + +class TweenSet +{ +public: + TweenSet(); + TweenSet(TweenSet ©); + ~TweenSet(); + void Push(Tween * tween); + void Clear(); + std::vector *GetTweens(); + Tween *GetTween(unsigned int index); + unsigned int GetSize(); + +private: + std::vector Set; +}; diff --git a/RetroFE/Source/Graphics/Animate/TweenSets.cpp b/RetroFE/Source/Graphics/Animate/TweenSets.cpp deleted file mode 100644 index a176d06..0000000 --- a/RetroFE/Source/Graphics/Animate/TweenSets.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* This file is part of RetroFE. - * - * RetroFE is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * RetroFE is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with RetroFE. If not, see . - */ - -#include "TweenSets.h" - -TweenSets::TweenSets() -{ -} -TweenSets::TweenSets(TweenSets ©) -{ - std::map >::iterator it; - - for(it = copy.TweenMap.begin(); it != copy.TweenMap.end(); it++) - { - std::map::iterator it2; - - for(it2 = (it->second).begin(); it2 != (it->second).end(); it2++) - { - TweenMap[it->first][it2->first] = it2->second; - } - } - -} - -TweenSets::~TweenSets() -{ - DestroyTweens(); -} - -void TweenSets::DestroyTweens() -{ - std::map >::iterator it = TweenMap.begin(); - - while(it != TweenMap.end()) - { - std::map::iterator it2 = (it->second).begin(); - - while(it2 != (it->second).end()) - { - delete it2->second; - (it->second).erase(it2); - it2 = (it->second).begin(); - } - - it =TweenMap.begin(); - } -} - -TweenSets::TweenAttributes *TweenSets::GetTween(std::string tween) -{ - return GetTween(tween, -1); -} - -TweenSets::TweenAttributes *TweenSets::GetTween(std::string tween, int index) -{ - return FindTween(TweenMap[tween], index); -} - -void TweenSets::SetTween(std::string tween, int index, TweenAttributes *set) -{ - TweenMap[tween][index] = set; -} - -TweenSets::TweenAttributes *TweenSets::FindTween(std::map &tweens, int index) -{ - if(tweens.find(index) == tweens.end()) - { - index = -1; - - if(tweens.find(index) == tweens.end()) - { - TweenAttributes *set = new TweenAttributes(); - tweens[index] = set; - } - } - - return tweens[index]; -} - - diff --git a/RetroFE/Source/Graphics/Component/Component.cpp b/RetroFE/Source/Graphics/Component/Component.cpp index 8d9046b..aa9936c 100644 --- a/RetroFE/Source/Graphics/Component/Component.cpp +++ b/RetroFE/Source/Graphics/Component/Component.cpp @@ -29,6 +29,23 @@ Component::Component() } +Component::Component(const Component ©) +{ + Tweens = NULL; + SelectedItem = NULL; + NewItemSelectedSinceEnter = false; + BackgroundTexture = NULL; + FreeGraphicsMemory(); + + if(copy.Tweens) + { + AnimationEvents *tweens = new AnimationEvents(*copy.Tweens); + SetTweens(tweens); + } + + +} + Component::~Component() { FreeGraphicsMemory(); @@ -151,18 +168,24 @@ void Component::SetCollectionName(std::string collectionName) CollectionName = collectionName; } -TweenSets *Component::GetTweens() +AnimationEvents *Component::GetTweens() { return Tweens; } -void Component::SetTweens(TweenSets *set) +void Component::SetTweens(AnimationEvents *set) { Tweens = set; + ForceIdle(); +} + +void Component::ForceIdle() +{ CurrentAnimationState = IDLE; CurrentTweenIndex = 0; CurrentTweenComplete = false; ElapsedTweenTime = 0; + CurrentTweens = NULL; } ViewInfo *Component::GetBaseViewInfo() @@ -219,7 +242,7 @@ void Component::Update(float dt) case ENTER: - CurrentTweens = Tweens->GetTween("enter", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("enter", MenuEnterIndex); CurrentAnimationState = HIGHLIGHT_ENTER; break; @@ -229,7 +252,7 @@ void Component::Update(float dt) break; case HIGHLIGHT_ENTER: - CurrentTweens = Tweens->GetTween("idle", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("idle", MenuEnterIndex); CurrentAnimationState = IDLE; break; @@ -242,13 +265,13 @@ void Component::Update(float dt) } else if(MenuExitRequested && (!MenuEnterRequested || MenuExitRequested <= MenuEnterRequested)) { - CurrentTweens = Tweens->GetTween("menuExit", MenuExitIndex); + CurrentTweens = Tweens->GetAnimation("menuExit", MenuExitIndex); CurrentAnimationState = MENU_EXIT; MenuExitRequested = false; } else if(MenuEnterRequested && (!MenuExitRequested || MenuExitRequested > MenuEnterRequested)) { - CurrentTweens = Tweens->GetTween("menuEnter", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("menuEnter", MenuEnterIndex); CurrentAnimationState = MENU_ENTER; MenuEnterRequested = false; @@ -256,17 +279,17 @@ void Component::Update(float dt) else if(MenuScrollRequested) { MenuScrollRequested = false; - CurrentTweens = Tweens->GetTween("menuScroll", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("menuScroll", MenuEnterIndex); CurrentAnimationState = MENU_SCROLL; } else if(IsScrollActive() || NewItemSelected || ExitRequested) { - CurrentTweens = Tweens->GetTween("highlightExit", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("highlightExit", MenuEnterIndex); CurrentAnimationState = HIGHLIGHT_EXIT; } else { - CurrentTweens = Tweens->GetTween("idle", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("idle", MenuEnterIndex); CurrentAnimationState = IDLE; } break; @@ -278,14 +301,14 @@ void Component::Update(float dt) if(ExitRequested && (CurrentAnimationState == HIGHLIGHT_WAIT)) { - CurrentTweens = Tweens->GetTween("highlightExit", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("highlightExit", MenuEnterIndex); CurrentAnimationState = HIGHLIGHT_EXIT; } else if(ExitRequested && (CurrentAnimationState == HIGHLIGHT_EXIT)) { - CurrentTweens = Tweens->GetTween("exit", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("exit", MenuEnterIndex); CurrentAnimationState = EXIT; ExitRequested = false; } @@ -296,7 +319,7 @@ void Component::Update(float dt) } else if(NewItemSelected) { - CurrentTweens = Tweens->GetTween("highlightEnter", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("highlightEnter", MenuEnterIndex); CurrentAnimationState = HIGHLIGHT_ENTER; HighlightExitComplete = true; NewItemSelected = false; @@ -311,19 +334,19 @@ void Component::Update(float dt) case HIDDEN: if(EnterRequested || ExitRequested) { - CurrentTweens = Tweens->GetTween("enter", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("enter", MenuEnterIndex); CurrentAnimationState = ENTER; } else if(MenuExitRequested && (!MenuEnterRequested || MenuExitRequested <= MenuEnterRequested)) { - CurrentTweens = Tweens->GetTween("menuExit", MenuExitIndex); + CurrentTweens = Tweens->GetAnimation("menuExit", MenuExitIndex); CurrentAnimationState = MENU_EXIT; MenuExitRequested = false; } else if(MenuEnterRequested && (!MenuExitRequested || MenuExitRequested > MenuEnterRequested)) { - CurrentTweens = Tweens->GetTween("menuEnter", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("menuEnter", MenuEnterIndex); CurrentAnimationState = MENU_ENTER; MenuEnterRequested = false; @@ -331,7 +354,7 @@ void Component::Update(float dt) else if(MenuScrollRequested) { MenuScrollRequested = false; - CurrentTweens = Tweens->GetTween("menuScroll", MenuEnterIndex); + CurrentTweens = Tweens->GetAnimation("menuScroll", MenuEnterIndex); CurrentAnimationState = MENU_SCROLL; } else @@ -375,18 +398,18 @@ void Component::Draw() bool Component::Animate(bool loop) { bool completeDone = false; - if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->size()) + if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->GetSize()) { completeDone = true; } else if(CurrentTweens) { bool currentDone = true; - std::vector *TweenSets = CurrentTweens->at(CurrentTweenIndex); + TweenSet *tweens = CurrentTweens->GetTweenSet(CurrentTweenIndex); - for(unsigned int i = 0; i < TweenSets->size(); i++) + for(unsigned int i = 0; i < tweens->GetSize(); i++) { - Tween *tween = TweenSets->at(i); + Tween *tween = tweens->GetTweens()->at(i); float elapsedTime = ElapsedTweenTime; //todo: too many levels of nesting @@ -460,7 +483,7 @@ bool Component::Animate(bool loop) } } - if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->size()) + if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->GetTweenSets()->size()) { if(loop) { diff --git a/RetroFE/Source/Graphics/Component/Component.h b/RetroFE/Source/Graphics/Component/Component.h index de42121..192ec63 100644 --- a/RetroFE/Source/Graphics/Component/Component.h +++ b/RetroFE/Source/Graphics/Component/Component.h @@ -21,13 +21,14 @@ #include "../MenuNotifierInterface.h" #include "../ViewInfo.h" #include "../Animate/Tween.h" -#include "../Animate/TweenSets.h" +#include "../Animate/AnimationEvents.h" #include "../../Collection/Item.h" class Component { public: Component(); + Component(const Component ©); virtual ~Component(); virtual void FreeGraphicsMemory(); virtual void AllocateGraphicsMemory(); @@ -48,8 +49,9 @@ public: virtual void Update(float dt); virtual void Draw(); - TweenSets *GetTweens(); - void SetTweens(TweenSets *set); + AnimationEvents *GetTweens(); + void SetTweens(AnimationEvents *set); + void ForceIdle(); ViewInfo *GetBaseViewInfo(); void UpdateBaseViewInfo(ViewInfo &info); bool IsScrollActive() const; @@ -87,8 +89,8 @@ private: bool Animate(bool loop); bool IsTweenSequencingComplete(); - TweenSets *Tweens; - TweenSets::TweenAttributes *CurrentTweens; + AnimationEvents *Tweens; + Animation *CurrentTweens; Item *SelectedItem; SDL_Texture *BackgroundTexture; diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index 7d42e33..c673cb7 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -15,6 +15,9 @@ */ #include "../Animate/Tween.h" +#include "../Animate/TweenSet.h" +#include "../Animate/Animation.h" +#include "../Animate/AnimationEvents.h" #include "../Animate/TweenTypes.h" #include "../ComponentItemBinding.h" #include "../Font.h" @@ -44,6 +47,7 @@ ScrollingList::ScrollingList(Configuration &c, std::string imageType) : SpriteList(NULL) , ScrollPoints(NULL) + , TweenPoints(NULL) , TweenEnterTime(0) , FirstSpriteIndex(0) , SelectedSpriteListIndex(0) @@ -62,11 +66,61 @@ ScrollingList::ScrollingList(Configuration &c, , FontColor(fontColor) , LayoutKey(layoutKey) , ImageType(imageType) - , MaxLayer(0) , Focus(false) { + Component::Component(); } +ScrollingList::ScrollingList(const ScrollingList ©) + : SpriteList(NULL) + , TweenEnterTime(0) + , FirstSpriteIndex(0) + , SelectedSpriteListIndex(0) + , ScrollStopRequested(true) + , NotifyAllRequested(false) + , CurrentScrollDirection(ScrollDirectionIdle) + , RequestedScrollDirection(ScrollDirectionIdle) + , CurrentScrollState(ScrollStateIdle) + , ScrollAcceleration(copy.ScrollAcceleration) + , StartScrollTime(copy.StartScrollTime) + , ScrollPeriod(0) + , Config(copy.Config) + , ScaleX(copy.ScaleX) + , ScaleY(copy.ScaleY) + , FontInst(copy.FontInst) + , FontColor(copy.FontColor) + , LayoutKey(copy.LayoutKey) + , ImageType(copy.ImageType) + , Focus(false) +{ + + ScrollPoints = NULL; + TweenPoints = NULL; + + if(copy.ScrollPoints) + { + ScrollPoints = new std::vector(); + for(unsigned int i = 0; i < copy.ScrollPoints->size(); ++i) + { + ViewInfo *v = new ViewInfo(*copy.ScrollPoints->at(i)); + ScrollPoints->push_back(v); + } + } + + if(copy.TweenPoints) + { + TweenPoints = new std::vector(); + for(unsigned int i = 0; i < copy.TweenPoints->size(); ++i) + { + AnimationEvents *v = new AnimationEvents(*copy.TweenPoints->at(i)); + TweenPoints->push_back(v); + } + } + + Component::Component(copy); +} + + ScrollingList::~ScrollingList() { DestroyItems(); @@ -200,16 +254,10 @@ void ScrollingList::DestroyItems() } -void ScrollingList::SetPoints(std::vector *scrollPoints, std::vector *tweenPoints) +void ScrollingList::SetPoints(std::vector *scrollPoints, std::vector *tweenPoints) { ScrollPoints = scrollPoints; TweenPoints = tweenPoints; - - for(unsigned int i = 0; i != scrollPoints->size(); ++i) - { - ViewInfo *info = scrollPoints->at(i); - MaxLayer = (MaxLayer < info->GetLayer()) ? MaxLayer : info->GetLayer(); - } } void ScrollingList::SetSelectedIndex(int selectedIndex) @@ -575,7 +623,7 @@ void ScrollingList::UpdateSprite(unsigned int spriteIndex, unsigned int pointInd CircularIncrement(spriteIndex, SpriteList); } -void ScrollingList::ResetTweens(Component *c, TweenSets *sets, ViewInfo *currentViewInfo, ViewInfo *nextViewInfo, double scrollTime) +void ScrollingList::ResetTweens(Component *c, AnimationEvents *sets, ViewInfo *currentViewInfo, ViewInfo *nextViewInfo, double scrollTime) { if(!c) { @@ -603,41 +651,24 @@ void ScrollingList::ResetTweens(Component *c, TweenSets *sets, ViewInfo *current //todo: delete properly, memory leak (big), proof of concept c->SetTweens(sets); - TweenSets::TweenAttributes *scrollTween = sets->GetTween("menuScroll"); - TweenSets::TweenAttributes::iterator it = scrollTween->begin(); - - while(it != scrollTween->end()) - { - std::vector::iterator it2 = (*it)->begin(); - while(it2 != (*it)->end()) - { - delete *it2; - (*it)->erase(it2); - it2 = (*it)->begin(); - } - delete *it; - scrollTween->erase(it); - it = scrollTween->begin(); - - } - - scrollTween->clear(); + Animation *scrollTween = sets->GetAnimation("menuScroll"); + scrollTween->Clear(); c->UpdateBaseViewInfo(*currentViewInfo); - std::vector *set = new std::vector(); - set->push_back(new Tween(TWEEN_PROPERTY_HEIGHT, EASE_INOUT_QUADRATIC, currentViewInfo->GetHeight(), nextViewInfo->GetHeight(), scrollTime)); - set->push_back(new Tween(TWEEN_PROPERTY_WIDTH, EASE_INOUT_QUADRATIC, currentViewInfo->GetWidth(), nextViewInfo->GetWidth(), scrollTime)); - set->push_back(new Tween(TWEEN_PROPERTY_ANGLE, EASE_INOUT_QUADRATIC, currentViewInfo->GetAngle(), nextViewInfo->GetAngle(), scrollTime)); - set->push_back(new Tween(TWEEN_PROPERTY_ALPHA, EASE_INOUT_QUADRATIC, currentViewInfo->GetAlpha(), nextViewInfo->GetAlpha(), scrollTime)); - set->push_back(new Tween(TWEEN_PROPERTY_X, EASE_INOUT_QUADRATIC, currentViewInfo->GetX(), nextViewInfo->GetX(), scrollTime)); - set->push_back(new Tween(TWEEN_PROPERTY_Y, EASE_INOUT_QUADRATIC, currentViewInfo->GetY(), nextViewInfo->GetY(), scrollTime)); - set->push_back(new Tween(TWEEN_PROPERTY_X_ORIGIN, EASE_INOUT_QUADRATIC, currentViewInfo->GetXOrigin(), nextViewInfo->GetXOrigin(), scrollTime)); - set->push_back(new Tween(TWEEN_PROPERTY_Y_ORIGIN, EASE_INOUT_QUADRATIC, currentViewInfo->GetYOrigin(), nextViewInfo->GetYOrigin(), scrollTime)); - set->push_back(new Tween(TWEEN_PROPERTY_X_OFFSET, EASE_INOUT_QUADRATIC, currentViewInfo->GetXOffset(), nextViewInfo->GetXOffset(), scrollTime)); - set->push_back(new Tween(TWEEN_PROPERTY_Y_OFFSET, EASE_INOUT_QUADRATIC, currentViewInfo->GetYOffset(), nextViewInfo->GetYOffset(), scrollTime)); - set->push_back(new Tween(TWEEN_PROPERTY_FONT_SIZE, EASE_INOUT_QUADRATIC, currentViewInfo->GetFontSize(), nextViewInfo->GetFontSize(), scrollTime)); - set->push_back(new Tween(TWEEN_PROPERTY_BACKGROUND_ALPHA, EASE_INOUT_QUADRATIC, currentViewInfo->GetBackgroundAlpha(), nextViewInfo->GetBackgroundAlpha(), scrollTime)); - scrollTween->push_back(set); + TweenSet *set = new TweenSet(); + set->Push(new Tween(TWEEN_PROPERTY_HEIGHT, EASE_INOUT_QUADRATIC, currentViewInfo->GetHeight(), nextViewInfo->GetHeight(), scrollTime)); + set->Push(new Tween(TWEEN_PROPERTY_WIDTH, EASE_INOUT_QUADRATIC, currentViewInfo->GetWidth(), nextViewInfo->GetWidth(), scrollTime)); + set->Push(new Tween(TWEEN_PROPERTY_ANGLE, EASE_INOUT_QUADRATIC, currentViewInfo->GetAngle(), nextViewInfo->GetAngle(), scrollTime)); + set->Push(new Tween(TWEEN_PROPERTY_ALPHA, EASE_INOUT_QUADRATIC, currentViewInfo->GetAlpha(), nextViewInfo->GetAlpha(), scrollTime)); + set->Push(new Tween(TWEEN_PROPERTY_X, EASE_INOUT_QUADRATIC, currentViewInfo->GetX(), nextViewInfo->GetX(), scrollTime)); + set->Push(new Tween(TWEEN_PROPERTY_Y, EASE_INOUT_QUADRATIC, currentViewInfo->GetY(), nextViewInfo->GetY(), scrollTime)); + set->Push(new Tween(TWEEN_PROPERTY_X_ORIGIN, EASE_INOUT_QUADRATIC, currentViewInfo->GetXOrigin(), nextViewInfo->GetXOrigin(), scrollTime)); + set->Push(new Tween(TWEEN_PROPERTY_Y_ORIGIN, EASE_INOUT_QUADRATIC, currentViewInfo->GetYOrigin(), nextViewInfo->GetYOrigin(), scrollTime)); + set->Push(new Tween(TWEEN_PROPERTY_X_OFFSET, EASE_INOUT_QUADRATIC, currentViewInfo->GetXOffset(), nextViewInfo->GetXOffset(), scrollTime)); + set->Push(new Tween(TWEEN_PROPERTY_Y_OFFSET, EASE_INOUT_QUADRATIC, currentViewInfo->GetYOffset(), nextViewInfo->GetYOffset(), scrollTime)); + set->Push(new Tween(TWEEN_PROPERTY_FONT_SIZE, EASE_INOUT_QUADRATIC, currentViewInfo->GetFontSize(), nextViewInfo->GetFontSize(), scrollTime)); + set->Push(new Tween(TWEEN_PROPERTY_BACKGROUND_ALPHA, EASE_INOUT_QUADRATIC, currentViewInfo->GetBackgroundAlpha(), nextViewInfo->GetBackgroundAlpha(), scrollTime)); + scrollTween->Push(set); } diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.h b/RetroFE/Source/Graphics/Component/ScrollingList.h index a607e3d..a35dc9d 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.h +++ b/RetroFE/Source/Graphics/Component/ScrollingList.h @@ -50,6 +50,8 @@ public: SDL_Color fontColor, std::string layoutKey, std::string imageType); + + ScrollingList(const ScrollingList ©); virtual ~ScrollingList(); void TriggerMenuEnterEvent(); void TriggerMenuExitEvent(); @@ -58,7 +60,7 @@ public: void DeallocateTexture(ComponentItemBinding *s); void SetItems(std::vector *spriteList); void DestroyItems(); - void SetPoints(std::vector *scrollPoints, std::vector *tweenPoints); + void SetPoints(std::vector *scrollPoints, std::vector *tweenPoints); void SetScrollDirection(ScrollDirection direction); void PageUp(); void PageDown(); @@ -84,7 +86,7 @@ private: void AllocateSpritePoints(); void UpdateSprite(unsigned int spriteIndex, unsigned int pointIndex, bool newScroll, float dt, double nextScrollTime); unsigned int GetNextTween(unsigned int currentIndex, std::vector *list); - void ResetTweens(Component *c, TweenSets *sets, ViewInfo *currentViewInfo, ViewInfo *nextViewInfo, double scrollTime); + void ResetTweens(Component *c, AnimationEvents *sets, ViewInfo *currentViewInfo, ViewInfo *nextViewInfo, double scrollTime); enum ScrollState { @@ -96,7 +98,7 @@ private: std::vector *SpriteList; std::vector *ScrollPoints; - std::vector *TweenPoints; + std::vector *TweenPoints; std::vector NotificationComponents; float TweenEnterTime; bool Focus; @@ -127,6 +129,5 @@ private: SDL_Color FontColor; std::string LayoutKey; std::string ImageType; - unsigned int MaxLayer; }; diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 3f3305e..a66ba57 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -368,6 +368,13 @@ bool Page::PushCollection(CollectionInfo *collection) menuExitIndex = MenuDepth - 1; } + if(Menus.size() >= MenuDepth && ActiveMenu) + { + ScrollingList *newList = new ScrollingList(*ActiveMenu); + newList->ForceIdle(); + PushMenu(newList); + } + ActiveMenu = Menus[MenuDepth]; ActiveMenu->SetCollectionName(collection->GetName()); ActiveMenu->DestroyItems(); diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index f5abc8c..3dde688 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -23,7 +23,7 @@ #include "Component/ReloadableText.h" #include "Component/ReloadableMedia.h" #include "Component/ScrollingList.h" -#include "Animate/TweenSets.h" +#include "Animate/AnimationEvents.h" #include "Animate/TweenTypes.h" #include "../Sound/Sound.h" #include "../Collection/Item.h" @@ -467,31 +467,31 @@ void PageBuilder::LoadTweens(Component *c, xml_node<> *componentXml) c->SetTweens(CreateTweenInstance(componentXml)); } -TweenSets *PageBuilder::CreateTweenInstance(xml_node<> *componentXml) +AnimationEvents *PageBuilder::CreateTweenInstance(xml_node<> *componentXml) { - TweenSets *tweens = new TweenSets(); + AnimationEvents *tweens = new AnimationEvents(); - BuildTweenAttributes(tweens, componentXml, "onEnter", "enter"); - BuildTweenAttributes(tweens, componentXml, "onExit", "exit"); - BuildTweenAttributes(tweens, componentXml, "onIdle", "idle"); - BuildTweenAttributes(tweens, componentXml, "onHighlightEnter", "highlightEnter"); - BuildTweenAttributes(tweens, componentXml, "onHighlightExit", "highlightExit"); - BuildTweenAttributes(tweens, componentXml, "onMenuEnter", "menuEnter"); - BuildTweenAttributes(tweens, componentXml, "onMenuExit", "menuExit"); + BuildTweenSet(tweens, componentXml, "onEnter", "enter"); + BuildTweenSet(tweens, componentXml, "onExit", "exit"); + BuildTweenSet(tweens, componentXml, "onIdle", "idle"); + BuildTweenSet(tweens, componentXml, "onHighlightEnter", "highlightEnter"); + BuildTweenSet(tweens, componentXml, "onHighlightExit", "highlightExit"); + BuildTweenSet(tweens, componentXml, "onMenuEnter", "menuEnter"); + BuildTweenSet(tweens, componentXml, "onMenuExit", "menuExit"); return tweens; } -void PageBuilder::BuildTweenAttributes(TweenSets *tweens, xml_node<> *componentXml, std::string tagName, std::string tweenName) +void PageBuilder::BuildTweenSet(AnimationEvents *tweens, xml_node<> *componentXml, std::string tagName, std::string tweenName) { for(componentXml = componentXml->first_node(tagName.c_str()); componentXml; componentXml = componentXml->next_sibling(tagName.c_str())) { xml_attribute<> *indexXml = componentXml->first_attribute("menuIndex"); int index = (indexXml) ? Utils::ConvertInt(indexXml->value()) : -1; - TweenSets::TweenAttributes *sets = new TweenSets::TweenAttributes(); - GetTweenAttributes(componentXml, sets); - tweens->SetTween(tweenName, index, sets); + Animation *animation = new Animation(); + GetTweenSet(componentXml, animation); + tweens->SetAnimation(tweenName, index, animation); } } @@ -560,7 +560,7 @@ ScrollingList * PageBuilder::BuildMenu(xml_node<> *menuXml) void PageBuilder::BuildCustomMenu(ScrollingList *menu, xml_node<> *menuXml, xml_node<> *itemDefaults) { std::vector *points = new std::vector(); - std::vector *tweenPoints = new std::vector(); + std::vector *tweenPoints = new std::vector(); int i = 0; @@ -587,7 +587,7 @@ void PageBuilder::BuildCustomMenu(ScrollingList *menu, xml_node<> *menuXml, xml_ void PageBuilder::BuildVerticalMenu(ScrollingList *menu, xml_node<> *menuXml, xml_node<> *itemDefaults) { std::vector *points = new std::vector(); - std::vector *tweenPoints = new std::vector(); + std::vector *tweenPoints = new std::vector(); int selectedIndex = MENU_FIRST; std::map *> overrideItems; @@ -810,20 +810,20 @@ void PageBuilder::BuildViewInfo(xml_node<> *componentXml, ViewInfo *info, xml_no } } -void PageBuilder::GetTweenAttributes(xml_node<> *node, std::vector *> *TweenAttributes) +void PageBuilder::GetTweenSet(xml_node<> *node, Animation *animation) { if(node) { for(xml_node<> *set = node->first_node("set"); set; set = set->next_sibling("set")) { - std::vector *tweens = new std::vector(); - GetTweenSets(set, *tweens); - TweenAttributes->push_back(tweens); + TweenSet *ts = new TweenSet(); + GetAnimationEvents(set, *ts); + animation->Push(ts); } } } -void PageBuilder::GetTweenSets(xml_node<> *node, std::vector &tweens) +void PageBuilder::GetAnimationEvents(xml_node<> *node, TweenSet &tweens) { xml_attribute<> *durationXml = node->first_attribute("duration"); @@ -903,7 +903,7 @@ void PageBuilder::GetTweenSets(xml_node<> *node, std::vector &tweens) } Tween *t = new Tween(property, algorithm, fromValue, toValue, durationValue); - tweens.push_back(t); + tweens.Push(t); } else { diff --git a/RetroFE/Source/Graphics/PageBuilder.h b/RetroFE/Source/Graphics/PageBuilder.h index cb575f6..fdc8986 100644 --- a/RetroFE/Source/Graphics/PageBuilder.h +++ b/RetroFE/Source/Graphics/PageBuilder.h @@ -53,14 +53,14 @@ private: void BuildViewInfo(rapidxml::xml_node<> *componentXml, ViewInfo *info, rapidxml::xml_node<> *defaultXml = NULL); bool BuildComponents(rapidxml::xml_node<> *layout, Page *page); void LoadTweens(Component *c, rapidxml::xml_node<> *componentXml); - TweenSets *CreateTweenInstance(rapidxml::xml_node<> *componentXml); - void BuildTweenAttributes(TweenSets *tweens, rapidxml::xml_node<> *componentXml, std::string tagName, std::string tweenName); + AnimationEvents *CreateTweenInstance(rapidxml::xml_node<> *componentXml); + void BuildTweenSet(AnimationEvents *tweens, rapidxml::xml_node<> *componentXml, std::string tagName, std::string tweenName); ScrollingList * BuildMenu(rapidxml::xml_node<> *menuXml); void BuildCustomMenu(ScrollingList *menu, rapidxml::xml_node<> *menuXml, rapidxml::xml_node<> *itemDefaults); void BuildVerticalMenu(ScrollingList *menu, rapidxml::xml_node<> *menuXml, rapidxml::xml_node<> *itemDefaults); int ParseMenuPosition(std::string strIndex); rapidxml::xml_attribute<> *FindAttribute(rapidxml::xml_node<> *componentXml, std::string attribute, rapidxml::xml_node<> *defaultXml); - void GetTweenAttributes(rapidxml::xml_node<> *node, std::vector *> *TweenAttributes); - void GetTweenSets(rapidxml::xml_node<> *node, std::vector &tweens); + void GetTweenSet(rapidxml::xml_node<> *node, Animation *animation); + void GetAnimationEvents(rapidxml::xml_node<> *node, TweenSet &tweens); ViewInfo * CreateMenuItemInfo(rapidxml::xml_node<> *component, rapidxml::xml_node<> *defaults, float y); };