make the next/prev work

This commit is contained in:
Cary Sandvig 2001-02-13 00:13:51 +00:00
parent 35ae45755e
commit d2767605e3
3 changed files with 55 additions and 2 deletions

View File

@ -4,3 +4,11 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE GuiChooser::GuiChooser(void) {} INLINE GuiChooser::GuiChooser(void) {}
INLINE void GuiChooser::set_loop(bool b) {
_loop = b;
}
INLINE bool GuiChooser::get_loop(void) const {
return _loop;
}

View File

@ -26,8 +26,8 @@ void GuiChooser::recompute_frame(void) {
} }
GuiChooser::GuiChooser(const string& name, GuiButton* prev, GuiButton* next) GuiChooser::GuiChooser(const string& name, GuiButton* prev, GuiButton* next)
: GuiBehavior(name), _curr(-1), _prev_button(prev), _next_button(next), : GuiBehavior(name), _curr(-1), _loop(false), _prev_button(prev),
_prev_functor((GuiChooser::ChooseFunctor*)0L), _next_button(next), _prev_functor((GuiChooser::ChooseFunctor*)0L),
_next_functor((GuiChooser::ChooseFunctor*)0L) { _next_functor((GuiChooser::ChooseFunctor*)0L) {
} }
@ -38,14 +38,55 @@ GuiChooser::~GuiChooser(void) {
void GuiChooser::move_prev(void) { void GuiChooser::move_prev(void) {
if (_curr == -1) if (_curr == -1)
return; return;
int tmp = _curr - 1;
if (_loop) {
if (tmp < 0)
tmp += _items.size();
}
if (_mgr != (GuiManager*)0L) {
_items[_curr]->unmanage();
_items[tmp]->manage(_mgr, *_eh);
if (tmp == 0)
_prev_button->inactive();
else
_prev_button->up();
int foo = _items.size() - 1;
if (tmp == foo)
_next_button->inactive();
else
_next_button->up();
}
_curr = tmp;
} }
void GuiChooser::move_next(void) { void GuiChooser::move_next(void) {
if (_curr == -1) if (_curr == -1)
return; return;
int tmp = _curr + 1;
if (_loop) {
int foo = _items.size();
if (tmp == foo)
tmp = 0;
}
if (_mgr != (GuiManager*)0L) {
_items[_curr]->unmanage();
_items[tmp]->manage(_mgr, *_eh);
if (tmp == 0)
_prev_button->inactive();
else
_prev_button->up();
if (tmp == (_items.size() - 1))
_next_button->inactive();
else
_next_button->up();
}
_curr = tmp;
} }
void GuiChooser::add_item(GuiItem* item) { void GuiChooser::add_item(GuiItem* item) {
_items.push_back(item);
if (_curr == -1)
_curr = 0;
} }
int GuiChooser::freeze(void) { int GuiChooser::freeze(void) {

View File

@ -32,6 +32,7 @@ private:
ItemVector _items; ItemVector _items;
int _curr; int _curr;
bool _loop;
PT(GuiButton) _prev_button; PT(GuiButton) _prev_button;
PT(GuiButton) _next_button; PT(GuiButton) _next_button;
@ -62,6 +63,9 @@ PUBLISHED:
virtual void reset_behavior(void); virtual void reset_behavior(void);
virtual void output(ostream&) const; virtual void output(ostream&) const;
INLINE void set_loop(bool);
INLINE bool get_loop(void) const;
public: public:
// type interface // type interface
static TypeHandle get_class_type(void) { static TypeHandle get_class_type(void) {