diff --git a/RetroFE/Source/Graphics/Component/Component.cpp b/RetroFE/Source/Graphics/Component/Component.cpp index fae7648..86fa3af 100644 --- a/RetroFE/Source/Graphics/Component/Component.cpp +++ b/RetroFE/Source/Graphics/Component/Component.cpp @@ -175,7 +175,7 @@ void Component::draw() static_cast(baseViewInfo.BackgroundGreen*255), static_cast(baseViewInfo.BackgroundBlue*255)); - SDL::renderCopy(backgroundTexture_, static_cast(baseViewInfo.BackgroundAlpha*255), NULL, &rect, baseViewInfo.Angle); + SDL::renderCopy(backgroundTexture_, static_cast(baseViewInfo.BackgroundAlpha*255), NULL, &rect, baseViewInfo.Angle, baseViewInfo.Reflection, baseViewInfo.ReflectionDistance, baseViewInfo.ReflectionScale, static_cast(baseViewInfo.ReflectionAlpha*255)); } } diff --git a/RetroFE/Source/Graphics/Component/Image.cpp b/RetroFE/Source/Graphics/Component/Image.cpp index d13de5b..7c52bce 100644 --- a/RetroFE/Source/Graphics/Component/Image.cpp +++ b/RetroFE/Source/Graphics/Component/Image.cpp @@ -84,6 +84,6 @@ void Image::draw() rect.h = static_cast(baseViewInfo.ScaledHeight()); rect.w = static_cast(baseViewInfo.ScaledWidth()); - SDL::renderCopy(texture_, static_cast((baseViewInfo.Alpha * 255)), NULL, &rect, baseViewInfo.Angle); + SDL::renderCopy(texture_, static_cast((baseViewInfo.Alpha * 255)), NULL, &rect, baseViewInfo.Angle, baseViewInfo.Reflection, baseViewInfo.ReflectionDistance, baseViewInfo.ReflectionScale, static_cast(baseViewInfo.ReflectionAlpha*255)); } } diff --git a/RetroFE/Source/Graphics/Component/Text.cpp b/RetroFE/Source/Graphics/Component/Text.cpp index 0954a5c..90805eb 100644 --- a/RetroFE/Source/Graphics/Component/Text.cpp +++ b/RetroFE/Source/Graphics/Component/Text.cpp @@ -133,7 +133,7 @@ void Text::draw() } - SDL::renderCopy(t, static_cast(baseViewInfo.Alpha * 255), &charRect, &rect, baseViewInfo.Angle); + SDL::renderCopy(t, static_cast(baseViewInfo.Alpha * 255), &charRect, &rect, baseViewInfo.Angle, baseViewInfo.Reflection, baseViewInfo.ReflectionDistance, baseViewInfo.ReflectionScale, static_cast(baseViewInfo.ReflectionAlpha*255)); rect.x += static_cast(glyph.advance * scale); diff --git a/RetroFE/Source/Graphics/Component/VideoComponent.cpp b/RetroFE/Source/Graphics/Component/VideoComponent.cpp index 672b6b4..d5bc960 100644 --- a/RetroFE/Source/Graphics/Component/VideoComponent.cpp +++ b/RetroFE/Source/Graphics/Component/VideoComponent.cpp @@ -100,6 +100,6 @@ void VideoComponent::draw() if(texture) { - SDL::renderCopy(texture, static_cast(baseViewInfo.Alpha * 255), NULL, &rect, static_cast(baseViewInfo.Angle)); + SDL::renderCopy(texture, static_cast(baseViewInfo.Alpha * 255), NULL, &rect, static_cast(baseViewInfo.Angle), baseViewInfo.Reflection, baseViewInfo.ReflectionDistance, baseViewInfo.ReflectionScale, static_cast(baseViewInfo.ReflectionAlpha*255)); } } diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index ae48e5c..f5f8e06 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -864,25 +864,29 @@ xml_attribute<> *PageBuilder::findAttribute(xml_node<> *componentXml, std::strin void PageBuilder::buildViewInfo(xml_node<> *componentXml, ViewInfo &info, xml_node<> *defaultXml) { - xml_attribute<> *x = findAttribute(componentXml, "x", defaultXml); - xml_attribute<> *y = findAttribute(componentXml, "y", defaultXml); - xml_attribute<> *xOffset = findAttribute(componentXml, "xOffset", defaultXml); - xml_attribute<> *yOffset = findAttribute(componentXml, "yOffset", defaultXml); - xml_attribute<> *xOrigin = findAttribute(componentXml, "xOrigin", defaultXml); - xml_attribute<> *yOrigin = findAttribute(componentXml, "yOrigin", defaultXml); - xml_attribute<> *height = findAttribute(componentXml, "height", defaultXml); - xml_attribute<> *width = findAttribute(componentXml, "width", defaultXml); - xml_attribute<> *fontSize = findAttribute(componentXml, "fontSize", defaultXml); - xml_attribute<> *fontColor = findAttribute(componentXml, "fontColor", defaultXml); - xml_attribute<> *minHeight = findAttribute(componentXml, "minHeight", defaultXml); - xml_attribute<> *minWidth = findAttribute(componentXml, "minWidth", defaultXml); - xml_attribute<> *maxHeight = findAttribute(componentXml, "maxHeight", defaultXml); - xml_attribute<> *maxWidth = findAttribute(componentXml, "maxWidth", defaultXml); - xml_attribute<> *alpha = findAttribute(componentXml, "alpha", defaultXml); - xml_attribute<> *angle = findAttribute(componentXml, "angle", defaultXml); - xml_attribute<> *layer = findAttribute(componentXml, "layer", defaultXml); - xml_attribute<> *backgroundColor = findAttribute(componentXml, "backgroundColor", defaultXml); - xml_attribute<> *backgroundAlpha = findAttribute(componentXml, "backgroundAlpha", defaultXml); + xml_attribute<> *x = findAttribute(componentXml, "x", defaultXml); + xml_attribute<> *y = findAttribute(componentXml, "y", defaultXml); + xml_attribute<> *xOffset = findAttribute(componentXml, "xOffset", defaultXml); + xml_attribute<> *yOffset = findAttribute(componentXml, "yOffset", defaultXml); + xml_attribute<> *xOrigin = findAttribute(componentXml, "xOrigin", defaultXml); + xml_attribute<> *yOrigin = findAttribute(componentXml, "yOrigin", defaultXml); + xml_attribute<> *height = findAttribute(componentXml, "height", defaultXml); + xml_attribute<> *width = findAttribute(componentXml, "width", defaultXml); + xml_attribute<> *fontSize = findAttribute(componentXml, "fontSize", defaultXml); + xml_attribute<> *fontColor = findAttribute(componentXml, "fontColor", defaultXml); + xml_attribute<> *minHeight = findAttribute(componentXml, "minHeight", defaultXml); + xml_attribute<> *minWidth = findAttribute(componentXml, "minWidth", defaultXml); + xml_attribute<> *maxHeight = findAttribute(componentXml, "maxHeight", defaultXml); + xml_attribute<> *maxWidth = findAttribute(componentXml, "maxWidth", defaultXml); + xml_attribute<> *alpha = findAttribute(componentXml, "alpha", defaultXml); + xml_attribute<> *angle = findAttribute(componentXml, "angle", defaultXml); + xml_attribute<> *layer = findAttribute(componentXml, "layer", defaultXml); + xml_attribute<> *backgroundColor = findAttribute(componentXml, "backgroundColor", defaultXml); + xml_attribute<> *backgroundAlpha = findAttribute(componentXml, "backgroundAlpha", defaultXml); + xml_attribute<> *reflection = findAttribute(componentXml, "reflection", defaultXml); + xml_attribute<> *reflectionDistance = findAttribute(componentXml, "reflectionDistance", defaultXml); + xml_attribute<> *reflectionScale = findAttribute(componentXml, "reflectionScale", defaultXml); + xml_attribute<> *reflectionAlpha = findAttribute(componentXml, "reflectionAlpha", defaultXml); info.X = getHorizontalAlignment(x, 0); info.Y = getVerticalAlignment(y, 0); @@ -907,14 +911,18 @@ void PageBuilder::buildViewInfo(xml_node<> *componentXml, ViewInfo &info, xml_no info.Height = getVerticalAlignment(height, -1); info.Width = getHorizontalAlignment(width, -1); } - info.FontSize = getVerticalAlignment(fontSize, -1); - info.MinHeight = getVerticalAlignment(minHeight, 0); - info.MinWidth = getHorizontalAlignment(minWidth, 0); - info.MaxHeight = getVerticalAlignment(maxHeight, FLT_MAX); - info.MaxWidth = getVerticalAlignment(maxWidth, FLT_MAX); - info.Alpha = alpha ? Utils::convertFloat(alpha->value()) : 1.f; - info.Angle = angle ? Utils::convertFloat(angle->value()) : 0.f; - info.Layer = layer ? Utils::convertInt(layer->value()) : 0; + info.FontSize = getVerticalAlignment(fontSize, -1); + info.MinHeight = getVerticalAlignment(minHeight, 0); + info.MinWidth = getHorizontalAlignment(minWidth, 0); + info.MaxHeight = getVerticalAlignment(maxHeight, FLT_MAX); + info.MaxWidth = getVerticalAlignment(maxWidth, FLT_MAX); + info.Alpha = alpha ? Utils::convertFloat(alpha->value()) : 1.f; + info.Angle = angle ? Utils::convertFloat(angle->value()) : 0.f; + info.Layer = layer ? Utils::convertInt(layer->value()) : 0; + info.Reflection = reflection ? reflection->value() : ""; + info.ReflectionDistance = reflectionDistance ? Utils::convertInt(reflectionDistance->value()) : 0; + info.ReflectionScale = reflectionScale ? Utils::convertFloat(reflectionScale->value()) : 0.25f; + info.ReflectionAlpha = reflectionAlpha ? Utils::convertFloat(reflectionAlpha->value()) : 1.f; if(fontColor) { diff --git a/RetroFE/Source/Graphics/ViewInfo.cpp b/RetroFE/Source/Graphics/ViewInfo.cpp index bfacb20..f775b6c 100644 --- a/RetroFE/Source/Graphics/ViewInfo.cpp +++ b/RetroFE/Source/Graphics/ViewInfo.cpp @@ -43,6 +43,10 @@ ViewInfo::ViewInfo() , BackgroundGreen(0) , BackgroundBlue(0) , BackgroundAlpha(0) + , Reflection("") + , ReflectionDistance(0) + , ReflectionScale(.25) + , ReflectionAlpha(1) { } diff --git a/RetroFE/Source/Graphics/ViewInfo.h b/RetroFE/Source/Graphics/ViewInfo.h index 944c9b2..91032f7 100644 --- a/RetroFE/Source/Graphics/ViewInfo.h +++ b/RetroFE/Source/Graphics/ViewInfo.h @@ -40,31 +40,35 @@ public: static const int AlignRight = -4; static const int AlignBottom = -5; - float X; - float Y; - float XOrigin; - float YOrigin; - float XOffset; - float YOffset; - float Width; - float MinWidth; - float MaxWidth; - float Height; - float MinHeight; - float MaxHeight; - float ImageWidth; - float ImageHeight; - float FontSize; - Font *font; - float Angle; - float Alpha; + float X; + float Y; + float XOrigin; + float YOrigin; + float XOffset; + float YOffset; + float Width; + float MinWidth; + float MaxWidth; + float Height; + float MinHeight; + float MaxHeight; + float ImageWidth; + float ImageHeight; + float FontSize; + Font *font; + float Angle; + float Alpha; unsigned int Layer; - float HorizontalScale; - float VerticalScale; - float BackgroundRed; - float BackgroundGreen; - float BackgroundBlue; - float BackgroundAlpha; + float HorizontalScale; + float VerticalScale; + float BackgroundRed; + float BackgroundGreen; + float BackgroundBlue; + float BackgroundAlpha; + std::string Reflection; + unsigned int ReflectionDistance; + float ReflectionScale; + float ReflectionAlpha; private: float AbsoluteHeight() const; diff --git a/RetroFE/Source/SDL.cpp b/RetroFE/Source/SDL.cpp index e74fe3a..c2c3e90 100644 --- a/RetroFE/Source/SDL.cpp +++ b/RetroFE/Source/SDL.cpp @@ -255,7 +255,7 @@ SDL_Window* SDL::getWindow() return window_; } -bool SDL::renderCopy(SDL_Texture *texture, unsigned char alpha, 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, std::string reflection, unsigned int reflectionDistance, double reflectionScale, unsigned char reflectionAlpha) { SDL_Rect rotateRect; rotateRect.w = dest->w; @@ -275,5 +275,37 @@ bool SDL::renderCopy(SDL_Texture *texture, unsigned char alpha, SDL_Rect *src, S SDL_SetTextureAlphaMod(texture, alpha); SDL_RenderCopyEx(getRenderer(), texture, src, &rotateRect, angle, NULL, SDL_FLIP_NONE); + if (reflection == "top") + { + rotateRect.h = rotateRect.h * reflectionScale; + rotateRect.y = rotateRect.y - rotateRect.h - reflectionDistance; + SDL_SetTextureAlphaMod(texture, reflectionAlpha * alpha); + SDL_RenderCopyEx(getRenderer(), texture, src, &rotateRect, angle, NULL, SDL_FLIP_VERTICAL); + } + + if (reflection == "bottom") + { + rotateRect.y = rotateRect.y + rotateRect.h + reflectionDistance; + rotateRect.h = rotateRect.h * reflectionScale; + SDL_SetTextureAlphaMod(texture, reflectionAlpha * alpha); + SDL_RenderCopyEx(getRenderer(), texture, src, &rotateRect, angle, NULL, SDL_FLIP_VERTICAL); + } + + if (reflection == "left") + { + rotateRect.w = rotateRect.w * reflectionScale; + rotateRect.x = rotateRect.x - rotateRect.w - reflectionDistance; + SDL_SetTextureAlphaMod(texture, reflectionAlpha * alpha); + SDL_RenderCopyEx(getRenderer(), texture, src, &rotateRect, angle, NULL, SDL_FLIP_HORIZONTAL); + } + + if (reflection == "right") + { + rotateRect.x = rotateRect.x + rotateRect.w + reflectionDistance; + rotateRect.w = rotateRect.w * reflectionScale; + SDL_SetTextureAlphaMod(texture, reflectionAlpha * alpha); + SDL_RenderCopyEx(getRenderer(), texture, src, &rotateRect, angle, NULL, SDL_FLIP_HORIZONTAL); + } + return true; } diff --git a/RetroFE/Source/SDL.h b/RetroFE/Source/SDL.h index 14b1a4c..6bf4645 100644 --- a/RetroFE/Source/SDL.h +++ b/RetroFE/Source/SDL.h @@ -15,6 +15,7 @@ */ #pragma once #include +#include // todo: this wrapper could be cleaned up class Configuration; @@ -27,7 +28,7 @@ public: static SDL_Renderer *getRenderer(); static SDL_mutex *getMutex(); static SDL_Window *getWindow(); - static bool renderCopy(SDL_Texture *texture, unsigned char alpha, 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, std::string reflection = "", unsigned int reflectionDistance = 0, double reflectionScale = 0.25, unsigned char reflectionAlpha = '0'); static int getWindowWidth() { return windowWidth_;