From e8645a07d9e363ef4bc5c2f0732eb821bef6898b Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 13 Mar 2001 20:37:28 +0000 Subject: [PATCH] *** empty log message *** --- direct/src/gui/ListBox.py | 60 +++++++++++++---------------- panda/src/event/eventHandler.cxx | 66 ++++++++++++++++++++++++++++++++ panda/src/event/eventHandler.h | 7 ++++ panda/src/gui/guiItem.cxx | 7 +++- panda/src/gui/guiListBox.cxx | 12 +++--- 5 files changed, 112 insertions(+), 40 deletions(-) diff --git a/direct/src/gui/ListBox.py b/direct/src/gui/ListBox.py index 9eb8228248..cab2f15d1d 100644 --- a/direct/src/gui/ListBox.py +++ b/direct/src/gui/ListBox.py @@ -22,37 +22,23 @@ class ListBox(DirectObject): self.drawOrder = drawOrder self.font = font - #arrow = loader.loadModelOnce('phase_3/models/props/scroll-arrow') - arrow = None - - if arrow == None: - self.up = Button.Button(name + '-up', '*', - scale = self.scale, - width = 2, - drawOrder = self.drawOrder, - font = self.font) - self.down = Button.Button(name + '-down', '*', - scale = self.scale, - width = 2, - drawOrder = self.drawOrder, - font = self.font) - else: - arrowScale = 0.1 - self.up = Button.Button(name + '-up', arrow, - left = -1, right = 1, - bottom = 0, top = 0.5, - scale = arrowScale, - drawOrder = drawOrder) - arrow.setR(180) - self.down = Button.Button(name + '-down', arrow, - left = -1, right = 1, - bottom = -0.5, top = 0, - scale = arrowScale, - drawOrder = drawOrder) - arrow.removeNode() + arrow = loader.loadModelOnce('phase_3/models/props/scroll-arrow') + arrowScale = 0.1 + self.up = Button.Button(name + '-up', arrow, + left = -1, right = 1, + bottom = 0, top = 0.5, + scale = arrowScale, + drawOrder = drawOrder) + arrow.setR(180) + self.down = Button.Button(name + '-down', arrow, + left = -1, right = 1, + bottom = -0.5, top = 0, + scale = arrowScale, + drawOrder = drawOrder) + arrow.removeNode() - self.listBox = GuiListBox(self.name, self.numSlots, + self.listBox = GuiListBox(self.name + '-lb', self.numSlots, self.up.button, self.down.button) self.managed = 0 @@ -68,7 +54,7 @@ class ListBox(DirectObject): drawOrder = self.drawOrder, font = self.font) - self.items.append(item) + self.items.append((item, button)) self.listBox.addItem(button.button) def addItems(self, items): @@ -80,9 +66,11 @@ class ListBox(DirectObject): def cleanup(self): if (self.managed): - self.listBox.unmanage() - self.up = None - self.down = None + self.unmanage() + for i in self.items: + i[1].cleanup() + self.up.cleanup() + self.down.cleanup() self.listBox = None return None @@ -98,6 +86,12 @@ class ListBox(DirectObject): def getGuiItem(self): return self.listBox + def getUpButton(self): + return self.up + + def getDownButton(self): + return self.down + def freeze(self): self.listBox.freeze() diff --git a/panda/src/event/eventHandler.cxx b/panda/src/event/eventHandler.cxx index 84867eda3e..00c6999cc8 100644 --- a/panda/src/event/eventHandler.cxx +++ b/panda/src/event/eventHandler.cxx @@ -77,6 +77,48 @@ dispatch_event(const CPT_Event &event) { } +//////////////////////////////////////////////////////////////////// +// Function: EventHandler::write +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void EventHandler:: +write(ostream &out) const { + Hooks::const_iterator hi; + hi = _hooks.begin(); + + CallbackHooks::const_iterator cbhi; + cbhi = _cbhooks.begin(); + + while (hi != _hooks.end() && cbhi != _cbhooks.end()) { + if ((*hi).first < (*cbhi).first) { + write_hook(out, *hi); + ++hi; + + } else if ((*cbhi).first < (*hi).first) { + write_cbhook(out, *cbhi); + ++cbhi; + + } else { + write_hook(out, *hi); + write_cbhook(out, *cbhi); + ++hi; + ++cbhi; + } + } + + while (hi != _hooks.end()) { + write_hook(out, *hi); + ++hi; + } + + while (cbhi != _cbhooks.end()) { + write_cbhook(out, *cbhi); + ++cbhi; + } +} + + //////////////////////////////////////////////////////////////////// // Function: EventHandler::add_hook @@ -152,3 +194,27 @@ remove_all_hooks() { _cbhooks.clear(); } + +//////////////////////////////////////////////////////////////////// +// Function: EventHandler::write_hook +// Access: Private +// Description: +//////////////////////////////////////////////////////////////////// +void EventHandler:: +write_hook(ostream &out, const EventHandler::Hooks::value_type &hook) const { + if (!hook.second.empty()) { + out << hook.first << " has " << hook.second.size() << " functions.\n"; + } +} + +//////////////////////////////////////////////////////////////////// +// Function: EventHandler::write_cbhook +// Access: Private +// Description: +//////////////////////////////////////////////////////////////////// +void EventHandler:: +write_cbhook(ostream &out, const EventHandler::CallbackHooks::value_type &hook) const { + if (!hook.second.empty()) { + out << hook.first << " has " << hook.second.size() << " callback functions.\n"; + } +} diff --git a/panda/src/event/eventHandler.h b/panda/src/event/eventHandler.h index c77a53be85..cd46f31f75 100644 --- a/panda/src/event/eventHandler.h +++ b/panda/src/event/eventHandler.h @@ -41,6 +41,8 @@ PUBLISHED: virtual void dispatch_event(const CPT_Event &event); + void write(ostream &out) const; + public: bool add_hook(const string &event_name, EventFunction *function); bool add_hook(const string &event_name, EventCallbackFunction *function, @@ -63,6 +65,11 @@ protected: CallbackHooks _cbhooks; EventQueue &_queue; +private: + void write_hook(ostream &out, const Hooks::value_type &hook) const; + void write_cbhook(ostream &out, const CallbackHooks::value_type &hook) const; + + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/gui/guiItem.cxx b/panda/src/gui/guiItem.cxx index 7fe763c124..0f6de4d283 100644 --- a/panda/src/gui/guiItem.cxx +++ b/panda/src/gui/guiItem.cxx @@ -42,11 +42,16 @@ GuiItem::GuiItem(const string& name) : Namable(name), _added_hooks(false), _bottom(-1.), _top(1.), _pos(0., 0., 0.), _mgr((GuiManager*)0L), _pri(P_Normal) { + + if (gui_cat->is_debug()) + gui_cat->debug() + << "creating item '" << get_name() << "' (" << (void *)this << ")\n"; } GuiItem::~GuiItem(void) { if (gui_cat->is_debug()) - gui_cat->debug() << "deleting item '" << this->get_name() << "'" << endl; + gui_cat->debug() + << "deleting item '" << get_name() << "' (" << (void *)this << ")\n"; // this->unmanage(); } diff --git a/panda/src/gui/guiListBox.cxx b/panda/src/gui/guiListBox.cxx index 6dddb8b1ff..54f7c83b80 100644 --- a/panda/src/gui/guiListBox.cxx +++ b/panda/src/gui/guiListBox.cxx @@ -238,8 +238,8 @@ void GuiListBox::manage(GuiManager* mgr, EventHandler& eh) { this->recompute_frame(); for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); ++i) (*i)->manage(mgr, eh); - _up_arrow->manage(mgr, eh); - _down_arrow->manage(mgr, eh); + // _up_arrow->manage(mgr, eh); + // _down_arrow->manage(mgr, eh); this->deal_with_buttons(); GuiBehavior::manage(mgr, eh); } else @@ -252,8 +252,8 @@ void GuiListBox::manage(GuiManager* mgr, EventHandler& eh, Node* n) { this->recompute_frame(); for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); ++i) (*i)->manage(mgr, eh, n); - _up_arrow->manage(mgr, eh, n); - _down_arrow->manage(mgr, eh, n); + // _up_arrow->manage(mgr, eh, n); + // _down_arrow->manage(mgr, eh, n); this->deal_with_buttons(); GuiBehavior::manage(mgr, eh, n); } else @@ -264,8 +264,8 @@ void GuiListBox::manage(GuiManager* mgr, EventHandler& eh, Node* n) { void GuiListBox::unmanage(void) { for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); ++i) (*i)->unmanage(); - _up_arrow->unmanage(); - _down_arrow->unmanage(); + // _up_arrow->unmanage(); + // _down_arrow->unmanage(); GuiBehavior::unmanage(); }