#include <spin_button.h>
Inheritance diagram for SpinButton:
Public Member Functions | |
SpinButton (const std::string &label, const Rectanglei &rect, int value=0, int step=1, int min_value=-1, int max_value=-1, const Color &color=white_color, bool shadowed=true) | |
virtual | ~SpinButton () |
void | SetSizePosition (const Rectanglei &rect) |
void | Draw (const Point2i &mousePosition, Surface &surf) const |
Widget * | Clic (const Point2i &mousePosition, uint button) |
int | GetValue () const |
void | SetValue (int value) |
Private Attributes | |
bool | shadowed |
Text * | txt_label |
Text * | txt_value |
int | m_value |
int | m_min_value |
int | m_max_value |
int | m_step |
Button * | m_plus |
Button * | m_minus |
Definition at line 31 of file spin_button.h.
SpinButton::SpinButton | ( | const std::string & | label, | |
const Rectanglei & | rect, | |||
int | value = 0 , |
|||
int | step = 1 , |
|||
int | min_value = -1 , |
|||
int | max_value = -1 , |
|||
const Color & | color = white_color , |
|||
bool | shadowed = true | |||
) |
Definition at line 28 of file spin_button.cpp.
00031 { 00032 position = rect.GetPosition(); 00033 size = rect.GetSize(); 00034 size.y = (*Font::GetInstance(Font::FONT_SMALL)).GetHeight(); 00035 shadowed = _shadowed; 00036 00037 Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false); 00038 00039 txt_label = new Text(label, color, Font::GetInstance(Font::FONT_SMALL), shadowed); 00040 00041 if ( min_value != -1 && min_value <= value) 00042 m_min_value = min_value; 00043 else m_min_value = value/2; 00044 00045 if ( max_value != -1 && max_value >= value) 00046 m_max_value = max_value; 00047 else m_max_value = value*2; 00048 00049 txt_value = new Text("", color, Font::GetInstance(Font::FONT_SMALL), shadowed); 00050 SetValue(value); 00051 00052 std::ostringstream max_value_s; 00053 max_value_s << m_max_value ; 00054 uint max_value_w = (*Font::GetInstance(Font::FONT_SMALL)).GetWidth(max_value_s.str()); 00055 00056 uint margin = 5; 00057 00058 m_plus = new Button( Point2i(position.x + size.x - 5, position.y), res, "menu/plus"); 00059 m_minus = new Button( Point2i(position.x + size.x - max_value_w - 5 - 2 * margin, position.y), res, "menu/minus"); 00060 resource_manager.UnLoadXMLProfile( res); 00061 m_step = step; 00062 }
Here is the call graph for this function:
SpinButton::~SpinButton | ( | ) | [virtual] |
Reimplemented from Widget.
Definition at line 97 of file spin_button.cpp.
00098 { 00099 need_redrawing = true; 00100 00101 if( (button == SDL_BUTTON_WHEELDOWN && Contains(mousePosition)) || 00102 (button == SDL_BUTTON_LEFT && m_minus->Contains(mousePosition)) ){ 00103 SetValue(m_value - m_step); 00104 return this; 00105 } else 00106 if( (button == SDL_BUTTON_WHEELUP && Contains(mousePosition)) || 00107 (button == SDL_BUTTON_LEFT && m_plus->Contains(mousePosition)) ){ 00108 SetValue(m_value + m_step); 00109 return this; 00110 } 00111 return NULL; 00112 }
Here is the call graph for this function:
Implements Widget.
Definition at line 86 of file spin_button.cpp.
00087 { 00088 txt_label->DrawTopLeft(position); 00089 00090 m_minus->Draw(mousePosition, surf); 00091 m_plus->Draw(mousePosition, surf); 00092 00093 uint center = (m_plus->GetPositionX() + 5 + m_minus->GetPositionX() )/2; 00094 txt_value->DrawCenterTop(center, position.y); 00095 }
Here is the call graph for this function:
int SpinButton::GetValue | ( | ) | const |
Definition at line 114 of file spin_button.cpp.
00115 { 00116 return m_value; 00117 }
Here is the caller graph for this function:
void SpinButton::SetSizePosition | ( | const Rectanglei & | rect | ) | [virtual] |
Implements Widget.
Definition at line 72 of file spin_button.cpp.
00073 { 00074 StdSetSizePosition(rect); 00075 00076 std::ostringstream max_value_s; 00077 max_value_s << m_max_value ; 00078 uint max_value_w = (*Font::GetInstance(Font::FONT_SMALL)).GetWidth(max_value_s.str()); 00079 00080 uint margin = 5; 00081 00082 m_plus->SetSizePosition( Rectanglei(position.x + size.x - 5, position.y, 5, 10) ); 00083 m_minus->SetSizePosition( Rectanglei(position.x + size.x - max_value_w - 5 - 2 * margin, position.y, 5, 10) ); 00084 }
Here is the call graph for this function:
void SpinButton::SetValue | ( | int | value | ) |
Definition at line 119 of file spin_button.cpp.
00120 { 00121 m_value = BorneLong(value, m_min_value, m_max_value); 00122 00123 std::ostringstream value_s; 00124 value_s << m_value ; 00125 00126 std::string s(value_s.str()); 00127 txt_value->Set(s); 00128 }
Here is the call graph for this function:
Here is the caller graph for this function:
int SpinButton::m_max_value [private] |
Definition at line 39 of file spin_button.h.
int SpinButton::m_min_value [private] |
Definition at line 39 of file spin_button.h.
Button * SpinButton::m_minus [private] |
Definition at line 40 of file spin_button.h.
Button* SpinButton::m_plus [private] |
Definition at line 40 of file spin_button.h.
int SpinButton::m_step [private] |
Definition at line 39 of file spin_button.h.
int SpinButton::m_value [private] |
Definition at line 38 of file spin_button.h.
bool SpinButton::shadowed [private] |
Definition at line 34 of file spin_button.h.
Text* SpinButton::txt_label [private] |
Definition at line 36 of file spin_button.h.
Text * SpinButton::txt_value [private] |
Definition at line 36 of file spin_button.h.