diff --git a/Assets/Environment/Common/Layouts/Default 16x9/Layout.xml b/Assets/Environment/Common/Layouts/Default 16x9/Layout.xml index 4a1a58c..43cf723 100644 --- a/Assets/Environment/Common/Layouts/Default 16x9/Layout.xml +++ b/Assets/Environment/Common/Layouts/Default 16x9/Layout.xml @@ -10,20 +10,20 @@ - - - - - - - - - + + + + + + + + + - + - + @@ -97,24 +97,24 @@ - + - + - + - + diff --git a/Assets/Environment/Common/Layouts/Default 4x3/Layout.xml b/Assets/Environment/Common/Layouts/Default 4x3/Layout.xml index 471c965..6695cfc 100644 --- a/Assets/Environment/Common/Layouts/Default 4x3/Layout.xml +++ b/Assets/Environment/Common/Layouts/Default 4x3/Layout.xml @@ -10,20 +10,20 @@ - - - - - - - - - + + + + + + + + + - + - + @@ -59,24 +59,24 @@ - + - + - + - + diff --git a/Source/Execute/AttractMode.cpp b/Source/Execute/AttractMode.cpp index 559f56e..d4dc21e 100644 --- a/Source/Execute/AttractMode.cpp +++ b/Source/Execute/AttractMode.cpp @@ -1,14 +1,14 @@ -/* This file is subject to the terms and conditions defined in - * file 'LICENSE.txt', which is part of this source code package. +/* This file is subject to the terms and conditions defined in + * file 'LICENSE.txt', which is part of this source code package. */ #include "AttractMode.h" #include "../Graphics/Page.h" AttractMode::AttractMode() -: IsActive(false) -, ElapsedTime(0) -, ActiveTime(0) -, IdleTime(0) + : IsActive(false) + , ElapsedTime(0) + , ActiveTime(0) + , IdleTime(0) { } diff --git a/Source/Execute/AttractMode.h b/Source/Execute/AttractMode.h index ac821e7..5ed1465 100644 --- a/Source/Execute/AttractMode.h +++ b/Source/Execute/AttractMode.h @@ -18,5 +18,5 @@ private: float ElapsedTime; float ActiveTime; float IdleTime; - + }; diff --git a/Source/Graphics/Animate/Tween.cpp b/Source/Graphics/Animate/Tween.cpp index ed91f72..2bcb26b 100644 --- a/Source/Graphics/Animate/Tween.cpp +++ b/Source/Graphics/Animate/Tween.cpp @@ -34,7 +34,7 @@ bool Tween::GetTweenProperty(std::string name, TweenProperty &property) TweenPropertyMap["x"] = TWEEN_PROPERTY_X; TweenPropertyMap["y"] = TWEEN_PROPERTY_Y; TweenPropertyMap["angle"] = TWEEN_PROPERTY_ANGLE; - TweenPropertyMap["transparency"] = TWEEN_PROPERTY_TRANSPARENCY; + TweenPropertyMap["alpha"] = TWEEN_PROPERTY_ALPHA; TweenPropertyMap["width"] = TWEEN_PROPERTY_WIDTH; TweenPropertyMap["height"] = TWEEN_PROPERTY_HEIGHT; TweenPropertyMap["xorigin"] = TWEEN_PROPERTY_X_ORIGIN; diff --git a/Source/Graphics/Animate/TweenTypes.h b/Source/Graphics/Animate/TweenTypes.h index d02149e..074543a 100644 --- a/Source/Graphics/Animate/TweenTypes.h +++ b/Source/Graphics/Animate/TweenTypes.h @@ -34,7 +34,7 @@ enum TweenProperty TWEEN_PROPERTY_HEIGHT, TWEEN_PROPERTY_WIDTH, TWEEN_PROPERTY_ANGLE, - TWEEN_PROPERTY_TRANSPARENCY, + TWEEN_PROPERTY_ALPHA, TWEEN_PROPERTY_X, TWEEN_PROPERTY_Y, TWEEN_PROPERTY_X_ORIGIN, diff --git a/Source/Graphics/Component/Component.cpp b/Source/Graphics/Component/Component.cpp index cc0e73c..efdb4ee 100644 --- a/Source/Graphics/Component/Component.cpp +++ b/Source/Graphics/Component/Component.cpp @@ -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(info->GetHeight()); + rect.w = static_cast(info->GetWidth()); + rect.x = static_cast(info->GetXRelativeToOrigin()); + rect.y = static_cast(info->GetYRelativeToOrigin()); + + SDL_SetTextureColorMod(BackgroundTexture, + static_cast(info->GetBackgroundRed()*255), + static_cast(info->GetBackgroundGreen()*255), + static_cast(info->GetBackgroundBlue()*255)); + + SDL::RenderCopy(BackgroundTexture, static_cast(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: diff --git a/Source/Graphics/Component/Component.h b/Source/Graphics/Component/Component.h index ff0807c..24da67e 100644 --- a/Source/Graphics/Component/Component.h +++ b/Source/Graphics/Component/Component.h @@ -5,6 +5,7 @@ #include +#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; + }; diff --git a/Source/Graphics/Component/Image.cpp b/Source/Graphics/Component/Image.cpp index ab91425..4994ce3 100644 --- a/Source/Graphics/Component/Image.cpp +++ b/Source/Graphics/Component/Image.cpp @@ -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(info->GetHeight()); rect.w = static_cast(info->GetWidth()); - SDL::RenderCopy(Texture, static_cast((info->GetTransparency() * 255)), NULL, &rect, info->GetAngle()); + SDL::RenderCopy(Texture, static_cast((info->GetAlpha() * 255)), NULL, &rect, info->GetAngle()); } } diff --git a/Source/Graphics/Component/ReloadableMedia.cpp b/Source/Graphics/Component/ReloadableMedia.cpp index 4a8e817..1d26cc2 100644 --- a/Source/Graphics/Component/ReloadableMedia.cpp +++ b/Source/Graphics/Component/ReloadableMedia.cpp @@ -162,6 +162,8 @@ void ReloadableMedia::Draw() { ViewInfo *info = GetBaseViewInfo(); + Component::Draw(); + if(LoadedComponent) { info->SetImageHeight(LoadedComponent->GetBaseViewInfo()->GetImageHeight()); diff --git a/Source/Graphics/Component/ScrollingList.cpp b/Source/Graphics/Component/ScrollingList.cpp index 5d74ade..f21fe20 100644 --- a/Source/Graphics/Component/ScrollingList.cpp +++ b/Source/Graphics/Component/ScrollingList.cpp @@ -61,11 +61,11 @@ ScrollingList::~ScrollingList() { if(SpriteList) { - std::vector::iterator it = SpriteList->begin(); + std::vector::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); diff --git a/Source/Graphics/Component/Text.cpp b/Source/Graphics/Component/Text.cpp index c4b472d..c2edd73 100644 --- a/Source/Graphics/Component/Text.cpp +++ b/Source/Graphics/Component/Text.cpp @@ -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(info->GetTransparency() * 255), &charRect, &rect, info->GetAngle()); + SDL::RenderCopy(t, static_cast(info->GetAlpha() * 255), &charRect, &rect, info->GetAngle()); rect.x += static_cast(glyph.Advance * scale); } } diff --git a/Source/Graphics/Component/VideoComponent.cpp b/Source/Graphics/Component/VideoComponent.cpp index 16ecc47..0e7a48f 100644 --- a/Source/Graphics/Component/VideoComponent.cpp +++ b/Source/Graphics/Component/VideoComponent.cpp @@ -79,6 +79,6 @@ void VideoComponent::Draw() if(texture) { - SDL::RenderCopy(texture, static_cast(info->GetTransparency() * 255), NULL, &rect, info->GetAngle()); + SDL::RenderCopy(texture, static_cast(info->GetAlpha() * 255), NULL, &rect, info->GetAngle()); } } diff --git a/Source/Graphics/PageBuilder.cpp b/Source/Graphics/PageBuilder.cpp index 9700adf..9169949 100644 --- a/Source/Graphics/PageBuilder.cpp +++ b/Source/Graphics/PageBuilder.cpp @@ -523,9 +523,11 @@ void PageBuilder::BuildViewInfo(xml_node<> *componentXml, ViewInfo *info) xml_attribute<> *minWidth = FindRecursiveAttribute(componentXml, "minWidth"); xml_attribute<> *maxHeight = FindRecursiveAttribute(componentXml, "maxHeight"); xml_attribute<> *maxWidth = FindRecursiveAttribute(componentXml, "maxWidth"); - xml_attribute<> *transparency = FindRecursiveAttribute(componentXml, "transparency"); + xml_attribute<> *alpha = FindRecursiveAttribute(componentXml, "alpha"); xml_attribute<> *angle = FindRecursiveAttribute(componentXml, "angle"); xml_attribute<> *layer = FindRecursiveAttribute(componentXml, "layer"); + xml_attribute<> *backgroundColor = FindRecursiveAttribute(componentXml, "backgroundColor"); + xml_attribute<> *backgroundAlpha = FindRecursiveAttribute(componentXml, "backgroundAlpha"); info->SetX(GetHorizontalAlignment(x, 0)); info->SetY(GetVerticalAlignment(y, 0)); @@ -552,18 +554,37 @@ void PageBuilder::BuildViewInfo(xml_node<> *componentXml, ViewInfo *info) info->SetWidth(GetHorizontalAlignment(width, -1)); } info->SetFontSize(GetVerticalAlignment(fontSize, -1)); - /* - std::stringstream ss; - ss << "font size is \"" << info->GetFontSize() << "\""; - Logger::Write(Logger::ZONE_ERROR, "Layout", ss.str()); - */ info->SetMinHeight(GetVerticalAlignment(minHeight, 0)); info->SetMinWidth(GetHorizontalAlignment(minWidth, 0)); info->SetMaxHeight(GetVerticalAlignment(maxHeight, FLT_MAX)); info->SetMaxWidth(GetVerticalAlignment(maxWidth, FLT_MAX)); - info->SetTransparency( transparency ? Utils::ConvertFloat(transparency->value()) : 1); + info->SetAlpha( alpha ? Utils::ConvertFloat(alpha->value()) : 1); info->SetAngle( angle ? Utils::ConvertFloat(angle->value()) : 0); info->SetLayer( layer ? Utils::ConvertInt(layer->value()) : 0); + + if(backgroundColor) + { + std::stringstream ss(backgroundColor->value()); + int num; + ss >> std::hex >> num; + int red = num / 0x10000; + int green = (num / 0x100) % 0x100; + int blue = num % 0x100; + + info->SetBackgroundRed(static_cast(red)/255); + info->SetBackgroundGreen(static_cast(green)/255); + info->SetBackgroundBlue(static_cast(blue)/255); + } + + if(backgroundAlpha) + { + std::stringstream ss(backgroundAlpha->value()); + int num; + ss >> std::hex >> num; + + info->SetBackgroundAlpha(static_cast(num)/255); + } + } diff --git a/Source/Graphics/ViewInfo.cpp b/Source/Graphics/ViewInfo.cpp index d795174..7fbfc4f 100644 --- a/Source/Graphics/ViewInfo.cpp +++ b/Source/Graphics/ViewInfo.cpp @@ -23,8 +23,12 @@ ViewInfo::ViewInfo() , ImageHeight(0) , FontSize(-1) , Angle(0) - , Transparency(1) + , Alpha(1) , Layer(0) + , BackgroundRed(0) + , BackgroundGreen(0) + , BackgroundBlue(0) + , BackgroundAlpha(0) { } @@ -201,14 +205,14 @@ void ViewInfo::SetMinWidth(float minwidth) MinWidth = minwidth; } -float ViewInfo::GetTransparency() const +float ViewInfo::GetAlpha() const { - return Transparency; + return Alpha; } -void ViewInfo::SetTransparency(float transparency) +void ViewInfo::SetAlpha(float alpha) { - Transparency = transparency; + Alpha = alpha; } float ViewInfo::GetX() const @@ -298,3 +302,43 @@ void ViewInfo::SetFontSize(float fontSize) { FontSize = fontSize; } + + +float ViewInfo::GetBackgroundRed() +{ + return BackgroundRed; +} + +void ViewInfo::SetBackgroundRed(float value) +{ + BackgroundRed = value; +} + +float ViewInfo::GetBackgroundGreen() +{ + return BackgroundGreen; +} + +void ViewInfo::SetBackgroundGreen(float value) +{ + BackgroundGreen = value; +} +float ViewInfo::GetBackgroundBlue() +{ + return BackgroundBlue; +} + +void ViewInfo::SetBackgroundBlue(float value) +{ + BackgroundBlue = value; +} + +float ViewInfo::GetBackgroundAlpha() +{ + return BackgroundAlpha; +} + +void ViewInfo::SetBackgroundAlpha(float value) +{ + BackgroundAlpha = value; +} \ No newline at end of file diff --git a/Source/Graphics/ViewInfo.h b/Source/Graphics/ViewInfo.h index 4bbde83..6d87331 100644 --- a/Source/Graphics/ViewInfo.h +++ b/Source/Graphics/ViewInfo.h @@ -35,8 +35,8 @@ public: void SetMinHeight(float minheight); float GetMinWidth() const; void SetMinWidth(float minwidth); - float GetTransparency() const; - void SetTransparency(float transparency); + float GetAlpha() const; + void SetAlpha(float alpha); float GetX() const; void SetX(float x); float GetXOffset() const; @@ -54,6 +54,15 @@ public: float GetRawWidth(); float GetRawHeight(); + float GetBackgroundRed(); + void SetBackgroundRed(float value); + float GetBackgroundGreen(); + void SetBackgroundGreen(float value); + float GetBackgroundBlue(); + void SetBackgroundBlue(float value); + float GetBackgroundAlpha(); + void SetBackgroundAlpha(float value); + void SetHeight(float height); void SetWidth(float width); float GetFontSize() const; @@ -82,8 +91,12 @@ private: float ImageHeight; float FontSize; float Angle; - float Transparency; + float Alpha; unsigned int Layer; float HorizontalScale; float VerticalScale; + float BackgroundRed; + float BackgroundGreen; + float BackgroundBlue; + float BackgroundAlpha; }; diff --git a/Source/RetroFE.cpp b/Source/RetroFE.cpp index 6374cc4..4bf6c63 100644 --- a/Source/RetroFE.cpp +++ b/Source/RetroFE.cpp @@ -279,7 +279,7 @@ bool RetroFE::Back(bool &exit) bool exitOnBack = false; Config.GetProperty("exitOnFirstPageBack", exitOnBack); exit = false; - + if(PageChain.size() > 1) { Page *page = PageChain.back(); @@ -374,7 +374,7 @@ Page *RetroFE::LoadPage(std::string collectionName) Logger::Write(Logger::ZONE_INFO, "RetroFE", "Creating page for collection " + collectionName); Page *page = NULL; - + std::vector *collection = GetCollection(collectionName); std::string layoutName = GetLayout(collectionName); @@ -387,7 +387,7 @@ Page *RetroFE::LoadPage(std::string collectionName) PageBuilder pb(layoutName, collectionName, Config, &FC); page = pb.BuildPage(); - if(!page) + if(!page) { Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not create page for " + collectionName); } diff --git a/Source/RetroFE.h b/Source/RetroFE.h index 042303e..1807a8a 100644 --- a/Source/RetroFE.h +++ b/Source/RetroFE.h @@ -49,7 +49,7 @@ private: RETROFE_STATE ProcessUserInput(Page *page); void Update(float dt, bool scrollActive); std::string GetLayout(std::string collectionName); - std::vector *GetCollection(std::string collectionName); + std::vector *GetCollection(std::string collectionName); Configuration &Config; CollectionDatabase &CollectionDB; UserInput Input; diff --git a/Source/SDL.cpp b/Source/SDL.cpp index 22543b7..b34d5bb 100644 --- a/Source/SDL.cpp +++ b/Source/SDL.cpp @@ -230,8 +230,7 @@ SDL_Window* SDL::GetWindow() return Window; } - -bool SDL::RenderCopy(SDL_Texture *texture, unsigned char transparency, SDL_Rect *src, SDL_Rect *dest, double angle) +bool SDL::RenderCopy(SDL_Texture *texture, unsigned char alpha, SDL_Rect *src, SDL_Rect *dest, double angle) { SDL_Rect rotateRect; rotateRect.w = dest->w; @@ -248,7 +247,7 @@ bool SDL::RenderCopy(SDL_Texture *texture, unsigned char transparency, SDL_Rect rotateRect.y = dest->y; } - SDL_SetTextureAlphaMod(texture, transparency); + SDL_SetTextureAlphaMod(texture, alpha); SDL_RenderCopyEx(GetRenderer(), texture, src, &rotateRect, angle, NULL, SDL_FLIP_NONE); return true; diff --git a/Source/SDL.h b/Source/SDL.h index 2fbb4d3..c546a9a 100644 --- a/Source/SDL.h +++ b/Source/SDL.h @@ -15,7 +15,7 @@ public: static SDL_Renderer *GetRenderer(); static SDL_mutex *GetMutex(); static SDL_Window *GetWindow(); - static bool RenderCopy(SDL_Texture *texture, unsigned char transparency, SDL_Rect *src, SDL_Rect *dest, double angle); + static bool RenderCopy(SDL_Texture *texture, unsigned char alpha, SDL_Rect *src, SDL_Rect *dest, double angle); static int GetWindowWidth() { return WindowWidth;