From d2767605e381f551929accb1e6e2cbd4dc231a03 Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Tue, 13 Feb 2001 00:13:51 +0000 Subject: [PATCH] make the next/prev work --- panda/src/gui/guiChooser.I | 8 +++++++ panda/src/gui/guiChooser.cxx | 45 ++++++++++++++++++++++++++++++++++-- panda/src/gui/guiChooser.h | 4 ++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/panda/src/gui/guiChooser.I b/panda/src/gui/guiChooser.I index 0aec290d0f..5271e3d9a0 100644 --- a/panda/src/gui/guiChooser.I +++ b/panda/src/gui/guiChooser.I @@ -4,3 +4,11 @@ //////////////////////////////////////////////////////////////////// INLINE GuiChooser::GuiChooser(void) {} + +INLINE void GuiChooser::set_loop(bool b) { + _loop = b; +} + +INLINE bool GuiChooser::get_loop(void) const { + return _loop; +} diff --git a/panda/src/gui/guiChooser.cxx b/panda/src/gui/guiChooser.cxx index b81cc3d429..0aaec827e8 100644 --- a/panda/src/gui/guiChooser.cxx +++ b/panda/src/gui/guiChooser.cxx @@ -26,8 +26,8 @@ void GuiChooser::recompute_frame(void) { } GuiChooser::GuiChooser(const string& name, GuiButton* prev, GuiButton* next) - : GuiBehavior(name), _curr(-1), _prev_button(prev), _next_button(next), - _prev_functor((GuiChooser::ChooseFunctor*)0L), + : GuiBehavior(name), _curr(-1), _loop(false), _prev_button(prev), + _next_button(next), _prev_functor((GuiChooser::ChooseFunctor*)0L), _next_functor((GuiChooser::ChooseFunctor*)0L) { } @@ -38,14 +38,55 @@ GuiChooser::~GuiChooser(void) { void GuiChooser::move_prev(void) { if (_curr == -1) 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) { if (_curr == -1) 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) { + _items.push_back(item); + if (_curr == -1) + _curr = 0; } int GuiChooser::freeze(void) { diff --git a/panda/src/gui/guiChooser.h b/panda/src/gui/guiChooser.h index 8189489d7e..553c82f456 100644 --- a/panda/src/gui/guiChooser.h +++ b/panda/src/gui/guiChooser.h @@ -32,6 +32,7 @@ private: ItemVector _items; int _curr; + bool _loop; PT(GuiButton) _prev_button; PT(GuiButton) _next_button; @@ -62,6 +63,9 @@ PUBLISHED: virtual void reset_behavior(void); virtual void output(ostream&) const; + + INLINE void set_loop(bool); + INLINE bool get_loop(void) const; public: // type interface static TypeHandle get_class_type(void) {