This commit is contained in:
Cary Sandvig 2001-02-13 23:15:29 +00:00
parent 632c534a90
commit 02ea8a3b82
2 changed files with 71 additions and 4 deletions

View File

@ -148,19 +148,29 @@ void GuiButton::switch_state(GuiButton::States nstate) {
break;
case UP:
_mgr->add_label(_up);
if (!_up_event.empty())
if (!_up_event.empty()) {
gui_cat->debug() << "throwing _up_event '" << _up_event << "'" << endl;
throw_event(_up_event);
} else
gui_cat->debug() << "_up_event is empty!" << endl;
_rgn->trap_clicks(true);
break;
case UP_ROLLOVER:
if (_up_rollover != (GuiLabel*)0L) {
_mgr->add_label(_up_rollover);
if (!_up_rollover_event.empty())
if (!_up_rollover_event.empty()) {
gui_cat->debug() << "throwing _up_rollover_event '" << _up_rollover_event << "'"
<< endl;
throw_event(_up_rollover_event);
} else
gui_cat->debug() << "_up_rollover_event is empty!" << endl;
} else {
_mgr->add_label(_up);
if (!_up_event.empty())
if (!_up_event.empty()) {
gui_cat->debug() << "throwing _up_event '" << _up_event << "'" << endl;
throw_event(_up_event);
} else
gui_cat->debug() << "_up_event is empty!" << endl;
_state = UP;
}
_rgn->trap_clicks(true);
@ -169,6 +179,8 @@ void GuiButton::switch_state(GuiButton::States nstate) {
_mgr->add_label(_down);
if (!_down_event.empty())
throw_event(_down_event);
else
gui_cat->debug() << "_down_event is empty!" << endl;
_rgn->trap_clicks(true);
break;
case DOWN_ROLLOVER:
@ -176,10 +188,14 @@ void GuiButton::switch_state(GuiButton::States nstate) {
_mgr->add_label(_down_rollover);
if (!_down_rollover_event.empty())
throw_event(_down_rollover_event);
else
gui_cat->debug() << "_down_rollover_event is empty!" << endl;
} else {
_mgr->add_label(_down);
if (!_down_event.empty())
throw_event(_down_event);
else
gui_cat->debug() << "_down_event is empty!" << endl;
_state = DOWN;
}
_rgn->trap_clicks(true);
@ -223,17 +239,22 @@ void GuiButton::recompute_frame(void) {
void GuiButton::behavior_up(CPT_Event, void* data) {
GuiButton* button = (GuiButton*)data;
gui_cat->debug() << "behavior_up (0x" << data << ")" << endl;
button->run_button_up();
}
void GuiButton::behavior_down(CPT_Event, void* data) {
GuiButton* button = (GuiButton*)data;
gui_cat->debug() << "behavior_down (0x" << data << ")" << endl;
button->run_button_down();
}
void GuiButton::run_button_up(void) {
gui_cat->debug() << "run_button_up (0x" << (void*)this << " '" << this->get_name()
<< "')" << endl;
if (_eh == (EventHandler*)0L)
return;
gui_cat->debug() << "doing work" << endl;
_eh->remove_hook(_up_event, GuiButton::behavior_up, (void*)this);
_eh->remove_hook(_up_rollover_event, GuiButton::behavior_up, (void*)this);
if (!_behavior_event.empty())
@ -243,8 +264,12 @@ void GuiButton::run_button_up(void) {
}
void GuiButton::run_button_down(void) {
gui_cat->debug() << "run_button_down (0x" << (void*)this << " '" << this->get_name()
<< "')" << endl;
if (_eh == (EventHandler*)0L)
return;
gui_cat->debug() << "doing work, up_event is '" << _up_event << "' '"
<< _up_rollover_event << "'" << endl;
_eh->add_hook(_up_event, GuiButton::behavior_up, (void*)this);
_eh->add_hook(_up_rollover_event, GuiButton::behavior_up, (void*)this);
}

View File

@ -85,6 +85,20 @@ static void test3(GuiManager* mgr, Node* font) {
l4->set_background_color(1., 1., 1., 0.5);
b1->thaw();
b1->manage(mgr, event_handler);
GuiLabel* ll1 = GuiLabel::make_simple_text_label("lup", font);
GuiLabel* ll2 = GuiLabel::make_simple_text_label("lupr", font);
GuiLabel* ll3 = GuiLabel::make_simple_text_label("ldown", font);
GuiLabel* ll4 = GuiLabel::make_simple_text_label("ldownr", font);
GuiLabel* ll5 = GuiLabel::make_simple_text_label("lnone", font);
GuiButton* b2 = new GuiButton("test3_2", ll1, ll2, ll3, ll4, ll5);
b2->set_scale(0.1);
b2->set_pos(LVector3f::rfu(0.25, 0., 0.25));
ll2->set_foreground_color(1., 1., 0., 1.);
ll4->set_foreground_color(1., 1., 0., 1.);
ll3->set_background_color(1., 1., 1., 0.5);
ll4->set_background_color(1., 1., 1., 0.5);
b2->thaw();
b2->manage(mgr, event_handler);
}
static void test4(GuiManager* mgr, Node* font) {
@ -624,6 +638,27 @@ static void test11(GuiManager* mgr, Node* font) {
lb1->manage(mgr, event_handler);
}
static void test12(GuiManager* mgr, Node* font) {
GuiLabel* l1 = GuiLabel::make_simple_text_label("up", font);
GuiLabel* l2 = GuiLabel::make_simple_text_label("upr", font);
GuiLabel* l3 = GuiLabel::make_simple_text_label("down", font);
GuiLabel* l4 = GuiLabel::make_simple_text_label("downr", font);
GuiLabel* l5 = GuiLabel::make_simple_text_label("none", font);
GuiButton* b1 = new GuiButton("test3", l1, l2, l3, l4, l5);
b1->set_scale(0.1);
b1->set_pos(LVector3f::rfu(-0.25, 0., 0.25));
l2->set_foreground_color(1., 1., 0., 1.);
l4->set_foreground_color(1., 1., 0., 1.);
l1->set_background_color(0., 0., 0., 1.);
l2->set_background_color(0., 0., 0., 1.);
l3->set_background_color(1., 1., 1., 0.5);
l4->set_background_color(1., 1., 1., 0.5);
b1->thaw();
b1->manage(mgr, event_handler);
b1->set_behavior_event("demo-event-thing");
b1->start_behavior();
}
static void setup_gui(void) {
GuiManager* mgr = GuiManager::get_ptr(main_win, mak, (Node*)0L);
PT_Node font = ModelPool::load_model("ttf-comic");
@ -632,7 +667,7 @@ static void setup_gui(void) {
// test 2
// test2(mgr, font);
// test 3
test3(mgr, font);
// test3(mgr, font);
// test 4
// test4(mgr, font);
// test 5
@ -652,6 +687,8 @@ static void setup_gui(void) {
// test10(mgr, font);
// test 11
// test11(mgr, font);
// test 12
test12(mgr, font);
}
static void event_2(CPT_Event) {
@ -743,6 +780,10 @@ static void event_4(CPT_Event) {
cout << *lb1;
}
static void event_demo(CPT_Event) {
cout << "got demo-event-thing event!" << endl;
}
void gui_keys(EventHandler&) {
new RenderRelation( lights, dlight );
have_dlight = true;
@ -754,6 +795,7 @@ void gui_keys(EventHandler&) {
// for test 11
event_handler.add_hook("4", event_4);
*/
event_handler.add_hook("demo-event-thing", event_demo);
}
int main(int argc, char *argv[]) {