mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
cleanup functioning
This commit is contained in:
parent
be7c5c62d8
commit
79c7602cbc
@ -48,6 +48,9 @@ INLINE void GuiButton::up(void) {
|
||||
case INACTIVE_ROLLOVER:
|
||||
switch_state(UP_ROLLOVER);
|
||||
break;
|
||||
case UP:
|
||||
case UP_ROLLOVER:
|
||||
break;
|
||||
default:
|
||||
gui_cat->warning() << "got up from invalid state (" << (int)_state << "),"
|
||||
<< " button '" << this->get_name() << "'" << endl;
|
||||
@ -64,6 +67,9 @@ INLINE void GuiButton::down(void) {
|
||||
case INACTIVE_ROLLOVER:
|
||||
switch_state(DOWN_ROLLOVER);
|
||||
break;
|
||||
case DOWN:
|
||||
case DOWN_ROLLOVER:
|
||||
break;
|
||||
default:
|
||||
gui_cat->warning() << "got down from invalid state (" << (int)_state
|
||||
<< "), button '" << this->get_name() << "'" << endl;
|
||||
|
@ -112,6 +112,7 @@ static void click_button_up(CPT_Event e) {
|
||||
|
||||
void GuiButton::switch_state(GuiButton::States nstate) {
|
||||
test_ref_count_integrity();
|
||||
States ostate = _state;
|
||||
// cleanup old state
|
||||
switch (_state) {
|
||||
case NONE:
|
||||
@ -154,6 +155,8 @@ void GuiButton::switch_state(GuiButton::States nstate) {
|
||||
} else
|
||||
gui_cat->debug() << "_up_event is empty!" << endl;
|
||||
_rgn->trap_clicks(true);
|
||||
if ((ostate == INACTIVE) || (ostate == INACTIVE_ROLLOVER))
|
||||
_mgr->add_region(_rgn);
|
||||
break;
|
||||
case UP_ROLLOVER:
|
||||
if (_up_rollover != (GuiLabel*)0L) {
|
||||
@ -174,6 +177,8 @@ void GuiButton::switch_state(GuiButton::States nstate) {
|
||||
_state = UP;
|
||||
}
|
||||
_rgn->trap_clicks(true);
|
||||
if ((ostate == INACTIVE) || (ostate == INACTIVE_ROLLOVER))
|
||||
_mgr->add_region(_rgn);
|
||||
break;
|
||||
case DOWN:
|
||||
_mgr->add_label(_down);
|
||||
@ -182,6 +187,8 @@ void GuiButton::switch_state(GuiButton::States nstate) {
|
||||
else
|
||||
gui_cat->debug() << "_down_event is empty!" << endl;
|
||||
_rgn->trap_clicks(true);
|
||||
if ((ostate == INACTIVE) || (ostate == INACTIVE_ROLLOVER))
|
||||
_mgr->add_region(_rgn);
|
||||
break;
|
||||
case DOWN_ROLLOVER:
|
||||
if (_down_rollover != (GuiLabel*)0L) {
|
||||
@ -199,6 +206,8 @@ void GuiButton::switch_state(GuiButton::States nstate) {
|
||||
_state = DOWN;
|
||||
}
|
||||
_rgn->trap_clicks(true);
|
||||
if ((ostate == INACTIVE) || (ostate == INACTIVE_ROLLOVER))
|
||||
_mgr->add_region(_rgn);
|
||||
break;
|
||||
case INACTIVE:
|
||||
if (_inactive != (GuiLabel*)0L) {
|
||||
@ -207,6 +216,8 @@ void GuiButton::switch_state(GuiButton::States nstate) {
|
||||
throw_event(_inactive_event);
|
||||
}
|
||||
_rgn->trap_clicks(false);
|
||||
if ((ostate != INACTIVE) && (ostate != INACTIVE_ROLLOVER))
|
||||
_mgr->remove_region(_rgn);
|
||||
break;
|
||||
case INACTIVE_ROLLOVER:
|
||||
if (_inactive != (GuiLabel*)0L) {
|
||||
@ -215,11 +226,14 @@ void GuiButton::switch_state(GuiButton::States nstate) {
|
||||
throw_event(_inactive_event);
|
||||
}
|
||||
_rgn->trap_clicks(false);
|
||||
if ((ostate != INACTIVE) && (ostate != INACTIVE_ROLLOVER))
|
||||
_mgr->remove_region(_rgn);
|
||||
break;
|
||||
default:
|
||||
gui_cat->warning() << "switched to invalid state (" << (int)_state << ")"
|
||||
<< endl;
|
||||
}
|
||||
_mgr->recompute_priorities();
|
||||
}
|
||||
|
||||
void GuiButton::recompute_frame(void) {
|
||||
|
@ -650,25 +650,27 @@ static void test11(GuiManager* mgr, Node* font) {
|
||||
cout << *lb1;
|
||||
}
|
||||
|
||||
PT(GuiButton) gb1;
|
||||
|
||||
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("test12", l1, l2, l3, l4, l5);
|
||||
b1->set_scale(0.1);
|
||||
b1->set_pos(LVector3f::rfu(-0.25, 0., 0.25));
|
||||
gb1 = new GuiButton("test12", l1, l2, l3, l4, l5);
|
||||
gb1->set_scale(0.1);
|
||||
gb1->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();
|
||||
gb1->thaw();
|
||||
gb1->manage(mgr, event_handler);
|
||||
gb1->set_behavior_event("demo-event-thing");
|
||||
gb1->start_behavior();
|
||||
}
|
||||
|
||||
static void test13(GuiManager* mgr, Node* font) {
|
||||
@ -1082,6 +1084,13 @@ static void event_3(CPT_Event) {
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// for test 12
|
||||
static void event_3(CPT_Event) {
|
||||
gb1->inactive();
|
||||
}
|
||||
*/
|
||||
|
||||
// for test 14-16
|
||||
static void event_3(CPT_Event) {
|
||||
ch1->move_prev();
|
||||
@ -1095,6 +1104,13 @@ static void event_4(CPT_Event) {
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// for test 12
|
||||
static void event_4(CPT_Event) {
|
||||
gb1->up();
|
||||
}
|
||||
*/
|
||||
|
||||
// for test 14-16
|
||||
static void event_4(CPT_Event) {
|
||||
ch1->move_next();
|
||||
@ -1109,9 +1125,9 @@ void gui_keys(EventHandler&) {
|
||||
have_dlight = true;
|
||||
|
||||
event_handler.add_hook("2", event_2);
|
||||
// for tests 7-11, 13-16
|
||||
// for tests 7-16
|
||||
event_handler.add_hook("3", event_3);
|
||||
// for test 11, 13-16
|
||||
// for test 11-16
|
||||
event_handler.add_hook("4", event_4);
|
||||
event_handler.add_hook("demo-event-thing", event_demo);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user