Setting code formatting standard to allman.

This commit is contained in:
emb
2015-01-01 14:08:42 -06:00
parent 174ea4f4f9
commit 6410139f87
76 changed files with 5352 additions and 5314 deletions

View File

@@ -8,34 +8,34 @@
Component::Component()
{
OnEnterTweens = NULL;
OnExitTweens = NULL;
OnIdleTweens = NULL;
OnHighlightEnterTweens = NULL;
OnHighlightExitTweens = NULL;
SelectedItem = NULL;
NewItemSelectedSinceEnter = false;
FreeGraphicsMemory();
OnEnterTweens = NULL;
OnExitTweens = NULL;
OnIdleTweens = NULL;
OnHighlightEnterTweens = NULL;
OnHighlightExitTweens = NULL;
SelectedItem = NULL;
NewItemSelectedSinceEnter = false;
FreeGraphicsMemory();
}
Component::~Component()
{
FreeGraphicsMemory();
FreeGraphicsMemory();
}
void Component::FreeGraphicsMemory()
{
CurrentAnimationState = HIDDEN;
EnterRequested = false;
ExitRequested = false;
NewItemSelected = false;
HighlightExitComplete = false;
CurrentTweens = NULL;
CurrentTweenIndex = 0;
CurrentTweenComplete = false;
ElapsedTweenTime =0;
ScrollActive = false;
CurrentAnimationState = HIDDEN;
EnterRequested = false;
ExitRequested = false;
NewItemSelected = false;
HighlightExitComplete = false;
CurrentTweens = NULL;
CurrentTweenIndex = 0;
CurrentTweenComplete = false;
ElapsedTweenTime =0;
ScrollActive = false;
}
void Component::AllocateGraphicsMemory()
{
@@ -43,240 +43,240 @@ void Component::AllocateGraphicsMemory()
void Component::TriggerEnterEvent()
{
EnterRequested = true;
EnterRequested = true;
}
void Component::TriggerExitEvent()
{
ExitRequested = true;
ExitRequested = true;
}
void Component::TriggerHighlightEvent(Item *selectedItem)
{
NewItemSelected = true;
this->SelectedItem = selectedItem;
NewItemSelected = true;
this->SelectedItem = selectedItem;
}
bool Component::IsIdle()
{
return (CurrentAnimationState == IDLE);
return (CurrentAnimationState == IDLE);
}
bool Component::IsHidden()
{
return (CurrentAnimationState == HIDDEN);
return (CurrentAnimationState == HIDDEN);
}
bool Component::IsWaiting()
{
return (CurrentAnimationState == HIGHLIGHT_WAIT);
return (CurrentAnimationState == HIGHLIGHT_WAIT);
}
void Component::Update(float dt)
{
ElapsedTweenTime += dt;
HighlightExitComplete = false;
if(IsHidden() || IsWaiting() || (IsIdle() && ExitRequested))
{
CurrentTweenComplete = true;
}
ElapsedTweenTime += dt;
HighlightExitComplete = false;
if(IsHidden() || IsWaiting() || (IsIdle() && ExitRequested))
{
CurrentTweenComplete = true;
}
if(CurrentTweenComplete)
{
CurrentTweens = NULL;
if(CurrentTweenComplete)
{
CurrentTweens = NULL;
// There was no request to override our state path. Continue on as normal.
switch(CurrentAnimationState)
{
case ENTER:
// There was no request to override our state path. Continue on as normal.
switch(CurrentAnimationState)
{
case ENTER:
CurrentTweens = OnHighlightEnterTweens;
CurrentAnimationState = HIGHLIGHT_ENTER;
break;
case EXIT:
case EXIT:
CurrentTweens = NULL;
CurrentAnimationState = HIDDEN;
break;
case HIGHLIGHT_ENTER:
case HIGHLIGHT_ENTER:
CurrentTweens = OnIdleTweens;
CurrentAnimationState = IDLE;
break;
case IDLE:
case IDLE:
// prevent us from automatically jumping to the exit tween upon enter
if(EnterRequested)
{
EnterRequested = false;
NewItemSelected = false;
EnterRequested = false;
NewItemSelected = false;
}
else if(IsScrollActive() || NewItemSelected || ExitRequested)
{
CurrentTweens = OnHighlightExitTweens;
CurrentAnimationState = HIGHLIGHT_EXIT;
CurrentTweens = OnHighlightExitTweens;
CurrentAnimationState = HIGHLIGHT_EXIT;
}
else
{
CurrentTweens = OnIdleTweens;
CurrentAnimationState = IDLE;
CurrentTweens = OnIdleTweens;
CurrentAnimationState = IDLE;
}
break;
case HIGHLIGHT_EXIT:
case HIGHLIGHT_EXIT:
// intentionally break down
case HIGHLIGHT_WAIT:
// intentionally break down
case HIGHLIGHT_WAIT:
if(ExitRequested && (CurrentAnimationState == HIGHLIGHT_WAIT))
{
CurrentTweens = OnHighlightExitTweens;
CurrentAnimationState = HIGHLIGHT_EXIT;
CurrentTweens = OnHighlightExitTweens;
CurrentAnimationState = HIGHLIGHT_EXIT;
}
else if(ExitRequested && (CurrentAnimationState == HIGHLIGHT_EXIT))
{
CurrentTweens = OnExitTweens;
CurrentAnimationState = EXIT;
ExitRequested = false;
CurrentTweens = OnExitTweens;
CurrentAnimationState = EXIT;
ExitRequested = false;
}
else if(IsScrollActive())
{
CurrentTweens = NULL;
CurrentAnimationState = HIGHLIGHT_WAIT;
CurrentTweens = NULL;
CurrentAnimationState = HIGHLIGHT_WAIT;
}
else if(NewItemSelected)
{
CurrentTweens = OnHighlightEnterTweens;
CurrentAnimationState = HIGHLIGHT_ENTER;
HighlightExitComplete = true;
NewItemSelected = false;
CurrentTweens = OnHighlightEnterTweens;
CurrentAnimationState = HIGHLIGHT_ENTER;
HighlightExitComplete = true;
NewItemSelected = false;
}
else
{
CurrentTweens = NULL;
CurrentAnimationState = HIGHLIGHT_WAIT;
CurrentTweens = NULL;
CurrentAnimationState = HIGHLIGHT_WAIT;
}
break;
case HIDDEN:
case HIDDEN:
if(EnterRequested || ExitRequested)
{
CurrentTweens = OnEnterTweens;
CurrentAnimationState = ENTER;
CurrentTweens = OnEnterTweens;
CurrentAnimationState = ENTER;
}
else
{
CurrentTweens = NULL;
CurrentAnimationState = HIDDEN;
CurrentTweens = NULL;
CurrentAnimationState = HIDDEN;
}
}
}
CurrentTweenIndex = 0;
CurrentTweenComplete = false;
CurrentTweenIndex = 0;
CurrentTweenComplete = false;
ElapsedTweenTime = 0;
}
ElapsedTweenTime = 0;
}
CurrentTweenComplete = Animate(IsIdle());
CurrentTweenComplete = Animate(IsIdle());
}
bool Component::Animate(bool loop)
{
bool completeDone = false;
if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->size())
{
completeDone = true;
}
else if(CurrentTweens)
{
bool currentDone = true;
std::vector<Tween *> *tweenSet = CurrentTweens->at(CurrentTweenIndex);
bool completeDone = false;
if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->size())
{
completeDone = true;
}
else if(CurrentTweens)
{
bool currentDone = true;
std::vector<Tween *> *tweenSet = CurrentTweens->at(CurrentTweenIndex);
for(unsigned int i = 0; i < tweenSet->size(); i++)
{
Tween *tween = tweenSet->at(i);
float elapsedTime = ElapsedTweenTime;
for(unsigned int i = 0; i < tweenSet->size(); i++)
{
Tween *tween = tweenSet->at(i);
float elapsedTime = ElapsedTweenTime;
//todo: too many levels of nesting
if(elapsedTime < tween->GetDuration())
{
currentDone = false;
}
else
{
elapsedTime = tween->GetDuration();
}
//todo: too many levels of nesting
if(elapsedTime < tween->GetDuration())
{
currentDone = false;
}
else
{
elapsedTime = tween->GetDuration();
}
float value = tween->Animate(elapsedTime);
float value = tween->Animate(elapsedTime);
switch(tween->GetProperty())
{
case TWEEN_PROPERTY_X:
GetBaseViewInfo()->SetX(value);
break;
switch(tween->GetProperty())
{
case TWEEN_PROPERTY_X:
GetBaseViewInfo()->SetX(value);
break;
case TWEEN_PROPERTY_Y:
GetBaseViewInfo()->SetY(value);
break;
case TWEEN_PROPERTY_Y:
GetBaseViewInfo()->SetY(value);
break;
case TWEEN_PROPERTY_HEIGHT:
GetBaseViewInfo()->SetHeight(value);
break;
case TWEEN_PROPERTY_HEIGHT:
GetBaseViewInfo()->SetHeight(value);
break;
case TWEEN_PROPERTY_WIDTH:
GetBaseViewInfo()->SetWidth(value);
break;
case TWEEN_PROPERTY_WIDTH:
GetBaseViewInfo()->SetWidth(value);
break;
case TWEEN_PROPERTY_ANGLE:
GetBaseViewInfo()->SetAngle(value);
break;
case TWEEN_PROPERTY_ANGLE:
GetBaseViewInfo()->SetAngle(value);
break;
case TWEEN_PROPERTY_TRANSPARENCY:
GetBaseViewInfo()->SetTransparency(value);
break;
case TWEEN_PROPERTY_TRANSPARENCY:
GetBaseViewInfo()->SetTransparency(value);
break;
case TWEEN_PROPERTY_X_ORIGIN:
GetBaseViewInfo()->SetXOrigin(value);
break;
case TWEEN_PROPERTY_X_ORIGIN:
GetBaseViewInfo()->SetXOrigin(value);
break;
case TWEEN_PROPERTY_Y_ORIGIN:
GetBaseViewInfo()->SetYOrigin(value);
break;
case TWEEN_PROPERTY_Y_ORIGIN:
GetBaseViewInfo()->SetYOrigin(value);
break;
case TWEEN_PROPERTY_X_OFFSET:
GetBaseViewInfo()->SetXOffset(value);
break;
case TWEEN_PROPERTY_X_OFFSET:
GetBaseViewInfo()->SetXOffset(value);
break;
case TWEEN_PROPERTY_Y_OFFSET:
GetBaseViewInfo()->SetYOffset(value);
break;
case TWEEN_PROPERTY_Y_OFFSET:
GetBaseViewInfo()->SetYOffset(value);
break;
case TWEEN_PROPERTY_FONT_SIZE:
GetBaseViewInfo()->SetFontSize(value);
break;
}
}
case TWEEN_PROPERTY_FONT_SIZE:
GetBaseViewInfo()->SetFontSize(value);
break;
}
}
if(currentDone)
{
CurrentTweenIndex++;
ElapsedTweenTime = 0;
}
}
if(currentDone)
{
CurrentTweenIndex++;
ElapsedTweenTime = 0;
}
}
if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->size())
{
if(loop)
{
CurrentTweenIndex = 0;
}
completeDone = true;
}
if(!CurrentTweens || CurrentTweenIndex >= CurrentTweens->size())
{
if(loop)
{
CurrentTweenIndex = 0;
}
completeDone = true;
}
return completeDone;
return completeDone;
}

View File

@@ -13,110 +13,110 @@
class Component
{
public:
Component();
virtual ~Component();
virtual void FreeGraphicsMemory();
virtual void AllocateGraphicsMemory();
virtual void LaunchEnter() {}
virtual void LaunchExit() {}
void TriggerEnterEvent();
void TriggerExitEvent();
void TriggerHighlightEvent(Item *selectedItem);
bool IsIdle();
bool IsHidden();
bool IsWaiting();
typedef std::vector<std::vector<Tween *> *> TweenSets;
Component();
virtual ~Component();
virtual void FreeGraphicsMemory();
virtual void AllocateGraphicsMemory();
virtual void LaunchEnter() {}
virtual void LaunchExit() {}
void TriggerEnterEvent();
void TriggerExitEvent();
void TriggerHighlightEvent(Item *selectedItem);
bool IsIdle();
bool IsHidden();
bool IsWaiting();
typedef std::vector<std::vector<Tween *> *> TweenSets;
void SetOnEnterTweens(TweenSets *tweens)
{
this->OnEnterTweens = tweens;
}
void SetOnEnterTweens(TweenSets *tweens)
{
this->OnEnterTweens = tweens;
}
void SetOnExitTweens(TweenSets *tweens)
{
this->OnExitTweens = tweens;
}
void SetOnExitTweens(TweenSets *tweens)
{
this->OnExitTweens = tweens;
}
void SetOnIdleTweens(TweenSets *tweens)
{
this->OnIdleTweens = tweens;
}
void SetOnIdleTweens(TweenSets *tweens)
{
this->OnIdleTweens = tweens;
}
void SetOnHighlightEnterTweens(TweenSets *tweens)
{
this->OnHighlightEnterTweens = tweens;
}
void SetOnHighlightEnterTweens(TweenSets *tweens)
{
this->OnHighlightEnterTweens = tweens;
}
void SetOnHighlightExitTweens(TweenSets *tweens)
{
this->OnHighlightExitTweens = tweens;
}
virtual void Update(float dt);
void SetOnHighlightExitTweens(TweenSets *tweens)
{
this->OnHighlightExitTweens = tweens;
}
virtual void Update(float dt);
virtual void Draw() = 0;
virtual void Draw() = 0;
ViewInfo *GetBaseViewInfo()
{
return &BaseViewInfo;
}
void UpdateBaseViewInfo(ViewInfo &info)
{
BaseViewInfo = info;
}
ViewInfo *GetBaseViewInfo()
{
return &BaseViewInfo;
}
void UpdateBaseViewInfo(ViewInfo &info)
{
BaseViewInfo = info;
}
bool IsScrollActive() const
{
return ScrollActive;
}
bool IsScrollActive() const
{
return ScrollActive;
}
void SetScrollActive(bool scrollActive)
{
ScrollActive = scrollActive;
}
void SetScrollActive(bool scrollActive)
{
ScrollActive = scrollActive;
}
protected:
Item *GetSelectedItem()
{
return SelectedItem;
}
enum AnimationState
{
IDLE,
ENTER,
HIGHLIGHT_EXIT,
HIGHLIGHT_WAIT,
HIGHLIGHT_ENTER,
EXIT,
HIDDEN
};
Item *GetSelectedItem()
{
return SelectedItem;
}
enum AnimationState
{
IDLE,
ENTER,
HIGHLIGHT_EXIT,
HIGHLIGHT_WAIT,
HIGHLIGHT_ENTER,
EXIT,
HIDDEN
};
AnimationState CurrentAnimationState;
bool EnterRequested;
bool ExitRequested;
bool NewItemSelected;
bool HighlightExitComplete;
bool NewItemSelectedSinceEnter;
AnimationState CurrentAnimationState;
bool EnterRequested;
bool ExitRequested;
bool NewItemSelected;
bool HighlightExitComplete;
bool NewItemSelectedSinceEnter;
private:
bool Animate(bool loop);
bool IsTweenSequencingComplete();
void ResetTweenSequence(std::vector<ViewInfo *> *tweens);
bool Animate(bool loop);
bool IsTweenSequencingComplete();
void ResetTweenSequence(std::vector<ViewInfo *> *tweens);
TweenSets *OnEnterTweens;
TweenSets *OnExitTweens;
TweenSets *OnIdleTweens;
TweenSets *OnHighlightEnterTweens;
TweenSets *OnHighlightExitTweens;
TweenSets *OnEnterTweens;
TweenSets *OnExitTweens;
TweenSets *OnIdleTweens;
TweenSets *OnHighlightEnterTweens;
TweenSets *OnHighlightExitTweens;
TweenSets *CurrentTweens;
unsigned int CurrentTweenIndex;
TweenSets *CurrentTweens;
unsigned int CurrentTweenIndex;
bool CurrentTweenComplete;
ViewInfo BaseViewInfo;
bool CurrentTweenComplete;
ViewInfo BaseViewInfo;
float ElapsedTweenTime;
Tween *TweenInst;
Item *SelectedItem;
bool ScrollActive;
float ElapsedTweenTime;
Tween *TweenInst;
Item *SelectedItem;
bool ScrollActive;
};

View File

@@ -8,68 +8,68 @@
#include <SDL2/SDL_image.h>
Image::Image(std::string file, float scaleX, float scaleY)
: Texture(NULL)
, File(file)
, ScaleX(scaleX)
, ScaleY(scaleY)
: Texture(NULL)
, File(file)
, ScaleX(scaleX)
, ScaleY(scaleY)
{
AllocateGraphicsMemory();
AllocateGraphicsMemory();
}
Image::~Image()
{
FreeGraphicsMemory();
FreeGraphicsMemory();
}
void Image::FreeGraphicsMemory()
{
Component::FreeGraphicsMemory();
Component::FreeGraphicsMemory();
SDL_LockMutex(SDL::GetMutex());
if (Texture != NULL)
{
SDL_DestroyTexture(Texture);
Texture = NULL;
}
SDL_UnlockMutex(SDL::GetMutex());
SDL_LockMutex(SDL::GetMutex());
if (Texture != NULL)
{
SDL_DestroyTexture(Texture);
Texture = NULL;
}
SDL_UnlockMutex(SDL::GetMutex());
}
void Image::AllocateGraphicsMemory()
{
int width;
int height;
int width;
int height;
Component::AllocateGraphicsMemory();
Component::AllocateGraphicsMemory();
if(!Texture)
{
SDL_LockMutex(SDL::GetMutex());
Texture = IMG_LoadTexture(SDL::GetRenderer(), File.c_str());
if(!Texture)
{
SDL_LockMutex(SDL::GetMutex());
Texture = IMG_LoadTexture(SDL::GetRenderer(), File.c_str());
if (Texture != NULL)
{
SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_BLEND);
SDL_QueryTexture(Texture, NULL, NULL, &width, &height);
GetBaseViewInfo()->SetImageWidth(width * ScaleX);
GetBaseViewInfo()->SetImageHeight(height * ScaleY);
}
SDL_UnlockMutex(SDL::GetMutex());
if (Texture != NULL)
{
SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_BLEND);
SDL_QueryTexture(Texture, NULL, NULL, &width, &height);
GetBaseViewInfo()->SetImageWidth(width * ScaleX);
GetBaseViewInfo()->SetImageHeight(height * ScaleY);
}
SDL_UnlockMutex(SDL::GetMutex());
}
}
}
void Image::Draw()
{
if(Texture)
{
ViewInfo *info = GetBaseViewInfo();
SDL_Rect rect;
if(Texture)
{
ViewInfo *info = GetBaseViewInfo();
SDL_Rect rect;
rect.x = static_cast<int>(info->GetXRelativeToOrigin());
rect.y = static_cast<int>(info->GetYRelativeToOrigin());
rect.h = static_cast<int>(info->GetHeight());
rect.w = static_cast<int>(info->GetWidth());
rect.x = static_cast<int>(info->GetXRelativeToOrigin());
rect.y = static_cast<int>(info->GetYRelativeToOrigin());
rect.h = static_cast<int>(info->GetHeight());
rect.w = static_cast<int>(info->GetWidth());
SDL::RenderCopy(Texture, static_cast<char>((info->GetTransparency() * 255)), NULL, &rect, info->GetAngle());
}
SDL::RenderCopy(Texture, static_cast<char>((info->GetTransparency() * 255)), NULL, &rect, info->GetAngle());
}
}

View File

@@ -10,15 +10,15 @@
class Image : public Component
{
public:
Image(std::string file, float scaleX, float scaleY);
virtual ~Image();
void FreeGraphicsMemory();
void AllocateGraphicsMemory();
void Draw();
Image(std::string file, float scaleX, float scaleY);
virtual ~Image();
void FreeGraphicsMemory();
void AllocateGraphicsMemory();
void Draw();
protected:
SDL_Texture *Texture;
std::string File;
float ScaleX;
float ScaleY;
SDL_Texture *Texture;
std::string File;
float ScaleX;
float ScaleY;
};

View File

@@ -8,23 +8,23 @@
Image * ImageBuilder::CreateImage(std::string path, std::string name, float scaleX, float scaleY)
{
Image *image = NULL;
std::vector<std::string> extensions;
Image *image = NULL;
std::vector<std::string> extensions;
extensions.push_back("png");
extensions.push_back("PNG");
extensions.push_back("jpg");
extensions.push_back("JPG");
extensions.push_back("jpeg");
extensions.push_back("JPEG");
extensions.push_back("png");
extensions.push_back("PNG");
extensions.push_back("jpg");
extensions.push_back("JPG");
extensions.push_back("jpeg");
extensions.push_back("JPEG");
std::string prefix = path + "/" + name;
std::string file;
std::string prefix = path + "/" + name;
std::string file;
if(Utils::FindMatchingFile(prefix, extensions, file))
{
image = new Image(file, scaleX, scaleY);
}
if(Utils::FindMatchingFile(prefix, extensions, file))
{
image = new Image(file, scaleX, scaleY);
}
return image;
return image;
}

View File

@@ -11,5 +11,5 @@
class ImageBuilder
{
public:
Image * CreateImage(std::string path, std::string name, float scaleX, float scaleY);
Image * CreateImage(std::string path, std::string name, float scaleX, float scaleY);
};

View File

@@ -15,158 +15,158 @@
#include <iostream>
ReloadableMedia::ReloadableMedia(std::string imagePath, std::string videoPath, bool isVideo, float scaleX, float scaleY)
: LoadedComponent(NULL)
, ImagePath(imagePath)
, VideoPath(videoPath)
, ReloadRequested(false)
, FirstLoad(true)
, IsVideo(isVideo)
, ScaleX(scaleX)
, ScaleY(scaleY)
: LoadedComponent(NULL)
, ImagePath(imagePath)
, VideoPath(videoPath)
, ReloadRequested(false)
, FirstLoad(true)
, IsVideo(isVideo)
, ScaleX(scaleX)
, ScaleY(scaleY)
{
AllocateGraphicsMemory();
AllocateGraphicsMemory();
}
ReloadableMedia::~ReloadableMedia()
{
if (LoadedComponent != NULL)
{
delete LoadedComponent;
}
if (LoadedComponent != NULL)
{
delete LoadedComponent;
}
}
void ReloadableMedia::Update(float dt)
{
if(NewItemSelected)
{
ReloadRequested = true;
}
// wait for the right moment to reload the image
if (ReloadRequested && (HighlightExitComplete || FirstLoad))
{
ReloadTexture();
ReloadRequested = false;
FirstLoad = false;
}
if(NewItemSelected)
{
ReloadRequested = true;
}
// wait for the right moment to reload the image
if (ReloadRequested && (HighlightExitComplete || FirstLoad))
{
ReloadTexture();
ReloadRequested = false;
FirstLoad = false;
}
if(LoadedComponent)
{
LoadedComponent->Update(dt);
}
if(LoadedComponent)
{
LoadedComponent->Update(dt);
}
// needs to be ran at the end to prevent the NewItemSelected flag from being detected
Component::Update(dt);
Component::Update(dt);
}
void ReloadableMedia::AllocateGraphicsMemory()
{
FirstLoad = true;
FirstLoad = true;
if(LoadedComponent)
{
LoadedComponent->AllocateGraphicsMemory();
}
if(LoadedComponent)
{
LoadedComponent->AllocateGraphicsMemory();
}
// NOTICE! needs to be done last to prevent flags from being missed
Component::AllocateGraphicsMemory();
// NOTICE! needs to be done last to prevent flags from being missed
Component::AllocateGraphicsMemory();
}
void ReloadableMedia::LaunchEnter()
{
if(LoadedComponent)
{
LoadedComponent->LaunchEnter();
}
if(LoadedComponent)
{
LoadedComponent->LaunchEnter();
}
}
void ReloadableMedia::LaunchExit()
{
if(LoadedComponent)
{
LoadedComponent->LaunchExit();
}
if(LoadedComponent)
{
LoadedComponent->LaunchExit();
}
}
void ReloadableMedia::FreeGraphicsMemory()
{
Component::FreeGraphicsMemory();
Component::FreeGraphicsMemory();
if(LoadedComponent)
{
LoadedComponent->FreeGraphicsMemory();
}
if(LoadedComponent)
{
LoadedComponent->FreeGraphicsMemory();
}
}
void ReloadableMedia::ReloadTexture()
{
bool found = false;
bool found = false;
if(LoadedComponent)
{
delete LoadedComponent;
LoadedComponent = NULL;
}
if(LoadedComponent)
{
delete LoadedComponent;
LoadedComponent = NULL;
}
Item *selectedItem = GetSelectedItem();
Item *selectedItem = GetSelectedItem();
if (selectedItem != NULL)
{
if(IsVideo)
{
std::vector<std::string> names;
if (selectedItem != NULL)
{
if(IsVideo)
{
std::vector<std::string> names;
names.push_back(selectedItem->GetName());
names.push_back(selectedItem->GetName());
if(selectedItem->GetCloneOf().length() > 0)
{
names.push_back(selectedItem->GetCloneOf());
}
for(unsigned int n = 0; n < names.size() && !found; ++n)
{
std::string filePrefix;
filePrefix.append(VideoPath);
filePrefix.append("/");
filePrefix.append(names[n]);
std::string file;
VideoBuilder videoBuild;
LoadedComponent = videoBuild.CreateVideo(VideoPath, names[n], ScaleX, ScaleY);
if(LoadedComponent)
if(selectedItem->GetCloneOf().length() > 0)
{
LoadedComponent->AllocateGraphicsMemory();
found = true;
names.push_back(selectedItem->GetCloneOf());
}
}
}
if(!LoadedComponent)
{
ImageBuilder imageBuild;
LoadedComponent = imageBuild.CreateImage(ImagePath, selectedItem->GetFullTitle(), ScaleX, ScaleY);
for(unsigned int n = 0; n < names.size() && !found; ++n)
{
std::string filePrefix;
filePrefix.append(VideoPath);
filePrefix.append("/");
filePrefix.append(names[n]);
if (LoadedComponent != NULL)
{
LoadedComponent->AllocateGraphicsMemory();
GetBaseViewInfo()->SetImageWidth(LoadedComponent->GetBaseViewInfo()->GetImageWidth());
GetBaseViewInfo()->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
}
}
}
std::string file;
VideoBuilder videoBuild;
LoadedComponent = videoBuild.CreateVideo(VideoPath, names[n], ScaleX, ScaleY);
if(LoadedComponent)
{
LoadedComponent->AllocateGraphicsMemory();
found = true;
}
}
}
if(!LoadedComponent)
{
ImageBuilder imageBuild;
LoadedComponent = imageBuild.CreateImage(ImagePath, selectedItem->GetFullTitle(), ScaleX, ScaleY);
if (LoadedComponent != NULL)
{
LoadedComponent->AllocateGraphicsMemory();
GetBaseViewInfo()->SetImageWidth(LoadedComponent->GetBaseViewInfo()->GetImageWidth());
GetBaseViewInfo()->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
}
}
}
}
void ReloadableMedia::Draw()
{
ViewInfo *info = GetBaseViewInfo();
ViewInfo *info = GetBaseViewInfo();
if(LoadedComponent)
{
info->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
info->SetImageWidth(LoadedComponent->GetBaseViewInfo()->GetImageWidth());
LoadedComponent->UpdateBaseViewInfo(*info);
LoadedComponent->Draw();
}
if(LoadedComponent)
{
info->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());
info->SetImageWidth(LoadedComponent->GetBaseViewInfo()->GetImageWidth());
LoadedComponent->UpdateBaseViewInfo(*info);
LoadedComponent->Draw();
}
}

View File

@@ -14,25 +14,25 @@ class Image;
class ReloadableMedia : public Component
{
public:
ReloadableMedia(std::string imagePath, std::string videoPath, bool isVideo, float scaleX, float scaleY);
virtual ~ReloadableMedia();
void Update(float dt);
void Draw();
void FreeGraphicsMemory();
void AllocateGraphicsMemory();
void LaunchEnter();
void LaunchExit();
ReloadableMedia(std::string imagePath, std::string videoPath, bool isVideo, float scaleX, float scaleY);
virtual ~ReloadableMedia();
void Update(float dt);
void Draw();
void FreeGraphicsMemory();
void AllocateGraphicsMemory();
void LaunchEnter();
void LaunchExit();
private:
void ReloadTexture();
Component *LoadedComponent;
std::string ImagePath;
std::string VideoPath;
bool ReloadRequested;
bool FirstLoad;
IVideo *VideoInst;
void ReloadTexture();
Component *LoadedComponent;
std::string ImagePath;
std::string VideoPath;
bool ReloadRequested;
bool FirstLoad;
IVideo *VideoInst;
bool IsVideo;
float ScaleX;
float ScaleY;
bool IsVideo;
float ScaleX;
float ScaleY;
};

View File

@@ -11,80 +11,80 @@
#include <iostream>
ReloadableText::ReloadableText(std::string type, Font *font, SDL_Color color, std::string layoutKey, std::string collection, float scaleX, float scaleY)
: ImageInst(NULL)
, LayoutKey(layoutKey)
, Collection(collection)
, ReloadRequested(false)
, FirstLoad(true)
, FontInst(font)
, FontColor(color)
, ScaleX(scaleX)
, ScaleY(scaleY)
: ImageInst(NULL)
, LayoutKey(layoutKey)
, Collection(collection)
, ReloadRequested(false)
, FirstLoad(true)
, FontInst(font)
, FontColor(color)
, ScaleX(scaleX)
, ScaleY(scaleY)
{
Type = TextTypeUnknown;
Type = TextTypeUnknown;
if(type == "numberButtons")
{
Type = TextTypeNumberButtons;
}
else if(type == "numberPlayers")
{
Type = TextTypeNumberPlayers;
}
else if(type == "year")
{
Type = TextTypeYear;
}
else if(type == "title")
{
Type = TextTypeTitle;
}
else if(type == "manufacturer")
{
Type = TextTypeManufacturer;
}
if(type == "numberButtons")
{
Type = TextTypeNumberButtons;
}
else if(type == "numberPlayers")
{
Type = TextTypeNumberPlayers;
}
else if(type == "year")
{
Type = TextTypeYear;
}
else if(type == "title")
{
Type = TextTypeTitle;
}
else if(type == "manufacturer")
{
Type = TextTypeManufacturer;
}
AllocateGraphicsMemory();
AllocateGraphicsMemory();
}
ReloadableText::~ReloadableText()
{
if (ImageInst != NULL)
{
delete ImageInst;
}
if (ImageInst != NULL)
{
delete ImageInst;
}
}
void ReloadableText::Update(float dt)
{
if(NewItemSelected)
{
ReloadRequested = true;
}
// wait for the right moment to reload the image
if (ReloadRequested && (HighlightExitComplete || FirstLoad))
{
ReloadTexture();
ReloadRequested = false;
FirstLoad = false;
}
if(NewItemSelected)
{
ReloadRequested = true;
}
// wait for the right moment to reload the image
if (ReloadRequested && (HighlightExitComplete || FirstLoad))
{
ReloadTexture();
ReloadRequested = false;
FirstLoad = false;
}
// needs to be ran at the end to prevent the NewItemSelected flag from being detected
Component::Update(dt);
// needs to be ran at the end to prevent the NewItemSelected flag from being detected
Component::Update(dt);
}
void ReloadableText::AllocateGraphicsMemory()
{
FirstLoad = true;
FirstLoad = true;
ReloadTexture();
ReloadTexture();
// NOTICE! needs to be done last to prevent flags from being missed
Component::AllocateGraphicsMemory();
// NOTICE! needs to be done last to prevent flags from being missed
Component::AllocateGraphicsMemory();
}
void ReloadableText::LaunchEnter()
@@ -97,61 +97,61 @@ void ReloadableText::LaunchExit()
void ReloadableText::FreeGraphicsMemory()
{
Component::FreeGraphicsMemory();
Component::FreeGraphicsMemory();
if (ImageInst != NULL)
{
delete ImageInst;
ImageInst = NULL;
}
if (ImageInst != NULL)
{
delete ImageInst;
ImageInst = NULL;
}
}
void ReloadableText::ReloadTexture()
{
if (ImageInst != NULL)
{
delete ImageInst;
ImageInst = NULL;
}
if (ImageInst != NULL)
{
delete ImageInst;
ImageInst = NULL;
}
Item *selectedItem = GetSelectedItem();
Item *selectedItem = GetSelectedItem();
if (selectedItem != NULL)
{
std::stringstream ss;
std::string text;
switch(Type)
{
case TextTypeNumberButtons:
ss << selectedItem->GetNumberButtons();
break;
case TextTypeNumberPlayers:
ss << selectedItem->GetNumberPlayers();
break;
case TextTypeYear:
ss << selectedItem->GetYear();
break;
case TextTypeTitle:
ss << selectedItem->GetTitle();
break;
case TextTypeManufacturer:
ss << selectedItem->GetManufacturer();
break;
default:
break;
}
if (selectedItem != NULL)
{
std::stringstream ss;
std::string text;
switch(Type)
{
case TextTypeNumberButtons:
ss << selectedItem->GetNumberButtons();
break;
case TextTypeNumberPlayers:
ss << selectedItem->GetNumberPlayers();
break;
case TextTypeYear:
ss << selectedItem->GetYear();
break;
case TextTypeTitle:
ss << selectedItem->GetTitle();
break;
case TextTypeManufacturer:
ss << selectedItem->GetManufacturer();
break;
default:
break;
}
ImageInst = new Text(ss.str(), FontInst, FontColor, ScaleX, ScaleY);
}
ImageInst = new Text(ss.str(), FontInst, FontColor, ScaleX, ScaleY);
}
}
void ReloadableText::Draw()
{
ViewInfo *info = GetBaseViewInfo();
ViewInfo *info = GetBaseViewInfo();
if(ImageInst)
{
ImageInst->UpdateBaseViewInfo(*info);
ImageInst->Draw();
}
if(ImageInst)
{
ImageInst->UpdateBaseViewInfo(*info);
ImageInst->Draw();
}
}

View File

@@ -12,37 +12,37 @@
class ReloadableText : public Component
{
public:
ReloadableText(std::string type, Font *font, SDL_Color color, std::string layoutKey, std::string collectionName, float scaleX, float scaleY);
virtual ~ReloadableText();
void Update(float dt);
void Draw();
void FreeGraphicsMemory();
void AllocateGraphicsMemory();
void LaunchEnter();
void LaunchExit();
ReloadableText(std::string type, Font *font, SDL_Color color, std::string layoutKey, std::string collectionName, float scaleX, float scaleY);
virtual ~ReloadableText();
void Update(float dt);
void Draw();
void FreeGraphicsMemory();
void AllocateGraphicsMemory();
void LaunchEnter();
void LaunchExit();
private:
enum TextType
{
TextTypeUnknown = 0,
TextTypeNumberButtons,
TextTypeNumberPlayers,
TextTypeYear,
TextTypeTitle,
TextTypeManufacturer,
};
enum TextType
{
TextTypeUnknown = 0,
TextTypeNumberButtons,
TextTypeNumberPlayers,
TextTypeYear,
TextTypeTitle,
TextTypeManufacturer,
};
void ReloadTexture();
void ReloadTexture();
Text *ImageInst;
TextType Type;
std::string LayoutKey;
std::string Collection;
bool ReloadRequested;
bool FirstLoad;
Font *FontInst;
SDL_Color FontColor;
Text *ImageInst;
TextType Type;
std::string LayoutKey;
std::string Collection;
bool ReloadRequested;
bool FirstLoad;
Font *FontInst;
SDL_Color FontColor;
float ScaleX;
float ScaleY;
float ScaleX;
float ScaleY;
};

File diff suppressed because it is too large Load Diff

View File

@@ -23,83 +23,83 @@ class Font;
class ScrollingList : public Component
{
public:
enum ScrollDirection
{
ScrollDirectionBack,
ScrollDirectionForward,
ScrollDirectionIdle,
enum ScrollDirection
{
ScrollDirectionBack,
ScrollDirectionForward,
ScrollDirectionIdle,
};
};
ScrollingList(Configuration *c, float scaleX, float scaleY, Font *font, SDL_Color fontColor, std::string layoutKey, std::string CollectionName, std::string imageType);
virtual ~ScrollingList();
void AllocateTexture(ComponentItemBinding *s);
void DeallocateTexture(ComponentItemBinding *s);
void SetItems(std::vector<ComponentItemBinding *> *spriteList);
void SetPoints(std::vector<ViewInfo *> *scrollPoints);
void SetScrollDirection(ScrollDirection direction);
void PageUp();
void PageDown();
bool IsIdle();
void SetSelectedIndex(int selectedIndex);
ComponentItemBinding *GetSelectedCollectionItemSprite();
ComponentItemBinding *GetPendingCollectionItemSprite();
ComponentItemBinding *GetPendingSelectedCollectionItemSprite();
void AddComponentForNotifications(MenuNotifierInterface *c);
void RemoveComponentForNotifications(MenuNotifierInterface *c);
std::vector<ComponentItemBinding *> *GetCollectionItemSprites();
void RemoveSelectedItem();
void FreeGraphicsMemory();
void Update(float dt);
void Draw();
void Draw(unsigned int layer);
ScrollingList(Configuration *c, float scaleX, float scaleY, Font *font, SDL_Color fontColor, std::string layoutKey, std::string CollectionName, std::string imageType);
virtual ~ScrollingList();
void AllocateTexture(ComponentItemBinding *s);
void DeallocateTexture(ComponentItemBinding *s);
void SetItems(std::vector<ComponentItemBinding *> *spriteList);
void SetPoints(std::vector<ViewInfo *> *scrollPoints);
void SetScrollDirection(ScrollDirection direction);
void PageUp();
void PageDown();
bool IsIdle();
void SetSelectedIndex(int selectedIndex);
ComponentItemBinding *GetSelectedCollectionItemSprite();
ComponentItemBinding *GetPendingCollectionItemSprite();
ComponentItemBinding *GetPendingSelectedCollectionItemSprite();
void AddComponentForNotifications(MenuNotifierInterface *c);
void RemoveComponentForNotifications(MenuNotifierInterface *c);
std::vector<ComponentItemBinding *> *GetCollectionItemSprites();
void RemoveSelectedItem();
void FreeGraphicsMemory();
void Update(float dt);
void Draw();
void Draw(unsigned int layer);
private:
void Click();
unsigned int GetNextTween(unsigned int currentIndex, std::vector<ViewInfo *> *list);
bool IsScrollChangedStarted;
bool IsScrollChangedSignalled;
bool IsScrollChangedComplete;
void Click();
unsigned int GetNextTween(unsigned int currentIndex, std::vector<ViewInfo *> *list);
bool IsScrollChangedStarted;
bool IsScrollChangedSignalled;
bool IsScrollChangedComplete;
enum ScrollState
{
ScrollStateActive,
ScrollStatePageChange,
ScrollStateStopping,
ScrollStateIdle
};
enum ScrollState
{
ScrollStateActive,
ScrollStatePageChange,
ScrollStateStopping,
ScrollStateIdle
};
std::vector<ComponentItemBinding *> *SpriteList;
std::vector<ViewInfo *> *ScrollPoints;
std::vector<MenuNotifierInterface *> NotificationComponents;
float TweenEnterTime;
std::vector<ComponentItemBinding *> *SpriteList;
std::vector<ViewInfo *> *ScrollPoints;
std::vector<MenuNotifierInterface *> NotificationComponents;
float TweenEnterTime;
unsigned int FirstSpriteIndex;
unsigned int SelectedSpriteListIndex;
float CurrentAnimateTime;
float ScrollTime;
unsigned int FirstSpriteIndex;
unsigned int SelectedSpriteListIndex;
float CurrentAnimateTime;
float ScrollTime;
ScrollDirection CurrentScrollDirection;
ScrollDirection RequestedScrollDirection;
ScrollState CurrentScrollState;
float ScrollAcceleration;
float ScrollVelocity;
ScrollDirection CurrentScrollDirection;
ScrollDirection RequestedScrollDirection;
ScrollState CurrentScrollState;
float ScrollAcceleration;
float ScrollVelocity;
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);
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;
Configuration *Config;
float ScaleX;
float ScaleY;
Font *FontInst;
SDL_Color FontColor;
std::string LayoutKey;
std::string CollectionName;
std::string ImageType;
unsigned int MaxLayer;
std::string Collection;
Configuration *Config;
float ScaleX;
float ScaleY;
Font *FontInst;
SDL_Color FontColor;
std::string LayoutKey;
std::string CollectionName;
std::string ImageType;
unsigned int MaxLayer;
};

View File

@@ -8,96 +8,96 @@
#include <sstream>
Text::Text(std::string text, Font *font, SDL_Color fontColor, float scaleX, float scaleY)
: TextData(text)
, FontInst(font)
, FontColor(fontColor)
, ScaleX(scaleX)
, ScaleY(scaleY)
: TextData(text)
, FontInst(font)
, FontColor(fontColor)
, ScaleX(scaleX)
, ScaleY(scaleY)
{
AllocateGraphicsMemory();
AllocateGraphicsMemory();
}
Text::~Text()
{
FreeGraphicsMemory();
FreeGraphicsMemory();
}
void Text::FreeGraphicsMemory()
{
Component::FreeGraphicsMemory();
Component::FreeGraphicsMemory();
}
void Text::AllocateGraphicsMemory()
{
//todo: make the font blend color a parameter that is passed in
Component::AllocateGraphicsMemory();
//todo: make the font blend color a parameter that is passed in
Component::AllocateGraphicsMemory();
}
void Text::Draw()
{
SDL_Texture *t = FontInst->GetTexture();
SDL_Texture *t = FontInst->GetTexture();
ViewInfo *info = GetBaseViewInfo();
float imageHeight = 0;
float imageWidth = 0;
ViewInfo *info = GetBaseViewInfo();
float imageHeight = 0;
float imageWidth = 0;
// determine image width
for(unsigned int i = 0; i < TextData.size(); ++i)
{
Font::GlyphInfo glyph;
if(FontInst->GetRect(TextData[i], glyph))
{
imageWidth += glyph.Advance;
imageHeight = (imageHeight >= glyph.Rect.h) ? imageHeight : glyph.Rect.h;
}
}
// determine image width
for(unsigned int i = 0; i < TextData.size(); ++i)
{
Font::GlyphInfo glyph;
if(FontInst->GetRect(TextData[i], glyph))
{
imageWidth += glyph.Advance;
imageHeight = (imageHeight >= glyph.Rect.h) ? imageHeight : glyph.Rect.h;
}
}
float scale = (float)info->GetFontSize() / (float)imageHeight;
float scale = (float)info->GetFontSize() / (float)imageHeight;
float width = info->GetRawWidth();
float height = info->GetRawHeight();
float width = info->GetRawWidth();
float height = info->GetRawHeight();
info->SetWidth(imageWidth*scale);
info->SetHeight(imageHeight*scale);
info->SetWidth(imageWidth*scale);
info->SetHeight(imageHeight*scale);
float xOrigin = info->GetXRelativeToOrigin();
float yOrigin = info->GetYRelativeToOrigin();
float xOrigin = info->GetXRelativeToOrigin();
float yOrigin = info->GetYRelativeToOrigin();
info->SetWidth(width);
info->SetHeight(height);
info->SetWidth(width);
info->SetHeight(height);
SDL_Rect rect;
rect.x = static_cast<int>(xOrigin);
SDL_Rect rect;
rect.x = static_cast<int>(xOrigin);
for(unsigned int i = 0; i < TextData.size(); ++i)
{
Font::GlyphInfo glyph;
for(unsigned int i = 0; i < TextData.size(); ++i)
{
Font::GlyphInfo glyph;
if(FontInst->GetRect(TextData[i], glyph) && glyph.Rect.h > 0)
{
SDL_Rect charRect = glyph.Rect;
float h = static_cast<float>(charRect.h * scale);
float w = static_cast<float>(charRect.w * scale);
rect.h = static_cast<int>(h);
rect.w = static_cast<int>(w);
rect.y = static_cast<int>(yOrigin);
/*
std::stringstream ss;
ss << " cx:" << charRect.x << " cy:" << charRect.y << " cw:" << charRect.w << " ch:" << charRect.h;
ss << " x:" << rect.x << " y:" << rect.y << " w:" << rect.w << " h:" << rect.h;
Logger::Write(Logger::ZONE_DEBUG, "Text", ss.str());
*/
if(FontInst->GetRect(TextData[i], glyph) && glyph.Rect.h > 0)
{
SDL_Rect charRect = glyph.Rect;
float h = static_cast<float>(charRect.h * scale);
float w = static_cast<float>(charRect.w * scale);
rect.h = static_cast<int>(h);
rect.w = static_cast<int>(w);
rect.y = static_cast<int>(yOrigin);
/*
std::stringstream ss;
ss << " cx:" << charRect.x << " cy:" << charRect.y << " cw:" << charRect.w << " ch:" << charRect.h;
ss << " x:" << rect.x << " y:" << rect.y << " w:" << rect.w << " h:" << rect.h;
Logger::Write(Logger::ZONE_DEBUG, "Text", ss.str());
*/
SDL_LockMutex(SDL::GetMutex());
SDL_SetTextureColorMod(t, FontColor.r, FontColor.g, FontColor.b);
SDL_UnlockMutex(SDL::GetMutex());
SDL_LockMutex(SDL::GetMutex());
SDL_SetTextureColorMod(t, FontColor.r, FontColor.g, FontColor.b);
SDL_UnlockMutex(SDL::GetMutex());
SDL::RenderCopy(t, static_cast<char>(info->GetTransparency() * 255), &charRect, &rect, info->GetAngle());
rect.x += static_cast<int>(glyph.Advance * scale);
}
}
SDL::RenderCopy(t, static_cast<char>(info->GetTransparency() * 255), &charRect, &rect, info->GetAngle());
rect.x += static_cast<int>(glyph.Advance * scale);
}
}
}

View File

@@ -13,17 +13,17 @@ class Font;
class Text : public Component
{
public:
//todo: should have a Font flass that references fontcache, pass that in as an argument
Text(std::string text, Font *font, SDL_Color fontColor, float scaleX, float scaleY);
virtual ~Text();
void AllocateGraphicsMemory();
void FreeGraphicsMemory();
void Draw();
//todo: should have a Font flass that references fontcache, pass that in as an argument
Text(std::string text, Font *font, SDL_Color fontColor, float scaleX, float scaleY);
virtual ~Text();
void AllocateGraphicsMemory();
void FreeGraphicsMemory();
void Draw();
private:
std::string TextData;
Font *FontInst;
SDL_Color FontColor;
float ScaleX;
float ScaleY;
std::string TextData;
Font *FontInst;
SDL_Color FontColor;
float ScaleX;
float ScaleY;
};

View File

@@ -10,27 +10,27 @@
VideoComponent * VideoBuilder::CreateVideo(std::string path, std::string name, float scaleX, float scaleY)
{
VideoComponent *component = NULL;
std::vector<std::string> extensions;
VideoComponent *component = NULL;
std::vector<std::string> extensions;
extensions.push_back("mp4");
extensions.push_back("MP4");
extensions.push_back("avi");
extensions.push_back("AVI");
extensions.push_back("mp4");
extensions.push_back("MP4");
extensions.push_back("avi");
extensions.push_back("AVI");
std::string prefix = path + "/" + name;
std::string file;
std::string prefix = path + "/" + name;
std::string file;
if(Utils::FindMatchingFile(prefix, extensions, file))
{
IVideo *video = Factory.CreateVideo();
if(Utils::FindMatchingFile(prefix, extensions, file))
{
IVideo *video = Factory.CreateVideo();
if(video)
{
component = new VideoComponent(video, file, scaleX, scaleY);
}
}
if(video)
{
component = new VideoComponent(video, file, scaleX, scaleY);
}
}
return component;
return component;
}

View File

@@ -11,8 +11,8 @@
class VideoBuilder
{
public:
VideoComponent * CreateVideo(std::string path, std::string name, float scaleX, float scaleY);
VideoComponent * CreateVideo(std::string path, std::string name, float scaleX, float scaleY);
private:
VideoFactory Factory;
VideoFactory Factory;
};

View File

@@ -8,77 +8,77 @@
#include "../../SDL.h"
VideoComponent::VideoComponent(IVideo *videoInst, std::string videoFile, float scaleX, float scaleY)
: VideoTexture(NULL)
, VideoFile(videoFile)
, VideoInst(videoInst)
, ScaleX(scaleX)
, ScaleY(scaleY)
, IsPlaying(false)
: VideoTexture(NULL)
, VideoFile(videoFile)
, VideoInst(videoInst)
, ScaleX(scaleX)
, ScaleY(scaleY)
, IsPlaying(false)
{
// AllocateGraphicsMemory();
}
VideoComponent::~VideoComponent()
{
FreeGraphicsMemory();
FreeGraphicsMemory();
if(VideoInst)
{
VideoInst->Stop();
}
if(VideoInst)
{
VideoInst->Stop();
}
}
void VideoComponent::Update(float dt)
{
if(IsPlaying)
{
VideoInst->Update(dt);
}
if(IsPlaying)
{
VideoInst->Update(dt);
}
Component::Update(dt);
Component::Update(dt);
}
void VideoComponent::AllocateGraphicsMemory()
{
Component::AllocateGraphicsMemory();
Component::AllocateGraphicsMemory();
if(!IsPlaying)
{
IsPlaying = VideoInst->Play(VideoFile);
}
if(!IsPlaying)
{
IsPlaying = VideoInst->Play(VideoFile);
}
}
void VideoComponent::FreeGraphicsMemory()
{
VideoInst->Stop();
IsPlaying = false;
VideoInst->Stop();
IsPlaying = false;
if (VideoTexture != NULL)
{
SDL_LockMutex(SDL::GetMutex());
SDL_DestroyTexture(VideoTexture);
SDL_UnlockMutex(SDL::GetMutex());
}
if (VideoTexture != NULL)
{
SDL_LockMutex(SDL::GetMutex());
SDL_DestroyTexture(VideoTexture);
SDL_UnlockMutex(SDL::GetMutex());
}
Component::FreeGraphicsMemory();
Component::FreeGraphicsMemory();
}
void VideoComponent::Draw()
{
ViewInfo *info = GetBaseViewInfo();
SDL_Rect rect;
ViewInfo *info = GetBaseViewInfo();
SDL_Rect rect;
rect.x = static_cast<int>(info->GetXRelativeToOrigin());
rect.y = static_cast<int>(info->GetYRelativeToOrigin());
rect.h = static_cast<int>(info->GetHeight());
rect.w = static_cast<int>(info->GetWidth());
rect.x = static_cast<int>(info->GetXRelativeToOrigin());
rect.y = static_cast<int>(info->GetYRelativeToOrigin());
rect.h = static_cast<int>(info->GetHeight());
rect.w = static_cast<int>(info->GetWidth());
VideoInst->Draw();
SDL_Texture *texture = VideoInst->GetTexture();
VideoInst->Draw();
SDL_Texture *texture = VideoInst->GetTexture();
if(texture)
{
SDL::RenderCopy(texture, static_cast<int>(info->GetTransparency() * 255), NULL, &rect, info->GetAngle());
}
if(texture)
{
SDL::RenderCopy(texture, static_cast<int>(info->GetTransparency() * 255), NULL, &rect, info->GetAngle());
}
}

View File

@@ -12,21 +12,27 @@
class VideoComponent : public Component
{
public:
VideoComponent(IVideo *videoInst, std::string videoFile, float scaleX, float scaleY);
virtual ~VideoComponent();
void Update(float dt);
void Draw();
void FreeGraphicsMemory();
void AllocateGraphicsMemory();
void LaunchEnter() {FreeGraphicsMemory(); }
void LaunchExit() { AllocateGraphicsMemory(); }
VideoComponent(IVideo *videoInst, std::string videoFile, float scaleX, float scaleY);
virtual ~VideoComponent();
void Update(float dt);
void Draw();
void FreeGraphicsMemory();
void AllocateGraphicsMemory();
void LaunchEnter()
{
FreeGraphicsMemory();
}
void LaunchExit()
{
AllocateGraphicsMemory();
}
private:
SDL_Texture *VideoTexture;
std::string VideoFile;
std::string Name;
IVideo *VideoInst;
float ScaleX;
float ScaleY;
bool IsPlaying;
SDL_Texture *VideoTexture;
std::string VideoFile;
std::string Name;
IVideo *VideoInst;
float ScaleX;
float ScaleY;
bool IsPlaying;
};