mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-29 19:55:37 +00:00
make color themable for ratings like normal images
This commit is contained in:
parent
bd348f03a2
commit
1a6beb5520
|
@ -3,7 +3,7 @@
|
|||
#include "Window.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);
|
||||
mUnfilledTexture = TextureResource::get(":/star_unfilled.svg", true);
|
||||
|
@ -37,6 +37,22 @@ std::string RatingComponent::getValue() const
|
|||
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()
|
||||
{
|
||||
if(mSize.y() == 0)
|
||||
|
@ -87,6 +103,11 @@ void RatingComponent::updateVertices()
|
|||
mVertices[11] = mVertices[7];
|
||||
}
|
||||
|
||||
void RatingComponent::updateColors()
|
||||
{
|
||||
Renderer::buildGLColorArray(mColors, mColorShift, 12);
|
||||
}
|
||||
|
||||
void RatingComponent::render(const Eigen::Affine3f& parentTrans)
|
||||
{
|
||||
Eigen::Affine3f trans = roundMatrix(parentTrans * getTransform());
|
||||
|
@ -96,13 +117,13 @@ void RatingComponent::render(const Eigen::Affine3f& parentTrans)
|
|||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glColor4ub(255, 255, 255, getOpacity());
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), &mVertices[0].pos);
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &mVertices[0].tex);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, mColors);
|
||||
|
||||
mFilledTexture->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
@ -112,12 +133,11 @@ void RatingComponent::render(const Eigen::Affine3f& parentTrans)
|
|||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
glColor4ub(255, 255, 255, 255);
|
||||
|
||||
renderChildren(trans);
|
||||
}
|
||||
|
||||
|
@ -157,6 +177,10 @@ void RatingComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const
|
|||
imgChanged = true;
|
||||
}
|
||||
|
||||
|
||||
if(properties & COLOR && elem->has("color"))
|
||||
setColorShift(elem->get<unsigned int>("color"));
|
||||
|
||||
if(imgChanged)
|
||||
onSizeChanged();
|
||||
}
|
||||
|
|
|
@ -23,12 +23,18 @@ public:
|
|||
|
||||
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 std::vector<HelpPrompt> getHelpPrompts() override;
|
||||
|
||||
private:
|
||||
void updateVertices();
|
||||
void updateColors();
|
||||
|
||||
float mValue;
|
||||
|
||||
|
@ -38,6 +44,11 @@ private:
|
|||
Eigen::Vector2f tex;
|
||||
} mVertices[12];
|
||||
|
||||
|
||||
GLubyte mColors[12*4];
|
||||
|
||||
unsigned int mColorShift;
|
||||
|
||||
std::shared_ptr<TextureResource> mFilledTexture;
|
||||
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
|
||||
("pos", NORMALIZED_PAIR)
|
||||
("size", NORMALIZED_PAIR)
|
||||
("color", COLOR)
|
||||
("filledPath", PATH)
|
||||
("unfilledPath", PATH)
|
||||
("zIndex", FLOAT)))
|
||||
|
|
Loading…
Reference in a new issue