diff --git a/src/GUI/puList.cxx b/src/GUI/puList.cxx index 7f85cc549..63bdd6011 100644 --- a/src/GUI/puList.cxx +++ b/src/GUI/puList.cxx @@ -37,6 +37,7 @@ handle_arrow (puObject * arrow) { puSlider * slider = (puSlider *)arrow->getUserData(); puListBox * list_box = (puListBox *)slider->getUserData(); + puList * list = (puList *)list_box->getUserData(); int step; switch (((puArrowButton *)arrow)->getArrowType()) { @@ -51,14 +52,9 @@ handle_arrow (puObject * arrow) break; } - int total = list_box->getNumItems(); - int visible = list_box->getNumVisible(); - int index = list_box->getTopItem(); - list_box->setTopItem(index + step); - // read back to get setTopItem()'s clamping - index = list_box->getTopItem(); - // negative numbers can't happen, as the buttons aren't visible then - slider->setValue(1.0f - float(index)/(total-visible)); + int index = list->getTopItem(); + list->setTopItem(index + step); + slider->setValue(1.0f - float(list->getTopItem()) / (list->getNumItems() - list->getNumVisible())); } puList::puList (int x, int y, int w, int h, int sl_width) @@ -92,6 +88,25 @@ puList::newList (char ** contents) setSize(_width, _height); } +void +puList::setTopItem( int top ) +{ + int visible = _list_box->getNumVisible(); + int num = _list_box->getNumItems(); + if ( top < 0 || num <= visible ) + top = 0 ; + else if ( num > 0 && top > num-visible ) + top = num-visible; + + _list_box->setTopItem(top); + top = _list_box->getTopItem(); + // read clamped value back in, and only set slider if it doesn't match the new + // index to avoid jumps + int slider_index = int((1.0f - _slider->getFloatValue()) * (getNumItems() - getNumVisible())); + if (slider_index != top) + _slider->setValue(1.0f - float(getTopItem()) / (getNumItems() - getNumVisible())); +} + char * puList::getListStringValue () { @@ -105,38 +120,6 @@ puList::getListIntegerValue() return _list_box->getIntegerValue(); } -void -puList::init (int w, int h, short transparent) -{ - if ( transparent ) - _frame = NULL ; - else - _frame = new puFrame(0, 0, w, h); - - _list_box = new puListBox(0, 0, w-_sw, h); - _list_box->setStyle(-PUSTYLE_SMALL_SHADED); - _list_box->setUserData(this); - _list_box->setCallback(handle_list_entry); - _list_box->setValue(0); - - _slider = new puSlider(w-_sw, _sw, h-2*_sw, true, _sw); - _slider->setValue(1.0f); - _slider->setUserData(_list_box); - _slider->setCallback(handle_slider); - _slider->setCBMode(PUSLIDER_ALWAYS); - - _down_arrow = new puArrowButton(w-_sw, 0, w, _sw, PUARROW_DOWN) ; - _down_arrow->setUserData(_slider); - _down_arrow->setCallback(handle_arrow); - - _up_arrow = new puArrowButton(w-_sw, h-_sw, w, h, PUARROW_UP); - _up_arrow->setUserData(_slider); - _up_arrow->setCallback(handle_arrow); - - setSize(w, h); - close(); -} - void puList::setColourScheme (float r, float g, float b, float a) { @@ -151,19 +134,6 @@ puList::setColour (int which, float r, float g, float b, float a) _list_box->setColour(which, r, g, b, a); } -void -puList::setTopItem( int top ) -{ - int visible = _list_box->getNumVisible(); - int num = _list_box->getNumItems(); - if ( top < 0 || num <= visible ) - top = 0 ; - else if ( num > 0 && top > num-visible ) - top = num-visible; - - _list_box->setTopItem(top) ; -} - void puList::setSize (int w, int h) { @@ -207,4 +177,36 @@ puList::setSize (int w, int h) } } +void +puList::init (int w, int h, short transparent) +{ + if ( transparent ) + _frame = NULL ; + else + _frame = new puFrame(0, 0, w, h); + + _list_box = new puListBox(0, 0, w-_sw, h); + _list_box->setStyle(-PUSTYLE_SMALL_SHADED); + _list_box->setUserData(this); + _list_box->setCallback(handle_list_entry); + _list_box->setValue(0); + + _slider = new puSlider(w-_sw, _sw, h-2*_sw, true, _sw); + _slider->setValue(1.0f); + _slider->setUserData(_list_box); + _slider->setCallback(handle_slider); + _slider->setCBMode(PUSLIDER_ALWAYS); + + _down_arrow = new puArrowButton(w-_sw, 0, w, _sw, PUARROW_DOWN) ; + _down_arrow->setUserData(_slider); + _down_arrow->setCallback(handle_arrow); + + _up_arrow = new puArrowButton(w-_sw, h-_sw, w, h, PUARROW_UP); + _up_arrow->setUserData(_slider); + _up_arrow->setCallback(handle_arrow); + + setSize(w, h); + close(); +} + // end of puList.cxx diff --git a/src/GUI/puList.hxx b/src/GUI/puList.hxx index 991f931dd..2962f5c64 100644 --- a/src/GUI/puList.hxx +++ b/src/GUI/puList.hxx @@ -18,28 +18,6 @@ */ class puList : public puGroup { - public: - puList (int x, int y, int w, int h, int sl_width = 20); - puList (int x, int y, int w, int h, char ** contents, int sl_width = 20); - virtual ~puList (); - - virtual void newList (char ** contents); - // TODO: other string value funcs - virtual char * getListStringValue (); - virtual int getListIntegerValue(); - virtual void setColourScheme (float r, float g, float b, float a); - virtual void setColour (int which, float r, float g, float b, float a); - virtual void setSize (int w, int h); - - int getNumItems ( void ) const ; - int getTopItem ( void ) const { return _list_box->getTopItem(); } - void setTopItem (int index); - - protected: - virtual void init (int w, int h, short transparent); - puListBox * _list_box; - - private: char ** _contents; puFrame * _frame; puSlider * _slider; @@ -48,6 +26,30 @@ class puList : public puGroup int _style; int _sw; // slider width int _width, _height; + + protected: + virtual void init (int w, int h, short transparent); + puListBox * _list_box; + + public: + puList (int x, int y, int w, int h, int sl_width = 20); + puList (int x, int y, int w, int h, char ** contents, int sl_width = 20); + virtual ~puList (); + + virtual void newList (char ** contents); + + // TODO: other string value funcs + virtual char * getListStringValue (); + virtual int getListIntegerValue(); + virtual void setColourScheme (float r, float g, float b, float a); + virtual void setColour (int which, float r, float g, float b, float a); + virtual void setSize (int w, int h); + + int getNumVisible ( void ) const { return _list_box->getNumVisible(); } + int getNumItems ( void ) const { return _list_box->getNumItems(); } + int getTopItem ( void ) const { return _list_box->getTopItem(); } + void setTopItem (int index); + }; #endif // __PULIST_HXX