From dba6793ad80afe410b62f7ecff72a684e7cdf071 Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Sat, 7 Apr 2001 00:50:31 +0000 Subject: [PATCH] set page functionality --- panda/src/gui/guiChooser.cxx | 106 +++++++++++++++++++---------------- panda/src/gui/guiChooser.h | 2 + 2 files changed, 60 insertions(+), 48 deletions(-) diff --git a/panda/src/gui/guiChooser.cxx b/panda/src/gui/guiChooser.cxx index d565af5453..9534fad781 100644 --- a/panda/src/gui/guiChooser.cxx +++ b/panda/src/gui/guiChooser.cxx @@ -80,6 +80,32 @@ GuiChooser::~GuiChooser(void) { this->unmanage(); } +void GuiChooser::adjust_buttons(void) { + if (_curr < 0) + return; + if (_curr == 0) { + _prev_button->exit(); + _prev_button->inactive(); + } else { + _prev_button->up(); + if (_behavior_running) { + _prev_button->start_behavior(); + _prev_button->set_behavior_functor(_prev_functor); + } + } + int foo = _items.size() - 1; + if (_curr == foo) { + _next_button->exit(); + _next_button->inactive(); + } else { + _next_button->up(); + if (_behavior_running) { + _next_button->start_behavior(); + _next_button->set_behavior_functor(_next_functor); + } + } +} + void GuiChooser::move_prev(void) { if (_curr == -1) return; @@ -96,31 +122,11 @@ void GuiChooser::move_prev(void) { _items[tmp]->manage(_mgr, *_eh); else _items[tmp]->manage(_mgr, *_eh, _alt_root); - if (tmp == 0) { - _prev_button->exit(); - _prev_button->inactive(); - } else { - _prev_button->up(); - if (_behavior_running) { - _prev_button->start_behavior(); - _prev_button->set_behavior_functor(_prev_functor); - } - } - int foo = _items.size() - 1; - if (tmp == foo) { - _next_button->exit(); - _next_button->inactive(); - } else { - _next_button->up(); - if (_behavior_running) { - _next_button->start_behavior(); - _next_button->set_behavior_functor(_next_functor); - } - } - } - _curr = tmp; - if (_mgr != (GuiManager*)0L) + _curr = tmp; + this->adjust_buttons(); _mgr->recompute_priorities(); + } else + _curr = tmp; } void GuiChooser::move_next(void) { @@ -140,31 +146,11 @@ void GuiChooser::move_next(void) { _items[tmp]->manage(_mgr, *_eh); else _items[tmp]->manage(_mgr, *_eh, _alt_root); - if (tmp == 0) { - _prev_button->exit(); - _prev_button->inactive(); - } else { - _prev_button->up(); - if (_behavior_running) { - _prev_button->start_behavior(); - _prev_button->set_behavior_functor(_prev_functor); - } - } - int foo = _items.size() - 1; - if (tmp == foo) { - _next_button->exit(); - _next_button->inactive(); - } else { - _next_button->up(); - if (_behavior_running) { - _next_button->start_behavior(); - _next_button->set_behavior_functor(_next_functor); - } - } - } - _curr = tmp; - if (_mgr != (GuiManager*)0L) + _curr = tmp; + this->adjust_buttons(); _mgr->recompute_priorities(); + } else + _curr = tmp; } void GuiChooser::add_item(GuiItem* item) { @@ -325,6 +311,30 @@ int GuiChooser::set_draw_order(int v) { return GuiBehavior::set_draw_order(o); } +void GuiChooser::set_curr_item(int i) { + int foo = _items.size(); + int ctmp = i; + if (i < 0) + return; + if (i > foo) { + if (_loop) + ctmp = i % foo; + else + return; + } + if (_mgr != (GuiManager*)0L) { + _items[_curr]->unmanage(); + if (_alt_root.is_null()) + _items[ctmp]->manage(_mgr, *_eh); + else + _items[ctmp]->manage(_mgr, *_eh, _alt_root); + _curr = ctmp; + this->adjust_buttons(); + _mgr->recompute_priorities(); + } else + _curr = ctmp; +} + void GuiChooser::output(ostream& os) const { GuiBehavior::output(os); os << " Chooser data:" << endl; diff --git a/panda/src/gui/guiChooser.h b/panda/src/gui/guiChooser.h index 6f9c9b4194..fa898c3c24 100644 --- a/panda/src/gui/guiChooser.h +++ b/panda/src/gui/guiChooser.h @@ -41,6 +41,7 @@ private: INLINE GuiChooser(void); virtual void recompute_frame(void); + void adjust_buttons(void); PUBLISHED: GuiChooser(const string&, GuiButton*, GuiButton*); ~GuiChooser(void); @@ -50,6 +51,7 @@ PUBLISHED: void add_item(GuiItem*); INLINE int get_curr_item(void) const; + void set_curr_item(int); virtual int freeze(void); virtual int thaw(void);