From 1aea5622dc37593b3e301c687c9b5a05cebbe96d Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Thu, 8 Feb 2001 22:49:25 +0000 Subject: [PATCH] here we go --- panda/src/gui/guiButton.I | 45 +++++++++++++++++++++++++++++++++++++ panda/src/gui/guiButton.cxx | 15 +++++++++++++ panda/src/gui/guiButton.h | 5 +++++ 3 files changed, 65 insertions(+) diff --git a/panda/src/gui/guiButton.I b/panda/src/gui/guiButton.I index 2fee8fb5e7..68e1865046 100644 --- a/panda/src/gui/guiButton.I +++ b/panda/src/gui/guiButton.I @@ -52,6 +52,7 @@ INLINE void GuiButton::up(void) { gui_cat->warning() << "got up from invalid state (" << (int)_state << ")," << " button '" << this->get_name() << "'" << endl; } + this->reset_behavior(); } INLINE void GuiButton::down(void) { @@ -84,6 +85,7 @@ INLINE void GuiButton::inactive(void) { gui_cat->warning() << "got inactive from invalid state (" << (int)_state << "), button '" << this->get_name() << "'" << endl; } + this->stop_behavior(); } INLINE void GuiButton::click(void) { @@ -124,25 +126,55 @@ INLINE bool GuiButton::is_active(void) const { } INLINE void GuiButton::set_up_event(const string& s) { + if (_behavior_running) + if (_mgr != (GuiManager*)0L) + _eh->remove_hook(_up_event, GuiButton::behavior_up, (void*)this); _up_event = s; + if (_behavior_running) + if (_mgr != (GuiManager*)0L) + _eh->add_hook(_up_event, GuiButton::behavior_up, (void*)this); } INLINE void GuiButton::set_up_rollover_event(const string& s) { + if (_behavior_running) + if (_mgr != (GuiManager*)0L) + _eh->remove_hook(_up_rollover_event, GuiButton::behavior_up, + (void*)this); _up_rollover_event = s; + if (_behavior_running) + if (_mgr != (GuiManager*)0L) + _eh->add_hook(_up_rollover_event, GuiButton::behavior_up, (void*)this); } INLINE void GuiButton::set_down_event(const string& s) { + if (_behavior_running) + if (_mgr != (GuiManager*)0L) + _eh->remove_hook(_down_event, GuiButton::behavior_up, (void*)this); _down_event = s; + if (_behavior_running) + if (_mgr != (GuiManager*)0L) + _eh->add_hook(_down_event, GuiButton::behavior_up, (void*)this); } INLINE void GuiButton::set_down_rollover_event(const string& s) { + if (_behavior_running) + if (_mgr != (GuiManager*)0L) + _eh->remove_hook(_down_rollover_event, GuiButton::behavior_up, + (void*)this); _down_rollover_event = s; + if (_behavior_running) + if (_mgr != (GuiManager*)0L) + _eh->add_hook(_down_rollover_event, GuiButton::behavior_up, (void*)this); } INLINE void GuiButton::set_inactive_event(const string& s) { _inactive_event = s; } +INLINE void GuiButton::set_behavior_event(const string& s) { + _behavior_event = s; +} + INLINE const string& GuiButton::get_up_event(void) const { return _up_event; } @@ -163,6 +195,10 @@ INLINE const string& GuiButton::get_inactive_event(void) const { return _inactive_event; } +INLINE const string& GuiButton::get_behavior_event(void) const { + return _behavior_event; +} + INLINE void GuiButton::set_up_rollover(GuiLabel* upr) { _up_rollover = upr; if (_up_rollover_event.empty()) @@ -174,3 +210,12 @@ INLINE void GuiButton::set_down_rollover(GuiLabel* downr) { if (_down_rollover_event.empty()) _down_rollover_event = this->get_name() + "-down-rollover"; } + +INLINE void GuiButton::set_behavior_functor(GuiBehavior::BehaviorFunctor* f) { + _behavior_functor = f; +} + +INLINE GuiBehavior::BehaviorFunctor* +GuiButton::get_behavior_functor(void) const { + return _behavior_functor; +} diff --git a/panda/src/gui/guiButton.cxx b/panda/src/gui/guiButton.cxx index 66e6213601..0114a86ad9 100644 --- a/panda/src/gui/guiButton.cxx +++ b/panda/src/gui/guiButton.cxx @@ -395,14 +395,29 @@ void GuiButton::set_pos(const LVector3f& p) { void GuiButton::start_behavior(void) { GuiBehavior::start_behavior(); + if (_mgr == (GuiManager*)0L) + return; + _eh->add_hook(_down_event, GuiButton::behavior_down, (void*)this); + _eh->add_hook(_down_rollover_event, GuiButton::behavior_down, (void*)this); } void GuiButton::stop_behavior(void) { GuiBehavior::stop_behavior(); + if (_mgr == (GuiManager*)0L) + return; + _eh->remove_hook(_up_event, GuiButton::behavior_up, (void*)this); + _eh->remove_hook(_up_rollover_event, GuiButton::behavior_up, (void*)this); + _eh->remove_hook(_down_event, GuiButton::behavior_down, (void*)this); + _eh->remove_hook(_down_rollover_event, GuiButton::behavior_down, + (void*)this); } void GuiButton::reset_behavior(void) { GuiBehavior::reset_behavior(); + if (_mgr == (GuiManager*)0L) + return; + _eh->remove_hook(_up_event, GuiButton::behavior_up, (void*)this); + _eh->remove_hook(_up_rollover_event, GuiButton::behavior_up, (void*)this); } void GuiButton::output(ostream& os) const { diff --git a/panda/src/gui/guiButton.h b/panda/src/gui/guiButton.h index d4e7a8609b..e70496a8ef 100644 --- a/panda/src/gui/guiButton.h +++ b/panda/src/gui/guiButton.h @@ -74,16 +74,21 @@ PUBLISHED: INLINE void set_down_event(const string&); INLINE void set_down_rollover_event(const string&); INLINE void set_inactive_event(const string&); + INLINE void set_behavior_event(const string&); INLINE const string& get_up_event(void) const; INLINE const string& get_up_rollover_event(void) const; INLINE const string& get_down_event(void) const; INLINE const string& get_down_rollover_event(void) const; INLINE const string& get_inactive_event(void) const; + INLINE const string& get_behavior_event(void) const; INLINE void set_up_rollover(GuiLabel*); INLINE void set_down_rollover(GuiLabel*); + INLINE void set_behavior_functor(GuiBehavior::BehaviorFunctor*); + INLINE GuiBehavior::BehaviorFunctor* get_behavior_functor(void) const; + virtual void set_scale(float); virtual void set_pos(const LVector3f&);