diff --git a/panda/src/gui/guiButton.cxx b/panda/src/gui/guiButton.cxx index 4d49cd544f..0495b6b473 100644 --- a/panda/src/gui/guiButton.cxx +++ b/panda/src/gui/guiButton.cxx @@ -8,21 +8,20 @@ #include -#include +#include -typedef set ButtonSet; -static ButtonSet buttons; +typedef map ButtonMap; +static ButtonMap buttons; static bool added_hooks = false; TypeHandle GuiButton::_type_handle; - -static GuiButton * -find_in_buttons_set(const MouseWatcherRegion* rgn) { - for (ButtonSet::const_iterator bi=buttons.begin(); bi!=buttons.end(); ++bi) - if ((*bi)->owns_region(rgn)) - return *bi; - return (GuiButton*)0L; +static inline GuiButton * +find_in_buttons_map(const MouseWatcherRegion* rgn) { + ButtonMap::iterator i = buttons.find(rgn); + if (i == buttons.end()) + return (GuiButton*)0L; + return (*i).second; } inline void GetExtents(GuiLabel* v, GuiLabel* w, GuiLabel* x, GuiLabel* y, @@ -59,7 +58,7 @@ inline void GetExtents(GuiLabel* v, GuiLabel* w, GuiLabel* x, GuiLabel* y, static void enter_button(CPT_Event e) { const MouseWatcherRegion* rgn = DCAST(MouseWatcherRegion, e->get_parameter(0).get_ptr()); - GuiButton* val = find_in_buttons_set(rgn); + GuiButton* val = find_in_buttons_map(rgn); if (val == (GuiButton *)0L) return; // this one wasn't for us val->test_ref_count_integrity(); @@ -68,7 +67,7 @@ static void enter_button(CPT_Event e) { static void exit_button(CPT_Event e) { const MouseWatcherRegion* rgn = DCAST(MouseWatcherRegion, e->get_parameter(0).get_ptr()); - GuiButton* val = find_in_buttons_set(rgn); + GuiButton* val = find_in_buttons_map(rgn); if (val == (GuiButton *)0L) return; // this one wasn't for us val->test_ref_count_integrity(); @@ -77,7 +76,10 @@ static void exit_button(CPT_Event e) { static void click_button_down(CPT_Event e) { const MouseWatcherRegion* rgn = DCAST(MouseWatcherRegion, e->get_parameter(0).get_ptr()); - GuiButton* val = find_in_buttons_set(rgn); + string button = e->get_parameter(1).get_string_value(); + if ((button != "mouse1") && (button != "mouse2") && (button != "mouse3")) + return; + GuiButton* val = find_in_buttons_map(rgn); if (val == (GuiButton *)0L) return; // this one wasn't for us val->test_ref_count_integrity(); @@ -86,7 +88,10 @@ static void click_button_down(CPT_Event e) { static void click_button_up(CPT_Event e) { const MouseWatcherRegion* rgn = DCAST(MouseWatcherRegion, e->get_parameter(0).get_ptr()); - GuiButton* val = find_in_buttons_set(rgn); + string button = e->get_parameter(1).get_string_value(); + if ((button != "mouse1") && (button != "mouse2") && (button != "mouse3")) + return; + GuiButton* val = find_in_buttons_map(rgn); if (val == (GuiButton *)0L) return; // this one wasn't for us val->test_ref_count_integrity(); @@ -406,7 +411,7 @@ GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* down) _rgn = new MouseWatcherRegion("button-" + name, _left, _right, _bottom, _top); _rgn->set_suppress_below(true); - buttons.insert(this); + buttons[this->_rgn] = this; } GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* down, @@ -425,7 +430,7 @@ GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* down, _rgn = new MouseWatcherRegion("button-" + name, _left, _right, _bottom, _top); _rgn->set_suppress_below(true); - buttons.insert(this); + buttons[this->_rgn] = this; } GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* up_roll, @@ -445,7 +450,7 @@ GuiButton::GuiButton(const string& name, GuiLabel* up, GuiLabel* up_roll, _rgn = new MouseWatcherRegion("button-" + name, _left, _right, _bottom, _top); _rgn->set_suppress_below(true); - buttons.insert(this); + buttons[this->_rgn] = this; } GuiButton::~GuiButton(void) { @@ -454,7 +459,7 @@ GuiButton::~GuiButton(void) { // Remove the names from the buttons map, so we don't end up with // an invalid pointer. string name = get_name(); - buttons.erase(this); + buttons.erase(this->_rgn); if ((buttons.size() == 0) && added_hooks) { _eh->remove_hook("gui-enter", enter_button); _eh->remove_hook("gui-exit" + get_name(), exit_button); diff --git a/panda/src/gui/guiRollover.cxx b/panda/src/gui/guiRollover.cxx index 2b6eec0739..e9107a99e3 100644 --- a/panda/src/gui/guiRollover.cxx +++ b/panda/src/gui/guiRollover.cxx @@ -6,21 +6,20 @@ #include "guiRollover.h" #include "config_gui.h" -#include +#include -typedef set RolloverSet; -static RolloverSet rollovers; +typedef map RolloverMap; +static RolloverMap rollovers; static bool added_hooks = false; TypeHandle GuiRollover::_type_handle; -static GuiRollover * -find_in_rollovers_set(const MouseWatcherRegion* rgn) { - for (RolloverSet::const_iterator bi=rollovers.begin(); bi!=rollovers.end(); - ++bi) - if ((*bi)->owns_region(rgn)) - return *bi; - return (GuiRollover*)0L; +static inline GuiRollover * +find_in_rollovers_map(const MouseWatcherRegion* rgn) { + RolloverMap::iterator i = rollovers.find(rgn); + if (i == rollovers.end()) + return (GuiRollover*)0L; + return (*i).second; } inline void GetExtents(GuiLabel* x, GuiLabel* y, float& l, float& r, float& b, @@ -36,7 +35,7 @@ inline void GetExtents(GuiLabel* x, GuiLabel* y, float& l, float& r, float& b, static void enter_rollover(CPT_Event e) { const MouseWatcherRegion* rgn = DCAST(MouseWatcherRegion, e->get_parameter(0).get_ptr()); - GuiRollover* val = find_in_rollovers_set(rgn); + GuiRollover* val = find_in_rollovers_map(rgn); if (val == (GuiRollover *)0L) return; // this wasn't for us val->enter(); @@ -44,7 +43,7 @@ static void enter_rollover(CPT_Event e) { static void exit_rollover(CPT_Event e) { const MouseWatcherRegion* rgn = DCAST(MouseWatcherRegion, e->get_parameter(0).get_ptr()); - GuiRollover* val = find_in_rollovers_set(rgn); + GuiRollover* val = find_in_rollovers_map(rgn); if (val == (GuiRollover *)0L) return; // this wasn't for us val->exit(); @@ -76,7 +75,7 @@ GuiRollover::GuiRollover(const string& name, GuiLabel* off, GuiLabel* on) _rgn = new MouseWatcherRegion("rollover-" + name, _left, _right, _bottom, _top); _rgn->set_suppress_below(false); - rollovers.insert(this); + rollovers[this->_rgn] = this; } GuiRollover::~GuiRollover(void) { @@ -85,7 +84,7 @@ GuiRollover::~GuiRollover(void) { // Remove the names from the rollovers map, so we don't end up with // an invalid pointer. string name = get_name(); - rollovers.erase(this); + rollovers.erase(this->_rgn); if ((rollovers.size() == 0) && added_hooks) { _eh->remove_hook("gui-enter", enter_rollover); _eh->remove_hook("gui-exit", exit_rollover);