*** empty log message ***

This commit is contained in:
David Rose 2001-03-13 20:37:28 +00:00
parent 2fddc9ceed
commit e8645a07d9
5 changed files with 112 additions and 40 deletions

View File

@ -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()

View File

@ -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";
}
}

View File

@ -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;

View File

@ -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();
}

View File

@ -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();
}