From 880c346ad7ba33d159ad833f1c0cd2b27c08c2cc Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Fri, 20 Apr 2001 01:51:16 +0000 Subject: [PATCH] whew --- direct/src/gui/GuiGlobals.py | 5 ----- panda/src/audio/audio_gui_functor.cxx | 7 ++++--- panda/src/audio/audio_gui_functor.h | 21 ++++++++++++++++++++- panda/src/gui/config_gui.cxx | 1 + panda/src/gui/guiBehavior.cxx | 3 ++- panda/src/gui/guiBehavior.h | 23 +++++++++++++++++++++-- panda/src/gui/guiButton.cxx | 4 ++-- panda/src/gui/guiButton.h | 4 ++-- panda/src/gui/guiChooser.cxx | 14 +++++++------- panda/src/gui/guiChooser.h | 25 ++++++++++++++++++++++--- panda/src/gui/guiListBox.cxx | 14 +++++++------- panda/src/gui/guiListBox.h | 25 ++++++++++++++++++++++--- 12 files changed, 110 insertions(+), 36 deletions(-) diff --git a/direct/src/gui/GuiGlobals.py b/direct/src/gui/GuiGlobals.py index fb9c527f7b..7d7084a81b 100644 --- a/direct/src/gui/GuiGlobals.py +++ b/direct/src/gui/GuiGlobals.py @@ -9,7 +9,6 @@ guiMgr = GuiManager.GuiManager.getPtr(base.win, base.mak.node(), font = None panel = None drawOrder = 100 -massiveLeak = [] def getDefaultFont(): global font @@ -45,8 +44,6 @@ def getNewRolloverFunctor(sound = None): val = AudioGuiFunctor(roll) else: val = AudioGuiFunctor() - global massiveLeak - massiveLeak.append(val) return val def getNewClickFunctor(sound = None): @@ -60,6 +57,4 @@ def getNewClickFunctor(sound = None): val = AudioGuiFunctor(click) else: val = AudioGuiFunctor() - global massiveLeak - massiveLeak.append(val) return val diff --git a/panda/src/audio/audio_gui_functor.cxx b/panda/src/audio/audio_gui_functor.cxx index ae8ff8b777..f6cfe81a98 100644 --- a/panda/src/audio/audio_gui_functor.cxx +++ b/panda/src/audio/audio_gui_functor.cxx @@ -5,13 +5,14 @@ #include "audio_gui_functor.h" +TypeHandle AudioGuiFunctor::_type_handle; + AudioGuiFunctor::AudioGuiFunctor(AudioSound* sound, GuiBehavior::BehaviorFunctor* prev) - : _prev(prev), _sound(sound) {} + : GuiBehavior::BehaviorFunctor(), _prev(prev), _sound(sound) {} AudioGuiFunctor::~AudioGuiFunctor(void) { - if (_prev != (GuiBehavior::BehaviorFunctor*)0L) - delete _prev; + _prev.clear(); } #include "audio_manager.h" diff --git a/panda/src/audio/audio_gui_functor.h b/panda/src/audio/audio_gui_functor.h index c0759590e4..60852a4514 100644 --- a/panda/src/audio/audio_gui_functor.h +++ b/panda/src/audio/audio_gui_functor.h @@ -11,7 +11,7 @@ class EXPCL_PANDA AudioGuiFunctor : public GuiBehavior::BehaviorFunctor { protected: - GuiBehavior::BehaviorFunctor* _prev; + PT(GuiBehavior::BehaviorFunctor) _prev; PT(AudioSound) _sound; public: virtual ~AudioGuiFunctor(void); @@ -22,6 +22,25 @@ PUBLISHED: (GuiBehavior::BehaviorFunctor*)0L); INLINE AudioSound* get_sound(void) const { return _sound; } INLINE GuiBehavior::BehaviorFunctor* get_prev(void) const { return _prev; } +public: + // type interface + static TypeHandle get_class_type(void) { + return _type_handle; + } + static void init_type(void) { + GuiBehavior::BehaviorFunctor::init_type(); + register_type(_type_handle, "AudioGuiFunctor", + GuiBehavior::BehaviorFunctor::get_class_type()); + } + virtual TypeHandle get_type(void) const { + return get_class_type(); + } + virtual TypeHandle force_init_type(void) { + init_type(); + return get_class_type(); + } +private: + static TypeHandle _type_handle; }; #endif /* __AUDIO_GUI_FUNCTOR_H__ */ diff --git a/panda/src/gui/config_gui.cxx b/panda/src/gui/config_gui.cxx index b368d8c592..95485823f2 100644 --- a/panda/src/gui/config_gui.cxx +++ b/panda/src/gui/config_gui.cxx @@ -25,6 +25,7 @@ ConfigureFn(config_gui) { GuiLabel::init_type(); GuiItem::init_type(); GuiBehavior::init_type(); + GuiBehavior::BehaviorFunctor::init_type(); GuiSign::init_type(); GuiRollover::init_type(); GuiButton::init_type(); diff --git a/panda/src/gui/guiBehavior.cxx b/panda/src/gui/guiBehavior.cxx index f52b6b7f2c..f8ac3ce1a4 100644 --- a/panda/src/gui/guiBehavior.cxx +++ b/panda/src/gui/guiBehavior.cxx @@ -6,8 +6,9 @@ #include "guiBehavior.h" TypeHandle GuiBehavior::_type_handle; +TypeHandle GuiBehavior::BehaviorFunctor::_type_handle; -GuiBehavior::BehaviorFunctor::BehaviorFunctor(void) { +GuiBehavior::BehaviorFunctor::BehaviorFunctor(void) : TypedReferenceCount() { } GuiBehavior::BehaviorFunctor::~BehaviorFunctor(void) { diff --git a/panda/src/gui/guiBehavior.h b/panda/src/gui/guiBehavior.h index 395dc3c68c..2692b23162 100644 --- a/panda/src/gui/guiBehavior.h +++ b/panda/src/gui/guiBehavior.h @@ -15,12 +15,31 @@ protected: INLINE GuiBehavior(void); PUBLISHED: - class EXPCL_PANDA BehaviorFunctor { + class EXPCL_PANDA BehaviorFunctor : public TypedReferenceCount { public: virtual void doit(GuiBehavior*) = 0; - virtual ~BehaviorFunctor(void); PUBLISHED: BehaviorFunctor(void); + virtual ~BehaviorFunctor(void); + public: + // type interface + static TypeHandle get_class_type(void) { + return _type_handle; + } + static void init_type(void) { + TypedReferenceCount::init_type(); + register_type(_type_handle, "GuiBehavior::BehaviorFunctor", + TypedReferenceCount::get_class_type()); + } + virtual TypeHandle get_type(void) const { + return get_class_type(); + } + virtual TypeHandle force_init_type(void) { + init_type(); + return get_class_type(); + } + private: + static TypeHandle _type_handle; }; PUBLISHED: GuiBehavior(const string&); diff --git a/panda/src/gui/guiButton.cxx b/panda/src/gui/guiButton.cxx index db35826618..4c57344d74 100644 --- a/panda/src/gui/guiButton.cxx +++ b/panda/src/gui/guiButton.cxx @@ -531,9 +531,9 @@ GuiButton::~GuiButton(void) { } if (_behavior_functor != (GuiBehavior::BehaviorFunctor*)0L) - delete _behavior_functor; + _behavior_functor.clear(); if (_rollover_functor != (GuiBehavior::BehaviorFunctor*)0L) - delete _behavior_functor; + _rollover_functor.clear(); } void GuiButton::manage(GuiManager* mgr, EventHandler& eh) { diff --git a/panda/src/gui/guiButton.h b/panda/src/gui/guiButton.h index 0290f7feb9..83ec81c8c3 100644 --- a/panda/src/gui/guiButton.h +++ b/panda/src/gui/guiButton.h @@ -36,8 +36,8 @@ private: string _behavior_event; bool _have_event_param; int _event_param; - GuiBehavior::BehaviorFunctor* _behavior_functor; - GuiBehavior::BehaviorFunctor* _rollover_functor; + PT(GuiBehavior::BehaviorFunctor) _behavior_functor; + PT(GuiBehavior::BehaviorFunctor) _rollover_functor; INLINE GuiButton(void); void switch_state(States); diff --git a/panda/src/gui/guiChooser.cxx b/panda/src/gui/guiChooser.cxx index 1968e64472..b48e0b3256 100644 --- a/panda/src/gui/guiChooser.cxx +++ b/panda/src/gui/guiChooser.cxx @@ -6,13 +6,15 @@ #include "guiChooser.h" TypeHandle GuiChooser::_type_handle; +TypeHandle GuiChooser::ChooseFunctor::_type_handle; GuiChooser::ChooseFunctor::ChooseFunctor(GuiChooser* ch, GuiBehavior::BehaviorFunctor* func) - : _prev(func), _ch(ch) { + : GuiBehavior::BehaviorFunctor(), _prev(func), _ch(ch) { } GuiChooser::ChooseFunctor::~ChooseFunctor(void) { + _prev.clear(); } void GuiChooser::ChooseFunctor::doit(GuiBehavior* b) { @@ -260,7 +262,7 @@ void GuiChooser::start_behavior(void) { return; if (_prev_functor != (GuiChooser::ChooseFunctor*)0L) { _prev_button->set_behavior_functor(_prev_functor->get_prev()); - delete _prev_functor; + _prev_functor.clear(); } _prev_functor = new GuiChooser::ChooseFunctor(this, _prev_button->get_behavior_functor()); @@ -268,7 +270,7 @@ void GuiChooser::start_behavior(void) { _prev_button->start_behavior(); if (_next_functor != (GuiChooser::ChooseFunctor*)0L) { _next_button->set_behavior_functor(_next_functor->get_prev()); - delete _next_functor; + _next_functor.clear(); } _next_functor = new GuiChooser::ChooseFunctor(this, _next_button->get_behavior_functor()); @@ -282,14 +284,12 @@ void GuiChooser::stop_behavior(void) { return; if (_prev_functor != (GuiChooser::ChooseFunctor*)0L) { _prev_button->set_behavior_functor(_prev_functor->get_prev()); - delete _prev_functor; - _prev_functor = (GuiChooser::ChooseFunctor*)0L; + _prev_functor.clear(); _prev_button->stop_behavior(); } if (_next_functor != (GuiChooser::ChooseFunctor*)0L) { _next_button->set_behavior_functor(_next_functor->get_prev()); - delete _next_functor; - _next_functor = (GuiChooser::ChooseFunctor*)0L; + _next_functor.clear(); _next_button->stop_behavior(); } } diff --git a/panda/src/gui/guiChooser.h b/panda/src/gui/guiChooser.h index fa898c3c24..ac0176185a 100644 --- a/panda/src/gui/guiChooser.h +++ b/panda/src/gui/guiChooser.h @@ -19,13 +19,32 @@ private: class EXPCL_PANDA ChooseFunctor : public GuiBehavior::BehaviorFunctor { protected: - GuiBehavior::BehaviorFunctor* _prev; + PT(GuiBehavior::BehaviorFunctor) _prev; GuiChooser* _ch; public: ChooseFunctor(GuiChooser*, GuiBehavior::BehaviorFunctor*); virtual ~ChooseFunctor(void); virtual void doit(GuiBehavior*); INLINE GuiBehavior::BehaviorFunctor* get_prev(void) { return _prev; } + public: + // type interface + static TypeHandle get_class_type(void) { + return _type_handle; + } + static void init_type(void) { + GuiBehavior::BehaviorFunctor::init_type(); + register_type(_type_handle, "ChooseFunctor", + GuiBehavior::BehaviorFunctor::get_class_type()); + } + virtual TypeHandle get_type(void) const { + return get_class_type(); + } + virtual TypeHandle force_init_type(void) { + init_type(); + return get_class_type(); + } + private: + static TypeHandle _type_handle; }; friend ChooseFunctor; @@ -36,8 +55,8 @@ private: PT(GuiButton) _prev_button; PT(GuiButton) _next_button; - ChooseFunctor* _prev_functor; - ChooseFunctor* _next_functor; + PT(ChooseFunctor) _prev_functor; + PT(ChooseFunctor) _next_functor; INLINE GuiChooser(void); virtual void recompute_frame(void); diff --git a/panda/src/gui/guiListBox.cxx b/panda/src/gui/guiListBox.cxx index b7b459f328..5d2d949d80 100644 --- a/panda/src/gui/guiListBox.cxx +++ b/panda/src/gui/guiListBox.cxx @@ -6,13 +6,15 @@ #include "guiListBox.h" TypeHandle GuiListBox::_type_handle; +TypeHandle GuiListBox::ListFunctor::_type_handle; GuiListBox::ListFunctor::ListFunctor(GuiListBox* box, GuiBehavior::BehaviorFunctor* func) - : _prev(func), _lb(box) { + : GuiBehavior::BehaviorFunctor(), _prev(func), _lb(box) { } GuiListBox::ListFunctor::~ListFunctor(void) { + _prev.clear(); } void GuiListBox::ListFunctor::doit(GuiBehavior* b) { @@ -332,7 +334,7 @@ void GuiListBox::start_behavior(void) { return; if (_up_functor != (GuiListBox::ListFunctor*)0L) { _up_arrow->set_behavior_functor(_up_functor->get_prev()); - delete _up_functor; + _up_functor.clear(); } _up_functor = new GuiListBox::ListFunctor(this, _up_arrow->get_behavior_functor()); @@ -340,7 +342,7 @@ void GuiListBox::start_behavior(void) { _up_arrow->start_behavior(); if (_down_functor != (GuiListBox::ListFunctor*)0L) { _down_arrow->set_behavior_functor(_down_functor->get_prev()); - delete _down_functor; + _down_functor.clear(); } _down_functor = new GuiListBox::ListFunctor(this, _down_arrow->get_behavior_functor()); @@ -354,14 +356,12 @@ void GuiListBox::stop_behavior(void) { return; if (_up_functor != (GuiListBox::ListFunctor*)0L) { _up_arrow->set_behavior_functor(_up_functor->get_prev()); - delete _up_functor; - _up_functor = (GuiListBox::ListFunctor*)0L; + _up_functor.clear(); _up_arrow->stop_behavior(); } if (_down_functor != (GuiListBox::ListFunctor*)0L) { _down_arrow->set_behavior_functor(_down_functor->get_prev()); - delete _down_functor; - _down_functor = (GuiListBox::ListFunctor*)0L; + _down_functor.clear(); _down_arrow->stop_behavior(); } } diff --git a/panda/src/gui/guiListBox.h b/panda/src/gui/guiListBox.h index 71d5f0177a..846080d04a 100644 --- a/panda/src/gui/guiListBox.h +++ b/panda/src/gui/guiListBox.h @@ -19,13 +19,32 @@ private: class EXPCL_PANDA ListFunctor : public GuiBehavior::BehaviorFunctor { protected: - GuiBehavior::BehaviorFunctor* _prev; + PT(GuiBehavior::BehaviorFunctor) _prev; GuiListBox* _lb; public: ListFunctor(GuiListBox*, GuiBehavior::BehaviorFunctor*); virtual ~ListFunctor(void); virtual void doit(GuiBehavior*); INLINE GuiBehavior::BehaviorFunctor* get_prev(void) { return _prev; } + public: + // type interface + static TypeHandle get_class_type(void) { + return _type_handle; + } + static void init_type(void) { + GuiBehavior::BehaviorFunctor::init_type(); + register_type(_type_handle, "ListFunctor", + GuiBehavior::BehaviorFunctor::get_class_type()); + } + virtual TypeHandle get_type(void) const { + return get_class_type(); + } + virtual TypeHandle force_init_type(void) { + init_type(); + return get_class_type(); + } + private: + static TypeHandle _type_handle; }; friend ListFunctor; @@ -37,8 +56,8 @@ private: PT(GuiButton) _down_arrow; unsigned int _n_visible; - ListFunctor* _up_functor; - ListFunctor* _down_functor; + PT(ListFunctor) _up_functor; + PT(ListFunctor) _down_functor; INLINE GuiListBox(void); virtual void recompute_frame(void);