Some styling changes, a little refactoring of RatingComponent.

This commit is contained in:
Aloshi 2014-04-06 19:15:02 -05:00
parent 062a004e4a
commit e5bada7f51
4 changed files with 22 additions and 20 deletions

View file

@ -9,8 +9,8 @@
#include <boost/assign.hpp> #include <boost/assign.hpp>
#define OFFSET_X 6 // move the entire thing right by this amount (px) #define OFFSET_X 12 // move the entire thing right by this amount (px)
#define OFFSET_Y 6 // move the entire thing up 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 ICON_TEXT_SPACING 8 // space between [icon] and [text] (px)
#define ENTRY_SPACING 16 // space between [text] and next [icon] (px) #define ENTRY_SPACING 16 // space between [text] and next [icon] (px)

View file

@ -9,7 +9,7 @@ RatingComponent::RatingComponent(Window* window) : GuiComponent(window)
mFilledTexture = TextureResource::get(":/star_filled.svg", true); mFilledTexture = TextureResource::get(":/star_filled.svg", true);
mUnfilledTexture = TextureResource::get(":/star_unfilled.svg", true); mUnfilledTexture = TextureResource::get(":/star_unfilled.svg", true);
mValue = 0.5f; mValue = 0.5f;
mSize << 64 * 5.0f, 64; mSize << 64 * NUM_RATING_STARS, 64;
updateVertices(); updateVertices();
} }
@ -18,14 +18,14 @@ void RatingComponent::setValue(const std::string& value)
if(value.empty()) if(value.empty())
{ {
mValue = 0.0f; 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(); updateVertices();
} }
@ -37,20 +37,20 @@ std::string RatingComponent::getValue() const
void RatingComponent::onSizeChanged() void RatingComponent::onSizeChanged()
{ {
if(mSize.y() == 0) if(mSize.y() == 0)
mSize[1] = mSize.x() / 5.0f; mSize[1] = mSize.x() / NUM_RATING_STARS;
else if(mSize.x() == 0) else if(mSize.x() == 0)
mSize[0] = mSize.y() * 5.0f; mSize[0] = mSize.y() * NUM_RATING_STARS;
auto filledSVG = dynamic_cast<SVGResource*>(mFilledTexture.get()); auto filledSVG = dynamic_cast<SVGResource*>(mFilledTexture.get());
auto unfilledSVG = dynamic_cast<SVGResource*>(mUnfilledTexture.get()); auto unfilledSVG = dynamic_cast<SVGResource*>(mUnfilledTexture.get());
if(mSize.y() > 0) if(mSize.y() > 0)
{ {
size_t sz = (size_t)round(mSize.y()); size_t heightPx = (size_t)round(mSize.y());
if(filledSVG) if(filledSVG)
filledSVG->rasterizeAt(sz, sz); filledSVG->rasterizeAt(heightPx, heightPx);
if(unfilledSVG) if(unfilledSVG)
unfilledSVG->rasterizeAt(sz, sz); unfilledSVG->rasterizeAt(heightPx, heightPx);
} }
updateVertices(); updateVertices();
@ -58,9 +58,9 @@ void RatingComponent::onSizeChanged()
void RatingComponent::updateVertices() 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 w = h * mValue * numStars;
const float fw = h * 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) if(config->isMappedTo("a", input) && input.value != 0)
{ {
mValue += 0.2f; mValue += 1.f / NUM_RATING_STARS;
if(mValue > 1.0f) if(mValue > 1.0f)
mValue = 0.0f; mValue = 0.0f;

View file

@ -3,6 +3,8 @@
#include "../GuiComponent.h" #include "../GuiComponent.h"
#include "../resources/TextureResource.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. // 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: // setSize(x, y) works a little differently than you might expect:
// * (0, y != 0) - x will be automatically calculated (5*y). // * (0, y != 0) - x will be automatically calculated (5*y).
@ -36,7 +38,7 @@ private:
Eigen::Vector2f tex; Eigen::Vector2f tex;
} mVertices[12]; } mVertices[12];
std::shared_ptr<TextureResource> mFilledTexture; // Must be square (width == height)! std::shared_ptr<TextureResource> mFilledTexture;
std::shared_ptr<TextureResource> mUnfilledTexture; // Must be square (width == height)! std::shared_ptr<TextureResource> mUnfilledTexture;
}; };

View file

@ -246,7 +246,7 @@ void ScraperSearchComponent::onSearchDone(const std::vector<ScraperSearchResult>
void ScraperSearchComponent::onSearchError(const std::string& error) 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), "RETRY", std::bind(&ScraperSearchComponent::search, this, mLastSearch),
"SKIP", mSkipCallback, "SKIP", mSkipCallback,
"CANCEL", mCancelCallback)); "CANCEL", mCancelCallback));