From 52317560c464d4f9357706da77721b7805be2898 Mon Sep 17 00:00:00 2001 From: Don Honerbrink Date: Tue, 17 Feb 2015 17:21:17 -0600 Subject: [PATCH] Starting efforts (does not compile). --- RetroFE/Source/Graphics/Animate/TweenSets.cpp | 44 +---- RetroFE/Source/Graphics/Animate/TweenSets.h | 15 +- .../Source/Graphics/Component/Component.cpp | 46 ++--- RetroFE/Source/Graphics/Component/Component.h | 6 +- .../Graphics/Component/ScrollingList.cpp | 115 ++++------- .../Source/Graphics/Component/ScrollingList.h | 27 ++- .../Source/Graphics/ComponentItemBinding.cpp | 6 +- .../Source/Graphics/ComponentItemBinding.h | 8 +- .../Graphics/ComponentItemBindingBuilder.cpp | 8 +- RetroFE/Source/Graphics/Font.cpp | 25 +-- RetroFE/Source/Graphics/Font.h | 2 +- RetroFE/Source/Graphics/PageBuilder.cpp | 186 +++++++++--------- RetroFE/Source/Graphics/PageBuilder.h | 12 +- RetroFE/Source/RetroFE.cpp | 2 +- 14 files changed, 212 insertions(+), 290 deletions(-) diff --git a/RetroFE/Source/Graphics/Animate/TweenSets.cpp b/RetroFE/Source/Graphics/Animate/TweenSets.cpp index a176d06..9882e40 100644 --- a/RetroFE/Source/Graphics/Animate/TweenSets.cpp +++ b/RetroFE/Source/Graphics/Animate/TweenSets.cpp @@ -19,62 +19,32 @@ 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) +TweenSets::TweenAttributes &TweenSets::GetTween(std::string tween) { return GetTween(tween, -1); } -TweenSets::TweenAttributes *TweenSets::GetTween(std::string tween, int index) +TweenSets::TweenAttributes &TweenSets::GetTween(std::string tween, int index) { return FindTween(TweenMap[tween], index); } -void TweenSets::SetTween(std::string tween, int index, TweenAttributes *set) +void TweenSets::ImportTween(std::string tween, int index, TweenAttributes &set) { TweenMap[tween][index] = set; } -TweenSets::TweenAttributes *TweenSets::FindTween(std::map &tweens, int index) +TweenSets::TweenAttributes &TweenSets::FindTween(std::map &tweens, int index) { if(tweens.find(index) == tweens.end()) { @@ -82,12 +52,10 @@ TweenSets::TweenAttributes *TweenSets::FindTween(std::mapat(index); } - - diff --git a/RetroFE/Source/Graphics/Animate/TweenSets.h b/RetroFE/Source/Graphics/Animate/TweenSets.h index ef23aa8..377f6a7 100644 --- a/RetroFE/Source/Graphics/Animate/TweenSets.h +++ b/RetroFE/Source/Graphics/Animate/TweenSets.h @@ -24,17 +24,14 @@ class TweenSets { public: TweenSets(); - TweenSets(TweenSets ©); ~TweenSets(); - typedef std::vector *> TweenAttributes; + typedef std::vector> TweenAttributes; - TweenAttributes *GetTween(std::string tween); - TweenAttributes *GetTween(std::string tween, int index); - void SetTween(std::string tween, int index, TweenAttributes *set); + TweenAttributes &GetTween(std::string tween); + TweenAttributes &GetTween(std::string tween, int index); + void ImportTween(std::string tween, int index, TweenAttributes &set); private: - TweenAttributes *FindTween(std::map &tweens, int index); - void DestroyTweens(); - - std::map > TweenMap; + TweenAttributes &FindTween(std::map &tweens, int index); + std::map > TweenMap; }; diff --git a/RetroFE/Source/Graphics/Component/Component.cpp b/RetroFE/Source/Graphics/Component/Component.cpp index 8d9046b..81a8f00 100644 --- a/RetroFE/Source/Graphics/Component/Component.cpp +++ b/RetroFE/Source/Graphics/Component/Component.cpp @@ -151,12 +151,12 @@ void Component::SetCollectionName(std::string collectionName) CollectionName = collectionName; } -TweenSets *Component::GetTweens() +TweenSets &Component::GetTweens() { return Tweens; } -void Component::SetTweens(TweenSets *set) +void Component::ImportTweens(TweenSets &set) { Tweens = set; CurrentAnimationState = IDLE; @@ -219,7 +219,7 @@ void Component::Update(float dt) case ENTER: - CurrentTweens = Tweens->GetTween("enter", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("enter", MenuEnterIndex); CurrentAnimationState = HIGHLIGHT_ENTER; break; @@ -229,7 +229,7 @@ void Component::Update(float dt) break; case HIGHLIGHT_ENTER: - CurrentTweens = Tweens->GetTween("idle", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("idle", MenuEnterIndex); CurrentAnimationState = IDLE; break; @@ -242,13 +242,13 @@ void Component::Update(float dt) } else if(MenuExitRequested && (!MenuEnterRequested || MenuExitRequested <= MenuEnterRequested)) { - CurrentTweens = Tweens->GetTween("menuExit", MenuExitIndex); + CurrentTweens = Tweens.GetTween("menuExit", MenuExitIndex); CurrentAnimationState = MENU_EXIT; MenuExitRequested = false; } else if(MenuEnterRequested && (!MenuExitRequested || MenuExitRequested > MenuEnterRequested)) { - CurrentTweens = Tweens->GetTween("menuEnter", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("menuEnter", MenuEnterIndex); CurrentAnimationState = MENU_ENTER; MenuEnterRequested = false; @@ -256,17 +256,17 @@ void Component::Update(float dt) else if(MenuScrollRequested) { MenuScrollRequested = false; - CurrentTweens = Tweens->GetTween("menuScroll", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("menuScroll", MenuEnterIndex); CurrentAnimationState = MENU_SCROLL; } else if(IsScrollActive() || NewItemSelected || ExitRequested) { - CurrentTweens = Tweens->GetTween("highlightExit", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("highlightExit", MenuEnterIndex); CurrentAnimationState = HIGHLIGHT_EXIT; } else { - CurrentTweens = Tweens->GetTween("idle", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("idle", MenuEnterIndex); CurrentAnimationState = IDLE; } break; @@ -278,14 +278,14 @@ void Component::Update(float dt) if(ExitRequested && (CurrentAnimationState == HIGHLIGHT_WAIT)) { - CurrentTweens = Tweens->GetTween("highlightExit", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("highlightExit", MenuEnterIndex); CurrentAnimationState = HIGHLIGHT_EXIT; } else if(ExitRequested && (CurrentAnimationState == HIGHLIGHT_EXIT)) { - CurrentTweens = Tweens->GetTween("exit", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("exit", MenuEnterIndex); CurrentAnimationState = EXIT; ExitRequested = false; } @@ -296,7 +296,7 @@ void Component::Update(float dt) } else if(NewItemSelected) { - CurrentTweens = Tweens->GetTween("highlightEnter", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("highlightEnter", MenuEnterIndex); CurrentAnimationState = HIGHLIGHT_ENTER; HighlightExitComplete = true; NewItemSelected = false; @@ -311,19 +311,19 @@ void Component::Update(float dt) case HIDDEN: if(EnterRequested || ExitRequested) { - CurrentTweens = Tweens->GetTween("enter", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("enter", MenuEnterIndex); CurrentAnimationState = ENTER; } else if(MenuExitRequested && (!MenuEnterRequested || MenuExitRequested <= MenuEnterRequested)) { - CurrentTweens = Tweens->GetTween("menuExit", MenuExitIndex); + CurrentTweens = Tweens.GetTween("menuExit", MenuExitIndex); CurrentAnimationState = MENU_EXIT; MenuExitRequested = false; } else if(MenuEnterRequested && (!MenuExitRequested || MenuExitRequested > MenuEnterRequested)) { - CurrentTweens = Tweens->GetTween("menuEnter", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("menuEnter", MenuEnterIndex); CurrentAnimationState = MENU_ENTER; MenuEnterRequested = false; @@ -331,7 +331,7 @@ void Component::Update(float dt) else if(MenuScrollRequested) { MenuScrollRequested = false; - CurrentTweens = Tweens->GetTween("menuScroll", MenuEnterIndex); + CurrentTweens = Tweens.GetTween("menuScroll", MenuEnterIndex); CurrentAnimationState = MENU_SCROLL; } else @@ -382,26 +382,26 @@ bool Component::Animate(bool loop) else if(CurrentTweens) { bool currentDone = true; - std::vector *TweenSets = CurrentTweens->at(CurrentTweenIndex); + std::vector &TweenSets = CurrentTweens->at(CurrentTweenIndex); - for(unsigned int i = 0; i < TweenSets->size(); i++) + for(unsigned int i = 0; i < TweenSets.size(); i++) { - Tween *tween = TweenSets->at(i); + Tween &tween = TweenSets.at(i); float elapsedTime = ElapsedTweenTime; //todo: too many levels of nesting - if(elapsedTime < tween->GetDuration()) + if(elapsedTime < tween.GetDuration()) { currentDone = false; } else { - elapsedTime = tween->GetDuration(); + elapsedTime = tween.GetDuration(); } - float value = tween->Animate(elapsedTime); + float value = tween.Animate(elapsedTime); - switch(tween->GetProperty()) + switch(tween.GetProperty()) { case TWEEN_PROPERTY_X: GetBaseViewInfo()->SetX(value); diff --git a/RetroFE/Source/Graphics/Component/Component.h b/RetroFE/Source/Graphics/Component/Component.h index de42121..c591701 100644 --- a/RetroFE/Source/Graphics/Component/Component.h +++ b/RetroFE/Source/Graphics/Component/Component.h @@ -48,8 +48,8 @@ public: virtual void Update(float dt); virtual void Draw(); - TweenSets *GetTweens(); - void SetTweens(TweenSets *set); + TweenSets &GetTweens(); + void ImportTweens(TweenSets &set); ViewInfo *GetBaseViewInfo(); void UpdateBaseViewInfo(ViewInfo &info); bool IsScrollActive() const; @@ -87,7 +87,7 @@ private: bool Animate(bool loop); bool IsTweenSequencingComplete(); - TweenSets *Tweens; + TweenSets Tweens; TweenSets::TweenAttributes *CurrentTweens; Item *SelectedItem; SDL_Texture *BackgroundTexture; diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index 7d42e33..e5b97dc 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -89,11 +89,8 @@ void ScrollingList::SetItems(std::vector *spriteList) { for(unsigned int i = 0; i < originalSize; ++i) { - Item *newItem = new Item(); - Item *originalItem = SpriteList->at(i)->GetCollectionItem(); - - *newItem = *originalItem; - ComponentItemBinding *newSprite = new ComponentItemBinding(newItem); + Item newItem = SpriteList->at(i).GetCollectionItem(); + ComponentItemBinding newSprite(newItem); SpriteList->push_back(newSprite); } } @@ -157,9 +154,9 @@ void ScrollingList::AllocateSpritePoints() { AllocateTexture(SpriteList->at(spriteIndex)); Component *c = SpriteList->at(spriteIndex)->GetComponent(); - ViewInfo *currentViewInfo = ScrollPoints->at(i); + ViewInfo ¤tViewInfo = ScrollPoints->at(i); unsigned int nextI = GetNextTween(i, ScrollPoints); - ViewInfo *nextViewInfo = ScrollPoints->at(nextI); + ViewInfo &nextViewInfo = ScrollPoints->at(nextI); ResetTweens(c, TweenPoints->at(i), currentViewInfo, nextViewInfo, 0); @@ -575,24 +572,12 @@ 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, TweenSets &sets, ViewInfo ¤tViewInfo, ViewInfo &nextViewInfo, double scrollTime) { if(!c) { return; } - if(!sets) - { - return; - } - if(!currentViewInfo) - { - return; - } - if(!nextViewInfo) - { - return; - } currentViewInfo->SetImageHeight(c->GetBaseViewInfo()->GetImageHeight()); currentViewInfo->SetImageWidth(c->GetBaseViewInfo()->GetImageWidth()); @@ -600,31 +585,15 @@ void ScrollingList::ResetTweens(Component *c, TweenSets *sets, ViewInfo *current nextViewInfo->SetImageWidth(c->GetBaseViewInfo()->GetImageWidth()); nextViewInfo->SetBackgroundAlpha(c->GetBaseViewInfo()->GetBackgroundAlpha()); - //todo: delete properly, memory leak (big), proof of concept c->SetTweens(sets); - TweenSets::TweenAttributes *scrollTween = sets->GetTween("menuScroll"); + TweenSets::TweenAttributes &scrollTween = sets->GetTween("menuScroll"); TweenSets::TweenAttributes::iterator it = scrollTween->begin(); + scrollTween.clear(); - 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(); + c->UpdateBaseViewInfo(currentViewInfo); - } - - scrollTween->clear(); - c->UpdateBaseViewInfo(*currentViewInfo); - - std::vector *set = new std::vector(); + std::vector set; 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)); @@ -637,7 +606,7 @@ void ScrollingList::ResetTweens(Component *c, TweenSets *sets, ViewInfo *current 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); + scrollTween.push_back(set); } @@ -715,11 +684,11 @@ void ScrollingList::Draw(unsigned int layer) for(unsigned int i = 0; i < ScrollPoints->size(); i++) { - ComponentItemBinding *s = SpriteList->at(spriteIndex); + ComponentItemBinding &s = SpriteList->at(spriteIndex); Component *c = s->GetComponent(); - ViewInfo *currentViewInfo = ScrollPoints->at(i); + ViewInfo ¤tViewInfo = ScrollPoints->at(i); - if(c && currentViewInfo && currentViewInfo->GetLayer() == layer) + if(c && currentViewInfo.GetLayer() == layer) { c->Draw(); } @@ -766,37 +735,35 @@ void ScrollingList::RemoveSelectedItem() } -std::vector *ScrollingList::GetCollectionItemSprites() +std::vector *ScrollingList::GetCollectionItemSprites() { return SpriteList; } ComponentItemBinding* ScrollingList::GetSelectedCollectionItemSprite() { - ComponentItemBinding *item = NULL; - if(SpriteList && SpriteList->size() > 0) { int index = (FirstSpriteIndex + SelectedSpriteListIndex) % SpriteList->size(); - - item = SpriteList->at(index); + ComponentItemBinding item = &SpriteList->at(index); + return &item; } - return item; + return NULL; } ComponentItemBinding* ScrollingList::GetPendingCollectionItemSprite() { - ComponentItemBinding *item = NULL; unsigned int index = FirstSpriteIndex; if(SpriteList && SpriteList->size() > 0) { index = (index + SelectedSpriteListIndex) % SpriteList->size(); - item = SpriteList->at(index); - } + ComponentItemBinding item = &SpriteList->at(index); + return &item; + } - return item; + return NULL; } void ScrollingList::AddComponentForNotifications(MenuNotifierInterface *c) @@ -820,30 +787,31 @@ void ScrollingList::RemoveComponentForNotifications(MenuNotifierInterface *c) ComponentItemBinding* ScrollingList::GetPendingSelectedCollectionItemSprite() { - ComponentItemBinding *item = NULL; - - if(SpriteList) + if(!SpriteList) { - unsigned int index = SelectedSpriteListIndex; + return NULL; - if(CurrentScrollDirection == ScrollDirectionBack) - { - CircularDecrement(index, SpriteList); - } - if(CurrentScrollDirection == ScrollDirectionForward) - { - CircularIncrement(index, SpriteList); - } + } + unsigned int index = SelectedSpriteListIndex; - if(SpriteList && SpriteList->size() > 0) - { - index = (index + SelectedSpriteListIndex) % SpriteList->size(); - - item = SpriteList->at(index); - } + if(CurrentScrollDirection == ScrollDirectionBack) + { + CircularDecrement(index, SpriteList); + } + if(CurrentScrollDirection == ScrollDirectionForward) + { + CircularIncrement(index, SpriteList); } - return item; + if(SpriteList && SpriteList->size() > 0) + { + index = (index + SelectedSpriteListIndex) % SpriteList->size(); + + ComponentItemBinding &item = SpriteList->at(index); + return &item; + } + + return NULL; } bool ScrollingList::IsIdle() @@ -921,4 +889,3 @@ void ScrollingList::CircularDecrement(unsigned int &index, std::vector *spriteList); + 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(); @@ -69,7 +69,7 @@ public: ComponentItemBinding *GetPendingSelectedCollectionItemSprite(); void AddComponentForNotifications(MenuNotifierInterface *c); void RemoveComponentForNotifications(MenuNotifierInterface *c); - std::vector *GetCollectionItemSprites(); + std::vector GetCollectionItemSprites(); void RemoveSelectedItem(); void FreeGraphicsMemory(); void Update(float dt); @@ -83,8 +83,8 @@ private: void DeallocateSpritePoints(); 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); + unsigned int GetNextTween(unsigned int currentIndex, std::vector *list); + void ResetTweens(Component *c, TweenSets &sets, ViewInfo ¤tViewInfo, ViewInfo &nextViewInfo, double scrollTime); enum ScrollState { @@ -94,9 +94,9 @@ private: ScrollStateIdle }; - std::vector *SpriteList; - std::vector *ScrollPoints; - std::vector *TweenPoints; + std::vector *SpriteList; + std::vector *ScrollPoints; + std::vector *TweenPoints; std::vector NotificationComponents; float TweenEnterTime; bool Focus; @@ -112,11 +112,11 @@ private: float StartScrollTime; float ScrollPeriod; - int CircularIncrement(unsigned int index, unsigned int offset, std::vector *list); - void CircularIncrement(unsigned &index, std::vector *list); - void CircularDecrement(unsigned &index, std::vector *list); - void CircularIncrement(unsigned &index, std::vector *list); - void CircularDecrement(unsigned &index, std::vector *list); + int CircularIncrement(unsigned int index, unsigned int offset, std::vector *list); + void CircularIncrement(unsigned &index, std::vector *list); + void CircularDecrement(unsigned &index, std::vector *list); + void CircularIncrement(unsigned &index, std::vector *list); + void CircularDecrement(unsigned &index, std::vector *list); void UpdateOffset(float dt); std::string Collection; @@ -129,4 +129,3 @@ private: std::string ImageType; unsigned int MaxLayer; }; - diff --git a/RetroFE/Source/Graphics/ComponentItemBinding.cpp b/RetroFE/Source/Graphics/ComponentItemBinding.cpp index ec9651e..32e4f15 100644 --- a/RetroFE/Source/Graphics/ComponentItemBinding.cpp +++ b/RetroFE/Source/Graphics/ComponentItemBinding.cpp @@ -15,13 +15,13 @@ */ #include "ComponentItemBinding.h" -ComponentItemBinding::ComponentItemBinding( Component *c, Item *item) +ComponentItemBinding::ComponentItemBinding( Component *c, Item &item) : CollectionComponent(c) , CollectionItem(item) { } -ComponentItemBinding::ComponentItemBinding(Item *item) +ComponentItemBinding::ComponentItemBinding(Item &item) : CollectionComponent(NULL) , CollectionItem(item) { @@ -31,7 +31,7 @@ ComponentItemBinding::~ComponentItemBinding() { } -Item* ComponentItemBinding::GetCollectionItem() const +Item &ComponentItemBinding::GetCollectionItem() const { return CollectionItem; } diff --git a/RetroFE/Source/Graphics/ComponentItemBinding.h b/RetroFE/Source/Graphics/ComponentItemBinding.h index 40f42eb..1c1ce6f 100644 --- a/RetroFE/Source/Graphics/ComponentItemBinding.h +++ b/RetroFE/Source/Graphics/ComponentItemBinding.h @@ -21,10 +21,10 @@ class ComponentItemBinding { public: - ComponentItemBinding(Component *c, Item *item); - ComponentItemBinding(Item *item); + ComponentItemBinding(Component *c, Item &item); + ComponentItemBinding(Item &item); virtual ~ComponentItemBinding(); - Item* GetCollectionItem() const; + Item &GetCollectionItem() const; void SetComponent(Component *c); Component* GetComponent() const; @@ -32,5 +32,5 @@ public: private: Component *CollectionComponent; - Item *CollectionItem; + Item CollectionItem; }; diff --git a/RetroFE/Source/Graphics/ComponentItemBindingBuilder.cpp b/RetroFE/Source/Graphics/ComponentItemBindingBuilder.cpp index 27d592c..aae670b 100644 --- a/RetroFE/Source/Graphics/ComponentItemBindingBuilder.cpp +++ b/RetroFE/Source/Graphics/ComponentItemBindingBuilder.cpp @@ -26,14 +26,14 @@ ComponentItemBindingBuilder::~ComponentItemBindingBuilder() { } -std::vector *ComponentItemBindingBuilder::BuildCollectionItems(std::vector *infoList) +std::vector *ComponentItemBindingBuilder::BuildCollectionItems(std::vector *infoList) { - std::vector *sprites = new std::vector(); - std::vector::iterator it; + std::vector *sprites = new std::vector(); + std::vector::iterator it; for(it = infoList->begin(); it != infoList->end(); ++it) { - ComponentItemBinding *s = new ComponentItemBinding(*it); + ComponentItemBinding s(*it); sprites->push_back(s); } diff --git a/RetroFE/Source/Graphics/Font.cpp b/RetroFE/Source/Graphics/Font.cpp index 68d90d7..c467dac 100644 --- a/RetroFE/Source/Graphics/Font.cpp +++ b/RetroFE/Source/Graphics/Font.cpp @@ -36,13 +36,13 @@ SDL_Texture *Font::GetTexture() bool Font::GetRect(unsigned int charCode, GlyphInfo &glyph) { - std::map::iterator it = Atlas.find(charCode); + std::map::iterator it = Atlas.find(charCode); if(it != Atlas.end()) { - GlyphInfoBuild *info = it->second; + GlyphInfoBuild &info = it->second; - glyph = info->Glyph; + glyph = info.Glyph; return true; } @@ -119,12 +119,12 @@ bool Font::Initialize(std::string fontPath, int fontSize, SDL_Color color) #endif SDL_Surface *atlasSurface = SDL_CreateRGBSurface(0, atlasWidth, atlasHeight, 32, rmask, gmask, bmask, amask); - std::map::iterator it; + std::map::iterator it; for(it = Atlas.begin(); it != Atlas.end(); it++) { - GlyphInfoBuild *info = it->second; - SDL_BlitSurface(info->Surface, NULL, atlasSurface, &info->Glyph.Rect); - SDL_FreeSurface(info->Surface); + GlyphInfoBuild &info = it->second; + SDL_BlitSurface(info.Surface, NULL, atlasSurface, &info.Glyph.Rect); + SDL_FreeSurface(info.Surface); info->Surface = NULL; } SDL_LockMutex(SDL::GetMutex()); @@ -149,13 +149,6 @@ void Font::DeInitialize() Texture = NULL; SDL_UnlockMutex(SDL::GetMutex()); } - - std::map::iterator atlasIt = Atlas.begin(); - while(atlasIt != Atlas.end()) - { - delete atlasIt->second; - Atlas.erase(atlasIt); - atlasIt = Atlas.begin(); - } - + + Atlas.clear(); } diff --git a/RetroFE/Source/Graphics/Font.h b/RetroFE/Source/Graphics/Font.h index a9d0561..2ea1ddb 100644 --- a/RetroFE/Source/Graphics/Font.h +++ b/RetroFE/Source/Graphics/Font.h @@ -47,6 +47,6 @@ private: SDL_Surface *Surface; }; - std::map Atlas; + std::map Atlas; SDL_Texture *Texture; }; diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index f5abc8c..61e8a1f 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -467,10 +467,9 @@ void PageBuilder::LoadTweens(Component *c, xml_node<> *componentXml) c->SetTweens(CreateTweenInstance(componentXml)); } -TweenSets *PageBuilder::CreateTweenInstance(xml_node<> *componentXml) +TweenSets PageBuilder::CreateTweenInstance(xml_node<> *componentXml) { - TweenSets *tweens = new TweenSets(); - + TweenSets tweens; BuildTweenAttributes(tweens, componentXml, "onEnter", "enter"); BuildTweenAttributes(tweens, componentXml, "onExit", "exit"); BuildTweenAttributes(tweens, componentXml, "onIdle", "idle"); @@ -482,16 +481,16 @@ TweenSets *PageBuilder::CreateTweenInstance(xml_node<> *componentXml) return tweens; } -void PageBuilder::BuildTweenAttributes(TweenSets *tweens, xml_node<> *componentXml, std::string tagName, std::string tweenName) +void PageBuilder::BuildTweenAttributes(TweenSets &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(); + TweenSets::TweenAttributes sets; GetTweenAttributes(componentXml, sets); - tweens->SetTween(tweenName, index, sets); + tweens.ImportTween(tweenName, index, sets); } } @@ -559,15 +558,15 @@ 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 *points = new std::vector(); + std::vector *tweenPoints = new std::vector(); int i = 0; for(xml_node<> *componentXml = menuXml->first_node("item"); componentXml; componentXml = componentXml->next_sibling("item")) { - ViewInfo *viewInfo = new ViewInfo(); - BuildViewInfo(componentXml, viewInfo, itemDefaults); + ViewInfo viewInfo; + BuildViewInfo(componentXml, &viewInfo, itemDefaults); points->push_back(viewInfo); tweenPoints->push_back(CreateTweenInstance(componentXml)); @@ -586,8 +585,8 @@ 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 *points = new std::vector(); + std::vector *tweenPoints = new std::vector(); int selectedIndex = MENU_FIRST; std::map *> overrideItems; @@ -630,7 +629,7 @@ void PageBuilder::BuildVerticalMenu(ScrollingList *menu, xml_node<> *menuXml, xm } while(!end) { - ViewInfo *viewInfo = new ViewInfo(); + ViewInfo viewInfo; xml_node<> *component = itemDefaults; // uss overridden item setting if specified by layout for the given index @@ -690,10 +689,10 @@ void PageBuilder::BuildVerticalMenu(ScrollingList *menu, xml_node<> *menuXml, xm menu->SetPoints(points, tweenPoints); } -ViewInfo *PageBuilder::CreateMenuItemInfo(xml_node<> *component, xml_node<> *defaults, float y) +ViewInfo PageBuilder::CreateMenuItemInfo(xml_node<> *component, xml_node<> *defaults, float y) { - ViewInfo *viewInfo = new ViewInfo(); - BuildViewInfo(component, viewInfo, defaults); + ViewInfo viewInfo; + BuildViewInfo(component, &viewInfo, defaults); viewInfo->SetY(y); return viewInfo; } @@ -810,107 +809,106 @@ void PageBuilder::BuildViewInfo(xml_node<> *componentXml, ViewInfo *info, xml_no } } -void PageBuilder::GetTweenAttributes(xml_node<> *node, std::vector *> *TweenAttributes) +void PageBuilder::GetTweenAttributes(xml_node<> *node, TweenSets::TweenAttributes &tweenAttributes) { 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); + std::vector tweens; + GetTweenSets(set, tweens); + tweenAttributes.push_back(tweens); } } } -void PageBuilder::GetTweenSets(xml_node<> *node, std::vector &tweens) +void PageBuilder::GetTweenSets(xml_node<> *node, std::vector &tweens) { xml_attribute<> *durationXml = node->first_attribute("duration"); if(!durationXml) { Logger::Write(Logger::ZONE_ERROR, "Layout", "Animation set tag missing \"duration\" attribute"); + return; } - else - { - for(xml_node<> *animate = node->first_node("animate"); animate; animate = animate->next_sibling("animate")) - { - xml_attribute<> *type = animate->first_attribute("type"); - xml_attribute<> *from = animate->first_attribute("from"); - xml_attribute<> *to = animate->first_attribute("to"); - xml_attribute<> *algorithmXml = animate->first_attribute("algorithm"); - if(!type) + for(xml_node<> *animate = node->first_node("animate"); animate; animate = animate->next_sibling("animate")) + { + xml_attribute<> *type = animate->first_attribute("type"); + xml_attribute<> *from = animate->first_attribute("from"); + xml_attribute<> *to = animate->first_attribute("to"); + xml_attribute<> *algorithmXml = animate->first_attribute("algorithm"); + + if(!type) + { + Logger::Write(Logger::ZONE_ERROR, "Layout", "Animate tag missing \"type\" attribute"); + } + else if(!from) + { + Logger::Write(Logger::ZONE_ERROR, "Layout", "Animate tag missing \"from\" attribute"); + } + else if(!to) + { + Logger::Write(Logger::ZONE_ERROR, "Layout", "Animate tag missing \"to\" attribute"); + } + else + { + float fromValue = Utils::ConvertFloat(from->value()); + float toValue = Utils::ConvertFloat(to->value()); + float durationValue = Utils::ConvertFloat(durationXml->value()); + + TweenAlgorithm algorithm = LINEAR; + TweenProperty property; + + if(algorithmXml) { - Logger::Write(Logger::ZONE_ERROR, "Layout", "Animate tag missing \"type\" attribute"); + algorithm = Tween::GetTweenType(algorithmXml->value()); + } - else if(!from) + + if(Tween::GetTweenProperty(type->value(), property)) { - Logger::Write(Logger::ZONE_ERROR, "Layout", "Animate tag missing \"from\" attribute"); - } - else if(!to) - { - Logger::Write(Logger::ZONE_ERROR, "Layout", "Animate tag missing \"to\" attribute"); + switch(property) + { + case TWEEN_PROPERTY_WIDTH: + case TWEEN_PROPERTY_X: + case TWEEN_PROPERTY_X_OFFSET: + fromValue = GetHorizontalAlignment(from, 0); + toValue = GetHorizontalAlignment(to, 0); + break; + + // x origin gets translated to a percent + case TWEEN_PROPERTY_X_ORIGIN: + fromValue = GetHorizontalAlignment(from, 0) / ScreenWidth; + toValue = GetHorizontalAlignment(to, 0) / ScreenWidth; + break; + + case TWEEN_PROPERTY_HEIGHT: + case TWEEN_PROPERTY_Y: + case TWEEN_PROPERTY_Y_OFFSET: + case TWEEN_PROPERTY_FONT_SIZE: + fromValue = GetVerticalAlignment(from, 0); + toValue = GetVerticalAlignment(to, 0); + break; + + // y origin gets translated to a percent + case TWEEN_PROPERTY_Y_ORIGIN: + fromValue = GetVerticalAlignment(from, 0) / ScreenHeight; + toValue = GetVerticalAlignment(to, 0) / ScreenHeight; + break; + + default: + break; + } + + Tween t(property, algorithm, fromValue, toValue, durationValue); + tweens.push_back(t); } else { - float fromValue = Utils::ConvertFloat(from->value()); - float toValue = Utils::ConvertFloat(to->value()); - float durationValue = Utils::ConvertFloat(durationXml->value()); - - TweenAlgorithm algorithm = LINEAR; - TweenProperty property; - - if(algorithmXml) - { - algorithm = Tween::GetTweenType(algorithmXml->value()); - - } - - if(Tween::GetTweenProperty(type->value(), property)) - { - switch(property) - { - case TWEEN_PROPERTY_WIDTH: - case TWEEN_PROPERTY_X: - case TWEEN_PROPERTY_X_OFFSET: - fromValue = GetHorizontalAlignment(from, 0); - toValue = GetHorizontalAlignment(to, 0); - break; - - // x origin gets translated to a percent - case TWEEN_PROPERTY_X_ORIGIN: - fromValue = GetHorizontalAlignment(from, 0) / ScreenWidth; - toValue = GetHorizontalAlignment(to, 0) / ScreenWidth; - break; - - case TWEEN_PROPERTY_HEIGHT: - case TWEEN_PROPERTY_Y: - case TWEEN_PROPERTY_Y_OFFSET: - case TWEEN_PROPERTY_FONT_SIZE: - fromValue = GetVerticalAlignment(from, 0); - toValue = GetVerticalAlignment(to, 0); - break; - - // y origin gets translated to a percent - case TWEEN_PROPERTY_Y_ORIGIN: - fromValue = GetVerticalAlignment(from, 0) / ScreenHeight; - toValue = GetVerticalAlignment(to, 0) / ScreenHeight; - break; - - default: - break; - } - - Tween *t = new Tween(property, algorithm, fromValue, toValue, durationValue); - tweens.push_back(t); - } - else - { - std::stringstream ss; - ss << "Unsupported tween type attribute \"" << type->value() << "\""; - Logger::Write(Logger::ZONE_ERROR, "Layout", ss.str()); - } + std::stringstream ss; + ss << "Unsupported tween type attribute \"" << type->value() << "\""; + Logger::Write(Logger::ZONE_ERROR, "Layout", ss.str()); } } } diff --git a/RetroFE/Source/Graphics/PageBuilder.h b/RetroFE/Source/Graphics/PageBuilder.h index cb575f6..1de288f 100644 --- a/RetroFE/Source/Graphics/PageBuilder.h +++ b/RetroFE/Source/Graphics/PageBuilder.h @@ -39,7 +39,7 @@ private: std::string LayoutPath; Configuration &Config; float ScaleX; - float ScaleY; + float ScaleY;-> int ScreenHeight; int ScreenWidth; SDL_Color FontColor; @@ -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); + TweenSets CreateTweenInstance(rapidxml::xml_node<> *componentXml); + void BuildTweenAttributes(TweenSets &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); - ViewInfo * CreateMenuItemInfo(rapidxml::xml_node<> *component, rapidxml::xml_node<> *defaults, float y); + void GetTweenAttributes(rapidxml::xml_node<> *node, std::vector> &TweenAttributes); + void GetTweenSets(rapidxml::xml_node<> *node, std::vector &tweens); + ViewInfo CreateMenuItemInfo(rapidxml::xml_node<> *component, rapidxml::xml_node<> *defaults, float y); }; diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index cdaaeb5..10dbfa2 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -503,4 +503,4 @@ std::string RetroFE::GetLayout(std::string collectionName) } return layoutName; -} \ No newline at end of file +}