making things work

This commit is contained in:
Cary Sandvig 2001-02-15 23:47:04 +00:00
parent ffff89ff41
commit aa19efb995
4 changed files with 188 additions and 20 deletions

View File

@ -470,6 +470,7 @@ void GuiButton::reset_behavior(void) {
GuiBehavior::reset_behavior();
if (_mgr == (GuiManager*)0L)
return;
this->start_behavior();
_eh->remove_hook(_up_event, GuiButton::behavior_up, (void*)this);
_eh->remove_hook(_up_rollover_event, GuiButton::behavior_up, (void*)this);
}

View File

@ -39,9 +39,11 @@ void GuiChooser::move_prev(void) {
if (_curr == -1)
return;
int tmp = _curr - 1;
if (_loop) {
if (tmp < 0)
if (tmp < 0) {
if (_loop)
tmp += _items.size();
else
return;
}
if (_mgr != (GuiManager*)0L) {
_items[_curr]->unmanage();
@ -63,10 +65,12 @@ void GuiChooser::move_next(void) {
if (_curr == -1)
return;
int tmp = _curr + 1;
if (_loop) {
int foo = _items.size();
if (tmp == foo)
if (tmp == foo) {
if (_loop)
tmp = 0;
else
return;
}
if (_mgr != (GuiManager*)0L) {
_items[_curr]->unmanage();
@ -92,16 +96,24 @@ void GuiChooser::add_item(GuiItem* item) {
int GuiChooser::freeze(void) {
int result = 0;
if (_curr != -1)
result = _items[_curr]->freeze();
_prev_button->freeze();
_next_button->freeze();
for (ItemVector::iterator i=_items.begin(); i!=_items.end(); ++i) {
int count = (*i)->freeze();
result = max(result, count);
}
return result;
}
int GuiChooser::thaw(void) {
int result = 0;
if (_curr != -1)
result = _items[_curr]->thaw();
_prev_button->thaw();
_next_button->thaw();
for (ItemVector::iterator i=_items.begin(); i!=_items.end(); ++i) {
int count = (*i)->thaw();
result = max(result, count);
}
return result;
}
@ -109,8 +121,17 @@ void GuiChooser::manage(GuiManager* mgr, EventHandler& eh) {
if (_mgr == (GuiManager*)0L) {
_prev_button->manage(mgr, eh);
_next_button->manage(mgr, eh);
if (_curr != -1)
if (_curr != -1) {
_items[_curr]->manage(mgr, eh);
if (_curr == 0)
_prev_button->inactive();
int foo = _items.size() - 1;
if (_curr == foo)
_next_button->inactive();
} else {
_prev_button->inactive();
_next_button->inactive();
}
GuiBehavior::manage(mgr, eh);
} else
gui_cat->warning() << "tried to manage chooser (0x" << (void*)this

View File

@ -16,11 +16,18 @@ GuiListBox::ListFunctor::~ListFunctor(void) {
}
void GuiListBox::ListFunctor::doit(GuiBehavior* b) {
if (b == this->_lb->_up_arrow)
gui_cat->debug() << "in GuiListBox::ListFunctor::doit" << endl;
gui_cat->debug() << "b = 0x" << (void*)b << " (" << b->get_name() << ")"
<< endl;
if (b == this->_lb->_up_arrow) {
gui_cat->debug() << "scrolling up" << endl;
this->_lb->scroll_up();
if (b == this->_lb->_down_arrow)
}
if (b == this->_lb->_down_arrow) {
gui_cat->debug() << "scrolling down" << endl;
this->_lb->scroll_down();
}
}
void GuiListBox::recompute_frame(void) {
GuiBehavior::recompute_frame();
@ -80,10 +87,11 @@ void GuiListBox::visible_patching(void) {
_visible[0]->unmanage();
_top_stack.push_back(_visible[0]);
_visible[0] = _up_arrow;
if (_mgr != (GuiManager*)0L)
if (_mgr != (GuiManager*)0L) {
_up_arrow->manage(_mgr, *_eh);
}
}
}
// now bottom
if (_arrow_bottom) {
@ -106,12 +114,17 @@ void GuiListBox::visible_patching(void) {
_visible[last]->unmanage();
_bottom_stack.push_back(_visible[last]);
_visible[last] = _down_arrow;
if (_mgr != (GuiManager*)0L)
if (_mgr != (GuiManager*)0L) {
_down_arrow->manage(_mgr, *_eh);
}
}
}
// and restart any behavior
if (_behavior_running)
this->reset_behavior();
}
GuiListBox::GuiListBox(const string& name, int N, GuiItem* up, GuiItem* down)
: GuiBehavior(name), _arrow_top(false), _arrow_bottom(false), _up_arrow(up),
_down_arrow(down), _n_visible(N),
@ -128,7 +141,7 @@ GuiListBox::~GuiListBox(void) {
this->unmanage();
}
void GuiListBox::scroll_up(void) {
void GuiListBox::scroll_down(void) {
if (_bottom_stack.size() == 0)
return; // nothing to scroll
// compute what the first and list item in the visible list are
@ -156,7 +169,7 @@ void GuiListBox::scroll_up(void) {
this->recompute_frame();
}
void GuiListBox::scroll_down(void) {
void GuiListBox::scroll_up(void) {
if (_top_stack.size() == 0)
return; // nothing to scroll
// compute what the first and last item in the visible list are
@ -311,6 +324,16 @@ void GuiListBox::set_pos(const LVector3f& p) {
#include "guiButton.h"
static void handle_scroll_up(CPT_Event, void* lb) {
GuiListBox* b = (GuiListBox*)lb;
b->scroll_up();
}
static void handle_scroll_down(CPT_Event, void* lb) {
GuiListBox* b = (GuiListBox*)lb;
b->scroll_down();
}
void GuiListBox::start_behavior(void) {
GuiBehavior::start_behavior();
if (_mgr == (GuiManager*)0L)
@ -319,6 +342,7 @@ void GuiListBox::start_behavior(void) {
_down_arrow->is_of_type(GuiButton::get_class_type())) {
GuiButton* up = DCAST(GuiButton, _up_arrow);
GuiButton* dn = DCAST(GuiButton, _down_arrow);
/*
if (_up_functor != (GuiListBox::ListFunctor*)0L) {
up->set_behavior_functor(_up_functor->get_prev());
delete _up_functor;
@ -326,7 +350,13 @@ void GuiListBox::start_behavior(void) {
_up_functor = new GuiListBox::ListFunctor(this,
up->get_behavior_functor());
up->set_behavior_functor(_up_functor);
*/
string ev = this->get_name();
ev += "-scroll-up";
up->set_behavior_event(ev);
up->start_behavior();
_eh->add_hook(ev, handle_scroll_up, (void*)this);
/*
if (_down_functor != (GuiListBox::ListFunctor*)0L) {
dn->set_behavior_functor(_down_functor->get_prev());
delete _down_functor;
@ -334,7 +364,12 @@ void GuiListBox::start_behavior(void) {
_down_functor = new GuiListBox::ListFunctor(this,
dn->get_behavior_functor());
dn->set_behavior_functor(_down_functor);
*/
ev = this->get_name();
ev += "-scroll-down";
dn->set_behavior_event(ev);
dn->start_behavior();
_eh->add_hook(ev, handle_scroll_down, (void*)this);
} else
gui_cat->error() << "tried to run behavior on listbox '"
<< this->get_name()
@ -345,6 +380,10 @@ void GuiListBox::stop_behavior(void) {
GuiBehavior::stop_behavior();
if (_mgr == (GuiManager*)0L)
return;
string ev = this->get_name();
_eh->remove_hook(ev + "-scroll-up", handle_scroll_up, (void*)this);
_eh->remove_hook(ev + "-scroll-down", handle_scroll_down, (void*)this);
/*
if (_up_functor != (GuiListBox::ListFunctor*)0L) {
GuiButton* up = DCAST(GuiButton, _up_arrow);
up->set_behavior_functor(_up_functor->get_prev());
@ -359,12 +398,14 @@ void GuiListBox::stop_behavior(void) {
_down_functor = (GuiListBox::ListFunctor*)0L;
dn->stop_behavior();
}
*/
}
void GuiListBox::reset_behavior(void) {
GuiBehavior::reset_behavior();
if (_mgr == (GuiManager*)0L)
return;
/*
if (_up_functor != (GuiListBox::ListFunctor*)0L) {
GuiButton* up = DCAST(GuiButton, _up_arrow);
up->reset_behavior();
@ -373,6 +414,20 @@ void GuiListBox::reset_behavior(void) {
GuiButton* dn = DCAST(GuiButton, _down_arrow);
dn->reset_behavior();
}
*/
string ev = this->get_name();
_eh->add_hook(ev + "-scroll-up", handle_scroll_up, (void*)this);
_eh->add_hook(ev + "-scroll-down", handle_scroll_down, (void*)this);
if (_up_arrow->is_of_type(GuiButton::get_class_type())) {
GuiButton* up = DCAST(GuiButton, _up_arrow);
up->start_behavior();
up->set_behavior_event(ev + "-scroll-up");
}
if (_down_arrow->is_of_type(GuiButton::get_class_type())) {
GuiButton* down = DCAST(GuiButton, _down_arrow);
down->start_behavior();
down->set_behavior_event(ev + "-scroll-down");
}
}
void GuiListBox::output(ostream& os) const {

View File

@ -48,6 +48,7 @@
#include <guiFrame.h>
#include <guiSign.h>
#include <guiListBox.h>
#include <guiChooser.h>
//From framework
extern PT(GeomNode) geomnode;
@ -679,7 +680,9 @@ static void test13(GuiManager* mgr, Node* font) {
GuiLabel* dl2 = GuiLabel::make_simple_text_label("dndn", font);
GuiLabel* dl3 = GuiLabel::make_simple_text_label("dndn", font);
GuiButton* db = new GuiButton("down_arrow", dl1, dl2, dl3);
dl->set_scale(0.1);
db->set_scale(0.1);
ub->set_behavior_event("demo-event-thing");
db->set_behavior_event("demo-event-thing");
lb1 = new GuiListBox("list_box", 4, ub, db);
GuiLabel* l1 = GuiLabel::make_simple_text_label("hyena", font);
GuiSign* s1 = new GuiSign("hyena", l1);
@ -736,6 +739,78 @@ static void test13(GuiManager* mgr, Node* font) {
lb1->start_behavior();
}
PT(GuiChooser) ch1;
static void test14(GuiManager* mgr, Node* font) {
GuiLabel* nl1 = GuiLabel::make_simple_text_label("next", font);
GuiLabel* nl2 = GuiLabel::make_simple_text_label("next", font);
GuiLabel* nl3 = GuiLabel::make_simple_text_label("next", font);
GuiButton* nb = new GuiButton("next_button", nl1, nl2, nl3);
nb->set_scale(0.1);
nb->set_pos(LVector3f::rfu(0.25, 0., -0.25));
GuiLabel* pl1 = GuiLabel::make_simple_text_label("prev", font);
GuiLabel* pl2 = GuiLabel::make_simple_text_label("prev", font);
GuiLabel* pl3 = GuiLabel::make_simple_text_label("prev", font);
GuiButton* pb = new GuiButton("prev_button", pl1, pl2, pl3);
pb->set_scale(0.1);
pb->set_pos(LVector3f::rfu(-0.25, 0., -0.25));
nb->set_behavior_event("demo-event-thing");
pb->set_behavior_event("demo-event-thing");
ch1 = new GuiChooser("chooser", pb, nb);
GuiLabel* l1 = GuiLabel::make_simple_text_label("hyena", font);
GuiSign* s1 = new GuiSign("hyena", l1);
s1->set_scale(0.1);
GuiLabel* l2 = GuiLabel::make_simple_text_label("dingo", font);
GuiSign* s2 = new GuiSign("dingo", l2);
s2->set_scale(0.1);
GuiLabel* l3 = GuiLabel::make_simple_text_label("jackal", font);
GuiSign* s3 = new GuiSign("jackal", l3);
s3->set_scale(0.1);
GuiLabel* l4 = GuiLabel::make_simple_text_label("wolf", font);
GuiSign* s4 = new GuiSign("wolf", l4);
s4->set_scale(0.1);
GuiLabel* l5 = GuiLabel::make_simple_text_label("fox", font);
GuiSign* s5 = new GuiSign("fox", l5);
s5->set_scale(0.1);
float w, w1, w2;
w1 = l1->get_width();
w2 = l2->get_width();
w = (w1>w2)?w1:w2;
w2 = l3->get_width();
w = (w>w2)?w:w2;
w2 = l4->get_width();
w = (w>w2)?w:w2;
w2 = l5->get_width();
w = (w>w2)?w:w2;
l1->set_width(w);
l2->set_width(w);
l3->set_width(w);
l4->set_width(w);
l5->set_width(w);
nl1->set_background_color(0., 0., 0., 1.);
nl2->set_background_color(0., 0., 0., 1.);
nl3->set_background_color(0., 0., 0., 1.);
nl2->set_foreground_color(1., 0., 0., 1.);
nl3->set_foreground_color(1., 1., 1., 0.5);
pl1->set_background_color(0., 0., 0., 1.);
pl2->set_background_color(0., 0., 0., 1.);
pl3->set_background_color(0., 0., 0., 1.);
pl2->set_foreground_color(1., 0., 0., 1.);
pl3->set_foreground_color(1., 1., 1., 0.5);
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.);
ch1->add_item(s1);
ch1->add_item(s2);
ch1->add_item(s3);
ch1->add_item(s4);
ch1->add_item(s5);
ch1->thaw();
ch1->manage(mgr, event_handler);
}
static void setup_gui(void) {
GuiManager* mgr = GuiManager::get_ptr(main_win, mak, (Node*)0L);
PT_Node font = ModelPool::load_model("ttf-comic");
@ -767,7 +842,9 @@ static void setup_gui(void) {
// test 12
// test12(mgr, font);
// test 13
test13(mgr, font);
// test13(mgr, font);
// test 14
test14(mgr, font);
}
static void event_2(CPT_Event) {
@ -847,17 +924,31 @@ static void event_3(CPT_Event) {
}
*/
/*
// for test 11, 13
static void event_3(CPT_Event) {
lb1->scroll_up();
cout << *lb1;
}
*/
// for test 14
static void event_3(CPT_Event) {
ch1->move_prev();
}
/*
// for test11, 13
static void event_4(CPT_Event) {
lb1->scroll_down();
cout << *lb1;
}
*/
// for test 14
static void event_4(CPT_Event) {
ch1->move_next();
}
static void event_demo(CPT_Event) {
cout << "got demo-event-thing event!" << endl;
@ -868,9 +959,9 @@ void gui_keys(EventHandler&) {
have_dlight = true;
event_handler.add_hook("2", event_2);
// for tests 7-11, 13
// for tests 7-11, 13-14
event_handler.add_hook("3", event_3);
// for test 11, 13
// for test 11, 13-14
event_handler.add_hook("4", event_4);
event_handler.add_hook("demo-event-thing", event_demo);
}