Added a property to RatingComponent to set interpolation method (nearest or linear) when using raster images.

This commit is contained in:
Leon Styhre 2022-08-28 20:45:04 +02:00
parent 2c86e4f99e
commit f61d0f1df8
2 changed files with 24 additions and 1 deletions

View file

@ -243,6 +243,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"rotation", FLOAT}, {"rotation", FLOAT},
{"rotationOrigin", NORMALIZED_PAIR}, {"rotationOrigin", NORMALIZED_PAIR},
{"gameselector", STRING}, {"gameselector", STRING},
{"interpolation", STRING},
{"color", COLOR}, {"color", COLOR},
{"filledPath", PATH}, {"filledPath", PATH},
{"unfilledPath", PATH}, {"unfilledPath", PATH},

View file

@ -181,7 +181,7 @@ void RatingComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
LOG(LogWarning) << "RatingComponent: Invalid theme configuration, property <size> " LOG(LogWarning) << "RatingComponent: Invalid theme configuration, property <size> "
"for element \"" "for element \""
<< element.substr(7) << "\" is set to zero"; << element.substr(7) << "\" is set to zero";
ratingSize.y = 0.01; ratingSize.y = 0.01f;
} }
if (ratingSize.x > 0.0f) if (ratingSize.x > 0.0f)
ratingSize.x = glm::clamp(ratingSize.x, 0.01f, 1.0f); ratingSize.x = glm::clamp(ratingSize.x, 0.01f, 1.0f);
@ -194,11 +194,32 @@ void RatingComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
mSize.x = mSize.y * NUM_RATING_STARS; mSize.x = mSize.y * NUM_RATING_STARS;
} }
bool linearInterpolation {false};
if (elem->has("interpolation")) {
const std::string interpolation {elem->get<std::string>("interpolation")};
if (interpolation == "linear") {
linearInterpolation = true;
}
else if (interpolation == "nearest") {
linearInterpolation = false;
}
else {
linearInterpolation = false;
LOG(LogWarning)
<< "RatingComponent: Invalid theme configuration, property <interpolation> "
"for element \""
<< element.substr(7) << "\" defined as \"" << interpolation << "\"";
}
}
mIconFilled.setTileSize(mSize.y, mSize.y); mIconFilled.setTileSize(mSize.y, mSize.y);
mIconFilled.setResize(glm::vec2 {mSize}, false); mIconFilled.setResize(glm::vec2 {mSize}, false);
if (properties & PATH && elem->has("filledPath")) { if (properties & PATH && elem->has("filledPath")) {
mIconFilled.setDynamic(true); mIconFilled.setDynamic(true);
mIconFilled.setLinearInterpolation(linearInterpolation);
mIconFilled.setImage(std::string(elem->get<std::string>("filledPath")), true); mIconFilled.setImage(std::string(elem->get<std::string>("filledPath")), true);
mIconFilled.getTexture()->setSize(mSize.y, mSize.y); mIconFilled.getTexture()->setSize(mSize.y, mSize.y);
if (!mIconFilled.getTexture()->getScalable()) if (!mIconFilled.getTexture()->getScalable())
@ -213,6 +234,7 @@ void RatingComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (properties & PATH && elem->has("unfilledPath")) { if (properties & PATH && elem->has("unfilledPath")) {
mIconUnfilled.setDynamic(true); mIconUnfilled.setDynamic(true);
mIconUnfilled.setLinearInterpolation(linearInterpolation);
mIconUnfilled.setImage(std::string(elem->get<std::string>("unfilledPath")), true); mIconUnfilled.setImage(std::string(elem->get<std::string>("unfilledPath")), true);
mIconUnfilled.getTexture()->setSize(mSize.y, mSize.y); mIconUnfilled.getTexture()->setSize(mSize.y, mSize.y);
if (!mIconUnfilled.getTexture()->getScalable()) if (!mIconUnfilled.getTexture()->getScalable())