diff --git a/src/guiengine/skin.cpp b/src/guiengine/skin.cpp index c16b51bf2..7a8cc69c8 100644 --- a/src/guiengine/skin.cpp +++ b/src/guiengine/skin.cpp @@ -815,9 +815,6 @@ void Skin::drawRatingBar(Widget *w, const core::recti &rect, { RatingBarWidget *ratingBar = (RatingBarWidget*)w; - core::position2d mouse_position = irr_driver->getDevice()->getCursorControl()->getPosition(); - ratingBar->setStepValuesByMouse(mouse_position); - const ITexture *texture = SkinConfig::m_render_params["rating::neutral"].getImage(); const int texture_w = texture->getSize().Width / 4; const int texture_h = texture->getSize().Height; @@ -839,6 +836,10 @@ void Skin::drawRatingBar(Widget *w, const core::recti &rect, const int x_from = rect.UpperLeftCorner.X + (rect.getWidth() - star_w) / 2; const int y_from = rect.UpperLeftCorner.Y + (rect.getHeight() - star_h) / 2; + core::recti stars_rect(x_from, y_from, x_from + (star_number * star_w), y_from + star_h); + + ratingBar->setStepValuesByMouse(irr_driver->getDevice()->getCursorControl()->getPosition(), stars_rect); + for (int i = 0; i < star_number; i++) { core::recti star_rect = rect; diff --git a/src/guiengine/widgets/rating_bar_widget.cpp b/src/guiengine/widgets/rating_bar_widget.cpp index cceecaeac..061ae5bf2 100644 --- a/src/guiengine/widgets/rating_bar_widget.cpp +++ b/src/guiengine/widgets/rating_bar_widget.cpp @@ -99,14 +99,12 @@ void RatingBarWidget::setRating(float rating) // ----------------------------------------------------------------------------- -void RatingBarWidget::setStepValuesByMouse(const core::position2d & mouse_position) +void RatingBarWidget::setStepValuesByMouse(const core::position2d & mouse_position, const core::recti & stars_rect) { - if(m_element->getAbsolutePosition().isPointInside(mouse_position)) + if(stars_rect.isPointInside(mouse_position)) { - - float value = (float)(mouse_position.X - m_element->getAbsolutePosition().UpperLeftCorner.X); - setStepValues( (float)( value / (float)m_w * (float)m_stars) ); - + float value = (float)(mouse_position.X - stars_rect.UpperLeftCorner.X); + setStepValues( (float)( value / (float)stars_rect.getWidth() * (float)m_stars) ); } } diff --git a/src/guiengine/widgets/rating_bar_widget.hpp b/src/guiengine/widgets/rating_bar_widget.hpp index f92441672..f4ebdd144 100644 --- a/src/guiengine/widgets/rating_bar_widget.hpp +++ b/src/guiengine/widgets/rating_bar_widget.hpp @@ -68,7 +68,7 @@ namespace GUIEngine int getStepsOfStar(int index); - void setStepValuesByMouse(const core::position2d & mouse_position); + void setStepValuesByMouse(const core::position2d & mouse_position, const core::recti & stars_rect); }; }