Added color marking to GuiMetaDataEd for newly scraped data.

This commit is contained in:
Leon Styhre 2020-06-10 19:54:37 +02:00
parent 4a38271f6a
commit 4c67dae788
6 changed files with 49 additions and 2 deletions

View file

@ -295,6 +295,14 @@ void GuiMetaDataEd::fetchDone(const ScraperSearchResult& result)
// Update the list with the scraped metadata values.
for (unsigned int i = 0; i < mEditors.size(); i++) {
const std::string& key = mMetaDataDecl.at(i).key;
if (mEditors.at(i)->getValue() != metadata->get(key)) {
if (key == "rating") {
mEditors.at(i)->setColorShift(0xDD2222FF);
}
else {
mEditors.at(i)->setColor(0x994444FF);
}
}
mEditors.at(i)->setValue(metadata->get(key));
}

View file

@ -269,6 +269,11 @@ void GuiComponent::setColorShift(unsigned int color)
mColorShiftEnd = color;
}
unsigned int GuiComponent::getColor() const
{
return mColor;
}
const Transform4x4f& GuiComponent::getTransform()
{
mTransform = Transform4x4f::Identity();

View file

@ -132,6 +132,7 @@ public:
virtual void setOpacity(unsigned char opacity);
virtual void setColor(unsigned int color);
virtual void setColorShift(unsigned int color);
virtual unsigned int getColor() const;
const Transform4x4f& getTransform();

View file

@ -176,8 +176,39 @@ void ComponentList::render(const Transform4x4f& parentTrans)
auto& entry = mEntries.at(i);
drawAll = !mFocused || i != (unsigned int)mCursor;
for (auto it = entry.data.elements.cbegin(); it != entry.data.elements.cend(); it++) {
if (drawAll || it->invert_when_selected)
it->component->render(trans);
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).
if (i == mCursor && it->component->getValue() != "" ) {
// Check if the text color is neutral.
unsigned int origColor = it->component->getColor();
unsigned char byteRed = origColor >> 24 & 0xFF;
unsigned char byteGreen = origColor >> 16 & 0xFF;
unsigned char byteBlue = origColor >> 8 & 0xFF;
// If it's neutral, just proceed with normal rendering.
if (byteRed == byteGreen && byteGreen == byteBlue) {
it->component->render(trans);
}
else {
// If there is a hue, average the brightness values to make
// an equivalent gray value before inverting the text.
// 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->render(trans);
// Revert to the original color after rendering.
it->component->setColor(origColor);
}
}
else {
it->component->render(trans);
}
}
else
drawAfterCursor.push_back(it->component.get());
}

View file

@ -30,6 +30,7 @@ public:
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
unsigned int getColor() const override { return mColor; };
void render(const Transform4x4f& parentTrans) override;
void onSizeChanged() override;

View file

@ -30,6 +30,7 @@ public:
void setBackgroundColor(unsigned int color);
void setRenderBackground(bool render);
unsigned int getColor() const override { return mColor; };
void render(const Transform4x4f& parentTrans) override;
std::string getValue() const override;