mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-04-10 19:15:13 +00:00
Merge pull request #159 from jrassa/rating-color
make color themable for ratings like normal images
This commit is contained in:
commit
13ace0e42e
|
@ -3,7 +3,7 @@
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
RatingComponent::RatingComponent(Window* window) : GuiComponent(window)
|
RatingComponent::RatingComponent(Window* window) : GuiComponent(window), mColorShift(0xFFFFFFFF)
|
||||||
{
|
{
|
||||||
mFilledTexture = TextureResource::get(":/star_filled.svg", true);
|
mFilledTexture = TextureResource::get(":/star_filled.svg", true);
|
||||||
mUnfilledTexture = TextureResource::get(":/star_unfilled.svg", true);
|
mUnfilledTexture = TextureResource::get(":/star_unfilled.svg", true);
|
||||||
|
@ -37,6 +37,22 @@ std::string RatingComponent::getValue() const
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RatingComponent::setOpacity(unsigned char opacity)
|
||||||
|
{
|
||||||
|
mOpacity = opacity;
|
||||||
|
mColorShift = (mColorShift >> 8 << 8) | mOpacity;
|
||||||
|
updateColors();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RatingComponent::setColorShift(unsigned int color)
|
||||||
|
{
|
||||||
|
mColorShift = color;
|
||||||
|
// Grab the opacity from the color shift because we may need to apply it if
|
||||||
|
// fading textures in
|
||||||
|
mOpacity = color & 0xff;
|
||||||
|
updateColors();
|
||||||
|
}
|
||||||
|
|
||||||
void RatingComponent::onSizeChanged()
|
void RatingComponent::onSizeChanged()
|
||||||
{
|
{
|
||||||
if(mSize.y() == 0)
|
if(mSize.y() == 0)
|
||||||
|
@ -87,6 +103,11 @@ void RatingComponent::updateVertices()
|
||||||
mVertices[11] = mVertices[7];
|
mVertices[11] = mVertices[7];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RatingComponent::updateColors()
|
||||||
|
{
|
||||||
|
Renderer::buildGLColorArray(mColors, mColorShift, 12);
|
||||||
|
}
|
||||||
|
|
||||||
void RatingComponent::render(const Eigen::Affine3f& parentTrans)
|
void RatingComponent::render(const Eigen::Affine3f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = roundMatrix(parentTrans * getTransform());
|
Eigen::Affine3f trans = roundMatrix(parentTrans * getTransform());
|
||||||
|
@ -96,13 +117,13 @@ void RatingComponent::render(const Eigen::Affine3f& parentTrans)
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
glColor4ub(255, 255, 255, getOpacity());
|
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), &mVertices[0].pos);
|
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), &mVertices[0].pos);
|
||||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &mVertices[0].tex);
|
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &mVertices[0].tex);
|
||||||
|
glColorPointer(4, GL_UNSIGNED_BYTE, 0, mColors);
|
||||||
|
|
||||||
mFilledTexture->bind();
|
mFilledTexture->bind();
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
@ -112,12 +133,11 @@ void RatingComponent::render(const Eigen::Affine3f& parentTrans)
|
||||||
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
glColor4ub(255, 255, 255, 255);
|
|
||||||
|
|
||||||
renderChildren(trans);
|
renderChildren(trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +177,10 @@ void RatingComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const
|
||||||
imgChanged = true;
|
imgChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(properties & COLOR && elem->has("color"))
|
||||||
|
setColorShift(elem->get<unsigned int>("color"));
|
||||||
|
|
||||||
if(imgChanged)
|
if(imgChanged)
|
||||||
onSizeChanged();
|
onSizeChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,18 @@ public:
|
||||||
|
|
||||||
void onSizeChanged() override;
|
void onSizeChanged() override;
|
||||||
|
|
||||||
|
void setOpacity(unsigned char opacity) override;
|
||||||
|
|
||||||
|
// Multiply all pixels in the image by this color when rendering.
|
||||||
|
void setColorShift(unsigned int color);
|
||||||
|
|
||||||
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
|
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
|
||||||
|
|
||||||
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateVertices();
|
void updateVertices();
|
||||||
|
void updateColors();
|
||||||
|
|
||||||
float mValue;
|
float mValue;
|
||||||
|
|
||||||
|
@ -38,6 +44,11 @@ private:
|
||||||
Eigen::Vector2f tex;
|
Eigen::Vector2f tex;
|
||||||
} mVertices[12];
|
} mVertices[12];
|
||||||
|
|
||||||
|
|
||||||
|
GLubyte mColors[12*4];
|
||||||
|
|
||||||
|
unsigned int mColorShift;
|
||||||
|
|
||||||
std::shared_ptr<TextureResource> mFilledTexture;
|
std::shared_ptr<TextureResource> mFilledTexture;
|
||||||
std::shared_ptr<TextureResource> mUnfilledTexture;
|
std::shared_ptr<TextureResource> mUnfilledTexture;
|
||||||
};
|
};
|
||||||
|
|
|
@ -88,6 +88,7 @@ std::map< std::string, ElementMapType > ThemeData::sElementMap = boost::assign::
|
||||||
("rating", makeMap(boost::assign::map_list_of
|
("rating", makeMap(boost::assign::map_list_of
|
||||||
("pos", NORMALIZED_PAIR)
|
("pos", NORMALIZED_PAIR)
|
||||||
("size", NORMALIZED_PAIR)
|
("size", NORMALIZED_PAIR)
|
||||||
|
("color", COLOR)
|
||||||
("filledPath", PATH)
|
("filledPath", PATH)
|
||||||
("unfilledPath", PATH)
|
("unfilledPath", PATH)
|
||||||
("zIndex", FLOAT)))
|
("zIndex", FLOAT)))
|
||||||
|
|
Loading…
Reference in a new issue