mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 06:05:38 +00:00
Implemented (somehow) proper inversions for images in menus.
This commit is contained in:
parent
f1f0596fe1
commit
bd33d5a3b9
|
@ -20,6 +20,9 @@
|
|||
GuiComponent::GuiComponent(Window* window)
|
||||
: mWindow(window),
|
||||
mParent(nullptr),
|
||||
mColor(0),
|
||||
mColorShift(0),
|
||||
mColorShiftEnd(0),
|
||||
mOpacity(255),
|
||||
mSaturation(1.0),
|
||||
mPosition(Vector3f::Zero()),
|
||||
|
@ -269,6 +272,11 @@ unsigned int GuiComponent::getColor() const
|
|||
return mColor;
|
||||
}
|
||||
|
||||
unsigned int GuiComponent::getColorShift() const
|
||||
{
|
||||
return mColorShift;
|
||||
}
|
||||
|
||||
void GuiComponent::setColor(unsigned int color)
|
||||
{
|
||||
mColor = color;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#define DEFAULT_TEXTCOLOR 0x777777FF
|
||||
#define DEFAULT_INVERTED_TEXTCOLOR 0x444444FF
|
||||
#define DEFAULT_INVERTED_IMAGECOLOR 0x666666FF
|
||||
#define DEFAULT_COLORSHIFT 0xFFFFFFFF
|
||||
#define ICONCOLOR_SCRAPERMARKED 0xFF5555FF
|
||||
#define ICONCOLOR_USERMARKED 0x5555FFFF
|
||||
|
@ -145,6 +146,7 @@ public:
|
|||
virtual unsigned char getOpacity() const;
|
||||
virtual void setOpacity(unsigned char opacity);
|
||||
virtual unsigned int getColor() const;
|
||||
virtual unsigned int getColorShift() const;
|
||||
virtual void setColor(unsigned int color);
|
||||
virtual float getSaturation() const;
|
||||
virtual void setSaturation(float saturation);
|
||||
|
|
|
@ -196,11 +196,17 @@ void ComponentList::render(const Transform4x4f& parentTrans)
|
|||
for (auto it = entry.data.elements.cbegin(); it != entry.data.elements.cend(); it++) {
|
||||
if (drawAll || it->invert_when_selected) {
|
||||
// For the row where the cursor is at, we want to remove any hue from the
|
||||
// font color before inverting, as it would otherwise lead to an ugly
|
||||
// inverted color (e.g. red text inverting to a green hue).
|
||||
// font or image before inverting, as it would otherwise lead to an ugly
|
||||
// inverted color (e.g. red inverting to a green hue).
|
||||
if (i == mCursor && it->component->getValue() != "" ) {
|
||||
// Check if the text color is neutral.
|
||||
// Check if we're dealing with text or an image component.
|
||||
bool isTextComponent = true;
|
||||
unsigned int origColor = it->component->getColor();
|
||||
if (origColor == 0) {
|
||||
origColor = it->component->getColorShift();
|
||||
isTextComponent = false;
|
||||
}
|
||||
// Check if the color is neutral.
|
||||
unsigned char byteRed = origColor >> 24 & 0xFF;
|
||||
unsigned char byteGreen = origColor >> 16 & 0xFF;
|
||||
unsigned char byteBlue = origColor >> 8 & 0xFF;
|
||||
|
@ -210,22 +216,28 @@ void ComponentList::render(const Transform4x4f& parentTrans)
|
|||
}
|
||||
else {
|
||||
// Note: I've disabled this code as it's overly complicated,
|
||||
// instead we're now using a simple constant which should be
|
||||
// instead we're now using simple constants which should be
|
||||
// good enough. Let's keep the code though if needed in the
|
||||
// future for some reason.
|
||||
// // If there is a hue, average the brightness values to make
|
||||
// // an equivalent gray value before inverting the text.
|
||||
// // an equivalent gray value before inverting.
|
||||
// // This is not the proper way to do a BW conversion as the RGB values
|
||||
// // should not be evenly distributed, but it's definitely good enough
|
||||
// // for this situation.
|
||||
// unsigned char byteAverage = (byteRed + byteGreen + byteBlue) / 3;
|
||||
// unsigned int averageColor = byteAverage << 24 | byteAverage << 16 |
|
||||
// byteAverage << 8 | 0xFF;
|
||||
// it->component->setColor(averageColor);
|
||||
it->component->setColor(DEFAULT_INVERTED_TEXTCOLOR);
|
||||
if (isTextComponent)
|
||||
it->component->setColor(DEFAULT_INVERTED_TEXTCOLOR);
|
||||
else
|
||||
it->component->setColorShift(DEFAULT_INVERTED_IMAGECOLOR);
|
||||
|
||||
it->component->render(trans);
|
||||
// Revert to the original color after rendering.
|
||||
it->component->setColor(origColor);
|
||||
if (isTextComponent)
|
||||
it->component->setColor(origColor);
|
||||
else
|
||||
it->component->setColorShift(origColor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
|
||||
// Multiply all pixels in the image by this color when rendering.
|
||||
void setColorShift(unsigned int color) override;
|
||||
unsigned int getColorShift() const override { return mColorShift; };
|
||||
|
||||
void setOriginalColor(unsigned int color) override { mColorOriginalValue = color; };
|
||||
void setChangedColor(unsigned int color) override { mColorChangedValue = color; };
|
||||
|
|
|
@ -89,6 +89,11 @@ void SwitchComponent::setColorShift(unsigned int color)
|
|||
mImage.setColorShift(color);
|
||||
}
|
||||
|
||||
unsigned int SwitchComponent::getColorShift() const
|
||||
{
|
||||
return mImage.getColorShift();
|
||||
}
|
||||
|
||||
void SwitchComponent::onStateChanged()
|
||||
{
|
||||
mImage.setImage(mState ? ":/graphics/on.svg" : ":/graphics/off.svg");
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
// Multiply all pixels in the image by this color when rendering.
|
||||
void setColorShift(unsigned int color) override;
|
||||
|
||||
unsigned int getColorShift() const override;
|
||||
|
||||
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue