Added support for image reflection via the following attributes:

reflection: top, bottom, left or right
reflectionDistance: distance between the image and the reflected image
reflectionScale: scaling of the image in the direction of the reflection
reflectionAlpha: transparency factor of the reflection
This commit is contained in:
Pieter Hulshoff 2016-06-17 11:01:08 +02:00
parent a63c10ec5c
commit f1fe21843d
9 changed files with 106 additions and 57 deletions

View File

@ -175,7 +175,7 @@ void Component::draw()
static_cast<char>(baseViewInfo.BackgroundGreen*255),
static_cast<char>(baseViewInfo.BackgroundBlue*255));
SDL::renderCopy(backgroundTexture_, static_cast<char>(baseViewInfo.BackgroundAlpha*255), NULL, &rect, baseViewInfo.Angle);
SDL::renderCopy(backgroundTexture_, static_cast<char>(baseViewInfo.BackgroundAlpha*255), NULL, &rect, baseViewInfo.Angle, baseViewInfo.Reflection, baseViewInfo.ReflectionDistance, baseViewInfo.ReflectionScale, static_cast<char>(baseViewInfo.ReflectionAlpha*255));
}
}

View File

@ -84,6 +84,6 @@ void Image::draw()
rect.h = static_cast<int>(baseViewInfo.ScaledHeight());
rect.w = static_cast<int>(baseViewInfo.ScaledWidth());
SDL::renderCopy(texture_, static_cast<char>((baseViewInfo.Alpha * 255)), NULL, &rect, baseViewInfo.Angle);
SDL::renderCopy(texture_, static_cast<char>((baseViewInfo.Alpha * 255)), NULL, &rect, baseViewInfo.Angle, baseViewInfo.Reflection, baseViewInfo.ReflectionDistance, baseViewInfo.ReflectionScale, static_cast<char>(baseViewInfo.ReflectionAlpha*255));
}
}

View File

@ -133,7 +133,7 @@ void Text::draw()
}
SDL::renderCopy(t, static_cast<char>(baseViewInfo.Alpha * 255), &charRect, &rect, baseViewInfo.Angle);
SDL::renderCopy(t, static_cast<char>(baseViewInfo.Alpha * 255), &charRect, &rect, baseViewInfo.Angle, baseViewInfo.Reflection, baseViewInfo.ReflectionDistance, baseViewInfo.ReflectionScale, static_cast<char>(baseViewInfo.ReflectionAlpha*255));
rect.x += static_cast<int>(glyph.advance * scale);

View File

@ -100,6 +100,6 @@ void VideoComponent::draw()
if(texture)
{
SDL::renderCopy(texture, static_cast<int>(baseViewInfo.Alpha * 255), NULL, &rect, static_cast<int>(baseViewInfo.Angle));
SDL::renderCopy(texture, static_cast<int>(baseViewInfo.Alpha * 255), NULL, &rect, static_cast<int>(baseViewInfo.Angle), baseViewInfo.Reflection, baseViewInfo.ReflectionDistance, baseViewInfo.ReflectionScale, static_cast<char>(baseViewInfo.ReflectionAlpha*255));
}
}

View File

@ -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)
{

View File

@ -43,6 +43,10 @@ ViewInfo::ViewInfo()
, BackgroundGreen(0)
, BackgroundBlue(0)
, BackgroundAlpha(0)
, Reflection("")
, ReflectionDistance(0)
, ReflectionScale(.25)
, ReflectionAlpha(1)
{
}

View File

@ -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;

View File

@ -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;
}

View File

@ -15,6 +15,7 @@
*/
#pragma once
#include <SDL2/SDL.h>
#include <string>
// 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_;