diff --git a/.hgignore b/.hgignore index 4539299..4453837 100644 --- a/.hgignore +++ b/.hgignore @@ -1,2 +1,4 @@ syntax: glob -Build/ \ No newline at end of file +Build/ +*.orig +.git \ No newline at end of file diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 49075b9..517e581 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -88,20 +88,21 @@ set(RETROFE_HEADERS "${RETROFE_DIR}/Source/Graphics/Animate/Tween.h" "${RETROFE_DIR}/Source/Graphics/Animate/TweenTypes.h" "${RETROFE_DIR}/Source/Graphics/ComponentItemBinding.h" + "${RETROFE_DIR}/Source/Graphics/Component/Container.h" "${RETROFE_DIR}/Source/Graphics/Component/Component.h" - "${RETROFE_DIR}/Source/Graphics/Font.h" - "${RETROFE_DIR}/Source/Graphics/FontCache.h" "${RETROFE_DIR}/Source/Graphics/Component/Image.h" - "${RETROFE_DIR}/Source/Graphics/Component/Text.h" - "${RETROFE_DIR}/Source/Graphics/PageBuilder.h" - "${RETROFE_DIR}/Source/Graphics/MenuNotifierInterface.h" - "${RETROFE_DIR}/Source/Graphics/Page.h" "${RETROFE_DIR}/Source/Graphics/Component/ImageBuilder.h" "${RETROFE_DIR}/Source/Graphics/Component/ReloadableMedia.h" "${RETROFE_DIR}/Source/Graphics/Component/ReloadableText.h" "${RETROFE_DIR}/Source/Graphics/Component/ScrollingList.h" + "${RETROFE_DIR}/Source/Graphics/Component/Text.h" "${RETROFE_DIR}/Source/Graphics/Component/VideoComponent.h" "${RETROFE_DIR}/Source/Graphics/Component/VideoBuilder.h" + "${RETROFE_DIR}/Source/Graphics/Font.h" + "${RETROFE_DIR}/Source/Graphics/FontCache.h" + "${RETROFE_DIR}/Source/Graphics/PageBuilder.h" + "${RETROFE_DIR}/Source/Graphics/MenuNotifierInterface.h" + "${RETROFE_DIR}/Source/Graphics/Page.h" "${RETROFE_DIR}/Source/Sound/Sound.h" "${RETROFE_DIR}/Source/Utility/Log.h" "${RETROFE_DIR}/Source/Utility/Utils.h" @@ -135,6 +136,7 @@ set(RETROFE_SOURCES "${RETROFE_DIR}/Source/Graphics/ViewInfo.cpp" "${RETROFE_DIR}/Source/Graphics/ComponentItemBindingBuilder.cpp" "${RETROFE_DIR}/Source/Graphics/ComponentItemBinding.cpp" + "${RETROFE_DIR}/Source/Graphics/Component/Container.cpp" "${RETROFE_DIR}/Source/Graphics/Component/Component.cpp" "${RETROFE_DIR}/Source/Graphics/Component/Image.cpp" "${RETROFE_DIR}/Source/Graphics/Component/ImageBuilder.cpp" diff --git a/Source/Graphics/Component/Component.cpp b/Source/Graphics/Component/Component.cpp index efdb4ee..1eec2f9 100644 --- a/Source/Graphics/Component/Component.cpp +++ b/Source/Graphics/Component/Component.cpp @@ -40,7 +40,10 @@ void Component::FreeGraphicsMemory() if(BackgroundTexture) { + SDL_LockMutex(SDL::GetMutex()); SDL_DestroyTexture(BackgroundTexture); + SDL_UnlockMutex(SDL::GetMutex()); + BackgroundTexture = NULL; } } @@ -52,7 +55,11 @@ void Component::AllocateGraphicsMemory() // 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)); + + SDL_LockMutex(SDL::GetMutex()); BackgroundTexture = SDL_CreateTextureFromSurface(SDL::GetRenderer(), surface); + SDL_UnlockMutex(SDL::GetMutex()); + SDL_FreeSurface(surface); SDL_SetTextureBlendMode(BackgroundTexture, SDL_BLENDMODE_BLEND); } @@ -201,19 +208,24 @@ void Component::Update(float dt) 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)); + if(BackgroundTexture) + { + 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::RenderCopy(BackgroundTexture, static_cast(info->GetBackgroundAlpha()*255), NULL, &rect, info->GetAngle()); + + 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) diff --git a/Source/Graphics/Component/Container.cpp b/Source/Graphics/Component/Container.cpp new file mode 100644 index 0000000..b54af75 --- /dev/null +++ b/Source/Graphics/Component/Container.cpp @@ -0,0 +1,31 @@ +/* This file is subject to the terms and conditions defined in + * file 'LICENSE.txt', which is part of this source code package. + */ +#include "Container.h" +#include "../ViewInfo.h" +#include "../../SDL.h" + +Container::Container() +{ + AllocateGraphicsMemory(); +} + +Container::~Container() +{ + FreeGraphicsMemory(); +} + +void Container::FreeGraphicsMemory() +{ + Component::FreeGraphicsMemory(); +} + +void Container::AllocateGraphicsMemory() +{ + Component::AllocateGraphicsMemory(); +} + +void Container::Draw() +{ + Component::Draw(); +} diff --git a/Source/Graphics/Component/Container.h b/Source/Graphics/Component/Container.h new file mode 100644 index 0000000..ddcf2fd --- /dev/null +++ b/Source/Graphics/Component/Container.h @@ -0,0 +1,18 @@ +/* This file is subject to the terms and conditions defined in + * file 'LICENSE.txt', which is part of this source code package. + */ +#pragma once + +#include "Component.h" +#include +#include + +class Container : public Component +{ +public: + Container(); + virtual ~Container(); + void FreeGraphicsMemory(); + void AllocateGraphicsMemory(); + void Draw(); +}; diff --git a/Source/Graphics/PageBuilder.cpp b/Source/Graphics/PageBuilder.cpp index 9169949..1235f09 100644 --- a/Source/Graphics/PageBuilder.cpp +++ b/Source/Graphics/PageBuilder.cpp @@ -4,6 +4,7 @@ #include "PageBuilder.h" #include "Page.h" #include "ViewInfo.h" +#include "Component/Container.h" #include "Component/Image.h" #include "Component/Text.h" #include "Component/ReloadableText.h" @@ -284,71 +285,80 @@ float PageBuilder::GetVerticalAlignment(xml_attribute<> *attribute, float valueI bool PageBuilder::BuildComponents(xml_node<> *layout, Page *page) { - bool retVal = true; xml_node<> *menuXml = layout->first_node("menu"); + if(!menuXml) { Logger::Write(Logger::ZONE_ERROR, "Layout", "Missing menu tag"); - retVal = false; + return false; } - else if(menuXml) + + ScrollingList *scrollingList = BuildCustomMenu(menuXml); + page->SetMenu(scrollingList); + + for(xml_node<> *componentXml = layout->first_node("container"); componentXml; componentXml = componentXml->next_sibling("container")) { - ScrollingList *scrollingList = BuildCustomMenu(menuXml); - page->SetMenu(scrollingList); - - for(xml_node<> *componentXml = layout->first_node("image"); componentXml; componentXml = componentXml->next_sibling("image")) - { - xml_attribute<> *src = componentXml->first_attribute("src"); - - if (!src) - { - Logger::Write(Logger::ZONE_ERROR, "Layout", "Image component in layout does not specify a source image file"); - } - else - { - std::string imagePath; - imagePath = Configuration::ConvertToAbsolutePath(LayoutPath, imagePath); - - imagePath.append("/"); - imagePath.append(src->value()); - - - - Image *c = new Image(imagePath, ScaleX, ScaleY); - ViewInfo *v = c->GetBaseViewInfo(); - BuildViewInfo(componentXml, v); - LoadTweens(c, componentXml); - page->AddComponent(c); - } - } - - for(xml_node<> *componentXml = layout->first_node("text"); componentXml; componentXml = componentXml->next_sibling("text")) - { - xml_attribute<> *value = componentXml->first_attribute("value"); - - if (!value) - { - Logger::Write(Logger::ZONE_WARNING, "Layout", "Text component in layout does not specify a value"); - } - else - { - FC->LoadFont(Font, FontColor); - Text *c = new Text(value->value(), FC->GetFont(Font), FontColor, ScaleX, ScaleY); - ViewInfo *v = c->GetBaseViewInfo(); - - BuildViewInfo(componentXml, v); - - LoadTweens(c, componentXml); - page->AddComponent(c); - } - } - - LoadReloadableImages(layout, "reloadableImage", page); - LoadReloadableImages(layout, "reloadableVideo", page); - LoadReloadableImages(layout, "reloadableText", page); + Container *c = new Container(); + ViewInfo *v = c->GetBaseViewInfo(); + BuildViewInfo(componentXml, v); + LoadTweens(c, componentXml); + page->AddComponent(c); } - return retVal; + + for(xml_node<> *componentXml = layout->first_node("image"); componentXml; componentXml = componentXml->next_sibling("image")) + { + xml_attribute<> *src = componentXml->first_attribute("src"); + + if (!src) + { + Logger::Write(Logger::ZONE_ERROR, "Layout", "Image component in layout does not specify a source image file"); + } + else + { + std::string imagePath; + imagePath = Configuration::ConvertToAbsolutePath(LayoutPath, imagePath); + + imagePath.append("/"); + imagePath.append(src->value()); + + + + Image *c = new Image(imagePath, ScaleX, ScaleY); + ViewInfo *v = c->GetBaseViewInfo(); + BuildViewInfo(componentXml, v); + LoadTweens(c, componentXml); + page->AddComponent(c); + } + } + + + for(xml_node<> *componentXml = layout->first_node("text"); componentXml; componentXml = componentXml->next_sibling("text")) + { + xml_attribute<> *value = componentXml->first_attribute("value"); + + if (!value) + { + Logger::Write(Logger::ZONE_WARNING, "Layout", "Text component in layout does not specify a value"); + } + else + { + FC->LoadFont(Font, FontColor); + Text *c = new Text(value->value(), FC->GetFont(Font), FontColor, ScaleX, ScaleY); + ViewInfo *v = c->GetBaseViewInfo(); + + BuildViewInfo(componentXml, v); + + LoadTweens(c, componentXml); + page->AddComponent(c); + } + } + + LoadReloadableImages(layout, "reloadableImage", page); + LoadReloadableImages(layout, "reloadableVideo", page); + LoadReloadableImages(layout, "reloadableText", page); + + return true; } void PageBuilder::LoadReloadableImages(xml_node<> *layout, std::string tagName, Page *page) diff --git a/Source/RetroFE.cpp b/Source/RetroFE.cpp index 4bf6c63..a6a7210 100644 --- a/Source/RetroFE.cpp +++ b/Source/RetroFE.cpp @@ -49,6 +49,7 @@ void RetroFE::Render() { page->Draw(); } + Logger::Write(Logger::ZONE_ERROR, "Component", "DRAW"); SDL_RenderPresent(SDL::GetRenderer()); SDL_UnlockMutex(SDL::GetMutex());