Awesome rating bar widget is awesome

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13408 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-08-02 02:25:58 +00:00
parent ed689232e0
commit 6198c43728
5 changed files with 28 additions and 7 deletions

View File

@ -681,13 +681,14 @@ EventPropagation EventHandler::onGUIEvent(const SEvent& event)
{
Widget* w = GUIEngine::getWidget(id);
if (w == NULL) break;
if (w->m_deactivated)
{
GUIEngine::getCurrentScreen()->onDisabledItemClicked(w->m_properties[PROP_ID].c_str());
return EVENT_BLOCK;
}
w->onClick();
// These events are only triggered by mouse (or so I hope)
// The player that owns the mouser receives "game master" priviledges
return onWidgetActivated(w, PLAYER_ID_GAME_MASTER);

View File

@ -362,4 +362,3 @@ void Widget::moveIrrlichtElement()
irr::core::dimension2di(m_w, m_h) ) );
}
}

View File

@ -650,6 +650,9 @@ namespace GUIEngine
*/
bool ok() const { return (m_magic_number == 0xCAFEC001); }
/** Gets called when the widget is active and got clicked. (Only works for button widgets for now.) */
virtual void onClick() { }
};

View File

@ -33,9 +33,11 @@ using namespace irr;
// -----------------------------------------------------------------------------
RatingBarWidget::RatingBarWidget() : Widget(WTYPE_RATINGBAR)
{
m_rating = 0;
m_rating = 0.0f;
m_hover_rating = 0.0f;
m_stars = 3;
m_steps = 3;
m_hovering = false;
for(int i = 0; i < m_stars; i++)
m_star_values.push_back(0);
}
@ -99,13 +101,25 @@ void RatingBarWidget::setRating(float rating)
// -----------------------------------------------------------------------------
void RatingBarWidget::setStepValuesByMouse(const core::position2d<s32> & mouse_position, const core::recti & stars_rect)
void RatingBarWidget::setStepValuesByMouse(const core::position2di & mouse_position, const core::recti & stars_rect)
{
if(stars_rect.isPointInside(mouse_position))
{
float value = (float)(mouse_position.X - stars_rect.UpperLeftCorner.X);
setStepValues( (float)( value / (float)stars_rect.getWidth() * (float)m_stars) );
m_hovering = true;
m_hover_rating = (float)(mouse_position.X - stars_rect.UpperLeftCorner.X) / (float)stars_rect.getWidth() * (float)m_stars;
setStepValues(m_hover_rating );
}
else if(m_hovering)
{
setStepValues(m_rating);
m_hovering = false;
}
}
void RatingBarWidget::onClick()
{
m_rating = m_hover_rating;
}

View File

@ -37,9 +37,11 @@ namespace GUIEngine
{
private:
float m_rating;
float m_hover_rating;
int m_stars;
int m_steps;
std::vector<int> m_star_values;
bool m_hovering;
void setStepValues(float rating);
@ -68,7 +70,9 @@ namespace GUIEngine
int getStepsOfStar(int index);
void setStepValuesByMouse(const core::position2d<s32> & mouse_position, const core::recti & stars_rect);
void setStepValuesByMouse(const core::position2di & mouse_position, const core::recti & stars_rect);
virtual void onClick();
};
}