From 4c67dae78824d25064a8c87776288ee146fed927 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 10 Jun 2020 19:54:37 +0200 Subject: [PATCH] Added color marking to GuiMetaDataEd for newly scraped data. --- es-app/src/guis/GuiMetaDataEd.cpp | 8 +++++ es-core/src/GuiComponent.cpp | 5 +++ es-core/src/GuiComponent.h | 1 + es-core/src/components/ComponentList.cpp | 35 +++++++++++++++++-- .../src/components/DateTimeEditComponent.h | 1 + es-core/src/components/TextComponent.h | 1 + 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 4b2353353..22c463d42 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -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)); } diff --git a/es-core/src/GuiComponent.cpp b/es-core/src/GuiComponent.cpp index 97cbc7a36..b4cf67810 100644 --- a/es-core/src/GuiComponent.cpp +++ b/es-core/src/GuiComponent.cpp @@ -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(); diff --git a/es-core/src/GuiComponent.h b/es-core/src/GuiComponent.h index db8dfa960..7cba51e47 100644 --- a/es-core/src/GuiComponent.h +++ b/es-core/src/GuiComponent.h @@ -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(); diff --git a/es-core/src/components/ComponentList.cpp b/es-core/src/components/ComponentList.cpp index 386e8440c..ecde5c112 100644 --- a/es-core/src/components/ComponentList.cpp +++ b/es-core/src/components/ComponentList.cpp @@ -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()); } diff --git a/es-core/src/components/DateTimeEditComponent.h b/es-core/src/components/DateTimeEditComponent.h index 4b9c602ab..dc097d430 100644 --- a/es-core/src/components/DateTimeEditComponent.h +++ b/es-core/src/components/DateTimeEditComponent.h @@ -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; diff --git a/es-core/src/components/TextComponent.h b/es-core/src/components/TextComponent.h index 172110577..9d24143ec 100644 --- a/es-core/src/components/TextComponent.h +++ b/es-core/src/components/TextComponent.h @@ -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;