Browse Source

and there's a skeleton

Cary Sandvig 25 years ago
parent
commit
302b280e2a

+ 6 - 3
panda/src/gui/Sources.pp

@@ -19,7 +19,8 @@
     guiSign.h guiSign.I guiSign.cxx \
     guiSign.h guiSign.I guiSign.cxx \
     guiListBox.h guiListBox.I guiListBox.cxx \
     guiListBox.h guiListBox.I guiListBox.cxx \
     guiBackground.h guiBackground.I guiBackground.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 \
   #define INSTALL_HEADERS \
     guiManager.h guiManager.I \
     guiManager.h guiManager.I \
@@ -32,7 +33,8 @@
     guiSign.h guiSign.I \
     guiSign.h guiSign.I \
     guiListBox.h guiListBox.I \
     guiListBox.h guiListBox.I \
     guiBackground.h guiBackground.I \
     guiBackground.h guiBackground.I \
-    guiBehavior.h guiBehavior.I
+    guiBehavior.h guiBehavior.I \
+    guiChooser.h guiChooser.I
 
 
   #define IGATESCAN \
   #define IGATESCAN \
     guiManager.h guiManager.I \
     guiManager.h guiManager.I \
@@ -45,6 +47,7 @@
     guiSign.h guiSign.I \
     guiSign.h guiSign.I \
     guiListBox.h guiListBox.I \
     guiListBox.h guiListBox.I \
     guiBackground.h guiBackground.I \
     guiBackground.h guiBackground.I \
-    guiBehavior.h guiBehavior.I
+    guiBehavior.h guiBehavior.I \
+    guiChooser.h guiChooser.I
 
 
 #end lib_target
 #end lib_target

+ 2 - 0
panda/src/gui/config_gui.cxx

@@ -14,6 +14,7 @@
 #include "guiListBox.h"
 #include "guiListBox.h"
 #include "guiBehavior.h"
 #include "guiBehavior.h"
 #include "guiBackground.h"
 #include "guiBackground.h"
+#include "guiChooser.h"
 
 
 #include <dconfig.h>
 #include <dconfig.h>
 
 
@@ -31,6 +32,7 @@ ConfigureFn(config_gui) {
   GuiFrame::init_type();
   GuiFrame::init_type();
   GuiListBox::init_type();
   GuiListBox::init_type();
   GuiBackground::init_type();
   GuiBackground::init_type();
+  GuiChooser::init_type();
 }
 }
 
 
 float simple_text_margin_top =
 float simple_text_margin_top =

+ 2 - 0
panda/src/gui/guiChooser.I

@@ -2,3 +2,5 @@
 // Created by:  cary (08Feb01)
 // Created by:  cary (08Feb01)
 // 
 // 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
+
+INLINE GuiChooser::GuiChooser(void) {}

+ 150 - 0
panda/src/gui/guiChooser.cxx

@@ -2,3 +2,153 @@
 // Created by:  cary (08Feb01)
 // 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;
+}

+ 84 - 0
panda/src/gui/guiChooser.h

@@ -2,3 +2,87 @@
 // Created by:  cary (08Feb01)
 // Created by:  cary (08Feb01)
 // 
 // 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
+
+#ifndef __GUICHOOSER_H__
+#define __GUICHOOSER_H__
+
+#include "guiBehavior.h"
+#include "guiButton.h"
+
+#include <vector>
+
+// 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__ */

+ 0 - 1
panda/src/gui/guiListBox.I

@@ -4,4 +4,3 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 
 
 INLINE GuiListBox::GuiListBox(void) {}
 INLINE GuiListBox::GuiListBox(void) {}
-

+ 0 - 1
panda/src/gui/guiListBox.cxx

@@ -215,7 +215,6 @@ void GuiListBox::manage(GuiManager* mgr, EventHandler& eh) {
   if (_mgr == (GuiManager*)0L) {
   if (_mgr == (GuiManager*)0L) {
     for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); ++i)
     for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); ++i)
       (*i)->manage(mgr, eh);
       (*i)->manage(mgr, eh);
-    _eh = &eh;
     GuiBehavior::manage(mgr, eh);
     GuiBehavior::manage(mgr, eh);
   } else
   } else
     gui_cat->warning() << "tried to manage listbox (0x" << (void*)this
     gui_cat->warning() << "tried to manage listbox (0x" << (void*)this