diff --git a/src/guiengine/event_handler.cpp b/src/guiengine/event_handler.cpp index 7d8de7c38..a8c5ae5bf 100644 --- a/src/guiengine/event_handler.cpp +++ b/src/guiengine/event_handler.cpp @@ -180,19 +180,26 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp { IGUIElement *el = GUIEngine::getGUIEnv()->getFocus(); if(el == NULL) break; - + Widget* w = GUIEngine::getCurrentScreen()->getWidget( el->getID() ); if(w == NULL) break; - + Widget* widget_to_call = w; /* Find topmost parent. Stop looping if a widget event handler's is itself, to not fall in an infinite loop (this can happen e.g. in checkboxes, where they need to be - notified of clicks onto themselves so they can toggle their state. ) */ - while(widget_to_call->m_event_handler != NULL && widget_to_call->m_event_handler != widget_to_call) + notified of clicks onto themselves so they can toggle their state. ) + On the way, also notify everyone in the chain of the left press. */ + while (widget_to_call->m_event_handler != NULL && widget_to_call->m_event_handler != widget_to_call) + { + if (widget_to_call->leftPressed()) + transmitEvent(w, w->m_properties[PROP_ID]); + widget_to_call = widget_to_call->m_event_handler; + } - if(widget_to_call->leftPressed()) + + if (widget_to_call->leftPressed()) transmitEvent(w, w->m_properties[PROP_ID]); } break; @@ -207,9 +214,15 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp Widget* widget_to_call = w; /* Find topmost parent. Stop looping if a widget event handler's is itself, to not fall in an infinite loop (this can happen e.g. in checkboxes, where they need to be - notified of clicks onto themselves so they can toggle their state. ) */ + notified of clicks onto themselves so they can toggle their state. ) + On the way, also notify everyone in the chain of the right press */ while(widget_to_call->m_event_handler != NULL && widget_to_call->m_event_handler != widget_to_call) + { + if(widget_to_call->rightPressed()) + transmitEvent(widget_to_call, w->m_properties[PROP_ID]); + widget_to_call = widget_to_call->m_event_handler; + } if(widget_to_call->rightPressed()) transmitEvent(widget_to_call, w->m_properties[PROP_ID]); diff --git a/src/guiengine/widgets/ribbon_grid_widget.cpp b/src/guiengine/widgets/ribbon_grid_widget.cpp index d40797f3b..e3eea0676 100644 --- a/src/guiengine/widgets/ribbon_grid_widget.cpp +++ b/src/guiengine/widgets/ribbon_grid_widget.cpp @@ -171,8 +171,6 @@ bool RibbonGridWidget::rightPressed() RibbonWidget* w = getSelectedRibbon(); if(w != NULL) { - w->rightPressed(); - updateLabel(); propagateSelection(); } @@ -193,8 +191,6 @@ bool RibbonGridWidget::leftPressed() RibbonWidget* w = getSelectedRibbon(); if(w != NULL) { - w->leftPressed(); - updateLabel(); propagateSelection(); } diff --git a/src/guiengine/widgets/spinner_widget.cpp b/src/guiengine/widgets/spinner_widget.cpp index 55db09d5b..e3ca0c34d 100644 --- a/src/guiengine/widgets/spinner_widget.cpp +++ b/src/guiengine/widgets/spinner_widget.cpp @@ -29,7 +29,6 @@ SpinnerWidget::SpinnerWidget(const bool gauge) { m_gauge = gauge; m_type = WTYPE_SPINNER; - } void SpinnerWidget::add() @@ -100,6 +99,7 @@ void SpinnerWidget::add() m_children[1].m_element = subbtn; m_children[1].m_type = WTYPE_ICON_BUTTON; m_children[1].id = subbtn->getID(); + m_children[1].m_event_handler = this; subbtn->setUseAlphaChannel(true); subbtn->setImage(texture); @@ -113,6 +113,7 @@ void SpinnerWidget::add() btn, getNewNoFocusID()); m_children[1].m_element = label; m_children[1].m_type = WTYPE_LABEL; + m_children[1].m_event_handler = this; m_children[1].id = label->getID(); label->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); label->setTabStop(false); @@ -129,7 +130,10 @@ void SpinnerWidget::add() m_children[2].m_event_handler = this; m_children[2].m_properties[PROP_ID] = "right"; m_children[2].id = m_children[2].m_element->getID(); + + std::cout << "Adding spinner with m_event_handler=" << m_event_handler << std::endl; } + void SpinnerWidget::move(const int x, const int y, const int w, const int h) { Widget::move(x, y, w, h); diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 1a51dfa7d..a1adfc1e2 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -295,11 +295,7 @@ namespace KartSelectionScreen virtual bool transmitEvent(Widget* w, std::string& originator) { - if (w->m_event_handler != NULL && w->m_event_handler != this) - { - if (!w->m_event_handler->transmitEvent(w, originator)) return false; - } - + std::cout << "= kart selection :: transmitEvent " << originator << "=\n"; Widget* topmost = w; /* Find topmost parent. Stop looping if a widget event handler's is itself, to not fall in an infinite loop (this can happen e.g. in checkboxes, where they need to be @@ -307,6 +303,9 @@ namespace KartSelectionScreen */ while(topmost->m_event_handler != NULL && topmost->m_event_handler != topmost) { + // transmit events to all listeners in the chain + std::cout << "transmitting event to widget " << topmost->m_type << std::endl; + if (!topmost->transmitEvent(w, originator)) return false; topmost = topmost->m_event_handler; std::string name = topmost->m_properties[PROP_ID]; @@ -314,6 +313,11 @@ namespace KartSelectionScreen if (name == spinnerID) { m_associatedPlayer->setPlayerProfile( UserConfigParams::m_all_players.get(playerName->getValue()) ); + + // transmit events to all listeners in the chain + std::cout << "transmitting event to widget " << topmost->m_type << std::endl; + if (!topmost->transmitEvent(w, originator)) return false; + return false; // do not continue propagating the event }