GG::Spin< T > Class Template Reference

a spin box control. More...

#include <Spin.h>

Inheritance diagram for GG::Spin< T >:

GG::Control GG::Wnd List of all members.

Signal Types

typedef boost::signal< void(T)> ValueChangedSignalType

Slot Types

typedef ValueChangedSignalType::slot_type ValueChangedSlotType

Accessors

ValueChangedSignalType ValueChangedSignal
virtual Pt MinUsableSize () const
Value () const
StepSize () const
MinValue () const
MaxValue () const
bool Editable () const
int ButtonWidth () const
Clr TextColor () const
Clr InteriorColor () const
Clr HiliteColor () const
Clr SelectedTextColor () const

Structors

 Spin (int x, int y, int w, T value, T step, T min, T max, bool edits, const boost::shared_ptr< Font > &font, Clr color, Clr text_color=CLR_BLACK, Clr interior=CLR_ZERO, Flags< WndFlag > flags=CLICKABLE)
 ~Spin ()

Mutators

virtual void Render ()
virtual void KeyPress (Key key, Flags< ModKey > mod_keys)
virtual void MouseWheel (const Pt &pt, int move, Flags< ModKey > mod_keys)
virtual void SizeMove (const Pt &ul, const Pt &lr)
virtual void Disable (bool b=true)
virtual void SetColor (Clr c)
void Incr ()
void Decr ()
void SetValue (T value)
void SetStepSize (T step)
void SetMinValue (T value)
void SetMaxValue (T value)
void AllowEdits (bool b=true)
void SetButtonWidth (int width)
void SetTextColor (Clr c)
void SetInteriorColor (Clr c)
void SetHiliteColor (Clr c)
void SetSelectedTextColor (Clr c)
virtual void DefineAttributes (WndEditor *editor)

Structors

 Spin ()

Accessors

ButtonUpButton () const
ButtonDownButton () const
EditGetEdit () const

Mutators

virtual bool EventFilter (Wnd *w, const WndEvent &event)

Protected Types

enum  {
  BORDER_THICK = 2,
  PIXEL_MARGIN = 5
}
typedef T ValueType

Detailed Description

template<class T>
class GG::Spin< T >

a spin box control.

This control class is templated so that arbitrary data types can be used with Spin. All the built-in numeric types are supported by the code here. If you want to use some other type, such as an enum type, you need to define operator+(), operator-(), and template specializations of spin_details::mod() and spin_details::div(). Spin controls are optionally directly editable by the user. When the user inputs a value that is not valid for the Spin's parameters (not on a step boundary, or outside the allowed range), the input gets locked to the nearest valid value. The user is responsible for selecting a min, max, and step size that make sense. For instance, min = 0, max = 4, step = 3 may produce odd results if the user increments all the way to the top, then back down, to produce the sequence 0, 3, 4, 1, 0. To avoid this, choose the values so that (max - min) mod step == 0. It is possible to provide custom buttons for a Spin to use; if you choose to add custom buttons, make sure they look alright at arbitrary sizes, and note that Spin buttons are always H wide by H/2 tall, where H is the height of the Spin, less the thickness of the Spin's border. Note that if you want Spin controls to be automatically serialized in your application, you need to export each instantiation of Spin<> yourself (e.g. Spin<int> or Spin<double>). See the boost serialization documentation for details.

Definition at line 104 of file Spin.h.


Member Typedef Documentation

template<class T>
typedef boost::signal<void (T)> GG::Spin< T >::ValueChangedSignalType

emitted whenever the value of the Spin has changed

Definition at line 108 of file Spin.h.

template<class T>
typedef ValueChangedSignalType::slot_type GG::Spin< T >::ValueChangedSlotType

type of functor(s) invoked on a ValueChangedSignalType

Definition at line 112 of file Spin.h.


Member Enumeration Documentation

template<class T>
anonymous enum [protected]

Enumerator:
BORDER_THICK 
PIXEL_MARGIN 

Definition at line 178 of file Spin.h.


Constructor & Destructor Documentation

template<class T>
GG::Spin< T >::Spin ( int  x,
int  y,
int  w,
value,
step,
min,
max,
bool  edits,
const boost::shared_ptr< Font > &  font,
Clr  color,
Clr  text_color = CLR_BLACK,
Clr  interior = CLR_ZERO,
Flags< WndFlag >  flags = CLICKABLE 
) [inline]

ctor that does not required height.

Height is determined from the font and point size used.

Definition at line 234 of file Spin.h.

template<class T>
GG::Spin< T >::Spin (  )  [inline, protected]

default ctor

Definition at line 220 of file Spin.h.


Member Function Documentation

template<class T>
Pt GG::Spin< T >::MinUsableSize (  )  const [inline, virtual]

returns the size of the minimum bounding box that can enclose the Wnd and still show all of its elements, plus enough room for interaction with those elements (if applicable).

For example, a TextControl's MinUsableSize() is just the area of its text, and a Scroll's RenderableMinSize() is the combined sizes of its up-button, down-button, and tab (plus a bit of room in which to drag the tab).

Reimplemented from GG::Wnd.

Definition at line 255 of file Spin.h.

References GG::Spin< T >::BORDER_THICK, GG::TextControl::MinUsableSize(), GG::Edit::MinUsableSize(), GG::Pt::x, and GG::Pt::y.

template<class T>
T GG::Spin< T >::Value (  )  const [inline]

returns the current value of the control's text

Definition at line 265 of file Spin.h.

template<class T>
T GG::Spin< T >::StepSize (  )  const [inline]

returns the step size of the control

Definition at line 271 of file Spin.h.

template<class T>
T GG::Spin< T >::MinValue (  )  const [inline]

returns the minimum value of the control

Definition at line 277 of file Spin.h.

template<class T>
T GG::Spin< T >::MaxValue (  )  const [inline]

returns the maximum value of the control

Definition at line 283 of file Spin.h.

template<class T>
bool GG::Spin< T >::Editable (  )  const [inline]

returns true if the spinbox can have its value typed in directly

Definition at line 289 of file Spin.h.

template<class T>
int GG::Spin< T >::ButtonWidth (  )  const [inline]

returns the width used for the up and down buttons

Definition at line 295 of file Spin.h.

template<class T>
Clr GG::Spin< T >::TextColor (  )  const [inline]

returns the text color

Definition at line 301 of file Spin.h.

References GG::TextControl::TextColor().

template<class T>
Clr GG::Spin< T >::InteriorColor (  )  const [inline]

returns the the interior color of the control

Definition at line 307 of file Spin.h.

References GG::Edit::InteriorColor().

Referenced by GG::Spin< T >::Render().

template<class T>
Clr GG::Spin< T >::HiliteColor (  )  const [inline]

returns the color used to render hiliting around selected text

Definition at line 313 of file Spin.h.

References GG::Edit::HiliteColor().

template<class T>
Clr GG::Spin< T >::SelectedTextColor (  )  const [inline]

returns the color used to render selected text

Definition at line 319 of file Spin.h.

References GG::Edit::SelectedTextColor().

template<class T>
void GG::Spin< T >::Render (  )  [inline, virtual]

draws this Wnd.

Note that Wnds being dragged for a drag-and-drop operation are rendered twice -- once in-place as normal, once in the location of the drag operation, attached to the cursor. Such Wnds may wish to render themselves differently in those two cases. To determine which render is being performed, they can call GUI::GetGUI()->RenderingDragDropWnds().

Implements GG::Control.

Definition at line 325 of file Spin.h.

References GG::BeveledRectangle(), GG::Spin< T >::BORDER_THICK, GG::Control::Color(), GG::Control::Disabled(), GG::DisabledColor(), GG::Spin< T >::InteriorColor(), GG::Wnd::LowerRight(), GG::Wnd::UpperLeft(), GG::Pt::x, and GG::Pt::y.

template<class T>
void GG::Spin< T >::KeyPress ( Key  key,
Flags< ModKey >  mod_keys 
) [inline, virtual]

respond to down-keystrokes (focus window only).

A window may receive KeyPress() messages passed up to it from its children. For instance, Control-derived classes pass KeyPress() messages to their Parent() windows by default.

Note:
Though mouse clicks consist of a press and a release, all Control classes by default respond immediately to KeyPress(), not KeyRelease(); in fact, by default no Wnd class does anything at all on a KeyRelease event.

Reimplemented from GG::Control.

Definition at line 334 of file Spin.h.

References GG::Spin< T >::Decr(), GG::GGK_DOWN, GG::GGK_END, GG::GGK_HOME, GG::GGK_KP_MINUS, GG::GGK_KP_PLUS, GG::GGK_MINUS, GG::GGK_PAGEDOWN, GG::GGK_PAGEUP, GG::GGK_PLUS, GG::GGK_UP, GG::Spin< T >::Incr(), and GG::Spin< T >::SetValue().

template<class T>
void GG::Spin< T >::MouseWheel ( const Pt pt,
int  move,
Flags< ModKey >  mod_keys 
) [inline, virtual]

respond to movement of the mouse wheel (move > 0 indicates the wheel is rolled up, < 0 indicates down)

Reimplemented from GG::Control.

Definition at line 361 of file Spin.h.

References GG::Spin< T >::Decr(), and GG::Spin< T >::Incr().

template<class T>
void GG::Spin< T >::SizeMove ( const Pt ul,
const Pt lr 
) [inline, virtual]

resizes and/or moves window to new upper-left and lower right boundaries

Reimplemented from GG::Wnd.

Definition at line 372 of file Spin.h.

References GG::Spin< T >::BORDER_THICK, GG::Wnd::Height(), GG::TextControl::SizeMove(), GG::Wnd::SizeMove(), and GG::Wnd::Width().

Referenced by GG::Spin< T >::SetButtonWidth().

template<class T>
void GG::Spin< T >::Disable ( bool  b = true  )  [inline, virtual]

disables/enables the control; disabled controls appear greyed

Reimplemented from GG::Control.

Definition at line 385 of file Spin.h.

References GG::Control::Disable().

template<class T>
void GG::Spin< T >::SetColor ( Clr  c  )  [inline, virtual]

sets the color of the control

Reimplemented from GG::Control.

Definition at line 394 of file Spin.h.

References GG::Button::SetColor(), and GG::Control::SetColor().

template<class T>
void GG::Spin< T >::Incr (  )  [inline]

increments the value of the control's text by StepSize(), up to at most MaxValue()

Definition at line 402 of file Spin.h.

References GG::Spin< T >::SetValue().

Referenced by GG::Spin< T >::KeyPress(), and GG::Spin< T >::MouseWheel().

template<class T>
void GG::Spin< T >::Decr (  )  [inline]

decrements the value of the control's text by StepSize(), down to at least MinValue()

Definition at line 408 of file Spin.h.

References GG::Spin< T >::SetValue().

Referenced by GG::Spin< T >::KeyPress(), and GG::Spin< T >::MouseWheel().

template<class T>
void GG::Spin< T >::SetValue ( value  )  [inline]

sets the value of the control's text to value, locked to the range [MinValue(), MaxValue()]

Definition at line 414 of file Spin.h.

References GG::Spin< T >::ValueChangedSignal.

Referenced by GG::Spin< T >::Decr(), GG::Spin< T >::Incr(), GG::Spin< T >::KeyPress(), GG::Spin< T >::SetMaxValue(), GG::Spin< T >::SetMinValue(), and GG::Spin< T >::SetStepSize().

template<class T>
void GG::Spin< T >::SetStepSize ( step  )  [inline]

sets the step size of the control to step

Definition at line 438 of file Spin.h.

References GG::Spin< T >::SetValue().

template<class T>
void GG::Spin< T >::SetMinValue ( value  )  [inline]

sets the minimum value of the control to value

Definition at line 445 of file Spin.h.

References GG::Spin< T >::SetValue().

template<class T>
void GG::Spin< T >::SetMaxValue ( value  )  [inline]

sets the maximum value of the control to value

Definition at line 453 of file Spin.h.

References GG::Spin< T >::SetValue().

template<class T>
void GG::Spin< T >::AllowEdits ( bool  b = true  ) 

turns on or off the mode that allows the user to edit the value in the spinbox directly.

template<class T>
void GG::Spin< T >::SetButtonWidth ( int  width  )  [inline]

sets the width used for the up and down buttons

Definition at line 467 of file Spin.h.

References GG::Spin< T >::BORDER_THICK, GG::Wnd::RelativeLowerRight(), GG::Wnd::RelativeUpperLeft(), GG::Spin< T >::SizeMove(), and GG::Wnd::Width().

template<class T>
void GG::Spin< T >::SetTextColor ( Clr  c  )  [inline]

sets the text color

Definition at line 461 of file Spin.h.

References GG::TextControl::SetTextColor().

template<class T>
void GG::Spin< T >::SetInteriorColor ( Clr  c  )  [inline]

sets the interior color of the control

Definition at line 478 of file Spin.h.

References GG::Edit::SetInteriorColor().

template<class T>
void GG::Spin< T >::SetHiliteColor ( Clr  c  )  [inline]

sets the color used to render hiliting around selected text

Definition at line 484 of file Spin.h.

References GG::Edit::SetHiliteColor().

template<class T>
void GG::Spin< T >::SetSelectedTextColor ( Clr  c  )  [inline]

sets the color used to render selected text

Definition at line 490 of file Spin.h.

References GG::Edit::SetSelectedTextColor().

template<class T>
void GG::Spin< T >::DefineAttributes ( WndEditor *  editor  )  [inline, virtual]

provides the attributes of this object that are appropriate for a user to edit in a WndEditor; see WndEditor for details.

Reimplemented from GG::Control.

Definition at line 496 of file Spin.h.

References GG::Control::DefineAttributes().

template<class T>
Button * GG::Spin< T >::UpButton (  )  const [inline, protected]

returns a pointer to the Button control used as this control's up button

Definition at line 520 of file Spin.h.

template<class T>
Button * GG::Spin< T >::DownButton (  )  const [inline, protected]

returns a pointer to the Button control used as this control's down button

Definition at line 526 of file Spin.h.

template<class T>
Edit * GG::Spin< T >::GetEdit (  )  const [inline, protected]

returns a pointer to the Edit control used to render this control's text and accept keyboard input

Definition at line 532 of file Spin.h.

template<class T>
bool GG::Spin< T >::EventFilter ( Wnd w,
const WndEvent event 
) [inline, protected, virtual]

handles an WndEvent destined for Wnd w, but which this Wnd is allowed to handle first.

Returns true if this filter processed the message.

Reimplemented from GG::Wnd.

Definition at line 538 of file Spin.h.

References GG::WndEvent::GainingFocus, GG::GUI::GetGUI(), GG::GUI::SetFocusWnd(), and GG::WndEvent::Type().


Member Data Documentation

template<class T>
ValueChangedSignalType GG::Spin< T >::ValueChangedSignal [mutable]

the value changed signal object for this DynamicGraphic

Definition at line 139 of file Spin.h.

Referenced by GG::Spin< T >::SetValue().


The documentation for this class was generated from the following file:
Generated on Wed Mar 26 14:35:42 2008 for GG by  doxygen 1.5.2