SuperTuxKart
rating_bar_widget.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2009-2015 Marianne Gagnon
3 // 2013 Glenn De Jonghe
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 
20 
21 #ifndef HEADER_RATING_BAR_HPP
22 #define HEADER_RATING_BAR_HPP
23 
24 #include <irrString.h>
25 
26 #include "guiengine/widget.hpp"
27 #include "utils/leak_check.hpp"
28 #include "utils/ptr_vector.hpp"
29 #include "utils/cpp2011.hpp"
30 
31 namespace GUIEngine
32 {
37  class RatingBarWidget : public Widget
38  {
39  private:
40  float m_rating;
41  float m_hover_rating;
42  int m_stars;
43  int m_steps;
44  std::vector<int> m_star_values;
45  bool m_hovering;
46  bool m_allow_voting;
47 
48  void setStepValues(float rating);
49 
50  public:
51 
52  LEAK_CHECK()
53 
55  virtual ~RatingBarWidget() {}
56 
57  void add() OVERRIDE;
58 
60  void setRating(float rating);
61 
63  float getRating() {return m_rating; };
64 
66  void setStarNumber(int star_number) { m_stars = star_number; };
67 
69  int getStarNumber() {return m_stars; };
70 
72  void setSteps(int steps) { m_steps = steps; }
73 
74  int getSteps() { return m_steps; }
75 
76  int getStepsOfStar(int index);
77 
78  void setStepValuesByMouse(const core::position2di & mouse_position, const core::recti & stars_rect);
79 
80  virtual EventPropagation rightPressed(const int playerID=0) OVERRIDE;
81  virtual EventPropagation leftPressed (const int playerID=0) OVERRIDE;
82 
84  bool updateRating();
85 
86  void allowVoting() { m_allow_voting = true; }
87  };
88 }
89 
90 #endif
A rating bar widget.
Definition: rating_bar_widget.hpp:38
void setSteps(int steps)
Set steps in each star.
Definition: rating_bar_widget.hpp:72
void setStarNumber(int star_number)
Change the number of stars of the widget.
Definition: rating_bar_widget.hpp:66
int getStepsOfStar(int index)
Get the current step of the star.
Definition: rating_bar_widget.cpp:64
bool updateRating()
True if succeed, false if fail.
Definition: rating_bar_widget.cpp:133
void setRating(float rating)
Change the rating value of the widget.
Definition: rating_bar_widget.cpp:90
virtual EventPropagation leftPressed(const int playerID=0) OVERRIDE
called when left key is pressed and focus is on widget.
Definition: rating_bar_widget.cpp:113
void add() OVERRIDE
Create and add the irrLicht widget(s) associated with this object.
Definition: rating_bar_widget.cpp:49
int getStarNumber()
Get the current number of stars of the widget.
Definition: rating_bar_widget.hpp:69
float getRating()
Get the current value of the widget.
Definition: rating_bar_widget.hpp:63
virtual EventPropagation rightPressed(const int playerID=0) OVERRIDE
called when right key is pressed and focus is on widget.
Definition: rating_bar_widget.cpp:123
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:147
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33