From e5bada7f519419b9086b86ac6d2e6e7b1ebb1d2e Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sun, 6 Apr 2014 19:15:02 -0500 Subject: [PATCH] Some styling changes, a little refactoring of RatingComponent. --- src/components/HelpComponent.cpp | 4 +-- src/components/RatingComponent.cpp | 30 +++++++++++------------ src/components/RatingComponent.h | 6 +++-- src/components/ScraperSearchComponent.cpp | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/components/HelpComponent.cpp b/src/components/HelpComponent.cpp index 58c4bb2cf..255f32f85 100644 --- a/src/components/HelpComponent.cpp +++ b/src/components/HelpComponent.cpp @@ -9,8 +9,8 @@ #include -#define OFFSET_X 6 // move the entire thing right by this amount (px) -#define OFFSET_Y 6 // move the entire thing up by this amount (px) +#define OFFSET_X 12 // move the entire thing right by this amount (px) +#define OFFSET_Y 12 // move the entire thing up by this amount (px) #define ICON_TEXT_SPACING 8 // space between [icon] and [text] (px) #define ENTRY_SPACING 16 // space between [text] and next [icon] (px) diff --git a/src/components/RatingComponent.cpp b/src/components/RatingComponent.cpp index dccc0a13c..980a4f3d2 100644 --- a/src/components/RatingComponent.cpp +++ b/src/components/RatingComponent.cpp @@ -9,7 +9,7 @@ RatingComponent::RatingComponent(Window* window) : GuiComponent(window) mFilledTexture = TextureResource::get(":/star_filled.svg", true); mUnfilledTexture = TextureResource::get(":/star_unfilled.svg", true); mValue = 0.5f; - mSize << 64 * 5.0f, 64; + mSize << 64 * NUM_RATING_STARS, 64; updateVertices(); } @@ -18,14 +18,14 @@ void RatingComponent::setValue(const std::string& value) if(value.empty()) { mValue = 0.0f; - return; + }else{ + mValue = stof(value); + if(mValue > 1.0f) + mValue = 1.0f; + else if(mValue < 0.0f) + mValue = 0.0f; } - mValue = stof(value); - if(mValue > 1.0f) - mValue = 1.0f; - else if(mValue < 0.0f) - mValue = 0.0f; updateVertices(); } @@ -37,20 +37,20 @@ std::string RatingComponent::getValue() const void RatingComponent::onSizeChanged() { if(mSize.y() == 0) - mSize[1] = mSize.x() / 5.0f; + mSize[1] = mSize.x() / NUM_RATING_STARS; else if(mSize.x() == 0) - mSize[0] = mSize.y() * 5.0f; + mSize[0] = mSize.y() * NUM_RATING_STARS; auto filledSVG = dynamic_cast(mFilledTexture.get()); auto unfilledSVG = dynamic_cast(mUnfilledTexture.get()); if(mSize.y() > 0) { - size_t sz = (size_t)round(mSize.y()); + size_t heightPx = (size_t)round(mSize.y()); if(filledSVG) - filledSVG->rasterizeAt(sz, sz); + filledSVG->rasterizeAt(heightPx, heightPx); if(unfilledSVG) - unfilledSVG->rasterizeAt(sz, sz); + unfilledSVG->rasterizeAt(heightPx, heightPx); } updateVertices(); @@ -58,9 +58,9 @@ void RatingComponent::onSizeChanged() void RatingComponent::updateVertices() { - const float numStars = 5.0f; + const float numStars = NUM_RATING_STARS; - const float h = getSize().y(); + const float h = getSize().y(); // is the same as a single star's width const float w = h * mValue * numStars; const float fw = h * numStars; @@ -128,7 +128,7 @@ bool RatingComponent::input(InputConfig* config, Input input) { if(config->isMappedTo("a", input) && input.value != 0) { - mValue += 0.2f; + mValue += 1.f / NUM_RATING_STARS; if(mValue > 1.0f) mValue = 0.0f; diff --git a/src/components/RatingComponent.h b/src/components/RatingComponent.h index 125ee5a83..bd587636b 100644 --- a/src/components/RatingComponent.h +++ b/src/components/RatingComponent.h @@ -3,6 +3,8 @@ #include "../GuiComponent.h" #include "../resources/TextureResource.h" +#define NUM_RATING_STARS 5 + // Used to visually display/edit some sort of "score" - e.g. 5/10, 3/5, etc. // setSize(x, y) works a little differently than you might expect: // * (0, y != 0) - x will be automatically calculated (5*y). @@ -36,7 +38,7 @@ private: Eigen::Vector2f tex; } mVertices[12]; - std::shared_ptr mFilledTexture; // Must be square (width == height)! - std::shared_ptr mUnfilledTexture; // Must be square (width == height)! + std::shared_ptr mFilledTexture; + std::shared_ptr mUnfilledTexture; }; diff --git a/src/components/ScraperSearchComponent.cpp b/src/components/ScraperSearchComponent.cpp index 5f1745ae6..27bf603e5 100644 --- a/src/components/ScraperSearchComponent.cpp +++ b/src/components/ScraperSearchComponent.cpp @@ -246,7 +246,7 @@ void ScraperSearchComponent::onSearchDone(const std::vector void ScraperSearchComponent::onSearchError(const std::string& error) { - mWindow->pushGui(new GuiMsgBox(mWindow, error, + mWindow->pushGui(new GuiMsgBox(mWindow, strToUpper(error), "RETRY", std::bind(&ScraperSearchComponent::search, this, mLastSearch), "SKIP", mSkipCallback, "CANCEL", mCancelCallback));