From 9840d1c71bcfbe0b7c5c4f772e19dae507f5cd42 Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Thu, 8 Mar 2001 08:16:54 +0000 Subject: [PATCH] and away we go --- panda/src/gui/Sources.pp | 9 ++++-- panda/src/gui/config_gui.cxx | 2 ++ panda/src/gui/guiCollection.cxx | 57 +++++++++++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/panda/src/gui/Sources.pp b/panda/src/gui/Sources.pp index 232ac1ef7e..3ea87e666b 100644 --- a/panda/src/gui/Sources.pp +++ b/panda/src/gui/Sources.pp @@ -20,7 +20,8 @@ guiListBox.h guiListBox.I guiListBox.cxx \ guiBackground.h guiBackground.I guiBackground.cxx \ guiBehavior.h guiBehavior.I guiBehavior.cxx \ - guiChooser.h guiChooser.I guiChooser.cxx + guiChooser.h guiChooser.I guiChooser.cxx \ + guiCollection.h guiCollection.I guiCollection.cxx #define INSTALL_HEADERS \ guiManager.h guiManager.I \ @@ -34,7 +35,8 @@ guiListBox.h guiListBox.I \ guiBackground.h guiBackground.I \ guiBehavior.h guiBehavior.I \ - guiChooser.h guiChooser.I + guiChooser.h guiChooser.I \ + guiCollection.h guiCollection.I #define IGATESCAN \ guiManager.h guiManager.I \ @@ -48,6 +50,7 @@ guiListBox.h guiListBox.I \ guiBackground.h guiBackground.I \ guiBehavior.h guiBehavior.I \ - guiChooser.h guiChooser.I + guiChooser.h guiChooser.I \ + guiCollection.h guiCollection.I #end lib_target diff --git a/panda/src/gui/config_gui.cxx b/panda/src/gui/config_gui.cxx index 2d2a6fb377..68712bfd8b 100644 --- a/panda/src/gui/config_gui.cxx +++ b/panda/src/gui/config_gui.cxx @@ -15,6 +15,7 @@ #include "guiBehavior.h" #include "guiBackground.h" #include "guiChooser.h" +#include "guiCollection.h" #include @@ -33,6 +34,7 @@ ConfigureFn(config_gui) { GuiListBox::init_type(); GuiBackground::init_type(); GuiChooser::init_type(); + GuiCollection::init_type(); } float simple_text_margin_top = diff --git a/panda/src/gui/guiCollection.cxx b/panda/src/gui/guiCollection.cxx index 38fc2a8c88..4c1f77daff 100644 --- a/panda/src/gui/guiCollection.cxx +++ b/panda/src/gui/guiCollection.cxx @@ -13,7 +13,7 @@ void GuiCollection::recompute_frame(void) { freeze(); for (Items::iterator i=_items.begin(); i!=_items.end(); ++i) - (*i)->recompute_frame(); + (*i)->recompute(); thaw(); } @@ -52,7 +52,7 @@ int GuiCollection::thaw(void) { void GuiCollection::add_item(GuiItem* item) { bool found = false; - for (Items.iterator i=_items.begin(); i!=_items.end(); ++i) + for (Items::iterator i=_items.begin(); i!=_items.end(); ++i) if ((*i) == item) found = true; if (!found) @@ -61,10 +61,61 @@ void GuiCollection::add_item(GuiItem* item) { } void GuiCollection::remove_item(GuiItem* item) { - Items::iterator i = _items.find(item); + Items::iterator i; + for (i=_items.begin(); i!=_items.end(); ++i) + if ((*i) == item) + break; if (i == _items.end()) return; item->unmanage(); _items.erase(i); this->recompute(); } + +void GuiCollection::manage(GuiManager* mgr, EventHandler& eh) { + if (!_added_hooks) + _added_hooks = true; + if (_mgr == (GuiManager*)0L) { + for (Items::iterator i=_items.begin(); i!=_items.end(); ++i) + (*i)->manage(mgr, eh); + GuiItem::manage(mgr, eh); + } else + gui_cat->warning() << "tried to manage collection (0x" << (void*)this + << ") that is already managed" << endl; +} + +void GuiCollection::unmanage(void) { + for (Items::iterator i=_items.begin(); i!=_items.end(); ++i) + (*i)->unmanage(); + GuiItem::unmanage(); +} + +void GuiCollection::set_scale(float f) { + for (Items::iterator i=_items.begin(); i!=_items.end(); ++i) + (*i)->set_scale(f * (*i)->get_scale()); + GuiItem::set_scale(f); + this->recompute_frame(); +} + +void GuiCollection::set_pos(const LVector3f& p) { + LVector3f delta = p - this->get_pos(); + for (Items::iterator i=_items.begin(); i!=_items.end(); ++i) + (*i)->set_pos((*i)->get_pos() + delta); + GuiItem::set_pos(p); + this->recompute_frame(); +} + +void GuiCollection::set_priority(GuiItem* it, const GuiItem::Priority p) { + for (Items::iterator i=_items.begin(); i!=_items.end(); ++i) + (*i)->set_priority(it, p); +} + +void GuiCollection::output(ostream& os) const { + GuiItem::output(os); + os << " Collection data:" << endl; + Items::const_iterator i; + for (i=_items.begin(); i!=_items.end(); ++i) + os << " item - 0x" << (void*)(*i) << endl; + for (i=_items.begin(); i!=_items.end(); ++i) + os << *(*i); +}