Added background image color support. Changed "transparency" to "alpha" for layouts. Fixed code syling.

This commit is contained in:
emb
2015-01-02 09:23:49 -06:00
parent ccdafb0e8f
commit d309c3b96f
20 changed files with 195 additions and 78 deletions

View File

@@ -5,6 +5,7 @@
#include "../Animate/Tween.h"
#include "../../Graphics/ViewInfo.h"
#include "../../Utility/Log.h"
#include "../../SDL.h"
Component::Component()
{
@@ -15,8 +16,8 @@ Component::Component()
OnHighlightExitTweens = NULL;
SelectedItem = NULL;
NewItemSelectedSinceEnter = false;
BackgroundTexture = NULL;
FreeGraphicsMemory();
}
Component::~Component()
@@ -34,11 +35,27 @@ void Component::FreeGraphicsMemory()
CurrentTweens = NULL;
CurrentTweenIndex = 0;
CurrentTweenComplete = false;
ElapsedTweenTime =0;
ElapsedTweenTime = 0;
ScrollActive = false;
if(BackgroundTexture)
{
SDL_DestroyTexture(BackgroundTexture);
BackgroundTexture = NULL;
}
}
void Component::AllocateGraphicsMemory()
{
if(!BackgroundTexture)
{
// make a 4x4 pixel wide surface to be stretched during rendering, make it a white background so we can use
// color later
SDL_Surface *surface = SDL_CreateRGBSurface(0, 4, 4, 32, 0, 0, 0, 0);
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 255, 255, 255));
BackgroundTexture = SDL_CreateTextureFromSurface(SDL::GetRenderer(), surface);
SDL_FreeSurface(surface);
SDL_SetTextureBlendMode(BackgroundTexture, SDL_BLENDMODE_BLEND);
}
}
void Component::TriggerEnterEvent()
@@ -72,8 +89,6 @@ bool Component::IsWaiting()
return (CurrentAnimationState == HIGHLIGHT_WAIT);
}
void Component::Update(float dt)
{
ElapsedTweenTime += dt;
@@ -184,6 +199,22 @@ void Component::Update(float dt)
CurrentTweenComplete = Animate(IsIdle());
}
void Component::Draw()
{
ViewInfo *info = GetBaseViewInfo();
SDL_Rect rect;
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());
SDL_SetTextureColorMod(BackgroundTexture,
static_cast<char>(info->GetBackgroundRed()*255),
static_cast<char>(info->GetBackgroundGreen()*255),
static_cast<char>(info->GetBackgroundBlue()*255));
SDL::RenderCopy(BackgroundTexture, static_cast<char>(info->GetBackgroundAlpha()*255), NULL, &rect, info->GetAngle());
}
bool Component::Animate(bool loop)
{
@@ -236,8 +267,8 @@ bool Component::Animate(bool loop)
GetBaseViewInfo()->SetAngle(value);
break;
case TWEEN_PROPERTY_TRANSPARENCY:
GetBaseViewInfo()->SetTransparency(value);
case TWEEN_PROPERTY_ALPHA:
GetBaseViewInfo()->SetAlpha(value);
break;
case TWEEN_PROPERTY_X_ORIGIN:

View File

@@ -5,6 +5,7 @@
#include <vector>
#include "../../SDL.h"
#include "../MenuNotifierInterface.h"
#include "../ViewInfo.h"
#include "../Animate/Tween.h"
@@ -53,7 +54,7 @@ public:
}
virtual void Update(float dt);
virtual void Draw() = 0;
virtual void Draw();
ViewInfo *GetBaseViewInfo()
{
@@ -119,4 +120,6 @@ private:
Tween *TweenInst;
Item *SelectedItem;
bool ScrollActive;
SDL_Texture *BackgroundTexture;
};

View File

@@ -60,6 +60,8 @@ void Image::AllocateGraphicsMemory()
void Image::Draw()
{
Component::Draw();
if(Texture)
{
ViewInfo *info = GetBaseViewInfo();
@@ -70,6 +72,6 @@ void Image::Draw()
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->GetAlpha() * 255)), NULL, &rect, info->GetAngle());
}
}

View File

@@ -162,6 +162,8 @@ void ReloadableMedia::Draw()
{
ViewInfo *info = GetBaseViewInfo();
Component::Draw();
if(LoadedComponent)
{
info->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight());

View File

@@ -61,11 +61,11 @@ ScrollingList::~ScrollingList()
{
if(SpriteList)
{
std::vector<ComponentItemBinding *>::iterator it = SpriteList->begin();
std::vector<ComponentItemBinding *>::iterator it = SpriteList->begin();
while(it != SpriteList->end())
{
if(*it != NULL)
if(*it != NULL)
{
DeallocateTexture(*it);
if((*it)->GetCollectionItem())
@@ -76,9 +76,9 @@ ScrollingList::~ScrollingList()
delete *it;
}
SpriteList->erase(it);
it = SpriteList->begin();
SpriteList->erase(it);
it = SpriteList->begin();
}
delete SpriteList;
@@ -329,7 +329,7 @@ void ScrollingList::Update(float dt)
spriteViewInfo->SetYOffset(Tween::AnimateSingle(LINEAR, currentViewInfo->GetYOffset(), nextViewInfo->GetYOffset(), scrollPeriod, CurrentAnimateTime));
spriteViewInfo->SetHeight(Tween::AnimateSingle(LINEAR, currentViewInfo->GetHeight(), nextViewInfo->GetHeight(), scrollPeriod, CurrentAnimateTime));
spriteViewInfo->SetWidth(Tween::AnimateSingle(LINEAR, currentViewInfo->GetWidth(), nextViewInfo->GetWidth(), scrollPeriod, CurrentAnimateTime));
spriteViewInfo->SetTransparency(Tween::AnimateSingle(LINEAR, currentViewInfo->GetTransparency(), nextViewInfo->GetTransparency(), scrollPeriod, CurrentAnimateTime));
spriteViewInfo->SetAlpha(Tween::AnimateSingle(LINEAR, currentViewInfo->GetAlpha(), nextViewInfo->GetAlpha(), scrollPeriod, CurrentAnimateTime));
spriteViewInfo->SetAngle(Tween::AnimateSingle(LINEAR, currentViewInfo->GetAngle(), nextViewInfo->GetAngle(), scrollPeriod, CurrentAnimateTime));
spriteViewInfo->SetFontSize(Tween::AnimateSingle(LINEAR, currentViewInfo->GetFontSize(), nextViewInfo->GetFontSize(), scrollPeriod, CurrentAnimateTime));
c->Update(dt);

View File

@@ -36,6 +36,8 @@ void Text::AllocateGraphicsMemory()
void Text::Draw()
{
Component::Draw();
SDL_Texture *t = FontInst->GetTexture();
ViewInfo *info = GetBaseViewInfo();
@@ -89,7 +91,7 @@ void Text::Draw()
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());
SDL::RenderCopy(t, static_cast<char>(info->GetAlpha() * 255), &charRect, &rect, info->GetAngle());
rect.x += static_cast<int>(glyph.Advance * scale);
}
}

View File

@@ -79,6 +79,6 @@ void VideoComponent::Draw()
if(texture)
{
SDL::RenderCopy(texture, static_cast<int>(info->GetTransparency() * 255), NULL, &rect, info->GetAngle());
SDL::RenderCopy(texture, static_cast<int>(info->GetAlpha() * 255), NULL, &rect, info->GetAngle());
}
}