From 302b280e2a347524edab0fb5b749f5dac6efd8bd Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Fri, 9 Feb 2001 02:15:09 +0000 Subject: [PATCH] and there's a skeleton --- panda/src/gui/Sources.pp | 9 ++- panda/src/gui/config_gui.cxx | 2 + panda/src/gui/guiChooser.I | 2 + panda/src/gui/guiChooser.cxx | 150 +++++++++++++++++++++++++++++++++++ panda/src/gui/guiChooser.h | 84 ++++++++++++++++++++ panda/src/gui/guiListBox.I | 1 - panda/src/gui/guiListBox.cxx | 1 - 7 files changed, 244 insertions(+), 5 deletions(-) diff --git a/panda/src/gui/Sources.pp b/panda/src/gui/Sources.pp index ad71859106..232ac1ef7e 100644 --- a/panda/src/gui/Sources.pp +++ b/panda/src/gui/Sources.pp @@ -19,7 +19,8 @@ guiSign.h guiSign.I guiSign.cxx \ guiListBox.h guiListBox.I guiListBox.cxx \ guiBackground.h guiBackground.I guiBackground.cxx \ - guiBehavior.h guiBehavior.I guiBehavior.cxx + guiBehavior.h guiBehavior.I guiBehavior.cxx \ + guiChooser.h guiChooser.I guiChooser.cxx #define INSTALL_HEADERS \ guiManager.h guiManager.I \ @@ -32,7 +33,8 @@ guiSign.h guiSign.I \ guiListBox.h guiListBox.I \ guiBackground.h guiBackground.I \ - guiBehavior.h guiBehavior.I + guiBehavior.h guiBehavior.I \ + guiChooser.h guiChooser.I #define IGATESCAN \ guiManager.h guiManager.I \ @@ -45,6 +47,7 @@ guiSign.h guiSign.I \ guiListBox.h guiListBox.I \ guiBackground.h guiBackground.I \ - guiBehavior.h guiBehavior.I + guiBehavior.h guiBehavior.I \ + guiChooser.h guiChooser.I #end lib_target diff --git a/panda/src/gui/config_gui.cxx b/panda/src/gui/config_gui.cxx index ac8c4c5f3e..2d2a6fb377 100644 --- a/panda/src/gui/config_gui.cxx +++ b/panda/src/gui/config_gui.cxx @@ -14,6 +14,7 @@ #include "guiListBox.h" #include "guiBehavior.h" #include "guiBackground.h" +#include "guiChooser.h" #include @@ -31,6 +32,7 @@ ConfigureFn(config_gui) { GuiFrame::init_type(); GuiListBox::init_type(); GuiBackground::init_type(); + GuiChooser::init_type(); } float simple_text_margin_top = diff --git a/panda/src/gui/guiChooser.I b/panda/src/gui/guiChooser.I index 7765824842..0aec290d0f 100644 --- a/panda/src/gui/guiChooser.I +++ b/panda/src/gui/guiChooser.I @@ -2,3 +2,5 @@ // Created by: cary (08Feb01) // //////////////////////////////////////////////////////////////////// + +INLINE GuiChooser::GuiChooser(void) {} diff --git a/panda/src/gui/guiChooser.cxx b/panda/src/gui/guiChooser.cxx index be14d96ead..b81cc3d429 100644 --- a/panda/src/gui/guiChooser.cxx +++ b/panda/src/gui/guiChooser.cxx @@ -2,3 +2,153 @@ // Created by: cary (08Feb01) // //////////////////////////////////////////////////////////////////// + +#include "guiChooser.h" + +TypeHandle GuiChooser::_type_handle; + +GuiChooser::ChooseFunctor::ChooseFunctor(GuiChooser* ch, + GuiBehavior::BehaviorFunctor* func) + : _prev(func), _ch(ch) { +} + +GuiChooser::ChooseFunctor::~ChooseFunctor(void) { +} + +void GuiChooser::ChooseFunctor::doit(GuiBehavior* b) { + if (b == this->_ch->_prev_button) + this->_ch->move_prev(); + if (b == this->_ch->_next_button) + this->_ch->move_next(); +} + +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), + _next_functor((GuiChooser::ChooseFunctor*)0L) { +} + +GuiChooser::~GuiChooser(void) { + this->unmanage(); +} + +void GuiChooser::move_prev(void) { + if (_curr == -1) + return; +} + +void GuiChooser::move_next(void) { + if (_curr == -1) + return; +} + +void GuiChooser::add_item(GuiItem* item) { +} + +int GuiChooser::freeze(void) { + int result = 0; + + if (_curr != -1) + result = _items[_curr]->freeze(); + return result; +} + +int GuiChooser::thaw(void) { + int result = 0; + + if (_curr != -1) + result = _items[_curr]->thaw(); + return result; +} + +void GuiChooser::manage(GuiManager* mgr, EventHandler& eh) { + if (_mgr == (GuiManager*)0L) { + _prev_button->manage(mgr, eh); + _next_button->manage(mgr, eh); + if (_curr != -1) + _items[_curr]->manage(mgr, eh); + GuiBehavior::manage(mgr, eh); + } else + gui_cat->warning() << "tried to manage chooser (0x" << (void*)this + << ") that is already managed" << endl; +} + +void GuiChooser::unmanage(void) { + _prev_button->unmanage(); + _next_button->unmanage(); + if (_curr != -1) + _items[_curr]->unmanage(); + GuiBehavior::unmanage(); +} + +void GuiChooser::set_scale(float f) { + GuiBehavior::set_scale(f); +} + +void GuiChooser::set_pos(const LVector3f& p) { + GuiBehavior::set_pos(p); +} + +void GuiChooser::start_behavior(void) { + GuiBehavior::start_behavior(); + if (_mgr == (GuiManager*)0L) + return; + if (_prev_functor != (GuiChooser::ChooseFunctor*)0L) { + _prev_button->set_behavior_functor(_prev_functor->get_prev()); + delete _prev_functor; + } + _prev_functor = + new GuiChooser::ChooseFunctor(this, _prev_button->get_behavior_functor()); + _prev_button->set_behavior_functor(_prev_functor); + _prev_button->start_behavior(); + if (_next_functor != (GuiChooser::ChooseFunctor*)0L) { + _next_button->set_behavior_functor(_next_functor->get_prev()); + delete _next_functor; + } + _next_functor = + new GuiChooser::ChooseFunctor(this, _next_button->get_behavior_functor()); + _next_button->set_behavior_functor(_next_functor); + _next_button->start_behavior(); +} + +void GuiChooser::stop_behavior(void) { + GuiBehavior::stop_behavior(); + if (_mgr == (GuiManager*)0L) + return; + if (_prev_functor != (GuiChooser::ChooseFunctor*)0L) { + _prev_button->set_behavior_functor(_prev_functor->get_prev()); + delete _prev_functor; + _prev_functor = (GuiChooser::ChooseFunctor*)0L; + _prev_button->stop_behavior(); + } + if (_next_functor != (GuiChooser::ChooseFunctor*)0L) { + _next_button->set_behavior_functor(_next_functor->get_prev()); + delete _next_functor; + _next_functor = (GuiChooser::ChooseFunctor*)0L; + _next_button->stop_behavior(); + } +} + +void GuiChooser::reset_behavior(void) { + GuiBehavior::reset_behavior(); + if (_mgr == (GuiManager*)0L) + return; + if (_prev_functor != (GuiChooser::ChooseFunctor*)0L) + _prev_button->reset_behavior(); + if (_next_functor != (GuiChooser::ChooseFunctor*)0L) + _next_button->reset_behavior(); +} + +void GuiChooser::output(ostream& os) const { + GuiBehavior::output(os); + os << " Chooser data:" << endl; + os << " prev button - 0x" << (void*)_prev_button << endl; + os << " next button - 0x" << (void*)_next_button << endl; + os << " current - " << _curr << endl; + os << " items (" << _items.size() << "):" << endl; + for (ItemVector::const_iterator i=_items.begin(); i!=_items.end(); ++i) + os << " 0x" << (void*)(*i) << endl; +} diff --git a/panda/src/gui/guiChooser.h b/panda/src/gui/guiChooser.h index 3962178f97..8189489d7e 100644 --- a/panda/src/gui/guiChooser.h +++ b/panda/src/gui/guiChooser.h @@ -2,3 +2,87 @@ // Created by: cary (08Feb01) // //////////////////////////////////////////////////////////////////// + +#ifndef __GUICHOOSER_H__ +#define __GUICHOOSER_H__ + +#include "guiBehavior.h" +#include "guiButton.h" + +#include + +// Only shows one item at a time. Has two buttons that move back and forth +// over the list of things it has. Can do both circular and linear lists. +class EXPCL_PANDA GuiChooser : public GuiBehavior { +private: + typedef vector< PT(GuiItem) > ItemVector; + + class EXPCL_PANDA ChooseFunctor : public GuiBehavior::BehaviorFunctor { + protected: + GuiBehavior::BehaviorFunctor* _prev; + GuiChooser* _ch; + public: + ChooseFunctor(GuiChooser*, GuiBehavior::BehaviorFunctor*); + virtual ~ChooseFunctor(void); + virtual void doit(GuiBehavior*); + INLINE GuiBehavior::BehaviorFunctor* get_prev(void) { return _prev; } + }; + + friend ChooseFunctor; + + ItemVector _items; + int _curr; + PT(GuiButton) _prev_button; + PT(GuiButton) _next_button; + + ChooseFunctor* _prev_functor; + ChooseFunctor* _next_functor; + + INLINE GuiChooser(void); + virtual void recompute_frame(void); +PUBLISHED: + GuiChooser(const string&, GuiButton*, GuiButton*); + ~GuiChooser(void); + + void move_prev(void); + void move_next(void); + void add_item(GuiItem*); + + virtual int freeze(void); + virtual int thaw(void); + + virtual void manage(GuiManager*, EventHandler&); + virtual void unmanage(void); + + virtual void set_scale(float); + virtual void set_pos(const LVector3f&); + + virtual void start_behavior(void); + virtual void stop_behavior(void); + virtual void reset_behavior(void); + + virtual void output(ostream&) const; +public: + // type interface + static TypeHandle get_class_type(void) { + return _type_handle; + } + static void init_type(void) { + GuiBehavior::init_type(); + register_type(_type_handle, "GuiChooser", + GuiBehavior::get_class_type()); + } + virtual TypeHandle get_type(void) const { + return get_class_type(); + } + virtual TypeHandle force_init_type(void) { + init_type(); + return get_class_type(); + } +private: + static TypeHandle _type_handle; +}; + +#include "guiChooser.I" + +#endif /* __GUICHOOSER_H__ */ diff --git a/panda/src/gui/guiListBox.I b/panda/src/gui/guiListBox.I index d07953cc48..ffb860953b 100644 --- a/panda/src/gui/guiListBox.I +++ b/panda/src/gui/guiListBox.I @@ -4,4 +4,3 @@ //////////////////////////////////////////////////////////////////// INLINE GuiListBox::GuiListBox(void) {} - diff --git a/panda/src/gui/guiListBox.cxx b/panda/src/gui/guiListBox.cxx index 09170fee72..220f4075f1 100644 --- a/panda/src/gui/guiListBox.cxx +++ b/panda/src/gui/guiListBox.cxx @@ -215,7 +215,6 @@ void GuiListBox::manage(GuiManager* mgr, EventHandler& eh) { if (_mgr == (GuiManager*)0L) { for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); ++i) (*i)->manage(mgr, eh); - _eh = &eh; GuiBehavior::manage(mgr, eh); } else gui_cat->warning() << "tried to manage listbox (0x" << (void*)this