diff --git a/panda/src/gui/guiListBox.cxx b/panda/src/gui/guiListBox.cxx index 220f4075f1..a21153e113 100644 --- a/panda/src/gui/guiListBox.cxx +++ b/panda/src/gui/guiListBox.cxx @@ -24,6 +24,7 @@ void GuiListBox::ListFunctor::doit(GuiBehavior* b) { void GuiListBox::recompute_frame(void) { GuiBehavior::recompute_frame(); + this->freeze(); LVector3f p = _pos; float lft = 100000.; float rgt = -100000.; @@ -31,7 +32,7 @@ void GuiListBox::recompute_frame(void) { float btm = 100000.; LVector4f frm; for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); - p+=((*i)->get_height() * LVector3f::up()), ++i) { + p-=((*i)->get_height() * LVector3f::up()), ++i) { (*i)->set_pos(p); frm = (*i)->get_frame(); if (frm[0] < lft) @@ -47,6 +48,7 @@ void GuiListBox::recompute_frame(void) { _right = rgt; _top = tp; _bottom = btm; + this->thaw(); } void GuiListBox::visible_patching(void) { @@ -193,26 +195,51 @@ void GuiListBox::add_item(GuiItem* item) { int GuiListBox::freeze(void) { int result = 0; + ItemVector::iterator i; + ItemDeque::iterator j; - for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); ++i) { + for (i=_top_stack.begin(); i!=_top_stack.end(); ++i) { int count = (*i)->freeze(); result = max(result, count); } + for (i=_visible.begin(); i!=_visible.end(); ++i) { + int count = (*i)->freeze(); + result = max(result, count); + } + for (j=_bottom_stack.begin(); j!=_bottom_stack.end(); ++j) { + int count = (*j)->freeze(); + result = max(result, count); + } + _up_arrow->freeze(); + _down_arrow->freeze(); return result; } int GuiListBox::thaw(void) { int result = 0; + ItemVector::iterator i; + ItemDeque::iterator j; - for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); ++i) { + for (i=_top_stack.begin(); i!=_top_stack.end(); ++i) { int count = (*i)->thaw(); result = max(result, count); } + for (i=_visible.begin(); i!=_visible.end(); ++i) { + int count = (*i)->thaw(); + result = max(result, count); + } + for (j=_bottom_stack.begin(); j!=_bottom_stack.end(); ++j) { + int count = (*j)->thaw(); + result = max(result, count); + } + _up_arrow->thaw(); + _down_arrow->thaw(); return result; } void GuiListBox::manage(GuiManager* mgr, EventHandler& eh) { if (_mgr == (GuiManager*)0L) { + this->recompute_frame(); for (ItemVector::iterator i=_visible.begin(); i!=_visible.end(); ++i) (*i)->manage(mgr, eh); GuiBehavior::manage(mgr, eh); @@ -331,14 +358,14 @@ void GuiListBox::output(ostream& os) const { os << " Top stack (" << _top_stack.size() << "):" << endl; ItemVector::const_iterator i; for (i=_top_stack.begin(); i!=_top_stack.end(); ++i) - os << " 0x" << (void*)(*i) << endl; + os << " 0x" << (void*)(*i) << " (" << (*i)->get_name() << ")" << endl; os << " Visible (" << _visible.size() << "):" << endl; for (i=_visible.begin(); i!=_visible.end(); ++i) - os << " 0x" << (void*)(*i) << endl; + os << " 0x" << (void*)(*i) << " (" << (*i)->get_name() << ")" << endl; os << " Bottom stack (" << _bottom_stack.size() << "):" << endl; ItemDeque::const_iterator j; for (j=_bottom_stack.begin(); j!=_bottom_stack.end(); ++j) - os << " 0x" << (void*)(*j) << endl; + os << " 0x" << (void*)(*j) << " (" << (*j)->get_name() << ")" << endl; for (i=_top_stack.begin(); i!=_top_stack.end(); ++i) os << *(*i); for (i=_visible.begin(); i!=_visible.end(); ++i) diff --git a/panda/src/testbed/gui_demo.cxx b/panda/src/testbed/gui_demo.cxx index 3f80e176cf..f5cf8b17c4 100644 --- a/panda/src/testbed/gui_demo.cxx +++ b/panda/src/testbed/gui_demo.cxx @@ -596,8 +596,10 @@ PT(GuiListBox) lb1; static void test11(GuiManager* mgr, Node* font) { GuiLabel* ul = GuiLabel::make_simple_text_label("upup", font); GuiSign* us = new GuiSign("up_arrow", ul); + us->set_scale(0.1); GuiLabel* dl = GuiLabel::make_simple_text_label("dndn", font); GuiSign* ds = new GuiSign("down_arrow", dl); + ds->set_scale(0.1); lb1 = new GuiListBox("list_box", 4, us, ds); GuiLabel* l1 = GuiLabel::make_simple_text_label("hyena", font); GuiSign* s1 = new GuiSign("hyena", l1); @@ -629,6 +631,13 @@ static void test11(GuiManager* mgr, Node* font) { l3->set_width(w); l4->set_width(w); l5->set_width(w); + ul->set_background_color(0., 0., 0., 1.); + dl->set_background_color(0., 0., 0., 1.); + l1->set_background_color(0., 0., 0., 1.); + l2->set_background_color(0., 0., 0., 1.); + l3->set_background_color(0., 0., 0., 1.); + l4->set_background_color(0., 0., 0., 1.); + l5->set_background_color(0., 0., 0., 1.); lb1->add_item(s1); lb1->add_item(s2); lb1->add_item(s3); @@ -636,6 +645,7 @@ static void test11(GuiManager* mgr, Node* font) { lb1->add_item(s5); lb1->thaw(); lb1->manage(mgr, event_handler); + cout << *lb1; } static void test12(GuiManager* mgr, Node* font) { @@ -686,9 +696,9 @@ static void setup_gui(void) { // test 10 // test10(mgr, font); // test 11 - // test11(mgr, font); + test11(mgr, font); // test 12 - test12(mgr, font); + // test12(mgr, font); } static void event_2(CPT_Event) { @@ -789,12 +799,10 @@ void gui_keys(EventHandler&) { have_dlight = true; event_handler.add_hook("2", event_2); - /* // for tests 7-11 event_handler.add_hook("3", event_3); // for test 11 event_handler.add_hook("4", event_4); - */ event_handler.add_hook("demo-event-thing", event_demo); }