Starting efforts (does not compile).

This commit is contained in:
Don Honerbrink
2015-02-17 17:21:17 -06:00
parent 1f8441a0ce
commit 52317560c4
14 changed files with 212 additions and 290 deletions

View File

@@ -19,62 +19,32 @@
TweenSets::TweenSets()
{
}
TweenSets::TweenSets(TweenSets &copy)
{
std::map<std::string, std::map<int, TweenAttributes *> >::iterator it;
for(it = copy.TweenMap.begin(); it != copy.TweenMap.end(); it++)
{
std::map<int, TweenAttributes *>::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<std::string, std::map<int, TweenAttributes *> >::iterator it = TweenMap.begin();
while(it != TweenMap.end())
{
std::map<int, TweenAttributes *>::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<int, TweenAttributes *> &tweens, int index)
TweenSets::TweenAttributes &TweenSets::FindTween(std::map<int, TweenAttributes> &tweens, int index)
{
if(tweens.find(index) == tweens.end())
{
@@ -82,12 +52,10 @@ TweenSets::TweenAttributes *TweenSets::FindTween(std::map<int, TweenAttributes *
if(tweens.find(index) == tweens.end())
{
TweenAttributes *set = new TweenAttributes();
TweenAttributes set;
tweens[index] = set;
}
}
return tweens[index];
return tweens->at(index);
}

View File

@@ -24,17 +24,14 @@ class TweenSets
{
public:
TweenSets();
TweenSets(TweenSets &copy);
~TweenSets();
typedef std::vector<std::vector<Tween *> *> TweenAttributes;
typedef std::vector<std::vector<Tween>> 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<int, TweenAttributes *> &tweens, int index);
void DestroyTweens();
std::map<std::string, std::map<int, TweenAttributes *> > TweenMap;
TweenAttributes &FindTween(std::map<int, TweenAttributes> &tweens, int index);
std::map<std::string, std::map<int, TweenAttributes> > TweenMap;
};

View File

@@ -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<Tween *> *TweenSets = CurrentTweens->at(CurrentTweenIndex);
std::vector<Tween> &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);

View File

@@ -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;

View File

@@ -89,11 +89,8 @@ void ScrollingList::SetItems(std::vector<ComponentItemBinding *> *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 &currentViewInfo = 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 &currentViewInfo, 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<Tween *>::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<Tween *> *set = new std::vector<Tween *>();
std::vector<Tween *> 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 &currentViewInfo = 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<ComponentItemBinding *> *ScrollingList::GetCollectionItemSprites()
std::vector<ComponentItemBinding> *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<Component
}
}
}

View File

@@ -56,9 +56,9 @@ public:
bool AllocateTexture(ComponentItemBinding *s);
void DeallocateTexture(ComponentItemBinding *s);
void SetItems(std::vector<ComponentItemBinding *> *spriteList);
void SetItems(std::vector<ComponentItemBinding> *spriteList);
void DestroyItems();
void SetPoints(std::vector<ViewInfo *> *scrollPoints, std::vector<TweenSets *> *tweenPoints);
void SetPoints(std::vector<ViewInfo> *scrollPoints, std::vector<TweenSets> *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<ComponentItemBinding *> *GetCollectionItemSprites();
std::vector<ComponentItemBinding> 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<ViewInfo *> *list);
void ResetTweens(Component *c, TweenSets *sets, ViewInfo *currentViewInfo, ViewInfo *nextViewInfo, double scrollTime);
unsigned int GetNextTween(unsigned int currentIndex, std::vector<ViewInfo> *list);
void ResetTweens(Component *c, TweenSets &sets, ViewInfo &currentViewInfo, ViewInfo &nextViewInfo, double scrollTime);
enum ScrollState
{
@@ -94,9 +94,9 @@ private:
ScrollStateIdle
};
std::vector<ComponentItemBinding *> *SpriteList;
std::vector<ViewInfo *> *ScrollPoints;
std::vector<TweenSets *> *TweenPoints;
std::vector<ComponentItemBinding> *SpriteList;
std::vector<ViewInfo> *ScrollPoints;
std::vector<TweenSets> *TweenPoints;
std::vector<MenuNotifierInterface *> NotificationComponents;
float TweenEnterTime;
bool Focus;
@@ -112,11 +112,11 @@ private:
float StartScrollTime;
float ScrollPeriod;
int CircularIncrement(unsigned int index, unsigned int offset, std::vector<ComponentItemBinding *> *list);
void CircularIncrement(unsigned &index, std::vector<ComponentItemBinding *> *list);
void CircularDecrement(unsigned &index, std::vector<ComponentItemBinding *> *list);
void CircularIncrement(unsigned &index, std::vector<ViewInfo *> *list);
void CircularDecrement(unsigned &index, std::vector<ViewInfo *> *list);
int CircularIncrement(unsigned int index, unsigned int offset, std::vector<ComponentItemBinding> *list);
void CircularIncrement(unsigned &index, std::vector<ComponentItemBinding> *list);
void CircularDecrement(unsigned &index, std::vector<ComponentItemBinding> *list);
void CircularIncrement(unsigned &index, std::vector<ViewInfo> *list);
void CircularDecrement(unsigned &index, std::vector<ViewInfo> *list);
void UpdateOffset(float dt);
std::string Collection;
@@ -129,4 +129,3 @@ private:
std::string ImageType;
unsigned int MaxLayer;
};

View File

@@ -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;
}

View File

@@ -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;
};

View File

@@ -26,14 +26,14 @@ ComponentItemBindingBuilder::~ComponentItemBindingBuilder()
{
}
std::vector<ComponentItemBinding *> *ComponentItemBindingBuilder::BuildCollectionItems(std::vector<Item *> *infoList)
std::vector<ComponentItemBinding> *ComponentItemBindingBuilder::BuildCollectionItems(std::vector<Item> *infoList)
{
std::vector<ComponentItemBinding *> *sprites = new std::vector<ComponentItemBinding *>();
std::vector<Item *>::iterator it;
std::vector<ComponentItemBinding> *sprites = new std::vector<ComponentItemBinding>();
std::vector<Item>::iterator it;
for(it = infoList->begin(); it != infoList->end(); ++it)
{
ComponentItemBinding *s = new ComponentItemBinding(*it);
ComponentItemBinding s(*it);
sprites->push_back(s);
}

View File

@@ -36,13 +36,13 @@ SDL_Texture *Font::GetTexture()
bool Font::GetRect(unsigned int charCode, GlyphInfo &glyph)
{
std::map<unsigned int, GlyphInfoBuild *>::iterator it = Atlas.find(charCode);
std::map<unsigned int, GlyphInfoBuild>::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<unsigned int, GlyphInfoBuild *>::iterator it;
std::map<unsigned int, GlyphInfoBuild>::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<unsigned int, GlyphInfoBuild *>::iterator atlasIt = Atlas.begin();
while(atlasIt != Atlas.end())
{
delete atlasIt->second;
Atlas.erase(atlasIt);
atlasIt = Atlas.begin();
}
Atlas.clear();
}

View File

@@ -47,6 +47,6 @@ private:
SDL_Surface *Surface;
};
std::map<unsigned int, GlyphInfoBuild *> Atlas;
std::map<unsigned int, GlyphInfoBuild> Atlas;
SDL_Texture *Texture;
};

View File

@@ -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<ViewInfo *> *points = new std::vector<ViewInfo *>();
std::vector<TweenSets *> *tweenPoints = new std::vector<TweenSets *>();
std::vector<ViewInfo> *points = new std::vector<ViewInfo>();
std::vector<TweenSets> *tweenPoints = new std::vector<TweenSets>();
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<ViewInfo *> *points = new std::vector<ViewInfo *>();
std::vector<TweenSets *> *tweenPoints = new std::vector<TweenSets *>();
std::vector<ViewInfo> *points = new std::vector<ViewInfo>();
std::vector<TweenSets> *tweenPoints = new std::vector<TweenSets>();
int selectedIndex = MENU_FIRST;
std::map<int, xml_node<> *> 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<std::vector<Tween *> *> *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<Tween *> *tweens = new std::vector<Tween *>();
GetTweenSets(set, *tweens);
TweenAttributes->push_back(tweens);
std::vector<Tween> tweens;
GetTweenSets(set, tweens);
tweenAttributes.push_back(tweens);
}
}
}
void PageBuilder::GetTweenSets(xml_node<> *node, std::vector<Tween *> &tweens)
void PageBuilder::GetTweenSets(xml_node<> *node, std::vector<Tween> &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());
}
}
}

View File

@@ -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<std::vector<Tween *> *> *TweenAttributes);
void GetTweenSets(rapidxml::xml_node<> *node, std::vector<Tween *> &tweens);
ViewInfo * CreateMenuItemInfo(rapidxml::xml_node<> *component, rapidxml::xml_node<> *defaults, float y);
void GetTweenAttributes(rapidxml::xml_node<> *node, std::vector<std::vector<Tween>> &TweenAttributes);
void GetTweenSets(rapidxml::xml_node<> *node, std::vector<Tween> &tweens);
ViewInfo CreateMenuItemInfo(rapidxml::xml_node<> *component, rapidxml::xml_node<> *defaults, float y);
};

View File

@@ -503,4 +503,4 @@ std::string RetroFE::GetLayout(std::string collectionName)
}
return layoutName;
}
}