Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Scroller Class Reference

#include <scroller.h>

Inheritance diagram for Scroller:
GroupControl Control EventResponder

Public Member Functions

void setRangeValues (int max, int visible, int min=0)
 
int scrollPosition (void)
 
void setScrollPosition (int pos)
 
void setThumbColor (const GFXColor &c, const GFXColor &outline)
 
void setButtonColor (const GFXColor &c)
 
virtual void draw (void)
 
virtual void setRect (const Rect &r)
 
virtual void setColor (const GFXColor &c)
 
virtual void setTextColor (const GFXColor &c)
 
virtual bool processCommand (const EventCommandId &command, Control *control)
 
 Scroller (void)
 
virtual ~Scroller (void)
 
- Public Member Functions inherited from GroupControl
virtual bool hasGroupChildren (void)
 
void addChild (Control *child)
 
bool deleteControl (Control *c)
 
ControlremoveControlFromGroup (Control *c)
 
ControlfindControlById (const std::string &id)
 
int childCount (void)
 
ControlchildAt (int index)
 
virtual bool processMouseDown (const InputEvent &event)
 
virtual bool processMouseUp (const InputEvent &event)
 
virtual bool processMouseMove (const InputEvent &event)
 
virtual bool processMouseDrag (const InputEvent &event)
 
 GroupControl (void)
 
virtual ~GroupControl (void)
 
- Public Member Functions inherited from Control
virtual Rect rect (void)
 
virtual bool hitTest (const Point &p)
 
virtual bool hidden (void)
 
virtual void setHidden (bool h=true)
 
virtual const std::string & id (void)
 
virtual void setId (const std::string &newId)
 
virtual GFXColor color (void)
 
virtual GFXColor outlineColor (void)
 
virtual void setOutlineColor (const GFXColor &c)
 
virtual GFXColor textColor (void)
 
virtual Font font (void)
 
virtual void setFont (const Font &f)
 
 Control (void)
 
virtual ~Control (void)
 
- Public Member Functions inherited from EventResponder
virtual bool processKeyDown (const InputEvent &event)
 
virtual bool processKeyUp (const InputEvent &event)
 
virtual void processUnfocus (const InputEvent &event)
 
virtual void sendCommand (const EventCommandId &command, Control *control)
 
virtual void setCommandTarget (EventResponder *responder)
 
virtual void setModal (bool modal)
 
 EventResponder (void)
 
virtual ~EventResponder (void)
 

Protected Member Functions

void calcLayout (void)
 
void createControls (void)
 

Protected Attributes

int m_minValue
 
int m_maxValue
 
int m_visible
 
int m_scrollPosition
 
GFXColor m_thumbColor
 
GFXColor m_thumbOutlineColor
 
bool m_needLayout
 
- Protected Attributes inherited from GroupControl
std::vector< Control * > m_controls
 
- Protected Attributes inherited from Control
Rect m_rect
 
std::string m_id
 
GFXColor m_color
 
GFXColor m_outlineColor
 
GFXColor m_textColor
 
Font m_font
 
bool m_hidden
 
- Protected Attributes inherited from EventResponder
bool m_modal
 
EventResponderm_commandTarget
 

Detailed Description

Definition at line 36 of file scroller.h.

Constructor & Destructor Documentation

Scroller::Scroller ( void  )

Definition at line 294 of file scroller.cpp.

References createControls().

294  :
295  m_minValue( 0 )
296  , m_maxValue( 10 )
297  , m_visible( 1 )
301  , m_needLayout( true )
302 {
303  createControls();
304 }
virtual Scroller::~Scroller ( void  )
inlinevirtual

Definition at line 76 of file scroller.h.

76 {}

Member Function Documentation

void Scroller::calcLayout ( void  )
protected

Definition at line 191 of file scroller.cpp.

References CHILD_CONTROL_COUNT, GroupControl::childAt(), GroupControl::childCount(), Rect::copyAndInset(), ScrollerButton::DOWN_ARROW, DOWN_BUTTON_INDEX, Size::height, ScrollerButton::LEFT_ARROW, Control::m_rect, Rect::origin, Control::rect(), Rect::right(), ScrollerButton::RIGHT_ARROW, ScrollerButton::setArrowType(), NewButton::setCommand(), Control::setRect(), Rect::size, SLIDER_INDEX, Rect::top(), ScrollerButton::UP_ARROW, UP_BUTTON_INDEX, Size::width, Point::x, and Point::y.

Referenced by draw().

192 {
193  assert( childCount() == CHILD_CONTROL_COUNT );
194 
195  //Make the buttons slightly smaller than the scroller.
196  static const Size BUTTON_INSET = Size( .005, .005 );
197 
198  //Get pointers to the buttons.
199  ScrollerButton *downButton = static_cast< ScrollerButton* > ( childAt( DOWN_BUTTON_INDEX ) );
200  ScrollerButton *upButton = static_cast< ScrollerButton* > ( childAt( UP_BUTTON_INDEX ) );
201  //Make the buttons square, and at the bottom/right of the scroller.
202  if (m_rect.size.height >= m_rect.size.width) {
203  //This is a vertical scroller.
204  Rect rect = m_rect;
205  rect.size.height = rect.size.width;
206  downButton->setRect( rect.copyAndInset( BUTTON_INSET ) );
207  downButton->setCommand( "LineDown" );
209 
210  rect.origin.y += rect.size.height;
211  upButton->setRect( rect.copyAndInset( BUTTON_INSET ) );
212  upButton->setCommand( "LineUp" );
214 
215  Rect thumbRect = m_rect;
216  thumbRect.origin.y = rect.top();
217  thumbRect.size.height -= thumbRect.origin.y-m_rect.origin.y;
218  childAt( SLIDER_INDEX )->setRect( thumbRect );
219  } else {
220  //This is a horizontal scroller.
221  //Need to flip the button commands -- "line up" does lower values.
222  Rect rect = m_rect;
223  rect.size.width = rect.size.height;
224  downButton->setRect( rect.copyAndInset( BUTTON_INSET ) );
225  downButton->setCommand( "LineUp" );
227 
228  rect.origin.x += rect.size.width;
229  upButton->setRect( rect.copyAndInset( BUTTON_INSET ) );
230  upButton->setCommand( "LineDown" );
232 
233  Rect thumbRect = m_rect;
234  thumbRect.origin.x = rect.right();
235  thumbRect.size.width -= thumbRect.origin.x-m_rect.origin.x;
236  childAt( SLIDER_INDEX )->setRect( thumbRect );
237  }
238 }
void Scroller::createControls ( void  )
protected

Definition at line 241 of file scroller.cpp.

References GroupControl::addChild(), Control::color(), GUI_CLEAR(), Slider::setColor(), Control::setColor(), NewButton::setCommand(), EventResponder::setCommandTarget(), Control::setTextColor(), Slider::setThumbColorBasedOnColor(), Control::textColor(), and up.

Referenced by Scroller().

242 {
243  //"Scroll Down" button.
244  NewButton *down = new ScrollerButton;
245  down->setCommand( "LineDown" );
246  down->setColor( color() );
247  down->setTextColor( textColor() ); //Arrow color.
248  down->setCommandTarget( this );
249  addChild( down );
250 
251  //"Scroll Up" button.
252  NewButton *up = new ScrollerButton;
253  up->setCommand( "LineUp" );
254  up->setColor( color() );
255  up->setTextColor( textColor() ); //Arrow color.
256  up->setCommandTarget( this );
257  addChild( up );
258 
259  //Slider control.
260  Slider *slider = new Slider;
261  slider->setColor( GUI_CLEAR );
262  slider->setThumbColorBasedOnColor( color() );
263  slider->setCommandTarget( this );
264  addChild( slider );
265 }
void Scroller::draw ( void  )
virtual

Reimplemented from GroupControl.

Definition at line 268 of file scroller.cpp.

References calcLayout(), GroupControl::draw(), Control::drawBackground(), and m_needLayout.

269 {
270  drawBackground();
271  if (m_needLayout)
272  calcLayout();
274 }
bool Scroller::processCommand ( const EventCommandId command,
Control control 
)
virtual

Reimplemented from EventResponder.

Definition at line 277 of file scroller.cpp.

References GroupControl::childAt(), Slider::position(), EventResponder::processCommand(), scrollPosition(), setScrollPosition(), and SLIDER_INDEX.

278 {
279  if (command == "LineUp") {
281  return true;
282  } else if (command == "LineDown") {
284  return true;
285  } else if (command == "Slider::PositionChanged") {
286  Slider *slider = static_cast< Slider* > ( childAt( SLIDER_INDEX ) );
287  setScrollPosition( slider->position() );
288  return true;
289  }
290  return GroupControl::processCommand( command, control );
291 }
int Scroller::scrollPosition ( void  )
inline
void Scroller::setColor ( const GFXColor c)
virtual

Reimplemented from Control.

Definition at line 87 of file scroller.cpp.

References CHILD_CONTROL_COUNT, GroupControl::childAt(), GroupControl::childCount(), DOWN_BUTTON_INDEX, isClear(), m_thumbColor, Control::setColor(), Slider::setThumbColorBasedOnColor(), SLIDER_INDEX, and UP_BUTTON_INDEX.

Referenced by NavComputer::constructControls(), BaseComputer::constructControls(), and ListQuestionDialog::CreateControlsForListWindow().

88 {
89  assert( childCount() == CHILD_CONTROL_COUNT );
92  if ( isClear( m_thumbColor ) ) {
93  //If we don't have an explicit thumb color, calculate it.
94  Slider *slider = static_cast< Slider* > ( childAt( SLIDER_INDEX ) );
95  slider->setThumbColorBasedOnColor( c );
96  }
98 }
void Scroller::setRangeValues ( int  max,
int  visible,
int  min = 0 
)

Definition at line 60 of file scroller.cpp.

References GroupControl::childAt(), guiMax, m_maxValue, m_minValue, m_needLayout, m_visible, min(), Slider::setMaxMin(), Slider::setPageSize(), Slider::setThumbLength(), and SLIDER_INDEX.

Referenced by StaticDisplay::draw(), and Picker::recalcDisplay().

61 {
62  const int newMax = guiMax( min, max-visible+1 );
63  if (newMax != m_maxValue || min != m_minValue || visible != m_visible) {
64  m_maxValue = newMax;
65  m_minValue = min;
66  m_visible = visible;
67  m_needLayout = true;
68 
69  Slider *slider = static_cast< Slider* > ( childAt( SLIDER_INDEX ) );
70  slider->setMaxMin( newMax, min );
71  const float thumbLength = (max > min) ? (float) visible/(max-min+1) : -1.;
72  //Note that impossible thumb lengths turn off the thumb.
73  slider->setThumbLength( thumbLength );
74  slider->setPageSize( guiMax( 1, visible-1 ) );
75  }
76 }
void Scroller::setRect ( const Rect r)
virtual

Reimplemented from Control.

Definition at line 79 of file scroller.cpp.

References m_needLayout, Control::m_rect, and Control::setRect().

Referenced by NavComputer::constructControls(), BaseComputer::constructControls(), and ListQuestionDialog::CreateControlsForListWindow().

80 {
81  if (m_rect != r)
82  m_needLayout = true;
84 }
void Scroller::setScrollPosition ( int  pos)

Definition at line 42 of file scroller.cpp.

References GroupControl::childAt(), m_maxValue, m_minValue, m_scrollPosition, EventResponder::sendCommand(), Slider::setPosition(), and SLIDER_INDEX.

Referenced by StaticDisplay::draw(), processCommand(), StaticDisplay::processMouseDown(), Picker::processMouseDown(), Picker::recalcDisplay(), and Picker::scrollToCell().

43 {
44  int newScrollPosition = pos;
45  if (pos > m_maxValue)
46  newScrollPosition = m_maxValue;
47  else if (pos < m_minValue)
48  newScrollPosition = m_minValue;
49  if (m_scrollPosition != newScrollPosition) {
50  m_scrollPosition = newScrollPosition;
51 
52  Slider *slider = static_cast< Slider* > ( childAt( SLIDER_INDEX ) );
53  slider->setPosition( m_scrollPosition );
54 
55  sendCommand( "Scroller::PositionChanged", this );
56  }
57 }
void Scroller::setThumbColor ( const GFXColor c,
const GFXColor outline 
)

Member Data Documentation

int Scroller::m_maxValue
protected

Definition at line 90 of file scroller.h.

Referenced by setRangeValues(), and setScrollPosition().

int Scroller::m_minValue
protected

Definition at line 89 of file scroller.h.

Referenced by setRangeValues(), and setScrollPosition().

bool Scroller::m_needLayout
protected

Definition at line 96 of file scroller.h.

Referenced by draw(), setRangeValues(), and setRect().

int Scroller::m_scrollPosition
protected

Definition at line 92 of file scroller.h.

Referenced by scrollPosition(), and setScrollPosition().

GFXColor Scroller::m_thumbColor
protected

Definition at line 93 of file scroller.h.

Referenced by setColor().

GFXColor Scroller::m_thumbOutlineColor
protected

Definition at line 94 of file scroller.h.

int Scroller::m_visible
protected

Definition at line 91 of file scroller.h.

Referenced by setRangeValues().


The documentation for this class was generated from the following files: