mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-01-27 02:05:06 +01:00
Add component tag for layouts (for custom or basic backgrounds).
This commit is contained in:
parent
d309c3b96f
commit
054688cec6
@ -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"
|
||||
|
||||
@ -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<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));
|
||||
if(BackgroundTexture)
|
||||
{
|
||||
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::RenderCopy(BackgroundTexture, static_cast<char>(info->GetBackgroundAlpha()*255), NULL, &rect, info->GetAngle());
|
||||
|
||||
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)
|
||||
|
||||
31
Source/Graphics/Component/Container.cpp
Normal file
31
Source/Graphics/Component/Container.cpp
Normal file
@ -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();
|
||||
}
|
||||
18
Source/Graphics/Component/Container.h
Normal file
18
Source/Graphics/Component/Container.h
Normal file
@ -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 <SDL2/SDL.h>
|
||||
#include <string>
|
||||
|
||||
class Container : public Component
|
||||
{
|
||||
public:
|
||||
Container();
|
||||
virtual ~Container();
|
||||
void FreeGraphicsMemory();
|
||||
void AllocateGraphicsMemory();
|
||||
void Draw();
|
||||
};
|
||||
@ -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)
|
||||
|
||||
@ -49,6 +49,7 @@ void RetroFE::Render()
|
||||
{
|
||||
page->Draw();
|
||||
}
|
||||
Logger::Write(Logger::ZONE_ERROR, "Component", "DRAW");
|
||||
|
||||
SDL_RenderPresent(SDL::GetRenderer());
|
||||
SDL_UnlockMutex(SDL::GetMutex());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user