Skip to content

Commit

Permalink
Fix #5134
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingJellyfish committed Jul 25, 2024
1 parent 5527a11 commit b7c98f2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/guiengine/skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,7 @@ void Skin::drawRatingBar(Widget *w, const core::recti &rect,
RatingBarWidget *ratingBar = (RatingBarWidget*)w;

const ITexture *texture = SkinConfig::m_render_params["rating::neutral"].getImage();
int all_steps = ratingBar->getSteps();
const int texture_w = texture->getSize().Width / 4;
const int texture_h = texture->getSize().Height;
const float aspect_ratio = 1.0f;
Expand Down Expand Up @@ -1216,9 +1217,10 @@ void Skin::drawRatingBar(Widget *w, const core::recti &rect,
star_rect.LowerRightCorner.Y = y_from + star_h;

int step = ratingBar->getStepsOfStar(i);
int begin = roundf(2.0f * step / (all_steps - 1)) * texture_w; // Round to the closest actual image

const core::recti source_area(texture_w * step, 0,
texture_w * (step + 1), texture_h);
const core::recti source_area(begin, 0,
begin + texture_w, texture_h);

draw2DImage(texture,
star_rect, source_area,
Expand Down
7 changes: 5 additions & 2 deletions src/guiengine/widgets/rating_bar_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ namespace GUIEngine

RatingBarWidget();
virtual ~RatingBarWidget() {}



void add() OVERRIDE;

Expand All @@ -69,6 +67,11 @@ namespace GUIEngine

/** Get the current number of stars of the widget. */
int getStarNumber() {return m_stars; };

/** Set steps in each star. Interpolate steps-2 values between 0 star and 1 star. */
void setSteps(int steps) { m_steps = steps; }

int getSteps() { return m_steps; }

int getStepsOfStar(int index);

Expand Down
1 change: 1 addition & 0 deletions src/states_screens/dialogs/vote_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ VoteDialog::VoteDialog(const std::string & addon_id)
m_rating_widget = getWidget<RatingBarWidget>("rating");
assert(m_rating_widget != NULL);

m_rating_widget->setSteps(2);
m_rating_widget->setRating(0);
m_rating_widget->allowVoting();
m_options_widget = getWidget<RibbonWidget>("options");
Expand Down

0 comments on commit b7c98f2

Please sign in to comment.